source: src/Parser/MpqcParser.cpp@ 44fce5

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 Candidate_v1.7.0 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 44fce5 was 44fce5, checked in by Frederik Heber <heber@…>, 15 years ago

Extended MpqcParser_Parameters, can set and get all values.

  • Property mode set to 100644
File size: 8.0 KB
Line 
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
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
28#include "atom.hpp"
29#include "config.hpp"
30#include "element.hpp"
31#include "molecule.hpp"
32#include "CodePatterns/Log.hpp"
33#include "CodePatterns/toString.hpp"
34#include "CodePatterns/Verbose.hpp"
35#include "LinearAlgebra/Vector.hpp"
36#include "periodentafel.hpp"
37#include "World.hpp"
38
39
40/** Constructor of MpqcParser.
41 *
42 */
43MpqcParser::MpqcParser()
44{}
45
46/** Destructor of MpqcParser.
47 *
48 */
49MpqcParser::~MpqcParser()
50{}
51
52/** Load an MPQC config file into the World.
53 * \param *file input stream
54 */
55void MpqcParser::load(istream *file)
56{
57 bool GeometryFollows = false;
58 char line[MAXSTRINGSIZE];
59 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
60 boost::char_separator<char> sep("[]");
61 boost::char_separator<char> whitesep(" \t");
62 ConvertTo<double> toDouble;
63
64 molecule *newmol = World::getInstance().createMolecule();
65 newmol->ActiveFlag = true;
66 while (file->good()) {
67 file->getline(line, MAXSTRINGSIZE-1);
68 std::string linestring(line);
69 if ((linestring.find("atoms geometry") == string::npos) && (linestring.find("}") != string::npos)) {
70 GeometryFollows = false;
71 }
72 if (GeometryFollows) { // we have an atom
73 tokenizer tokens(linestring, sep);
74// if (tokens.size() != 2)
75// throw MpqcParseException;
76 tokenizer::iterator tok_iter = tokens.begin();
77 std::stringstream whitespacefilter(*tok_iter++);
78 std::string element;
79 whitespacefilter >> element;
80 std::string vector = *tok_iter;
81 tokenizer vectorcomponents(vector, whitesep);
82 Vector X;
83// if (vectorcomponents.size() != NDIM)
84// throw MpqcParseException;
85 tok_iter = vectorcomponents.begin();
86 for (int i=0; i<NDIM; ++i) {
87 X[i] = toDouble(*tok_iter++);
88 }
89 // create atom
90 atom *newAtom = World::getInstance().createAtom();
91 newAtom->setType(World::getInstance().getPeriode()->FindElement(element));
92 newAtom->setPosition(X);
93 newmol->AddAtom(newAtom);
94 DoLog(1) && (Log() << Verbose(1) << "Adding atom " << *newAtom << std::endl);
95 }
96 // set some scan flags
97 if (linestring.find("atoms geometry") != string::npos) {
98 GeometryFollows = true;
99 }
100 }
101}
102
103/** Saves all atoms and data into a MPQC config file.
104 * \param *file output stream
105 * \param atoms atoms to store
106 */
107void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms)
108{
109 Vector center;
110 vector<atom *> allatoms = World::getInstance().getAllAtoms();
111
112 // calculate center
113 for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
114 center += (*runner)->getPosition();
115 center.Scale(1./(double)allatoms.size());
116
117 // first without hessian
118 if (file->fail()) {
119 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl);
120 } else {
121 *file << "% Created by MoleCuilder" << endl;
122 *file << "mpqc: (" << endl;
123 *file << "\tsavestate = " << params.getString(MpqcParser_Parameters::savestateParam) << endl;
124 *file << "\tdo_gradient = " << params.getString(MpqcParser_Parameters::do_gradientParam) << endl;
125 if (params.getBool(MpqcParser_Parameters::hessianParam)) {
126 *file << "\tfreq<MolecularFrequencies>: (" << endl;
127 *file << "\t\tmolecule=$:molecule" << endl;
128 *file << "\t)" << endl;
129 }
130 switch (params.getTheory()) {
131 case MpqcParser_Parameters::CLHF:
132 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
133 *file << "\t\tmolecule = $:molecule" << endl;
134 *file << "\t\tbasis = $:basis" << endl;
135 *file << "\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
136 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
137 *file << "\t)" << endl;
138 break;
139 case MpqcParser_Parameters::CLKS:
140 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
141 *file << "\t\tfunctional<StdDenFunctional>:(name=B3LYP)" << endl;
142 *file << "\t\tmolecule = $:molecule" << endl;
143 *file << "\t\tbasis = $:basis" << endl;
144 *file << "\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
145 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
146 *file << "\t)" << endl;
147 break;
148 case MpqcParser_Parameters::MBPT2:
149 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
150 *file << "\t\tbasis = $:basis" << endl;
151 *file << "\t\tmolecule = $:molecule" << endl;
152 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
153 *file << "\t\treference<CLHF>: (" << endl;
154 *file << "\t\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam))<< endl;
155 *file << "\t\t\tbasis = $:basis" << endl;
156 *file << "\t\t\tmolecule = $:molecule" << endl;
157 *file << "\t\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
158 *file << "\t\t)" << endl;
159 *file << "\t)" << endl;
160 break;
161 case MpqcParser_Parameters::MBPT2_R12:
162 *file << "\tmole<" << params.getString(MpqcParser_Parameters::theoryParam) << ">: (" << endl;
163 *file << "\t\tmolecule = $:molecule" << endl;
164 *file << "\t\tbasis = $:basis" << endl;
165 *file << "\t\taux_basis = $:abasis" << endl;
166 *file << "\t\tstdapprox = \"" << params.getString(MpqcParser_Parameters::stdapproxParam) << "\"" << endl;
167 *file << "\t\tnfzc = " << toString(params.getInt(MpqcParser_Parameters::nfzcParam)) << endl;
168 *file << "\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
169 *file << "\t\tintegrals<IntegralCints>:()" << endl;
170 *file << "\t\treference<CLHF>: (" << endl;
171 *file << "\t\t\tmolecule = $:molecule" << endl;
172 *file << "\t\t\tbasis = $:basis" << endl;
173 *file << "\t\t\tmaxiter = " << toString(params.getInt(MpqcParser_Parameters::maxiterParam)) << endl;
174 *file << "\t\t\tmemory = " << toString(params.getInt(MpqcParser_Parameters::memoryParam)) << endl;
175 *file << "\t\t\tintegrals<" << params.getString(MpqcParser_Parameters::integrationParam) << ">:()" << endl;
176 *file << "\t\t)" << endl;
177 *file << "\t)" << endl;
178 break;
179 default:
180 DoeLog(0) && (eLog() << Verbose(0)
181 << "Unknown level of theory requested for MPQC output file." << std::endl);
182 break;
183 }
184 *file << ")" << endl;
185 *file << "molecule<Molecule>: (" << endl;
186 *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
187 *file << "\t{ atoms geometry } = {" << endl;
188 // output of atoms
189 for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
190 (*AtomRunner)->OutputMPQCLine(file, &center);
191 }
192 *file << "\t}" << endl;
193 *file << ")" << endl;
194 *file << "basis<GaussianBasisSet>: (" << endl;
195 *file << "\tname = \"" << params.getString(MpqcParser_Parameters::basisParam) << "\"" << endl;
196 *file << "\tmolecule = $:molecule" << endl;
197 *file << ")" << endl;
198 if (params.getTheory() == MpqcParser_Parameters::MBPT2_R12) {
199 *file << "% auxiliary basis set specification" << endl;
200 *file << "\tabasis<GaussianBasisSet>: (" << endl;
201 *file << "\tname = \"" << params.getString(MpqcParser_Parameters::aux_basisParam) << "\"" << endl;
202 *file << "\tmolecule = $:molecule" << endl;
203 *file << ")" << endl;
204 }
205 }
206}
207
Note: See TracBrowser for help on using the repository browser.