Skip to content

Commit

Permalink
Tool plugin for Py-ChemShell finished; removed all changes to command…
Browse files Browse the repository at this point in the history
…s and gui
  • Loading branch information
chemsh committed Aug 6, 2019
1 parent e20f441 commit b3accc6
Show file tree
Hide file tree
Showing 11 changed files with 1,999 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ src/aten
Aten.desktop
.kdev4/
build/
bin

# Miscellaneous
*swp
changes

#CMake
cmake_install.cmake
CMakeFiles
CMakeCache.txt

# QRC
*.qrc.depends
qrc_*.cpp
1 change: 1 addition & 0 deletions src/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ add_subdirectory(io_vfield)
add_subdirectory(io_xyz)
add_subdirectory(method_mopac71)
add_subdirectory(tool_springs)
add_subdirectory(tool_chemshell)
add_subdirectory(tool_test)
39 changes: 37 additions & 2 deletions src/plugins/io_chemshell/chemshell_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ ChemShellModelPlugin::ChemShellModelPlugin()
{
// Setup plugin options
pluginOptions_.add("useTypeNames", "false");
pluginOptions_.add("py-chemsh_input", "false");
// YL 06/08/2019: strings for PY-ChemShell input script
pluginOptions_.add("_frag" , "");
pluginOptions_.add("_qm_region", "");
pluginOptions_.add("_theory" , "");
pluginOptions_.add("_task" , "");
}

// Destructor
Expand Down Expand Up @@ -145,6 +151,8 @@ bool ChemShellModelPlugin::importData()
for (i = 0; i < nRecords; ++i) {
if (!fileParser_.parseLine()) break;
atom = createAtom(targetModel(), fileParser_.argc(0), fileParser_.arg3d(1)*ANGBOHR);
ForcefieldAtom* ffa = targetModel()->addAtomName(atom->element(), fileParser_.argc(0));
atom->setType(ffa);
}
break;
case (ChemShellModelPlugin::AtomChargesBlock):
Expand Down Expand Up @@ -202,6 +210,26 @@ bool ChemShellModelPlugin::exportData()
// Get the current model pointer containing the data we are to export
Model* sourceModel = targetModel();

// YL 06/08/2019: we have to use io_chemshell to write out since tool_chemshell cannot access I/O
if(pluginOptions_.value("py-chemsh_input") == "true") {

if(!fileParser_.writeLine("# Py-ChemShell input script generated by Aten")) return false;
if(!fileParser_.writeLine("# www.chemshell.org")) return false;
if(!fileParser_.writeLine("# Cite: J. Chem. Theory Comput. 2019, 15, 1317-1328\n")) return false;
if(!fileParser_.writeLine("from chemsh import *\n")) return false;
if(!fileParser_.writeLine(pluginOptions_.value("_frag"))) return false;
if(!fileParser_.writeLine(pluginOptions_.value("_pun_filename"))) return false;
if(!fileParser_.writeLine(pluginOptions_.value("_qm_region"))) return false;
if(!fileParser_.writeLine(pluginOptions_.value("_theory"))) return false;
if(!fileParser_.writeLine(pluginOptions_.value("_task"))) return false;
if(!fileParser_.writeLine("my_task.run()\n")) return false;
if(!fileParser_.writeLine("energy = my_task.result.energy\n")) return false;

Messenger::print("Py-ChemShell input script '%s' generated", qPrintable(fileParser_.filename()));
return true;

}

// Header
if (!fileParser_.writeLine("block = fragment records = 0")) return false;
if (!fileParser_.writeLine("block = title records = 1")) return false;
Expand All @@ -210,10 +238,17 @@ bool ChemShellModelPlugin::exportData()
// Atom coordinates
if (!fileParser_.writeLineF("block = coordinates records = %d", sourceModel->nAtoms())) return false;
for ( Atom* i = sourceModel->atoms(); i != NULL; i = i->next ) {
if (!fileParser_.writeLineF("%s %20.14e %20.14e %20.14e ", ElementMap::symbol(i->element()),
i->r().x/ANGBOHR, i->r().y/ANGBOHR, i->r().z/ANGBOHR)) return false;
// YL 02/08/2019: changed to print ff types rather than element symbols
if (!fileParser_.writeLineF("%s %20.14e %20.14e %20.14e ", i->type()->name().toUtf8().constData(),
i->r().x/ANGBOHR, i->r().y/ANGBOHR, i->r().z/ANGBOHR)) return false;
// if (!fileParser_.writeLineF("%s %20.14e %20.14e %20.14e ", ElementMap::symbol(i->element()),
// i->r().x/ANGBOHR, i->r().y/ANGBOHR, i->r().z/ANGBOHR)) return false;
}

