| 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 | /**
|
|---|
| 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)
|
|---|
| 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 | */
|
|---|
| 75 | void 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, ¢er);
|
|---|
| 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 | */
|
|---|
| 123 | void 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, ¢er);
|
|---|
| 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 | }
|
|---|