source: src/Parser/MpqcParser.cpp@ 794bc8

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 794bc8 was 6f0841, checked in by Frederik Heber <heber@…>, 13 years ago

Shifted all modules related to atoms into own subfolder src/Atom/

  • also created own convenience library for this. This makes unit testing on list containing TesselPoint or atom a lot easier.
  • shifted TesselPoint to src/Atom from src/Tesselation and adapted include's.
  • Property mode set to 100644
File size: 14.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2011 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#include "MpqcParser_Parameters.hpp"
28
29#include "Atom/atom.hpp"
30#include "CodePatterns/Log.hpp"
31#include "CodePatterns/toString.hpp"
32#include "config.hpp"
33#include "Element/element.hpp"
34#include "Element/periodentafel.hpp"
35#include "LinearAlgebra/Vector.hpp"
36#include "molecule.hpp"
37#include "MoleculeListClass.hpp"
38#include "World.hpp"
39
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;
44
45// a converter we often need
46ConvertTo<bool> FormatParser<mpqc>::Converter;
47
48/** Constructor of MpqcParser.
49 *
50 */
51FormatParser< mpqc >::FormatParser() :
52 FormatParser_common(new MpqcParser_Parameters())
53{}
54
55/** Destructor of MpqcParser.
56 *
57 */
58FormatParser< mpqc >::~FormatParser()
59{}
60
61/** Load an MPQC config file into the World.
62 * \param *file input stream
63 */
64void FormatParser< mpqc >::load(istream *file)
65{
66 bool MpqcSection = 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 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();
101 ASSERT(tok_iter != tokens.end(),
102 "FormatParser< mpqc >::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< mpqc >::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 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);
122 LOG(1, "Adding atom " << *newAtom);
123 }
124 }
125 if (MpqcSection) {
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< mpqc >::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< mpqc >::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< mpqc >::load() - missing token before '=' for MpqcSection 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 LOG(2, "INFO: '"+key+"' is unknown and ignored.");
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< mpqc >::load() - missing token for BasisSection in line "+linestring+"!");
166 std::string key(*tok_iter++);
167 ASSERT(tok_iter != tokens.end(),
168 "FormatParser< mpqc >::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< mpqc >::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< mpqc >::load() - missing token for AuxBasisSection in line "+linestring+"!");
184 std::string key(*tok_iter++);
185 ASSERT(tok_iter != tokens.end(),
186 "FormatParser< mpqc >::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< mpqc >::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("mpqc:") != string::npos) {
199 MpqcSection = 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 */
222void FormatParser< mpqc >::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 ELOG(1, "Cannot open mpqc output file.");
235 } else {
236 *file << "% Created by MoleCuilder" << endl;
237 *file << "mpqc: (" << endl;
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))) {
241 *file << "\tfreq<MolecularFrequencies>: (" << endl;
242 *file << "\t\tmolecule=$:molecule" << endl;
243 *file << "\t)" << endl;
244 }
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 {
301 ELOG(0, "Unknown level of theory requested for MPQC output file.");
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
308 for (std::vector<atom *>::const_iterator AtomRunner = atoms.begin(); AtomRunner != atoms.end(); ++AtomRunner) {
309 (*AtomRunner)->OutputMPQCLine(file, &center);
310 }
311 *file << "\t}" << endl;
312 *file << ")" << endl;
313 *file << "basis<GaussianBasisSet>: (" << endl;
314 *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::basisParam) << "\"" << endl;
315 *file << "\tmolecule = $:molecule" << endl;
316 *file << ")" << endl;
317 if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) {
318 *file << "% auxiliary basis set specification" << endl;
319 *file << "\tabasis<GaussianBasisSet>: (" << endl;
320 *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
321 *file << "\tmolecule = $:molecule" << endl;
322 *file << ")" << endl;
323 }
324 }
325}
326
327
Note: See TracBrowser for help on using the repository browser.