source: src/Parser/MpqcParser_Parameters.cpp@ f758dd

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
Last change on this file since f758dd was ee50c1, checked in by Frederik Heber <heber@…>, 13 years ago

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.
  • Property mode set to 100644
File size: 9.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * MpqcParser_Parameters.cpp
10 *
11 * Created on: Feb 3, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include <iostream>
21#include <boost/tokenizer.hpp>
22#include <string>
23
24#include "CodePatterns/MemDebug.hpp"
25
26#include "CodePatterns/Log.hpp"
27
28#include "MpqcParser.hpp"
29
30#include "MpqcParser_Parameters.hpp"
31
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
60
61MpqcParser_Parameters::MpqcParser_Parameters()
62{
63 Init();
64}
65
66void MpqcParser_Parameters::Init()
67{
68 // add all known basis
69 initBasis();
70
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 }
128}
129
130MpqcParser_Parameters::~MpqcParser_Parameters()
131{}
132
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)
192{
193 // this is ugly, but with boost::any to safeguard const-ness is plain impossible
194 std::ostringstream output;
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) << ";";
199 ost << output.str();
200 return ost;
201}
202
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 */
209std::istream & operator >> (std::istream& ist, MpqcParser_Parameters &params)
210{
211 typedef boost::tokenizer<boost::char_separator<char> >
212 tokenizer;
213 boost::char_separator<char> semicolonsep(";");
214 boost::char_separator<char> equalitysep(" =");
215 boost::char_separator<char> ticksep("\"");
216 std::string line;
217 std::getline( ist, line );
218 //DoLog(0) && (Log() << Verbose(0) << "INFO: full line of parameters is '" << line << "'" << std::endl);
219 tokenizer tokens(line, semicolonsep);
220 ASSERT(tokens.begin() != tokens.end(),
221 "operator<< on MpqcParser_Parameters - empty string, need at least ';' in line "+line+"!");
222 for (tokenizer::iterator tok_iter = tokens.begin();
223 tok_iter != tokens.end(); ++tok_iter) {
224 tokenizer paramtokens(*tok_iter, equalitysep);
225 if (paramtokens.begin() != paramtokens.end()) {
226 tokenizer::iterator tok_paramiter = paramtokens.begin();
227 tokenizer::iterator tok_valueiter = tok_paramiter;
228 tokenizer::iterator tok_checkiter = ++tok_valueiter;
229 ++tok_checkiter;
230 // TODO: throw exception instead of ASSERT
231 ASSERT(tok_paramiter != paramtokens.end(),
232 "operator<< on MpqcParser_Parameters - missing value before ' =' in token "+*tok_iter+"!");
233 ASSERT(tok_valueiter != paramtokens.end(),
234 "operator<< on MpqcParser_Parameters - missing value after ' =' in token "+*tok_iter+"!");
235 ASSERT(tok_checkiter == paramtokens.end(),
236 "operator<< on MpqcParser_Parameters - still more tokens after ' =' in token "+*tok_iter+":"
237 +*tok_checkiter+"!");
238 std::stringstream keystream(*tok_paramiter);
239 std::string key;
240 keystream >> ws >> key;
241 tokenizer ticklesstokens(*tok_valueiter, ticksep);
242 ASSERT(ticklesstokens.begin() != ticklesstokens.end(),
243 "operator<< on MpqcParser_Parameters - no tokens present after removing ticks in token "+*tok_valueiter+"!");
244 std::stringstream valuestream(*(ticklesstokens.begin()));
245 DoLog(2) && (Log() << Verbose(2)
246 << "INFO: Token pair is " << key << "," << valuestream.str() << std::endl);
247
248 // TODO: throw exception instead of DoeLog()
249 ASSERT(params.haveParameter(key),
250 "operator >> on MpqcParser_Parameters - unknown parameter name '"
251 +key+"' with value "+valuestream.str()+"!");
252 if (params.haveParameter(key)) {
253 Parameter *instance = params.FormatParser_Parameters::getParameter(key);
254 instance->set(valuestream.str());
255 }
256 } else {
257 ist.setstate(std::ios::eofbit);
258 }
259 }
260 return ist;
261}
262
263/** Checks whether all elements in the world also have parameters in the basis.
264 *
265 * @return true - all elements parametrized, false - at least one element is missing.
266 */
267bool MpqcParser_Parameters::checkWorldElementsAgainstCurrentBasis() const
268{
269 DoeLog(0) && (eLog() << Verbose(0)
270 << "MpqcParser_Parameters::checkWorldElementsAgainstCurrentBasis() - not implemented yet."
271 << std::endl);
272
273 return false;
274}
275
Note: See TracBrowser for help on using the repository browser.