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 | */
|
---|
37 | MpqcParser::MpqcParser() : HessianPresent(false)
|
---|
38 | {}
|
---|
39 |
|
---|
40 | /** Destructor of MpqcParser.
|
---|
41 | *
|
---|
42 | */
|
---|
43 | MpqcParser::~MpqcParser()
|
---|
44 | {}
|
---|
45 |
|
---|
46 | /** Load an MPQC config file into the World.
|
---|
47 | * \param *file input stream
|
---|
48 | */
|
---|
49 | void MpqcParser::load(istream *file)
|
---|
50 | {
|
---|
51 | // TODO: MpqcParser::load implementation
|
---|
52 | ASSERT(false, "Not implemented yet");
|
---|
53 | }
|
---|
54 |
|
---|
55 | void MpqcParser::save(ostream *file)
|
---|
56 | {
|
---|
57 | DoLog(0) && (Log() << Verbose(0) << "Saving changes to MPQC ." << std::endl);
|
---|
58 |
|
---|
59 | if (HessianPresent)
|
---|
60 | saveHessian(file);
|
---|
61 | else
|
---|
62 | saveSimple(file);
|
---|
63 | }
|
---|
64 |
|
---|
65 | /** Saves all atoms and data into a MPQC config file without hessian.
|
---|
66 | * \param *file output stream
|
---|
67 | */
|
---|
68 | void MpqcParser::saveSimple(ostream *file)
|
---|
69 | {
|
---|
70 | Vector center;
|
---|
71 | vector<atom *> allatoms = World::getInstance().getAllAtoms();
|
---|
72 |
|
---|
73 | // calculate center
|
---|
74 | for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
|
---|
75 | center += (*runner)->getPosition();
|
---|
76 | center.Scale(1./allatoms.size());
|
---|
77 |
|
---|
78 | // first without hessian
|
---|
79 | if (file->fail()) {
|
---|
80 | DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl);
|
---|
81 | } else {
|
---|
82 | *file << "% Created by MoleCuilder" << endl;
|
---|
83 | *file << "mpqc: (" << endl;
|
---|
84 | *file << "\tsavestate = no" << endl;
|
---|
85 | *file << "\tdo_gradient = yes" << endl;
|
---|
86 | *file << "\tmole<MBPT2>: (" << endl;
|
---|
87 | *file << "\t\tmaxiter = 200" << endl;
|
---|
88 | *file << "\t\tbasis = $:basis" << endl;
|
---|
89 | *file << "\t\tmolecule = $:molecule" << endl;
|
---|
90 | *file << "\t\treference<CLHF>: (" << endl;
|
---|
91 | *file << "\t\t\tbasis = $:basis" << endl;
|
---|
92 | *file << "\t\t\tmolecule = $:molecule" << endl;
|
---|
93 | *file << "\t\t)" << endl;
|
---|
94 | *file << "\t)" << endl;
|
---|
95 | *file << ")" << endl;
|
---|
96 | *file << "molecule<Molecule>: (" << endl;
|
---|
97 | *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
|
---|
98 | *file << "\t{ atoms geometry } = {" << endl;
|
---|
99 | // output of atoms
|
---|
100 | for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
|
---|
101 | (*AtomRunner)->OutputMPQCLine(file, ¢er);
|
---|
102 | }
|
---|
103 | *file << "\t}" << endl;
|
---|
104 | *file << ")" << endl;
|
---|
105 | *file << "basis<GaussianBasisSet>: (" << endl;
|
---|
106 | *file << "\tname = \"" << World::getInstance().getConfig()->basis << "\"" << endl;
|
---|
107 | *file << "\tmolecule = $:molecule" << endl;
|
---|
108 | *file << ")" << endl;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | /** Saves all atoms and data into a MPQC config file with hessian.
|
---|
113 | * \param *file output stream
|
---|
114 | */
|
---|
115 | void MpqcParser::saveHessian(ostream *file)
|
---|
116 | {
|
---|
117 | Vector center;
|
---|
118 | vector<atom *> allatoms = World::getInstance().getAllAtoms();
|
---|
119 |
|
---|
120 | // calculate center
|
---|
121 | for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
|
---|
122 | center += (*runner)->getPosition();
|
---|
123 | center.Scale(1./allatoms.size());
|
---|
124 |
|
---|
125 | // with hessian
|
---|
126 | if (file->fail()) {
|
---|
127 | DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl);
|
---|
128 | } else {
|
---|
129 | *file << "% Created by MoleCuilder" << endl;
|
---|
130 | *file << "mpqc: (" << endl;
|
---|
131 | *file << "\tsavestate = no" << endl;
|
---|
132 | *file << "\tdo_gradient = yes" << endl;
|
---|
133 | *file << "\tmole<CLHF>: (" << endl;
|
---|
134 | *file << "\t\tmaxiter = 200" << endl;
|
---|
135 | *file << "\t\tbasis = $:basis" << endl;
|
---|
136 | *file << "\t\tmolecule = $:molecule" << endl;
|
---|
137 | *file << "\t)" << endl;
|
---|
138 | *file << "\tfreq<MolecularFrequencies>: (" << endl;
|
---|
139 | *file << "\t\tmolecule=$:molecule" << endl;
|
---|
140 | *file << "\t)" << endl;
|
---|
141 | *file << ")" << endl;
|
---|
142 | *file << "molecule<Molecule>: (" << endl;
|
---|
143 | *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
|
---|
144 | *file << "\t{ atoms geometry } = {" << endl;
|
---|
145 | // output of atoms
|
---|
146 | for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
|
---|
147 | (*AtomRunner)->OutputMPQCLine(file, ¢er);
|
---|
148 | }
|
---|
149 | *file << "\t}" << endl;
|
---|
150 | *file << ")" << endl;
|
---|
151 | *file << "basis<GaussianBasisSet>: (" << endl;
|
---|
152 | *file << "\tname = \"" << World::getInstance().getConfig()->basis << "\"" << endl;
|
---|
153 | *file << "\tmolecule = $:molecule" << endl;
|
---|
154 | *file << ")" << endl;
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | /** Sets whether hessian is desired or not
|
---|
159 | * \param hessian statement
|
---|
160 | */
|
---|
161 | void MpqcParser::setHessian(bool hessian)
|
---|
162 | {
|
---|
163 | HessianPresent = hessian;
|
---|
164 | }
|
---|