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