[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 |
|
---|
[14de469] | 8 | /** \file molecules.cpp
|
---|
[69eb71] | 9 | *
|
---|
[14de469] | 10 | * Functions for the class molecule.
|
---|
[69eb71] | 11 | *
|
---|
[14de469] | 12 | */
|
---|
| 13 |
|
---|
[bf3817] | 14 | // include config.h
|
---|
[aafd77] | 15 | #ifdef HAVE_CONFIG_H
|
---|
| 16 | #include <config.h>
|
---|
| 17 | #endif
|
---|
| 18 |
|
---|
[ad011c] | 19 | #include "CodePatterns/MemDebug.hpp"
|
---|
[112b09] | 20 |
|
---|
[49e1ae] | 21 | #include <cstring>
|
---|
[ac9b56] | 22 | #include <boost/bind.hpp>
|
---|
[9df5c6] | 23 | #include <boost/foreach.hpp>
|
---|
[49e1ae] | 24 |
|
---|
[aafd77] | 25 | #include <gsl/gsl_inline.h>
|
---|
| 26 | #include <gsl/gsl_heapsort.h>
|
---|
| 27 |
|
---|
[f66195] | 28 | #include "atom.hpp"
|
---|
| 29 | #include "bond.hpp"
|
---|
[9d83b6] | 30 | #include "Box.hpp"
|
---|
| 31 | #include "CodePatterns/enumeration.hpp"
|
---|
| 32 | #include "CodePatterns/Log.hpp"
|
---|
[a80fbdf] | 33 | #include "config.hpp"
|
---|
[f66195] | 34 | #include "element.hpp"
|
---|
[9d83b6] | 35 | #include "Exceptions/LinearDependenceException.hpp"
|
---|
[f66195] | 36 | #include "graph.hpp"
|
---|
[952f38] | 37 | #include "Helpers/helpers.hpp"
|
---|
[13d150] | 38 | #include "LinearAlgebra/leastsquaremin.hpp"
|
---|
[9d83b6] | 39 | #include "LinearAlgebra/Plane.hpp"
|
---|
| 40 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
|
---|
| 41 | #include "LinearAlgebra/Vector.hpp"
|
---|
[f66195] | 42 | #include "linkedcell.hpp"
|
---|
[cee0b57] | 43 | #include "molecule.hpp"
|
---|
[f66195] | 44 | #include "periodentafel.hpp"
|
---|
| 45 | #include "tesselation.hpp"
|
---|
[b34306] | 46 | #include "World.hpp"
|
---|
[9d83b6] | 47 | #include "WorldTime.hpp"
|
---|
[14de469] | 48 |
|
---|
| 49 |
|
---|
| 50 | /************************************* Functions for class molecule *********************************/
|
---|
| 51 |
|
---|
| 52 | /** Constructor of class molecule.
|
---|
| 53 | * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
|
---|
| 54 | */
|
---|
[cd5047] | 55 | molecule::molecule(const periodentafel * const teil) :
|
---|
| 56 | Observable("molecule"),
|
---|
[389cc8] | 57 | elemente(teil), MDSteps(0), BondCount(0), NoNonHydrogen(0), NoNonBonds(0),
|
---|
[cd5047] | 58 | NoCyclicBonds(0), BondDistance(0.), ActiveFlag(false), IndexNr(-1),
|
---|
[274d45] | 59 | AtomCount(this,boost::bind(&molecule::doCountAtoms,this),"AtomCount"), last_atom(0), InternalPointer(atoms.begin())
|
---|
[69eb71] | 60 | {
|
---|
[fa649a] | 61 |
|
---|
[387b36] | 62 | strcpy(name,World::getInstance().getDefaultName().c_str());
|
---|
[14de469] | 63 | };
|
---|
| 64 |
|
---|
[cbc5fb] | 65 | molecule *NewMolecule(){
|
---|
[23b547] | 66 | return new molecule(World::getInstance().getPeriode());
|
---|
[cbc5fb] | 67 | }
|
---|
| 68 |
|
---|
[14de469] | 69 | /** Destructor of class molecule.
|
---|
| 70 | * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
|
---|
| 71 | */
|
---|
[69eb71] | 72 | molecule::~molecule()
|
---|
[14de469] | 73 | {
|
---|
[042f82] | 74 | CleanupMolecule();
|
---|
[14de469] | 75 | };
|
---|
| 76 |
|
---|
[357fba] | 77 |
|
---|
[cbc5fb] | 78 | void DeleteMolecule(molecule *mol){
|
---|
| 79 | delete mol;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[520c8b] | 82 | // getter and setter
|
---|
[73a857] | 83 | const std::string molecule::getName() const{
|
---|
[520c8b] | 84 | return std::string(name);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[ea7176] | 87 | int molecule::getAtomCount() const{
|
---|
| 88 | return *AtomCount;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[520c8b] | 91 | void molecule::setName(const std::string _name){
|
---|
[2ba827] | 92 | OBSERVE;
|
---|
[35b698] | 93 | cout << "Set name of molecule " << getId() << " to " << _name << endl;
|
---|
[520c8b] | 94 | strncpy(name,_name.c_str(),MAXSTRINGSIZE);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[a7a087] | 97 | bool molecule::changeId(moleculeId_t newId){
|
---|
| 98 | // first we move ourselves in the world
|
---|
| 99 | // the world lets us know if that succeeded
|
---|
| 100 | if(World::getInstance().changeMoleculeId(id,newId,this)){
|
---|
| 101 | id = newId;
|
---|
| 102 | return true;
|
---|
| 103 | }
|
---|
| 104 | else{
|
---|
| 105 | return false;
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 |
|
---|
[73a857] | 110 | moleculeId_t molecule::getId() const {
|
---|
[cbc5fb] | 111 | return id;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | void molecule::setId(moleculeId_t _id){
|
---|
| 115 | id =_id;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[73a857] | 118 | const Formula &molecule::getFormula() const {
|
---|
[f17e1c] | 119 | return formula;
|
---|
[ac9b56] | 120 | }
|
---|
| 121 |
|
---|
[73a857] | 122 | unsigned int molecule::getElementCount() const{
|
---|
[389cc8] | 123 | return formula.getElementCount();
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | bool molecule::hasElement(const element *element) const{
|
---|
| 127 | return formula.hasElement(element);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | bool molecule::hasElement(atomicNumber_t Z) const{
|
---|
| 131 | return formula.hasElement(Z);
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | bool molecule::hasElement(const string &shorthand) const{
|
---|
| 135 | return formula.hasElement(shorthand);
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[bd58fb] | 138 | /************************** Access to the List of Atoms ****************/
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | molecule::iterator molecule::begin(){
|
---|
| 142 | return molecule::iterator(atoms.begin(),this);
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | molecule::const_iterator molecule::begin() const{
|
---|
| 146 | return atoms.begin();
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[9879f6] | 149 | molecule::iterator molecule::end(){
|
---|
[bd58fb] | 150 | return molecule::iterator(atoms.end(),this);
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[9879f6] | 153 | molecule::const_iterator molecule::end() const{
|
---|
[bd58fb] | 154 | return atoms.end();
|
---|
| 155 | }
|
---|
[520c8b] | 156 |
|
---|
[9879f6] | 157 | bool molecule::empty() const
|
---|
| 158 | {
|
---|
| 159 | return (begin() == end());
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | size_t molecule::size() const
|
---|
| 163 | {
|
---|
| 164 | size_t counter = 0;
|
---|
| 165 | for (molecule::const_iterator iter = begin(); iter != end (); ++iter)
|
---|
| 166 | counter++;
|
---|
| 167 | return counter;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | molecule::const_iterator molecule::erase( const_iterator loc )
|
---|
| 171 | {
|
---|
[bf8e20] | 172 | OBSERVE;
|
---|
[9879f6] | 173 | molecule::const_iterator iter = loc;
|
---|
| 174 | iter--;
|
---|
[6cfa36] | 175 | atom* atom = *loc;
|
---|
[274d45] | 176 | atomIds.erase( atom->getId() );
|
---|
| 177 | atoms.remove( atom );
|
---|
[8f4df1] | 178 | formula-=atom->getType();
|
---|
[6cfa36] | 179 | atom->removeFromMolecule();
|
---|
[9879f6] | 180 | return iter;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
[6cfa36] | 183 | molecule::const_iterator molecule::erase( atom * key )
|
---|
[9879f6] | 184 | {
|
---|
[bf8e20] | 185 | OBSERVE;
|
---|
[9879f6] | 186 | molecule::const_iterator iter = find(key);
|
---|
[a7b761b] | 187 | if (iter != end()){
|
---|
[274d45] | 188 | atomIds.erase( key->getId() );
|
---|
| 189 | atoms.remove( key );
|
---|
[8f4df1] | 190 | formula-=key->getType();
|
---|
[6cfa36] | 191 | key->removeFromMolecule();
|
---|
[a7b761b] | 192 | }
|
---|
| 193 | return iter;
|
---|
[9879f6] | 194 | }
|
---|
| 195 |
|
---|
[6cfa36] | 196 | molecule::const_iterator molecule::find ( atom * key ) const
|
---|
[9879f6] | 197 | {
|
---|
[274d45] | 198 | molecule::const_iterator iter;
|
---|
| 199 | for (molecule::const_iterator Runner = begin(); Runner != end(); ++Runner) {
|
---|
| 200 | if (*Runner == key)
|
---|
| 201 | return molecule::const_iterator(Runner);
|
---|
| 202 | }
|
---|
| 203 | return molecule::const_iterator(atoms.end());
|
---|
[9879f6] | 204 | }
|
---|
| 205 |
|
---|
| 206 | pair<molecule::iterator,bool> molecule::insert ( atom * const key )
|
---|
| 207 | {
|
---|
[bf8e20] | 208 | OBSERVE;
|
---|
[274d45] | 209 | pair<atomIdSet::iterator,bool> res = atomIds.insert(key->getId());
|
---|
| 210 | if (res.second) { // push atom if went well
|
---|
| 211 | atoms.push_back(key);
|
---|
[8f4df1] | 212 | formula+=key->getType();
|
---|
[274d45] | 213 | return pair<iterator,bool>(molecule::iterator(--end()),res.second);
|
---|
| 214 | } else {
|
---|
| 215 | return pair<iterator,bool>(molecule::iterator(end()),res.second);
|
---|
| 216 | }
|
---|
[9879f6] | 217 | }
|
---|
[520c8b] | 218 |
|
---|
[6cfa36] | 219 | bool molecule::containsAtom(atom* key){
|
---|
[274d45] | 220 | return (find(key) != end());
|
---|
[6cfa36] | 221 | }
|
---|
| 222 |
|
---|
[14de469] | 223 | /** Adds given atom \a *pointer from molecule list.
|
---|
[69eb71] | 224 | * Increases molecule::last_atom and gives last number to added atom and names it according to its element::abbrev and molecule::AtomCount
|
---|
[14de469] | 225 | * \param *pointer allocated and set atom
|
---|
| 226 | * \return true - succeeded, false - atom not found in list
|
---|
| 227 | */
|
---|
| 228 | bool molecule::AddAtom(atom *pointer)
|
---|
[69eb71] | 229 | {
|
---|
[2ba827] | 230 | OBSERVE;
|
---|
[042f82] | 231 | if (pointer != NULL) {
|
---|
| 232 | pointer->sort = &pointer->nr;
|
---|
[d74077] | 233 | if (pointer->getType() != NULL) {
|
---|
[83f176] | 234 | if (pointer->getType()->getAtomicNumber() != 1)
|
---|
[042f82] | 235 | NoNonHydrogen++;
|
---|
[68f03d] | 236 | if(pointer->getName() == "Unknown"){
|
---|
| 237 | stringstream sstr;
|
---|
[b5c53d] | 238 | sstr << pointer->getType()->getSymbol() << pointer->nr+1;
|
---|
[68f03d] | 239 | pointer->setName(sstr.str());
|
---|
[042f82] | 240 | }
|
---|
| 241 | }
|
---|
[9879f6] | 242 | insert(pointer);
|
---|
[6cfa36] | 243 | pointer->setMolecule(this);
|
---|
[f721c6] | 244 | }
|
---|
[9879f6] | 245 | return true;
|
---|
[14de469] | 246 | };
|
---|
| 247 |
|
---|
| 248 | /** Adds a copy of the given atom \a *pointer from molecule list.
|
---|
| 249 | * Increases molecule::last_atom and gives last number to added atom.
|
---|
| 250 | * \param *pointer allocated and set atom
|
---|
[89c8b2] | 251 | * \return pointer to the newly added atom
|
---|
[14de469] | 252 | */
|
---|
| 253 | atom * molecule::AddCopyAtom(atom *pointer)
|
---|
[69eb71] | 254 | {
|
---|
[f721c6] | 255 | atom *retval = NULL;
|
---|
[2ba827] | 256 | OBSERVE;
|
---|
[042f82] | 257 | if (pointer != NULL) {
|
---|
[46d958] | 258 | atom *walker = pointer->clone();
|
---|
[a7b761b] | 259 | walker->setName(pointer->getName());
|
---|
[2319ed] | 260 | walker->nr = last_atom++; // increase number within molecule
|
---|
[9879f6] | 261 | insert(walker);
|
---|
[83f176] | 262 | if ((pointer->getType() != NULL) && (pointer->getType()->getAtomicNumber() != 1))
|
---|
[042f82] | 263 | NoNonHydrogen++;
|
---|
[e8926e] | 264 | walker->setMolecule(this);
|
---|
[f721c6] | 265 | retval=walker;
|
---|
| 266 | }
|
---|
| 267 | return retval;
|
---|
[14de469] | 268 | };
|
---|
| 269 |
|
---|
| 270 | /** Adds a Hydrogen atom in replacement for the given atom \a *partner in bond with a *origin.
|
---|
| 271 | * Here, we have to distinguish between single, double or triple bonds as stated by \a BondDegree, that each demand
|
---|
| 272 | * a different scheme when adding \a *replacement atom for the given one.
|
---|
| 273 | * -# Single Bond: Simply add new atom with bond distance rescaled to typical hydrogen one
|
---|
| 274 | * -# Double Bond: Here, we need the **BondList of the \a *origin atom, by scanning for the other bonds instead of
|
---|
[042f82] | 275 | * *Bond, we use the through these connected atoms to determine the plane they lie in, vector::MakeNormalvector().
|
---|
| 276 | * The orthonormal vector to this plane along with the vector in *Bond direction determines the plane the two
|
---|
| 277 | * replacing hydrogens shall lie in. Now, all remains to do is take the usual hydrogen double bond angle for the
|
---|
| 278 | * element of *origin and form the sin/cos admixture of both plane vectors for the new coordinates of the two
|
---|
| 279 | * hydrogens forming this angle with *origin.
|
---|
[14de469] | 280 | * -# Triple Bond: The idea is to set up a tetraoid (C1-H1-H2-H3) (however the lengths \f$b\f$ of the sides of the base
|
---|
[042f82] | 281 | * triangle formed by the to be added hydrogens are not equal to the typical bond distance \f$l\f$ but have to be
|
---|
| 282 | * determined from the typical angle \f$\alpha\f$ for a hydrogen triple connected to the element of *origin):
|
---|
| 283 | * We have the height \f$d\f$ as the vector in *Bond direction (from triangle C1-H1-H2).
|
---|
| 284 | * \f[ h = l \cdot \cos{\left (\frac{\alpha}{2} \right )} \qquad b = 2l \cdot \sin{\left (\frac{\alpha}{2} \right)} \quad \rightarrow \quad d = l \cdot \sqrt{\cos^2{\left (\frac{\alpha}{2} \right)}-\frac{1}{3}\cdot\sin^2{\left (\frac{\alpha}{2}\right )}}
|
---|
| 285 | * \f]
|
---|
| 286 | * vector::GetNormalvector() creates one orthonormal vector from this *Bond vector and vector::MakeNormalvector creates
|
---|
| 287 | * the third one from the former two vectors. The latter ones form the plane of the base triangle mentioned above.
|
---|
| 288 | * The lengths for these are \f$f\f$ and \f$g\f$ (from triangle H1-H2-(center of H1-H2-H3)) with knowledge that
|
---|
| 289 | * the median lines in an isosceles triangle meet in the center point with a ratio 2:1.
|
---|
| 290 | * \f[ f = \frac{b}{\sqrt{3}} \qquad g = \frac{b}{2}
|
---|
| 291 | * \f]
|
---|
| 292 | * as the coordination of all three atoms in the coordinate system of these three vectors:
|
---|
| 293 | * \f$\pmatrix{d & f & 0}\f$, \f$\pmatrix{d & -0.5 \cdot f & g}\f$ and \f$\pmatrix{d & -0.5 \cdot f & -g}\f$.
|
---|
[69eb71] | 294 | *
|
---|
[14de469] | 295 | * \param *out output stream for debugging
|
---|
[69eb71] | 296 | * \param *Bond pointer to bond between \a *origin and \a *replacement
|
---|
| 297 | * \param *TopOrigin son of \a *origin of upper level molecule (the atom added to this molecule as a copy of \a *origin)
|
---|
[14de469] | 298 | * \param *origin pointer to atom which acts as the origin for scaling the added hydrogen to correct bond length
|
---|
| 299 | * \param *replacement pointer to the atom which shall be copied as a hydrogen atom in this molecule
|
---|
| 300 | * \param isAngstroem whether the coordination of the given atoms is in AtomicLength (false) or Angstrom(true)
|
---|
| 301 | * \return number of atoms added, if < bond::BondDegree then something went wrong
|
---|
| 302 | * \todo double and triple bonds splitting (always use the tetraeder angle!)
|
---|
| 303 | */
|
---|
[e138de] | 304 | bool molecule::AddHydrogenReplacementAtom(bond *TopBond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem)
|
---|
[14de469] | 305 | {
|
---|
[f721c6] | 306 | bool AllWentWell = true; // flag gathering the boolean return value of molecule::AddAtom and other functions, as return value on exit
|
---|
[2ba827] | 307 | OBSERVE;
|
---|
[042f82] | 308 | double bondlength; // bond length of the bond to be replaced/cut
|
---|
| 309 | double bondangle; // bond angle of the bond to be replaced/cut
|
---|
| 310 | double BondRescale; // rescale value for the hydrogen bond length
|
---|
| 311 | bond *FirstBond = NULL, *SecondBond = NULL; // Other bonds in double bond case to determine "other" plane
|
---|
| 312 | atom *FirstOtherAtom = NULL, *SecondOtherAtom = NULL, *ThirdOtherAtom = NULL; // pointer to hydrogen atoms to be added
|
---|
| 313 | double b,l,d,f,g, alpha, factors[NDIM]; // hold temporary values in triple bond case for coordination determination
|
---|
| 314 | Vector Orthovector1, Orthovector2; // temporary vectors in coordination construction
|
---|
| 315 | Vector InBondvector; // vector in direction of *Bond
|
---|
[cca9ef] | 316 | const RealSpaceMatrix &matrix = World::getInstance().getDomain().getM();
|
---|
[266237] | 317 | bond *Binder = NULL;
|
---|
[042f82] | 318 |
|
---|
[e138de] | 319 | // Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl;
|
---|
[042f82] | 320 | // create vector in direction of bond
|
---|
[d74077] | 321 | InBondvector = TopReplacement->getPosition() - TopOrigin->getPosition();
|
---|
[042f82] | 322 | bondlength = InBondvector.Norm();
|
---|
| 323 |
|
---|
| 324 | // is greater than typical bond distance? Then we have to correct periodically
|
---|
| 325 | // the problem is not the H being out of the box, but InBondvector have the wrong direction
|
---|
| 326 | // due to TopReplacement or Origin being on the wrong side!
|
---|
| 327 | if (bondlength > BondDistance) {
|
---|
[e138de] | 328 | // Log() << Verbose(4) << "InBondvector is: ";
|
---|
[042f82] | 329 | // InBondvector.Output(out);
|
---|
[e138de] | 330 | // Log() << Verbose(0) << endl;
|
---|
[042f82] | 331 | Orthovector1.Zero();
|
---|
| 332 | for (int i=NDIM;i--;) {
|
---|
[d74077] | 333 | l = TopReplacement->at(i) - TopOrigin->at(i);
|
---|
[042f82] | 334 | if (fabs(l) > BondDistance) { // is component greater than bond distance
|
---|
[0a4f7f] | 335 | Orthovector1[i] = (l < 0) ? -1. : +1.;
|
---|
[042f82] | 336 | } // (signs are correct, was tested!)
|
---|
| 337 | }
|
---|
[5108e1] | 338 | Orthovector1 *= matrix;
|
---|
[1bd79e] | 339 | InBondvector -= Orthovector1; // subtract just the additional translation
|
---|
[042f82] | 340 | bondlength = InBondvector.Norm();
|
---|
[e138de] | 341 | // Log() << Verbose(4) << "Corrected InBondvector is now: ";
|
---|
[042f82] | 342 | // InBondvector.Output(out);
|
---|
[e138de] | 343 | // Log() << Verbose(0) << endl;
|
---|
[042f82] | 344 | } // periodic correction finished
|
---|
| 345 |
|
---|
| 346 | InBondvector.Normalize();
|
---|
| 347 | // get typical bond length and store as scale factor for later
|
---|
[d74077] | 348 | ASSERT(TopOrigin->getType() != NULL, "AddHydrogenReplacementAtom: element of TopOrigin is not given.");
|
---|
[83f176] | 349 | BondRescale = TopOrigin->getType()->getHBondDistance(TopBond->BondDegree-1);
|
---|
[042f82] | 350 | if (BondRescale == -1) {
|
---|
[68f03d] | 351 | DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->getName() << "<->" << TopReplacement->getName() << ") of degree " << TopBond->BondDegree << "!" << endl);
|
---|
[2ba827] | 352 | return false;
|
---|
[042f82] | 353 | BondRescale = bondlength;
|
---|
| 354 | } else {
|
---|
| 355 | if (!IsAngstroem)
|
---|
| 356 | BondRescale /= (1.*AtomicLengthToAngstroem);
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | // discern single, double and triple bonds
|
---|
| 360 | switch(TopBond->BondDegree) {
|
---|
| 361 | case 1:
|
---|
[23b547] | 362 | FirstOtherAtom = World::getInstance().createAtom(); // new atom
|
---|
[d74077] | 363 | FirstOtherAtom->setType(1); // element is Hydrogen
|
---|
[bce72c] | 364 | FirstOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
|
---|
[6625c3] | 365 | FirstOtherAtom->setFixedIon(TopReplacement->getFixedIon());
|
---|
[83f176] | 366 | if (TopReplacement->getType()->getAtomicNumber() == 1) { // neither rescale nor replace if it's already hydrogen
|
---|
[042f82] | 367 | FirstOtherAtom->father = TopReplacement;
|
---|
| 368 | BondRescale = bondlength;
|
---|
| 369 | } else {
|
---|
| 370 | FirstOtherAtom->father = NULL; // if we replace hydrogen, we mark it as our father, otherwise we are just an added hydrogen with no father
|
---|
| 371 | }
|
---|
[1bd79e] | 372 | InBondvector *= BondRescale; // rescale the distance vector to Hydrogen bond length
|
---|
[d74077] | 373 | FirstOtherAtom->setPosition(TopOrigin->getPosition() + InBondvector); // set coordination to origin and add distance vector to replacement atom
|
---|
[042f82] | 374 | AllWentWell = AllWentWell && AddAtom(FirstOtherAtom);
|
---|
[e138de] | 375 | // Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: ";
|
---|
[042f82] | 376 | // FirstOtherAtom->x.Output(out);
|
---|
[e138de] | 377 | // Log() << Verbose(0) << endl;
|
---|
[042f82] | 378 | Binder = AddBond(BottomOrigin, FirstOtherAtom, 1);
|
---|
| 379 | Binder->Cyclic = false;
|
---|
| 380 | Binder->Type = TreeEdge;
|
---|
| 381 | break;
|
---|
| 382 | case 2:
|
---|
[9d83b6] | 383 | {
|
---|
| 384 | // determine two other bonds (warning if there are more than two other) plus valence sanity check
|
---|
| 385 | const BondList& ListOfBonds = TopOrigin->getListOfBonds();
|
---|
| 386 | for (BondList::const_iterator Runner = ListOfBonds.begin();
|
---|
| 387 | Runner != ListOfBonds.end();
|
---|
| 388 | ++Runner) {
|
---|
| 389 | if ((*Runner) != TopBond) {
|
---|
| 390 | if (FirstBond == NULL) {
|
---|
| 391 | FirstBond = (*Runner);
|
---|
| 392 | FirstOtherAtom = (*Runner)->GetOtherAtom(TopOrigin);
|
---|
| 393 | } else if (SecondBond == NULL) {
|
---|
| 394 | SecondBond = (*Runner);
|
---|
| 395 | SecondOtherAtom = (*Runner)->GetOtherAtom(TopOrigin);
|
---|
| 396 | } else {
|
---|
| 397 | DoeLog(2) && (eLog()<< Verbose(2) << "Detected more than four bonds for atom " << TopOrigin->getName());
|
---|
| 398 | }
|
---|
[042f82] | 399 | }
|
---|
| 400 | }
|
---|
| 401 | }
|
---|
| 402 | if (SecondOtherAtom == NULL) { // then we have an atom with valence four, but only 3 bonds: one to replace and one which is TopBond (third is FirstBond)
|
---|
| 403 | SecondBond = TopBond;
|
---|
| 404 | SecondOtherAtom = TopReplacement;
|
---|
| 405 | }
|
---|
| 406 | if (FirstOtherAtom != NULL) { // then we just have this double bond and the plane does not matter at all
|
---|
[e138de] | 407 | // Log() << Verbose(3) << "Regarding the double bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") to be constructed: Taking " << FirstOtherAtom->Name << " and " << SecondOtherAtom->Name << " along with " << TopOrigin->Name << " to determine orthogonal plane." << endl;
|
---|
[042f82] | 408 |
|
---|
| 409 | // determine the plane of these two with the *origin
|
---|
[0a4f7f] | 410 | try {
|
---|
[d74077] | 411 | Orthovector1 =Plane(TopOrigin->getPosition(), FirstOtherAtom->getPosition(), SecondOtherAtom->getPosition()).getNormal();
|
---|
[0a4f7f] | 412 | }
|
---|
| 413 | catch(LinearDependenceException &excp){
|
---|
| 414 | Log() << Verbose(0) << excp;
|
---|
| 415 | // TODO: figure out what to do with the Orthovector in this case
|
---|
| 416 | AllWentWell = false;
|
---|
| 417 | }
|
---|
[042f82] | 418 | } else {
|
---|
[273382] | 419 | Orthovector1.GetOneNormalVector(InBondvector);
|
---|
[042f82] | 420 | }
|
---|
[e138de] | 421 | //Log() << Verbose(3)<< "Orthovector1: ";
|
---|
[042f82] | 422 | //Orthovector1.Output(out);
|
---|
[e138de] | 423 | //Log() << Verbose(0) << endl;
|
---|
[042f82] | 424 | // orthogonal vector and bond vector between origin and replacement form the new plane
|
---|
[0a4f7f] | 425 | Orthovector1.MakeNormalTo(InBondvector);
|
---|
[042f82] | 426 | Orthovector1.Normalize();
|
---|
[e138de] | 427 | //Log() << Verbose(3) << "ReScaleCheck: " << Orthovector1.Norm() << " and " << InBondvector.Norm() << "." << endl;
|
---|
[042f82] | 428 |
|
---|
| 429 | // create the two Hydrogens ...
|
---|
[23b547] | 430 | FirstOtherAtom = World::getInstance().createAtom();
|
---|
| 431 | SecondOtherAtom = World::getInstance().createAtom();
|
---|
[d74077] | 432 | FirstOtherAtom->setType(1);
|
---|
| 433 | SecondOtherAtom->setType(1);
|
---|
[bce72c] | 434 | FirstOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
|
---|
[6625c3] | 435 | FirstOtherAtom->setFixedIon(TopReplacement->getFixedIon());
|
---|
[bce72c] | 436 | SecondOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
|
---|
[6625c3] | 437 | SecondOtherAtom->setFixedIon(TopReplacement->getFixedIon());
|
---|
[042f82] | 438 | FirstOtherAtom->father = NULL; // we are just an added hydrogen with no father
|
---|
| 439 | SecondOtherAtom->father = NULL; // we are just an added hydrogen with no father
|
---|
[83f176] | 440 | bondangle = TopOrigin->getType()->getHBondAngle(1);
|
---|
[042f82] | 441 | if (bondangle == -1) {
|
---|
[68f03d] | 442 | DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->getName() << "<->" << TopReplacement->getName() << ") of degree " << TopBond->BondDegree << "!" << endl);
|
---|
[2ba827] | 443 | return false;
|
---|
[042f82] | 444 | bondangle = 0;
|
---|
| 445 | }
|
---|
| 446 | bondangle *= M_PI/180./2.;
|
---|
[e138de] | 447 | // Log() << Verbose(3) << "ReScaleCheck: InBondvector ";
|
---|
[042f82] | 448 | // InBondvector.Output(out);
|
---|
[e138de] | 449 | // Log() << Verbose(0) << endl;
|
---|
| 450 | // Log() << Verbose(3) << "ReScaleCheck: Orthovector ";
|
---|
[042f82] | 451 | // Orthovector1.Output(out);
|
---|
[e138de] | 452 | // Log() << Verbose(0) << endl;
|
---|
| 453 | // Log() << Verbose(3) << "Half the bond angle is " << bondangle << ", sin and cos of it: " << sin(bondangle) << ", " << cos(bondangle) << endl;
|
---|
[d74077] | 454 | FirstOtherAtom->Zero();
|
---|
| 455 | SecondOtherAtom->Zero();
|
---|
[042f82] | 456 | for(int i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondvector is bondangle = 0 direction)
|
---|
[d74077] | 457 | FirstOtherAtom->set(i, InBondvector[i] * cos(bondangle) + Orthovector1[i] * (sin(bondangle)));
|
---|
| 458 | SecondOtherAtom->set(i, InBondvector[i] * cos(bondangle) + Orthovector1[i] * (-sin(bondangle)));
|
---|
[042f82] | 459 | }
|
---|
[d74077] | 460 | FirstOtherAtom->Scale(BondRescale); // rescale by correct BondDistance
|
---|
| 461 | SecondOtherAtom->Scale(BondRescale);
|
---|
[e138de] | 462 | //Log() << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl;
|
---|
[d74077] | 463 | *FirstOtherAtom += TopOrigin->getPosition();
|
---|
| 464 | *SecondOtherAtom += TopOrigin->getPosition();
|
---|
[042f82] | 465 | // ... and add to molecule
|
---|
| 466 | AllWentWell = AllWentWell && AddAtom(FirstOtherAtom);
|
---|
| 467 | AllWentWell = AllWentWell && AddAtom(SecondOtherAtom);
|
---|
[e138de] | 468 | // Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: ";
|
---|
[042f82] | 469 | // FirstOtherAtom->x.Output(out);
|
---|
[e138de] | 470 | // Log() << Verbose(0) << endl;
|
---|
| 471 | // Log() << Verbose(4) << "Added " << *SecondOtherAtom << " at: ";
|
---|
[042f82] | 472 | // SecondOtherAtom->x.Output(out);
|
---|
[e138de] | 473 | // Log() << Verbose(0) << endl;
|
---|
[042f82] | 474 | Binder = AddBond(BottomOrigin, FirstOtherAtom, 1);
|
---|
| 475 | Binder->Cyclic = false;
|
---|
| 476 | Binder->Type = TreeEdge;
|
---|
| 477 | Binder = AddBond(BottomOrigin, SecondOtherAtom, 1);
|
---|
| 478 | Binder->Cyclic = false;
|
---|
| 479 | Binder->Type = TreeEdge;
|
---|
| 480 | break;
|
---|
| 481 | case 3:
|
---|
| 482 | // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid)
|
---|
[23b547] | 483 | FirstOtherAtom = World::getInstance().createAtom();
|
---|
| 484 | SecondOtherAtom = World::getInstance().createAtom();
|
---|
| 485 | ThirdOtherAtom = World::getInstance().createAtom();
|
---|
[d74077] | 486 | FirstOtherAtom->setType(1);
|
---|
| 487 | SecondOtherAtom->setType(1);
|
---|
| 488 | ThirdOtherAtom->setType(1);
|
---|
[bce72c] | 489 | FirstOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
|
---|
[6625c3] | 490 | FirstOtherAtom->setFixedIon(TopReplacement->getFixedIon());
|
---|
[bce72c] | 491 | SecondOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
|
---|
[6625c3] | 492 | SecondOtherAtom->setFixedIon(TopReplacement->getFixedIon());
|
---|
[bce72c] | 493 | ThirdOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
|
---|
[6625c3] | 494 | ThirdOtherAtom->setFixedIon(TopReplacement->getFixedIon());
|
---|
[042f82] | 495 | FirstOtherAtom->father = NULL; // we are just an added hydrogen with no father
|
---|
| 496 | SecondOtherAtom->father = NULL; // we are just an added hydrogen with no father
|
---|
| 497 | ThirdOtherAtom->father = NULL; // we are just an added hydrogen with no father
|
---|
| 498 |
|
---|
| 499 | // we need to vectors orthonormal the InBondvector
|
---|
[273382] | 500 | AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector(InBondvector);
|
---|
[e138de] | 501 | // Log() << Verbose(3) << "Orthovector1: ";
|
---|
[042f82] | 502 | // Orthovector1.Output(out);
|
---|
[e138de] | 503 | // Log() << Verbose(0) << endl;
|
---|
[0a4f7f] | 504 | try{
|
---|
| 505 | Orthovector2 = Plane(InBondvector, Orthovector1,0).getNormal();
|
---|
| 506 | }
|
---|
| 507 | catch(LinearDependenceException &excp) {
|
---|
| 508 | Log() << Verbose(0) << excp;
|
---|
| 509 | AllWentWell = false;
|
---|
| 510 | }
|
---|
[e138de] | 511 | // Log() << Verbose(3) << "Orthovector2: ";
|
---|
[042f82] | 512 | // Orthovector2.Output(out);
|
---|
[e138de] | 513 | // Log() << Verbose(0) << endl;
|
---|
[042f82] | 514 |
|
---|
| 515 | // create correct coordination for the three atoms
|
---|
[83f176] | 516 | alpha = (TopOrigin->getType()->getHBondAngle(2))/180.*M_PI/2.; // retrieve triple bond angle from database
|
---|
[042f82] | 517 | l = BondRescale; // desired bond length
|
---|
| 518 | b = 2.*l*sin(alpha); // base length of isosceles triangle
|
---|
| 519 | d = l*sqrt(cos(alpha)*cos(alpha) - sin(alpha)*sin(alpha)/3.); // length for InBondvector
|
---|
| 520 | f = b/sqrt(3.); // length for Orthvector1
|
---|
| 521 | g = b/2.; // length for Orthvector2
|
---|
[e138de] | 522 | // Log() << Verbose(3) << "Bond length and half-angle: " << l << ", " << alpha << "\t (b,d,f,g) = " << b << ", " << d << ", " << f << ", " << g << ", " << endl;
|
---|
| 523 | // Log() << Verbose(3) << "The three Bond lengths: " << sqrt(d*d+f*f) << ", " << sqrt(d*d+(-0.5*f)*(-0.5*f)+g*g) << ", " << sqrt(d*d+(-0.5*f)*(-0.5*f)+g*g) << endl;
|
---|
[042f82] | 524 | factors[0] = d;
|
---|
| 525 | factors[1] = f;
|
---|
| 526 | factors[2] = 0.;
|
---|
[d74077] | 527 | FirstOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
|
---|
[042f82] | 528 | factors[1] = -0.5*f;
|
---|
| 529 | factors[2] = g;
|
---|
[d74077] | 530 | SecondOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
|
---|
[042f82] | 531 | factors[2] = -g;
|
---|
[d74077] | 532 | ThirdOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
|
---|
[042f82] | 533 |
|
---|
| 534 | // rescale each to correct BondDistance
|
---|
| 535 | // FirstOtherAtom->x.Scale(&BondRescale);
|
---|
| 536 | // SecondOtherAtom->x.Scale(&BondRescale);
|
---|
| 537 | // ThirdOtherAtom->x.Scale(&BondRescale);
|
---|
| 538 |
|
---|
| 539 | // and relative to *origin atom
|
---|
[d74077] | 540 | *FirstOtherAtom += TopOrigin->getPosition();
|
---|
| 541 | *SecondOtherAtom += TopOrigin->getPosition();
|
---|
| 542 | *ThirdOtherAtom += TopOrigin->getPosition();
|
---|
[042f82] | 543 |
|
---|
| 544 | // ... and add to molecule
|
---|
| 545 | AllWentWell = AllWentWell && AddAtom(FirstOtherAtom);
|
---|
| 546 | AllWentWell = AllWentWell && AddAtom(SecondOtherAtom);
|
---|
| 547 | AllWentWell = AllWentWell && AddAtom(ThirdOtherAtom);
|
---|
[e138de] | 548 | // Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: ";
|
---|
[042f82] | 549 | // FirstOtherAtom->x.Output(out);
|
---|
[e138de] | 550 | // Log() << Verbose(0) << endl;
|
---|
| 551 | // Log() << Verbose(4) << "Added " << *SecondOtherAtom << " at: ";
|
---|
[042f82] | 552 | // SecondOtherAtom->x.Output(out);
|
---|
[e138de] | 553 | // Log() << Verbose(0) << endl;
|
---|
| 554 | // Log() << Verbose(4) << "Added " << *ThirdOtherAtom << " at: ";
|
---|
[042f82] | 555 | // ThirdOtherAtom->x.Output(out);
|
---|
[e138de] | 556 | // Log() << Verbose(0) << endl;
|
---|
[042f82] | 557 | Binder = AddBond(BottomOrigin, FirstOtherAtom, 1);
|
---|
| 558 | Binder->Cyclic = false;
|
---|
| 559 | Binder->Type = TreeEdge;
|
---|
| 560 | Binder = AddBond(BottomOrigin, SecondOtherAtom, 1);
|
---|
| 561 | Binder->Cyclic = false;
|
---|
| 562 | Binder->Type = TreeEdge;
|
---|
| 563 | Binder = AddBond(BottomOrigin, ThirdOtherAtom, 1);
|
---|
| 564 | Binder->Cyclic = false;
|
---|
| 565 | Binder->Type = TreeEdge;
|
---|
| 566 | break;
|
---|
| 567 | default:
|
---|
[58ed4a] | 568 | DoeLog(1) && (eLog()<< Verbose(1) << "BondDegree does not state single, double or triple bond!" << endl);
|
---|
[042f82] | 569 | AllWentWell = false;
|
---|
| 570 | break;
|
---|
| 571 | }
|
---|
| 572 |
|
---|
[e138de] | 573 | // Log() << Verbose(3) << "End of AddHydrogenReplacementAtom." << endl;
|
---|
[042f82] | 574 | return AllWentWell;
|
---|
[14de469] | 575 | };
|
---|
| 576 |
|
---|
| 577 | /** Adds given atom \a *pointer from molecule list.
|
---|
| 578 | * Increases molecule::last_atom and gives last number to added atom.
|
---|
| 579 | * \param filename name and path of xyz file
|
---|
| 580 | * \return true - succeeded, false - file not found
|
---|
| 581 | */
|
---|
| 582 | bool molecule::AddXYZFile(string filename)
|
---|
[69eb71] | 583 | {
|
---|
[f721c6] | 584 |
|
---|
[042f82] | 585 | istringstream *input = NULL;
|
---|
| 586 | int NumberOfAtoms = 0; // atom number in xyz read
|
---|
[6625c3] | 587 | int i; // loop variables
|
---|
[042f82] | 588 | atom *Walker = NULL; // pointer to added atom
|
---|
| 589 | char shorthand[3]; // shorthand for atom name
|
---|
| 590 | ifstream xyzfile; // xyz file
|
---|
| 591 | string line; // currently parsed line
|
---|
| 592 | double x[3]; // atom coordinates
|
---|
| 593 |
|
---|
| 594 | xyzfile.open(filename.c_str());
|
---|
| 595 | if (!xyzfile)
|
---|
| 596 | return false;
|
---|
| 597 |
|
---|
[2ba827] | 598 | OBSERVE;
|
---|
[042f82] | 599 | getline(xyzfile,line,'\n'); // Read numer of atoms in file
|
---|
| 600 | input = new istringstream(line);
|
---|
| 601 | *input >> NumberOfAtoms;
|
---|
[a67d19] | 602 | DoLog(0) && (Log() << Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl);
|
---|
[042f82] | 603 | getline(xyzfile,line,'\n'); // Read comment
|
---|
[a67d19] | 604 | DoLog(1) && (Log() << Verbose(1) << "Comment: " << line << endl);
|
---|
[042f82] | 605 |
|
---|
| 606 | if (MDSteps == 0) // no atoms yet present
|
---|
| 607 | MDSteps++;
|
---|
| 608 | for(i=0;i<NumberOfAtoms;i++){
|
---|
[23b547] | 609 | Walker = World::getInstance().createAtom();
|
---|
[042f82] | 610 | getline(xyzfile,line,'\n');
|
---|
| 611 | istringstream *item = new istringstream(line);
|
---|
| 612 | //istringstream input(line);
|
---|
[e138de] | 613 | //Log() << Verbose(1) << "Reading: " << line << endl;
|
---|
[042f82] | 614 | *item >> shorthand;
|
---|
| 615 | *item >> x[0];
|
---|
| 616 | *item >> x[1];
|
---|
| 617 | *item >> x[2];
|
---|
[d74077] | 618 | Walker->setType(elemente->FindElement(shorthand));
|
---|
| 619 | if (Walker->getType() == NULL) {
|
---|
[58ed4a] | 620 | DoeLog(1) && (eLog()<< Verbose(1) << "Could not parse the element at line: '" << line << "', setting to H.");
|
---|
[d74077] | 621 | Walker->setType(1);
|
---|
[042f82] | 622 | }
|
---|
[056e70] | 623 |
|
---|
[d74077] | 624 | Walker->setPosition(Vector(x));
|
---|
[056e70] | 625 | Walker->setPositionAtStep(MDSteps-1, Vector(x));
|
---|
| 626 | Walker->setAtomicVelocityAtStep(MDSteps-1, zeroVec);
|
---|
| 627 | Walker->setAtomicForceAtStep(MDSteps-1, zeroVec);
|
---|
[042f82] | 628 | AddAtom(Walker); // add to molecule
|
---|
| 629 | delete(item);
|
---|
| 630 | }
|
---|
| 631 | xyzfile.close();
|
---|
| 632 | delete(input);
|
---|
| 633 | return true;
|
---|
[14de469] | 634 | };
|
---|
| 635 |
|
---|
| 636 | /** Creates a copy of this molecule.
|
---|
| 637 | * \return copy of molecule
|
---|
| 638 | */
|
---|
[e4afb4] | 639 | molecule *molecule::CopyMolecule() const
|
---|
[14de469] | 640 | {
|
---|
[5f612ee] | 641 | molecule *copy = World::getInstance().createMolecule();
|
---|
[042f82] | 642 |
|
---|
| 643 | // copy all atoms
|
---|
[0cc92b] | 644 | for_each(atoms.begin(),atoms.end(),bind1st(mem_fun(&molecule::AddCopyAtom),copy));
|
---|
[042f82] | 645 |
|
---|
| 646 | // copy all bonds
|
---|
[9d83b6] | 647 | for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) {
|
---|
| 648 | const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
|
---|
| 649 | for(BondList::const_iterator BondRunner = ListOfBonds.begin();
|
---|
| 650 | BondRunner != ListOfBonds.end();
|
---|
| 651 | ++BondRunner)
|
---|
[e08c46] | 652 | if ((*BondRunner)->leftatom == *AtomRunner) {
|
---|
[0cc92b] | 653 | bond *Binder = (*BondRunner);
|
---|
[e08c46] | 654 | // get the pendant atoms of current bond in the copy molecule
|
---|
[76ff55] | 655 | atomSet::iterator leftiter=find_if(copy->atoms.begin(),copy->atoms.end(),bind2nd(mem_fun(&atom::isFather),Binder->leftatom));
|
---|
| 656 | atomSet::iterator rightiter=find_if(copy->atoms.begin(),copy->atoms.end(),bind2nd(mem_fun(&atom::isFather),Binder->rightatom));
|
---|
| 657 | ASSERT(leftiter!=copy->atoms.end(),"No copy of original left atom for bond copy found");
|
---|
| 658 | ASSERT(leftiter!=copy->atoms.end(),"No copy of original right atom for bond copy found");
|
---|
[0cc92b] | 659 | atom *LeftAtom = *leftiter;
|
---|
| 660 | atom *RightAtom = *rightiter;
|
---|
| 661 |
|
---|
| 662 | bond *NewBond = copy->AddBond(LeftAtom, RightAtom, Binder->BondDegree);
|
---|
[e08c46] | 663 | NewBond->Cyclic = Binder->Cyclic;
|
---|
| 664 | if (Binder->Cyclic)
|
---|
| 665 | copy->NoCyclicBonds++;
|
---|
| 666 | NewBond->Type = Binder->Type;
|
---|
| 667 | }
|
---|
[9d83b6] | 668 | }
|
---|
[042f82] | 669 | // correct fathers
|
---|
[0cc92b] | 670 | for_each(atoms.begin(),atoms.end(),mem_fun(&atom::CorrectFather));
|
---|
[cee0b57] | 671 |
|
---|
[042f82] | 672 | // copy values
|
---|
[e08c46] | 673 | if (hasBondStructure()) { // if adjaceny list is present
|
---|
[042f82] | 674 | copy->BondDistance = BondDistance;
|
---|
| 675 | }
|
---|
| 676 |
|
---|
| 677 | return copy;
|
---|
[14de469] | 678 | };
|
---|
| 679 |
|
---|
[89c8b2] | 680 |
|
---|
[9df680] | 681 | /** Destroys all atoms inside this molecule.
|
---|
| 682 | */
|
---|
| 683 | void molecule::removeAtomsinMolecule()
|
---|
| 684 | {
|
---|
| 685 | // remove each atom from world
|
---|
| 686 | for(molecule::const_iterator AtomRunner = begin(); !empty(); AtomRunner = begin())
|
---|
| 687 | World::getInstance().destroyAtom(*AtomRunner);
|
---|
| 688 | };
|
---|
| 689 |
|
---|
| 690 |
|
---|
[89c8b2] | 691 | /**
|
---|
| 692 | * Copies all atoms of a molecule which are within the defined parallelepiped.
|
---|
| 693 | *
|
---|
| 694 | * @param offest for the origin of the parallelepiped
|
---|
| 695 | * @param three vectors forming the matrix that defines the shape of the parallelpiped
|
---|
| 696 | */
|
---|
[c550dd] | 697 | molecule* molecule::CopyMoleculeFromSubRegion(const Shape ®ion) const {
|
---|
[5f612ee] | 698 | molecule *copy = World::getInstance().createMolecule();
|
---|
[89c8b2] | 699 |
|
---|
[9df5c6] | 700 | BOOST_FOREACH(atom *iter,atoms){
|
---|
[c550dd] | 701 | if(iter->IsInShape(region)){
|
---|
[9df5c6] | 702 | copy->AddCopyAtom(iter);
|
---|
| 703 | }
|
---|
| 704 | }
|
---|
[89c8b2] | 705 |
|
---|
[e138de] | 706 | //TODO: copy->BuildInducedSubgraph(this);
|
---|
[89c8b2] | 707 |
|
---|
| 708 | return copy;
|
---|
| 709 | }
|
---|
| 710 |
|
---|
[14de469] | 711 | /** Adds a bond to a the molecule specified by two atoms, \a *first and \a *second.
|
---|
| 712 | * Also updates molecule::BondCount and molecule::NoNonBonds.
|
---|
| 713 | * \param *first first atom in bond
|
---|
| 714 | * \param *second atom in bond
|
---|
| 715 | * \return pointer to bond or NULL on failure
|
---|
| 716 | */
|
---|
[cee0b57] | 717 | bond * molecule::AddBond(atom *atom1, atom *atom2, int degree)
|
---|
[14de469] | 718 | {
|
---|
[f8e486] | 719 | OBSERVE;
|
---|
[042f82] | 720 | bond *Binder = NULL;
|
---|
[05a97c] | 721 |
|
---|
| 722 | // some checks to make sure we are able to create the bond
|
---|
| 723 | ASSERT(atom1, "First atom in bond-creation was an invalid pointer");
|
---|
| 724 | ASSERT(atom2, "Second atom in bond-creation was an invalid pointer");
|
---|
| 725 | ASSERT(FindAtom(atom1->nr),"First atom in bond-creation was not part of molecule");
|
---|
[76ff55] | 726 | ASSERT(FindAtom(atom2->nr),"Second atom in bond-creation was not part of molecule");
|
---|
[05a97c] | 727 |
|
---|
| 728 | Binder = new bond(atom1, atom2, degree, BondCount++);
|
---|
[073a9e4] | 729 | atom1->RegisterBond(WorldTime::getTime(), Binder);
|
---|
| 730 | atom2->RegisterBond(WorldTime::getTime(), Binder);
|
---|
[83f176] | 731 | if ((atom1->getType() != NULL) && (atom1->getType()->getAtomicNumber() != 1) && (atom2->getType() != NULL) && (atom2->getType()->getAtomicNumber() != 1))
|
---|
[05a97c] | 732 | NoNonBonds++;
|
---|
| 733 |
|
---|
[042f82] | 734 | return Binder;
|
---|
[14de469] | 735 | };
|
---|
| 736 |
|
---|
[fa649a] | 737 | /** Remove bond from bond chain list and from the both atom::ListOfBonds.
|
---|
[073a9e4] | 738 | * Bond::~Bond takes care of bond removal
|
---|
[14de469] | 739 | * \param *pointer bond pointer
|
---|
| 740 | * \return true - bound found and removed, false - bond not found/removed
|
---|
| 741 | */
|
---|
| 742 | bool molecule::RemoveBond(bond *pointer)
|
---|
| 743 | {
|
---|
[58ed4a] | 744 | //DoeLog(1) && (eLog()<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl);
|
---|
[e08c46] | 745 | delete(pointer);
|
---|
[042f82] | 746 | return true;
|
---|
[14de469] | 747 | };
|
---|
| 748 |
|
---|
| 749 | /** Remove every bond from bond chain list that atom \a *BondPartner is a constituent of.
|
---|
[69eb71] | 750 | * \todo Function not implemented yet
|
---|
[14de469] | 751 | * \param *BondPartner atom to be removed
|
---|
| 752 | * \return true - bounds found and removed, false - bonds not found/removed
|
---|
| 753 | */
|
---|
| 754 | bool molecule::RemoveBonds(atom *BondPartner)
|
---|
| 755 | {
|
---|
[58ed4a] | 756 | //DoeLog(1) && (eLog()<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl);
|
---|
[266237] | 757 | BondList::const_iterator ForeRunner;
|
---|
[9d83b6] | 758 | BondList& ListOfBonds = BondPartner->getListOfBonds();
|
---|
| 759 | while (!ListOfBonds.empty()) {
|
---|
| 760 | ForeRunner = ListOfBonds.begin();
|
---|
[266237] | 761 | RemoveBond(*ForeRunner);
|
---|
| 762 | }
|
---|
[042f82] | 763 | return false;
|
---|
[14de469] | 764 | };
|
---|
| 765 |
|
---|
[1907a7] | 766 | /** Set molecule::name from the basename without suffix in the given \a *filename.
|
---|
| 767 | * \param *filename filename
|
---|
| 768 | */
|
---|
[d67150] | 769 | void molecule::SetNameFromFilename(const char *filename)
|
---|
[1907a7] | 770 | {
|
---|
| 771 | int length = 0;
|
---|
[f7f7a4] | 772 | const char *molname = strrchr(filename, '/');
|
---|
| 773 | if (molname != NULL)
|
---|
| 774 | molname += sizeof(char); // search for filename without dirs
|
---|
| 775 | else
|
---|
| 776 | molname = filename; // contains no slashes
|
---|
[49e1ae] | 777 | const char *endname = strchr(molname, '.');
|
---|
[1907a7] | 778 | if ((endname == NULL) || (endname < molname))
|
---|
| 779 | length = strlen(molname);
|
---|
| 780 | else
|
---|
| 781 | length = strlen(molname) - strlen(endname);
|
---|
[35b698] | 782 | cout << "Set name of molecule " << getId() << " to " << molname << endl;
|
---|
[1907a7] | 783 | strncpy(name, molname, length);
|
---|
[d67150] | 784 | name[length]='\0';
|
---|
[1907a7] | 785 | };
|
---|
| 786 |
|
---|
[14de469] | 787 | /** Sets the molecule::cell_size to the components of \a *dim (rectangular box)
|
---|
| 788 | * \param *dim vector class
|
---|
| 789 | */
|
---|
[e9b8bb] | 790 | void molecule::SetBoxDimension(Vector *dim)
|
---|
[14de469] | 791 | {
|
---|
[cca9ef] | 792 | RealSpaceMatrix domain;
|
---|
[84c494] | 793 | for(int i =0; i<NDIM;++i)
|
---|
| 794 | domain.at(i,i) = dim->at(i);
|
---|
| 795 | World::getInstance().setDomain(domain);
|
---|
[14de469] | 796 | };
|
---|
| 797 |
|
---|
[fa7989] | 798 | /** Removes atom from molecule list and removes all of its bonds.
|
---|
[cee0b57] | 799 | * \param *pointer atom to be removed
|
---|
| 800 | * \return true - succeeded, false - atom not found in list
|
---|
[a9d254] | 801 | */
|
---|
[cee0b57] | 802 | bool molecule::RemoveAtom(atom *pointer)
|
---|
[a9d254] | 803 | {
|
---|
[a7b761b] | 804 | ASSERT(pointer, "Null pointer passed to molecule::RemoveAtom().");
|
---|
[ea7176] | 805 | OBSERVE;
|
---|
[266237] | 806 | RemoveBonds(pointer);
|
---|
[9879f6] | 807 | erase(pointer);
|
---|
| 808 | return true;
|
---|
[a9d254] | 809 | };
|
---|
| 810 |
|
---|
[cee0b57] | 811 | /** Removes atom from molecule list, but does not delete it.
|
---|
| 812 | * \param *pointer atom to be removed
|
---|
| 813 | * \return true - succeeded, false - atom not found in list
|
---|
[f3278b] | 814 | */
|
---|
[cee0b57] | 815 | bool molecule::UnlinkAtom(atom *pointer)
|
---|
[f3278b] | 816 | {
|
---|
[cee0b57] | 817 | if (pointer == NULL)
|
---|
| 818 | return false;
|
---|
[9879f6] | 819 | erase(pointer);
|
---|
[cee0b57] | 820 | return true;
|
---|
[f3278b] | 821 | };
|
---|
| 822 |
|
---|
[cee0b57] | 823 | /** Removes every atom from molecule list.
|
---|
| 824 | * \return true - succeeded, false - atom not found in list
|
---|
[14de469] | 825 | */
|
---|
[cee0b57] | 826 | bool molecule::CleanupMolecule()
|
---|
[14de469] | 827 | {
|
---|
[9879f6] | 828 | for (molecule::iterator iter = begin(); !empty(); iter = begin())
|
---|
[fa7989] | 829 | erase(*iter);
|
---|
[274d45] | 830 | return empty();
|
---|
[69eb71] | 831 | };
|
---|
[14de469] | 832 |
|
---|
[cee0b57] | 833 | /** Finds an atom specified by its continuous number.
|
---|
| 834 | * \param Nr number of atom withim molecule
|
---|
| 835 | * \return pointer to atom or NULL
|
---|
[14de469] | 836 | */
|
---|
[9879f6] | 837 | atom * molecule::FindAtom(int Nr) const
|
---|
| 838 | {
|
---|
| 839 | molecule::const_iterator iter = begin();
|
---|
| 840 | for (; iter != end(); ++iter)
|
---|
| 841 | if ((*iter)->nr == Nr)
|
---|
| 842 | break;
|
---|
| 843 | if (iter != end()) {
|
---|
[e138de] | 844 | //Log() << Verbose(0) << "Found Atom Nr. " << walker->nr << endl;
|
---|
[9879f6] | 845 | return (*iter);
|
---|
[cee0b57] | 846 | } else {
|
---|
[a67d19] | 847 | DoLog(0) && (Log() << Verbose(0) << "Atom not found in list." << endl);
|
---|
[cee0b57] | 848 | return NULL;
|
---|
[042f82] | 849 | }
|
---|
[69eb71] | 850 | };
|
---|
[14de469] | 851 |
|
---|
[cee0b57] | 852 | /** Asks for atom number, and checks whether in list.
|
---|
| 853 | * \param *text question before entering
|
---|
[a6b7fb] | 854 | */
|
---|
[cee0b57] | 855 | atom * molecule::AskAtom(string text)
|
---|
[a6b7fb] | 856 | {
|
---|
[cee0b57] | 857 | int No;
|
---|
| 858 | atom *ion = NULL;
|
---|
| 859 | do {
|
---|
[e138de] | 860 | //Log() << Verbose(0) << "============Atom list==========================" << endl;
|
---|
[cee0b57] | 861 | //mol->Output((ofstream *)&cout);
|
---|
[e138de] | 862 | //Log() << Verbose(0) << "===============================================" << endl;
|
---|
[a67d19] | 863 | DoLog(0) && (Log() << Verbose(0) << text);
|
---|
[cee0b57] | 864 | cin >> No;
|
---|
| 865 | ion = this->FindAtom(No);
|
---|
| 866 | } while (ion == NULL);
|
---|
| 867 | return ion;
|
---|
[a6b7fb] | 868 | };
|
---|
| 869 |
|
---|
[cee0b57] | 870 | /** Checks if given coordinates are within cell volume.
|
---|
| 871 | * \param *x array of coordinates
|
---|
| 872 | * \return true - is within, false - out of cell
|
---|
[14de469] | 873 | */
|
---|
[cee0b57] | 874 | bool molecule::CheckBounds(const Vector *x) const
|
---|
[14de469] | 875 | {
|
---|
[cca9ef] | 876 | const RealSpaceMatrix &domain = World::getInstance().getDomain().getM();
|
---|
[cee0b57] | 877 | bool result = true;
|
---|
| 878 | for (int i=0;i<NDIM;i++) {
|
---|
[84c494] | 879 | result = result && ((x->at(i) >= 0) && (x->at(i) < domain.at(i,i)));
|
---|
[042f82] | 880 | }
|
---|
[cee0b57] | 881 | //return result;
|
---|
| 882 | return true; /// probably not gonna use the check no more
|
---|
[69eb71] | 883 | };
|
---|
[14de469] | 884 |
|
---|
[cee0b57] | 885 | /** Prints molecule to *out.
|
---|
| 886 | * \param *out output stream
|
---|
[14de469] | 887 | */
|
---|
[e4afb4] | 888 | bool molecule::Output(ostream * const output) const
|
---|
[14de469] | 889 | {
|
---|
[e138de] | 890 | if (output == NULL) {
|
---|
[cee0b57] | 891 | return false;
|
---|
| 892 | } else {
|
---|
[0ba410] | 893 | int AtomNo[MAX_ELEMENTS];
|
---|
| 894 | memset(AtomNo,0,(MAX_ELEMENTS-1)*sizeof(*AtomNo));
|
---|
| 895 | enumeration<const element*> elementLookup = formula.enumerateElements();
|
---|
| 896 | *output << "#Ion_TypeNr._Nr.R[0] R[1] R[2] MoveType (0 MoveIon, 1 FixedIon)" << endl;
|
---|
| 897 | for_each(atoms.begin(),atoms.end(),boost::bind(&atom::OutputArrayIndexed,_1,output,elementLookup,AtomNo,(const char*)0));
|
---|
[cee0b57] | 898 | return true;
|
---|
[042f82] | 899 | }
|
---|
[14de469] | 900 | };
|
---|
| 901 |
|
---|
[cee0b57] | 902 | /** Prints molecule with all atomic trajectory positions to *out.
|
---|
| 903 | * \param *out output stream
|
---|
[21c017] | 904 | */
|
---|
[e4afb4] | 905 | bool molecule::OutputTrajectories(ofstream * const output) const
|
---|
[21c017] | 906 | {
|
---|
[e138de] | 907 | if (output == NULL) {
|
---|
[cee0b57] | 908 | return false;
|
---|
| 909 | } else {
|
---|
| 910 | for (int step = 0; step < MDSteps; step++) {
|
---|
| 911 | if (step == 0) {
|
---|
[e138de] | 912 | *output << "#Ion_TypeNr._Nr.R[0] R[1] R[2] MoveType (0 MoveIon, 1 FixedIon)" << endl;
|
---|
[205ccd] | 913 | } else {
|
---|
[e138de] | 914 | *output << "# ====== MD step " << step << " =========" << endl;
|
---|
[cee0b57] | 915 | }
|
---|
[882a8a] | 916 | int AtomNo[MAX_ELEMENTS];
|
---|
| 917 | memset(AtomNo,0,(MAX_ELEMENTS-1)*sizeof(*AtomNo));
|
---|
| 918 | enumeration<const element*> elementLookup = formula.enumerateElements();
|
---|
| 919 | for_each(atoms.begin(),atoms.end(),boost::bind(&atom::OutputTrajectory,_1,output,elementLookup, AtomNo, (const int)step));
|
---|
[21c017] | 920 | }
|
---|
[cee0b57] | 921 | return true;
|
---|
[21c017] | 922 | }
|
---|
| 923 | };
|
---|
| 924 |
|
---|
[266237] | 925 | /** Outputs contents of each atom::ListOfBonds.
|
---|
[cee0b57] | 926 | * \param *out output stream
|
---|
[14de469] | 927 | */
|
---|
[e138de] | 928 | void molecule::OutputListOfBonds() const
|
---|
[14de469] | 929 | {
|
---|
[a67d19] | 930 | DoLog(2) && (Log() << Verbose(2) << endl << "From Contents of ListOfBonds, all non-hydrogen atoms:" << endl);
|
---|
[0eea14] | 931 | for_each(atoms.begin(),atoms.end(),mem_fun(&atom::OutputBondOfAtom));
|
---|
[a67d19] | 932 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[14de469] | 933 | };
|
---|
| 934 |
|
---|
[cee0b57] | 935 | /** Output of element before the actual coordination list.
|
---|
| 936 | * \param *out stream pointer
|
---|
[14de469] | 937 | */
|
---|
[e138de] | 938 | bool molecule::Checkout(ofstream * const output) const
|
---|
[14de469] | 939 | {
|
---|
[389cc8] | 940 | return formula.checkOut(output);
|
---|
[6e9353] | 941 | };
|
---|
| 942 |
|
---|
[cee0b57] | 943 | /** Prints molecule with all its trajectories to *out as xyz file.
|
---|
| 944 | * \param *out output stream
|
---|
[d7e30c] | 945 | */
|
---|
[e138de] | 946 | bool molecule::OutputTrajectoriesXYZ(ofstream * const output)
|
---|
[d7e30c] | 947 | {
|
---|
[cee0b57] | 948 | time_t now;
|
---|
[042f82] | 949 |
|
---|
[e138de] | 950 | if (output != NULL) {
|
---|
[681a8a] | 951 | now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time'
|
---|
[cee0b57] | 952 | for (int step=0;step<MDSteps;step++) {
|
---|
[ea7176] | 953 | *output << getAtomCount() << "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now);
|
---|
[7baf4a] | 954 | for_each(atoms.begin(),atoms.end(),boost::bind(&atom::OutputTrajectoryXYZ,_1,output,step));
|
---|
[042f82] | 955 | }
|
---|
[cee0b57] | 956 | return true;
|
---|
| 957 | } else
|
---|
| 958 | return false;
|
---|
[14de469] | 959 | };
|
---|
| 960 |
|
---|
[cee0b57] | 961 | /** Prints molecule to *out as xyz file.
|
---|
| 962 | * \param *out output stream
|
---|
[69eb71] | 963 | */
|
---|
[e138de] | 964 | bool molecule::OutputXYZ(ofstream * const output) const
|
---|
[4aa03a] | 965 | {
|
---|
[cee0b57] | 966 | time_t now;
|
---|
[042f82] | 967 |
|
---|
[e138de] | 968 | if (output != NULL) {
|
---|
[23b830] | 969 | now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time'
|
---|
[ea7176] | 970 | *output << getAtomCount() << "\n\tCreated by molecuilder on " << ctime(&now);
|
---|
[7baf4a] | 971 | for_each(atoms.begin(),atoms.end(),bind2nd(mem_fun(&atom::OutputXYZLine),output));
|
---|
[042f82] | 972 | return true;
|
---|
[cee0b57] | 973 | } else
|
---|
| 974 | return false;
|
---|
| 975 | };
|
---|
[4aa03a] | 976 |
|
---|
[cee0b57] | 977 | /** Brings molecule::AtomCount and atom::*Name up-to-date.
|
---|
[14de469] | 978 | * \param *out output stream for debugging
|
---|
| 979 | */
|
---|
[ea7176] | 980 | int molecule::doCountAtoms()
|
---|
[14de469] | 981 | {
|
---|
[ea7176] | 982 | int res = size();
|
---|
[cee0b57] | 983 | int i = 0;
|
---|
[ea7176] | 984 | NoNonHydrogen = 0;
|
---|
[e0b6fd] | 985 | for (molecule::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
|
---|
[ea7176] | 986 | (*iter)->nr = i; // update number in molecule (for easier referencing in FragmentMolecule lateron)
|
---|
[83f176] | 987 | if ((*iter)->getType()->getAtomicNumber() != 1) // count non-hydrogen atoms whilst at it
|
---|
[ea7176] | 988 | NoNonHydrogen++;
|
---|
[a7b761b] | 989 | stringstream sstr;
|
---|
[b5c53d] | 990 | sstr << (*iter)->getType()->getSymbol() << (*iter)->nr+1;
|
---|
[a7b761b] | 991 | (*iter)->setName(sstr.str());
|
---|
[7fd416] | 992 | DoLog(3) && (Log() << Verbose(3) << "Naming atom nr. " << (*iter)->nr << " " << (*iter)->getName() << "." << endl);
|
---|
[cee0b57] | 993 | i++;
|
---|
| 994 | }
|
---|
[ea7176] | 995 | return res;
|
---|
[cee0b57] | 996 | };
|
---|
[042f82] | 997 |
|
---|
[14de469] | 998 | /** Returns an index map for two father-son-molecules.
|
---|
| 999 | * The map tells which atom in this molecule corresponds to which one in the other molecul with their fathers.
|
---|
| 1000 | * \param *out output stream for debugging
|
---|
| 1001 | * \param *OtherMolecule corresponding molecule with fathers
|
---|
| 1002 | * \return allocated map of size molecule::AtomCount with map
|
---|
| 1003 | * \todo make this with a good sort O(n), not O(n^2)
|
---|
| 1004 | */
|
---|
[e138de] | 1005 | int * molecule::GetFatherSonAtomicMap(molecule *OtherMolecule)
|
---|
[14de469] | 1006 | {
|
---|
[a67d19] | 1007 | DoLog(3) && (Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl);
|
---|
[1024cb] | 1008 | int *AtomicMap = new int[getAtomCount()];
|
---|
[ea7176] | 1009 | for (int i=getAtomCount();i--;)
|
---|
[042f82] | 1010 | AtomicMap[i] = -1;
|
---|
| 1011 | if (OtherMolecule == this) { // same molecule
|
---|
[ea7176] | 1012 | for (int i=getAtomCount();i--;) // no need as -1 means already that there is trivial correspondence
|
---|
[042f82] | 1013 | AtomicMap[i] = i;
|
---|
[a67d19] | 1014 | DoLog(4) && (Log() << Verbose(4) << "Map is trivial." << endl);
|
---|
[042f82] | 1015 | } else {
|
---|
[a67d19] | 1016 | DoLog(4) && (Log() << Verbose(4) << "Map is ");
|
---|
[9879f6] | 1017 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
| 1018 | if ((*iter)->father == NULL) {
|
---|
| 1019 | AtomicMap[(*iter)->nr] = -2;
|
---|
[042f82] | 1020 | } else {
|
---|
[9879f6] | 1021 | for (molecule::const_iterator runner = OtherMolecule->begin(); runner != OtherMolecule->end(); ++runner) {
|
---|
[042f82] | 1022 | //for (int i=0;i<AtomCount;i++) { // search atom
|
---|
[1024cb] | 1023 | //for (int j=0;j<OtherMolecule->getAtomCount();j++) {
|
---|
[9879f6] | 1024 | //Log() << Verbose(4) << "Comparing father " << (*iter)->father << " with the other one " << (*runner)->father << "." << endl;
|
---|
| 1025 | if ((*iter)->father == (*runner))
|
---|
| 1026 | AtomicMap[(*iter)->nr] = (*runner)->nr;
|
---|
[042f82] | 1027 | }
|
---|
| 1028 | }
|
---|
[a7b761b] | 1029 | DoLog(0) && (Log() << Verbose(0) << AtomicMap[(*iter)->nr] << "\t");
|
---|
[042f82] | 1030 | }
|
---|
[a67d19] | 1031 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
[042f82] | 1032 | }
|
---|
[a67d19] | 1033 | DoLog(3) && (Log() << Verbose(3) << "End of GetFatherAtomicMap." << endl);
|
---|
[042f82] | 1034 | return AtomicMap;
|
---|
[14de469] | 1035 | };
|
---|
| 1036 |
|
---|
[698b04] | 1037 | /** Stores the temperature evaluated from velocities in molecule::Trajectories.
|
---|
| 1038 | * We simply use the formula equivaleting temperature and kinetic energy:
|
---|
| 1039 | * \f$k_B T = \sum_i m_i v_i^2\f$
|
---|
[e138de] | 1040 | * \param *output output stream of temperature file
|
---|
[698b04] | 1041 | * \param startstep first MD step in molecule::Trajectories
|
---|
| 1042 | * \param endstep last plus one MD step in molecule::Trajectories
|
---|
| 1043 | * \return file written (true), failure on writing file (false)
|
---|
[69eb71] | 1044 | */
|
---|
[e138de] | 1045 | bool molecule::OutputTemperatureFromTrajectories(ofstream * const output, int startstep, int endstep)
|
---|
[698b04] | 1046 | {
|
---|
[042f82] | 1047 | double temperature;
|
---|
| 1048 | // test stream
|
---|
| 1049 | if (output == NULL)
|
---|
| 1050 | return false;
|
---|
| 1051 | else
|
---|
| 1052 | *output << "# Step Temperature [K] Temperature [a.u.]" << endl;
|
---|
| 1053 | for (int step=startstep;step < endstep; step++) { // loop over all time steps
|
---|
[900402] | 1054 | temperature = atoms.totalTemperatureAtStep(step);
|
---|
[042f82] | 1055 | *output << step << "\t" << temperature*AtomicEnergyToKelvin << "\t" << temperature << endl;
|
---|
| 1056 | }
|
---|
| 1057 | return true;
|
---|
[65de9b] | 1058 | };
|
---|
[4a7776a] | 1059 |
|
---|
[c68025] | 1060 | void molecule::flipActiveFlag(){
|
---|
| 1061 | ActiveFlag = !ActiveFlag;
|
---|
| 1062 | }
|
---|