| [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 atom.cpp
 | 
|---|
| [1907a7] | 9 |  *
 | 
|---|
| [14de469] | 10 |  * Function implementations for the class atom.
 | 
|---|
| [1907a7] | 11 |  *
 | 
|---|
| [14de469] | 12 |  */
 | 
|---|
 | 13 | 
 | 
|---|
| [bf3817] | 14 | // include config.h
 | 
|---|
 | 15 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 16 | #include <config.h>
 | 
|---|
 | 17 | #endif
 | 
|---|
 | 18 | 
 | 
|---|
| [ad011c] | 19 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [112b09] | 20 | 
 | 
|---|
| [357fba] | 21 | #include "atom.hpp"
 | 
|---|
| [e41951] | 22 | #include "bond.hpp"
 | 
|---|
| [4a7776a] | 23 | #include "config.hpp"
 | 
|---|
| [f66195] | 24 | #include "element.hpp"
 | 
|---|
| [266237] | 25 | #include "lists.hpp"
 | 
|---|
| [ccd9f5] | 26 | #include "parser.hpp"
 | 
|---|
| [57f243] | 27 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| [d346b6] | 28 | #include "World.hpp"
 | 
|---|
| [6cfa36] | 29 | #include "molecule.hpp"
 | 
|---|
| [c550dd] | 30 | #include "Shapes/Shape.hpp"
 | 
|---|
| [a0064e] | 31 | 
 | 
|---|
| [36166d] | 32 | #include <iomanip>
 | 
|---|
| [0ba410] | 33 | #include <iostream>
 | 
|---|
| [36166d] | 34 | 
 | 
|---|
| [14de469] | 35 | /************************************* Functions for class atom *************************************/
 | 
|---|
 | 36 | 
 | 
|---|
| [70ff32] | 37 | 
 | 
|---|
| [14de469] | 38 | /** Constructor of class atom.
 | 
|---|
 | 39 |  */
 | 
|---|
| [46d958] | 40 | atom::atom() :
 | 
|---|
| [97b825] | 41 |   father(this),
 | 
|---|
 | 42 |   sort(&nr),
 | 
|---|
 | 43 |   mol(0)
 | 
|---|
| [d74077] | 44 | {};
 | 
|---|
| [14de469] | 45 | 
 | 
|---|
| [2319ed] | 46 | /** Constructor of class atom.
 | 
|---|
 | 47 |  */
 | 
|---|
| [46d958] | 48 | atom::atom(atom *pointer) :
 | 
|---|
| [97b825] | 49 |     ParticleInfo(pointer),
 | 
|---|
 | 50 |     father(pointer),
 | 
|---|
| [9df680] | 51 |     sort(&nr),
 | 
|---|
 | 52 |     mol(0)
 | 
|---|
| [2319ed] | 53 | {
 | 
|---|
| [d74077] | 54 |   setType(pointer->getType());  // copy element of atom
 | 
|---|
 | 55 |   setPosition(pointer->getPosition()); // copy coordination
 | 
|---|
 | 56 |   AtomicVelocity = pointer->AtomicVelocity; // copy velocity
 | 
|---|
| [2319ed] | 57 |   FixedIon = pointer->FixedIon;
 | 
|---|
| [b453f9] | 58 | };
 | 
|---|
| [2319ed] | 59 | 
 | 
|---|
| [46d958] | 60 | atom *atom::clone(){
 | 
|---|
| [68f03d] | 61 |   atom *res = new atom(this);
 | 
|---|
| [23b547] | 62 |   World::getInstance().registerAtom(res);
 | 
|---|
| [46d958] | 63 |   return res;
 | 
|---|
 | 64 | }
 | 
|---|
 | 65 | 
 | 
|---|
| [2319ed] | 66 | 
 | 
|---|
| [14de469] | 67 | /** Destructor of class atom.
 | 
|---|
 | 68 |  */
 | 
|---|
| [1907a7] | 69 | atom::~atom()
 | 
|---|
| [14de469] | 70 | {
 | 
|---|
| [6cfa36] | 71 |   removeFromMolecule();
 | 
|---|
| [a80241] | 72 |   for(BondList::iterator iter=ListOfBonds.begin(); iter!=ListOfBonds.end();){
 | 
|---|
 | 73 |     // deleting the bond will invalidate the iterator !!!
 | 
|---|
 | 74 |     bond *bond =*(iter++);
 | 
|---|
 | 75 |     delete(bond);
 | 
|---|
 | 76 |   }
 | 
|---|
| [14de469] | 77 | };
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 | 
 | 
|---|
 | 80 | /** Climbs up the father list until NULL, last is returned.
 | 
|---|
 | 81 |  * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
 | 
|---|
 | 82 |  */
 | 
|---|
 | 83 | atom *atom::GetTrueFather()
 | 
|---|
 | 84 | {
 | 
|---|
| [215df0] | 85 |   if(father == this){ // top most father is the one that points on itself
 | 
|---|
 | 86 |     return this;
 | 
|---|
 | 87 |   }
 | 
|---|
 | 88 |   else if(!father) {
 | 
|---|
 | 89 |     return 0;
 | 
|---|
 | 90 |   }
 | 
|---|
 | 91 |   else {
 | 
|---|
 | 92 |     return father->GetTrueFather();
 | 
|---|
 | 93 |   }
 | 
|---|
| [14de469] | 94 | };
 | 
|---|
 | 95 | 
 | 
|---|
| [e65246] | 96 | /** Sets father to itself or its father in case of copying a molecule.
 | 
|---|
 | 97 |  */
 | 
|---|
 | 98 | void atom::CorrectFather()
 | 
|---|
 | 99 | {
 | 
|---|
 | 100 |   if (father->father == father)   // same atom in copy's father points to itself
 | 
|---|
 | 101 |     father = this;  // set father to itself (copy of a whole molecule)
 | 
|---|
 | 102 |   else
 | 
|---|
 | 103 |    father = father->father;  // set father to original's father
 | 
|---|
 | 104 | 
 | 
|---|
 | 105 | };
 | 
|---|
 | 106 | 
 | 
|---|
 | 107 | /** Check whether father is equal to given atom.
 | 
|---|
 | 108 |  * \param *ptr atom to compare father to
 | 
|---|
 | 109 |  * \param **res return value (only set if atom::father is equal to \a *ptr)
 | 
|---|
 | 110 |  */
 | 
|---|
| [b453f9] | 111 | void atom::EqualsFather ( const atom *ptr, const atom **res ) const
 | 
|---|
| [e65246] | 112 | {
 | 
|---|
 | 113 |   if ( ptr == father )
 | 
|---|
 | 114 |     *res = this;
 | 
|---|
 | 115 | };
 | 
|---|
 | 116 | 
 | 
|---|
| [00abfc] | 117 | bool atom::isFather(const atom *ptr){
 | 
|---|
 | 118 |   return ptr==father;
 | 
|---|
 | 119 | }
 | 
|---|
 | 120 | 
 | 
|---|
| [e9f8f9] | 121 | /** Checks whether atom is within the given box.
 | 
|---|
 | 122 |  * \param offset offset to box origin
 | 
|---|
 | 123 |  * \param *parallelepiped box matrix
 | 
|---|
 | 124 |  * \return true - is inside, false - is not
 | 
|---|
 | 125 |  */
 | 
|---|
| [c550dd] | 126 | bool atom::IsInShape(const Shape& shape) const
 | 
|---|
| [e9f8f9] | 127 | {
 | 
|---|
| [d74077] | 128 |   return shape.isInside(getPosition());
 | 
|---|
| [e9f8f9] | 129 | };
 | 
|---|
 | 130 | 
 | 
|---|
| [266237] | 131 | /** Counts the number of bonds weighted by bond::BondDegree.
 | 
|---|
 | 132 |  * \param bonds times bond::BondDegree
 | 
|---|
 | 133 |  */
 | 
|---|
| [4455f4] | 134 | int BondedParticle::CountBonds() const
 | 
|---|
| [266237] | 135 | {
 | 
|---|
 | 136 |   int NoBonds = 0;
 | 
|---|
 | 137 |   for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
 | 
|---|
 | 138 |     NoBonds += (*Runner)->BondDegree;
 | 
|---|
 | 139 |   return NoBonds;
 | 
|---|
 | 140 | };
 | 
|---|
 | 141 | 
 | 
|---|
| [b453f9] | 142 | /** Output of a single atom with given numbering.
 | 
|---|
| [14de469] | 143 |  * \param ElementNo cardinal number of the element
 | 
|---|
 | 144 |  * \param AtomNo cardinal number among these atoms of the same element
 | 
|---|
 | 145 |  * \param *out stream to output to
 | 
|---|
| [1907a7] | 146 |  * \param *comment commentary after '#' sign
 | 
|---|
| [e41951] | 147 |   * \return true - \a *out present, false - \a *out is NULL
 | 
|---|
| [14de469] | 148 |  */
 | 
|---|
| [e138de] | 149 | bool atom::OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment) const
 | 
