Skip to content

Commit

Permalink
Merge pull request #32 from trisyoungs/py-chemshell
Browse files Browse the repository at this point in the history
Py-chemshell plugin
  • Loading branch information
trisyoungs authored Aug 12, 2019
2 parents e20f441 + 520a481 commit 1130512
Show file tree
Hide file tree
Showing 14 changed files with 2,095 additions and 3 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 configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ src/plugins/method_mopac71/Makefile
src/plugins/method_mopac71/mopac7.1/Makefile
src/plugins/tool_springs/Makefile
src/plugins/tool_test/Makefile
src/plugins/tool_chemshell/Makefile
src/sg/Makefile
src/templates/Makefile
)
Expand Down
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)
2 changes: 1 addition & 1 deletion src/plugins/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SUBDIRS = interfaces
SUBDIRS += io_akf io_chemshell io_cif io_cube io_dlpoly io_dlputils io_epsr io_ff io_gamessus io_gromacs io_mdlmol io_mopac io_msi io_pdb io_rmcprofile io_sybylmol2 io_test io_vfield io_xyz
#SUBDIRS += io_csd io_espresso io_gaussian io_siesta
SUBDIRS += method_mopac71
SUBDIRS += tool_springs tool_test
SUBDIRS += tool_springs tool_test tool_chemshell

noinst_LTLIBRARIES = libplugins.la

Expand Down
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
56 changes: 56 additions & 0 deletions src/plugins/tool_chemshell/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This plugin was written by You Lu, Aug. 2019
# [email protected]


# 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}
)

35 changes: 35 additions & 0 deletions src/plugins/tool_chemshell/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Set plugin installation dir and define plugin targets
pluginexecdir = @ATEN_PLUGINLIBDIR@
pluginexec_LTLIBRARIES = chemshelltool.la

SUFFIXES: .ui .hui .qrc

.ui.lo:
$(QTUIC) -o ui_$*.h $<
$(QTMOC) -o moc_$*.cpp $*.h
${LIBTOOL} --tag=CXX --mode=compile ${CXX} -I$(top_srcdir)/src -I../ -I./ ${AM_CPPFLAGS} -c moc_$*.cpp -o $@
rm moc_$*.cpp

.hui.lo:
${QTMOC} -o $*.cpp -I../../ @ATEN_INCLUDES@ $<
${LIBTOOL} --tag=CXX --mode=compile $(CXX) -I$(top_srcdir)/src -I../ -I./ ${AM_CPPFLAGS} -c $*.cpp -o $@
rm $*.cpp

.qrc.lo:
$(QTRCC) -o $*.cpp -name $* $<
${LIBTOOL} --tag=CXX --mode=compile $(CXX) -I$(top_srcdir)/src -I../ -I./ ${AM_CPPFLAGS} -c -o $@ $*.cpp
rm $*.cpp

# Local clean (temporary files generated from rules)
clean-local:
-rm -f chemshelltool.cpp chemshelltool_icons.cpp ui_*

# Py-ChemShell Tool Plugin
chemshelltool_la_SOURCES = chemshelltool_icons.qrc chemshelltooldialog.ui chemshelltooldialog_funcs.cpp chemshelltool_funcs.cpp chemshelltool.hui
chemshelltool_la_LDFLAGS = -module -shared -avoid-version

AM_CPPFLAGS = -I${top_srcdir}/src @ATEN_INCLUDES@ @ATEN_CFLAGS@

noinst_HEADERS = chemshelltooldialog.h

EXTRA_DIST = icon.svg
132 changes: 132 additions & 0 deletions src/plugins/tool_chemshell/chemshelltool.hui
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
*** Py-ChemShell Tool Plugin
*** src/plugins/tool_chemshell/chemshelltool.hui
Copyright T. Youngs 2016-2019
Copyright Y. Lu 2019

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/>.
*/
/*
This plugin was written by You Lu, Aug. 2019
[email protected]
*/

#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 1130512

Please sign in to comment.