// total charge
if (!fileParser_.writeLine("block = charge records = 1")) return false;
if (!fileParser_.writeLineF("%20.5e", 0.00000)) return false;

// Atom charges
hasCharges = false;
tiny = 1.0e-10;
Expand Down
52 changes: 52 additions & 0 deletions src/plugins/tool_chemshell/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Meta-Objects
set(chemshelltool_MOC_HDRS
chemshelltool.hui
chemshelltooldialog.h
)
QT5_WRAP_CPP(chemshelltool_MOC_SRCS ${chemshelltool_MOC_HDRS} OPTIONS -I${PROJECT_SOURCE_DIR}/src)

SET(chemshelltool_UIS
chemshelltooldialog.ui
)
QT5_WRAP_UI(chemshelltool_UIS_H ${chemshelltool_UIS})

# Resources
set(chemshelltool_RES_QRC
chemshelltool_icons.qrc
)
QT5_ADD_RESOURCES(chemshelltool_RES ${chemshelltool_RES_QRC})

add_library(chemshelltool MODULE
chemshelltool_funcs.cpp
chemshelltooldialog_funcs.cpp
${chemshelltool_RES}
${chemshelltool_MOC_SRCS}
${chemshelltool_UIS_H}
)
target_link_libraries(chemshelltool
plugins
${PLUGIN_LINK_LIBS}
)
set_target_properties(chemshelltool PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${Aten_BINARY_DIR}/data/plugins
COMPILE_DEFINITIONS "QT_PLUGIN"
PREFIX ""
)

# Install Targets
if(UNIX AND NOT APPLE)
install(TARGETS chemshelltool
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/aten/plugins COMPONENT RuntimePlugins
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/aten/plugins COMPONENT RuntimePlugins
)
endif(UNIX AND NOT APPLE)

# Includes
target_include_directories(chemshelltool PRIVATE
${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
)

127 changes: 127 additions & 0 deletions src/plugins/tool_chemshell/chemshelltool.hui
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
*** ChemShell Tool Plugin
*** src/plugins/tool_chemshell/chemshelltool.hui
Copyright T. Youngs 2016-2018

This file is part of Aten.

Aten is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Aten is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Aten. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ATEN_CHEMSHELLPLUGIN_H
#define ATEN_CHEMSHELLPLUGIN_H

#include "plugins/interfaces/toolplugin.h"
#include "plugins/interfaces/fileplugin.h"
#include "gui/mainwindow.h"
#include "main/aten.h"
#include <QDir>
#include "base/kvmap.h"
#include "base/prefs.h"
#include "base/encoderdefinition.h"
#include "model/bundle.h"
#include "model/fragment.h"
#include "model/fragmentgroup.h"
#include "templates/list.h"
#include "parser/program.h"
#include "parser/variablelist.h"
#include "methods/partitioningscheme.h"
#include "gui/useractions.h"
#include "plugins/pluginstore.h"
#include "base/namespace.h"

// forward declarations
class AtenWindow;
class FileParser;

ATEN_BEGIN_NAMESPACE

// ChemShell Tool Plugin
class ChemShellToolPlugin : public QObject, public ToolPluginInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.projectaten.Aten.CSToolPluginInterface.v1")
Q_INTERFACES(AtenSpace::ToolPluginInterface)


public:
// Constructor
ChemShellToolPlugin();
// Destructor
~ChemShellToolPlugin();


private:
AtenWindow* atenWindow();

/*
* Instance Handling
*/
private:
// Return a copy of the plugin object
BasePluginInterface* makeCopy() const;
void renameKeywords();


/*
* Definition
*/
public:
// Return type of plugin
PluginTypes::PluginType type() const;
// Return category of plugin
int category() const;
// Return name of plugin
QString name() const;
// Return nickname of plugin
QString nickname() const;
// Return whether plugin is enabled
bool enabled() const;
// Return description (long name) of plugin
QString description() const;


/*
* Tool Definition
*/
public:
// Return button label to use in GUI
QString buttonLabel() const;
// Return icon for button in GUI
QIcon buttonIcon() const;
// Return group name for tool (used to group similar tools together)
QString groupName() const;
// Return whether the tool is enabled (appears in the GUI)
bool isEnabled() const;
// Return whether the tool has a dialog
bool hasDialog() const;
// Show the dialog for the tool
bool showDialog();
// Run the tool with the current settings
bool runTool();

/*
* QObject / Signals
*/
public:
// Return interface as QObject
QObject* object();

signals:
void updateWidgets(int);
};

ATEN_END_NAMESPACE

#endif
Loading

0 comments on commit b3accc6

Please sign in to comment.