|---|
| [14de469] | 150 | {
 | 
|---|
 | 151 |   if (out != NULL) {
 | 
|---|
 | 152 |     *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t"  << fixed << setprecision(9) << showpoint;
 | 
|---|
| [d74077] | 153 |     *out << at(0) << "\t" << at(1) << "\t" << at(2);
 | 
|---|
| [943d02] | 154 |     *out << "\t" << FixedIon;
 | 
|---|
| [d74077] | 155 |     if (AtomicVelocity.Norm() > MYEPSILON)
 | 
|---|
 | 156 |       *out << "\t" << scientific << setprecision(6) << AtomicVelocity[0] << "\t" << AtomicVelocity[1] << "\t" << AtomicVelocity[2] << "\t";
 | 
|---|
| [437922] | 157 |     if (comment != NULL)
 | 
|---|
 | 158 |       *out << " # " << comment << endl;
 | 
|---|
| [e9f8f9] | 159 |     else
 | 
|---|
 | 160 |       *out << " # molecule nr " << nr << endl;
 | 
|---|
 | 161 |     return true;
 | 
|---|
 | 162 |   } else
 | 
|---|
 | 163 |     return false;
 | 
|---|
 | 164 | };
 | 
|---|
| [b453f9] | 165 | 
 | 
|---|
 | 166 | /** Output of a single atom with numbering from array according to atom::type.
 | 
|---|
 | 167 |  * \param *ElementNo cardinal number of the element
 | 
|---|
 | 168 |  * \param *AtomNo cardinal number among these atoms of the same element
 | 
|---|
 | 169 |  * \param *out stream to output to
 | 
|---|
 | 170 |  * \param *comment commentary after '#' sign
 | 
|---|
 | 171 |   * \return true - \a *out present, false - \a *out is NULL
 | 
|---|
 | 172 |  */
 | 
