[bcf653] | 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 |
|
---|
[43dad6] | 8 | /*
|
---|
| 9 | * MpqcParser.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: 12.06.2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
|
---|
[bbbad5] | 21 |
|
---|
[1b2d30] | 22 | #include "MpqcParser.hpp"
|
---|
| 23 |
|
---|
| 24 | #include "atom.hpp"
|
---|
| 25 | #include "config.hpp"
|
---|
| 26 | #include "element.hpp"
|
---|
[ad011c] | 27 | #include "CodePatterns/Log.hpp"
|
---|
| 28 | #include "CodePatterns/Verbose.hpp"
|
---|
[e97a44] | 29 | #include "LinearAlgebra/Vector.hpp"
|
---|
| 30 | #include "periodentafel.hpp"
|
---|
[1b2d30] | 31 | #include "World.hpp"
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | /** Constructor of MpqcParser.
|
---|
| 35 | *
|
---|
| 36 | */
|
---|
[2fd80b5] | 37 | MpqcParser::MpqcParser() : HessianPresent(false)
|
---|
[97b825] | 38 | {}
|
---|
[1b2d30] | 39 |
|
---|
| 40 | /** Destructor of MpqcParser.
|
---|
| 41 | *
|
---|
| 42 | */
|
---|
[97b825] | 43 | MpqcParser::~MpqcParser()
|
---|
| 44 | {}
|
---|
[1b2d30] | 45 |
|
---|
| 46 | /** Load an MPQC config file into the World.
|
---|
| 47 | * \param *file input stream
|
---|
| 48 | */
|
---|
| 49 | void MpqcParser::load(istream *file)
|
---|
| 50 | {
|
---|
[bd2390] | 51 | // TODO: MpqcParser::load implementation
|
---|
| 52 | ASSERT(false, "Not implemented yet");
|
---|
[1b2d30] | 53 | }
|
---|
| 54 |
|
---|
[73916f] | 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 | */
|
---|
| 61 | void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms)
|
---|
[1b2d30] | 62 | {
|
---|
[e97a44] | 63 | DoLog(0) && (Log() << Verbose(0) << "Saving changes to MPQC ." << std::endl);
|
---|
| 64 |
|
---|
[1b2d30] | 65 | if (HessianPresent)
|
---|
[73916f] | 66 | saveHessian(file, atoms);
|
---|
[1b2d30] | 67 | else
|
---|
[73916f] | 68 | saveSimple(file, atoms);
|
---|
[1b2d30] | 69 | }
|
---|
| 70 |
|
---|
| 71 | /** Saves all atoms and data into a MPQC config file without hessian.
|
---|
| 72 | * \param *file output stream
|
---|
[73916f] | 73 | * \param atoms atoms to store
|
---|
[1b2d30] | 74 | */
|
---|
[73916f] | 75 | void MpqcParser::saveSimple(ostream *file, const std::vector<atom *> &atoms)
|
---|
[1b2d30] | 76 | {
|
---|
| 77 | Vector center;
|
---|
| 78 | vector<atom *> allatoms = World::getInstance().getAllAtoms();
|
---|
| 79 |
|
---|
[d6b8e1] | 80 | // calculate center
|
---|
| 81 | for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
|
---|
[d74077] | 82 | center += (*runner)->getPosition();
|
---|
[d6b8e1] | 83 | center.Scale(1./allatoms.size());
|
---|
| 84 |
|
---|
[1b2d30] | 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) {
|
---|
[0dc86e2] | 108 | (*AtomRunner)->OutputMPQCLine(file, ¢er);
|
---|
[1b2d30] | 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
|
---|
[73916f] | 121 | * \param atoms atoms to store
|
---|
[1b2d30] | 122 | */
|
---|
[73916f] | 123 | void MpqcParser::saveHessian(ostream *file, const std::vector<atom *> &atoms)
|
---|
[1b2d30] | 124 | {
|
---|
| 125 | Vector center;
|
---|
| 126 | vector<atom *> allatoms = World::getInstance().getAllAtoms();
|
---|
| 127 |
|
---|
[d6b8e1] | 128 | // calculate center
|
---|
| 129 | for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
|
---|
[d74077] | 130 | center += (*runner)->getPosition();
|
---|
[d6b8e1] | 131 | center.Scale(1./allatoms.size());
|
---|
| 132 |
|
---|
[1b2d30] | 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) {
|
---|
[0dc86e2] | 155 | (*AtomRunner)->OutputMPQCLine(file, ¢er);
|
---|
[1b2d30] | 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 | */
|
---|
| 169 | void MpqcParser::setHessian(bool hessian)
|
---|
| 170 | {
|
---|
| 171 | HessianPresent = hessian;
|
---|
| 172 | }
|
---|