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 | * Psi3Parser_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 "Psi3Parser.hpp"
|
---|
29 |
|
---|
30 | #include "Psi3Parser_Parameters.hpp"
|
---|
31 |
|
---|
32 | #include "Parser/Parameters/ContinuousParameter.hpp"
|
---|
33 | #include "Parser/Parameters/DiscreteParameter.hpp"
|
---|
34 | #include "Parser/Parameters/StringParameter.hpp"
|
---|
35 |
|
---|
36 | // TODO: ContinuousValue<bool>::get() must be defined inline otherwise we get multiple definition of virtual thunk compilation errors
|
---|
37 | template <>
|
---|
38 | inline const std::string ContinuousValue<bool>::get() const
|
---|
39 | {
|
---|
40 | ASSERT(ValueSet,
|
---|
41 | "ContinuousValue<bool>::get() - requesting unset value.");
|
---|
42 | if (value)
|
---|
43 | return std::string("yes");
|
---|
44 | else
|
---|
45 | return std::string("no");
|
---|
46 | }
|
---|
47 |
|
---|
48 | // TODO: ContinuousValue<bool>::set must be defined inline otherwise we get multiple definition of virtual thunk compilation errors
|
---|
49 | template <>
|
---|
50 | inline void ContinuousValue<bool>::set(const std::string _value)
|
---|
51 | {
|
---|
52 | if (_value == std::string("yes")) {
|
---|
53 | setValue(true);
|
---|
54 | } else if (_value == std::string("no")) {
|
---|
55 | setValue(false);
|
---|
56 | } else {
|
---|
57 | ASSERT(0,
|
---|
58 | "void ContinuousValue<bool>::set() - value "+_value+" is neither yes or no.");
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | Psi3Parser_Parameters::Psi3Parser_Parameters()
|
---|
64 | {
|
---|
65 | Init();
|
---|
66 | }
|
---|
67 |
|
---|
68 | void Psi3Parser_Parameters::Init()
|
---|
69 | {
|
---|
70 | // add all known basis
|
---|
71 | //initBasis();
|
---|
72 |
|
---|
73 | // add all parameter names
|
---|
74 | {
|
---|
75 | ParamNames.clear();
|
---|
76 | ParamNames.resize(unknownParam);
|
---|
77 | ParamNames[labelParam] = "label";
|
---|
78 | ParamNames[jobtypeParam] = "jobtype";
|
---|
79 | ParamNames[wavefunctionParam] = "wfn";
|
---|
80 | ParamNames[maxiterParam] = "maxiter";
|
---|
81 | ParamNames[referenceParam] = "reference";
|
---|
82 | ParamNames[basisParam] = "basis";
|
---|
83 | ParamNames[freeze_coreParam] = "freeze_core";
|
---|
84 | ParamNames[unitsParam] = "units";
|
---|
85 | ParamNames[dertypeParam] = "dertype";
|
---|
86 | ParamNames[originParam] = "origin";
|
---|
87 | ParamNames[multipParam] = "multip";
|
---|
88 | ParamNames[chargeParam] = "charge";
|
---|
89 | ParamNames[soccParam] = "socc";
|
---|
90 | ParamNames[doccParam] = "docc";
|
---|
91 | ParamNames[subgroupParam] = "subgroup";
|
---|
92 | ParamNames[unique_axisParam] = "unique_axis";
|
---|
93 | }
|
---|
94 |
|
---|
95 | // create freeze_core parameter
|
---|
96 | {
|
---|
97 | ValidFreezeCore.clear();
|
---|
98 | ValidFreezeCore.resize(unknownFreezeCore);
|
---|
99 | ValidFreezeCore[YES]="yes";
|
---|
100 | ValidFreezeCore[TRUE]="true";
|
---|
101 | ValidFreezeCore[NO]="no";
|
---|
102 | ValidFreezeCore[FALSE]="false";
|
---|
103 | ValidFreezeCore[SMALL]="small";
|
---|
104 | ValidFreezeCore[LARGE]="large";
|
---|
105 | appendParameter(
|
---|
106 | new DiscreteParameter<std::string>(
|
---|
107 | ParamNames[freeze_coreParam],
|
---|
108 | ValidFreezeCore,
|
---|
109 | ValidFreezeCore[YES]));
|
---|
110 | }
|
---|
111 |
|
---|
112 | // create units parameter
|
---|
113 | {
|
---|
114 | ValidUnits.clear();
|
---|
115 | ValidUnits.resize(unknownUnits);
|
---|
116 | ValidUnits[angstrom]="angstrom";
|
---|
117 | ValidUnits[bohr]="bohr";
|
---|
118 | appendParameter(
|
---|
119 | new DiscreteParameter<std::string>(
|
---|
120 | ParamNames[unitsParam],
|
---|
121 | ValidUnits,
|
---|
122 | ValidUnits[angstrom]));
|
---|
123 | }
|
---|
124 |
|
---|
125 | // create dertype parameter
|
---|
126 | {
|
---|
127 | ValidDerivativeType.clear();
|
---|
128 | ValidDerivativeType.resize(unknownDerivativeType);
|
---|
129 | ValidDerivativeType[NONE]="none";
|
---|
130 | appendParameter(
|
---|
131 | new DiscreteParameter<std::string>(
|
---|
132 | ParamNames[dertypeParam],
|
---|
133 | ValidDerivativeType,
|
---|
134 | ValidDerivativeType[NONE]));
|
---|
135 | }
|
---|
136 |
|
---|
137 | // create unique_axis parameter
|
---|
138 | {
|
---|
139 | ValidUniqueAxis.clear();
|
---|
140 | ValidUniqueAxis.resize(unknownUniqueAxis);
|
---|
141 | ValidUniqueAxis[X]="x";
|
---|
142 | ValidUniqueAxis[Y]="y";
|
---|
143 | ValidUniqueAxis[Z]="z";
|
---|
144 | appendParameter(
|
---|
145 | new DiscreteParameter<std::string>(
|
---|
146 | ParamNames[unique_axisParam],
|
---|
147 | ValidUniqueAxis,
|
---|
148 | ValidUniqueAxis[X]));
|
---|
149 | }
|
---|
150 |
|
---|
151 | // create jobtype parameter
|
---|
152 | {
|
---|
153 | ValidJobtypes.clear();
|
---|
154 | ValidJobtypes.resize(unknownJobtype);
|
---|
155 | ValidJobtypes[SP]="sp";
|
---|
156 | ValidJobtypes[OPT]="opt";
|
---|
157 | ValidJobtypes[DISP]="disp";
|
---|
158 | ValidJobtypes[FREQ]="freq";
|
---|
159 | ValidJobtypes[SYMM_FREQ]="symm_freq";
|
---|
160 | ValidJobtypes[DBOC]="dboc";
|
---|
161 | ValidJobtypes[RESPONSE]="response";
|
---|
162 | appendParameter(
|
---|
163 | new DiscreteParameter<std::string>(
|
---|
164 | ParamNames[jobtypeParam],
|
---|
165 | ValidJobtypes,
|
---|
166 | ValidJobtypes[SP]));
|
---|
167 | }
|
---|
168 |
|
---|
169 | // create wavefunction parameter
|
---|
170 | {
|
---|
171 | ValidWavefunction.clear();
|
---|
172 | ValidWavefunction.resize(unknownWavefunction);
|
---|
173 | ValidWavefunction[SCF]="scf";
|
---|
174 | ValidWavefunction[MP2]="mp2";
|
---|
175 | ValidWavefunction[MP2R12]="mp2r12";
|
---|
176 | ValidWavefunction[CIS]="cis";
|
---|
177 | ValidWavefunction[DETCI]="detci";
|
---|
178 | ValidWavefunction[CASSCF]="casscf";
|
---|
179 | ValidWavefunction[RASSCF]="rasscf";
|
---|
180 | ValidWavefunction[CCSD]="ccsd";
|
---|
181 | ValidWavefunction[CCSD_T]="ccsd_t";
|
---|
182 | ValidWavefunction[BCCD]="bccd";
|
---|
183 | ValidWavefunction[BCCD_T]="bccd_t";
|
---|
184 | ValidWavefunction[EOM_CCSD]="eom_ccsd";
|
---|
185 | ValidWavefunction[ZAPTN]="zaptn";
|
---|
186 | appendParameter(
|
---|
187 | new DiscreteParameter<std::string>(
|
---|
188 | ParamNames[wavefunctionParam],
|
---|
189 | ValidWavefunction,
|
---|
190 | ValidWavefunction[SCF]));
|
---|
191 | }
|
---|
192 |
|
---|
193 | // create reference parameter
|
---|
194 | {
|
---|
195 | ValidReference.clear();
|
---|
196 | ValidReference.resize(unknownReference);
|
---|
197 | ValidReference[RHF]="rhf";
|
---|
198 | ValidReference[ROHF]="rohf";
|
---|
199 | ValidReference[UHF]="uhf";
|
---|
200 | ValidReference[TWOCON]="twocon";
|
---|
201 | appendParameter(
|
---|
202 | new DiscreteParameter<std::string>(
|
---|
203 | ParamNames[referenceParam],
|
---|
204 | ValidReference,
|
---|
205 | ValidReference[RHF]));
|
---|
206 | }
|
---|
207 |
|
---|
208 | // add all continuous parameters
|
---|
209 | {
|
---|
210 | appendParameter(new StringParameter(ParamNames[labelParam], std::string("unknown job")));
|
---|
211 | appendParameter(new ContinuousParameter<int>(ParamNames[maxiterParam], 80));
|
---|
212 | appendParameter(new StringParameter(ParamNames[basisParam], std::string("cc-pVTZ")));
|
---|
213 | appendParameter(new StringParameter(ParamNames[originParam], std::string("(0.0\t0.0\t0.0)"))); // TODO: this should be a vector
|
---|
214 | appendParameter(new ContinuousParameter<int>(ParamNames[multipParam], 1));
|
---|
215 | appendParameter(new ContinuousParameter<int>(ParamNames[chargeParam], 0));
|
---|
216 | appendParameter(new StringParameter(ParamNames[soccParam], std::string("()")));
|
---|
217 | appendParameter(new StringParameter(ParamNames[doccParam], std::string("()")));
|
---|
218 | appendParameter(new StringParameter(ParamNames[subgroupParam], std::string("")));
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | Psi3Parser_Parameters::~Psi3Parser_Parameters()
|
---|
223 | {}
|
---|
224 |
|
---|
225 | /** Getter for a specific Parameter.
|
---|
226 | *
|
---|
227 | * @param param index among enum Parameters
|
---|
228 | * @return value of the desired Parameters
|
---|
229 | */
|
---|
230 | const std::string Psi3Parser_Parameters::getParameter(const enum Parameters param) const
|
---|
231 | {
|
---|
232 | return FormatParser_Parameters::getParameter(ParamNames[param])->get();
|
---|
233 | }
|
---|
234 |
|
---|
235 | /** Setter for a specific Parameter.
|
---|
236 | *
|
---|
237 | * @param param index among enum Parameters
|
---|
238 | * @param _value value to set desired Parameter to
|
---|
239 | */
|
---|
240 | void Psi3Parser_Parameters::setParameter(const enum Parameters param, const std::string &_value)
|
---|
241 | {
|
---|
242 | const std::string &name = getParameterName(param);
|
---|
243 | FormatParser_Parameters::getParameter(name)->set(_value);
|
---|
244 | }
|
---|
245 |
|
---|
246 | /** Getter for name of a specific Parameter.
|
---|
247 | *
|
---|
248 | * @param param index among enum Parameters
|
---|
249 | * @return name of the desired Parameter
|
---|
250 | */
|
---|
251 | const std::string &Psi3Parser_Parameters::getParameterName(const enum Parameters param) const
|
---|
252 | {
|
---|
253 | return ParamNames[param];
|
---|
254 | }
|
---|
255 |
|
---|
256 | ///** Getter for name of a specific Parameter.
|
---|
257 | // *
|
---|
258 | // * @param param index among enum Theory
|
---|
259 | // * @return name of the desired Theory
|
---|
260 | // */
|
---|
261 | //const std::string &Psi3Parser_Parameters::getTheoryName(const enum Theory theory) const
|
---|
262 | //{
|
---|
263 | // return ValidTheories[theory];
|
---|
264 | //}
|
---|
265 | //
|
---|
266 | ///** Getter for the name of specific of IntegrationMethod.
|
---|
267 | // *
|
---|
268 | // * @param param index among enum IntegrationMethod
|
---|
269 | // * @return value of the desired IntegrationMethod
|
---|
270 | // */
|
---|
271 | //const std::string &Psi3Parser_Parameters::getIntegrationMethodName(const enum IntegrationMethod integration) const
|
---|
272 | //{
|
---|
273 | // return ValidIntegrationMethods[integration];
|
---|
274 | //}
|
---|
275 |
|
---|
276 |
|
---|
277 | /** Output operator for the contents of Psi3Parser_Parameters::params.
|
---|
278 | *
|
---|
279 | * @param ost output stream
|
---|
280 | * @param params reference to Psi3Parser_Parameters containing params.
|
---|
281 | * @return reference to output stream for concatenation
|
---|
282 | */
|
---|
283 | std::ostream & operator << (std::ostream& ost, const Psi3Parser_Parameters ¶ms)
|
---|
284 | {
|
---|
285 | // this is ugly, but with boost::any to safeguard const-ness is plain impossible
|
---|
286 | std::ostringstream output;
|
---|
287 | for (size_t param = (enum Psi3Parser_Parameters::Parameters)0;
|
---|
288 | param < (size_t)Psi3Parser_Parameters::unknownParam; ++param)
|
---|
289 | output << params.getParameterName((enum Psi3Parser_Parameters::Parameters)param)
|
---|
290 | << "=" << params.getParameter((enum Psi3Parser_Parameters::Parameters)param) << ";";
|
---|
291 | ost << output.str();
|
---|
292 | return ost;
|
---|
293 | }
|
---|
294 |
|
---|
295 | /** Input operator for a list of parameters to place into \a params.
|
---|
296 | *
|
---|
297 | * @param ist input stream
|
---|
298 | * @param params parameters to parse into
|
---|
299 | * @return input stream for concatenation
|
---|
300 | */
|
---|
301 | std::istream & operator >> (std::istream& ist, Psi3Parser_Parameters ¶ms)
|
---|
302 | {
|
---|
303 | typedef boost::tokenizer<boost::char_separator<char> >
|
---|
304 | tokenizer;
|
---|
305 | boost::char_separator<char> semicolonsep(";");
|
---|
306 | boost::char_separator<char> equalitysep(" =");
|
---|
307 | boost::char_separator<char> ticksep("\"");
|
---|
308 | std::string line;
|
---|
309 | std::getline( ist, line );
|
---|
310 | //DoLog(0) && (Log() << Verbose(0) << "INFO: full line of parameters is '" << line << "'" << std::endl);
|
---|
311 | tokenizer tokens(line, semicolonsep);
|
---|
312 | ASSERT(tokens.begin() != tokens.end(),
|
---|
313 | "operator<< on Psi3Parser_Parameters - empty string, need at least ';' in line "+line+"!");
|
---|
314 | for (tokenizer::iterator tok_iter = tokens.begin();
|
---|
315 | tok_iter != tokens.end(); ++tok_iter) {
|
---|
316 | tokenizer paramtokens(*tok_iter, equalitysep);
|
---|
317 | if (paramtokens.begin() != paramtokens.end()) {
|
---|
318 | tokenizer::iterator tok_paramiter = paramtokens.begin();
|
---|
319 | tokenizer::iterator tok_valueiter = tok_paramiter;
|
---|
320 | tokenizer::iterator tok_checkiter = ++tok_valueiter;
|
---|
321 | ++tok_checkiter;
|
---|
322 | // TODO: throw exception instead of ASSERT
|
---|
323 | ASSERT(tok_paramiter != paramtokens.end(),
|
---|
324 | "operator<< on Psi3Parser_Parameters - missing value before ' =' in token "+*tok_iter+"!");
|
---|
325 | ASSERT(tok_valueiter != paramtokens.end(),
|
---|
326 | "operator<< on Psi3Parser_Parameters - missing value after ' =' in token "+*tok_iter+"!");
|
---|
327 | ASSERT(tok_checkiter == paramtokens.end(),
|
---|
328 | "operator<< on Psi3Parser_Parameters - still more tokens after ' =' in token "+*tok_iter+":"
|
---|
329 | +*tok_checkiter+"!");
|
---|
330 | std::stringstream keystream(*tok_paramiter);
|
---|
331 | std::string key;
|
---|
332 | keystream >> ws >> key;
|
---|
333 | tokenizer ticklesstokens(*tok_valueiter, ticksep);
|
---|
334 | ASSERT(ticklesstokens.begin() != ticklesstokens.end(),
|
---|
335 | "operator<< on Psi3Parser_Parameters - no tokens present after removing ticks in token "+*tok_valueiter+"!");
|
---|
336 | std::stringstream valuestream(*(ticklesstokens.begin()));
|
---|
337 | DoLog(2) && (Log() << Verbose(2)
|
---|
338 | << "INFO: Token pair is " << key << "," << valuestream.str() << std::endl);
|
---|
339 |
|
---|
340 | // TODO: throw exception instead of DoeLog()
|
---|
341 | ASSERT(params.haveParameter(key),
|
---|
342 | "operator >> on Psi3Parser_Parameters - unknown parameter name '"
|
---|
343 | +key+"' with value "+valuestream.str()+"!");
|
---|
344 | if (params.haveParameter(key)) {
|
---|
345 | Parameter *instance = params.FormatParser_Parameters::getParameter(key);
|
---|
346 | instance->set(valuestream.str());
|
---|
347 | }
|
---|
348 | } else {
|
---|
349 | ist.setstate(std::ios::eofbit);
|
---|
350 | }
|
---|
351 | }
|
---|
352 | return ist;
|
---|
353 | }
|
---|
354 |
|
---|
355 | /** Checks whether all elements in the world also have parameters in the basis.
|
---|
356 | *
|
---|
357 | * @return true - all elements parametrized, false - at least one element is missing.
|
---|
358 | */
|
---|
359 | bool Psi3Parser_Parameters::checkWorldElementsAgainstCurrentBasis() const
|
---|
360 | {
|
---|
361 | DoeLog(0) && (eLog() << Verbose(0)
|
---|
362 | << "Psi3Parser_Parameters::checkWorldElementsAgainstCurrentBasis() - not implemented yet."
|
---|
363 | << std::endl);
|
---|
364 |
|
---|
365 | return false;
|
---|
366 | }
|
---|
367 |
|
---|