|---|
| [0ba410] | 173 | bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
 | 
|---|
| [e9f8f9] | 174 | {
 | 
|---|
| [83f176] | 175 |   AtomNo[getType()->getAtomicNumber()]++;  // increment number
 | 
|---|
| [e9f8f9] | 176 |   if (out != NULL) {
 | 
|---|
| [8f4df1] | 177 |     const element *elemental = getType();
 | 
|---|
 | 178 |     ASSERT(elementLookup.there.find(elemental)!=elementLookup.there.end(),"Type of this atom was not in the formula upon enumeration");
 | 
|---|
| [83f176] | 179 |     *out << "Ion_Type" << elementLookup.there.find(elemental)->second << "_" << AtomNo[elemental->getAtomicNumber()] << "\t"  << fixed << setprecision(9) << showpoint;
 | 
|---|
| [d74077] | 180 |     *out << at(0) << "\t" << at(1) << "\t" << at(2);
 | 
|---|
| [e9f8f9] | 181 |     *out << "\t" << FixedIon;
 | 
|---|
| [d74077] | 182 |     if (AtomicVelocity.Norm() > MYEPSILON)
 | 
|---|
 | 183 |       *out << "\t" << scientific << setprecision(6) << AtomicVelocity[0] << "\t" << AtomicVelocity[1] << "\t" << AtomicVelocity[2] << "\t";
 | 
|---|
| [e9f8f9] | 184 |     if (comment != NULL)
 | 
|---|
 | 185 |       *out << " # " << comment << endl;
 | 
|---|
| [437922] | 186 |     else
 | 
|---|
 | 187 |       *out << " # molecule nr " << nr << endl;
 | 
|---|
| [14de469] | 188 |     return true;
 | 
|---|
 | 189 |   } else
 | 
|---|
 | 190 |     return false;
 | 
|---|
 | 191 | };
 | 
