source: src/Parser/MpqcParser.cpp@ 36bb2d

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 36bb2d was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 15.7 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 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * MpqcParser.cpp
25 *
26 * Created on: 12.06.2010
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include <iomanip>
36#include <iostream>
37#include <boost/foreach.hpp>
38#include <boost/tokenizer.hpp>
39#include <sstream>
40#include <string>
41
42#include "CodePatterns/MemDebug.hpp"
43
44#include "MpqcParser.hpp"
45#include "MpqcParser_Parameters.hpp"
46
47#include "Atom/atom.hpp"
48#include "CodePatterns/Log.hpp"
49#include "CodePatterns/toString.hpp"
50#include "config.hpp"
51#include "Element/element.hpp"
52#include "Element/periodentafel.hpp"
53#include "LinearAlgebra/Vector.hpp"
54#include "molecule.hpp"
55#include "MoleculeListClass.hpp"
56#include "World.hpp"
57
58// declare specialized static variables
59const std::string FormatParserTrait<mpqc>::name = "mpqc";
60const std::string FormatParserTrait<mpqc>::suffix = "in";
61const ParserTypes FormatParserTrait<mpqc>::type = mpqc;
62
63// a converter we often need
64ConvertTo<bool> FormatParser<mpqc>::Converter;
65
66/** Constructor of MpqcParser.
67 *
68 */
69FormatParser< mpqc >::FormatParser() :
70 FormatParser_common(new MpqcParser_Parameters())
71{}
72
73/** Destructor of MpqcParser.
74 *
75 */
76FormatParser< mpqc >::~FormatParser()
77{}
78
79/** Load an MPQC config file into the World.
80 * \param *file input stream
81 */
82void FormatParser< mpqc >::load(istream *file)
83{
84 bool MpqcSection = false;
85 bool MoleculeSection = false;
86 bool GeometrySection = false;
87 bool BasisSection = false;
88 bool AuxBasisSection = false;
89 char line[MAXSTRINGSIZE];
90 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
91 boost::char_separator<char> sep("[]");
92 boost::char_separator<char> angularsep("<>");
93 boost::char_separator<char> equalitysep(" =");
94 boost::char_separator<char> whitesep(" \t");
95 ConvertTo<double> toDouble;
96
97 molecule *newmol = World::getInstance().createMolecule();
98 newmol->ActiveFlag = true;
99 // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
100 World::getInstance().getMolecules()->insert(newmol);
101 while (file->good()) {
102 file->getline(line, MAXSTRINGSIZE-1);
103 std::string linestring(line);
104 if ((linestring.find("atoms geometry") == string::npos) && (linestring.find("}") != string::npos)) {
105 GeometrySection = false;
106 }
107 if ((linestring.find(")") != string::npos)) { // ends a section which do not overlap
108 MpqcSection = false;
109 MoleculeSection = false;
110 BasisSection = false;
111 AuxBasisSection = false;
112 }
113 if (MoleculeSection) {
114 if (GeometrySection) { // we have an atom
115 tokenizer tokens(linestring, sep);
116 // if (tokens.size() != 2)
117 // throw MpqcParseException;
118 tokenizer::iterator tok_iter = tokens.begin();
119 ASSERT(tok_iter != tokens.end(),
120 "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");
121 std::stringstream whitespacefilter(*tok_iter++);
122 std::string element;
123 whitespacefilter >> ws >> element;
124 ASSERT(tok_iter != tokens.end(),
125 "FormatParser< mpqc >::load() - missing token for MoleculeSection in line "+linestring+"!");
126 std::string vector = *tok_iter;
127 tokenizer vectorcomponents(vector, whitesep);
128 Vector X;
129 // if (vectorcomponents.size() != NDIM)
130 // throw MpqcParseException;
131 tok_iter = vectorcomponents.begin();
132 for (int i=0; i<NDIM; ++i) {
133 X[i] = toDouble(*tok_iter++);
134 }
135 // create atom
136 atom *newAtom = World::getInstance().createAtom();
137 newAtom->setType(World::getInstance().getPeriode()->FindElement(element));
138 newAtom->setPosition(X);
139 newmol->AddAtom(newAtom);
140 LOG(1, "Adding atom " << *newAtom);
141 }
142 }
143 if (MpqcSection) {
144 if (linestring.find("mole<") != string::npos) { // get theory
145 tokenizer tokens(linestring, angularsep);
146 tokenizer::iterator tok_iter = tokens.begin();
147 ++tok_iter;
148 ASSERT(tok_iter != tokens.end(),
149 "FormatParser< mpqc >::load() - missing token in brackets<> for mole< in line "+linestring+"!");
150 std::string value(*tok_iter);
151 std::stringstream linestream("theory = "+value);
152 linestream >> getParams();
153 } else if (linestring.find("integrals<") != string::npos) { // get theory
154 tokenizer tokens(linestring, angularsep);
155 tokenizer::iterator tok_iter = tokens.begin();
156 ++tok_iter;
157 ASSERT(tok_iter != tokens.end(),
158 "FormatParser< mpqc >::load() - missing token in brackets<> for integrals< in line "+linestring+"!");
159 std::string value(*tok_iter);
160 std::stringstream linestream("integration = "+value);
161 linestream >> getParams();
162 } else if ((linestring.find("molecule") == string::npos) && (linestring.find("basis") == string::npos)){
163 // molecule and basis must not be parsed in this section
164 tokenizer tokens(linestring, equalitysep);
165 tokenizer::iterator tok_iter = tokens.begin();
166 ASSERT(tok_iter != tokens.end(),
167 "FormatParser< mpqc >::load() - missing token before '=' for MpqcSection in line "+linestring+"!");
168 std::stringstream whitespacefilter(*tok_iter);
169 std::string key;
170 whitespacefilter >> ws >> key;
171 if (getParams().haveParameter(key)) {
172 std::stringstream linestream(linestring);
173 linestream >> getParams();
174 } else { // unknown keys are simply ignored as long as parser is incomplete
175 LOG(2, "INFO: '"+key+"' is unknown and ignored.");
176 }
177 }
178 }
179 if (BasisSection) {
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 BasisSection 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("basis = "+value);
194 linestream >> getParams();
195 }
196 }
197 if (AuxBasisSection) {
198 tokenizer tokens(linestring, equalitysep);
199 tokenizer::iterator tok_iter = tokens.begin();
200 ASSERT(tok_iter != tokens.end(),
201 "FormatParser< mpqc >::load() - missing token for AuxBasisSection in line "+linestring+"!");
202 std::string key(*tok_iter++);
203 ASSERT(tok_iter != tokens.end(),
204 "FormatParser< mpqc >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!");
205 std::string value(*tok_iter);
206 tok_iter++;
207 // TODO: use exception instead of ASSERT
208 ASSERT(tok_iter == tokens.end(),
209 "FormatParser< mpqc >::load() - more than (key = value) on line "+linestring+".");
210 if (key == "name") {
211 std::stringstream linestream("aux_basis = "+value);
212 linestream >> getParams();
213 }
214 }
215 // set some scan flags
216 if (linestring.find("mpqc:") != string::npos) {
217 MpqcSection = true;
218 }
219 if (linestring.find("molecule<Molecule>:") != string::npos) {
220 MoleculeSection = true;
221 }
222 if (linestring.find("atoms geometry") != string::npos) {
223 GeometrySection = true;
224 }
225 if ((linestring.find("basis<GaussianBasisSet>:") != string::npos) && ((linestring.find("abasis<") == string::npos))) {
226 BasisSection = true;
227 }
228 if (linestring.find("abasis<") != string::npos) {
229 AuxBasisSection = true;
230 }
231 }
232 // refresh atom::nr and atom::name
233 newmol->getAtomCount();
234}
235
236void FormatParser< mpqc >::OutputMPQCLine(ostream * const out, const atom &_atom, const Vector *center) const
237{
238 Vector recentered(_atom.getPosition());
239 recentered -= *center;
240 *out << "\t\t" << _atom.getType()->getSymbol() << " [ ";
241 {
242 std::stringstream posstream;
243 posstream << std::setprecision(12) << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2];
244 *out << posstream.str();
245 }
246 *out << " ]" << std::endl;
247};
248
249
250/** Saves all atoms and data into a MPQC config file.
251 * \param *file output stream
252 * \param atoms atoms to store
253 */
254void FormatParser< mpqc >::save(ostream *file, const std::vector<atom *> &atoms)
255{
256 Vector center;
257// vector<atom *> allatoms = World::getInstance().getAllAtoms();
258
259 // calculate center
260// for (std::vector<atom *>::const_iterator runner = atoms.begin();runner != atoms.end(); ++runner)
261// center += (*runner)->getPosition();
262// center.Scale(1./(double)atoms.size());
263 center.Zero();
264
265 // first without hessian
266 if (file->fail()) {
267 ELOG(1, "Cannot open mpqc output file.");
268 } else {
269 *file << "% Created by MoleCuilder" << endl;
270 *file << "mpqc: (" << endl;
271 *file << "\tsavestate = " << getParams().getParameter(MpqcParser_Parameters::savestateParam) << endl;
272 *file << "\tdo_gradient = " << getParams().getParameter(MpqcParser_Parameters::do_gradientParam) << endl;
273 if (Converter(getParams().getParameter(MpqcParser_Parameters::hessianParam))) {
274 *file << "\tfreq<MolecularFrequencies>: (" << endl;
275 *file << "\t\tmolecule=$:molecule" << endl;
276 *file << "\t)" << endl;
277 }
278 const std::string theory = getParams().getParameter(MpqcParser_Parameters::theoryParam);
279 if (theory == getParams().getTheoryName(MpqcParser_Parameters::CLHF)) {
280 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
281 *file << "\t\tmolecule = $:molecule" << endl;
282 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
283 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam)
284 << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
285 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
286 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
287 *file << "\t)" << endl;
288 } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::CLKS)) {
289 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
290 *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << 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::maxiterParam)
294 << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
295 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
296 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
297 *file << "\t)" << endl;
298 } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2)) {
299 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
300 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
301 *file << "\t\tmolecule = $:molecule" << endl;
302 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
303 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
304 *file << "\t\treference<CLHF>: (" << endl;
305 *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::maxiterParam)
306 << " = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam)<< endl;
307 *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
308 *file << "\t\t\tmolecule = $:molecule" << endl;
309 *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
310 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
311 *file << "\t\t)" << endl;
312 *file << "\t)" << endl;
313 } else if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) {
314 *file << "\tmole<" << getParams().getParameter(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
315 *file << "\t\tmolecule = $:molecule" << endl;
316 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
317 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::aux_basisParam) << " = $:abasis" << endl;
318 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::stdapproxParam)
319 << " = \"" << getParams().getParameter(MpqcParser_Parameters::stdapproxParam) << "\"" << endl;
320 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::nfzcParam)
321 << " = " << getParams().getParameter(MpqcParser_Parameters::nfzcParam) << endl;
322 *file << "\t\t" << getParams().getParameterName(MpqcParser_Parameters::memoryParam)
323 << " = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
324 *file << "\t\tintegrals<IntegralCints>:()" << endl;
325 *file << "\t\treference<CLHF>: (" << endl;
326 *file << "\t\t\tmolecule = $:molecule" << endl;
327 *file << "\t\t\t" << getParams().getParameterName(MpqcParser_Parameters::basisParam) << " = $:basis" << endl;
328 *file << "\t\t\tmaxiter = " << getParams().getParameter(MpqcParser_Parameters::maxiterParam) << endl;
329 *file << "\t\t\tmemory = " << getParams().getParameter(MpqcParser_Parameters::memoryParam) << endl;
330 *file << "\t\t\tintegrals<" << getParams().getParameter(MpqcParser_Parameters::integrationParam) << ">:()" << endl;
331 *file << "\t\t)" << endl;
332 *file << "\t)" << endl;
333 } else {
334 ELOG(0, "Unknown level of theory requested for MPQC output file.");
335 }
336 *file << ")" << endl;
337 *file << "molecule<Molecule>: (" << endl;
338 *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
339 *file << "\t{ atoms geometry } = {" << endl;
340 // output of atoms
341 BOOST_FOREACH(const atom *_atom, atoms) {
342 OutputMPQCLine(file, *_atom, &center);
343 }
344 *file << "\t}" << endl;
345 *file << ")" << endl;
346 *file << "basis<GaussianBasisSet>: (" << endl;
347 *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::basisParam) << "\"" << endl;
348 *file << "\tmolecule = $:molecule" << endl;
349 *file << ")" << endl;
350 if (theory == getParams().getTheoryName(MpqcParser_Parameters::MBPT2_R12)) {
351 *file << "% auxiliary basis set specification" << endl;
352 *file << "\tabasis<GaussianBasisSet>: (" << endl;
353 *file << "\tname = \"" << getParams().getParameter(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
354 *file << "\tmolecule = $:molecule" << endl;
355 *file << ")" << endl;
356 }
357 }
358}
359
360
Note: See TracBrowser for help on using the repository browser.