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