[61d69a4] | 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 |
|
---|
[ee50c1] | 32 | #include "Parser/Parameters/ContinuousParameter.hpp"
|
---|
| 33 | #include "Parser/Parameters/DiscreteParameter.hpp"
|
---|
| 34 | #include "Parser/Parameters/StringParameter.hpp"
|
---|
[61d69a4] | 35 |
|
---|
[ee50c1] | 36 | template <>
|
---|
| 37 | const std::string ContinuousValue<bool>::get() const
|
---|
[c1db05] | 38 | {
|
---|
[ee50c1] | 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");
|
---|
[c1db05] | 45 | }
|
---|
| 46 |
|
---|
[ee50c1] | 47 | template <>
|
---|
| 48 | void ContinuousValue<bool>::set(const std::string _value)
|
---|
[d3d6c6] | 49 | {
|
---|
[ee50c1] | 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.");
|
---|
[d3d6c6] | 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[ee50c1] | 60 |
|
---|
| 61 | MpqcParser_Parameters::MpqcParser_Parameters()
|
---|
| 62 | {
|
---|
| 63 | Init();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[c1db05] | 66 | void MpqcParser_Parameters::Init()
|
---|
[61d69a4] | 67 | {
|
---|
| 68 | // add all known basis
|
---|
| 69 | initBasis();
|
---|
| 70 |
|
---|
[ee50c1] | 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 | }
|
---|
[61d69a4] | 87 |
|
---|
[ee50c1] | 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 | }
|
---|
[44fce5] | 115 |
|
---|
[ee50c1] | 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 | }
|
---|
[61d69a4] | 128 | }
|
---|
| 129 |
|
---|
[ee50c1] | 130 | MpqcParser_Parameters::~MpqcParser_Parameters()
|
---|
| 131 | {}
|
---|
[c1db05] | 132 |
|
---|
[ee50c1] | 133 | /** Getter for a specific Parameter.
|
---|
| 134 | *
|
---|
| 135 | * @param param index among enum Parameters
|
---|
| 136 | * @return value of the desired Parameters
|
---|
| 137 | */
|
---|
| 138 | const std::string MpqcParser_Parameters::getParameter(const enum Parameters param) const
|
---|
| 139 | {
|
---|
| 140 | return FormatParser_Parameters::getParameter(ParamNames[param])->get();
|
---|
[c1db05] | 141 | }
|
---|
| 142 |
|
---|
[ee50c1] | 143 | /** Setter for a specific Parameter.
|
---|
| 144 | *
|
---|
| 145 | * @param param index among enum Parameters
|
---|
| 146 | * @param _value value to set desired Parameter to
|
---|
| 147 | */
|
---|
| 148 | void MpqcParser_Parameters::setParameter(const enum Parameters param, const std::string &_value)
|
---|
[c1db05] | 149 | {
|
---|
[ee50c1] | 150 | const std::string &name = getParameterName(param);
|
---|
| 151 | FormatParser_Parameters::getParameter(name)->set(_value);
|
---|
[c1db05] | 152 | }
|
---|
| 153 |
|
---|
[ee50c1] | 154 | /** Getter for name of a specific Parameter.
|
---|
| 155 | *
|
---|
| 156 | * @param param index among enum Parameters
|
---|
| 157 | * @return name of the desired Parameter
|
---|
| 158 | */
|
---|
| 159 | const std::string &MpqcParser_Parameters::getParameterName(const enum Parameters param) const
|
---|
[c1db05] | 160 | {
|
---|
[ee50c1] | 161 | return ParamNames[param];
|
---|
[c1db05] | 162 | }
|
---|
| 163 |
|
---|
[ee50c1] | 164 | /** Getter for name of a specific Parameter.
|
---|
| 165 | *
|
---|
| 166 | * @param param index among enum Theory
|
---|
| 167 | * @return name of the desired Theory
|
---|
| 168 | */
|
---|
| 169 | const std::string &MpqcParser_Parameters::getTheoryName(const enum Theory theory) const
|
---|
[c1db05] | 170 | {
|
---|
[ee50c1] | 171 | return ValidTheories[theory];
|
---|
[c1db05] | 172 | }
|
---|
| 173 |
|
---|
[ee50c1] | 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 | */
|
---|
| 179 | const std::string &MpqcParser_Parameters::getIntegrationMethodName(const enum IntegrationMethod integration) const
|
---|
[61d69a4] | 180 | {
|
---|
[ee50c1] | 181 | return ValidIntegrationMethods[integration];
|
---|
[61d69a4] | 182 | }
|
---|
| 183 |
|
---|
| 184 |
|
---|
[ee50c1] | 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 | */
|
---|
| 191 | std::ostream & operator << (std::ostream& ost, const MpqcParser_Parameters ¶ms)
|
---|
[61d69a4] | 192 | {
|
---|
[963321a] | 193 | // this is ugly, but with boost::any to safeguard const-ness is plain impossible
|
---|
[61d69a4] | 194 | std::ostringstream output;
|
---|
[ee50c1] | 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) << ";";
|
---|
[61d69a4] | 199 | ost << output.str();
|
---|
| 200 | return ost;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[ee50c1] | 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 | */
|
---|
[61d69a4] | 209 | std::istream & operator >> (std::istream& ist, MpqcParser_Parameters ¶ms)
|
---|
| 210 | {
|
---|
| 211 | typedef boost::tokenizer<boost::char_separator<char> >
|
---|
| 212 | tokenizer;
|
---|
| 213 | boost::char_separator<char> semicolonsep(";");
|
---|
[44fce5] | 214 | boost::char_separator<char> equalitysep(" =");
|
---|
[311da7b] | 215 | boost::char_separator<char> ticksep("\"");
|
---|
[61d69a4] | 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(),
|
---|
[311da7b] | 221 | "operator<< on MpqcParser_Parameters - empty string, need at least ';' in line "+line+"!");
|
---|
[61d69a4] | 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;
|
---|
[311da7b] | 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);
|
---|
[61d69a4] | 247 |
|
---|
[44fce5] | 248 | // TODO: throw exception instead of DoeLog()
|
---|
[ee50c1] | 249 | ASSERT(params.haveParameter(key),
|
---|
[311da7b] | 250 | "operator >> on MpqcParser_Parameters - unknown parameter name '"
|
---|
| 251 | +key+"' with value "+valuestream.str()+"!");
|
---|
[ee50c1] | 252 | if (params.haveParameter(key)) {
|
---|
| 253 | Parameter *instance = params.FormatParser_Parameters::getParameter(key);
|
---|
| 254 | instance->set(valuestream.str());
|
---|
| 255 | }
|
---|
[61d69a4] | 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 | */
|
---|
| 267 | bool 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 |
|
---|