Next: , Previous: The Structure of GAMESS CCA Components, Up: Top



7 Code Example

7.1 An Example of Creating a New Component

This simple example shows how to add a component to the gamess-component package. We choose to add an IntegralEvaluatorFactory component.

  1. configure and compile gamess-component-$VERSION package.

  2. create a sidl file ”test.sidl” under components/sidl and copy it to ports/sidl
              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);
                }
              }
         

  3. add ”sidl/test.sidl” to ”SIDL_FILES” list and ”Tutorial.IntegralComponent-cxx” to ”COMPONENTS” list in components/MakeIncl.components

  4. Generating Babel Server Code by run ”make .Tutorial.IntegralComponent-cxx” under components directory.

  5. Edit ”components/Tutorial/cxx/Tutorial_IntegralComponent_Impl.hxx” Insert headers
              #include <iostream>
              using namespace std;
         

    Under ”protected” section, add variable declarations

              gov::cca::Services                  services_;
         

  6. Edit ”Tutorial_IntegralComponent_Impl.cxx” Implement ”print_in_wrapper” method
              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");
         

  7. Create ”legacy/gamess/wrapper/test.src”, and edit
                    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.

  8. Add function header Create legacy/gamess/include/test.fh
              #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"
         

  9. Do ”make” under components directory and do ”make clean;make” under legacy/gamess directories

  10. Create a driver component Do ”make” under components/drivers/cxx and do ”make clean;make” under shared directory.
  11. Test the newly added components. Under components/examples directory, create a RC file ”my_rc”. Substitue ”the-path-to-gamess-component-$VERSION” with real path to shared directory; substitute ”the-path-to-cca-chem-generic2” with the prefix of cca-chem-generic2; substitute ”the-path-scratch-directory” with the path to GAMESS scratch directory.
              #!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.

  12. Sample output
              ...
              begin to test IntegralComponent.print_in_wrapper()
              printing in GAMESS wrapper function ----
              calling print_in_wrapper from CCA
              ##specific go command successful
              ...
         

7.2 An Simple Example of Adding a New Option

If you want to add an option for user to specify, such as ”–with-mypath”, the follow steps may be helpful.

  1. add
              AC_ARG_WITH(mypath,
              [  --with-mypath     set mypath],
              [MY_PATH=$withval]
              )
              AC_SUBST(MY_PATH)
         

    in the file ”configure.in”.

  2. type ”autoconf” in the command line.
  3. add ”–with-mypath=the-path-you-want-to-add” to your configuration
  4. edit ”MakeIncl.user.in” to add ”mypath=@MY_PATH@”.
  5. use ”$mypath” in the makefiles with ”MakeIncl.user” included.