source: src/Parser/MpqcParser.cpp@ b49c5d

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since b49c5d was 0aa122, checked in by Frederik Heber <heber@…>, 13 years ago

Updated all source files's copyright note to current year 2012.

  • Property mode set to 100644
File size: 14.6 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[bcf653]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"
[c1db05]27#include "MpqcParser_Parameters.hpp"
[1b2d30]28
[6f0841]29#include "Atom/atom.hpp"
[41a467]30#include "CodePatterns/Log.hpp"
31#include "CodePatterns/toString.hpp"
[1b2d30]32#include "config.hpp"
[3bdb6d]33#include "Element/element.hpp"
[41a467]34#include "Element/periodentafel.hpp"
35#include "LinearAlgebra/Vector.hpp"
[aa8ef2]36#include "molecule.hpp"
[42127c]37#include "MoleculeListClass.hpp"
[1b2d30]38#include "World.hpp"
39
[765f16]40// declare specialized static variables
41const std::string FormatParserTrait<mpqc>::name = "mpqc";
42const std::string FormatParserTrait<mpqc>::suffix = "in";
43const ParserTypes FormatParserTrait<mpqc>::type = mpqc;
[1b2d30]44
[ee50c1]45// a converter we often need
46ConvertTo<bool> FormatParser<mpqc>::Converter;
[1b2d30]47
48/** Constructor of MpqcParser.
49 *
50 */
[765f16]51FormatParser< mpqc >::FormatParser() :
52 FormatParser_common(new MpqcParser_Parameters())
53{}
[1b2d30]54
55/** Destructor of MpqcParser.
56 *
57 */
[765f16]58FormatParser< mpqc >::~FormatParser()
59{}
[1b2d30]60
61/** Load an MPQC config file into the World.
62 * \param *file input stream
63 */
[765f16]64void FormatParser< mpqc >::load(istream *file)
[1b2d30]65{
[4cbca0]66 bool MpqcSection = false;
67 bool MoleculeSection = false;
68 bool GeometrySection = false;
69 bool BasisSection = false;
70 bool AuxBasisSection = false;
[aa8ef2]71 char line[MAXSTRINGSIZE];
72 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
73 boost::char_separator<char> sep("[]");
[4cbca0]74 boost::char_separator<char> angularsep("<>");
[311da7b]75 boost::char_separator<char> equalitysep(" =");
[aa8ef2]76 boost::char_separator<char> whitesep(" \t");
77 ConvertTo<double> toDouble;
78
79 molecule *newmol = World::getInstance().createMolecule();
80 newmol->ActiveFlag = true;
[4cbca0]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);
[aa8ef2]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)) {
[4cbca0]87 GeometrySection = false;
[aa8ef2]88 }
[4cbca0]89 if ((linestring.find(")") != string::npos)) { // ends a section which do not overlap
90 MpqcSection = 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 MpqcParseException;
100 tokenizer::iterator tok_iter = tokens.begin();
[311da7b]101 ASSERT(tok_iter != tokens.end(),
[765f16]102 "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");
[4cbca0]103 std::stringstream whitespacefilter(*tok_iter++);
104 std::string element;
[311da7b]105 whitespacefilter >> ws >> element;
106 ASSERT(tok_iter != tokens.end(),
[765f16]107 "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");
[4cbca0]108 std::string vector = *tok_iter;
109 tokenizer vectorcomponents(vector, whitesep);
110 Vector X;
111 // if (vectorcomponents.size() != NDIM)
112 // throw MpqcParseException;
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);
[47d041]122 LOG(1, "Adding atom " << *newAtom);
[4cbca0]123 }
124 }
125 if (MpqcSection) {
[311da7b]126 if (linestring.find("mole<") != string::npos) { // get theory
[4cbca0]127 tokenizer tokens(linestring, angularsep);
128 tokenizer::iterator tok_iter = tokens.begin();
[311da7b]129 ++tok_iter;
130 ASSERT(tok_iter != tokens.end(),
[765f16]131 "FormatParser< mpqc >::load() - missing token in brackets<> for mole< in line "+linestring+"!");
[311da7b]132 std::string value(*tok_iter);
[4cbca0]133 std::stringstream linestream("theory = "+value);
[c1db05]134 linestream >> getParams();
[4cbca0]135 } else if (linestring.find("integrals<") != string::npos) { // get theory
136 tokenizer tokens(linestring, angularsep);
137 tokenizer::iterator tok_iter = tokens.begin();
[311da7b]138 ++tok_iter;
139 ASSERT(tok_iter != tokens.end(),
[765f16]140 "FormatParser< mpqc >::load() - missing token in brackets<> for integrals< in line "+linestring+"!");
[311da7b]141 std::string value(*tok_iter);
[4cbca0]142 std::stringstream linestream("integration = "+value);
[c1db05]143 linestream >> getParams();
[311da7b]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(),
[765f16]149 "FormatParser< mpqc >::load() - missing token before '=' for MpqcSection in line "+linestring+"!");
[311da7b]150 std::stringstream whitespacefilter(*tok_iter);
151 std::string key;
152 whitespacefilter >> ws >> key;
[ee50c1]153 if (getParams().haveParameter(key)) {
[311da7b]154 std::stringstream linestream(linestring);
[c1db05]155 linestream >> getParams();
[311da7b]156 } else { // unknown keys are simply ignored as long as parser is incomplete
[47d041]157 LOG(2, "INFO: '"+key+"' is unknown and ignored.");
[311da7b]158 }
[4cbca0]159 }
160 }
161 if (BasisSection) {
162 tokenizer tokens(linestring, equalitysep);
163 tokenizer::iterator tok_iter = tokens.begin();
[311da7b]164 ASSERT(tok_iter != tokens.end(),
[765f16]165 "FormatParser< mpqc >::load() - missing token for BasisSection in line "+linestring+"!");
[4cbca0]166 std::string key(*tok_iter++);
[311da7b]167 ASSERT(tok_iter != tokens.end(),
[765f16]168 "FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
[4cbca0]169 std::string value(*tok_iter);
[311da7b]170 tok_iter++;
[4cbca0]171 // TODO: use exception instead of ASSERT
172 ASSERT(tok_iter == tokens.end(),
[765f16]173 "FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+".");
[4cbca0]174 if (key == "name") {
175 std::stringstream linestream("basis = "+value);
[c1db05]176 linestream >> getParams();
[4cbca0]177 }
178 }
179 if (AuxBasisSection) {
180 tokenizer tokens(linestring, equalitysep);
181 tokenizer::iterator tok_iter = tokens.begin();
[311da7b]182 ASSERT(tok_iter != tokens.end(),
[765f16]183 "FormatParser< mpqc >::load() - missing token for AuxBasisSection in line "+linestring+"!");
[4cbca0]184 std::string key(*tok_iter++);
[311da7b]185 ASSERT(tok_iter != tokens.end(),
[765f16]186 "FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
[4cbca0]187 std::string value(*tok_iter);
[311da7b]188 tok_iter++;
[4cbca0]189 // TODO: use exception instead of ASSERT
190 ASSERT(tok_iter == tokens.end(),
[765f16]191 "FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+".");
[4cbca0]192 if (key == "name") {
193 std::stringstream linestream("aux_basis = "+value);
[c1db05]194 linestream >> getParams();
[aa8ef2]195 }
196 }
197 // set some scan flags
[4cbca0]198 if (linestring.find("mpqc:") != string::npos) {
199 MpqcSection = true;
200 }
201 if (linestring.find("molecule<Molecule>:") != string::npos) {
202 MoleculeSection = true;
203 }
[aa8ef2]204 if (linestring.find("atoms geometry") != string::npos) {
[4cbca0]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;
[aa8ef2]212 }
213 }
[4afa46]214 // refresh atom::nr and atom::name
215 newmol->getAtomCount();
[1b2d30]216}
217
[f31edc]218/** Saves all atoms and data into a MPQC config file.
[1b2d30]219 * \param *file output stream
[73916f]220 * \param atoms atoms to store
[1b2d30]221 */
[765f16]222void FormatParser< mpqc >::save(ostream *file, const std::vector<atom *> &atoms)
[1b2d30]223{
224 Vector center;
[f7c19e]225// vector<atom *> allatoms = World::getInstance().getAllAtoms();
[1b2d30]226
[d6b8e1]227 // calculate center
[f7c19e]228 for (std::vector<atom *>::const_iterator runner = atoms.begin();runner != atoms.end(); ++runner)
[d74077]229 center += (*runner)->getPosition();
[f7c19e]230 center.Scale(1./(double)atoms.size());
[d6b8e1]231
[1b2d30]232 // first without hessian
233 if (file->fail()) {
[47d041]234 ELOG(1, "Cannot open mpqc output file.");
[1b2d30]235 } else {
236 *file << "% Created by MoleCuilder" << endl;
237 *file << "mpqc: (" << endl;
[ee50c1]238 *file << "\tsavestate = " << getParams().getParameter(MpqcParser_Parameters::savestateParam) << endl;
239 *file << "\tdo_gradient = " << getParams().getParameter(MpqcParser_Parameters::do_gradientParam) << endl;
240 if (Converter(getParams().getParameter(MpqcParser_Parameters::hessianParam))) {
[f31edc]241 *file << "\tfreq<MolecularFrequencies>: (" << endl;
242 *file << "\t\tmolecule=$:molecule" << endl;
243 *file << "\t)" << endl;
244 }
[ee50c1]245 const std::string theory = getParams().getParameter(MpqcParser_Parameters::theoryParam);
246 if (theory == getParams().getTheoryName(MpqcParser_Parameters::CLHF)) {
247 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
248 *file << "\t\tmolecule = $:molecule" << endl;
249 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
250 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam)
251 << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
252 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
253 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
254 *file << "\t)" << endl;
255 } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::CLKS)) {
256 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
257 *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
258 *file << "\t\tmolecule = $:molecule" << endl;
259 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
260 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam)
261 << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
262 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
263 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
264 *file << "\t)" << endl;
265 } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2)) {
266 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
267 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
268 *file << "\t\tmolecule = $:molecule" << endl;
269 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
270 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
271 *file << "\t\treference<CLHF>: (" << endl;
272 *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam)
273 << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
274 *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
275 *file << "\t\t\tmolecule = $:molecule" << endl;
276 *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
277 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
278 *file << "\t\t)" << endl;
279 *file << "\t)" << endl;
280 } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) {
281 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
282 *file << "\t\tmolecule = $:molecule" << endl;
283 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
284 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::aux_basisParam) << " = $:abasis" << endl;
285 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::stdapproxParam)
286 << " = \"" << getParams().getParameter(MpqcParser_Parameters::stdapproxParam) << "\"" << endl;
287 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::nfzcParam)
288 << " = " << getParams().getParameter(MpqcParser_Parameters::nfzcParam) << endl;
289 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
290 << " = " << getParams().getParameter(MpqcParser_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(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
295 *file << "\t\t\tmaxiter = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam) << endl;
296 *file << "\t\t\tmemory = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
297 *file << "\t\t\tintegrals<" << getParams().getParameter(MpqcParser_Parameters::integrationParam) << ">:()" << endl;
298 *file << "\t\t)" << endl;
299 *file << "\t)" << endl;
300 } else {
[47d041]301 ELOG(0, "Unknown level of theory requested for MPQC output file.");
[1b2d30]302 }
303 *file << ")" << endl;
304 *file << "molecule<Molecule>: (" << endl;
305 *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
306 *file << "\t{ atoms geometry } = {" << endl;
307 // output of atoms
[f7c19e]308 for (std::vector<atom *>::const_iterator AtomRunner = atoms.begin(); AtomRunner != atoms.end(); ++AtomRunner) {
[0dc86e2]309 (*AtomRunner)->OutputMPQCLine(file, &center);
[1b2d30]310 }
311 *file << "\t}" << endl;
312 *file << ")" << endl;
313 *file << "basis<GaussianBasisSet>: (" << endl;
[ee50c1]314 *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::basisParam) << "\"" << endl;
[1b2d30]315 *file << "\tmolecule = $:molecule" << endl;
316 *file << ")" << endl;
[ee50c1]317 if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) {
[f31edc]318 *file << "% auxiliary basis set specification" << endl;
319 *file << "\tabasis<GaussianBasisSet>: (" << endl;
[ee50c1]320 *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
[f31edc]321 *file << "\tmolecule = $:molecule" << endl;
322 *file << ")" << endl;
323 }
[1b2d30]324 }
325}
326
[963321a]327
Note: See TracBrowser for help on using the repository browser.