source: src/Parser/MpqcParser_Parameters.hpp@ bcedf7

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 bcedf7 was c1db05, checked in by Frederik Heber <heber@…>, 13 years ago

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.
  • Property mode set to 100644
File size: 8.8 KB
Line 
1/*
2 * MpqcParser_Parameters.hpp
3 *
4 * Created on: Feb 3, 2011
5 * Author: heber
6 */
7
8#ifndef MPQCPARSER_PARAMETERS_HPP_
9#define MPQCPARSER_PARAMETERS_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <iosfwd>
17#include <list>
18#include <typeinfo>
19#include <vector>
20
21#include "CodePatterns/Clone.hpp"
22#include "CodePatterns/Log.hpp"
23#include "CodePatterns/Verbose.hpp"
24
25#include <boost/any.hpp>
26
27#include "Parser/FormatParser_Parameters.hpp"
28
29class MpqcParser;
30
31class MpqcParser_Parameters : public FormatParser_Parameters
32{
33 // MpqcParser should be friend to access params directly for types.
34 friend class MpqcParser;
35 // ParserMpqcUnitTest needs to be friend to check types contained in params.
36 friend class ParserMpqcUnitTest;
37
38public:
39 /** Constructor of MpqcParser_Parameters.
40 *
41 */
42 MpqcParser_Parameters();
43
44 /** Copy Constructor of MpqcParser_Parameters.
45 *
46 * @param state ref to instance to copy
47 */
48 MpqcParser_Parameters(const MpqcParser_Parameters & state);
49
50 /** Destructor of MpqcParser_Parameters.
51 *
52 */
53 virtual ~MpqcParser_Parameters();
54
55 /** Enumeration of all known theories.
56 *
57 */
58 enum Theory {
59 CLHF, //!< Closed Shell Hartree-Fock equations
60 CLKS, //!< Closed Shell Kohn-Sham equations
61 MBPT2, //!< Moeller Plesset Perturbation Theory second order
62 MBPT2_R12, //!< Moeller Plesset Perturbation Theory second order with R12 integral
63 unknownTheory //!< designates an unknown theory
64 };
65
66 /** Enumeration of all known integration methods
67 *
68 */
69 enum IntegrationMethod {
70 IntegralCints, //!< Integration method Cints in MBPT2 R12?
71 unknownIntegration //!< designates unknown integration method
72 };
73
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
90
91 bool checkWorldElementsAgainstCurrentBasis() const;
92
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
215private:
216 /** Global initialization in cstor.
217 *
218 */
219 void Init();
220
221 /** Initializes BasisList.
222 *
223 */
224 void initBasis();
225
226 /** Initializes params.
227 * Sets the type and the associated enumeration index.
228 */
229 void initParameters();
230
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 }
240
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
257 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;
270};
271
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 */
278std::ostream & operator << (std::ostream& ost, const MpqcParser_Parameters &params);
279
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 */
286std::istream & operator >> (std::istream& ist, MpqcParser_Parameters &params);
287
288#endif /* MPQCPARSER_PARAMETERS_HPP_ */
Note: See TracBrowser for help on using the repository browser.