|---|
 | 192 | 
 | 
|---|
 | 193 | /** Output of a single atom as one lin in xyz file.
 | 
|---|
 | 194 |  * \param *out stream to output to
 | 
|---|
| [e41951] | 195 |   * \return true - \a *out present, false - \a *out is NULL
 | 
|---|
| [14de469] | 196 |  */
 | 
|---|
 | 197 | bool atom::OutputXYZLine(ofstream *out) const
 | 
|---|
 | 198 | {
 | 
|---|
 | 199 |   if (out != NULL) {
 | 
|---|
| [b5c53d] | 200 |     *out << getType()->getSymbol() << "\t" << at(0) << "\t" << at(1) << "\t" << at(2) << "\t" << endl;
 | 
|---|
| [14de469] | 201 |     return true;
 | 
|---|
 | 202 |   } else
 | 
|---|
 | 203 |     return false;
 | 
|---|
 | 204 | };
 | 
|---|
 | 205 | 
 | 
|---|
| [fcd7b6] | 206 | /** Output of a single atom as one lin in xyz file.
 | 
|---|
 | 207 |  * \param *out stream to output to
 | 
|---|
| [e41951] | 208 |  * \param *ElementNo array with ion type number in the config file this atom's element shall have
 | 
|---|
 | 209 |  * \param *AtomNo array with atom number in the config file this atom shall have, is increase by one automatically
 | 
|---|
 | 210 |  * \param step Trajectory time step to output
 | 
|---|
 | 211 |   * \return true - \a *out present, false - \a *out is NULL
 | 
|---|
| [fcd7b6] | 212 |  */
 | 
|---|
| [882a8a] | 213 | bool atom::OutputTrajectory(ofstream * const out, const enumeration<const element*> &elementLookup, int *AtomNo, const int step) const
 | 
|---|
| [fcd7b6] | 214 | {
 | 
|---|
| [83f176] | 215 |   AtomNo[getType()->getAtomicNumber()]++;
 | 
|---|
| [882a8a] | 216 |   if (out != NULL) {
 | 
|---|
 | 217 |     const element *elemental = getType();
 | 
|---|
 | 218 |     ASSERT(elementLookup.there.find(elemental)!=elementLookup.there.end(),"Type of this atom was not in the formula upon enumeration");
 | 
|---|
 | 219 |     *out << "Ion_Type" << elementLookup.there.find(elemental)->second << "_" << AtomNo[getType()->getAtomicNumber()] << "\t"  << fixed << setprecision(9) << showpoint;
 | 
|---|
| [0a4f7f] | 220 |     *out << Trajectory.R.at(step)[0] << "\t" << Trajectory.R.at(step)[1] << "\t" << Trajectory.R.at(step)[2];
 | 
|---|
| [fcd7b6] | 221 |     *out << "\t" << FixedIon;
 | 
|---|
 | 222 |     if (Trajectory.U.at(step).Norm() > MYEPSILON)
 | 
|---|
| [0a4f7f] | 223 |       *out << "\t" << scientific << setprecision(6) << Trajectory.U.at(step)[0] << "\t" << Trajectory.U.at(step)[1] << "\t" << Trajectory.U.at(step)[2] << "\t";
 | 
|---|
| [fcd7b6] | 224 |     if (Trajectory.F.at(step).Norm() > MYEPSILON)
 | 
|---|
| [0a4f7f] | 225 |       *out << "\t" << scientific << setprecision(6) << Trajectory.F.at(step)[0] << "\t" << Trajectory.F.at(step)[1] << "\t" << Trajectory.F.at(step)[2] << "\t";
 | 
|---|
| [fcd7b6] | 226 |     *out << "\t# Number in molecule " << nr << endl;
 | 
|---|
 | 227 |     return true;
 | 
|---|
 | 228 |   } else
 | 
|---|
 | 229 |     return false;
 | 
|---|
 | 230 | };
 | 
