source: src/Parser/MpqcParser.cpp@ a2c4f3

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 a2c4f3 was 73916f, checked in by Frederik Heber <heber@…>, 14 years ago

Extended FormatParser::save() to use vector<atom *> to save.

  • This is needed to make the save functions also work on selected atoms or molecules only.
  • Within ParserCommonUnitTest, ParserTremoloUnitTest we create the vector by calling World's getAllAtoms() (which would have been done before in the specialized save() functions).
  • new functions in FormatParserStorage:
    • saveSelectedAtoms().
    • saveSelectedMolecules().
    • saveWorld().
  • renamed ::get() and ::put() to ::load() and ::save() to have it more consistent with underlying FormatParser functions and also to avoid misinterpretation with all ::get...() functions.
  • Property mode set to 100644
File size: 5.1 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 "Helpers/MemDebug.hpp"
21
22#include "MpqcParser.hpp"
23
24#include "atom.hpp"
25#include "config.hpp"
26#include "element.hpp"
27#include "Helpers/Log.hpp"
28#include "Helpers/Verbose.hpp"
29#include "LinearAlgebra/Vector.hpp"
30#include "periodentafel.hpp"
31#include "World.hpp"
32
33
34/** Constructor of MpqcParser.
35 *
36 */
37MpqcParser::MpqcParser() : HessianPresent(false)
38{}
39
40/** Destructor of MpqcParser.
41 *
42 */
43MpqcParser::~MpqcParser()
44{}
45
46/** Load an MPQC config file into the World.
47 * \param *file input stream
48 */
49void MpqcParser::load(istream *file)
50{
51 // TODO: MpqcParser::load implementation
52 ASSERT(false, "Not implemented yet");
53}
54
55/**
56 * Saves the \a atoms into as a MPQC file.
57 *
58 * \param file where to save the state
59 * \param atoms atoms to store
60 */
61void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms)
62{
63 DoLog(0) && (Log() << Verbose(0) << "Saving changes to MPQC ." << std::endl);
64
65 if (HessianPresent)
66 saveHessian(file, atoms);
67 else
68 saveSimple(file, atoms);
69}
70
71/** Saves all atoms and data into a MPQC config file without hessian.
72 * \param *file output stream
73 * \param atoms atoms to store
74 */
75void MpqcParser::saveSimple(ostream *file, const std::vector<atom *> &atoms)
76{
77 Vector center;
78 vector<atom *> allatoms = World::getInstance().getAllAtoms();
79
80 // calculate center
81 for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
82 center += (*runner)->getPosition();
83 center.Scale(1./allatoms.size());
84
85 // first without hessian
86 if (file->fail()) {
87 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl);
88 } else {
89 *file << "% Created by MoleCuilder" << endl;
90 *file << "mpqc: (" << endl;
91 *file << "\tsavestate = no" << endl;
92 *file << "\tdo_gradient = yes" << endl;
93 *file << "\tmole<MBPT2>: (" << endl;
94 *file << "\t\tmaxiter = 200" << endl;
95 *file << "\t\tbasis = $:basis" << endl;
96 *file << "\t\tmolecule = $:molecule" << endl;
97 *file << "\t\treference<CLHF>: (" << endl;
98 *file << "\t\t\tbasis = $:basis" << endl;
99 *file << "\t\t\tmolecule = $:molecule" << endl;
100 *file << "\t\t)" << endl;
101 *file << "\t)" << endl;
102 *file << ")" << endl;
103 *file << "molecule<Molecule>: (" << endl;
104 *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
105 *file << "\t{ atoms geometry } = {" << endl;
106 // output of atoms
107 for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
108 (*AtomRunner)->OutputMPQCLine(file, &center);
109 }
110 *file << "\t}" << endl;
111 *file << ")" << endl;
112 *file << "basis<GaussianBasisSet>: (" << endl;
113 *file << "\tname = \"" << World::getInstance().getConfig()->basis << "\"" << endl;
114 *file << "\tmolecule = $:molecule" << endl;
115 *file << ")" << endl;
116 }
117}
118
119/** Saves all atoms and data into a MPQC config file with hessian.
120 * \param *file output stream
121 * \param atoms atoms to store
122 */
123void MpqcParser::saveHessian(ostream *file, const std::vector<atom *> &atoms)
124{
125 Vector center;
126 vector<atom *> allatoms = World::getInstance().getAllAtoms();
127
128 // calculate center
129 for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
130 center += (*runner)->getPosition();
131 center.Scale(1./allatoms.size());
132
133 // with hessian
134 if (file->fail()) {
135 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl);
136 } else {
137 *file << "% Created by MoleCuilder" << endl;
138 *file << "mpqc: (" << endl;
139 *file << "\tsavestate = no" << endl;
140 *file << "\tdo_gradient = yes" << endl;
141 *file << "\tmole<CLHF>: (" << endl;
142 *file << "\t\tmaxiter = 200" << endl;
143 *file << "\t\tbasis = $:basis" << endl;
144 *file << "\t\tmolecule = $:molecule" << endl;
145 *file << "\t)" << endl;
146 *file << "\tfreq<MolecularFrequencies>: (" << endl;
147 *file << "\t\tmolecule=$:molecule" << endl;
148 *file << "\t)" << endl;
149 *file << ")" << endl;
150 *file << "molecule<Molecule>: (" << endl;
151 *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
152 *file << "\t{ atoms geometry } = {" << endl;
153 // output of atoms
154 for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
155 (*AtomRunner)->OutputMPQCLine(file, &center);
156 }
157 *file << "\t}" << endl;
158 *file << ")" << endl;
159 *file << "basis<GaussianBasisSet>: (" << endl;
160 *file << "\tname = \"" << World::getInstance().getConfig()->basis << "\"" << endl;
161 *file << "\tmolecule = $:molecule" << endl;
162 *file << ")" << endl;
163 }
164}
165
166/** Sets whether hessian is desired or not
167 * \param hessian statement
168 */
169void MpqcParser::setHessian(bool hessian)
170{
171 HessianPresent = hessian;
172}
Note: See TracBrowser for help on using the repository browser.