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 | {
|
---|
66 | // bool Psi3Section = false;
|
---|
67 | // bool MoleculeSection = false;
|
---|
68 | // bool GeometrySection = false;
|
---|
69 | // bool BasisSection = false;
|
---|
70 | // bool AuxBasisSection = false;
|
---|
71 | // char line[MAXSTRINGSIZE];
|
---|
72 | // typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
---|
73 | // boost::char_separator<char> sep("[]");
|
---|
74 | // boost::char_separator<char> angularsep("<>");
|
---|
75 | // boost::char_separator<char> equalitysep(" =");
|
---|
76 | // boost::char_separator<char> whitesep(" \t");
|
---|
77 | // ConvertTo<double> toDouble;
|
---|
78 | //
|
---|
79 | // molecule *newmol = World::getInstance().createMolecule();
|
---|
80 | // newmol->ActiveFlag = true;
|
---|
81 | // // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
|
---|
82 | // World::getInstance().getMolecules()->insert(newmol);
|
---|
83 | // while (file->good()) {
|
---|
84 | // file->getline(line, MAXSTRINGSIZE-1);
|
---|
85 | // std::string linestring(line);
|
---|
86 | // if ((linestring.find("atoms geometry") == string::npos) && (linestring.find("}") != string::npos)) {
|
---|
87 | // GeometrySection = false;
|
---|
88 | // }
|
---|
89 | // if ((linestring.find(")") != string::npos)) { // ends a section which do not overlap
|
---|
90 | // Psi3Section = false;
|
---|
91 | // MoleculeSection = false;
|
---|
92 | // BasisSection = false;
|
---|
93 | // AuxBasisSection = false;
|
---|
94 | // }
|
---|
95 | // if (MoleculeSection) {
|
---|
96 | // if (GeometrySection) { // we have an atom
|
---|
97 | // tokenizer tokens(linestring, sep);
|
---|
98 | // // if (tokens.size() != 2)
|
---|
99 | // // throw Psi3ParseException;
|
---|
100 | // tokenizer::iterator tok_iter = tokens.begin();
|
---|
101 | // ASSERT(tok_iter != tokens.end(),
|
---|
102 | // "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!");
|
---|
103 | // std::stringstream whitespacefilter(*tok_iter++);
|
---|
104 | // std::string element;
|
---|
105 | // whitespacefilter >> ws >> element;
|
---|
106 | // ASSERT(tok_iter != tokens.end(),
|
---|
107 | // "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!");
|
---|
108 | // std::string vector = *tok_iter;
|
---|
109 | // tokenizer vectorcomponents(vector, whitesep);
|
---|
110 | // Vector X;
|
---|
111 | // // if (vectorcomponents.size() != NDIM)
|
---|
112 | // // throw Psi3ParseException;
|
---|
113 | // tok_iter = vectorcomponents.begin();
|
---|
114 | // for (int i=0; i<NDIM; ++i) {
|
---|
115 | // X[i] = toDouble(*tok_iter++);
|
---|
116 | // }
|
---|
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 | // }
|
---|
125 | // if (Psi3Section) {
|
---|
126 | // if (linestring.find("mole<") != string::npos) { // get theory
|
---|
127 | // tokenizer tokens(linestring, angularsep);
|
---|
128 | // tokenizer::iterator tok_iter = tokens.begin();
|
---|
129 | // ++tok_iter;
|
---|
130 | // ASSERT(tok_iter != tokens.end(),
|
---|
131 | // "FormatParser< psi3 >::load() - missing token in brackets<> for mole< in line "+linestring+"!");
|
---|
132 | // std::string value(*tok_iter);
|
---|
133 | // std::stringstream linestream("theory = "+value);
|
---|
134 | // linestream >> getParams();
|
---|
135 | // } else if (linestring.find("integrals<") != string::npos) { // get theory
|
---|
136 | // tokenizer tokens(linestring, angularsep);
|
---|
137 | // tokenizer::iterator tok_iter = tokens.begin();
|
---|
138 | // ++tok_iter;
|
---|
139 | // ASSERT(tok_iter != tokens.end(),
|
---|
140 | // "FormatParser< psi3 >::load() - missing token in brackets<> for integrals< in line "+linestring+"!");
|
---|
141 | // std::string value(*tok_iter);
|
---|
142 | // std::stringstream linestream("integration = "+value);
|
---|
143 | // linestream >> getParams();
|
---|
144 | // } else if ((linestring.find("molecule") == string::npos) && (linestring.find("basis") == string::npos)){
|
---|
145 | // // molecule and basis must not be parsed in this section
|
---|
146 | // tokenizer tokens(linestring, equalitysep);
|
---|
147 | // tokenizer::iterator tok_iter = tokens.begin();
|
---|
148 | // ASSERT(tok_iter != tokens.end(),
|
---|
149 | // "FormatParser< psi3 >::load() - missing token before '=' for Psi3Section in line "+linestring+"!");
|
---|
150 | // std::stringstream whitespacefilter(*tok_iter);
|
---|
151 | // std::string key;
|
---|
152 | // whitespacefilter >> ws >> key;
|
---|
153 | // if (getParams().haveParameter(key)) {
|
---|
154 | // std::stringstream linestream(linestring);
|
---|
155 | // linestream >> getParams();
|
---|
156 | // } else { // unknown keys are simply ignored as long as parser is incomplete
|
---|
157 | // DoLog(2) && (Log() << Verbose(2) << "INFO: '"+key+"' is unknown and ignored." << std::endl);
|
---|
158 | // }
|
---|
159 | // }
|
---|
160 | // }
|
---|
161 | // if (BasisSection) {
|
---|
162 | // tokenizer tokens(linestring, equalitysep);
|
---|
163 | // tokenizer::iterator tok_iter = tokens.begin();
|
---|
164 | // ASSERT(tok_iter != tokens.end(),
|
---|
165 | // "FormatParser< psi3 >::load() - missing token for BasisSection in line "+linestring+"!");
|
---|
166 | // std::string key(*tok_iter++);
|
---|
167 | // ASSERT(tok_iter != tokens.end(),
|
---|
168 | // "FormatParser< psi3 >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
|
---|
169 | // std::string value(*tok_iter);
|
---|
170 | // tok_iter++;
|
---|
171 | // // TODO: use exception instead of ASSERT
|
---|
172 | // ASSERT(tok_iter == tokens.end(),
|
---|
173 | // "FormatParser< psi3 >::load() - more than (key = value) on line "+linestring+".");
|
---|
174 | // if (key == "name") {
|
---|
175 | // std::stringstream linestream("basis = "+value);
|
---|
176 | // linestream >> getParams();
|
---|
177 | // }
|
---|
178 | // }
|
---|
179 | // if (AuxBasisSection) {
|
---|
180 | // tokenizer tokens(linestring, equalitysep);
|
---|
181 | // tokenizer::iterator tok_iter = tokens.begin();
|
---|
182 | // ASSERT(tok_iter != tokens.end(),
|
---|
183 | // "FormatParser< psi3 >::load() - missing token for AuxBasisSection in line "+linestring+"!");
|
---|
184 | // std::string key(*tok_iter++);
|
---|
185 | // ASSERT(tok_iter != tokens.end(),
|
---|
186 | // "FormatParser< psi3 >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
|
---|
187 | // std::string value(*tok_iter);
|
---|
188 | // tok_iter++;
|
---|
189 | // // TODO: use exception instead of ASSERT
|
---|
190 | // ASSERT(tok_iter == tokens.end(),
|
---|
191 | // "FormatParser< psi3 >::load() - more than (key = value) on line "+linestring+".");
|
---|
192 | // if (key == "name") {
|
---|
193 | // std::stringstream linestream("aux_basis = "+value);
|
---|
194 | // linestream >> getParams();
|
---|
195 | // }
|
---|
196 | // }
|
---|
197 | // // set some scan flags
|
---|
198 | // if (linestring.find("psi3:") != string::npos) {
|
---|
199 | // Psi3Section = true;
|
---|
200 | // }
|
---|
201 | // if (linestring.find("molecule<Molecule>:") != string::npos) {
|
---|
202 | // MoleculeSection = true;
|
---|
203 | // }
|
---|
204 | // if (linestring.find("atoms geometry") != string::npos) {
|
---|
205 | // GeometrySection = true;
|
---|
206 | // }
|
---|
207 | // if ((linestring.find("basis<GaussianBasisSet>:") != string::npos) && ((linestring.find("abasis<") == string::npos))) {
|
---|
208 | // BasisSection = true;
|
---|
209 | // }
|
---|
210 | // if (linestring.find("abasis<") != string::npos) {
|
---|
211 | // AuxBasisSection = true;
|
---|
212 | // }
|
---|
213 | // }
|
---|
214 | // // refresh atom::nr and atom::name
|
---|
215 | // newmol->getAtomCount();
|
---|
216 | }
|
---|
217 |
|
---|
218 | /** Saves all atoms and data into a MPQC config file.
|
---|
219 | * \param *file output stream
|
---|
220 | * \param atoms atoms to store
|
---|
221 | */
|
---|
222 | void FormatParser< psi3 >::save(ostream *file, const std::vector<atom *> &atoms)
|
---|
223 | {
|
---|
224 | // Vector center;
|
---|
225 | //// vector<atom *> allatoms = World::getInstance().getAllAtoms();
|
---|
226 | //
|
---|
227 | // // calculate center
|
---|
228 | // for (std::vector<atom *>::const_iterator runner = atoms.begin();runner != atoms.end(); ++runner)
|
---|
229 | // center += (*runner)->getPosition();
|
---|
230 | // center.Scale(1./(double)atoms.size());
|
---|
231 | //
|
---|
232 | // // first without hessian
|
---|
233 | // if (file->fail()) {
|
---|
234 | // DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open psi3 output file." << endl);
|
---|
235 | // } else {
|
---|
236 | // *file << "% Created by MoleCuilder" << endl;
|
---|
237 | // *file << "psi3: (" << endl;
|
---|
238 | // *file << "\tsavestate = " << getParams().getParameter(Psi3Parser_Parameters::savestateParam) << endl;
|
---|
239 | // *file << "\tdo_gradient = " << getParams().getParameter(Psi3Parser_Parameters::do_gradientParam) << endl;
|
---|
240 | // if (Converter(getParams().getParameter(Psi3Parser_Parameters::hessianParam))) {
|
---|
241 | // *file << "\tfreq<MolecularFrequencies>: (" << endl;
|
---|
242 | // *file << "\t\tmolecule=$:molecule" << endl;
|
---|
243 | // *file << "\t)" << endl;
|
---|
244 | // }
|
---|
245 | // const std::string theory = getParams().getParameter(Psi3Parser_Parameters::theoryParam);
|
---|
246 | // if (theory == getParams().getTheoryName(Psi3Parser_Parameters::CLHF)) {
|
---|
247 | // *file << "\tmole<" << getParams().getParameter(Psi3Parser_Parameters::theoryParam) << ">: (" << endl;
|
---|
248 | // *file << "\t\tmolecule = $:molecule" << endl;
|
---|
249 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
250 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::maxiterParam)
|
---|
251 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::maxiterParam)<< endl;
|
---|
252 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::memoryParam)
|
---|
253 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
254 | // *file << "\t)" << endl;
|
---|
255 | // } else if (theory == getParams().getTheoryName(Psi3Parser_Parameters::CLKS)) {
|
---|
256 | // *file << "\tmole<" << getParams().getParameter(Psi3Parser_Parameters::theoryParam) << ">: (" << endl;
|
---|
257 | // *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
|
---|
258 | // *file << "\t\tmolecule = $:molecule" << endl;
|
---|
259 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
260 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::maxiterParam)
|
---|
261 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::maxiterParam)<< endl;
|
---|
262 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::memoryParam)
|
---|
263 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
264 | // *file << "\t)" << endl;
|
---|
265 | // } else if (theory == getParams().getTheoryName(Psi3Parser_Parameters::MBPT2)) {
|
---|
266 | // *file << "\tmole<" << getParams().getParameter(Psi3Parser_Parameters::theoryParam) << ">: (" << endl;
|
---|
267 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
268 | // *file << "\t\tmolecule = $:molecule" << endl;
|
---|
269 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::memoryParam)
|
---|
270 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
271 | // *file << "\t\treference<CLHF>: (" << endl;
|
---|
272 | // *file << "\t\t\t" << getParams().getParameterName(Psi3Parser_Parameters::maxiterParam)
|
---|
273 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::maxiterParam)<< endl;
|
---|
274 | // *file << "\t\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
275 | // *file << "\t\t\tmolecule = $:molecule" << endl;
|
---|
276 | // *file << "\t\t\t" << getParams().getParameterName(Psi3Parser_Parameters::memoryParam)
|
---|
277 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
278 | // *file << "\t\t)" << endl;
|
---|
279 | // *file << "\t)" << endl;
|
---|
280 | // } else if (theory == getParams().getTheoryName(Psi3Parser_Parameters::MBPT2_R12)) {
|
---|
281 | // *file << "\tmole<" << getParams().getParameter(Psi3Parser_Parameters::theoryParam) << ">: (" << endl;
|
---|
282 | // *file << "\t\tmolecule = $:molecule" << endl;
|
---|
283 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
284 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::aux_basisParam) << " = $:abasis" << endl;
|
---|
285 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::stdapproxParam)
|
---|
286 | // << " = \"" << getParams().getParameter(Psi3Parser_Parameters::stdapproxParam) << "\"" << endl;
|
---|
287 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::nfzcParam)
|
---|
288 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::nfzcParam) << endl;
|
---|
289 | // *file << "\t\t" << getParams().getParameterName(Psi3Parser_Parameters::memoryParam)
|
---|
290 | // << " = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
291 | // *file << "\t\tintegrals<IntegralCints>:()" << endl;
|
---|
292 | // *file << "\t\treference<CLHF>: (" << endl;
|
---|
293 | // *file << "\t\t\tmolecule = $:molecule" << endl;
|
---|
294 | // *file << "\t\t\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam) << " = $:basis" << endl;
|
---|
295 | // *file << "\t\t\tmaxiter = " << getParams().getParameter(Psi3Parser_Parameters::maxiterParam) << endl;
|
---|
296 | // *file << "\t\t\tmemory = " << getParams().getParameter(Psi3Parser_Parameters::memoryParam) << endl;
|
---|
297 | // *file << "\t\t\tintegrals<" << getParams().getParameter(Psi3Parser_Parameters::integrationParam) << ">:()" << endl;
|
---|
298 | // *file << "\t\t)" << endl;
|
---|
299 | // *file << "\t)" << endl;
|
---|
300 | // } else {
|
---|
301 | // DoeLog(0) && (eLog() << Verbose(0)
|
---|
302 | // << "Unknown level of theory requested for MPQC output file." << std::endl);
|
---|
303 | // }
|
---|
304 | // *file << ")" << endl;
|
---|
305 | // *file << "molecule<Molecule>: (" << endl;
|
---|
306 | // *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
|
---|
307 | // *file << "\t{ atoms geometry } = {" << endl;
|
---|
308 | // // output of atoms
|
---|
309 | // for (std::vector<atom *>::const_iterator AtomRunner = atoms.begin(); AtomRunner != atoms.end(); ++AtomRunner) {
|
---|
310 | // (*AtomRunner)->OutputMPQCLine(file, ¢er);
|
---|
311 | // }
|
---|
312 | // *file << "\t}" << endl;
|
---|
313 | // *file << ")" << endl;
|
---|
314 | // *file << "basis<GaussianBasisSet>: (" << endl;
|
---|
315 | // *file << "\tname = \"" << getParams().getParameter(Psi3Parser_Parameters::basisParam) << "\"" << endl;
|
---|
316 | // *file << "\tmolecule = $:molecule" << endl;
|
---|
317 | // *file << ")" << endl;
|
---|
318 | // if (theory == getParams().getTheoryName(Psi3Parser_Parameters::MBPT2_R12)) {
|
---|
319 | // *file << "% auxiliary basis set specification" << endl;
|
---|
320 | // *file << "\tabasis<GaussianBasisSet>: (" << endl;
|
---|
321 | // *file << "\tname = \"" << getParams().getParameter(Psi3Parser_Parameters::aux_basisParam) << "\"" << endl;
|
---|
322 | // *file << "\tmolecule = $:molecule" << endl;
|
---|
323 | // *file << ")" << endl;
|
---|
324 | // }
|
---|
325 | // }
|
---|
326 | }
|
---|
327 |
|
---|
328 |
|
---|