| [61d69a4] | 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 | 
 | 
|---|
| [c1db05] | 21 | #include "CodePatterns/Clone.hpp"
 | 
|---|
| [61d69a4] | 22 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 23 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 | #include <boost/any.hpp>
 | 
|---|
 | 26 | 
 | 
|---|
| [c1db05] | 27 | #include "Parser/FormatParser_Parameters.hpp"
 | 
|---|
| [61d69a4] | 28 | 
 | 
|---|
 | 29 | class MpqcParser;
 | 
|---|
 | 30 | 
 | 
|---|
| [c1db05] | 31 | class MpqcParser_Parameters : public FormatParser_Parameters
 | 
|---|
| [61d69a4] | 32 | {
 | 
|---|
| [44fce5] | 33 |   // MpqcParser should be friend to access params directly for types.
 | 
|---|
| [61d69a4] | 34 |   friend class MpqcParser;
 | 
|---|
| [44fce5] | 35 |   // ParserMpqcUnitTest needs to be friend to check types contained in params.
 | 
|---|
| [61d69a4] | 36 |   friend class ParserMpqcUnitTest;
 | 
|---|
| [44fce5] | 37 | 
 | 
|---|
| [61d69a4] | 38 | public:
 | 
|---|
| [44fce5] | 39 |   /** Constructor of MpqcParser_Parameters.
 | 
|---|
 | 40 |    *
 | 
|---|
 | 41 |    */
 | 
|---|
| [61d69a4] | 42 |   MpqcParser_Parameters();
 | 
|---|
| [44fce5] | 43 | 
 | 
|---|
| [c1db05] | 44 |   /** Copy Constructor of MpqcParser_Parameters.
 | 
|---|
 | 45 |    *
 | 
|---|
 | 46 |    * @param state ref to instance to copy
 | 
|---|
 | 47 |    */
 | 
|---|
 | 48 |   MpqcParser_Parameters(const MpqcParser_Parameters & state);
 | 
|---|
 | 49 | 
 | 
|---|
| [44fce5] | 50 |   /** Destructor of MpqcParser_Parameters.
 | 
|---|
 | 51 |    *
 | 
|---|
 | 52 |    */
 | 
|---|
| [c1db05] | 53 |   virtual ~MpqcParser_Parameters();
 | 
|---|
| [61d69a4] | 54 | 
 | 
|---|
| [44fce5] | 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 |   };
 | 
|---|
| [61d69a4] | 73 | 
 | 
|---|
| [44fce5] | 74 |   /** Enumeration of all known Parameters to allow placing them in vectors, maps.
 | 
|---|
 | 75 |    *
 | 
|---|
 | 76 |    */
 | 
