Changeset c1db05 for src/Parser


Ignore:
Timestamp:
Oct 10, 2011, 2:27:06 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:
4151b0
Parents:
e611dc
git-author:
Frederik Heber <heber@…> (09/06/11 08:45:22)
git-committer:
Frederik Heber <heber@…> (10/10/11 14:27:06)
Message:

Abstracted FormatParser_Parameters and made it "Clone"able.

  • this is preparatory for having an undoable LoadAction.
  • is so far only used by MpqcParser_Parameters.
  • FormatParser_Parameters::clone() clones the instance (uses CodePattern's Clone pattern).
  • FormatParser has pointer to FormatParser_Parameters.
  • MpqcParser now has parameters as inheritance from FormatParser, allocates in cstor, removes in dstor.
  • new function MpqcParser_Parameters::makeClone() sets instance to be a copy of the given one.
  • MpqcParser: replaced direct access to params by getParams().
  • added ParameterCloneTest to ParserMpqcUnitTest.
Location:
src/Parser
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/Parser/FormatParser.cpp

    re611dc rc1db05  
    3030FormatParser::FormatParser() :
    3131  Observer("FormatParser"),
     32  parameters(NULL),
    3233  saveStream(NULL)
    3334{
  • TabularUnified src/Parser/FormatParser.hpp

    re611dc rc1db05  
    1717#include "CodePatterns/Observer.hpp"
    1818#include "ChangeTracker.hpp"
     19#include "FormatParser_Parameters.hpp"
    1920#include "parser.hpp"
     21
    2022
    2123class atom;
     
    2527 */
    2628class FormatParser : public Observer {
     29  friend class MoleculeLoadAction;
    2730public:
    2831  FormatParser();
     
    4144  virtual void AtomRemoved(atomId_t) {};
    4245
     46  FormatParser_Parameters *parameters;
    4347private:
     48
    4449  std::ostream* saveStream;
    4550};
  • TabularUnified src/Parser/Makefile.am

    re611dc rc1db05  
    2020  Parser/ChangeTracker.hpp \
    2121  Parser/FormatParser.hpp \
     22  Parser/FormatParser_Parameters.hpp \
    2223  Parser/FormatParserStorage.hpp \
    2324  Parser/MpqcParser.hpp \
  • TabularUnified src/Parser/MpqcParser.cpp

    re611dc rc1db05  
    2525
    2626#include "MpqcParser.hpp"
     27#include "MpqcParser_Parameters.hpp"
    2728
    2829#include "atom.hpp"
     
    4243 */
    4344MpqcParser::MpqcParser()
    44 {}
     45{
     46  parameters = new MpqcParser_Parameters();
     47}
    4548
    4649/** Destructor of MpqcParser.
     
    4851 */
    4952MpqcParser::~MpqcParser()
    50 {}
     53{
     54  delete parameters;
     55}
    5156
    5257/** Load an MPQC config file into the World.
     
    123128        std::string value(*tok_iter);
    124129        std::stringstream linestream("theory = "+value);
    125         linestream >> params;
     130        linestream >> getParams();
    126131      } else if (linestring.find("integrals<") != string::npos) { // get theory
    127132        tokenizer tokens(linestring, angularsep);
     
    132137        std::string value(*tok_iter);
    133138        std::stringstream linestream("integration = "+value);
    134         linestream >> params;
     139        linestream >> getParams();
    135140      } else if ((linestring.find("molecule") == string::npos) && (linestring.find("basis") == string::npos)){
    136141        // molecule and basis must not be parsed in this section
     
    142147        std::string key;
    143148        whitespacefilter >> ws >> key;
    144         if (params.haveParam(key)) {
     149        if (getParams().haveParam(key)) {
    145150          std::stringstream linestream(linestring);
    146           linestream >> params;
     151          linestream >> getParams();
    147152        } else { // unknown keys are simply ignored as long as parser is incomplete
    148153          DoLog(2) && (Log() << Verbose(2) << "INFO: '"+key+"' is unknown and ignored." << std::endl);
     
    165170      if (key == "name") {
    166171        std::stringstream linestream("basis = "+value);
    167         linestream >> params;
     172        linestream >> getParams();
    168173      }
    169174    }
     
    183188      if (key == "name") {
    184189        std::stringstream linestream("aux_basis = "+value);
    185         linestream >> params;
     190        linestream >> getParams();
    186191      }
    187192    }
     
    227232    *file << "% Created by MoleCuilder" << endl;
    228233    *file << "mpqc: (" << endl;
    229     *file << "\tsavestate = " << params.getString(MpqcParser_Parameters::savestateParam) << endl;
    230     *file << "\tdo_gradient = " << params.getString(MpqcParser_Parameters::do_gradientParam) << endl;
    231     if (params.getBool(MpqcParser_Parameters::hessianParam)) {
     234    *file << "\tsavestate = " << getParams().getString(MpqcParser_Parameters::savestateParam) << endl;
     235    *file << "\tdo_gradient = " << getParams().getString(MpqcParser_Parameters::do_gradientParam) << endl;
     236    if (getParams().getBool(MpqcParser_Parameters::hessianParam)) {
    232237      *file << "\tfreq<MolecularFrequencies>: (" << endl;
    233238      *file << "\t\tmolecule=$:molecule" << endl;
    234239      *file << "\t)" << endl;
    235240    }
    236     switch (params.getTheory()) {
     241    switch (getParams().getTheory()) {
    237242      case MpqcParser_Parameters::CLHF:
    238         *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     243        *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    239244        *file << "\t\tmolecule = $:molecule" << endl;
    240245        *file << "\t\tbasis = $:basis" << endl;
    241         *file << "\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
    242         *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
     246        *file << "\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl;
     247        *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
    243248        *file << "\t)" << endl;
    244249        break;
    245250      case MpqcParser_Parameters::CLKS:
    246         *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     251        *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    247252        *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
    248253        *file << "\t\tmolecule = $:molecule" << endl;
    249254        *file << "\t\tbasis = $:basis" << endl;
    250         *file << "\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
    251         *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
     255        *file << "\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl;
     256        *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
    252257        *file << "\t)" << endl;
    253258        break;
    254259      case MpqcParser_Parameters::MBPT2:
    255         *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     260        *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    256261        *file << "\t\tbasis = $:basis" << endl;
    257262        *file << "\t\tmolecule = $:molecule" << endl;
    258         *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
     263        *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
    259264        *file << "\t\treference<CLHF>: (" << endl;
    260         *file << "\t\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
     265        *file << "\t\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam))<< endl;
    261266        *file << "\t\t\tbasis = $:basis" << endl;
    262267        *file << "\t\t\tmolecule = $:molecule" << endl;
    263         *file << "\t\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
     268        *file << "\t\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
    264269        *file << "\t\t)" << endl;
    265270        *file << "\t)" << endl;
    266271        break;
    267272      case MpqcParser_Parameters::MBPT2_R12:
    268         *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
     273        *file << "\tmole<" << getParams().getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
    269274        *file << "\t\tmolecule = $:molecule" << endl;
    270275        *file << "\t\tbasis = $:basis" << endl;
    271276        *file << "\t\taux_basis = $:abasis" << endl;
    272         *file << "\t\tstdapprox = \"" << params.getString(MpqcParser_Parameters::stdapproxParam) << "\"" << endl;
    273         *file << "\t\tnfzc = " << toString(params.getInt(MpqcParser_Parameters::nfzcParam)) << endl;
    274         *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
     277        *file << "\t\tstdapprox = \"" << getParams().getString(MpqcParser_Parameters::stdapproxParam) << "\"" << endl;
     278        *file << "\t\tnfzc = " << toString(getParams().getInt(MpqcParser_Parameters::nfzcParam)) << endl;
     279        *file << "\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
    275280        *file << "\t\tintegrals<IntegralCints>:()" << endl;
    276281        *file << "\t\treference<CLHF>: (" << endl;
    277282        *file << "\t\t\tmolecule = $:molecule" << endl;
    278283        *file << "\t\t\tbasis = $:basis" << endl;
    279         *file << "\t\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam)) << endl;
    280         *file << "\t\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
    281         *file << "\t\t\tintegrals<" << params.getString(MpqcParser_Parameters::integrationParam) << ">:()" << endl;
     284        *file << "\t\t\tmaxiter = " << toString(getParams().getInt(MpqcParser_Parameters::maxiterParam)) << endl;
     285        *file << "\t\t\tmemory = " << toString(getParams().getInt(MpqcParser_Parameters::memoryParam)) << endl;
     286        *file << "\t\t\tintegrals<" << getParams().getString(MpqcParser_Parameters::integrationParam) << ">:()" << endl;
    282287        *file << "\t\t)" << endl;
    283288        *file << "\t)" << endl;
     
    299304    *file << ")" << endl;
    300305    *file << "basis<GaussianBasisSet>: (" << endl;
    301     *file << "\tname = \"" << params.getString(MpqcParser_Parameters::basisParam) << "\"" << endl;
     306    *file << "\tname = \"" << getParams().getString(MpqcParser_Parameters::basisParam) << "\"" << endl;
    302307    *file << "\tmolecule = $:molecule" << endl;
    303308    *file << ")" << endl;
    304     if (params.getTheory() == MpqcParser_Parameters::MBPT2_R12) {
     309    if (getParams().getTheory() == MpqcParser_Parameters::MBPT2_R12) {
    305310      *file << "% auxiliary basis set specification" << endl;
    306311      *file << "\tabasis<GaussianBasisSet>: (" << endl;
    307       *file << "\tname = \"" << params.getString(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
     312      *file << "\tname = \"" << getParams().getString(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
    308313      *file << "\tmolecule = $:molecule" << endl;
    309314      *file << ")" << endl;
     
    312317}
    313318
    314 MpqcParser_Parameters & MpqcParser::getParams()
    315 {
    316   return params;
    317 }
    318 
     319
  • TabularUnified src/Parser/MpqcParser.hpp

    re611dc rc1db05  
    2929
    3030  MpqcParser();
    31   ~MpqcParser();
     31  virtual ~MpqcParser();
    3232  void load(std::istream* file);
    3333  void save(std::ostream* file, const std::vector<atom *> &atoms);
     
    3737   * @return reference to parameter class
    3838   */
    39   MpqcParser_Parameters & getParams();
    40 
    41 private:
    42   MpqcParser_Parameters params;
     39  MpqcParser_Parameters & getParams() { return *static_cast<MpqcParser_Parameters *>(parameters); }
    4340};
    4441
  • TabularUnified src/Parser/MpqcParser_Parameters.cpp

    re611dc rc1db05  
    3535
    3636MpqcParser_Parameters::MpqcParser_Parameters()
     37{
     38  Init();
     39}
     40
     41void MpqcParser_Parameters::Init()
    3742{
    3843  // add all known basis
     
    106111
    107112  initParameters();
     113}
     114
     115MpqcParser_Parameters::MpqcParser_Parameters(const MpqcParser_Parameters & state)
     116{
     117  // init
     118  Init();
     119
     120  // copy values
     121  copyParameters(state);
     122}
     123
     124void MpqcParser_Parameters::copyParameters(const MpqcParser_Parameters & state)
     125{
     126  appendParameter(hessianParam, state.getBool(hessianParam));
     127  appendParameter(savestateParam, state.getBool(savestateParam));
     128  appendParameter(do_gradientParam, state.getBool(do_gradientParam));
     129  appendParameter(maxiterParam, state.getInt(maxiterParam));
     130  appendParameter(memoryParam, state.getInt(memoryParam));
     131  appendParameter(stdapproxParam, state.getString(stdapproxParam));
     132  appendParameter(nfzcParam, state.getInt(nfzcParam));
     133  appendParameter(basisParam, state.getString(basisParam));
     134  appendParameter(aux_basisParam, state.getString(aux_basisParam));
     135  appendParameter(integrationParam, state.getIntegration());
     136  appendParameter(theoryParam, state.getTheory());
     137}
     138
     139FormatParser_Parameters* MpqcParser_Parameters::clone() const
     140{
     141  //LOG(3, "Cloning parameters.");
     142  MpqcParser_Parameters *instance = new MpqcParser_Parameters(*this);
     143  return instance;
     144}
     145
     146void MpqcParser_Parameters::makeClone(const FormatParser_Parameters & _state)
     147{
     148  //LOG(3, "Cloning parameters from other instance.");
     149  copyParameters(static_cast<const MpqcParser_Parameters &>(_state));
    108150}
    109151
     
    279321}
    280322
    281 enum MpqcParser_Parameters::Parameters MpqcParser_Parameters::getParam(std::string _name)
    282 {
    283   return ParamLookup[_name];
    284 }
    285 
    286 enum MpqcParser_Parameters::IntegrationMethod MpqcParser_Parameters::getIntegration()
    287 {
     323enum MpqcParser_Parameters::Parameters MpqcParser_Parameters::getParam(std::string _name) const
     324{
     325  ParamLookupType::const_iterator iter = ParamLookup.find(_name);
     326  return iter->second;
     327}
     328
     329enum MpqcParser_Parameters::IntegrationMethod MpqcParser_Parameters::getIntegration() const
     330{
     331  parameterlist::const_iterator iter = params.find(integrationParam);
    288332  enum IntegrationMethod value;
    289333  // TODO: throw exception instead of eLog()
    290334//  try {
    291     value = boost::any_cast<enum IntegrationMethod>(params[integrationParam]);
     335    value = boost::any_cast<enum IntegrationMethod>(iter->second);
    292336//  } catch(const boost::bad_any_cast &) {
    293337//    DoeLog(0) && (eLog() << Verbose(0)
     
    298342}
    299343
    300 enum MpqcParser_Parameters::Theory MpqcParser_Parameters::getTheory()
    301 {
     344enum MpqcParser_Parameters::Theory MpqcParser_Parameters::getTheory() const
     345{
     346  parameterlist::const_iterator iter = params.find(theoryParam);
    302347  enum Theory value;
    303348  // TODO: throw exception instead of eLog()
    304349//  try {
    305     value = boost::any_cast<enum Theory>(params[theoryParam]);
     350    value = boost::any_cast<enum Theory>(iter->second);
    306351//  } catch(const boost::bad_any_cast &) {
    307352//    DoeLog(0) && (eLog() << Verbose(0)
     
    312357}
    313358
    314 std::string MpqcParser_Parameters::getString(enum Parameters _param)
     359std::string MpqcParser_Parameters::getString(enum Parameters _param) const
    315360{
    316361  std::string value;
     
    318363  enum Theory Tindex;
    319364  bool test;
     365  parameterlist::const_iterator iter = params.find(_param);
    320366  switch (_param) {
    321367    case hessianParam:
    322368    case savestateParam:
    323369    case do_gradientParam:
    324       test = boost::any_cast<bool>(params[_param]);
     370      test = boost::any_cast<bool>(iter->second);
    325371      if (test)
    326372        value = "yes";
     
    331377      // TODO: throw exception instead of eLog()
    332378//      try {
    333         Iindex = boost::any_cast<enum IntegrationMethod>(params[_param]);
     379        Iindex = boost::any_cast<enum IntegrationMethod>(iter->second);
    334380//      } catch(const boost::bad_any_cast &) {
    335381//        DoeLog(0) && (eLog() << Verbose(0)
     
    337383//            +ParamNames[_param]+" to string!" << std::endl);
    338384//      }
    339       value = IntegrationNames[Iindex];
     385      {
     386        IntegrationNamesType::const_iterator Iiter = IntegrationNames.find(Iindex);
     387        value = Iiter->second;
     388      }
    340389      break;
    341390    case theoryParam:
    342391      // TODO: throw exception instead of eLog()
    343392//      try {
    344         Tindex = boost::any_cast<enum Theory>(params[_param]);
     393        Tindex = boost::any_cast<enum Theory>(iter->second);
    345394//      } catch(const boost::bad_any_cast &) {
    346395//        DoeLog(0) && (eLog() << Verbose(0)
     
    348397//            +ParamNames[_param]+" to string!" << std::endl);
    349398//      }
    350       value = TheoryNames[(enum Theory)Tindex];
     399        {
     400          TheoryNamesType::const_iterator Titer = TheoryNames.find(Tindex);
     401          value = Titer->second;
     402        }
    351403      break;
    352404    default:
    353405      // TODO: throw exception instead of eLog()
    354406//      try {
    355         value = boost::any_cast<std::string>(params[_param]);
     407        value = boost::any_cast<std::string>(iter->second);
    356408//      } catch(const boost::bad_any_cast &) {
    357409//        DoeLog(0) && (eLog() << Verbose(0)
     
    365417}
    366418
    367 int MpqcParser_Parameters::getInt(enum Parameters _param)
     419int MpqcParser_Parameters::getInt(enum Parameters _param) const
    368420{
    369421  int value;
     422  parameterlist::const_iterator iter = params.find(_param);
    370423  switch (_param) {
    371424    default:
    372425      // TODO: throw exception instead of eLog()
    373426//      try {
    374         value = boost::any_cast<int>(params[_param]);
     427        value = boost::any_cast<int>(iter->second);
    375428//      } catch(const boost::bad_any_cast &) {
    376429//        DoeLog(0) && (eLog() << Verbose(0)
     
    383436}
    384437
    385 double MpqcParser_Parameters::getDouble(enum Parameters _param)
     438double MpqcParser_Parameters::getDouble(enum Parameters _param) const
    386439{
    387440  double value;
    388   // TODO: throw exception instead of eLog()
    389 //  try {
    390     value = boost::any_cast<double>(params[_param]);
     441  parameterlist::const_iterator iter = params.find(_param);
     442  // TODO: throw exception instead of eLog()
     443//  try {
     444    value = boost::any_cast<double>(iter->second);
    391445//  } catch(const boost::bad_any_cast &) {
    392446//    DoeLog(0) && (eLog() << Verbose(0)
     
    397451}
    398452
    399 bool MpqcParser_Parameters::getBool(enum Parameters _param)
     453bool MpqcParser_Parameters::getBool(enum Parameters _param) const
    400454{
    401455  bool value;
    402   // TODO: throw exception instead of eLog()
    403 //  try {
    404     value = boost::any_cast<bool>(params[_param]);
     456  parameterlist::const_iterator iter = params.find(_param);
     457  // TODO: throw exception instead of eLog()
     458//  try {
     459    value = boost::any_cast<bool>(iter->second);
    405460//  } catch(const boost::bad_any_cast &) {
    406461//    DoeLog(0) && (eLog() << Verbose(0)
  • TabularUnified src/Parser/MpqcParser_Parameters.hpp

    re611dc rc1db05  
    1919#include <vector>
    2020
     21#include "CodePatterns/Clone.hpp"
    2122#include "CodePatterns/Log.hpp"
    2223#include "CodePatterns/Verbose.hpp"
     
    2425#include <boost/any.hpp>
    2526
     27#include "Parser/FormatParser_Parameters.hpp"
    2628
    2729class MpqcParser;
    2830
    29 class MpqcParser_Parameters
     31class MpqcParser_Parameters : public FormatParser_Parameters
    3032{
    3133  // MpqcParser should be friend to access params directly for types.
     
    4042  MpqcParser_Parameters();
    4143
     44  /** Copy Constructor of MpqcParser_Parameters.
     45   *
     46   * @param state ref to instance to copy
     47   */
     48  MpqcParser_Parameters(const MpqcParser_Parameters & state);
     49
    4250  /** Destructor of MpqcParser_Parameters.
    4351   *
    4452   */
    45   ~MpqcParser_Parameters();
     53  virtual ~MpqcParser_Parameters();
    4654
    4755  /** Enumeration of all known theories.
     
    99107   * @return enumeration index of IntegrationMethod.
    100108   */
    101   enum IntegrationMethod getIntegration();
     109  enum IntegrationMethod getIntegration() const;
    102110
    103111  /** Getter for current Theory in params.
     
    105113   * @return enumeration index of Theory
    106114   */
    107   enum Theory getTheory();
     115  enum Theory getTheory() const;
    108116
    109117  /** Getter for a parameter in params as a string.
     
    112120   * @return string value
    113121   */
    114   std::string getString(enum Parameters _param);
     122  std::string getString(enum Parameters _param) const;
    115123
    116124  /** Getter for integer value of desired Parameter in params.
     
    121129   * @return integer value of parameter
    122130   */
    123   int getInt(enum Parameters _param);
     131  int getInt(enum Parameters _param) const;
    124132
    125133  /** Getter for double value of desired Parameter in params.
     
    130138   * @return double value of parameter
    131139   */
    132   double getDouble(enum Parameters _param);
     140  double getDouble(enum Parameters _param) const;
    133141
    134142  /** Getter for bool value of desired Parameter in params.
     
    139147   * @return bool value of parameter
    140148   */
    141   bool getBool(enum Parameters _param);
     149  bool getBool(enum Parameters _param) const;
    142150
    143151  /** Setter for a desired value of its type is known.
     
    178186   * @return enumeration index of Parameters
    179187   */
    180   enum Parameters getParam(std::string _name);
     188  enum Parameters getParam(std::string _name) const;
    181189
    182190  /** Checker whether parameter with name is known.
     
    187195  bool haveParam(std::string _name) const;
    188196
     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
    189215private:
     216  /** Global initialization in cstor.
     217   *
     218   */
     219  void Init();
     220
    190221  /** Initializes BasisList.
    191222   *
  • TabularUnified src/Parser/unittests/ParserMpqcUnitTest.cpp

    re611dc rc1db05  
    178178void ParserMpqcUnitTest::ParameterTypeTest() {
    179179  // check types in boost::any map
    180   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));
    181   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::hessianParam].type() != typeid(int));
    182   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));
    183   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));
    184   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));
    185   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::memoryParam].type() == typeid(int));
    186   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));
    187   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));
    188   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));
    189   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));
    190   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));
    191   CPPUNIT_ASSERT(mpqc->params.params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));
     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));
    192192}
    193193
    194194void ParserMpqcUnitTest::ParameterDefaultTest() {
    195195  // check default values
    196   CPPUNIT_ASSERT(mpqc->params.getString(MpqcParser_Parameters::hessianParam) == "no");
    197   CPPUNIT_ASSERT(!mpqc->params.getBool(MpqcParser_Parameters::hessianParam));
    198   CPPUNIT_ASSERT(mpqc->params.getString(MpqcParser_Parameters::savestateParam) == "no");
    199   CPPUNIT_ASSERT(!mpqc->params.getBool(MpqcParser_Parameters::savestateParam));
    200   CPPUNIT_ASSERT(mpqc->params.getString(MpqcParser_Parameters::do_gradientParam) == "yes");
    201   CPPUNIT_ASSERT(mpqc->params.getBool(MpqcParser_Parameters::do_gradientParam));
    202   CPPUNIT_ASSERT(mpqc->params.getInt(MpqcParser_Parameters::maxiterParam) == 1000);
    203   CPPUNIT_ASSERT(mpqc->params.getInt(MpqcParser_Parameters::memoryParam) == 16000000);
    204   CPPUNIT_ASSERT(mpqc->params.getString(MpqcParser_Parameters::stdapproxParam) == "A'");
    205   CPPUNIT_ASSERT(mpqc->params.getInt(MpqcParser_Parameters::nfzcParam) == 1);
    206   CPPUNIT_ASSERT(mpqc->params.getString(MpqcParser_Parameters::basisParam) == "3-21G");
    207   CPPUNIT_ASSERT(mpqc->params.getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ");
    208   CPPUNIT_ASSERT(mpqc->params.getString(MpqcParser_Parameters::integrationParam) == "IntegralCints");
    209   CPPUNIT_ASSERT(mpqc->params.getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    210   CPPUNIT_ASSERT(mpqc->params.getTheory() == MpqcParser_Parameters::MBPT2);
    211   CPPUNIT_ASSERT(mpqc->params.getIntegration() == MpqcParser_Parameters::IntegralCints);
     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);
    212212
    213213  // check that values are not removed
    214   CPPUNIT_ASSERT(!mpqc->params.params[MpqcParser_Parameters::theoryParam].empty());
     214  CPPUNIT_ASSERT(!mpqc->getParams().params[MpqcParser_Parameters::theoryParam].empty());
    215215
    216216  // check throw, for the moment aren't, are caught in getInt()
    217   CPPUNIT_ASSERT_THROW(mpqc->params.getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);
    218   CPPUNIT_ASSERT_THROW(mpqc->params.getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);
    219 
     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
     220}
     221
     222void ParserMpqcUnitTest::ParameterCloneTest() {
     223  FormatParser_Parameters *clone = mpqc->getParams().clone();
     224  CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     225  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");
    220230}
    221231
     
    224234  {
    225235    std::stringstream setvalue("theory = CLHF");
    226     setvalue >> mpqc->params;
     236    setvalue >> mpqc->getParams();
    227237//    std::cout << "integration method is "
    228 //        << mpqc->params.getString(MpqcParser_Parameters::theoryParam) << std::endl;
    229     CPPUNIT_ASSERT(mpqc->params.getString(MpqcParser_Parameters::theoryParam) == "CLHF");
     238//        << mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
     239    CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
    230240  }
    231241  // test a bool
    232242  {
    233243    std::stringstream setvalue("Hessian = yes");
    234     setvalue >> mpqc->params;
     244    setvalue >> mpqc->getParams();
    235245//    std::cout << "Hessian is "
    236 //        << mpqc->params.getString(MpqcParser_Parameters::hessianParam) << std::endl;
    237     CPPUNIT_ASSERT(mpqc->params.getString(MpqcParser_Parameters::hessianParam) == "yes");
     246//        << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
     247    CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
    238248  }
    239249  // test int
    240250  {
    241251    std::stringstream setvalue("maxiter = 500");
    242     setvalue >> mpqc->params;
     252    setvalue >> mpqc->getParams();
    243253//    std::cout << "maxiter is "
    244 //        << mpqc->params.getString(MpqcParser_Parameters::maxiterParam) << std::endl;
    245     CPPUNIT_ASSERT(mpqc->params.getInt(MpqcParser_Parameters::maxiterParam) == 500);
     254//        << mpqc->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
     255    CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);
    246256  }
    247257  // test whether unknown key fails
     
    251261#ifndef NDEBUG
    252262    ASSERT_DO(Assert::Throw);
    253     CPPUNIT_ASSERT_THROW(setvalue >> mpqc->params, Assert::AssertionFailure);
     263    CPPUNIT_ASSERT_THROW(setvalue >> mpqc->getParams(), Assert::AssertionFailure);
    254264#else
    255     setvalue >> mpqc->params;
     265    setvalue >> mpqc->getParams();
    256266#endif
    257267//    std::cout << "Hessian is still "
    258 //        << mpqc->params.getString(MpqcParser_Parameters::hessianParam) << std::endl;
    259     CPPUNIT_ASSERT(mpqc->params.getString(MpqcParser_Parameters::hessianParam) == "yes");
     268//        << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
     269    CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
    260270  }
    261271}
     
    263273void ParserMpqcUnitTest::readMpqcTest() {
    264274  stringstream input(waterMpqc_CLHF);
    265   mpqc->params.setTheory(MpqcParser_Parameters::CLHF);
     275  mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);
    266276  mpqc->load(&input);
    267277
     
    291301    // compare both configs for CLHF
    292302    stringstream output;
    293     mpqc->params.setTheory(MpqcParser_Parameters::CLHF);
     303    mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);
    294304    mpqc->save(&output, atoms);
    295305    stringstream input(waterMpqc_CLHF);
     
    302312    // compare both configs for CLKS
    303313    stringstream output;
    304     mpqc->params.setTheory(MpqcParser_Parameters::CLKS);
     314    mpqc->getParams().setTheory(MpqcParser_Parameters::CLKS);
    305315    mpqc->save(&output, atoms);
    306316    stringstream input(waterMpqc_CLKS);
     
    313323    // compare both configs for MBPT2
    314324    stringstream output;
    315     mpqc->params.setTheory(MpqcParser_Parameters::MBPT2);
     325    mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2);
    316326    mpqc->save(&output, atoms);
    317327    stringstream input(waterMpqc_MBPT2);
     
    324334    // compare both configs for MBPT2_R12
    325335    stringstream output;
    326     mpqc->params.setTheory(MpqcParser_Parameters::MBPT2_R12);
     336    mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12);
    327337    mpqc->save(&output, atoms);
    328338    stringstream input(waterMpqc_MBPT2_R12);
  • TabularUnified src/Parser/unittests/ParserMpqcUnitTest.hpp

    re611dc rc1db05  
    2424  CPPUNIT_TEST ( ParameterDefaultTest );
    2525  CPPUNIT_TEST ( ParameterSetterTest );
     26  CPPUNIT_TEST ( ParameterCloneTest );
    2627  CPPUNIT_TEST ( readMpqcTest );
    2728  CPPUNIT_TEST ( writeMpqcTest );
     
    3536  void ParameterDefaultTest();
    3637  void ParameterSetterTest();
     38  void ParameterCloneTest();
    3739  void readMpqcTest();
    3840  void writeMpqcTest();
Note: See TracChangeset for help on using the changeset viewer.