[1bef07] | 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 | * Psi3Parser.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Oct 04, 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 "Psi3Parser.hpp"
|
---|
| 27 | #include "Psi3Parser_Parameters.hpp"
|
---|
| 28 |
|
---|
| 29 | #include "atom.hpp"
|
---|
| 30 | #include "config.hpp"
|
---|
| 31 | #include "element.hpp"
|
---|
| 32 | #include "molecule.hpp"
|
---|
| 33 | #include "CodePatterns/Log.hpp"
|
---|
| 34 | #include "CodePatterns/toString.hpp"
|
---|
| 35 | #include "CodePatterns/Verbose.hpp"
|
---|
| 36 | #include "LinearAlgebra/Vector.hpp"
|
---|
| 37 | #include "periodentafel.hpp"
|
---|
| 38 | #include "World.hpp"
|
---|
| 39 |
|
---|
| 40 | // declare specialized static variables
|
---|
| 41 | const std::string FormatParserTrait<psi3>::name = "psi3";
|
---|
| 42 | const std::string FormatParserTrait<psi3>::suffix = "in";
|
---|
| 43 | const ParserTypes FormatParserTrait<psi3>::type = psi3;
|
---|
| 44 |
|
---|
| 45 | // a converter we often need
|
---|
| 46 | ConvertTo<bool> FormatParser<psi3>::Converter;
|
---|
| 47 |
|
---|
| 48 | /** Constructor of Psi3Parser.
|
---|
| 49 | *
|
---|
| 50 | */
|
---|
| 51 | FormatParser< psi3 >::FormatParser() :
|
---|
| 52 | FormatParser_common(new Psi3Parser_Parameters())
|
---|
| 53 | {}
|
---|
| 54 |
|
---|
| 55 | /** Destructor of Psi3Parser.
|
---|
| 56 | *
|
---|
| 57 | */
|
---|
| 58 | FormatParser< psi3 >::~FormatParser()
|
---|
| 59 | {}
|
---|
| 60 |
|
---|
| 61 | /** Load an MPQC config file into the World.
|
---|
| 62 | * \param *file input stream
|
---|
| 63 | */
|
---|
| 64 | void FormatParser< psi3 >::load(istream *file)
|
---|
| 65 | {
|
---|
[032f31] | 66 | bool Psi3Section = false;
|
---|
| 67 | bool GeometrySection = false;
|
---|
| 68 | char line[MAXSTRINGSIZE];
|
---|
| 69 | typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
---|
| 70 | boost::char_separator<char> sep("()");
|
---|
| 71 | boost::char_separator<char> angularsep("<>");
|
---|
| 72 | boost::char_separator<char> equalitysep(" =");
|
---|
| 73 | boost::char_separator<char> whitesep(" \t");
|
---|
| 74 | ConvertTo<double> toDouble;
|
---|
| 75 |
|
---|
| 76 | molecule *newmol = World::getInstance().createMolecule();
|
---|
| 77 | newmol->ActiveFlag = true;
|
---|
| 78 | // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
|
---|
| 79 | World::getInstance().getMolecules()->insert(newmol);
|
---|
| 80 | while (file->good()) {
|
---|
| 81 | file->getline(line, MAXSTRINGSIZE-1);
|
---|
| 82 | std::string linestring(line);
|
---|
| 83 | LOG(3, "INFO: Current line is: " << line);
|
---|
| 84 | if ((linestring.find(")") != string::npos) && (linestring.find("(") == string::npos)) {
|
---|
| 85 | LOG(3, "INFO: Line contains ')' and no '(' (end of section): " << line);
|
---|
| 86 | // ends a section which do not overlap
|
---|
| 87 | if (GeometrySection)
|
---|
| 88 | GeometrySection = false;
|
---|
| 89 | else
|
---|
| 90 | Psi3Section = false;
|
---|
| 91 | }
|
---|
| 92 | if (GeometrySection) { // we have an atom
|
---|
| 93 | tokenizer tokens(linestring, sep);
|
---|
| 94 | // if (tokens.size() != 2)
|
---|
| 95 | // throw Psi3ParseException;
|
---|
| 96 | tokenizer::iterator tok_iter = tokens.begin();
|
---|
| 97 | ASSERT(tok_iter != tokens.end(),
|
---|
| 98 | "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!");
|
---|
| 99 | std::stringstream whitespacefilter(*++tok_iter);
|
---|
| 100 | std::string element;
|
---|
| 101 | whitespacefilter >> ws >> element;
|
---|
| 102 | LOG(2, "INFO: element of atom is " << element);
|
---|
| 103 | ASSERT(tok_iter != tokens.end(),
|
---|
| 104 | "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!");
|
---|
| 105 | std::string vector = *tok_iter;
|
---|
| 106 | tokenizer vectorcomponents(vector, whitesep);
|
---|
| 107 | Vector X;
|
---|
| 108 | // if (vectorcomponents.size() != NDIM)
|
---|
| 109 | // throw Psi3ParseException;
|
---|
| 110 | tok_iter = vectorcomponents.begin();
|
---|
| 111 | ++tok_iter;
|
---|
| 112 | for (int i=0; i<NDIM; ++i) {
|
---|
| 113 | LOG(4, "INFO: Current value is " << *tok_iter << ".");
|
---|
| 114 | X[i] = toDouble(*tok_iter++);
|
---|
| 115 | }
|
---|
| 116 | LOG(2, "INFO: position of atom is " << X);
|
---|
| 117 | // create atom
|
---|
| 118 | atom *newAtom = World::getInstance().createAtom();
|
---|
| 119 | newAtom->setType(World::getInstance().getPeriode()->FindElement(element));
|
---|
| 120 | newAtom->setPosition(X);
|
---|
| 121 | newmol->AddAtom(newAtom);
|
---|
| 122 | DoLog(1) && (Log() << Verbose(1) << "Adding atom " << *newAtom << std::endl);
|
---|
| 123 | }
|
---|
| 124 | if ((Psi3Section) && (!GeometrySection)) {
|
---|
| 125 | if (linestring.find("=") != string::npos) { // get param value
|
---|
| 126 | tokenizer tokens(linestring, equalitysep);
|
---|
| 127 | tokenizer::iterator tok_iter = tokens.begin();
|
---|
| 128 | ASSERT(tok_iter != tokens.end(),
|
---|
| 129 | "FormatParser< psi3 >::load() - missing token before '=' for Psi3Section in line "+linestring+"!");
|
---|
| 130 | std::stringstream whitespacefilter(*tok_iter);
|
---|
| 131 | std::string key;
|
---|
| 132 | whitespacefilter >> ws >> key;
|
---|
| 133 | //LOG(2, "INFO: key to check is: " << key);
|
---|
| 134 | if (getParams().haveParameter(key)) {
|
---|
| 135 | //LOG(2, "INFO: Line submitted to parameter is: " << linestring);
|
---|
| 136 | std::stringstream linestream(linestring);
|
---|
| 137 | linestream >> getParams();
|
---|
| 138 | } else { // unknown keys are simply ignored as long as parser is incomplete
|
---|
| 139 | LOG(3, "INFO: '"+key+"' is unknown and ignored.");
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | if ((linestring.find("geometry") != string::npos) && (linestring.find("(") != string::npos)) {
|
---|
| 144 | LOG(3, "INFO: Line contains geometry and '(': " << line);
|
---|
| 145 | GeometrySection = true;
|
---|
| 146 | }
|
---|
| 147 | if ((linestring.find("psi:") != string::npos) && (linestring.find("(") != string::npos)) {
|
---|
| 148 | LOG(3, "INFO: Line contains psi: and '(': " << line);
|
---|
| 149 | Psi3Section = true;
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 | // refresh atom::nr and atom::name
|
---|
| 153 | newmol->getAtomCount();
|
---|
[1bef07] | 154 | }
|
---|
| 155 |
|
---|
| 156 | /** Saves all atoms and data into a MPQC config file.
|
---|
| 157 | * \param *file output stream
|
---|
| 158 | * \param atoms atoms to store
|
---|
| 159 | */
|
---|
| 160 | void FormatParser< psi3 >::save(ostream *file, const std::vector<atom *> &atoms)
|
---|
| 161 | {
|
---|
| 162 | // Vector center;
|
---|
| 163 | //// vector<atom *> allatoms = World::getInstance().getAllAtoms();
|
---|
| 164 | //
|
---|
| 165 | // // calculate center
|
---|
| 166 | // for (std::vector<atom *>::const_iterator runner = atoms.begin();runner != atoms.end(); ++runner)
|
---|
| 167 | // center += (*runner)->getPosition();
|
---|
| 168 | // center.Scale(1./(double)atoms.size());
|
---|
| 169 | //
|
---|
| 170 | // // first without hessian
|
---|
| 171 | // if (file->fail()) {
|
---|
| 172 | // DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open psi3 output file." << endl);
|
---|
| 173 | // } else {
|
---|
| 174 | // *file << "% Created by MoleCuilder" << endl;
|
---|
| 175 | // *file << "psi3: (" << endl;
|
---|
| 176 | // *file << "\tsavestate = " << getParams().getParameter(Psi3Parser_Parameters::savestateParam) << endl;
|
---|
| 177 | // *file << "\tdo_gradient = " << getParams().getParameter(Psi3Parser_Parameters::do_gradientParam) << endl;
|
---|
| 178 | // if (Converter(getParams().getParameter(Psi3Parser_Parameters::hessianParam))) {
|
---|
| 179 | // *file << "\tfreq<MolecularFrequencies>: (" << endl;
|
---|
| 180 | // *file << "\t\tmolecule=$:molecule" << endl;
|
---|
| 181 | // *file << "\t)" << endl;
|
---|
| 182 | // }
|
---|
| 183 | // const std::string theory = getParams().getParameter(Psi3Parser_Parameters::theoryParam);
|
---|
| 184 | // if (theory == getParams().getTheoryName(Psi3Parser_Parameters::CLHF)) {
|
---|
| 185 | // *file << "\tmole<" << getParams().getParameter(Psi3Parser_Parameters::theoryParam) << ">: (" << endl;
|
---|
| 186 | // *file << "\t\tmolecule = $:molecule" << endl;
|
---|
| 187 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
| 188 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::maxiterParam)
|
---|
| 189 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::maxiterParam)<< endl;
|
---|
| 190 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::memoryParam)
|
---|
| 191 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
| 192 | // *file << "\t)" << endl;
|
---|
| 193 | // } else if (theory == getParams().getTheoryName(Psi3Parser_Parameters::CLKS)) {
|
---|
| 194 | // *file << "\tmole<" << getParams().getParameter(Psi3Parser_Parameters::theoryParam) << ">: (" << endl;
|
---|
| 195 | // *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
|
---|
| 196 | // *file << "\t\tmolecule = $:molecule" << endl;
|
---|
| 197 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
| 198 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::maxiterParam)
|
---|
| 199 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::maxiterParam)<< endl;
|
---|
| 200 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::memoryParam)
|
---|
| 201 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
| 202 | // *file << "\t)" << endl;
|
---|
| 203 | // } else if (theory == getParams().getTheoryName(Psi3Parser_Parameters::MBPT2)) {
|
---|
| 204 | // *file << "\tmole<" << getParams().getParameter(Psi3Parser_Parameters::theoryParam) << ">: (" << endl;
|
---|
| 205 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
| 206 | // *file << "\t\tmolecule = $:molecule" << endl;
|
---|
| 207 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::memoryParam)
|
---|
| 208 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
| 209 | // *file << "\t\treference<CLHF>: (" << endl;
|
---|
| 210 | // *file << "\t\t\t" << getParams().getParameterName(Psi3Parser_Parameters::maxiterParam)
|
---|
| 211 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::maxiterParam)<< endl;
|
---|
| 212 | // *file << "\t\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
| 213 | // *file << "\t\t\tmolecule = $:molecule" << endl;
|
---|
| 214 | // *file << "\t\t\t" << getParams().getParameterName(Psi3Parser_Parameters::memoryParam)
|
---|
| 215 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
| 216 | // *file << "\t\t)" << endl;
|
---|
| 217 | // *file << "\t)" << endl;
|
---|
| 218 | // } else if (theory == getParams().getTheoryName(Psi3Parser_Parameters::MBPT2_R12)) {
|
---|
| 219 | // *file << "\tmole<" << getParams().getParameter(Psi3Parser_Parameters::theoryParam) << ">: (" << endl;
|
---|
| 220 | // *file << "\t\tmolecule = $:molecule" << endl;
|
---|
| 221 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
| 222 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::aux_basisParam) << " = $:abasis" << endl;
|
---|
| 223 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::stdapproxParam)
|
---|
| 224 | // << " = \"" << getParams().getParameter(Psi3Parser_Parameters::stdapproxParam) << "\"" << endl;
|
---|
| 225 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::nfzcParam)
|
---|
| 226 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::nfzcParam) << endl;
|
---|
| 227 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::memoryParam)
|
---|
| 228 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
| 229 | // *file << "\t\tintegrals<IntegralCints>:()" << endl;
|
---|
| 230 | // *file << "\t\treference<CLHF>: (" << endl;
|
---|
| 231 | // *file << "\t\t\tmolecule = $:molecule" << endl;
|
---|
| 232 | // *file << "\t\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
| 233 | // *file << "\t\t\tmaxiter = " << getParams().getParameter(Psi3Parser_Parameters::maxiterParam) << endl;
|
---|
| 234 | // *file << "\t\t\tmemory = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
| 235 | // *file << "\t\t\tintegrals<" << getParams().getParameter(Psi3Parser_Parameters::integrationParam) << ">:()" << endl;
|
---|
| 236 | // *file << "\t\t)" << endl;
|
---|
| 237 | // *file << "\t)" << endl;
|
---|
| 238 | // } else {
|
---|
| 239 | // DoeLog(0) && (eLog() << Verbose(0)
|
---|
| 240 | // << "Unknown level of theory requested for MPQC output file." << std::endl);
|
---|
| 241 | // }
|
---|
| 242 | // *file << ")" << endl;
|
---|
| 243 | // *file << "molecule<Molecule>: (" << endl;
|
---|
| 244 | // *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
|
---|
| 245 | // *file << "\t{ atoms geometry } = {" << endl;
|
---|
| 246 | // // output of atoms
|
---|
| 247 | // for (std::vector<atom *>::const_iterator AtomRunner = atoms.begin(); AtomRunner != atoms.end(); ++AtomRunner) {
|
---|
| 248 | // (*AtomRunner)->OutputMPQCLine(file, ¢er);
|
---|
| 249 | // }
|
---|
| 250 | // *file << "\t}" << endl;
|
---|
| 251 | // *file << ")" << endl;
|
---|
| 252 | // *file << "basis<GaussianBasisSet>: (" << endl;
|
---|
| 253 | // *file << "\tname = \"" << getParams().getParameter(Psi3Parser_Parameters::basisParam) << "\"" << endl;
|
---|
| 254 | // *file << "\tmolecule = $:molecule" << endl;
|
---|
| 255 | // *file << ")" << endl;
|
---|
| 256 | // if (theory == getParams().getTheoryName(Psi3Parser_Parameters::MBPT2_R12)) {
|
---|
| 257 | // *file << "% auxiliary basis set specification" << endl;
|
---|
| 258 | // *file << "\tabasis<GaussianBasisSet>: (" << endl;
|
---|
| 259 | // *file << "\tname = \"" << getParams().getParameter(Psi3Parser_Parameters::aux_basisParam) << "\"" << endl;
|
---|
| 260 | // *file << "\tmolecule = $:molecule" << endl;
|
---|
| 261 | // *file << ")" << endl;
|
---|
| 262 | // }
|
---|
| 263 | // }
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 |
|
---|