|---|
| [61d69a4] | 77 |   enum Parameters {
 | 
|---|
| [44fce5] | 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
 | 
|---|
| [61d69a4] | 90 | 
 | 
|---|
 | 91 |   bool checkWorldElementsAgainstCurrentBasis() const;
 | 
|---|
| [44fce5] | 92 | 
 | 
|---|
 | 93 |   /** Sets the desired level of solving theory to use.
 | 
|---|
 | 94 |    *
 | 
|---|
 | 95 |    * \param _theory shorthand of the theory
 | 
|---|
 | 96 |    */
 | 
|---|
| [61d69a4] | 97 |   void setTheory(enum Theory _theory);
 | 
|---|
| [44fce5] | 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 |    */
 | 
|---|
| [c1db05] | 109 |   enum IntegrationMethod getIntegration() const;
 | 
|---|
| [44fce5] | 110 | 
 | 
|---|
 | 111 |   /** Getter for current Theory in params.
 | 
|---|
 | 112 |    *
 | 
|---|
 | 113 |    * @return enumeration index of Theory
 | 
|---|
 | 114 |    */
 | 
|---|
| [c1db05] | 115 |   enum Theory getTheory() const;
 | 
|---|
| [61d69a4] | 116 | 
 | 
|---|
| [44fce5] | 117 |   /** Getter for a parameter in params as a string.
 | 
|---|
 | 118 |    *
 | 
|---|
 | 119 |    * @param _param enumeration index of desired Parameter
 | 
|---|
 | 120 |    * @return string value
 | 
|---|
 | 121 |    */
 | 
|---|
| [c1db05] | 122 |   std::string getString(enum Parameters _param) const;
 | 
|---|
| [44fce5] | 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 |    */
 | 
|---|
| [c1db05] | 131 |   int getInt(enum Parameters _param) const;
 | 
|---|
| [44fce5] | 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 |    */
 | 
|---|
| [c1db05] | 140 |   double getDouble(enum Parameters _param) const;
 | 
|---|
| [44fce5] | 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 |    */
 | 
|---|
| [c1db05] | 149 |   bool getBool(enum Parameters _param) const;
 | 
|---|
| [61d69a4] | 150 | 
 | 
|---|
| [44fce5] | 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 |    */
 | 
|---|
| [61d69a4] | 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 | 
 | 
|---|
| [44fce5] | 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 |    */
 | 
|---|
| [c1db05] | 188 |   enum Parameters getParam(std::string _name) const;
 | 
|---|
| [44fce5] | 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;
 | 
|---|
| [61d69a4] | 196 | 
 | 
|---|
| [c1db05] | 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 | 
 | 
|---|
| [61d69a4] | 215 | private:
 | 
|---|
| [c1db05] | 216 |   /** Global initialization in cstor.
 | 
|---|
 | 217 |    *
 | 
|---|
 | 218 |    */
 | 
|---|
 | 219 |   void Init();
 | 
|---|
 | 220 | 
 | 
|---|
| [44fce5] | 221 |   /** Initializes BasisList.
 | 
|---|
 | 222 |    *
 | 
|---|
 | 223 |    */
 | 
|---|
| [61d69a4] | 224 |   void initBasis();
 | 
|---|
| [44fce5] | 225 | 
 | 
|---|
 | 226 |   /** Initializes params.
 | 
|---|
 | 227 |    * Sets the type and the associated enumeration index.
 | 
|---|
 | 228 |    */
 | 
|---|
| [61d69a4] | 229 |   void initParameters();
 | 
|---|
 | 230 | 
 | 
|---|
| [44fce5] | 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 |    */
 | 
|---|
| [61d69a4] | 236 |   template <class T> void appendParameter(enum Parameters _enum, T _p) {
 | 
|---|
 | 237 |     boost::any _p_value = _p;
 | 
|---|
 | 238 |     params[_enum] = _p_value;
 | 
|---|
 | 239 |   }
 | 
|---|
 | 240 | 
 | 
|---|
| [44fce5] | 241 |   // all internal typedefs for lists below
 | 
|---|
| [61d69a4] | 242 |   typedef std::map<std::string, std::list<std::string> > BasisMapType;
 | 
|---|
 | 243 |   typedef std::map<enum Theory, std::string> TheoryNamesType;
 | 
|---|
| [44fce5] | 244 |   typedef std::map<std::string, enum Theory> TheoryLookupType;
 | 
|---|
| [61d69a4] | 245 |   typedef std::map<enum IntegrationMethod, std::string> IntegrationNamesType;
 | 
|---|
| [44fce5] | 246 |   typedef std::map<std::string, enum IntegrationMethod> IntegrationLookupType;
 | 
|---|
| [61d69a4] | 247 |   typedef std::map<enum Parameters, std::string> ParamNamesType;
 | 
|---|
| [44fce5] | 248 |   typedef std::map<std::string, enum Parameters> ParamLookupType;
 | 
|---|
| [61d69a4] | 249 |   typedef std::map<enum Parameters, boost::any> parameterlist;
 | 
|---|
 | 250 | 
 | 
|---|
| [44fce5] | 251 |   //!> boost::any container for all the parameters
 | 
|---|
| [61d69a4] | 252 |   parameterlist params;
 | 
|---|
 | 253 | 
 | 
|---|
| [44fce5] | 254 |   // maps from names to enumerations
 | 
|---|
 | 255 | 
 | 
|---|
 | 256 |   //!> contains basis and all elements the basis knows about
 | 
|---|
| [61d69a4] | 257 |   BasisMapType BasisList;
 | 
|---|
| [44fce5] | 258 |   //!> contains the name of a theory as string
 | 
|---|
| [61d69a4] | 259 |   TheoryNamesType TheoryNames;
 | 
|---|
| [44fce5] | 260 |   //!> contains a lookup from theory name to enumeration index
 | 
|---|
 | 261 |   TheoryLookupType TheoryLookup;
 | 
|---|
 | 262 |   //!> contains the name of an integration method as string
 | 
|---|
| [61d69a4] | 263 |   IntegrationNamesType IntegrationNames;
 | 
|---|
| [44fce5] | 264 |   //!> contains a lookup from integration method name to enumeration index
 | 
|---|
 | 265 |   IntegrationLookupType IntegrationLookup;
 | 
|---|
 | 266 |   //!> contains the name of a parameter
 | 
|---|
| [61d69a4] | 267 |   ParamNamesType ParamNames;
 | 
|---|
| [44fce5] | 268 |   //!> contains a lookup from parameter name to enumeration index
 | 
|---|
 | 269 |   ParamLookupType ParamLookup;
 | 
|---|
| [61d69a4] | 270 | };
 | 
|---|
 | 271 | 
 | 
|---|
| [44fce5] | 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 |  */
 | 
|---|
| [61d69a4] | 278 | std::ostream & operator << (std::ostream& ost, const MpqcParser_Parameters ¶ms);
 | 
|---|
| [44fce5] | 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 |  */
 | 
|---|
| [61d69a4] | 286 | std::istream & operator >> (std::istream& ist, MpqcParser_Parameters ¶ms);
 | 
|---|
 | 287 | 
 | 
|---|
 | 288 | #endif /* MPQCPARSER_PARAMETERS_HPP_ */
 | 
|---|