This simple example shows how to add a component to the gamess-component package. We choose to add an IntegralEvaluatorFactory component.
package Tutorial version 1.0 { class IntegralComponent implements-all Chemistry.QC.GaussianBasis.IntegralEvaluatorFactoryInterface, gov.cca.Component, gov.cca.Port, gov.cca.ComponentRelease { void print_in_wrapper(in string str); } }
#include <iostream> using namespace std;
Under ”protected” section, add variable declarations
gov::cca::Services services_;
gamess_print_(str.c_str(),strlen(str.c_str()));
Implement ”setServices” method
services_ = services; if (services_._is_nil()) return; gov::cca::TypeMap tm = services.createTypeMap(); if(tm._is_nil()) { fprintf(stderr, "Error:: %s:%d: gov::cca::TypeMap is nil\n", __FILE__, __LINE__); exit(1); } gov::cca::Port p = (*this); // Babel required casting if(p._is_nil()) { fprintf(stderr, "Error:: %s:%d: Error casting (*this) to gov::cca::Port \n", __FILE__, __LINE__); exit(1); } /* * setup provides port */ try { services_.addProvidesPort(p, "IntegralEvaluatorFactoryInterface", "Chemistry.QC.GaussianBasis.IntegralEvaluatorFactoryInterface", tm); // Babel required casting gov::cca::ComponentRelease cr = ::babel_cast< gov::cca::ComponentRelease >(*this); services_.registerForRelease(cr); } catch (gov::cca::CCAException e) { cout << "Error in setting up provides port - IntegralEvaluatorFactory!" << endl; cout << e.getNote() << endl; } return;
Edit ”releaseServices” method
services.removeProvidesPort("IntegralEvaluatorFactoryInterface");
subroutine gamess_print(str) character str*(*) print *,"printing in GAMESS wrapper function ----" print *,str end
Edit ”legacy/gamess/Makefile” by adding ”test” into ”OBJS” list.
#ifdef __cplusplus extern "C" { #endif void gamess_print_(const char* str,int len); #ifdef __cplusplus } #endif
Insert the include header to ”components/Tutorial/cxx/Tutorial_IntegralComponent_Impl.cxx”
#include "test.fh"
class MyDriver implements-all gov.cca.Component, gov.cca.ports.GoPort, gov.cca.ComponentRelease {}
#include "Chemistry_QC_ModelFactoryInterface.hxx" #include "Chemistry_QC_ModelInterface.hxx" #include "Tutorial_IntegralComponent.hxx" #include <iostream> using namespace std;
and adding variables under ”protected” section
Chemistry::QC::ModelFactoryInterface model_factory_; Chemistry::QC::ModelInterface model_; Chemistry::QC::GaussianBasis::IntegralEvaluatorFactoryInterface eval_factory_; gov::cca::Services services_; gov::cca::TypeMap tm_;
services_ = services; if (services_._is_nil()) { cout << "services is nill in GAMESS_Integral Driver::setServices" << endl; return; } tm_ = services.createTypeMap(); if(tm_._is_nil()) { fprintf(stderr, "Error:: %s:%d: gov::cca::TypeMap is nil\n", __FILE__, __LINE__); exit(1); } gov::cca::Port p = (*this); // Babel required casting if(p._is_nil()) { fprintf(stderr, "Error:: %s:%d: Error casting (*this) to gov::cca::Port \n", __FILE__, __LINE__); exit(1); } /* * setup uses/provides port */ try { services_.addProvidesPort(p, "go","gov.cca.ports.GoPort",tm_); services_.registerUsesPort("ModelFactoryInterface", "Chemistry.QC.ModelFactoryInterface",0); services_.registerUsesPort("IntegralEvaluatorFactoryInterface", "Chemistry.QC.GaussianBasis.IntegralEvaluatorFactoryInterface", 0); // Babel required casting gov::cca::ComponentRelease cr = ::babel_cast< gov::cca::ComponentRelease >(*this); services_.registerForRelease(cr); } catch (gov::cca::CCAException e) { cout << "MyDriver: error in setting up ports - " << e.getNote() << endl; }
Implement releaseServices method as the follows:
services.removeProvidesPort("go"); services.unregisterUsesPort("ModelFactoryInterface"); services.unregisterUsesPort("IntegralEvaluatorFactoryInterface");
Implement go method as the follows:
model_factory_ = babel_cast<Chemistry::QC::ModelFactoryInterface>(services_.getPort("ModelFactoryInterface")); if (model_factory_._is_nil()) { cout << "Cannot get the model factory!" << endl; abort(); } model_ = model_factory_.get_model(); if (model_._is_nil()) { cout << "Cannot get model" << endl; abort(); } eval_factory_ = babel_cast<Chemistry::QC::GaussianBasis::IntegralEvaluatorFactoryInterface> (services_.getPort("IntegralEvaluatorFactoryInterface")); if (eval_factory_._is_nil()) { cout << "Cannot get integral evaluator factory" << endl; abort(); } Tutorial::IntegralComponent test_component = babel_cast<Tutorial::IntegralComponent>(eval_factory_); cout << "begin to test IntegralComponent.print_in_wrapper()" << endl; test_component.print_in_wrapper("calling print_in_wrapper from CCA"); services_.releasePort("ModelFactoryInterface"); services_.releasePort("IntegralEvaluatorFactoryInterface");
#!ccaffeine bootstrap file. # ------- don't change anything ABOVE this line.------------- path set /the-path-to-gamess-component-$VERSION-source/shared path append /the-path-to-prefix-of-cca-chem-generic2/lib repository get-global drivers.MyDriver repository get-global Chemistry.MoleculeFactory repository get-global GAMESS.ModelFactory repository get-global Tutorial.IntegralComponent instantiate drivers.MyDriver driver instantiate Chemistry.MoleculeFactory molecule instantiate GAMESS.ModelFactory model instantiate Tutorial.IntegralComponent integral connect driver ModelFactoryInterface model ModelFactoryInterface connect model MoleculeFactoryInterface molecule MoleculeFactoryInterface connect driver IntegralEvaluatorFactoryInterface integral IntegralEvaluatorFactoryInterface parameter model CONFIG scratchParam /the-path-to-scratch-directory parameter model CONFIG theoryParam RHF parameter model CONFIG coordParam /the-path-to-gamess-component-$VERSION-source/components/examples/h2o.xyz parameter model CONFIG basisSetParam STO-3 go driver go disconnect driver ModelFactoryInterface model ModelFactoryInterface disconnect model MoleculeFactoryInterface molecule MoleculeFactoryInterface remove model remove driver remove integral remove molecule quit
Do ”./rungms exam01 my_rc” for testing.
... begin to test IntegralComponent.print_in_wrapper() printing in GAMESS wrapper function ---- calling print_in_wrapper from CCA ##specific go command successful ...
If you want to add an option for user to specify, such as ”–with-mypath”, the follow steps may be helpful.
AC_ARG_WITH(mypath, [ --with-mypath set mypath], [MY_PATH=$withval] ) AC_SUBST(MY_PATH)
in the file ”configure.in”.