| 1 | /*
 | 
|---|
| 2 |  * MpqcParser.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: 12.06.2010
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | // include config.h
 | 
|---|
| 9 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 10 | #include <config.h>
 | 
|---|
| 11 | #endif
 | 
|---|
| 12 | 
 | 
|---|
| 13 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| 14 | 
 | 
|---|
| 15 | #include "MpqcParser.hpp"
 | 
|---|
| 16 | 
 | 
|---|
| 17 | #include "atom.hpp"
 | 
|---|
| 18 | #include "config.hpp"
 | 
|---|
| 19 | #include "element.hpp"
 | 
|---|
| 20 | #include "Helpers/Log.hpp"
 | 
|---|
| 21 | #include "Helpers/Verbose.hpp"
 | 
|---|
| 22 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| 23 | #include "periodentafel.hpp"
 | 
|---|
| 24 | #include "World.hpp"
 | 
|---|
| 25 | 
 | 
|---|
| 26 | 
 | 
|---|
| 27 | /** Constructor of MpqcParser.
 | 
|---|
| 28 |  *
 | 
|---|
| 29 |  */
 | 
|---|
| 30 | MpqcParser::MpqcParser() : HessianPresent(false)
 | 
|---|
| 31 | {}
 | 
|---|
| 32 | 
 | 
|---|
| 33 | /** Destructor of MpqcParser.
 | 
|---|
| 34 |  *
 | 
|---|
| 35 |  */
 | 
|---|
| 36 | MpqcParser::~MpqcParser()
 | 
|---|
| 37 | {}
 | 
|---|
| 38 | 
 | 
|---|
| 39 | /** Load an MPQC config file into the World.
 | 
|---|
| 40 |  * \param *file input stream
 | 
|---|
| 41 |  */
 | 
|---|
| 42 | void MpqcParser::load(istream *file)
 | 
|---|
| 43 | {
 | 
|---|
| 44 |   DoeLog(0) && (Log() << Verbose(0) << "Not yet implemented" << endl) ;
 | 
|---|
| 45 | }
 | 
|---|
| 46 | 
 | 
|---|
| 47 | void MpqcParser::save(ostream *file)
 | 
|---|
| 48 | {
 | 
|---|
| 49 |   DoLog(0) && (Log() << Verbose(0) << "Saving changes to MPQC ." << std::endl);
 | 
|---|
| 50 | 
 | 
|---|
| 51 |   if (HessianPresent)
 | 
|---|
| 52 |     saveHessian(file);
 | 
|---|
| 53 |   else
 | 
|---|
| 54 |     saveSimple(file);
 | 
|---|
| 55 | }
 | 
|---|
| 56 | 
 | 
|---|
| 57 | /** Saves all atoms and data into a MPQC config file without hessian.
 | 
|---|
| 58 |  * \param *file output stream
 | 
|---|
| 59 |  */
 | 
|---|
| 60 | void MpqcParser::saveSimple(ostream *file)
 | 
|---|
| 61 | {
 | 
|---|
| 62 |   int AtomNo = 0;
 | 
|---|
| 63 |   Vector center;
 | 
|---|
| 64 |   vector<atom *> allatoms = World::getInstance().getAllAtoms();
 | 
|---|
| 65 | 
 | 
|---|
| 66 |   // calculate center
 | 
|---|
| 67 |   for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
 | 
|---|
| 68 |     center += (*runner)->getPosition();
 | 
|---|
| 69 |   center.Scale(1./allatoms.size());
 | 
|---|
| 70 | 
 | 
|---|
| 71 |   // first without hessian
 | 
|---|
| 72 |   if (file->fail()) {
 | 
|---|
| 73 |     DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl);
 | 
|---|
| 74 |   } else {
 | 
|---|
| 75 |     *file << "% Created by MoleCuilder" << endl;
 | 
|---|
| 76 |     *file << "mpqc: (" << endl;
 | 
|---|
| 77 |     *file << "\tsavestate = no" << endl;
 | 
|---|
| 78 |     *file << "\tdo_gradient = yes" << endl;
 | 
|---|
| 79 |     *file << "\tmole<MBPT2>: (" << endl;
 | 
|---|
| 80 |     *file << "\t\tmaxiter = 200" << endl;
 | 
|---|
| 81 |     *file << "\t\tbasis = $:basis" << endl;
 | 
|---|
| 82 |     *file << "\t\tmolecule = $:molecule" << endl;
 | 
|---|
| 83 |     *file << "\t\treference<CLHF>: (" << endl;
 | 
|---|
| 84 |     *file << "\t\t\tbasis = $:basis" << endl;
 | 
|---|
| 85 |     *file << "\t\t\tmolecule = $:molecule" << endl;
 | 
|---|
| 86 |     *file << "\t\t)" << endl;
 | 
|---|
| 87 |     *file << "\t)" << endl;
 | 
|---|
| 88 |     *file << ")" << endl;
 | 
|---|
| 89 |     *file << "molecule<Molecule>: (" << endl;
 | 
|---|
| 90 |     *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
 | 
|---|
| 91 |     *file << "\t{ atoms geometry } = {" << endl;
 | 
|---|
| 92 |     // output of atoms
 | 
|---|
| 93 |     for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
 | 
|---|
| 94 |       (*AtomRunner)->OutputMPQCLine(file, ¢er, &AtomNo);
 | 
|---|
| 95 |     }
 | 
