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