source: src/Parser/MpqcParser.cpp@ 9cff8b

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 9cff8b was aa8ef2, checked in by Frederik Heber <heber@…>, 15 years ago

Implemented MpqcParser::load().

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