|---|
 | 231 | 
 | 
|---|
| [681a8a] | 232 | /** Output of a single atom as one lin in xyz file.
 | 
|---|
 | 233 |  * \param *out stream to output to
 | 
|---|
| [e41951] | 234 |  * \param step Trajectory time step to output
 | 
|---|
 | 235 |  * \return true - \a *out present, false - \a *out is NULL
 | 
|---|
| [681a8a] | 236 |  */
 | 
|---|
| [e138de] | 237 | bool atom::OutputTrajectoryXYZ(ofstream * const out, const int step) const
 | 
|---|
| [681a8a] | 238 | {
 | 
|---|
 | 239 |   if (out != NULL) {
 | 
|---|
| [b5c53d] | 240 |     *out << getType()->getSymbol() << "\t";
 | 
|---|
| [0a4f7f] | 241 |     *out << Trajectory.R.at(step)[0] << "\t";
 | 
|---|
 | 242 |     *out << Trajectory.R.at(step)[1] << "\t";
 | 
|---|
 | 243 |     *out << Trajectory.R.at(step)[2] << endl;
 | 
|---|
| [681a8a] | 244 |     return true;
 | 
|---|
 | 245 |   } else
 | 
|---|
 | 246 |     return false;
 | 
|---|
 | 247 | };
 | 
|---|
 | 248 | 
 | 
|---|
| [4455f4] | 249 | /** Outputs the MPQC configuration line for this atom.
 | 
|---|
 | 250 |  * \param *out output stream
 | 
|---|
 | 251 |  * \param *center center of molecule subtracted from position
 | 
|---|
 | 252 |  * \param *AtomNo pointer to atom counter that is increased by one
 | 
|---|
 | 253 |  */
 | 
|---|
| [0dc86e2] | 254 | void atom::OutputMPQCLine(ostream * const out, const Vector *center) const
 | 
|---|
| [4455f4] | 255 | {
 | 
|---|
| [d74077] | 256 |   Vector recentered(getPosition());
 | 
|---|
 | 257 |   recentered -= *center;
 | 
|---|
| [b5c53d] | 258 |   *out << "\t\t" << getType()->getSymbol() << " [ " << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2] << " ]" << endl;
 | 
|---|
| [4455f4] | 259 | };
 | 
|---|
 | 260 | 
 | 
|---|
 | 261 | /** Compares the indices of \a this atom with a given \a ptr.
 | 
|---|
 | 262 |  * \param ptr atom to compare index against
 | 
|---|
 | 263 |  * \return true - this one's is smaller, false - not
 | 
|---|
 | 264 |  */
 | 
|---|
| [b453f9] | 265 | bool atom::Compare(const atom &ptr) const
 | 
|---|
| [4455f4] | 266 | {
 | 
|---|
 | 267 |   if (nr < ptr.nr)
 | 
|---|
 | 268 |     return true;
 | 
|---|
 | 269 |   else
 | 
|---|
 | 270 |     return false;
 | 
|---|
 | 271 | };
 | 
|---|
 | 272 | 
 | 
|---|
 | 273 | /** Returns squared distance to a given vector.
 | 
|---|
 | 274 |  * \param origin vector to calculate distance to
 | 
|---|
 | 275 |  * \return distance squared
 | 
|---|
 | 276 |  */
 | 
|---|
| [b453f9] | 277 | double atom::DistanceSquaredToVector(const Vector &origin) const
 | 
