Changeset ee50c1 for src/Parser


Ignore:
Timestamp:
Oct 17, 2011, 4:56:36 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:
1bef07
Parents:
89a67f
git-author:
Frederik Heber <heber@…> (09/30/11 16:20:34)
git-committer:
Frederik Heber <heber@…> (10/17/11 16:56:36)
Message:

Complete rewrite of MpqcParser_Parameters to incorporate new Parameter(Storage) structure.

  • FormatParser_Parameters now contains a ParameterStorage instance which contains all parameters and is easy to clone.
  • MpqcParser_Parameters is basically just an Init() function that fills this storage for the specific case of the FormatParser<mpqc>.
  • additionally, there are some convenience functions, enums and maps which contains strings and make setting and getting parameters more easy.
  • adapted MpqcParser.
  • adapted Unit test for MpqcParser accordingly:
    • no more tests on type
  • TESTFIX: regression test Parser/Mpqc/post/empty.in was CLHF instead of default MBPT2. As the cloning is now working flawlessly, this has been fixed.
Location:
src/Parser
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/FormatParser_Parameters.hpp

    r89a67f ree50c1  
    1616#include "CodePatterns/Clone.hpp"
    1717
     18#include "Parser/Parameters/ParameterStorage.hpp"
     19
     20class Parameter;
     21
    1822/** This class is an interface to the internal parameters of any FormatParser.
    1923 *
     
    2428{
    2529public:
    26   FormatParser_Parameters() {}
    27   ~FormatParser_Parameters() {}
     30  FormatParser_Parameters();
     31  FormatParser_Parameters(const FormatParser_Parameters &_parameters);
     32  ~FormatParser_Parameters();
    2833
    29   /** Makes this instance a clone of given \a _instance.
    30    *
    31    * @param _instance instance to clone
    32    */
    33   virtual void makeClone(const FormatParser_Parameters & _instance)=0;
     34  // cloning
     35  FormatParser_Parameters* clone() const;
     36  void makeClone(const FormatParser_Parameters &_instance);
     37
     38  // accessing parameters in storage
     39  void appendParameter(Parameter *instance);
     40  bool haveParameter(const std::string &_name) const;
     41  Parameter *getParameter(const std::string &_name) const;
     42
     43protected:
     44  ParameterStorage *storage;
    3445};
    3546
  • src/Parser/Makefile.am

    r89a67f ree50c1  
    66  Parser/ChangeTracker.cpp \
    77  Parser/FormatParser_common.cpp \
     8  Parser/FormatParser_Parameters.cpp \
    89  Parser/FormatParserStorage.cpp \
    910  Parser/MpqcParser.cpp \
     
    4243  Parser/XyzParser.hpp
    4344
    44 PARSERPARAMETERSSOURCE =
     45PARSERPARAMETERSSOURCE = \
     46        Parser/Parameters/ParameterStorage.cpp \
     47        Parser/Parameters/StringParameter.cpp
    4548
    4649PARSERPARAMETERSHEADER = \
    47   Parser/Parameters/ContinuousValue.hpp \
    48   Parser/Parameters/ContinuousValue_impl.hpp \
    49   Parser/Parameters/DiscreteValue.hpp \
    50   Parser/Parameters/DiscreteValue_impl.hpp \
    51   Parser/Parameters/ValueInterface.hpp
     50        Parser/Parameters/ParameterStorage.hpp \
     51        Parser/Parameters/ContinuousParameter.hpp \
     52        Parser/Parameters/ContinuousParameter_impl.hpp \
     53        Parser/Parameters/ContinuousValue.hpp \
     54        Parser/Parameters/ContinuousValue_impl.hpp \
     55        Parser/Parameters/DiscreteParameter.hpp \
     56        Parser/Parameters/DiscreteParameter_impl.hpp \
     57        Parser/Parameters/DiscreteValue.hpp \
     58        Parser/Parameters/DiscreteValue_impl.hpp \
     59        Parser/Parameters/Parameter.hpp \
     60        Parser/Parameters/StringParameter.hpp \
     61        Parser/Parameters/ValueInterface.hpp
    5262
    5363noinst_LTLIBRARIES += libMolecuilderParser.la
  • src/Parser/MpqcParser.cpp

    r89a67f ree50c1  
    4242const std::string FormatParserTrait<mpqc>::suffix = "in";
    4343const ParserTypes FormatParserTrait<mpqc>::type = mpqc;
     44
     45// a converter we often need
     46ConvertTo<bool> FormatParser<mpqc>::Converter;
    4447
    4548/** Constructor of MpqcParser.
     
    148151        std::string key;
    149152        whitespacefilter >> ws >> key;
    150         if (getParams().haveParam(key)) {
     153        if (getParams().haveParameter(key)) {
    151154          std::stringstream linestream(linestring);
    152155          linestream >> getParams();
     
    233236    *file << "% Created by MoleCuilder" << endl;
    234237    *file << "mpqc: (" << endl;
    235     *file << "\tsavestate = " << getParams().getString(MpqcParser_Parameters::savestateParam) << endl;
    236     *file << "\tdo_gradient = " << getParams().getString(MpqcParser_Parameters::do_gradientParam) << endl;
    237     if (getParams().getBool(MpqcParser_Parameters::hessianParam)) {
     238    *file << "\tsavestate = " << getParams().getParameter(MpqcParser_Parameters::savestateParam) << endl;
     239    *file << "\tdo_gradient = " << getParams().getParameter(MpqcParser_Parameters::do_gradientParam) << endl;
     240    if (Converter(getParams().getParameter(MpqcParser_Parameters::hessianParam))) {
    238241      *file << "\tfreq<MolecularFrequencies>: (" << endl;
    239242      *file << "\t\tmolecule=$:molecule" << endl;
    240243      *file << "\t)" << endl;
    241244    }
    242     switch (getParams().getTheory()) {
    243       case MpqcParser_Parameters::CLHF:
    244         *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    245         *file << "\t\tmolecule = $:molecule" << endl;
    246         *file << "\t\tbasis = $:basis" << endl;
    247         *file << "\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl;
    248         *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
    249         *file << "\t)" << endl;
    250         break;
    251       case MpqcParser_Parameters::CLKS:
    252         *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    253         *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
    254         *file << "\t\tmolecule = $:molecule" << endl;
    255         *file << "\t\tbasis = $:basis" << endl;
    256         *file << "\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl;
    257         *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
    258         *file << "\t)" << endl;
    259         break;
    260       case MpqcParser_Parameters::MBPT2:
    261         *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    262         *file << "\t\tbasis = $:basis" << endl;
    263         *file << "\t\tmolecule = $:molecule" << endl;
    264         *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
    265         *file << "\t\treference<CLHF>: (" << endl;
    266         *file << "\t\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl;
    267         *file << "\t\t\tbasis = $:basis" << endl;
    268         *file << "\t\t\tmolecule = $:molecule" << endl;
    269         *file << "\t\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
    270         *file << "\t\t)" << endl;
    271         *file << "\t)" << endl;
    272         break;
    273       case MpqcParser_Parameters::MBPT2_R12:
    274         *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    275         *file << "\t\tmolecule = $:molecule" << endl;
    276         *file << "\t\tbasis = $:basis" << endl;
    277         *file << "\t\taux_basis = $:abasis" << endl;
    278         *file << "\t\tstdapprox = \"" << getParams().getString(MpqcParser_Parameters::stdapproxParam) << "\"" << endl;
    279         *file << "\t\tnfzc = " << toString(getParams().getInt(MpqcParser_Parameters::nfzcParam)) << endl;
    280         *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
    281         *file << "\t\tintegrals<IntegralCints>:()" << endl;
    282         *file << "\t\treference<CLHF>: (" << endl;
    283         *file << "\t\t\tmolecule = $:molecule" << endl;
    284         *file << "\t\t\tbasis = $:basis" << endl;
    285         *file << "\t\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam)) << endl;
    286         *file << "\t\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
    287         *file << "\t\t\tintegrals<" << getParams().getString(MpqcParser_Parameters::integrationParam) << ">:()" << endl;
    288         *file << "\t\t)" << endl;
    289         *file << "\t)" << endl;
    290         break;
    291       default:
    292         DoeLog(0) && (eLog() << Verbose(0)
    293             << "Unknown level of theory requested for MPQC output file." << std::endl);
    294         break;
     245    const std::string theory = getParams().getParameter(MpqcParser_Parameters::theoryParam);
     246    if (theory == getParams().getTheoryName(MpqcParser_Parameters::CLHF)) {
     247      *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     248      *file << "\t\tmolecule = $:molecule" << endl;
     249      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
     250      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam)
     251          << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
     252      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
     253          << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
     254      *file << "\t)" << endl;
     255    } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::CLKS)) {
     256      *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     257      *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
     258      *file << "\t\tmolecule = $:molecule" << endl;
     259      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
     260      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam)
     261          << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
     262      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
     263          << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
     264      *file << "\t)" << endl;
     265    } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2)) {
     266      *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     267      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
     268      *file << "\t\tmolecule = $:molecule" << endl;
     269      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
     270          << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
     271      *file << "\t\treference<CLHF>: (" << endl;
     272      *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam)
     273          << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
     274      *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
     275      *file << "\t\t\tmolecule = $:molecule" << endl;
     276      *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
     277          << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
     278      *file << "\t\t)" << endl;
     279      *file << "\t)" << endl;
     280    } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) {
     281      *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     282      *file << "\t\tmolecule = $:molecule" << endl;
     283      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
     284      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::aux_basisParam) << " = $:abasis" << endl;
     285      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::stdapproxParam)
     286          << " = \"" << getParams().getParameter(MpqcParser_Parameters::stdapproxParam) << "\"" << endl;
     287      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::nfzcParam)
     288          << " = " << getParams().getParameter(MpqcParser_Parameters::nfzcParam) << endl;
     289      *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
     290          << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
     291      *file << "\t\tintegrals<IntegralCints>:()" << endl;
     292      *file << "\t\treference<CLHF>: (" << endl;
     293      *file << "\t\t\tmolecule = $:molecule" << endl;
     294      *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
     295      *file << "\t\t\tmaxiter = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam) << endl;
     296      *file << "\t\t\tmemory = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
     297      *file << "\t\t\tintegrals<" << getParams().getParameter(MpqcParser_Parameters::integrationParam) << ">:()" << endl;
     298      *file << "\t\t)" << endl;
     299      *file << "\t)" << endl;
     300    } else {
     301      DoeLog(0) && (eLog() << Verbose(0)
     302          << "Unknown level of theory requested for MPQC output file." << std::endl);
    295303    }
    296304    *file << ")" << endl;
     
    305313    *file << ")" << endl;
    306314    *file << "basis<GaussianBasisSet>: (" << endl;
    307     *file << "\tname = \"" << getParams().getString(MpqcParser_Parameters::basisParam) << "\"" << endl;
     315    *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::basisParam) << "\"" << endl;
    308316    *file << "\tmolecule = $:molecule" << endl;
    309317    *file << ")" << endl;
    310     if (getParams().getTheory() == MpqcParser_Parameters::MBPT2_R12) {
     318    if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) {
    311319      *file << "% auxiliary basis set specification" << endl;
    312320      *file << "\tabasis<GaussianBasisSet>: (" << endl;
    313       *file << "\tname = \"" << getParams().getString(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
     321      *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
    314322      *file << "\tmolecule = $:molecule" << endl;
    315323      *file << ")" << endl;
  • src/Parser/MpqcParser.hpp

    r89a67f ree50c1  
    1414#endif
    1515
     16#include "CodePatterns/toString.hpp"
    1617
    1718#include "FormatParser.hpp"
     
    5657   */
    5758  MpqcParser_Parameters & getParams() { return *static_cast<MpqcParser_Parameters *>(parameters); }
     59
     60private:
     61  static ConvertTo<bool> Converter;
    5862};
    5963
  • src/Parser/MpqcParser_Parameters.cpp

    r89a67f ree50c1  
    2121#include <boost/tokenizer.hpp>
    2222#include <string>
    23 #include <typeinfo>
    2423
    2524#include "CodePatterns/MemDebug.hpp"
     
    3130#include "MpqcParser_Parameters.hpp"
    3231
    33 
    34 using boost::any_cast;
     32#include "Parser/Parameters/ContinuousParameter.hpp"
     33#include "Parser/Parameters/DiscreteParameter.hpp"
     34#include "Parser/Parameters/StringParameter.hpp"
     35
     36template <>
     37const std::string ContinuousValue<bool>::get() const
     38{
     39  ASSERT(ValueSet,
     40      "ContinuousValue<bool>::get() - requesting unset value.");
     41  if (value)
     42    return std::string("yes");
     43  else
     44    return std::string("no");
     45}
     46
     47template <>
     48void ContinuousValue<bool>::set(const std::string _value)
     49{
     50  if (_value == std::string("yes")) {
     51    setValue(true);
     52  } else if (_value == std::string("no")) {
     53    setValue(false);
     54  } else {
     55    ASSERT(0,
     56        "void ContinuousValue<bool>::set() - value "+_value+" is neither yes or no.");
     57  }
     58}
     59
    3560
    3661MpqcParser_Parameters::MpqcParser_Parameters()
    3762{
    3863  Init();
    39 }
    40 
    41 /** Inverter for the (key, value) pairs in a map.
    42  *
    43  * Basically, we just clear \a invertmap and fill with (value, key).
    44  * \note critial error is thrown when values are not unique in \a realmap.
    45  *
    46  * \param realmap the map to invert
    47  * \param invertmap the map that is cleared and filled with (value, key)
    48  */
    49 template <typename MapType, typename InvertMapType>
    50 void InvertMap(const MapType &realmap, InvertMapType &invertmap)
    51 {
    52   invertmap.clear();
    53   // TODO: throw exception instead of eLog()
    54   std::pair<typename InvertMapType::iterator, bool> inserter;
    55   for (typename MapType::const_iterator iter = realmap.begin();
    56       iter != realmap.end();
    57       ++iter) {
    58     // check uniqueness
    59     const std::pair<typename InvertMapType::iterator, bool> inserter =
    60         invertmap.insert( std::make_pair(iter->second, iter->first) );
    61     if (!inserter.second)
    62       ELOG(0, "InvertMap<"
    63 //+std::typeid(realmap).name()+", "+std::typeid(invertmap).name()
    64           << ">() - cannot invert (" << iter->first
    65           << "," << iter->second << "). Key is already present as (" << inserter.first->first
    66           << "," << inserter.first->second << ") in InvertMap.");
    67   }
    6864}
    6965
     
    7369  initBasis();
    7470
    75   // add all theory names
    76   TheoryNames[CLHF]="CLHF";
    77   TheoryNames[CLKS]="CLKS";
    78   TheoryNames[MBPT2]="MBPT2";
    79   TheoryNames[MBPT2_R12]="MBPT2_R12";
    80   InvertMap<TheoryNamesType,TheoryLookupType>(TheoryNames,TheoryLookup);
    81 
    82   // add all integration names
    83   IntegrationNames[IntegralCints] = "IntegralCints";
    84   InvertMap<IntegrationNamesType,IntegrationLookupType>(IntegrationNames, IntegrationLookup);
    85 
    86   // have names for all parmaters
    87   ParamNames[hessianParam] = "Hessian";
    88   ParamNames[savestateParam] = "savestate";
    89   ParamNames[do_gradientParam] = "do_gradient";
    90   ParamNames[maxiterParam] = "maxiter";
    91   ParamNames[memoryParam] = "memory";
    92   ParamNames[stdapproxParam] = "stdapprox";
    93   ParamNames[nfzcParam] = "nfzc";
    94   ParamNames[basisParam] = "basis";
    95   ParamNames[aux_basisParam] = "aux_basis";
    96   ParamNames[integrationParam] = "integration";
    97   ParamNames[theoryParam] = "theory";
    98   InvertMap<ParamNamesType,ParamLookupType>(ParamNames, ParamLookup);
    99 
    100   initParameters();
    101 }
    102 
    103 MpqcParser_Parameters::MpqcParser_Parameters(const MpqcParser_Parameters & state)
    104 {
    105   // init
    106   Init();
    107 
    108   // copy values
    109   copyParameters(state);
    110 }
    111 
    112 void MpqcParser_Parameters::copyParameters(const MpqcParser_Parameters & state)
    113 {
    114   appendParameter(hessianParam, state.getBool(hessianParam));
    115   appendParameter(savestateParam, state.getBool(savestateParam));
    116   appendParameter(do_gradientParam, state.getBool(do_gradientParam));
    117   appendParameter(maxiterParam, state.getInt(maxiterParam));
    118   appendParameter(memoryParam, state.getInt(memoryParam));
    119   appendParameter(stdapproxParam, state.getString(stdapproxParam));
    120   appendParameter(nfzcParam, state.getInt(nfzcParam));
    121   appendParameter(basisParam, state.getString(basisParam));
    122   appendParameter(aux_basisParam, state.getString(aux_basisParam));
    123   appendParameter(integrationParam, state.getIntegration());
    124   appendParameter(theoryParam, state.getTheory());
    125 }
    126 
    127 FormatParser_Parameters* MpqcParser_Parameters::clone() const
    128 {
    129   //LOG(3, "Cloning parameters.");
    130   MpqcParser_Parameters *instance = new MpqcParser_Parameters(*this);
    131   return instance;
    132 }
    133 
    134 void MpqcParser_Parameters::makeClone(const FormatParser_Parameters & _state)
    135 {
    136   //LOG(3, "Cloning parameters from other instance.");
    137   copyParameters(static_cast<const MpqcParser_Parameters &>(_state));
    138 }
    139 
    140 void MpqcParser_Parameters::initParameters()
    141 {
    142         appendParameter(hessianParam, bool(false));
    143         appendParameter(savestateParam, bool(false));
    144         appendParameter(do_gradientParam, bool(true));
    145         appendParameter(maxiterParam, int(1000));
    146         appendParameter(memoryParam, int(16000000));
    147         appendParameter(stdapproxParam, std::string("A'"));
    148         appendParameter(nfzcParam, int(1));
    149         appendParameter(basisParam, std::string("3-21G"));
    150         appendParameter(aux_basisParam, std::string("aug-cc-pVDZ"));
    151         appendParameter(integrationParam, IntegralCints);
    152         appendParameter(theoryParam, MBPT2);
     71  // add all parameter names
     72  {
     73    ParamNames.clear();
     74    ParamNames.resize(unknownParam);
     75    ParamNames[hessianParam] = "Hessian";
     76    ParamNames[savestateParam] = "savestate";
     77    ParamNames[do_gradientParam] = "do_gradient";
     78    ParamNames[maxiterParam] = "maxiter";
     79    ParamNames[memoryParam] = "memory";
     80    ParamNames[stdapproxParam] = "stdapprox";
     81    ParamNames[nfzcParam] = "nfzc";
     82    ParamNames[basisParam] = "basis";
     83    ParamNames[aux_basisParam] = "aux_basis";
     84    ParamNames[integrationParam] = "integration";
     85    ParamNames[theoryParam] = "theory";
     86  }
     87
     88  // create theory parameter
     89  {
     90    ValidTheories.clear();
     91    ValidTheories.resize(unknownTheory);
     92    ValidTheories[CLHF]="CLHF";
     93    ValidTheories[CLKS]="CLKS";
     94    ValidTheories[MBPT2]="MBPT2";
     95    ValidTheories[MBPT2_R12]="MBPT2_R12";
     96    appendParameter(
     97        new DiscreteParameter<std::string>(
     98            ParamNames[theoryParam],
     99            ValidTheories,
     100            ValidTheories[MBPT2]));
     101  }
     102  //InvertMap<TheoryNamesType,TheoryLookupType>(TheoryNames,TheoryLookup);
     103
     104  // create integration parameter
     105  {
     106    ValidIntegrationMethods.clear();
     107    ValidIntegrationMethods.resize(unknownIntegration);
     108    ValidIntegrationMethods[IntegralCints] = "IntegralCints";
     109    appendParameter(
     110        new DiscreteParameter<std::string>(
     111            ParamNames[integrationParam],
     112            ValidIntegrationMethods,
     113            ValidIntegrationMethods[IntegralCints]));
     114  }
     115
     116  // add all continuous parameters
     117  {
     118    appendParameter(new ContinuousParameter<bool>(ParamNames[hessianParam], false));
     119    appendParameter(new ContinuousParameter<bool>(ParamNames[savestateParam], false));
     120    appendParameter(new ContinuousParameter<bool>(ParamNames[do_gradientParam], true));
     121    appendParameter(new ContinuousParameter<int>(ParamNames[maxiterParam], 1000));
     122    appendParameter(new ContinuousParameter<int>(ParamNames[memoryParam], 16000000));
     123    appendParameter(new StringParameter(ParamNames[stdapproxParam], "A'"));
     124    appendParameter(new ContinuousParameter<int>(ParamNames[nfzcParam], 1));
     125    appendParameter(new StringParameter(ParamNames[basisParam], "3-21G"));
     126    appendParameter(new StringParameter(ParamNames[aux_basisParam], "aug-cc-pVDZ"));
     127  }
    153128}
    154129
     
    156131{}
    157132
    158 std::ostream & operator << (std::ostream& ost, MpqcParser_Parameters const &_mpqc_params)
     133/** Getter for a specific Parameter.
     134 *
     135 * @param param index among enum Parameters
     136 * @return value of the desired Parameters
     137 */
     138const std::string MpqcParser_Parameters::getParameter(const enum Parameters param) const
     139{
     140  return FormatParser_Parameters::getParameter(ParamNames[param])->get();
     141}
     142
     143/** Setter for a specific Parameter.
     144 *
     145 * @param param index among enum Parameters
     146 * @param _value value to set desired Parameter to
     147 */
     148void MpqcParser_Parameters::setParameter(const enum Parameters param, const std::string &_value)
     149{
     150  const std::string &name = getParameterName(param);
     151  FormatParser_Parameters::getParameter(name)->set(_value);
     152}
     153
     154/** Getter for name of a specific Parameter.
     155 *
     156 * @param param index among enum Parameters
     157 * @return name of the desired Parameter
     158 */
     159const std::string &MpqcParser_Parameters::getParameterName(const enum Parameters param) const
     160{
     161  return ParamNames[param];
     162}
     163
     164/** Getter for name of a specific Parameter.
     165 *
     166 * @param param index among enum Theory
     167 * @return name of the desired Theory
     168 */
     169const std::string &MpqcParser_Parameters::getTheoryName(const enum Theory theory) const
     170{
     171  return ValidTheories[theory];
     172}
     173
     174/** Getter for the name of specific of IntegrationMethod.
     175 *
     176 * @param param index among enum IntegrationMethod
     177 * @return value of the desired IntegrationMethod
     178 */
     179const std::string &MpqcParser_Parameters::getIntegrationMethodName(const enum IntegrationMethod integration) const
     180{
     181  return ValidIntegrationMethods[integration];
     182}
     183
     184
     185/** Output operator for the contents of MpqcParser_Parameters::params.
     186 *
     187 * @param ost output stream
     188 * @param params reference to MpqcParser_Parameters containing params.
     189 * @return reference to output stream for concatenation
     190 */
     191std::ostream & operator << (std::ostream& ost, const MpqcParser_Parameters &params)
    159192{
    160193  // this is ugly, but with boost::any to safeguard const-ness is plain impossible
    161   MpqcParser_Parameters &mpqc_params = const_cast<MpqcParser_Parameters &>(_mpqc_params);
    162194  std::ostringstream output;
    163   output << "Hessian=" << mpqc_params.getBool(MpqcParser_Parameters::hessianParam) << ";";
    164   output << "savestate=" << mpqc_params.getBool(MpqcParser_Parameters::savestateParam) << ";";
    165   output << "do_gradient=" << mpqc_params.getBool(MpqcParser_Parameters::do_gradientParam) << ";";
    166   output << "maxiter=" << mpqc_params.getInt(MpqcParser_Parameters::maxiterParam) << ";";
    167   output << "memory=" << mpqc_params.getInt(MpqcParser_Parameters::memoryParam) << ";";
    168   output << "stdapprox=" << mpqc_params.getString(MpqcParser_Parameters::stdapproxParam) << ";";
    169   output << "nfzc=" << mpqc_params.getInt(MpqcParser_Parameters::nfzcParam) << ";";
    170   output << "basis=" << mpqc_params.getString(MpqcParser_Parameters::basisParam) << ";";
    171   output << "aux_basis=" << mpqc_params.getString(MpqcParser_Parameters::aux_basisParam) << ";";
    172   output << "integration=" << mpqc_params.getString(MpqcParser_Parameters::integrationParam) << ";";
    173   output << "theory=" << mpqc_params.getString(MpqcParser_Parameters::theoryParam) << ";";
     195  for (size_t param = (enum MpqcParser_Parameters::Parameters)0;
     196      param < (size_t)MpqcParser_Parameters::unknownParam; ++param)
     197    output << params.getParameterName((enum MpqcParser_Parameters::Parameters)param)
     198           <<  "=" << params.getParameter((enum MpqcParser_Parameters::Parameters)param) << ";";
    174199  ost << output.str();
    175200  return ost;
    176201}
    177202
     203/** Input operator for a list of parameters to place into \a params.
     204 *
     205 * @param ist input stream
     206 * @param params parameters to parse into
     207 * @return input stream for concatenation
     208 */
    178209std::istream & operator >> (std::istream& ist, MpqcParser_Parameters &params)
    179210{
     
    216247
    217248      // TODO: throw exception instead of DoeLog()
    218       ASSERT(params.haveParam(key),
     249      ASSERT(params.haveParameter(key),
    219250          "operator >> on MpqcParser_Parameters - unknown parameter name '"
    220251          +key+"' with value "+valuestream.str()+"!");
    221       if (params.haveParam(key))
    222         params.setter(params.getParam(key), valuestream);
     252      if (params.haveParameter(key)) {
     253        Parameter *instance = params.FormatParser_Parameters::getParameter(key);
     254        instance->set(valuestream.str());
     255      }
    223256    } else {
    224257      ist.setstate(std::ios::eofbit);
     
    228261}
    229262
    230 
    231 /** Sets a desired value in the params from a string.
    232  *
    233  * This is due to strict typing of C++ very ugly and boost::any does not make
    234  * it any better because it offers to functions to use values directly from
    235  * stringstream. Probably, because value is unknown to is as well and hence
    236  * the author could not implement it beautifully, so he dropped it altogether.
    237  * Grrr ....
    238  *
    239  * @param _param param to set
    240  * @param _desired stringstream containing value as next argument
    241  * @return true - type ok, false - unknown type in params.
    242  */
    243 bool MpqcParser_Parameters::setter(enum Parameters _param, std::stringstream& _desired) {
    244   if (_param == integrationParam) {
    245      std::string tmp;
    246     _desired >> tmp;
    247     params[_param] = IntegrationLookup[tmp];
    248   } else if(_param == theoryParam) {
    249     std::string tmp;
    250     _desired >> tmp;
    251     params[_param] = TheoryLookup[tmp];
    252   } else if (params[_param].type() == typeid(std::string)) {
    253     std::string tmp;
    254     _desired >> tmp;
    255     params[_param] = tmp;
    256   } else if (params[_param].type() ==  typeid(int)) {
    257     int tmp;
    258     _desired >> tmp;
    259     params[_param] = tmp;
    260   } else if (params[_param].type() == typeid(double)) {
    261     double tmp;
    262     _desired >> tmp;
    263     params[_param] = tmp;
    264   } else if (params[_param].type() == typeid(bool)) {
    265     std::string tmp;
    266     _desired >> tmp;
    267     if ((tmp == "yes") || (tmp == "1")) {
    268       params[_param] = bool(true);
    269     } else if ((tmp == "no") || (tmp == "0")) {
    270       params[_param] = bool(false);
    271     } else {
    272       DoeLog(0) && (eLog() << Verbose(0)
    273           << "MpqcParser_Parameters::setter() - unknown boolean key "
    274           << tmp << "!" << std::endl);
    275     }
    276   } else {
    277     DoeLog(0) && (eLog() << Verbose(0)
    278         << "MpqcParser_Parameters::setter() - unknown type!" << std::endl);
    279     return false;
    280   }
    281   return true;
    282 }
    283 
    284 
    285 void MpqcParser_Parameters::setTheory(enum Theory _theory)
    286 {
    287   // TODO: throw exception instead of eLog()
    288 //  try {
    289     params[theoryParam] = _theory;
    290 //  } catch(const boost::bad_any_cast &) {
    291 //    DoeLog(0) && (eLog() << Verbose(0)
    292 //        << "MpqcParser_Parameters::setTheory() - could not set boolean!" << std::endl);
    293 //  }
    294 }
    295 
    296 void MpqcParser_Parameters::setIntegration(enum MpqcParser_Parameters::IntegrationMethod _integration){
    297   // TODO: throw exception instead of eLog()
    298 //  try {
    299     params[integrationParam] = _integration;
    300 //  } catch(const boost::bad_any_cast &) {
    301 //    DoeLog(0) && (eLog() << Verbose(0)
    302 //        << "MpqcParser_Parameters::setIntegration() - could not set boolean!" << std::endl);
    303 //  }
    304 }
    305 
    306 bool MpqcParser_Parameters::haveParam(std::string _name) const
    307 {
    308   return ParamLookup.count(_name) != 0;
    309 }
    310 
    311 enum MpqcParser_Parameters::Parameters MpqcParser_Parameters::getParam(std::string _name) const
    312 {
    313   ParamLookupType::const_iterator iter = ParamLookup.find(_name);
    314   return iter->second;
    315 }
    316 
    317 enum MpqcParser_Parameters::IntegrationMethod MpqcParser_Parameters::getIntegration() const
    318 {
    319   parameterlist::const_iterator iter = params.find(integrationParam);
    320   enum IntegrationMethod value;
    321   // TODO: throw exception instead of eLog()
    322 //  try {
    323     value = boost::any_cast<enum IntegrationMethod>(iter->second);
    324 //  } catch(const boost::bad_any_cast &) {
    325 //    DoeLog(0) && (eLog() << Verbose(0)
    326 //        << "MpqcParser_Parameters::getIntegration() - could not convert "
    327 //        +ParamNames[integrationParam]+" to enum IntegrationMethod!" << std::endl);
    328 //  }
    329   return value;
    330 }
    331 
    332 enum MpqcParser_Parameters::Theory MpqcParser_Parameters::getTheory() const
    333 {
    334   parameterlist::const_iterator iter = params.find(theoryParam);
    335   enum Theory value;
    336   // TODO: throw exception instead of eLog()
    337 //  try {
    338     value = boost::any_cast<enum Theory>(iter->second);
    339 //  } catch(const boost::bad_any_cast &) {
    340 //    DoeLog(0) && (eLog() << Verbose(0)
    341 //        << "MpqcParser_Parameters::getTheory() - could not convert "
    342 //        +ParamNames[theoryParam]+" to enum Theory!" << std::endl);
    343 //  }
    344   return value;
    345 }
    346 
    347 std::string MpqcParser_Parameters::getString(enum Parameters _param) const
    348 {
    349   std::string value;
    350   enum IntegrationMethod Iindex;
    351   enum Theory Tindex;
    352   bool test;
    353   parameterlist::const_iterator iter = params.find(_param);
    354   switch (_param) {
    355     case hessianParam:
    356     case savestateParam:
    357     case do_gradientParam:
    358       test = boost::any_cast<bool>(iter->second);
    359       if (test)
    360         value = "yes";
    361       else
    362         value = "no";
    363       break;
    364     case integrationParam:
    365       // TODO: throw exception instead of eLog()
    366 //      try {
    367         Iindex = boost::any_cast<enum IntegrationMethod>(iter->second);
    368 //      } catch(const boost::bad_any_cast &) {
    369 //        DoeLog(0) && (eLog() << Verbose(0)
    370 //            << "MpqcParser_Parameters::getString() - could not convert "
    371 //            +ParamNames[_param]+" to string!" << std::endl);
    372 //      }
    373       {
    374         IntegrationNamesType::const_iterator Iiter = IntegrationNames.find(Iindex);
    375         value = Iiter->second;
    376       }
    377       break;
    378     case theoryParam:
    379       // TODO: throw exception instead of eLog()
    380 //      try {
    381         Tindex = boost::any_cast<enum Theory>(iter->second);
    382 //      } catch(const boost::bad_any_cast &) {
    383 //        DoeLog(0) && (eLog() << Verbose(0)
    384 //            << "MpqcParser_Parameters::getString() - could not convert "
    385 //            +ParamNames[_param]+" to string!" << std::endl);
    386 //      }
    387         {
    388           TheoryNamesType::const_iterator Titer = TheoryNames.find(Tindex);
    389           value = Titer->second;
    390         }
    391       break;
    392     default:
    393       // TODO: throw exception instead of eLog()
    394 //      try {
    395         value = boost::any_cast<std::string>(iter->second);
    396 //      } catch(const boost::bad_any_cast &) {
    397 //        DoeLog(0) && (eLog() << Verbose(0)
    398 //            << "MpqcParser_Parameters::getString() - could not convert "
    399 //            +ParamNames[_param]+" to string!" << std::endl);
    400 //      }
    401       break;
    402   }
    403 
    404   return value;
    405 }
    406 
    407 int MpqcParser_Parameters::getInt(enum Parameters _param) const
    408 {
    409   int value;
    410   parameterlist::const_iterator iter = params.find(_param);
    411   switch (_param) {
    412     default:
    413       // TODO: throw exception instead of eLog()
    414 //      try {
    415         value = boost::any_cast<int>(iter->second);
    416 //      } catch(const boost::bad_any_cast &) {
    417 //        DoeLog(0) && (eLog() << Verbose(0)
    418 //            << "MpqcParser_Parameters::getInt() - could not convert "
    419 //            +ParamNames[_param]+" to int!" << std::endl);
    420 //      }
    421       break;
    422   }
    423   return value;
    424 }
    425 
    426 double MpqcParser_Parameters::getDouble(enum Parameters _param) const
    427 {
    428   double value;
    429   parameterlist::const_iterator iter = params.find(_param);
    430   // TODO: throw exception instead of eLog()
    431 //  try {
    432     value = boost::any_cast<double>(iter->second);
    433 //  } catch(const boost::bad_any_cast &) {
    434 //    DoeLog(0) && (eLog() << Verbose(0)
    435 //        << "MpqcParser_Parameters::getDouble() - could not convert "
    436 //        +ParamNames[_param]+" to double!" << std::endl);
    437 //  }
    438   return value;
    439 }
    440 
    441 bool MpqcParser_Parameters::getBool(enum Parameters _param) const
    442 {
    443   bool value;
    444   parameterlist::const_iterator iter = params.find(_param);
    445   // TODO: throw exception instead of eLog()
    446 //  try {
    447     value = boost::any_cast<bool>(iter->second);
    448 //  } catch(const boost::bad_any_cast &) {
    449 //    DoeLog(0) && (eLog() << Verbose(0)
    450 //        << "MpqcParser_Parameters::getBool() - could not convert "
    451 //        +ParamNames[_param]+" to bool!" << std::endl);
    452 //  }
    453   return value;
    454 }
    455 
    456 
    457263/** Checks whether all elements in the world also have parameters in the basis.
    458264 *
  • src/Parser/MpqcParser_Parameters.hpp

    r89a67f ree50c1  
    1616#include <iosfwd>
    1717#include <list>
    18 #include <typeinfo>
     18#include <map>
    1919#include <vector>
    2020
    2121#include "CodePatterns/Clone.hpp"
    2222#include "CodePatterns/Log.hpp"
    23 #include "CodePatterns/Verbose.hpp"
    24 
    25 #include <boost/any.hpp>
    2623
    2724#include "Parser/FormatParser_Parameters.hpp"
     25
     26#include "Parser/Parameters/ContinuousParameter.hpp"
     27
     28// specialization for bool (we want "yes/no" not "1/0")
     29template <> const std::string ContinuousValue<bool>::get() const;
     30template <> void ContinuousValue<bool>::set(const std::string _value);
    2831
    2932class MpqcParser;
     
    4245  MpqcParser_Parameters();
    4346
    44   /** Copy Constructor of MpqcParser_Parameters.
    45    *
    46    * @param state ref to instance to copy
    47    */
    48   MpqcParser_Parameters(const MpqcParser_Parameters & state);
    49 
    5047  /** Destructor of MpqcParser_Parameters.
    5148   *
    5249   */
    5350  virtual ~MpqcParser_Parameters();
     51
     52  /** Enumeration of all known Parameters to allow placing them in vectors, maps.
     53   *
     54   */
     55  enum Parameters {
     56    hessianParam,    //!< HessianParam, whether hessian should be calculated or not
     57    savestateParam,  //!< savestateParam, whether intermediate/final states (wave function) should be stored
     58    do_gradientParam,//!< do_gradientParam, whether a gradient should be calculated
     59    maxiterParam,    //!< maxiterParam, number of maximum iterations for CG
     60    memoryParam,     //!< memoryParam, maximum amount of memory to use
     61    stdapproxParam,  //!< stdapproxParam, standard approximation in MBPT2 R12
     62    nfzcParam,       //!< nfzcParam, nfzc parameter in MBPT2 R12
     63    basisParam,      //!< basisParam, basis set to use
     64    aux_basisParam,  //!< aux_basisParam, auxiliary baseis set to use in MBPT2 R12
     65    integrationParam,//!< integrationParam, integration method to use in MBPT2 R12
     66    theoryParam,     //!< theoryParam, level of theory to use
     67    unknownParam};   //!< unknownParam, designates an unknown parameter
    5468
    5569  /** Enumeration of all known theories.
     
    7286  };
    7387
    74   /** Enumeration of all known Parameters to allow placing them in vectors, maps.
    75    *
    76    */
    77   enum Parameters {
    78     hessianParam,    //!< HessianParam, whether hessian should be calculated or not
    79     savestateParam,  //!< savestateParam, whether intermediate/final states (wave function) should be stored
    80     do_gradientParam,//!< do_gradientParam, whether a gradient should be calculated
    81     maxiterParam,    //!< maxiterParam, number of maximum iterations for CG
    82     memoryParam,     //!< memoryParam, maximum amount of memory to use
    83     stdapproxParam,  //!< stdapproxParam, standard approximation in MBPT2 R12
    84     nfzcParam,       //!< nfzcParam, nfzc parameter in MBPT2 R12
    85     basisParam,      //!< basisParam, basis set to use
    86     aux_basisParam,  //!< aux_basisParam, auxiliary baseis set to use in MBPT2 R12
    87     integrationParam,//!< integrationParam, integration method to use in MBPT2 R12
    88     theoryParam,     //!< theoryParam, level of theory to use
    89     unknownParam};   //!< unknownParam, designates an unknown parameter
     88  // enum to string getters
     89  const std::string getParameter(const enum Parameters param) const;
     90  void setParameter(const enum Parameters param, const std::string &);
     91  const std::string &getParameterName(const enum Parameters param) const;
     92  const std::string &getTheoryName(const enum Theory theory) const;
     93  const std::string &getIntegrationMethodName(const enum IntegrationMethod integration) const;
     94
     95private:
     96
     97
     98  //!> vector with all available theories in same order as enum Theory.
     99  std::vector<std::string> ValidTheories;
     100
     101  //!> vector with all available integration methods in same order as enum IntegrationMethod.
     102  std::vector<std::string> ValidIntegrationMethods;
    90103
    91104  bool checkWorldElementsAgainstCurrentBasis() const;
    92105
    93   /** Sets the desired level of solving theory to use.
    94    *
    95    * \param _theory shorthand of the theory
    96    */
    97   void setTheory(enum Theory _theory);
    98 
    99   /** Sets the desired level of solving integration to use.
    100    *
    101    * \param _integration shorthand of the integration
    102    */
    103   void setIntegration(enum IntegrationMethod _integration);
    104 
    105   /** Getter for integration method in params.
    106    *
    107    * @return enumeration index of IntegrationMethod.
    108    */
    109   enum IntegrationMethod getIntegration() const;
    110 
    111   /** Getter for current Theory in params.
    112    *
    113    * @return enumeration index of Theory
    114    */
    115   enum Theory getTheory() const;
    116 
    117   /** Getter for a parameter in params as a string.
    118    *
    119    * @param _param enumeration index of desired Parameter
    120    * @return string value
    121    */
    122   std::string getString(enum Parameters _param) const;
    123 
    124   /** Getter for integer value of desired Parameter in params.
    125    *
    126    * Only if type in params matches int!
    127    *
    128    * @param _param enumeration index in Parameter
    129    * @return integer value of parameter
    130    */
    131   int getInt(enum Parameters _param) const;
    132 
    133   /** Getter for double value of desired Parameter in params.
    134    *
    135    * Only if type in params matches double!
    136    *
    137    * @param _param enumeration index in Parameter
    138    * @return double value of parameter
    139    */
    140   double getDouble(enum Parameters _param) const;
    141 
    142   /** Getter for bool value of desired Parameter in params.
    143    *
    144    * Only if type in params matches bool!
    145    *
    146    * @param _param enumeration index in Parameter
    147    * @return bool value of parameter
    148    */
    149   bool getBool(enum Parameters _param) const;
    150 
    151   /** Setter for a desired value of its type is known.
    152    *
    153    * We check whether given type matches present type in params.
    154    *
    155    * @param _param enumeration index of Parameter
    156    * @param _desired desired value to set to
    157    * @return true - type match, value set, false - type mismatch
    158    */
    159   template <class T> bool setter(enum Parameters _param, T _desired) {
    160     if (typeid(T) == params[_param].type()) {
    161       params[_param] = _desired;
    162       return true;
    163     } else
    164       return false;
    165   }
    166 
    167   /** Sets a desired value in the params from a string.
    168    *
    169    * This is due to strict typing of C++ very ugly and boost::any does not make
    170    * it any better because it offers to functions to use values directly from
    171    * stringstream. Probably, because value is unknown to is as well and hence
    172    * the author could not implement it beautifully, so he dropped it altogether.
    173    * Grrr ....
    174    *
    175    * @param _param param to set
    176    * @param _desired stringstream containing value as next argument
    177    * @return true - type ok, false - unknown type in params.
    178    */
    179   bool setter(enum Parameters _param, std::stringstream& _desired);
    180 
    181   /** Grants access to ParamLookup.
    182    *
    183    *  Does not check for unknown parameter.
    184    *
    185    * @param _name name of parameter
    186    * @return enumeration index of Parameters
    187    */
    188   enum Parameters getParam(std::string _name) const;
    189 
    190   /** Checker whether parameter with name is known.
    191    *
    192    * @param _name
    193    * @return true - parameter known, false - parameter unknown
    194    */
    195   bool haveParam(std::string _name) const;
    196 
    197   /** Creates a clone of the class.
    198    *
    199    * @return
    200    */
    201   FormatParser_Parameters* clone() const;
    202 
    203   /** Applies a before returned undo state.
    204    *
    205    * @param undo state to set
    206    */
    207   void makeClone(const FormatParser_Parameters & _state);
    208 
    209   /** Set the internal parameters to the one's from the given \a state.
    210    *
    211    * @param state set of parameters
    212    */
    213   void copyParameters(const MpqcParser_Parameters & state);
    214 
    215 private:
    216106  /** Global initialization in cstor.
    217107   *
     
    224114  void initBasis();
    225115
    226   /** Initializes params.
    227    * Sets the type and the associated enumeration index.
    228    */
    229   void initParameters();
     116  //!> vector with all parameter names in same order as enum Parameters
     117  std::vector<std::string> ParamNames;
    230118
    231   /** Internal function used by initParameters() to add parameters to params.
    232    *
    233    * @param _enum enumeration index to set
    234    * @param _p (default) value to set with certain type
    235    */
    236   template <class T> void appendParameter(enum Parameters _enum, T _p) {
    237     boost::any _p_value = _p;
    238     params[_enum] = _p_value;
    239   }
     119  //!> typedef for the list of all available basis sets
     120  typedef std::map<std::string, std::list<std::string> > BasisMapType;
    240121
    241   // all internal typedefs for lists below
    242   typedef std::map<std::string, std::list<std::string> > BasisMapType;
    243   typedef std::map<enum Theory, std::string> TheoryNamesType;
    244   typedef std::map<std::string, enum Theory> TheoryLookupType;
    245   typedef std::map<enum IntegrationMethod, std::string> IntegrationNamesType;
    246   typedef std::map<std::string, enum IntegrationMethod> IntegrationLookupType;
    247   typedef std::map<enum Parameters, std::string> ParamNamesType;
    248   typedef std::map<std::string, enum Parameters> ParamLookupType;
    249   typedef std::map<enum Parameters, boost::any> parameterlist;
    250 
    251   //!> boost::any container for all the parameters
    252   parameterlist params;
    253 
    254   // maps from names to enumerations
    255 
    256   //!> contains basis and all elements the basis knows about
     122  //!> list of all basis along with their present element parametrization
    257123  BasisMapType BasisList;
    258   //!> contains the name of a theory as string
    259   TheoryNamesType TheoryNames;
    260   //!> contains a lookup from theory name to enumeration index
    261   TheoryLookupType TheoryLookup;
    262   //!> contains the name of an integration method as string
    263   IntegrationNamesType IntegrationNames;
    264   //!> contains a lookup from integration method name to enumeration index
    265   IntegrationLookupType IntegrationLookup;
    266   //!> contains the name of a parameter
    267   ParamNamesType ParamNames;
    268   //!> contains a lookup from parameter name to enumeration index
    269   ParamLookupType ParamLookup;
    270124};
    271125
    272 /** Output operator for the contents of MpqcParser_Parameters::params.
    273  *
    274  * @param ost output stream
    275  * @param params reference to MpqcParser_Parameters containing params.
    276  * @return reference to output stream for concatenation
    277  */
    278126std::ostream & operator << (std::ostream& ost, const MpqcParser_Parameters &params);
    279127
    280 /** Input operator for a list of parameters to place into \a params.
    281  *
    282  * @param ist input stream
    283  * @param params parameters to parse into
    284  * @return input stream for concatenation
    285  */
    286128std::istream & operator >> (std::istream& ist, MpqcParser_Parameters &params);
    287129
  • src/Parser/unittests/ParserMpqcUnitTest.cpp

    r89a67f ree50c1  
    183183/************************************ tests ***********************************/
    184184
    185 void ParserMpqcUnitTest::ParameterTypeTest() {
    186   // check types in boost::any map
    187   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));
    188   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int));
    189   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));
    190   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));
    191   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));
    192   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int));
    193   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));
    194   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));
    195   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));
    196   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));
    197   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));
    198   CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));
    199 }
    200 
    201185void ParserMpqcUnitTest::ParameterDefaultTest() {
    202186  // check default values
    203   CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "no");
    204   CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::hessianParam));
    205   CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::savestateParam) == "no");
    206   CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::savestateParam));
    207   CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes");
    208   CPPUNIT_ASSERT(parser->getParams().getBool(MpqcParser_Parameters::do_gradientParam));
    209   CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000);
    210   CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000);
    211   CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'");
    212   CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1);
    213   CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G");
    214   CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ");
    215   CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints");
    216   CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    217   CPPUNIT_ASSERT(parser->getParams().getTheory() == MpqcParser_Parameters::MBPT2);
    218   CPPUNIT_ASSERT(parser->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints);
    219 
    220   // check that values are not removed
    221   CPPUNIT_ASSERT(!parser->getParams().params[MpqcParser_Parameters::theoryParam].empty());
    222 
    223   // check throw, for the moment aren't, are caught in getInt()
    224   CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);
    225   CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);
    226 
     187  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("no"));
     188  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::savestateParam) == std::string("no"));
     189  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::do_gradientParam) == std::string("yes"));
     190  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("1000"));
     191  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::memoryParam) == std::string("16000000"));
     192  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::stdapproxParam) == std::string("A'"));
     193  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::nfzcParam) == std::string("1"));
     194  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::basisParam) == std::string("3-21G"));
     195  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::aux_basisParam) == std::string("aug-cc-pVDZ"));
     196  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::integrationParam) == std::string("IntegralCints"));
     197  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
    227198}
    228199
    229200void ParserMpqcUnitTest::ParameterCloneTest() {
    230201  FormatParser_Parameters *clone = parser->getParams().clone();
    231   CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     202  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
    232203  std::stringstream setvalue("theory = CLHF");
    233204  setvalue >> parser->getParams();
    234   CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
     205  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
    235206  parser->getParams().makeClone(*clone);
    236   CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     207  CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("MBPT2"));
    237208}
    238209
     
    244215//    std::cout << "integration method is "
    245216//        << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
    246     CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
     217    CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::theoryParam) == std::string("CLHF"));
    247218  }
    248219  // test a bool
     
    252223//    std::cout << "Hessian is "
    253224//        << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
    254     CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
     225    CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
    255226  }
    256227  // test int
     
    260231//    std::cout << "maxiter is "
    261232//        << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
    262     CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);
     233    CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::maxiterParam) == std::string("500"));
    263234  }
    264235  // test whether unknown key fails
     
    274245//    std::cout << "Hessian is still "
    275246//        << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
    276     CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
     247    CPPUNIT_ASSERT(parser->getParams().getParameter(MpqcParser_Parameters::hessianParam) == std::string("yes"));
    277248  }
    278249}
     
    280251void ParserMpqcUnitTest::readMpqcTest() {
    281252  stringstream input(waterMpqc_CLHF);
    282   parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
     253  parser->getParams().setParameter(
     254      MpqcParser_Parameters::theoryParam,
     255      parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
     256          );
    283257  parser->load(&input);
    284258
     
    308282    // compare both configs for CLHF
    309283    stringstream output;
    310     parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
     284    parser->getParams().setParameter(
     285        MpqcParser_Parameters::theoryParam,
     286        parser->getParams().getTheoryName(MpqcParser_Parameters::CLHF)
     287            );
    311288    parser->save(&output, atoms);
    312289    stringstream input(waterMpqc_CLHF);
     
    319296    // compare both configs for CLKS
    320297    stringstream output;
    321     parser->getParams().setTheory(MpqcParser_Parameters::CLKS);
    322     parser->save(&output, atoms);
     298    parser->getParams().setParameter(
     299        MpqcParser_Parameters::theoryParam,
     300        parser->getParams().getTheoryName(MpqcParser_Parameters::CLKS)
     301            );
    323302    stringstream input(waterMpqc_CLKS);
    324303    for (; std::getline(input, first) && std::getline(output, second); ) {
     
    330309    // compare both configs for MBPT2
    331310    stringstream output;
    332     parser->getParams().setTheory(MpqcParser_Parameters::MBPT2);
    333     parser->save(&output, atoms);
     311    parser->getParams().setParameter(
     312        MpqcParser_Parameters::theoryParam,
     313        parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2)
     314            );
    334315    stringstream input(waterMpqc_MBPT2);
    335316    for (; std::getline(input, first) && std::getline(output, second); ) {
     
    341322    // compare both configs for MBPT2_R12
    342323    stringstream output;
    343     parser->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12);
    344     parser->save(&output, atoms);
     324    parser->getParams().setParameter(
     325        MpqcParser_Parameters::theoryParam,
     326        parser->getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)
     327            );
    345328    stringstream input(waterMpqc_MBPT2_R12);
    346329    for (; std::getline(input, first) && std::getline(output, second); ) {
  • src/Parser/unittests/ParserMpqcUnitTest.hpp

    r89a67f ree50c1  
    2121{
    2222  CPPUNIT_TEST_SUITE( ParserMpqcUnitTest ) ;
    23   CPPUNIT_TEST ( ParameterTypeTest );
    2423  CPPUNIT_TEST ( ParameterDefaultTest );
    2524  CPPUNIT_TEST ( ParameterSetterTest );
     
    3332  void tearDown();
    3433
    35   void ParameterTypeTest();
    3634  void ParameterDefaultTest();
    3735  void ParameterSetterTest();
Note: See TracChangeset for help on using the changeset viewer.