[bcf653] | 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 |
|
---|
[43dad6] | 8 | /*
|
---|
| 9 | * MpqcParser.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: 12.06.2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[aa8ef2] | 20 | #include <iostream>
|
---|
| 21 | #include <boost/tokenizer.hpp>
|
---|
| 22 | #include <string>
|
---|
| 23 |
|
---|
[ad011c] | 24 | #include "CodePatterns/MemDebug.hpp"
|
---|
[bbbad5] | 25 |
|
---|
[1b2d30] | 26 | #include "MpqcParser.hpp"
|
---|
| 27 |
|
---|
| 28 | #include "atom.hpp"
|
---|
| 29 | #include "config.hpp"
|
---|
| 30 | #include "element.hpp"
|
---|
[aa8ef2] | 31 | #include "molecule.hpp"
|
---|
[ad011c] | 32 | #include "CodePatterns/Log.hpp"
|
---|
[aa8ef2] | 33 | #include "CodePatterns/toString.hpp"
|
---|
[ad011c] | 34 | #include "CodePatterns/Verbose.hpp"
|
---|
[e97a44] | 35 | #include "LinearAlgebra/Vector.hpp"
|
---|
| 36 | #include "periodentafel.hpp"
|
---|
[1b2d30] | 37 | #include "World.hpp"
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | /** Constructor of MpqcParser.
|
---|
| 41 | *
|
---|
| 42 | */
|
---|
[61d69a4] | 43 | MpqcParser::MpqcParser()
|
---|
[97b825] | 44 | {}
|
---|
[1b2d30] | 45 |
|
---|
| 46 | /** Destructor of MpqcParser.
|
---|
| 47 | *
|
---|
| 48 | */
|
---|
[97b825] | 49 | MpqcParser::~MpqcParser()
|
---|
| 50 | {}
|
---|
[1b2d30] | 51 |
|
---|
| 52 | /** Load an MPQC config file into the World.
|
---|
| 53 | * \param *file input stream
|
---|
| 54 | */
|
---|
| 55 | void MpqcParser::load(istream *file)
|
---|
| 56 | {
|
---|
[4cbca0] | 57 | bool MpqcSection = false;
|
---|
| 58 | bool MoleculeSection = false;
|
---|
| 59 | bool GeometrySection = false;
|
---|
| 60 | bool BasisSection = false;
|
---|
| 61 | bool AuxBasisSection = false;
|
---|
[aa8ef2] | 62 | char line[MAXSTRINGSIZE];
|
---|
| 63 | typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
---|
| 64 | boost::char_separator<char> sep("[]");
|
---|
[4cbca0] | 65 | boost::char_separator<char> angularsep("<>");
|
---|
| 66 | boost::char_separator<char> equalitysep("=");
|
---|
[aa8ef2] | 67 | boost::char_separator<char> whitesep(" \t");
|
---|
| 68 | ConvertTo<double> toDouble;
|
---|
| 69 |
|
---|
| 70 | molecule *newmol = World::getInstance().createMolecule();
|
---|
| 71 | newmol->ActiveFlag = true;
|
---|
[4cbca0] | 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);
|
---|
[aa8ef2] | 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)) {
|
---|
[4cbca0] | 78 | GeometrySection = false;
|
---|
[aa8ef2] | 79 | }
|
---|
[4cbca0] | 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);
|
---|
[aa8ef2] | 114 | tokenizer::iterator tok_iter = tokens.begin();
|
---|
| 115 | std::stringstream whitespacefilter(*tok_iter++);
|
---|
[4cbca0] | 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;
|
---|
[aa8ef2] | 158 | }
|
---|
| 159 | }
|
---|
| 160 | // set some scan flags
|
---|
[4cbca0] | 161 | if (linestring.find("mpqc:") != string::npos) {
|
---|
| 162 | MpqcSection = true;
|
---|
| 163 | }
|
---|
| 164 | if (linestring.find("molecule<Molecule>:") != string::npos) {
|
---|
| 165 | MoleculeSection = true;
|
---|
| 166 | }
|
---|
[aa8ef2] | 167 | if (linestring.find("atoms geometry") != string::npos) {
|
---|
[4cbca0] | 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;
|
---|
[aa8ef2] | 175 | }
|
---|
| 176 | }
|
---|
[1b2d30] | 177 | }
|
---|
| 178 |
|
---|
[f31edc] | 179 | /** Saves all atoms and data into a MPQC config file.
|
---|
[1b2d30] | 180 | * \param *file output stream
|
---|
[73916f] | 181 | * \param atoms atoms to store
|
---|
[1b2d30] | 182 | */
|
---|
[f31edc] | 183 | void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms)
|
---|
[1b2d30] | 184 | {
|
---|
| 185 | Vector center;
|
---|
| 186 | vector<atom *> allatoms = World::getInstance().getAllAtoms();
|
---|
| 187 |
|
---|
[d6b8e1] | 188 | // calculate center
|
---|
| 189 | for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
|
---|
[d74077] | 190 | center += (*runner)->getPosition();
|
---|
[61d69a4] | 191 | center.Scale(1./(double)allatoms.size());
|
---|
[d6b8e1] | 192 |
|
---|
[1b2d30] | 193 | // first without hessian
|
---|
| 194 | if (file->fail()) {
|
---|
| 195 | DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl);
|
---|
| 196 | } else {
|
---|
| 197 | *file << "% Created by MoleCuilder" << endl;
|
---|
| 198 | *file << "mpqc: (" << endl;
|
---|
[61d69a4] | 199 | *file << "\tsavestate = " << params.getString(MpqcParser_Parameters::savestateParam) << endl;
|
---|
| 200 | *file << "\tdo_gradient = " << params.getString(MpqcParser_Parameters::do_gradientParam) << endl;
|
---|
[44fce5] | 201 | if (params.getBool(MpqcParser_Parameters::hessianParam)) {
|
---|
[f31edc] | 202 | *file << "\tfreq<MolecularFrequencies>: (" << endl;
|
---|
| 203 | *file << "\t\tmolecule=$:molecule" << endl;
|
---|
| 204 | *file << "\t)" << endl;
|
---|
| 205 | }
|
---|
[61d69a4] | 206 | switch (params.getTheory()) {
|
---|
| 207 | case MpqcParser_Parameters::CLHF:
|
---|
| 208 | *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
|
---|
[f31edc] | 209 | *file << "\t\tmolecule = $:molecule" << endl;
|
---|
| 210 | *file << "\t\tbasis = $:basis" << endl;
|
---|
[61d69a4] | 211 | *file << "\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
|
---|
| 212 | *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
|
---|
[f31edc] | 213 | *file << "\t)" << endl;
|
---|
| 214 | break;
|
---|
[61d69a4] | 215 | case MpqcParser_Parameters::CLKS:
|
---|
| 216 | *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
|
---|
[f31edc] | 217 | *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
|
---|
| 218 | *file << "\t\tmolecule = $:molecule" << endl;
|
---|
| 219 | *file << "\t\tbasis = $:basis" << endl;
|
---|
[61d69a4] | 220 | *file << "\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
|
---|
| 221 | *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
|
---|
[f31edc] | 222 | *file << "\t)" << endl;
|
---|
| 223 | break;
|
---|
[61d69a4] | 224 | case MpqcParser_Parameters::MBPT2:
|
---|
| 225 | *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
|
---|
[f31edc] | 226 | *file << "\t\tbasis = $:basis" << endl;
|
---|
| 227 | *file << "\t\tmolecule = $:molecule" << endl;
|
---|
[61d69a4] | 228 | *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
|
---|
[f31edc] | 229 | *file << "\t\treference<CLHF>: (" << endl;
|
---|
[61d69a4] | 230 | *file << "\t\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
|
---|
[f31edc] | 231 | *file << "\t\t\tbasis = $:basis" << endl;
|
---|
| 232 | *file << "\t\t\tmolecule = $:molecule" << endl;
|
---|
[61d69a4] | 233 | *file << "\t\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
|
---|
[f31edc] | 234 | *file << "\t\t)" << endl;
|
---|
| 235 | *file << "\t)" << endl;
|
---|
| 236 | break;
|
---|
[61d69a4] | 237 | case MpqcParser_Parameters::MBPT2_R12:
|
---|
| 238 | *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
|
---|
[f31edc] | 239 | *file << "\t\tmolecule = $:molecule" << endl;
|
---|
| 240 | *file << "\t\tbasis = $:basis" << endl;
|
---|
| 241 | *file << "\t\taux_basis = $:abasis" << endl;
|
---|
[61d69a4] | 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;
|
---|
[f31edc] | 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;
|
---|
[61d69a4] | 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;
|
---|
[f31edc] | 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;
|
---|
[1b2d30] | 259 | }
|
---|
| 260 | *file << ")" << endl;
|
---|
| 261 | *file << "molecule<Molecule>: (" << endl;
|
---|
| 262 | *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
|
---|
| 263 | *file << "\t{ atoms geometry } = {" << endl;
|
---|
| 264 | // output of atoms
|
---|
| 265 | for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
|
---|
[0dc86e2] | 266 | (*AtomRunner)->OutputMPQCLine(file, ¢er);
|
---|
[1b2d30] | 267 | }
|
---|
| 268 | *file << "\t}" << endl;
|
---|
| 269 | *file << ")" << endl;
|
---|
| 270 | *file << "basis<GaussianBasisSet>: (" << endl;
|
---|
[61d69a4] | 271 | *file << "\tname = \"" << params.getString(MpqcParser_Parameters::basisParam) << "\"" << endl;
|
---|
[1b2d30] | 272 | *file << "\tmolecule = $:molecule" << endl;
|
---|
| 273 | *file << ")" << endl;
|
---|
[61d69a4] | 274 | if (params.getTheory() == MpqcParser_Parameters::MBPT2_R12) {
|
---|
[f31edc] | 275 | *file << "% auxiliary basis set specification" << endl;
|
---|
| 276 | *file << "\tabasis<GaussianBasisSet>: (" << endl;
|
---|
[61d69a4] | 277 | *file << "\tname = \"" << params.getString(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
|
---|
[f31edc] | 278 | *file << "\tmolecule = $:molecule" << endl;
|
---|
| 279 | *file << ")" << endl;
|
---|
| 280 | }
|
---|
[1b2d30] | 281 | }
|
---|
| 282 | }
|
---|
| 283 |
|
---|
[963321a] | 284 | MpqcParser_Parameters & MpqcParser::getParams()
|
---|
| 285 | {
|
---|
| 286 | return params;
|
---|
| 287 | }
|
---|
| 288 |
|
---|