source: src/Parser/MpqcParser.cpp@ a636f8

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 a636f8 was 03a589, checked in by Frederik Heber <heber@…>, 13 years ago

Removed lots of remnant output functions in atom and molecule that are not used anymore.

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