|---|
| [4455f4] | 278 | {
 | 
|---|
| [d74077] | 279 |   return DistanceSquared(origin);
 | 
|---|
| [4455f4] | 280 | };
 | 
|---|
 | 281 | 
 | 
|---|
 | 282 | /** Returns distance to a given vector.
 | 
|---|
 | 283 |  * \param origin vector to calculate distance to
 | 
|---|
 | 284 |  * \return distance
 | 
|---|
 | 285 |  */
 | 
|---|
| [b453f9] | 286 | double atom::DistanceToVector(const Vector &origin) const
 | 
|---|
| [4455f4] | 287 | {
 | 
|---|
| [d74077] | 288 |   return distance(origin);
 | 
|---|
| [4455f4] | 289 | };
 | 
|---|
 | 290 | 
 | 
|---|
 | 291 | /** Initialises the component number array.
 | 
|---|
 | 292 |  * Size is set to atom::ListOfBonds.size()+1 (last is th encode end by -1)
 | 
|---|
 | 293 |  */
 | 
|---|
 | 294 | void atom::InitComponentNr()
 | 
|---|
 | 295 | {
 | 
|---|
 | 296 |   if (ComponentNr != NULL)
 | 
|---|
| [920c70] | 297 |     delete[](ComponentNr);
 | 
|---|
 | 298 |   ComponentNr = new int[ListOfBonds.size()+1];
 | 
|---|
| [4455f4] | 299 |   for (int i=ListOfBonds.size()+1;i--;)
 | 
|---|
 | 300 |     ComponentNr[i] = -1;
 | 
|---|
| [14b65e] | 301 | };
 | 
|---|
 | 302 | 
 | 
|---|
 | 303 | void atom::resetGraphNr(){
 | 
|---|
 | 304 |   GraphNr=-1;
 | 
|---|
 | 305 | }
 | 
|---|
| [4455f4] | 306 | 
 | 
|---|
| [d74077] | 307 | std::ostream & atom::operator << (std::ostream &ost) const
 | 
|---|
 | 308 | {
 | 
|---|
 | 309 |   ParticleInfo::operator<<(ost);
 | 
|---|
 | 310 |   ost << "," << getPosition();
 | 
|---|
 | 311 |   return ost;
 | 
|---|
 | 312 | }
 | 
|---|
 | 313 | 
 | 
|---|
 | 314 | std::ostream & operator << (std::ostream &ost, const atom &a)
 | 
|---|
 | 315 | {
 | 
|---|
 | 316 |   a.ParticleInfo::operator<<(ost);
 | 
|---|
 | 317 |   ost << "," << a.getPosition();
 | 
|---|
 | 318 |   return ost;
 | 
|---|
 | 319 | }
 | 
|---|
| [4455f4] | 320 | 
 | 
|---|
 | 321 | bool operator < (atom &a, atom &b)
 | 
|---|
 | 322 | {
 | 
|---|
 | 323 |   return a.Compare(b);
 | 
|---|
 | 324 | };
 | 
|---|
 | 325 | 
 | 
|---|
| [46d958] | 326 | World *atom::getWorld(){
 | 
|---|
 | 327 |   return world;
 | 
|---|
 | 328 | }
 | 
|---|
 | 329 | 
 | 
|---|
 | 330 | void atom::setWorld(World* _world){
 | 
|---|
 | 331 |   world = _world;
 | 
|---|
 | 332 | }
 | 
|---|
 | 333 | 
 | 
|---|
| [88d586] | 334 | bool atom::changeId(atomId_t newId){
 | 
|---|
 | 335 |   // first we move ourselves in the world
 | 
|---|
 | 336 |   // the world lets us know if that succeeded
 | 
|---|
 | 337 |   if(world->changeAtomId(id,newId,this)){
 | 
|---|
 | 338 |     id = newId;
 | 
|---|
 | 339 |     return true;
 | 
|---|
 | 340 |   }
 | 
|---|
 | 341 |   else{
 | 
|---|
 | 342 |     return false;
 | 
|---|
 | 343 |   }
 | 
|---|
 | 344 | }
 | 
