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