Ignore:
Timestamp:
Oct 14, 2011, 3:15:30 PM (13 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:
d3d6c6
Parents:
9a6b76e
git-author:
Frederik Heber <heber@…> (09/27/11 19:04:36)
git-committer:
Frederik Heber <heber@…> (10/14/11 15:15:30)
Message:

Huge Refactoring of FormatParserStorage and all FormatParser's.

FormatParser:

FormatParserStorage:

  • We construct all lookup tables and alikes via boost preprocessor magic from a list of all available parser (enums).
  • we use the templated getParser() and addParser() functions to serve parsers to the outside. Instances are as usual created only once.

Tests:

  • tests only had to be changed because of the "renaming" of the Parsers.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/unittests/ParserMpqcUnitTest.cpp

    r9a6b76e r765f16  
    3232#include "Descriptors/AtomTypeDescriptor.hpp"
    3333#include "CodePatterns/Assert.hpp"
     34#include "Parser/ChangeTracker.hpp"
     35#include "Parser/MpqcParser.hpp"
    3436
    3537#ifdef HAVE_TESTRUNNER
     
    157159
    158160void ParserMpqcUnitTest::setUp() {
    159   mpqc = new MpqcParser();
     161  parser = new FormatParser<mpqc>();
    160162
    161163  World::getInstance();
     
    169171
    170172void ParserMpqcUnitTest::tearDown() {
    171   delete mpqc;
     173  delete parser;
    172174  ChangeTracker::purgeInstance();
    173175  World::purgeInstance();
     
    178180void ParserMpqcUnitTest::ParameterTypeTest() {
    179181  // check types in boost::any map
    180   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));
    181   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int));
    182   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));
    183   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));
    184   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));
    185   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int));
    186   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));
    187   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));
    188   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));
    189   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));
    190   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));
    191   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));
     182  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));
     183  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int));
     184  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));
     185  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));
     186  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));
     187  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int));
     188  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));
     189  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));
     190  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));
     191  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));
     192  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));
     193  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));
    192194}
    193195
    194196void ParserMpqcUnitTest::ParameterDefaultTest() {
    195197  // check default values
    196   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "no");
    197   CPPUNIT_ASSERT(!mpqc->getParams().getBool(MpqcParser_Parameters::hessianParam));
    198   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::savestateParam) == "no");
    199   CPPUNIT_ASSERT(!mpqc->getParams().getBool(MpqcParser_Parameters::savestateParam));
    200   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes");
    201   CPPUNIT_ASSERT(mpqc->getParams().getBool(MpqcParser_Parameters::do_gradientParam));
    202   CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000);
    203   CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000);
    204   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'");
    205   CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1);
    206   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G");
    207   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ");
    208   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints");
    209   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    210   CPPUNIT_ASSERT(mpqc->getParams().getTheory() == MpqcParser_Parameters::MBPT2);
    211   CPPUNIT_ASSERT(mpqc->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints);
     198  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "no");
     199  CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::hessianParam));
     200  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::savestateParam) == "no");
     201  CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::savestateParam));
     202  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes");
     203  CPPUNIT_ASSERT(parser->getParams().getBool(MpqcParser_Parameters::do_gradientParam));
     204  CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000);
     205  CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000);
     206  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'");
     207  CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1);
     208  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G");
     209  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ");
     210  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints");
     211  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     212  CPPUNIT_ASSERT(parser->getParams().getTheory() == MpqcParser_Parameters::MBPT2);
     213  CPPUNIT_ASSERT(parser->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints);
    212214
    213215  // check that values are not removed
    214   CPPUNIT_ASSERT(!mpqc->getParams().params[MpqcParser_Parameters::theoryParam].empty());
     216  CPPUNIT_ASSERT(!parser->getParams().params[MpqcParser_Parameters::theoryParam].empty());
    215217
    216218  // check throw, for the moment aren't, are caught in getInt()
    217   CPPUNIT_ASSERT_THROW(mpqc->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);
    218   CPPUNIT_ASSERT_THROW(mpqc->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);
     219  CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);
     220  CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);
    219221
    220222}
    221223
    222224void ParserMpqcUnitTest::ParameterCloneTest() {
    223   FormatParser_Parameters *clone = mpqc->getParams().clone();
    224   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     225  FormatParser_Parameters *clone = parser->getParams().clone();
     226  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    225227  std::stringstream setvalue("theory = CLHF");
    226   setvalue >> mpqc->getParams();
    227   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
    228   mpqc->getParams().makeClone(*clone);
    229   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     228  setvalue >> parser->getParams();
     229  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
     230  parser->getParams().makeClone(*clone);
     231  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    230232}
    231233
     
    234236  {
    235237    std::stringstream setvalue("theory = CLHF");
    236     setvalue >> mpqc->getParams();
     238    setvalue >> parser->getParams();
    237239//    std::cout << "integration method is "
    238 //        << mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
    239     CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
     240//        << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
     241    CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
    240242  }
    241243  // test a bool
    242244  {
    243245    std::stringstream setvalue("Hessian = yes");
    244     setvalue >> mpqc->getParams();
     246    setvalue >> parser->getParams();
    245247//    std::cout << "Hessian is "
    246 //        << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
    247     CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
     248//        << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
     249    CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
    248250  }
    249251  // test int
    250252  {
    251253    std::stringstream setvalue("maxiter = 500");
    252     setvalue >> mpqc->getParams();
     254    setvalue >> parser->getParams();
    253255//    std::cout << "maxiter is "
    254 //        << mpqc->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
    255     CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);
     256//        << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
     257    CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);
    256258  }
    257259  // test whether unknown key fails
     
    261263#ifndef NDEBUG
    262264    ASSERT_DO(Assert::Throw);
    263     CPPUNIT_ASSERT_THROW(setvalue >> mpqc->getParams(), Assert::AssertionFailure);
     265    CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
    264266#else
    265     setvalue >> mpqc->getParams();
     267    setvalue >> parser->getParams();
    266268#endif
    267269//    std::cout << "Hessian is still "
    268 //        << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
    269     CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
     270//        << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
     271    CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
    270272  }
    271273}
     
    273275void ParserMpqcUnitTest::readMpqcTest() {
    274276  stringstream input(waterMpqc_CLHF);
    275   mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);
    276   mpqc->load(&input);
     277  parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
     278  parser->load(&input);
    277279
    278280  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
     
    301303    // compare both configs for CLHF
    302304    stringstream output;
    303     mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);
    304     mpqc->save(&output, atoms);
     305    parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
     306    parser->save(&output, atoms);
    305307    stringstream input(waterMpqc_CLHF);
    306308    for (; std::getline(input, first) && std::getline(output, second); ) {
     
    312314    // compare both configs for CLKS
    313315    stringstream output;
    314     mpqc->getParams().setTheory(MpqcParser_Parameters::CLKS);
    315     mpqc->save(&output, atoms);
     316    parser->getParams().setTheory(MpqcParser_Parameters::CLKS);
     317    parser->save(&output, atoms);
    316318    stringstream input(waterMpqc_CLKS);
    317319    for (; std::getline(input, first) && std::getline(output, second); ) {
     
    323325    // compare both configs for MBPT2
    324326    stringstream output;
    325     mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2);
    326     mpqc->save(&output, atoms);
     327    parser->getParams().setTheory(MpqcParser_Parameters::MBPT2);
     328    parser->save(&output, atoms);
    327329    stringstream input(waterMpqc_MBPT2);
    328330    for (; std::getline(input, first) && std::getline(output, second); ) {
     
    334336    // compare both configs for MBPT2_R12
    335337    stringstream output;
    336     mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12);
    337     mpqc->save(&output, atoms);
     338    parser->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12);
     339    parser->save(&output, atoms);
    338340    stringstream input(waterMpqc_MBPT2_R12);
    339341    for (; std::getline(input, first) && std::getline(output, second); ) {
Note: See TracChangeset for help on using the changeset viewer.