| [357fba] | 1 | /* | 
|---|
|  | 2 | * atom.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Aug 3, 2009 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef ATOM_HPP_ | 
|---|
|  | 9 | #define ATOM_HPP_ | 
|---|
|  | 10 |  | 
|---|
|  | 11 | using namespace std; | 
|---|
|  | 12 |  | 
|---|
| [f66195] | 13 | /*********************************************** includes ***********************************/ | 
|---|
|  | 14 |  | 
|---|
| [cd4ccc] | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
| [986ed3] | 20 | #include <iosfwd> | 
|---|
| [266237] | 21 | #include <list> | 
|---|
| [fcd7b6] | 22 | #include <vector> | 
|---|
| [cd4ccc] | 23 |  | 
|---|
| [6b919f8] | 24 | #include "atom_atominfo.hpp" | 
|---|
|  | 25 | #include "atom_bondedparticle.hpp" | 
|---|
|  | 26 | #include "atom_graphnode.hpp" | 
|---|
|  | 27 | #include "atom_particleinfo.hpp" | 
|---|
| [d74077] | 28 | #include "TesselPoint.hpp" | 
|---|
| [ead4e6] | 29 | #include "types.hpp" | 
|---|
| [f66195] | 30 |  | 
|---|
| [ad011c] | 31 | #include "CodePatterns/enumeration.hpp" | 
|---|
| [a0064e] | 32 |  | 
|---|
| [f66195] | 33 | /****************************************** forward declarations *****************************/ | 
|---|
| [357fba] | 34 |  | 
|---|
| [0d9546] | 35 | class AtomicInfo; | 
|---|
| [f66195] | 36 | class Vector; | 
|---|
| [46d958] | 37 | class World; | 
|---|
| [6cfa36] | 38 | class molecule; | 
|---|
| [c550dd] | 39 | class Shape; | 
|---|
| [f66195] | 40 |  | 
|---|
|  | 41 | /********************************************** declarations *******************************/ | 
|---|
| [e41951] | 42 |  | 
|---|
| [357fba] | 43 | /** Single atom. | 
|---|
|  | 44 | * Class incorporates position, type | 
|---|
|  | 45 | */ | 
|---|
| [6625c3] | 46 | class atom : public GraphNode, public BondedParticle, public TesselPoint { | 
|---|
| [88d586] | 47 | friend atom* NewAtom(atomId_t); | 
|---|
| [46d958] | 48 | friend void  DeleteAtom(atom*); | 
|---|
| [1363de] | 49 | public: | 
|---|
| [357fba] | 50 | atom *father;   //!< In many-body bond order fragmentations points to originating atom | 
|---|
|  | 51 | int *sort;      //!< sort criteria | 
|---|
|  | 52 |  | 
|---|
| [1363de] | 53 | /** Clones this atom. | 
|---|
|  | 54 | * | 
|---|
|  | 55 | * Does not clone the bonds! | 
|---|
|  | 56 | * | 
|---|
|  | 57 | * @return reference to atom | 
|---|
|  | 58 | */ | 
|---|
| [46d958] | 59 | virtual atom *clone(); | 
|---|
| [357fba] | 60 |  | 
|---|
| [e2373df] | 61 | /** Pushes back another step in all trajectory vectors. | 
|---|
|  | 62 | * | 
|---|
|  | 63 | * This allows to extend all trajectories contained in different classes | 
|---|
|  | 64 | * consistently. This is implemented by the topmost class which calls the | 
|---|
|  | 65 | * real functions, \sa AppendTrajectoryStep(), by all necessary subclasses. | 
|---|
|  | 66 | */ | 
|---|
|  | 67 | virtual void UpdateSteps(); | 
|---|
|  | 68 |  | 
|---|
| [1363de] | 69 | /** Output of a single atom with given numbering. | 
|---|
|  | 70 | * \param ElementNo cardinal number of the element | 
|---|
|  | 71 | * \param AtomNo cardinal number among these atoms of the same element | 
|---|
|  | 72 | * \param *out stream to output to | 
|---|
|  | 73 | * \param *comment commentary after '#' sign | 
|---|
|  | 74 | * \return true - \a *out present, false - \a *out is NULL | 
|---|
|  | 75 | */ | 
|---|
| [e138de] | 76 | bool OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment = NULL) const; | 
|---|
| [1363de] | 77 |  | 
|---|
|  | 78 | /** Output of a single atom with numbering from array according to atom::type. | 
|---|
|  | 79 | * \param *ElementNo cardinal number of the element | 
|---|
|  | 80 | * \param *AtomNo cardinal number among these atoms of the same element | 
|---|
|  | 81 | * \param *out stream to output to | 
|---|
|  | 82 | * \param *comment commentary after '#' sign | 
|---|
|  | 83 | * \return true - \a *out present, false - \a *out is NULL | 
|---|
|  | 84 | */ | 
|---|
| [0ba410] | 85 | bool OutputArrayIndexed(ostream * const out,const enumeration<const element*>&, int *AtomNo, const char *comment = NULL) const; | 
|---|
| [1363de] | 86 |  | 
|---|
|  | 87 | /** Output of a single atom as one line in xyz file. | 
|---|
|  | 88 | * \param *out stream to output to | 
|---|
|  | 89 | * \return true - \a *out present, false - \a *out is NULL | 
|---|
|  | 90 | */ | 
|---|
| [357fba] | 91 | bool OutputXYZLine(ofstream *out) const; | 
|---|
| [1363de] | 92 |  | 
|---|
|  | 93 | /** Output of a single atom as one line in xyz file. | 
|---|
|  | 94 | * \param *out stream to output to | 
|---|
|  | 95 | * \param *ElementNo array with ion type number in the config file this atom's element shall have | 
|---|
|  | 96 | * \param *AtomNo array with atom number in the config file this atom shall have, is increase by one automatically | 
|---|
|  | 97 | * \param step Trajectory time step to output | 
|---|
|  | 98 | * \return true - \a *out present, false - \a *out is NULL | 
|---|
|  | 99 | */ | 
|---|
| [882a8a] | 100 | bool OutputTrajectory(ofstream * const out, const enumeration<const element*>&, int *AtomNo, const int step) const; | 
|---|
| [1363de] | 101 |  | 
|---|
|  | 102 | /** Output of a single atom as one lin in xyz file. | 
|---|
|  | 103 | * \param *out stream to output to | 
|---|
|  | 104 | * \param step Trajectory time step to output | 
|---|
|  | 105 | * \return true - \a *out present, false - \a *out is NULL | 
|---|
|  | 106 | */ | 
|---|
| [e138de] | 107 | bool OutputTrajectoryXYZ(ofstream * const out, const int step) const; | 
|---|
| [1363de] | 108 |  | 
|---|
|  | 109 | /** Outputs the MPQC configuration line for this atom. | 
|---|
|  | 110 | * \param *out output stream | 
|---|
|  | 111 | * \param *center center of molecule subtracted from position | 
|---|
|  | 112 | * \param *AtomNo pointer to atom counter that is increased by one | 
|---|
|  | 113 | */ | 
|---|
| [0dc86e2] | 114 | void OutputMPQCLine(ostream * const out, const Vector *center) const; | 
|---|
| [266237] | 115 |  | 
|---|
| [1363de] | 116 | /** Initialises the component number array. | 
|---|
|  | 117 | * Size is set to atom::ListOfBonds.size()+1 (last is th encode end by -1) | 
|---|
|  | 118 | */ | 
|---|
| [4455f4] | 119 | void InitComponentNr(); | 
|---|
| [1363de] | 120 |  | 
|---|
|  | 121 | /** Resets GraphNr to -1. | 
|---|
|  | 122 | * | 
|---|
|  | 123 | */ | 
|---|
| [14b65e] | 124 | void resetGraphNr(); | 
|---|
| [681a8a] | 125 |  | 
|---|
| [1363de] | 126 | /** Check whether father is equal to given atom. | 
|---|
|  | 127 | * \param *ptr atom to compare father to | 
|---|
|  | 128 | * \param **res return value (only set if atom::father is equal to \a *ptr) | 
|---|
|  | 129 | */ | 
|---|
| [b453f9] | 130 | void EqualsFather ( const atom *ptr, const atom **res ) const; | 
|---|
| [1363de] | 131 |  | 
|---|
|  | 132 | /** States whether the given \a *ptr is our father. | 
|---|
|  | 133 | * | 
|---|
|  | 134 | * @param ptr atom to compare atom::Father with | 
|---|
|  | 135 | * @return true - \a *ptr is father, false - not | 
|---|
|  | 136 | */ | 
|---|
| [00abfc] | 137 | bool isFather(const atom *ptr); | 
|---|
| [1363de] | 138 |  | 
|---|
|  | 139 | /** If we are copy of copy, we are linked to be just a copy. | 
|---|
|  | 140 | * | 
|---|
|  | 141 | */ | 
|---|
| [e65246] | 142 | void CorrectFather(); | 
|---|
| [1363de] | 143 |  | 
|---|
|  | 144 | /** Climbs up the father list until NULL, last is returned. | 
|---|
|  | 145 | * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen) | 
|---|
|  | 146 | */ | 
|---|
| [357fba] | 147 | atom *GetTrueFather(); | 
|---|
| [1363de] | 148 |  | 
|---|
|  | 149 | /** Compares the indices of \a this atom with a given \a ptr. | 
|---|
|  | 150 | * \param ptr atom to compare index against | 
|---|
|  | 151 | * \return true - this one's is smaller, false - not | 
|---|
|  | 152 | */ | 
|---|
| [b453f9] | 153 | bool Compare(const atom &ptr) const; | 
|---|
| [357fba] | 154 |  | 
|---|
| [1363de] | 155 | /** Returns distance to a given vector. | 
|---|
|  | 156 | * \param origin vector to calculate distance to | 
|---|
|  | 157 | * \return distance | 
|---|
|  | 158 | */ | 
|---|
| [b453f9] | 159 | double DistanceToVector(const Vector &origin) const; | 
|---|
| [1363de] | 160 |  | 
|---|
|  | 161 | /** Returns squared distance to a given vector. | 
|---|
|  | 162 | * \param origin vector to calculate distance to | 
|---|
|  | 163 | * \return distance squared | 
|---|
|  | 164 | */ | 
|---|
| [b453f9] | 165 | double DistanceSquaredToVector(const Vector &origin) const; | 
|---|
| [1363de] | 166 | /** Checks whether atom is within the given box. | 
|---|
|  | 167 | * \param offset offset to box origin | 
|---|
|  | 168 | * \param *parallelepiped box matrix | 
|---|
|  | 169 | * \return true - is inside, false - is not | 
|---|
|  | 170 | */ | 
|---|
| [c550dd] | 171 | bool IsInShape(const Shape&) const; | 
|---|
| [4a7776a] | 172 |  | 
|---|
| [46d958] | 173 | // getter and setter | 
|---|
|  | 174 |  | 
|---|
|  | 175 | /** | 
|---|
|  | 176 | * returns the World that contains this atom. | 
|---|
|  | 177 | * Use this if you need to get the world without locking | 
|---|
|  | 178 | * the singleton for example. | 
|---|
|  | 179 | * | 
|---|
|  | 180 | */ | 
|---|
|  | 181 | World *getWorld(); | 
|---|
|  | 182 | void setWorld(World*); | 
|---|
|  | 183 |  | 
|---|
| [ad2b411] | 184 | virtual atomId_t getId() const; | 
|---|
| [88d586] | 185 | virtual bool changeId(atomId_t newId); | 
|---|
|  | 186 |  | 
|---|
|  | 187 | /** | 
|---|
|  | 188 | * this function sets the Id without notifying the world. Only use it, if the world has already | 
|---|
|  | 189 | * gotten an ID for this Atom. | 
|---|
|  | 190 | */ | 
|---|
|  | 191 | virtual void setId(atomId_t); | 
|---|
|  | 192 |  | 
|---|
| [1363de] | 193 | /** Returns pointer to the molecule which atom belongs to. | 
|---|
|  | 194 | * \return containing molecule | 
|---|
|  | 195 | */ | 
|---|
| [e41c48] | 196 | molecule* getMolecule() const; | 
|---|
| [1363de] | 197 |  | 
|---|
|  | 198 | /** Erases the atom in atom::mol's list of atoms and sets it to zero. | 
|---|
|  | 199 | */ | 
|---|
| [6cfa36] | 200 | void removeFromMolecule(); | 
|---|
|  | 201 |  | 
|---|
| [1363de] | 202 | /** Getter for ParticleInfo::Nr of the atom. | 
|---|
|  | 203 | * | 
|---|
|  | 204 | * @return index | 
|---|
|  | 205 | */ | 
|---|
| [e8a21f] | 206 | int getNr() const; | 
|---|
| [1f8337] | 207 |  | 
|---|
| [d74077] | 208 | // Output operator | 
|---|
|  | 209 | std::ostream & operator << (std::ostream &ost) const; | 
|---|
|  | 210 |  | 
|---|
| [46d958] | 211 | protected: | 
|---|
| [6cfa36] | 212 |  | 
|---|
| [46d958] | 213 | /** | 
|---|
|  | 214 | * Protected constructor to ensure construction of atoms through the world. | 
|---|
|  | 215 | * see World::createAtom() | 
|---|
|  | 216 | */ | 
|---|
|  | 217 | atom(); | 
|---|
|  | 218 |  | 
|---|
|  | 219 | /** | 
|---|
|  | 220 | * Protected copy-constructor to ensure construction of atoms by cloning. | 
|---|
|  | 221 | * see atom::clone() | 
|---|
|  | 222 | */ | 
|---|
|  | 223 | atom(class atom *pointer); | 
|---|
|  | 224 |  | 
|---|
|  | 225 | /** | 
|---|
|  | 226 | * Protected destructor to ensure destruction of atoms through the world. | 
|---|
|  | 227 | * see World::destroyAtom() | 
|---|
|  | 228 | */ | 
|---|
|  | 229 | virtual ~atom(); | 
|---|
| [0d9546] | 230 | private: | 
|---|
|  | 231 | friend class molecule; | 
|---|
|  | 232 | friend class AtomicInfo; | 
|---|
|  | 233 | /** Makes the atom be contained in the new molecule \a *_mol. | 
|---|
|  | 234 | * Uses atom::removeFromMolecule() to delist from old molecule. | 
|---|
|  | 235 | * \param *_mol pointer to new molecule | 
|---|
|  | 236 | */ | 
|---|
|  | 237 | void setMolecule(molecule*); | 
|---|
|  | 238 |  | 
|---|
|  | 239 | /** Makes the atom be contained in the no molecule. | 
|---|
|  | 240 | * Use atom::removeFromMolecule() to delist from old molecule, | 
|---|
|  | 241 | * this assume that the molecule already knows about it. | 
|---|
|  | 242 | */ | 
|---|
|  | 243 | void unsetMolecule(); | 
|---|
|  | 244 |  | 
|---|
|  | 245 |  | 
|---|
| [357fba] | 246 | private: | 
|---|
| [6cfa36] | 247 | molecule *mol; // !< the molecule this atom belongs to | 
|---|
| [46d958] | 248 | World* world; | 
|---|
| [88d586] | 249 | atomId_t id; | 
|---|
| [357fba] | 250 | }; | 
|---|
|  | 251 |  | 
|---|
| [d74077] | 252 | /** | 
|---|
|  | 253 | * Global output operator for class atom. | 
|---|
|  | 254 | */ | 
|---|
|  | 255 | std::ostream & operator << (std::ostream &ost, const atom &_atom); | 
|---|
|  | 256 |  | 
|---|
| [46d958] | 257 | /** | 
|---|
|  | 258 | * internal method used by the world. Do not use if you don't know what you are doing. | 
|---|
|  | 259 | * You might get burned... | 
|---|
|  | 260 | * Use World::createAtom() instead. | 
|---|
|  | 261 | */ | 
|---|
| [88d586] | 262 | atom* NewAtom(atomId_t _id); | 
|---|
| [46d958] | 263 |  | 
|---|
|  | 264 | /** | 
|---|
|  | 265 | * internal method used by the world. Do not use if you don't know what you are doing. | 
|---|
|  | 266 | * You might get burned... | 
|---|
|  | 267 | * Use World::destroyAtom() instead. | 
|---|
|  | 268 | */ | 
|---|
|  | 269 | void  DeleteAtom(atom*); | 
|---|
|  | 270 |  | 
|---|
| [e5f64de] | 271 | /** | 
|---|
|  | 272 | * Simple function to compare atoms by their elements to allow sorting of atoms by this criteria | 
|---|
|  | 273 | */ | 
|---|
|  | 274 | bool compareAtomElements(atom* atom1,atom* atom2); | 
|---|
|  | 275 |  | 
|---|
| [46d958] | 276 |  | 
|---|
| [357fba] | 277 | #endif /* ATOM_HPP_ */ | 
|---|