source: src/Parser/Psi3Parser.cpp@ b3d687

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 b3d687 was 03a589, checked in by Frederik Heber <heber@…>, 13 years ago

Removed lots of remnant output functions in atom and molecule that are not used anymore.

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