| 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.cpp
|
|---|
| 10 | *
|
|---|
| 11 | * Created on: 12.06.2010
|
|---|
| 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 "MpqcParser.hpp"
|
|---|
| 27 |
|
|---|
| 28 | #include "atom.hpp"
|
|---|
| 29 | #include "config.hpp"
|
|---|
| 30 | #include "element.hpp"
|
|---|
| 31 | #include "molecule.hpp"
|
|---|
| 32 | #include "CodePatterns/Log.hpp"
|
|---|
| 33 | #include "CodePatterns/toString.hpp"
|
|---|
| 34 | #include "CodePatterns/Verbose.hpp"
|
|---|
| 35 | #include "LinearAlgebra/Vector.hpp"
|
|---|
| 36 | #include "periodentafel.hpp"
|
|---|
| 37 | #include "World.hpp"
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | /** Constructor of MpqcParser.
|
|---|
| 41 | *
|
|---|
| 42 | */
|
|---|
| 43 | MpqcParser::MpqcParser() :
|
|---|
| 44 | HessianPresent(false),
|
|---|
| 45 | theory(MBPT2)
|
|---|
| 46 | {}
|
|---|
| 47 |
|
|---|
| 48 | /** Destructor of MpqcParser.
|
|---|
| 49 | *
|
|---|
| 50 | */
|
|---|
| 51 | MpqcParser::~MpqcParser()
|
|---|
| 52 | {}
|
|---|
| 53 |
|
|---|
| 54 | /** Load an MPQC config file into the World.
|
|---|
| 55 | * \param *file input stream
|
|---|
| 56 | */
|
|---|
| 57 | void MpqcParser::load(istream *file)
|
|---|
| 58 | {
|
|---|
| 59 | bool GeometryFollows = false;
|
|---|
| 60 | char line[MAXSTRINGSIZE];
|
|---|
| 61 | typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
|---|
| 62 | boost::char_separator<char> sep("[]");
|
|---|
| 63 | boost::char_separator<char> whitesep(" \t");
|
|---|
| 64 | ConvertTo<double> toDouble;
|
|---|
| 65 |
|
|---|
| 66 | molecule *newmol = World::getInstance().createMolecule();
|
|---|
| 67 | newmol->ActiveFlag = true;
|
|---|
| 68 | while (file->good()) {
|
|---|
| 69 | file->getline(line, MAXSTRINGSIZE-1);
|
|---|
| 70 | std::string linestring(line);
|
|---|
| 71 | if ((linestring.find("atoms geometry") == string::npos) && (linestring.find("}") != string::npos)) {
|
|---|
| 72 | GeometryFollows = false;
|
|---|
| 73 | }
|
|---|
| 74 | if (GeometryFollows) { // we have an atom
|
|---|
| 75 | tokenizer tokens(linestring, sep);
|
|---|
| 76 | // if (tokens.size() != 2)
|
|---|
| 77 | // throw MpqcParseException;
|
|---|
| 78 | tokenizer::iterator tok_iter = tokens.begin();
|
|---|
| 79 | std::stringstream whitespacefilter(*tok_iter++);
|
|---|
| 80 | std::string element;
|
|---|
| 81 | whitespacefilter >> element;
|
|---|
| 82 | std::string vector = *tok_iter;
|
|---|
| 83 | tokenizer vectorcomponents(vector, whitesep);
|
|---|
| 84 | Vector X;
|
|---|
| 85 | // if (vectorcomponents.size() != NDIM)
|
|---|
| 86 | // throw MpqcParseException;
|
|---|
| 87 | tok_iter = vectorcomponents.begin();
|
|---|
| 88 | for (int i=0; i<NDIM; ++i) {
|
|---|
| 89 | X[i] = toDouble(*tok_iter++);
|
|---|
| 90 | }
|
|---|
| 91 | // create atom
|
|---|
| 92 | atom *newAtom = World::getInstance().createAtom();
|
|---|
| 93 | newAtom->setType(World::getInstance().getPeriode()->FindElement(element));
|
|---|
| 94 | newAtom->setPosition(X);
|
|---|
| 95 | newmol->AddAtom(newAtom);
|
|---|
| 96 | DoLog(1) && (Log() << Verbose(1) << "Adding atom " << *newAtom << std::endl);
|
|---|
| 97 | }
|
|---|
| 98 | // set some scan flags
|
|---|
| 99 | if (linestring.find("atoms geometry") != string::npos) {
|
|---|
| 100 | GeometryFollows = true;
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | /** Saves all atoms and data into a MPQC config file.
|
|---|
| 106 | * \param *file output stream
|
|---|
| 107 | * \param atoms atoms to store
|
|---|
| 108 | */
|
|---|
| 109 | void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms)
|
|---|
| 110 | {
|
|---|
| 111 | Vector center;
|
|---|
| 112 | vector<atom *> allatoms = World::getInstance().getAllAtoms();
|
|---|
| 113 |
|
|---|
| 114 | // calculate center
|
|---|
| 115 | for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
|
|---|
| 116 | center += (*runner)->getPosition();
|
|---|
| 117 | center.Scale(1./allatoms.size());
|
|---|
| 118 |
|
|---|
| 119 | // first without hessian
|
|---|
| 120 | if (file->fail()) {
|
|---|
| 121 | DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl);
|
|---|
| 122 | } else {
|
|---|
| 123 | *file << "% Created by MoleCuilder" << endl;
|
|---|
| 124 | *file << "mpqc: (" << endl;
|
|---|
| 125 | *file << "\tsavestate = no" << endl;
|
|---|
| 126 | *file << "\tdo_gradient = yes" << endl;
|
|---|
| 127 | if (HessianPresent) {
|
|---|
| 128 | *file << "\tfreq<MolecularFrequencies>: (" << endl;
|
|---|
| 129 | *file << "\t\tmolecule=$:molecule" << endl;
|
|---|
| 130 | *file << "\t)" << endl;
|
|---|
| 131 | }
|
|---|
| 132 | switch (theory) {
|
|---|
| 133 | case CLHF:
|
|---|
| 134 | *file << "\tmole<CLHF>: (" << endl;
|
|---|
| 135 | *file << "\t\tmolecule = $:molecule" << endl;
|
|---|
| 136 | *file << "\t\tbasis = $:basis" << endl;
|
|---|
| 137 | *file << "\t\tmemory = 16000000" << endl;
|
|---|
| 138 | *file << "\t)" << endl;
|
|---|
| 139 | break;
|
|---|
| 140 | case CLKS:
|
|---|
| 141 | *file << "\tmole<CLKS>: (" << endl;
|
|---|
| 142 | *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
|
|---|
| 143 | *file << "\t\tmolecule = $:molecule" << endl;
|
|---|
| 144 | *file << "\t\tbasis = $:basis" << endl;
|
|---|
| 145 | *file << "\t\tmemory = 16000000" << endl;
|
|---|
| 146 | *file << "\t)" << endl;
|
|---|
| 147 | break;
|
|---|
| 148 | case MBPT2:
|
|---|
| 149 | *file << "\tmole<MBPT2>: (" << endl;
|
|---|
| 150 | *file << "\t\tbasis = $:basis" << endl;
|
|---|
| 151 | *file << "\t\tmolecule = $:molecule" << endl;
|
|---|
| 152 | *file << "\t\treference<CLHF>: (" << endl;
|
|---|
| 153 | *file << "\t\t\tmaxiter = 1000" << endl;
|
|---|
| 154 | *file << "\t\t\tbasis = $:basis" << endl;
|
|---|
| 155 | *file << "\t\t\tmolecule = $:molecule" << endl;
|
|---|
| 156 | *file << "\t\t)" << endl;
|
|---|
| 157 | *file << "\t)" << endl;
|
|---|
| 158 | break;
|
|---|
| 159 | case MBPT2_R12:
|
|---|
| 160 | *file << "\tmole<MBPT2_R12>: (" << endl;
|
|---|
| 161 | *file << "\t\tmolecule = $:molecule" << endl;
|
|---|
| 162 | *file << "\t\tbasis = $:basis" << endl;
|
|---|
| 163 | *file << "\t\taux_basis = $:abasis" << endl;
|
|---|
| 164 | *file << "\t\tstdapprox = \"A'\"" << endl;
|
|---|
| 165 | *file << "\t\tnfzc = 1" << endl;
|
|---|
| 166 | *file << "\t\tmemory = 16000000" << endl;
|
|---|
| 167 | *file << "\t\tintegrals<IntegralCints>:()" << endl;
|
|---|
| 168 | *file << "\t\treference<CLHF>: (" << endl;
|
|---|
| 169 | *file << "\t\t\tmolecule = $:molecule" << endl;
|
|---|
| 170 | *file << "\t\t\tbasis = $:basis" << endl;
|
|---|
| 171 | *file << "\t\t\tmaxiter = 1000" << endl;
|
|---|
| 172 | *file << "\t\t\tmemory = 16000000" << endl;
|
|---|
| 173 | *file << "\t\t\tintegrals<IntegralCints>:()" << endl;
|
|---|
| 174 | *file << "\t\t)" << endl;
|
|---|
| 175 | *file << "\t)" << endl;
|
|---|
| 176 | break;
|
|---|
| 177 | default:
|
|---|
| 178 | DoeLog(0) && (eLog() << Verbose(0)
|
|---|
| 179 | << "Unknown level of theory requested for MPQC output file." << std::endl);
|
|---|
| 180 | break;
|
|---|
| 181 | }
|
|---|
| 182 | *file << ")" << endl;
|
|---|
| 183 | *file << "molecule<Molecule>: (" << endl;
|
|---|
| 184 | *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
|
|---|
| 185 | *file << "\t{ atoms geometry } = {" << endl;
|
|---|
| 186 | // output of atoms
|
|---|
| 187 | for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
|
|---|
| 188 | (*AtomRunner)->OutputMPQCLine(file, ¢er);
|
|---|
| 189 | }
|
|---|
| 190 | *file << "\t}" << endl;
|
|---|
| 191 | *file << ")" << endl;
|
|---|
| 192 | *file << "basis<GaussianBasisSet>: (" << endl;
|
|---|
| 193 | *file << "\tname = \"" << World::getInstance().getConfig()->basis << "\"" << endl;
|
|---|
| 194 | *file << "\tmolecule = $:molecule" << endl;
|
|---|
| 195 | *file << ")" << endl;
|
|---|
| 196 | if (theory == MBPT2_R12) {
|
|---|
| 197 | *file << "% auxiliary basis set specification" << endl;
|
|---|
| 198 | *file << "\tabasis<GaussianBasisSet>: (" << endl;
|
|---|
| 199 | *file << "\tname = \"aug-cc-pVDZ\"" << endl;
|
|---|
| 200 | *file << "\tmolecule = $:molecule" << endl;
|
|---|
| 201 | *file << ")" << endl;
|
|---|
| 202 | }
|
|---|
| 203 | }
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | /** Sets whether hessian is desired or not
|
|---|
| 207 | * \param hessian statement
|
|---|
| 208 | */
|
|---|
| 209 | void MpqcParser::setHessian(bool hessian)
|
|---|
| 210 | {
|
|---|
| 211 | HessianPresent = hessian;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | /** Sets the desired level of solving theory to use
|
|---|
| 215 | * \param _theory shorthand of the theory
|
|---|
| 216 | */
|
|---|
| 217 | void MpqcParser::setTheory(enum Theory _theory)
|
|---|
| 218 | {
|
|---|
| 219 | theory = _theory;
|
|---|
| 220 | }
|
|---|