source: src/Parser/Psi3Parser.cpp@ 50e4e5

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 50e4e5 was 42127c, checked in by Frederik Heber <heber@…>, 13 years ago

Extracted definition of MoleculeListClass and put into own header module.

  • Property mode set to 100644
File size: 10.2 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 * Psi3Parser.cpp
10 *
11 * Created on: Oct 04, 2011
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 "Psi3Parser.hpp"
27#include "Psi3Parser_Parameters.hpp"
28
29#include "atom.hpp"
30#include "config.hpp"
31#include "Element/element.hpp"
32#include "Element/periodentafel.hpp"
33#include "molecule.hpp"
34#include "MoleculeListClass.hpp"
35#include "CodePatterns/Log.hpp"
36#include "CodePatterns/toString.hpp"
37#include "CodePatterns/Verbose.hpp"
38#include "LinearAlgebra/Vector.hpp"
39#include "World.hpp"
40
41// declare specialized static variables
42const std::string FormatParserTrait<psi3>::name = "psi3";
43const std::string FormatParserTrait<psi3>::suffix = "psi";
44const ParserTypes FormatParserTrait<psi3>::type = psi3;
45
46// a converter we often need
47ConvertTo<bool> FormatParser<psi3>::Converter;
48
49/** Constructor of Psi3Parser.
50 *
51 */
52FormatParser< psi3 >::FormatParser() :
53 FormatParser_common(new Psi3Parser_Parameters())
54{}
55
56/** Destructor of Psi3Parser.
57 *
58 */
59FormatParser< psi3 >::~FormatParser()
60{}
61
62/** Load an MPQC config file into the World.
63 * \param *file input stream
64 */
65void FormatParser< psi3 >::load(istream *file)
66{
67 bool Psi3Section = false;
68 bool GeometrySection = false;
69 char line[MAXSTRINGSIZE];
70 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
71 boost::char_separator<char> sep("()");
72 boost::char_separator<char> angularsep("<>");
73 boost::char_separator<char> equalitysep(" =");
74 boost::char_separator<char> whitesep(" \t");
75 ConvertTo<double> toDouble;
76
77 molecule *newmol = World::getInstance().createMolecule();
78 newmol->ActiveFlag = true;
79 // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
80 World::getInstance().getMolecules()->insert(newmol);
81 while (file->good()) {
82 file->getline(line, MAXSTRINGSIZE-1);
83 std::string linestring(line);
84 LOG(3, "INFO: Current line is: " << line);
85 if ((linestring.find(")") != string::npos) && (linestring.find("(") == string::npos)) {
86 LOG(3, "INFO: Line contains ')' and no '(' (end of section): " << line);
87 // ends a section which do not overlap
88 if (GeometrySection)
89 GeometrySection = false;
90 else
91 Psi3Section = false;
92 }
93 if (GeometrySection) { // we have an atom
94 tokenizer tokens(linestring, sep);
95// if (tokens.size() != 2)
96// throw Psi3ParseException;
97 tokenizer::iterator tok_iter = tokens.begin();
98 ASSERT(tok_iter != tokens.end(),
99 "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!");
100 std::stringstream whitespacefilter(*++tok_iter);
101 std::string element;
102 whitespacefilter >> ws >> element;
103 LOG(2, "INFO: element of atom is " << element);
104 ASSERT(tok_iter != tokens.end(),
105 "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!");
106 std::string vector = *tok_iter;
107 tokenizer vectorcomponents(vector, whitesep);
108 Vector X;
109// if (vectorcomponents.size() != NDIM)
110// throw Psi3ParseException;
111 tok_iter = vectorcomponents.begin();
112 ++tok_iter;
113 for (int i=0; i<NDIM; ++i) {
114 LOG(4, "INFO: Current value is " << *tok_iter << ".");
115 X[i] = toDouble(*tok_iter++);
116 }
117 LOG(2, "INFO: position of atom is " << X);
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 DoLog(1) && (Log() << Verbose(1) << "Adding atom " << *newAtom << std::endl);
124 }
125 if ((Psi3Section) && (!GeometrySection)) {
126 if (linestring.find("=") != string::npos) { // get param value
127 tokenizer tokens(linestring, equalitysep);
128 tokenizer::iterator tok_iter = tokens.begin();
129 ASSERT(tok_iter != tokens.end(),
130 "FormatParser< psi3 >::load() - missing token before '=' for Psi3Section in line "+linestring+"!");
131 std::stringstream whitespacefilter(*tok_iter);
132 std::string key;
133 whitespacefilter >> ws >> key;
134 //LOG(2, "INFO: key to check is: " << key);
135 if (getParams().haveParameter(key)) {
136 //LOG(2, "INFO: Line submitted to parameter is: " << linestring);
137 std::stringstream linestream(linestring);
138 linestream >> getParams();
139 } else { // unknown keys are simply ignored as long as parser is incomplete
140 LOG(3, "INFO: '"+key+"' is unknown and ignored.");
141 }
142 }
143 }
144 if ((linestring.find("geometry") != string::npos) && (linestring.find("(") != string::npos)) {
145 LOG(3, "INFO: Line contains geometry and '(': " << line);
146 GeometrySection = true;
147 }
148 if ((linestring.find("psi:") != string::npos) && (linestring.find("(") != string::npos)) {
149 LOG(3, "INFO: Line contains psi: and '(': " << line);
150 Psi3Section = true;
151 }
152 }
153 // refresh atom::nr and atom::name
154 newmol->getAtomCount();
155}
156
157/** Saves all atoms and data into a MPQC config file.
158 * \param *file output stream
159 * \param atoms atoms to store
160 */
161void FormatParser< psi3 >::save(ostream *file, const std::vector<atom *> &atoms)
162{
163 Vector center;
164// vector<atom *> allatoms = World::getInstance().getAllAtoms();
165
166 // calculate center
167 for (std::vector<atom *>::const_iterator runner = atoms.begin();runner != atoms.end(); ++runner)
168 center += (*runner)->getPosition();
169 center.Scale(1./(double)atoms.size());
170
171 // first without hessian
172 if (file->fail()) {
173 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open psi3 output file." << std::endl);
174 } else {
175 *file << "% Created by MoleCuilder" << std::endl;
176 *file << "psi: (" << std::endl;
177 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::labelParam)
178 << " = \"" << getParams().getParameter(Psi3Parser_Parameters::labelParam) << "\"" << std::endl;
179 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::jobtypeParam)
180 << " = " << getParams().getParameter(Psi3Parser_Parameters::jobtypeParam) << std::endl;
181 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::wavefunctionParam)
182 << " = " << getParams().getParameter(Psi3Parser_Parameters::wavefunctionParam) << std::endl;
183 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::maxiterParam)
184 << " = " << getParams().getParameter(Psi3Parser_Parameters::maxiterParam) << std::endl;
185 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::referenceParam)
186 << " = " << getParams().getParameter(Psi3Parser_Parameters::referenceParam) << std::endl;
187 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::basisParam)
188 << " = \"" << getParams().getParameter(Psi3Parser_Parameters::basisParam) << "\"" << std::endl;
189 const std::string reference = getParams().getParameter(Psi3Parser_Parameters::referenceParam);
190// if (reference == getParams().getReferenceName(Psi3Parser_Parameters::RHF)) {
191// }
192// if (reference == getParams().getReferenceName(Psi3Parser_Parameters::ROHF)) {
193// }
194 if ((reference == getParams().getReferenceName(Psi3Parser_Parameters::UHF))
195 || (reference == getParams().getReferenceName(Psi3Parser_Parameters::TWOCON))) {
196 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::multiplicityParam)
197 << " = " << getParams().getParameter(Psi3Parser_Parameters::multiplicityParam) << std::endl;
198 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::chargeParam)
199 << " = " << getParams().getParameter(Psi3Parser_Parameters::chargeParam) << std::endl;
200 }
201 if (reference == getParams().getReferenceName(Psi3Parser_Parameters::TWOCON)) {
202 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::soccParam)
203 << " = " << getParams().getParameter(Psi3Parser_Parameters::soccParam) << std::endl;
204 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::doccParam)
205 << " = " << getParams().getParameter(Psi3Parser_Parameters::doccParam) << std::endl;
206 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::subgroupParam)
207 << " = " << getParams().getParameter(Psi3Parser_Parameters::subgroupParam) << std::endl;
208 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::unique_axisParam)
209 << " = " << getParams().getParameter(Psi3Parser_Parameters::unique_axisParam) << std::endl;
210 }
211 if ((reference != getParams().getReferenceName(Psi3Parser_Parameters::RHF))
212 && (reference != getParams().getReferenceName(Psi3Parser_Parameters::ROHF))
213 && (reference != getParams().getReferenceName(Psi3Parser_Parameters::UHF))
214 && (reference != getParams().getReferenceName(Psi3Parser_Parameters::TWOCON)))
215 {
216 DoeLog(0) && (eLog() << Verbose(0)
217 << "Unknown level of reference requested for Psi3 output file." << std::endl);
218 }
219 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::freeze_coreParam)
220 << " = " << getParams().getParameter(Psi3Parser_Parameters::freeze_coreParam) << std::endl;
221 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::unitsParam)
222 << " = " << getParams().getParameter(Psi3Parser_Parameters::unitsParam) << std::endl;
223 *file << "\tgeometry = (" << std::endl;
224 // output of atoms
225 for (std::vector<atom *>::const_iterator AtomRunner = atoms.begin(); AtomRunner != atoms.end(); ++AtomRunner) {
226 (*AtomRunner)->OutputPsi3Line(file, &center);
227 }
228 *file << "\t)" << std::endl;
229 *file << "\t" << getParams().getParameterName(Psi3Parser_Parameters::originParam)
230 << " = " << getParams().getParameter(Psi3Parser_Parameters::originParam) << std::endl;
231 *file << ")" << std::endl;
232 }
233}
234
235
Note: See TracBrowser for help on using the repository browser.