|---|
| 96 |     *file << "\t}" << endl;
 | 
|---|
| 97 |     *file << ")" << endl;
 | 
|---|
| 98 |     *file << "basis<GaussianBasisSet>: (" << endl;
 | 
|---|
| 99 |     *file << "\tname = \"" << World::getInstance().getConfig()->basis << "\"" << endl;
 | 
|---|
| 100 |     *file << "\tmolecule = $:molecule" << endl;
 | 
|---|
| 101 |     *file << ")" << endl;
 | 
|---|
| 102 |   }
 | 
|---|
| 103 | }
 | 
|---|
| 104 | 
 | 
|---|
| 105 | /** Saves all atoms and data into a MPQC config file with hessian.
 | 
|---|
| 106 |  * \param *file output stream
 | 
|---|
| 107 |  */
 | 
|---|
| 108 | void MpqcParser::saveHessian(ostream *file)
 | 
|---|
| 109 | {
 | 
|---|
| 110 |   int AtomNo = 0;
 | 
|---|
| 111 |   Vector center;
 | 
|---|
| 112 |   vector<atom *> allatoms = World::getInstance().getAllAtoms();
 | 
|---|
| 113 | 
 | 
|---|
| 114 |   // calculate center
 | 
|---|
| 115 |   for (vector<atom *>::iterator runner = allatoms.begin();runner != allatoms.end(); ++runner)
 | 
|---|
| 116 |     center += (*runner)->getPosition();
 | 
|---|
| 117 |   center.Scale(1./allatoms.size());
 | 
|---|
| 118 | 
 | 
|---|
| 119 |   // with hessian
 | 
|---|
| 120 |   if (file->fail()) {
 | 
|---|
| 121 |     DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file." << endl);
 | 
|---|
| 122 |   } else {
 | 
|---|
| 123 |     *file << "% Created by MoleCuilder" << endl;
 | 
|---|
| 124 |     *file << "mpqc: (" << endl;
 | 
|---|
| 125 |     *file << "\tsavestate = no" << endl;
 | 
|---|
| 126 |     *file << "\tdo_gradient = yes" << endl;
 | 
|---|
| 127 |     *file << "\tmole<CLHF>: (" << endl;
 | 
|---|
| 128 |     *file << "\t\tmaxiter = 200" << endl;
 | 
|---|
| 129 |     *file << "\t\tbasis = $:basis" << endl;
 | 
|---|
| 130 |     *file << "\t\tmolecule = $:molecule" << endl;
 | 
|---|
| 131 |     *file << "\t)" << endl;
 | 
|---|
| 132 |     *file << "\tfreq<MolecularFrequencies>: (" << endl;
 | 
|---|
| 133 |     *file << "\t\tmolecule=$:molecule" << endl;
 | 
|---|
| 134 |     *file << "\t)" << endl;
 | 
|---|
| 135 |     *file << ")" << endl;
 | 
|---|
| 136 |     *file << "molecule<Molecule>: (" << endl;
 | 
|---|
| 137 |     *file << "\tunit = " << (World::getInstance().getConfig()->GetIsAngstroem() ? "angstrom" : "bohr" ) << endl;
 | 
|---|
| 138 |     *file << "\t{ atoms geometry } = {" << endl;
 | 
|---|
| 139 |     // output of atoms
 | 
|---|
| 140 |     for (vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
 | 
|---|
| 141 |       (*AtomRunner)->OutputMPQCLine(file, ¢er, &AtomNo);
 | 
|---|
| 142 |     }
 | 
|---|
| 143 |     *file << "\t}" << endl;
 | 
|---|
| 144 |     *file << ")" << endl;
 | 
|---|
| 145 |     *file << "basis<GaussianBasisSet>: (" << endl;
 | 
|---|
| 146 |     *file << "\tname = \"" << World::getInstance().getConfig()->basis << "\"" << endl;
 | 
|---|
| 147 |     *file << "\tmolecule = $:molecule" << endl;
 | 
|---|
| 148 |     *file << ")" << endl;
 | 
|---|
| 149 |   }
 | 
|---|
| 150 | }
 | 
|---|
| 151 | 
 | 
|---|
| 152 | /** Sets whether hessian is desired or not
 | 
|---|
| 153 |  * \param hessian statement
 | 
|---|
| 154 |  */
 | 
|---|
| 155 | void MpqcParser::setHessian(bool hessian)
 | 
|---|
| 156 | {
 | 
|---|
| 157 |   HessianPresent = hessian;
 | 
|---|
| 158 | }
 | 
|---|