source: src/Parser/MpqcParser.cpp@ 0bfe73

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 0bfe73 was 4cbca0, checked in by Frederik Heber <heber@…>, 14 years ago

Implemented full MpqcParser::load().

  • regression tests for four theories: CLHF, CLKS, MBPT2, MBPT2_R12.
  • extended regression test on set-mpqc-parameters by checking changed value against a written file.
  • Property mode set to 100644
File size: 11.1 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
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"
27
28#include "atom.hpp"
29#include "config.hpp"
30#include "element.hpp"
[aa8ef2]31#include "molecule.hpp"
[ad011c]32#include "CodePatterns/Log.hpp"
[aa8ef2]33#include "CodePatterns/toString.hpp"
[ad011c]34#include "CodePatterns/Verbose.hpp"
[e97a44]35#include "LinearAlgebra/Vector.hpp"
36#include "periodentafel.hpp"
[1b2d30]37#include "World.hpp"
38
39
40/** Constructor of MpqcParser.
41 *
42 */
[61d69a4]43MpqcParser::MpqcParser()
[97b825]44{}
[1b2d30]45
46/** Destructor of MpqcParser.
47 *
48 */
[97b825]49MpqcParser::~MpqcParser()
50{}
[1b2d30]51
52/** Load an MPQC config file into the World.
53 * \param *file input stream
54 */
55void MpqcParser::load(istream *file)
56{
[4cbca0]57 bool MpqcSection = false;
58 bool MoleculeSection = false;
59 bool GeometrySection = false;
60 bool BasisSection = false;
61 bool AuxBasisSection = false;
[aa8ef2]62 char line[MAXSTRINGSIZE];
63 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
64 boost::char_separator<char> sep("[]");
[4cbca0]65 boost::char_separator<char> angularsep("<>");
66 boost::char_separator<char> equalitysep("=");
[aa8ef2]67 boost::char_separator<char> whitesep(" \t");
68 ConvertTo<double> toDouble;
69
70 molecule *newmol = World::getInstance().createMolecule();
71 newmol->ActiveFlag = true;
[4cbca0]72 // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
73 World::getInstance().getMolecules()->insert(newmol);
[aa8ef2]74 while (file->good()) {
75 file->getline(line, MAXSTRINGSIZE-1);
76 std::string linestring(line);
77 if ((linestring.find("atoms geometry") == string::npos) && (linestring.find("}") != string::npos)) {
[4cbca0]78 GeometrySection = false;
[aa8ef2]79 }
[4cbca0]80 if ((linestring.find(")") != string::npos)) { // ends a section which do not overlap
81 MpqcSection = false;
82 MoleculeSection = false;
83 BasisSection = false;
84 AuxBasisSection = false;
85 }
86 if (MoleculeSection) {
87 if (GeometrySection) { // we have an atom
88 tokenizer tokens(linestring, sep);
89 // if (tokens.size() != 2)
90 // throw MpqcParseException;
91 tokenizer::iterator tok_iter = tokens.begin();
92 std::stringstream whitespacefilter(*tok_iter++);
93 std::string element;
94 whitespacefilter >> element;
95 std::string vector = *tok_iter;
96 tokenizer vectorcomponents(vector, whitesep);
97 Vector X;
98 // if (vectorcomponents.size() != NDIM)
99 // throw MpqcParseException;
100 tok_iter = vectorcomponents.begin();
101 for (int i=0; i<NDIM; ++i) {
102 X[i] = toDouble(*tok_iter++);
103 }
104 // create atom
105 atom *newAtom = World::getInstance().createAtom();
106 newAtom->setType(World::getInstance().getPeriode()->FindElement(element));
107 newAtom->setPosition(X);
108 newmol->AddAtom(newAtom);
109 DoLog(1) && (Log() << Verbose(1) << "Adding atom " << *newAtom << std::endl);
110 }
111 }
112 if (MpqcSection) {
113 tokenizer tokens(linestring, equalitysep);
[aa8ef2]114 tokenizer::iterator tok_iter = tokens.begin();
115 std::stringstream whitespacefilter(*tok_iter++);
[4cbca0]116 std::string key(*tok_iter++);
117 if (params.haveParam(key)) {
118 std::stringstream linestream(linestring);
119 linestream >> params;
120 } else if (linestring.find("mole<") != string::npos) { // get theory
121 tokenizer tokens(linestring, angularsep);
122 tokenizer::iterator tok_iter = tokens.begin();
123 std::string value(*(++tok_iter));
124 std::stringstream linestream("theory = "+value);
125 linestream >> params;
126 } else if (linestring.find("integrals<") != string::npos) { // get theory
127 tokenizer tokens(linestring, angularsep);
128 tokenizer::iterator tok_iter = tokens.begin();
129 std::string value(*(++tok_iter));
130 std::stringstream linestream("integration = "+value);
131 linestream >> params;
132 }
133 }
134 if (BasisSection) {
135 tokenizer tokens(linestring, equalitysep);
136 tokenizer::iterator tok_iter = tokens.begin();
137 std::string key(*tok_iter++);
138 std::string value(*tok_iter);
139 // TODO: use exception instead of ASSERT
140 ASSERT(tok_iter == tokens.end(),
141 "MpqcParser::load() - more than (key = value) on line "+linestring+".");
142 if (key == "name") {
143 std::stringstream linestream("basis = "+value);
144 linestream >> params;
145 }
146 }
147 if (AuxBasisSection) {
148 tokenizer tokens(linestring, equalitysep);
149 tokenizer::iterator tok_iter = tokens.begin();
150 std::string key(*tok_iter++);
151 std::string value(*tok_iter);
152 // TODO: use exception instead of ASSERT
153 ASSERT(tok_iter == tokens.end(),
154 "MpqcParser::load() - more than (key = value) on line "+linestring+".");
155 if (key == "name") {
156 std::stringstream linestream("aux_basis = "+value);
157 linestream >> params;
[aa8ef2]158 }
159 }
160 // set some scan flags
[4cbca0]161 if (linestring.find("mpqc:") != string::npos) {
162 MpqcSection = true;
163 }
164 if (linestring.find("molecule<Molecule>:") != string::npos) {
165 MoleculeSection = true;
166 }
[aa8ef2]167 if (linestring.find("atoms geometry") != string::npos) {
[4cbca0]168 GeometrySection = true;
169 }
170 if ((linestring.find("basis<GaussianBasisSet>:") != string::npos) && ((linestring.find("abasis<") == string::npos))) {
171 BasisSection = true;
172 }
173 if (linestring.find("abasis<") != string::npos) {
174 AuxBasisSection = true;
[aa8ef2]175 }
176 }
[1b2d30]177}
178
[f31edc]179/** Saves all atoms and data into a MPQC config file.
[1b2d30]180 * \param *file output stream
[73916f]181 * \param atoms atoms to store
[1b2d30]182 */
[f31edc]183void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms)
[1b2d30]184{
185 Vector center;
186 vector<atom *> allatoms = World::getInstance().getAllAtoms();
187
[d6b8e1]188 // calculate center
189 for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
[d74077]190 center += (*runner)->getPosition();
[61d69a4]191 center.Scale(1./(double)allatoms.size());
[d6b8e1]192
[1b2d30]193 // first without hessian
194 if (file->fail()) {
195 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl);
196 } else {
197 *file << "% Created by MoleCuilder" << endl;
198 *file << "mpqc: (" << endl;
[61d69a4]199 *file << "\tsavestate = " << params.getString(MpqcParser_Parameters::savestateParam) << endl;
200 *file << "\tdo_gradient = " << params.getString(MpqcParser_Parameters::do_gradientParam) << endl;
[44fce5]201 if (params.getBool(MpqcParser_Parameters::hessianParam)) {
[f31edc]202 *file << "\tfreq<MolecularFrequencies>: (" << endl;
203 *file << "\t\tmolecule=$:molecule" << endl;
204 *file << "\t)" << endl;
205 }
[61d69a4]206 switch (params.getTheory()) {
207 case MpqcParser_Parameters::CLHF:
208 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
[f31edc]209 *file << "\t\tmolecule = $:molecule" << endl;
210 *file << "\t\tbasis = $:basis" << endl;
[61d69a4]211 *file << "\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
212 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
[f31edc]213 *file << "\t)" << endl;
214 break;
[61d69a4]215 case MpqcParser_Parameters::CLKS:
216 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
[f31edc]217 *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
218 *file << "\t\tmolecule = $:molecule" << endl;
219 *file << "\t\tbasis = $:basis" << endl;
[61d69a4]220 *file << "\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
221 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
[f31edc]222 *file << "\t)" << endl;
223 break;
[61d69a4]224 case MpqcParser_Parameters::MBPT2:
225 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
[f31edc]226 *file << "\t\tbasis = $:basis" << endl;
227 *file << "\t\tmolecule = $:molecule" << endl;
[61d69a4]228 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
[f31edc]229 *file << "\t\treference<CLHF>: (" << endl;
[61d69a4]230 *file << "\t\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
[f31edc]231 *file << "\t\t\tbasis = $:basis" << endl;
232 *file << "\t\t\tmolecule = $:molecule" << endl;
[61d69a4]233 *file << "\t\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
[f31edc]234 *file << "\t\t)" << endl;
235 *file << "\t)" << endl;
236 break;
[61d69a4]237 case MpqcParser_Parameters::MBPT2_R12:
238 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
[f31edc]239 *file << "\t\tmolecule = $:molecule" << endl;
240 *file << "\t\tbasis = $:basis" << endl;
241 *file << "\t\taux_basis = $:abasis" << endl;
[61d69a4]242 *file << "\t\tstdapprox = \"" << params.getString(MpqcParser_Parameters::stdapproxParam) << "\"" << endl;
243 *file << "\t\tnfzc = " << toString(params.getInt(MpqcParser_Parameters::nfzcParam)) << endl;
244 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
[f31edc]245 *file << "\t\tintegrals<IntegralCints>:()" << endl;
246 *file << "\t\treference<CLHF>: (" << endl;
247 *file << "\t\t\tmolecule = $:molecule" << endl;
248 *file << "\t\t\tbasis = $:basis" << endl;
[61d69a4]249 *file << "\t\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam)) << endl;
250 *file << "\t\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
251 *file << "\t\t\tintegrals<" << params.getString(MpqcParser_Parameters::integrationParam) << ">:()" << endl;
[f31edc]252 *file << "\t\t)" << endl;
253 *file << "\t)" << endl;
254 break;
255 default:
256 DoeLog(0) && (eLog() << Verbose(0)
257 << "Unknown level of theory requested for MPQC output file." << std::endl);
258 break;
[1b2d30]259 }
260 *file << ")" << endl;
261 *file << "molecule<Molecule>: (" << endl;
262 *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
263 *file << "\t{ atoms geometry } = {" << endl;
264 // output of atoms
265 for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
[0dc86e2]266 (*AtomRunner)->OutputMPQCLine(file, &center);
[1b2d30]267 }
268 *file << "\t}" << endl;
269 *file << ")" << endl;
270 *file << "basis<GaussianBasisSet>: (" << endl;
[61d69a4]271 *file << "\tname = \"" << params.getString(MpqcParser_Parameters::basisParam) << "\"" << endl;
[1b2d30]272 *file << "\tmolecule = $:molecule" << endl;
273 *file << ")" << endl;
[61d69a4]274 if (params.getTheory() == MpqcParser_Parameters::MBPT2_R12) {
[f31edc]275 *file << "% auxiliary basis set specification" << endl;
276 *file << "\tabasis<GaussianBasisSet>: (" << endl;
[61d69a4]277 *file << "\tname = \"" << params.getString(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
[f31edc]278 *file << "\tmolecule = $:molecule" << endl;
279 *file << ")" << endl;
280 }
[1b2d30]281 }
282}
283
[963321a]284MpqcParser_Parameters & MpqcParser::getParams()
285{
286 return params;
287}
288
Note: See TracBrowser for help on using the repository browser.