|---|
 | 345 | 
 | 
|---|
 | 346 | void atom::setId(atomId_t _id) {
 | 
|---|
| [46d958] | 347 |   id=_id;
 | 
|---|
 | 348 | }
 | 
|---|
 | 349 | 
 | 
|---|
| [ad2b411] | 350 | atomId_t atom::getId() const {
 | 
|---|
| [46d958] | 351 |   return id;
 | 
|---|
 | 352 | }
 | 
|---|
 | 353 | 
 | 
|---|
| [fa7989] | 354 | /** Makes the atom be contained in the new molecule \a *_mol.
 | 
|---|
 | 355 |  * Uses atom::removeFromMolecule() to delist from old molecule.
 | 
|---|
 | 356 |  * \param *_mol pointer to new molecule
 | 
|---|
 | 357 |  */
 | 
|---|
| [6cfa36] | 358 | void atom::setMolecule(molecule *_mol){
 | 
|---|
 | 359 |   // take this atom from the old molecule
 | 
|---|
 | 360 |   removeFromMolecule();
 | 
|---|
 | 361 |   mol = _mol;
 | 
|---|
 | 362 |   if(!mol->containsAtom(this)){
 | 
|---|
| [dddbfe] | 363 |     mol->insert(this);
 | 
|---|
| [6cfa36] | 364 |   }
 | 
|---|
 | 365 | }
 | 
|---|
 | 366 | 
 | 
|---|
| [fa7989] | 367 | /** Returns pointer to the molecule which atom belongs to.
 | 
|---|
 | 368 |  * \return containing molecule
 | 
|---|
 | 369 |  */
 | 
|---|
| [e41c48] | 370 | molecule* atom::getMolecule() const {
 | 
|---|
| [c084cc] | 371 |   return mol;
 | 
|---|
 | 372 | }
 | 
|---|
 | 373 | 
 | 
|---|
| [fa7989] | 374 | /** Erases the atom in atom::mol's list of atoms and sets it to zero.
 | 
|---|
 | 375 |  */
 | 
|---|
| [6cfa36] | 376 | void atom::removeFromMolecule(){
 | 
|---|
 | 377 |   if(mol){
 | 
|---|
 | 378 |     if(mol->containsAtom(this)){
 | 
|---|
 | 379 |       mol->erase(this);
 | 
|---|
 | 380 |     }
 | 
|---|
 | 381 |     mol=0;
 | 
|---|
 | 382 |   }
 | 
|---|
| [1f8337] | 383 | }
 | 
|---|
 | 384 | 
 | 
|---|
 | 385 | double atom::getMass() const{
 | 
|---|
 | 386 |   return getType()->getMass();
 | 
|---|
| [6cfa36] | 387 | }
 | 
|---|
| [e8a21f] | 388 | 
 | 
|---|
 | 389 | int atom::getNr() const{
 | 
|---|
 | 390 |   return nr;
 | 
|---|
 | 391 | }
 | 
|---|
| [6cfa36] | 392 | 
 | 
|---|
| [88d586] | 393 | atom* NewAtom(atomId_t _id){
 | 
|---|
 | 394 |   atom * res =new atom();
 | 
|---|
 | 395 |   res->setId(_id);
 | 
|---|
 | 396 |   return res;
 | 
|---|
| [46d958] | 397 | }
 | 
|---|
 | 398 | 
 | 
|---|
| [88d586] | 399 | void DeleteAtom(atom* atom){
 | 
|---|
| [46d958] | 400 |   delete atom;
 | 
|---|
| [e5f64de] | 401 | }
 | 
|---|
 | 402 | 
 | 
|---|
 | 403 | bool compareAtomElements(atom* atom1,atom* atom2){
 | 
|---|
 | 404 |   return atom1->getType()->getNumber() < atom2->getType()->getNumber();
 | 
|---|
| [46d958] | 405 | }
 | 
|---|