source: src/Parser/Psi3Parser.cpp@ bcfb77

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 bcfb77 was 41a467, checked in by Frederik Heber <heber@…>, 13 years ago

LARGE: config class is now just a tiny container.

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