Changeset f31edc for src/Parser


Ignore:
Timestamp:
Feb 7, 2011, 10:27:23 AM (14 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
aa8ef2
Parents:
bb74ba
git-author:
Frederik Heber <heber@…> (02/01/11 16:39:55)
git-committer:
Frederik Heber <heber@…> (02/07/11 10:27:23)
Message:

Extended MpqcParser to write config files for all possible theory levels: CLHF, CLKS, MBPT2, MBPT2_R12.

  • ParserMpqcUnitTest tests all four cases now and each contained string with the config file has been tested to work with mpqc-3.0.0-alpha.
Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/MpqcParser.cpp

    rbb74ba rf31edc  
    3535 *
    3636 */
    37 MpqcParser::MpqcParser() : HessianPresent(false)
     37MpqcParser::MpqcParser() :
     38  HessianPresent(false),
     39  theory(MBPT2)
    3840{}
    3941
     
    5355}
    5456
    55 /**
    56  * Saves the \a atoms into as a MPQC file.
    57  *
    58  * \param file where to save the state
     57/** Saves all atoms and data into a MPQC config file.
     58 * \param *file output stream
    5959 * \param atoms atoms to store
    6060 */
    6161void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms)
    62 {
    63   DoLog(0) && (Log() << Verbose(0) << "Saving changes to MPQC ." << std::endl);
    64 
    65   if (HessianPresent)
    66     saveHessian(file, atoms);
    67   else
    68     saveSimple(file, atoms);
    69 }
    70 
    71 /** Saves all atoms and data into a MPQC config file without hessian.
    72  * \param *file output stream
    73  * \param atoms atoms to store
    74  */
    75 void MpqcParser::saveSimple(ostream *file, const std::vector<atom *> &atoms)
    7662{
    7763  Vector center;
     
    9177    *file << "\tsavestate = no" << endl;
    9278    *file << "\tdo_gradient = yes" << endl;
    93     *file << "\tmole<MBPT2>: (" << endl;
    94     *file << "\t\tbasis = $:basis" << endl;
    95     *file << "\t\tmolecule = $:molecule" << endl;
    96     *file << "\t\treference<CLHF>: (" << endl;
    97     *file << "\t\t\tmaxiter = 1000" << endl;
    98     *file << "\t\t\tbasis = $:basis" << endl;
    99     *file << "\t\t\tmolecule = $:molecule" << endl;
    100     *file << "\t\t)" << endl;
    101     *file << "\t)" << endl;
     79    if (HessianPresent) {
     80      *file << "\tfreq<MolecularFrequencies>: (" << endl;
     81      *file << "\t\tmolecule=$:molecule" << endl;
     82      *file << "\t)" << endl;
     83    }
     84    switch (theory) {
     85      case CLHF:
     86        *file << "\tmole<CLHF>: (" << endl;
     87        *file << "\t\tmolecule = $:molecule" << endl;
     88        *file << "\t\tbasis = $:basis" << endl;
     89        *file << "\t\tmemory = 16000000" << endl;
     90        *file << "\t)" << endl;
     91        break;
     92      case CLKS:
     93        *file << "\tmole<CLKS>: (" << endl;
     94        *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
     95        *file << "\t\tmolecule = $:molecule" << endl;
     96        *file << "\t\tbasis = $:basis" << endl;
     97        *file << "\t\tmemory = 16000000" << endl;
     98        *file << "\t)" << endl;
     99        break;
     100      case MBPT2:
     101        *file << "\tmole<MBPT2>: (" << endl;
     102        *file << "\t\tbasis = $:basis" << endl;
     103        *file << "\t\tmolecule = $:molecule" << endl;
     104        *file << "\t\treference<CLHF>: (" << endl;
     105        *file << "\t\t\tmaxiter = 1000" << endl;
     106        *file << "\t\t\tbasis = $:basis" << endl;
     107        *file << "\t\t\tmolecule = $:molecule" << endl;
     108        *file << "\t\t)" << endl;
     109        *file << "\t)" << endl;
     110        break;
     111      case MBPT2_R12:
     112        *file << "\tmole<MBPT2_R12>: (" << endl;
     113        *file << "\t\tmolecule = $:molecule" << endl;
     114        *file << "\t\tbasis = $:basis" << endl;
     115        *file << "\t\taux_basis = $:abasis" << endl;
     116        *file << "\t\tstdapprox = \"A'\"" << endl;
     117        *file << "\t\tnfzc = 1" << endl;
     118        *file << "\t\tmemory = 16000000" << endl;
     119        *file << "\t\tintegrals<IntegralCints>:()" << endl;
     120        *file << "\t\treference<CLHF>: (" << endl;
     121        *file << "\t\t\tmolecule = $:molecule" << endl;
     122        *file << "\t\t\tbasis = $:basis" << endl;
     123        *file << "\t\t\tmaxiter = 1000" << endl;
     124        *file << "\t\t\tmemory = 16000000" << endl;
     125        *file << "\t\t\tintegrals<IntegralCints>:()" << endl;
     126        *file << "\t\t)" << endl;
     127        *file << "\t)" << endl;
     128        break;
     129      default:
     130        DoeLog(0) && (eLog() << Verbose(0)
     131            << "Unknown level of theory requested for MPQC output file." << std::endl);
     132        break;
     133    }
    102134    *file << ")" << endl;
    103135    *file << "molecule<Molecule>: (" << endl;
     
    114146    *file << "\tmolecule = $:molecule" << endl;
    115147    *file << ")" << endl;
    116   }
    117 }
    118 
    119 /** Saves all atoms and data into a MPQC config file with hessian.
    120  * \param *file output stream
    121  * \param atoms atoms to store
    122  */
    123 void MpqcParser::saveHessian(ostream *file, const std::vector<atom *> &atoms)
    124 {
    125   Vector center;
    126   vector<atom *> allatoms = World::getInstance().getAllAtoms();
    127 
    128   // calculate center
    129   for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
    130     center += (*runner)->getPosition();
    131   center.Scale(1./allatoms.size());
    132 
    133   // with hessian
    134   if (file->fail()) {
    135     DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl);
    136   } else {
    137     *file << "% Created by MoleCuilder" << endl;
    138     *file << "mpqc: (" << endl;
    139     *file << "\tsavestate = no" << endl;
    140     *file << "\tdo_gradient = yes" << endl;
    141     *file << "\tmole<CLHF>: (" << endl;
    142     *file << "\t\tmaxiter = 200" << endl;
    143     *file << "\t\tbasis = $:basis" << endl;
    144     *file << "\t\tmolecule = $:molecule" << endl;
    145     *file << "\t)" << endl;
    146     *file << "\tfreq<MolecularFrequencies>: (" << endl;
    147     *file << "\t\tmolecule=$:molecule" << endl;
    148     *file << "\t)" << endl;
    149     *file << ")" << endl;
    150     *file << "molecule<Molecule>: (" << endl;
    151     *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
    152     *file << "\t{ atoms geometry } = {" << endl;
    153     // output of atoms
    154     for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
    155       (*AtomRunner)->OutputMPQCLine(file, &center);
     148    if (theory == MBPT2_R12) {
     149      *file << "% auxiliary basis set specification" << endl;
     150      *file << "\tabasis<GaussianBasisSet>: (" << endl;
     151      *file << "\tname = \"aug-cc-pVDZ\"" << endl;
     152      *file << "\tmolecule = $:molecule" << endl;
     153      *file << ")" << endl;
    156154    }
    157     *file << "\t}" << endl;
    158     *file << ")" << endl;
    159     *file << "basis<GaussianBasisSet>: (" << endl;
    160     *file << "\tname = \"" << World::getInstance().getConfig()->basis << "\"" << endl;
    161     *file << "\tmolecule = $:molecule" << endl;
    162     *file << ")" << endl;
    163155  }
    164156}
     
    171163  HessianPresent = hessian;
    172164}
     165
     166/** Sets the desired level of solving theory to use
     167 * \param _theory shorthand of the theory
     168 */
     169void MpqcParser::setTheory(enum Theory _theory)
     170{
     171  theory = _theory;
     172}
  • src/Parser/MpqcParser.hpp

    rbb74ba rf31edc  
    2525{
    2626public:
     27
     28  enum Theory { CLHF, CLKS, MBPT2, MBPT2_R12, unknown };
     29
    2730  MpqcParser();
    2831  ~MpqcParser();
     
    3134
    3235  void setHessian(bool hessian);
     36  void setTheory(enum Theory _theory);
    3337
    3438private:
    3539  // whether output with computing hessian is desired.
    3640  bool HessianPresent;
     41  enum Theory theory;
    3742
    3843  void saveSimple(std::ostream *file, const std::vector<atom *> &atoms);
  • src/Parser/unittests/ParserMpqcUnitTest.cpp

    rbb74ba rf31edc  
    4040CPPUNIT_TEST_SUITE_REGISTRATION( ParserMpqcUnitTest );
    4141
    42 static string waterMpqc ="% Created by MoleCuilder\n\
     42static string waterMpqc_CLHF ="% Created by MoleCuilder\n\
     43mpqc: (\n\
     44\tsavestate = no\n\
     45\tdo_gradient = yes\n\
     46\tmole<CLHF>: (\n\
     47\t\tmolecule = $:molecule\n\
     48\t\tbasis = $:basis\n\
     49\t\tmemory = 16000000\n\
     50\t)\n\
     51)\n\
     52molecule<Molecule>: (\n\
     53\tunit = angstrom\n\
     54\t{ atoms geometry } = {\n\
     55\t\tO [ -0.505735\t0\t0 ]\n\
     56\t\tH [ 0.252867\t0\t0.504284 ]\n\
     57\t\tH [ 0.252867\t0\t-0.504284 ]\n\
     58\t}\n\
     59)\n\
     60basis<GaussianBasisSet>: (\n\
     61\tname = \"3-21G\"\n\
     62\tmolecule = $:molecule\n\
     63)\n"; // tested with mpqc 3.0.0-alpha
     64static string waterMpqc_CLKS ="% Created by MoleCuilder\n\
     65mpqc: (\n\
     66\tsavestate = no\n\
     67\tdo_gradient = yes\n\
     68\tmole<CLKS>: (\n\
     69\t\tfunctional<StdDenFunctional>:(name=B3LYP)\n\
     70\t\tmolecule = $:molecule\n\
     71\t\tbasis = $:basis\n\
     72\t\tmemory = 16000000\n\
     73\t)\n\
     74)\n\
     75molecule<Molecule>: (\n\
     76\tunit = angstrom\n\
     77\t{ atoms geometry } = {\n\
     78\t\tO [ -0.505735\t0\t0 ]\n\
     79\t\tH [ 0.252867\t0\t0.504284 ]\n\
     80\t\tH [ 0.252867\t0\t-0.504284 ]\n\
     81\t}\n\
     82)\n\
     83basis<GaussianBasisSet>: (\n\
     84\tname = \"3-21G\"\n\
     85\tmolecule = $:molecule\n\
     86)\n"; // tested with mpqc 3.0.0-alpha
     87static string waterMpqc_MBPT2 ="% Created by MoleCuilder\n\
    4388mpqc: (\n\
    4489\tsavestate = no\n\
     
    65110\tname = \"3-21G\"\n\
    66111\tmolecule = $:molecule\n\
    67 )\n";
     112)\n"; // tested with mpqc 3.0.0-alpha
     113static string waterMpqc_MBPT2_R12 ="% Created by MoleCuilder\n\
     114mpqc: (\n\
     115\tsavestate = no\n\
     116\tdo_gradient = yes\n\
     117\tmole<MBPT2_R12>: (\n\
     118\t\tmolecule = $:molecule\n\
     119\t\tbasis = $:basis\n\
     120\t\taux_basis = $:abasis\n\
     121\t\tstdapprox = \"A'\"\n\
     122\t\tnfzc = 1\n\
     123\t\tmemory = 16000000\n\
     124\t\tintegrals<IntegralCints>:()\n\
     125\t\treference<CLHF>: (\n\
     126\t\t\tmolecule = $:molecule\n\
     127\t\t\tbasis = $:basis\n\
     128\t\t\tmaxiter = 1000\n\
     129\t\t\tmemory = 16000000\n\
     130\t\t\tintegrals<IntegralCints>:()\n\
     131\t\t)\n\
     132\t)\n\
     133)\n\
     134molecule<Molecule>: (\n\
     135\tunit = angstrom\n\
     136\t{ atoms geometry } = {\n\
     137\t\tO [ -0.505735\t0\t0 ]\n\
     138\t\tH [ 0.252867\t0\t0.504284 ]\n\
     139\t\tH [ 0.252867\t0\t-0.504284 ]\n\
     140\t}\n\
     141)\n\
     142basis<GaussianBasisSet>: (\n\
     143\tname = \"3-21G\"\n\
     144\tmolecule = $:molecule\n\
     145)\n\
     146% auxiliary basis set specification\n\
     147\tabasis<GaussianBasisSet>: (\n\
     148\tname = \"aug-cc-pVDZ\"\n\
     149\tmolecule = $:molecule\n\
     150)\n"; // basically tested with mpqc 3.0.0-alpha (no parse errors but did not calculate due to missing code)
    68151
    69152void ParserMpqcUnitTest::setUp() {
     
    86169void ParserMpqcUnitTest::writeMpqcTest() {
    87170  // build up water molecule
     171  string first;
     172  string second;
    88173  atom *Walker = NULL;
    89174  Walker = World::getInstance().createAtom();
     
    99184
    100185  // create two stringstreams, one stored, one created
    101   stringstream input(waterMpqc);
     186
    102187  MpqcParser* testParser = new MpqcParser();
    103   stringstream output;
    104188  std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    105   testParser->save(&output, atoms);
    106 
    107   // compare both configs
    108   string first = input.str();
    109   string second = output.str();
    110   CPPUNIT_ASSERT(first == second);
     189  {
     190    // compare both configs for CLHF
     191    stringstream output;
     192    testParser->setTheory(MpqcParser::CLHF);
     193    testParser->save(&output, atoms);
     194    stringstream input(waterMpqc_CLHF);
     195    for (; std::getline(input, first) && std::getline(output, second); ) {
     196      //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
     197      CPPUNIT_ASSERT(first == second);
     198    }
     199  }
     200  {
     201    // compare both configs for CLKS
     202    stringstream output;
     203    testParser->setTheory(MpqcParser::CLKS);
     204    testParser->save(&output, atoms);
     205    stringstream input(waterMpqc_CLKS);
     206    for (; std::getline(input, first) && std::getline(output, second); ) {
     207      //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
     208      CPPUNIT_ASSERT(first == second);
     209    }
     210  }
     211  {
     212    // compare both configs for MBPT2
     213    stringstream output;
     214    testParser->setTheory(MpqcParser::MBPT2);
     215    testParser->save(&output, atoms);
     216    stringstream input(waterMpqc_MBPT2);
     217    for (; std::getline(input, first) && std::getline(output, second); ) {
     218      //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
     219      CPPUNIT_ASSERT(first == second);
     220    }
     221  }
     222  {
     223    // compare both configs for MBPT2_R12
     224    stringstream output;
     225    testParser->setTheory(MpqcParser::MBPT2_R12);
     226    testParser->save(&output, atoms);
     227    stringstream input(waterMpqc_MBPT2_R12);
     228    for (; std::getline(input, first) && std::getline(output, second); ) {
     229      //std::cout << "Comparing '" << first << "' to '" << second << "'" << std::endl;
     230      CPPUNIT_ASSERT(first == second);
     231    }
     232  }
    111233}
Note: See TracChangeset for help on using the changeset viewer.