Changes in src/Parser/MpqcParser.cpp [ad011c:4cbca0]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/MpqcParser.cpp
rad011c r4cbca0 18 18 #endif 19 19 20 #include <iostream> 21 #include <boost/tokenizer.hpp> 22 #include <string> 23 20 24 #include "CodePatterns/MemDebug.hpp" 21 25 … … 25 29 #include "config.hpp" 26 30 #include "element.hpp" 31 #include "molecule.hpp" 27 32 #include "CodePatterns/Log.hpp" 33 #include "CodePatterns/toString.hpp" 28 34 #include "CodePatterns/Verbose.hpp" 29 35 #include "LinearAlgebra/Vector.hpp" … … 35 41 * 36 42 */ 37 MpqcParser::MpqcParser() : HessianPresent(false)43 MpqcParser::MpqcParser() 38 44 {} 39 45 … … 49 55 void MpqcParser::load(istream *file) 50 56 { 51 // TODO: MpqcParser::load implementation 52 ASSERT(false, "Not implemented yet"); 57 bool MpqcSection = false; 58 bool MoleculeSection = false; 59 bool GeometrySection = false; 60 bool BasisSection = false; 61 bool AuxBasisSection = false; 62 char line[MAXSTRINGSIZE]; 63 typedef boost::tokenizer<boost::char_separator<char> > tokenizer; 64 boost::char_separator<char> sep("[]"); 65 boost::char_separator<char> angularsep("<>"); 66 boost::char_separator<char> equalitysep("="); 67 boost::char_separator<char> whitesep(" \t"); 68 ConvertTo<double> toDouble; 69 70 molecule *newmol = World::getInstance().createMolecule(); 71 newmol->ActiveFlag = true; 72 // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include 73 World::getInstance().getMolecules()->insert(newmol); 74 while (file->good()) { 75 file->getline(line, MAXSTRINGSIZE-1); 76 std::string linestring(line); 77 if ((linestring.find("atoms geometry") == string::npos) && (linestring.find("}") != string::npos)) { 78 GeometrySection = false; 79 } 80 if ((linestring.find(")") != string::npos)) { // ends a section which do not overlap 81 MpqcSection = false; 82 MoleculeSection = false; 83 BasisSection = false; 84 AuxBasisSection = false; 85 } 86 if (MoleculeSection) { 87 if (GeometrySection) { // we have an atom 88 tokenizer tokens(linestring, sep); 89 // if (tokens.size() != 2) 90 // throw MpqcParseException; 91 tokenizer::iterator tok_iter = tokens.begin(); 92 std::stringstream whitespacefilter(*tok_iter++); 93 std::string element; 94 whitespacefilter >> element; 95 std::string vector = *tok_iter; 96 tokenizer vectorcomponents(vector, whitesep); 97 Vector X; 98 // if (vectorcomponents.size() != NDIM) 99 // throw MpqcParseException; 100 tok_iter = vectorcomponents.begin(); 101 for (int i=0; i<NDIM; ++i) { 102 X[i] = toDouble(*tok_iter++); 103 } 104 // create atom 105 atom *newAtom = World::getInstance().createAtom(); 106 newAtom->setType(World::getInstance().getPeriode()->FindElement(element)); 107 newAtom->setPosition(X); 108 newmol->AddAtom(newAtom); 109 DoLog(1) && (Log() << Verbose(1) << "Adding atom " << *newAtom << std::endl); 110 } 111 } 112 if (MpqcSection) { 113 tokenizer tokens(linestring, equalitysep); 114 tokenizer::iterator tok_iter = tokens.begin(); 115 std::stringstream whitespacefilter(*tok_iter++); 116 std::string key(*tok_iter++); 117 if (params.haveParam(key)) { 118 std::stringstream linestream(linestring); 119 linestream >> params; 120 } else if (linestring.find("mole<") != string::npos) { // get theory 121 tokenizer tokens(linestring, angularsep); 122 tokenizer::iterator tok_iter = tokens.begin(); 123 std::string value(*(++tok_iter)); 124 std::stringstream linestream("theory = "+value); 125 linestream >> params; 126 } else if (linestring.find("integrals<") != string::npos) { // get theory 127 tokenizer tokens(linestring, angularsep); 128 tokenizer::iterator tok_iter = tokens.begin(); 129 std::string value(*(++tok_iter)); 130 std::stringstream linestream("integration = "+value); 131 linestream >> params; 132 } 133 } 134 if (BasisSection) { 135 tokenizer tokens(linestring, equalitysep); 136 tokenizer::iterator tok_iter = tokens.begin(); 137 std::string key(*tok_iter++); 138 std::string value(*tok_iter); 139 // TODO: use exception instead of ASSERT 140 ASSERT(tok_iter == tokens.end(), 141 "MpqcParser::load() - more than (key = value) on line "+linestring+"."); 142 if (key == "name") { 143 std::stringstream linestream("basis = "+value); 144 linestream >> params; 145 } 146 } 147 if (AuxBasisSection) { 148 tokenizer tokens(linestring, equalitysep); 149 tokenizer::iterator tok_iter = tokens.begin(); 150 std::string key(*tok_iter++); 151 std::string value(*tok_iter); 152 // TODO: use exception instead of ASSERT 153 ASSERT(tok_iter == tokens.end(), 154 "MpqcParser::load() - more than (key = value) on line "+linestring+"."); 155 if (key == "name") { 156 std::stringstream linestream("aux_basis = "+value); 157 linestream >> params; 158 } 159 } 160 // set some scan flags 161 if (linestring.find("mpqc:") != string::npos) { 162 MpqcSection = true; 163 } 164 if (linestring.find("molecule<Molecule>:") != string::npos) { 165 MoleculeSection = true; 166 } 167 if (linestring.find("atoms geometry") != string::npos) { 168 GeometrySection = true; 169 } 170 if ((linestring.find("basis<GaussianBasisSet>:") != string::npos) && ((linestring.find("abasis<") == string::npos))) { 171 BasisSection = true; 172 } 173 if (linestring.find("abasis<") != string::npos) { 174 AuxBasisSection = true; 175 } 176 } 53 177 } 54 178 55 /** 56 * Saves the \a atoms into as a MPQC file. 57 * 58 * \param file where to save the state 59 * \param atoms atoms to store 60 */ 61 void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms) 62 { 63 DoLog(0) && (Log() << Verbose(0) << "Saving changes to MPQC ." << std::endl); 64 65 if (HessianPresent) 66 saveHessian(file, atoms); 67 else 68 saveSimple(file, atoms); 69 } 70 71 /** Saves all atoms and data into a MPQC config file without hessian. 179 /** Saves all atoms and data into a MPQC config file. 72 180 * \param *file output stream 73 181 * \param atoms atoms to store 74 182 */ 75 void MpqcParser::save Simple(ostream *file, const std::vector<atom *> &atoms)183 void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms) 76 184 { 77 185 Vector center; … … 81 189 for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner) 82 190 center += (*runner)->getPosition(); 83 center.Scale(1./ allatoms.size());191 center.Scale(1./(double)allatoms.size()); 84 192 85 193 // first without hessian … … 89 197 *file << "% Created by MoleCuilder" << endl; 90 198 *file << "mpqc: (" << endl; 91 *file << "\tsavestate = no" << endl; 92 *file << "\tdo_gradient = yes" << endl; 93 *file << "\tmole<MBPT2>: (" << endl; 94 *file << "\t\tmaxiter = 200" << endl; 95 *file << "\t\tbasis = $:basis" << endl; 96 *file << "\t\tmolecule = $:molecule" << endl; 97 *file << "\t\treference<CLHF>: (" << endl; 98 *file << "\t\t\tbasis = $:basis" << endl; 99 *file << "\t\t\tmolecule = $:molecule" << endl; 100 *file << "\t\t)" << endl; 101 *file << "\t)" << endl; 199 *file << "\tsavestate = " << params.getString(MpqcParser_Parameters::savestateParam) << endl; 200 *file << "\tdo_gradient = " << params.getString(MpqcParser_Parameters::do_gradientParam) << endl; 201 if (params.getBool(MpqcParser_Parameters::hessianParam)) { 202 *file << "\tfreq<MolecularFrequencies>: (" << endl; 203 *file << "\t\tmolecule=$:molecule" << endl; 204 *file << "\t)" << endl; 205 } 206 switch (params.getTheory()) { 207 case MpqcParser_Parameters::CLHF: 208 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 209 *file << "\t\tmolecule = $:molecule" << endl; 210 *file << "\t\tbasis = $:basis" << endl; 211 *file << "\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl; 212 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl; 213 *file << "\t)" << endl; 214 break; 215 case MpqcParser_Parameters::CLKS: 216 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 217 *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl; 218 *file << "\t\tmolecule = $:molecule" << endl; 219 *file << "\t\tbasis = $:basis" << endl; 220 *file << "\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl; 221 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl; 222 *file << "\t)" << endl; 223 break; 224 case MpqcParser_Parameters::MBPT2: 225 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 226 *file << "\t\tbasis = $:basis" << endl; 227 *file << "\t\tmolecule = $:molecule" << endl; 228 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl; 229 *file << "\t\treference<CLHF>: (" << endl; 230 *file << "\t\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl; 231 *file << "\t\t\tbasis = $:basis" << endl; 232 *file << "\t\t\tmolecule = $:molecule" << endl; 233 *file << "\t\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl; 234 *file << "\t\t)" << endl; 235 *file << "\t)" << endl; 236 break; 237 case MpqcParser_Parameters::MBPT2_R12: 238 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl; 239 *file << "\t\tmolecule = $:molecule" << endl; 240 *file << "\t\tbasis = $:basis" << endl; 241 *file << "\t\taux_basis = $:abasis" << endl; 242 *file << "\t\tstdapprox = \"" << params.getString(MpqcParser_Parameters::stdapproxParam) << "\"" << endl; 243 *file << "\t\tnfzc = " << toString(params.getInt(MpqcParser_Parameters::nfzcParam)) << endl; 244 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl; 245 *file << "\t\tintegrals<IntegralCints>:()" << endl; 246 *file << "\t\treference<CLHF>: (" << endl; 247 *file << "\t\t\tmolecule = $:molecule" << endl; 248 *file << "\t\t\tbasis = $:basis" << endl; 249 *file << "\t\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam)) << endl; 250 *file << "\t\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl; 251 *file << "\t\t\tintegrals<" << params.getString(MpqcParser_Parameters::integrationParam) << ">:()" << endl; 252 *file << "\t\t)" << endl; 253 *file << "\t)" << endl; 254 break; 255 default: 256 DoeLog(0) && (eLog() << Verbose(0) 257 << "Unknown level of theory requested for MPQC output file." << std::endl); 258 break; 259 } 102 260 *file << ")" << endl; 103 261 *file << "molecule<Molecule>: (" << endl; … … 111 269 *file << ")" << endl; 112 270 *file << "basis<GaussianBasisSet>: (" << endl; 113 *file << "\tname = \"" << World::getInstance().getConfig()->basis<< "\"" << endl;271 *file << "\tname = \"" << params.getString(MpqcParser_Parameters::basisParam) << "\"" << endl; 114 272 *file << "\tmolecule = $:molecule" << endl; 115 273 *file << ")" << endl; 274 if (params.getTheory() == MpqcParser_Parameters::MBPT2_R12) { 275 *file << "% auxiliary basis set specification" << endl; 276 *file << "\tabasis<GaussianBasisSet>: (" << endl; 277 *file << "\tname = \"" << params.getString(MpqcParser_Parameters::aux_basisParam) << "\"" << endl; 278 *file << "\tmolecule = $:molecule" << endl; 279 *file << ")" << endl; 280 } 116 281 } 117 282 } 118 283 119 /** Saves all atoms and data into a MPQC config file with hessian. 120 * \param *file output stream 121 * \param atoms atoms to store 122 */ 123 void MpqcParser::saveHessian(ostream *file, const std::vector<atom *> &atoms) 284 MpqcParser_Parameters & MpqcParser::getParams() 124 285 { 125 Vector center; 126 vector<atom *> allatoms = World::getInstance().getAllAtoms(); 127 128 // calculate center 129 for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner) 130 center += (*runner)->getPosition(); 131 center.Scale(1./allatoms.size()); 132 133 // with hessian 134 if (file->fail()) { 135 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl); 136 } else { 137 *file << "% Created by MoleCuilder" << endl; 138 *file << "mpqc: (" << endl; 139 *file << "\tsavestate = no" << endl; 140 *file << "\tdo_gradient = yes" << endl; 141 *file << "\tmole<CLHF>: (" << endl; 142 *file << "\t\tmaxiter = 200" << endl; 143 *file << "\t\tbasis = $:basis" << endl; 144 *file << "\t\tmolecule = $:molecule" << endl; 145 *file << "\t)" << endl; 146 *file << "\tfreq<MolecularFrequencies>: (" << endl; 147 *file << "\t\tmolecule=$:molecule" << endl; 148 *file << "\t)" << endl; 149 *file << ")" << endl; 150 *file << "molecule<Molecule>: (" << endl; 151 *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl; 152 *file << "\t{ atoms geometry } = {" << endl; 153 // output of atoms 154 for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) { 155 (*AtomRunner)->OutputMPQCLine(file, ¢er); 156 } 157 *file << "\t}" << endl; 158 *file << ")" << endl; 159 *file << "basis<GaussianBasisSet>: (" << endl; 160 *file << "\tname = \"" << World::getInstance().getConfig()->basis << "\"" << endl; 161 *file << "\tmolecule = $:molecule" << endl; 162 *file << ")" << endl; 163 } 286 return params; 164 287 } 165 288 166 /** Sets whether hessian is desired or not167 * \param hessian statement168 */169 void MpqcParser::setHessian(bool hessian)170 {171 HessianPresent = hessian;172 }
Note:
See TracChangeset
for help on using the changeset viewer.