source: src/Parser/MpqcParser.cpp@ b3d687

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 b3d687 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
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 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/foreach.hpp>
22#include <boost/tokenizer.hpp>
23#include <string>
24
25#include "CodePatterns/MemDebug.hpp"
26
27#include "MpqcParser.hpp"
28#include "MpqcParser_Parameters.hpp"
29
30#include "Atom/atom.hpp"
31#include "CodePatterns/Log.hpp"
32#include "CodePatterns/toString.hpp"
33#include "config.hpp"
34#include "Element/element.hpp"
35#include "Element/periodentafel.hpp"
36#include "LinearAlgebra/Vector.hpp"
37#include "molecule.hpp"
38#include "MoleculeListClass.hpp"
39#include "World.hpp"
40
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;
45
46// a converter we often need
47ConvertTo<bool> FormatParser<mpqc>::Converter;
48
49/** Constructor of MpqcParser.
50 *
51 */
52FormatParser< mpqc >::FormatParser() :
53 FormatParser_common(new MpqcParser_Parameters())
54{}
55
56/** Destructor of MpqcParser.
57 *
58 */
59FormatParser< mpqc >::~FormatParser()
60{}
61
62/** Load an MPQC config file into the World.
63 * \param *file input stream
64 */
65void FormatParser< mpqc >::load(istream *file)
66{
67 bool MpqcSection = false;
68 bool MoleculeSection = false;
69 bool GeometrySection = false;
70 bool BasisSection = false;
71 bool AuxBasisSection = false;
72 char line[MAXSTRINGSIZE];
73 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
74 boost::char_separator<char> sep("[]");
75 boost::char_separator<char> angularsep("<>");
76 boost::char_separator<char> equalitysep(" =");
77 boost::char_separator<char> whitesep(" \t");
78 ConvertTo<double> toDouble;
79
80 molecule *newmol = World::getInstance().createMolecule();
81 newmol->ActiveFlag = true;
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);
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)) {
88 GeometrySection = false;
89 }
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();
102 ASSERT(tok_iter != tokens.end(),
103 "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");
104 std::stringstream whitespacefilter(*tok_iter++);
105 std::string element;
106 whitespacefilter >> ws >> element;
107 ASSERT(tok_iter != tokens.end(),
108 "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");
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);
123 LOG(1, "Adding atom " << *newAtom);
124 }
125 }
126 if (MpqcSection) {
127 if (linestring.find("mole<") != string::npos) { // get theory
128 tokenizer tokens(linestring, angularsep);
129 tokenizer::iterator tok_iter = tokens.begin();
130 ++tok_iter;
131 ASSERT(tok_iter != tokens.end(),
132 "FormatParser< mpqc >::load() - missing token in brackets<> for mole< in line "+linestring+"!");
133 std::string value(*tok_iter);
134 std::stringstream linestream("theory = "+value);
135 linestream >> getParams();
136 } else if (linestring.find("integrals<") != string::npos) { // get theory
137 tokenizer tokens(linestring, angularsep);
138 tokenizer::iterator tok_iter = tokens.begin();
139 ++tok_iter;
140 ASSERT(tok_iter != tokens.end(),
141 "FormatParser< mpqc >::load() - missing token in brackets<> for integrals< in line "+linestring+"!");
142 std::string value(*tok_iter);
143 std::stringstream linestream("integration = "+value);
144 linestream >> getParams();
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(),
150 "FormatParser< mpqc >::load() - missing token before '=' for MpqcSection in line "+linestring+"!");
151 std::stringstream whitespacefilter(*tok_iter);
152 std::string key;
153 whitespacefilter >> ws >> key;
154 if (getParams().haveParameter(key)) {
155 std::stringstream linestream(linestring);
156 linestream >> getParams();
157 } else { // unknown keys are simply ignored as long as parser is incomplete
158 LOG(2, "INFO: '"+key+"' is unknown and ignored.");
159 }
160 }
161 }
162 if (BasisSection) {
163 tokenizer tokens(linestring, equalitysep);
164 tokenizer::iterator tok_iter = tokens.begin();
165 ASSERT(tok_iter != tokens.end(),
166 "FormatParser< mpqc >::load() - missing token for BasisSection in line "+linestring+"!");
167 std::string key(*tok_iter++);
168 ASSERT(tok_iter != tokens.end(),
169 "FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
170 std::string value(*tok_iter);
171 tok_iter++;
172 // TODO: use exception instead of ASSERT
173 ASSERT(tok_iter == tokens.end(),
174 "FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+".");
175 if (key == "name") {
176 std::stringstream linestream("basis = "+value);
177 linestream >> getParams();
178 }
179 }
180 if (AuxBasisSection) {
181 tokenizer tokens(linestring, equalitysep);
182 tokenizer::iterator tok_iter = tokens.begin();
183 ASSERT(tok_iter != tokens.end(),
184 "FormatParser< mpqc >::load() - missing token for AuxBasisSection in line "+linestring+"!");
185 std::string key(*tok_iter++);
186 ASSERT(tok_iter != tokens.end(),
187 "FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
188 std::string value(*tok_iter);
189 tok_iter++;
190 // TODO: use exception instead of ASSERT
191 ASSERT(tok_iter == tokens.end(),
192 "FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+".");
193 if (key == "name") {
194 std::stringstream linestream("aux_basis = "+value);
195 linestream >> getParams();
196 }
197 }
198 // set some scan flags
199 if (linestring.find("mpqc:") != string::npos) {
200 MpqcSection = true;
201 }
202 if (linestring.find("molecule<Molecule>:") != string::npos) {
203 MoleculeSection = true;
204 }
205 if (linestring.find("atoms geometry") != string::npos) {
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;
213 }
214 }
215 // refresh atom::nr and atom::name
216 newmol->getAtomCount();
217}
218
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
227/** Saves all atoms and data into a MPQC config file.
228 * \param *file output stream
229 * \param atoms atoms to store
230 */
231void FormatParser< mpqc >::save(ostream *file, const std::vector<atom *> &atoms)
232{
233 Vector center;
234// vector<atom *> allatoms = World::getInstance().getAllAtoms();
235
236 // calculate center
237 for (std::vector<atom *>::const_iterator runner = atoms.begin();runner != atoms.end(); ++runner)
238 center += (*runner)->getPosition();
239 center.Scale(1./(double)atoms.size());
240
241 // first without hessian
242 if (file->fail()) {
243 ELOG(1, "Cannot open mpqc output file.");
244 } else {
245 *file << "% Created by MoleCuilder" << endl;
246 *file << "mpqc: (" << endl;
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))) {
250 *file << "\tfreq<MolecularFrequencies>: (" << endl;
251 *file << "\t\tmolecule=$:molecule" << endl;
252 *file << "\t)" << endl;
253 }
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 {
310 ELOG(0, "Unknown level of theory requested for MPQC output file.");
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
317 BOOST_FOREACH(const atom *_atom, atoms) {
318 OutputMPQCLine(file, *_atom, &center);
319 }
320 *file << "\t}" << endl;
321 *file << ")" << endl;
322 *file << "basis<GaussianBasisSet>: (" << endl;
323 *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::basisParam) << "\"" << endl;
324 *file << "\tmolecule = $:molecule" << endl;
325 *file << ")" << endl;
326 if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) {
327 *file << "% auxiliary basis set specification" << endl;
328 *file << "\tabasis<GaussianBasisSet>: (" << endl;
329 *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
330 *file << "\tmolecule = $:molecule" << endl;
331 *file << ")" << endl;
332 }
333 }
334}
335
336
Note: See TracBrowser for help on using the repository browser.