| [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"
 | 
|---|
| [6f0841] | 28 | #include "Atom/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 |   /** Initialises the component number array.
 | 
|---|
 | 88 |    * Size is set to atom::ListOfBonds.size()+1 (last is th encode end by -1)
 | 
|---|
 | 89 |    */
 | 
|---|
| [4455f4] | 90 |   void InitComponentNr();
 | 
|---|
| [1363de] | 91 | 
 | 
|---|
 | 92 |   /** Resets GraphNr to -1.
 | 
|---|
 | 93 |    *
 | 
|---|
 | 94 |    */
 | 
|---|
| [14b65e] | 95 |   void resetGraphNr();
 | 
|---|
| [681a8a] | 96 | 
 | 
|---|
| [1363de] | 97 |   /** Check whether father is equal to given atom.
 | 
|---|
 | 98 |    * \param *ptr atom to compare father to
 | 
|---|
 | 99 |    * \param **res return value (only set if atom::father is equal to \a *ptr)
 | 
|---|
 | 100 |    */
 | 
|---|
| [b453f9] | 101 |   void EqualsFather ( const atom *ptr, const atom **res ) const;
 | 
|---|
| [1363de] | 102 | 
 | 
|---|
 | 103 |   /** States whether the given \a *ptr is our father.
 | 
|---|
 | 104 |    *
 | 
|---|
 | 105 |    * @param ptr atom to compare atom::Father with
 | 
|---|
 | 106 |    * @return true - \a *ptr is father, false - not
 | 
|---|
 | 107 |    */
 | 
|---|
| [00abfc] | 108 |   bool isFather(const atom *ptr);
 | 
|---|
| [1363de] | 109 | 
 | 
|---|
 | 110 |   /** If we are copy of copy, we are linked to be just a copy.
 | 
|---|
 | 111 |    *
 | 
|---|
 | 112 |    */
 | 
|---|
| [e65246] | 113 |   void CorrectFather();
 | 
|---|
| [1363de] | 114 | 
 | 
|---|
 | 115 |   /** Climbs up the father list until NULL, last is returned.
 | 
|---|
 | 116 |    * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
 | 
|---|
 | 117 |    */
 | 
|---|
| [357fba] | 118 |   atom *GetTrueFather();
 | 
|---|
| [1363de] | 119 | 
 | 
|---|
| [59fff1] | 120 |   /** Const version of \sa GetTrueFather().
 | 
|---|
 | 121 |    * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
 | 
|---|
 | 122 |    */
 | 
|---|
 | 123 |   const atom *GetTrueFather() const;
 | 
|---|
 | 124 | 
 | 
|---|
| [1363de] | 125 |   /** Compares the indices of \a this atom with a given \a ptr.
 | 
|---|
 | 126 |    * \param ptr atom to compare index against
 | 
|---|
 | 127 |    * \return true - this one's is smaller, false - not
 | 
|---|
 | 128 |    */
 | 
|---|
| [b453f9] | 129 |   bool Compare(const atom &ptr) const;
 | 
|---|
| [357fba] | 130 | 
 | 
|---|
| [1363de] | 131 |   /** Returns distance to a given vector.
 | 
|---|
 | 132 |    * \param origin vector to calculate distance to
 | 
|---|
 | 133 |    * \return distance
 | 
|---|
 | 134 |    */
 | 
|---|
| [b453f9] | 135 |   double DistanceToVector(const Vector &origin) const;
 | 
|---|
| [1363de] | 136 | 
 | 
|---|
 | 137 |   /** Returns squared distance to a given vector.
 | 
|---|
 | 138 |    * \param origin vector to calculate distance to
 | 
|---|
 | 139 |    * \return distance squared
 | 
|---|
 | 140 |    */
 | 
|---|
| [b453f9] | 141 |   double DistanceSquaredToVector(const Vector &origin) const;
 | 
|---|
| [1363de] | 142 |   /** Checks whether atom is within the given box.
 | 
|---|
 | 143 |    * \param offset offset to box origin
 | 
|---|
 | 144 |    * \param *parallelepiped box matrix
 | 
|---|
 | 145 |    * \return true - is inside, false - is not
 | 
|---|
 | 146 |    */
 | 
|---|
| [c550dd] | 147 |   bool IsInShape(const Shape&) const;
 | 
|---|
| [4a7776a] | 148 | 
 | 
|---|
| [46d958] | 149 |   // getter and setter
 | 
|---|
 | 150 | 
 | 
|---|
 | 151 |   /**
 | 
|---|
 | 152 |    * returns the World that contains this atom.
 | 
|---|
 | 153 |    * Use this if you need to get the world without locking
 | 
|---|
 | 154 |    * the singleton for example.
 | 
|---|
 | 155 |    *
 | 
|---|
 | 156 |    */
 | 
|---|
 | 157 |   World *getWorld();
 | 
|---|
 | 158 |   void setWorld(World*);
 | 
|---|
 | 159 | 
 | 
|---|
| [ad2b411] | 160 |   virtual atomId_t getId() const;
 | 
|---|
| [88d586] | 161 |   virtual bool changeId(atomId_t newId);
 | 
|---|
 | 162 | 
 | 
|---|
 | 163 |   /**
 | 
|---|
 | 164 |    * this function sets the Id without notifying the world. Only use it, if the world has already
 | 
|---|
 | 165 |    * gotten an ID for this Atom.
 | 
|---|
 | 166 |    */
 | 
|---|
 | 167 |    virtual void setId(atomId_t);
 | 
|---|
 | 168 | 
 | 
|---|
| [1363de] | 169 |    /** Returns pointer to the molecule which atom belongs to.
 | 
|---|
 | 170 |     * \return containing molecule
 | 
|---|
 | 171 |     */
 | 
|---|
| [e41c48] | 172 |    molecule* getMolecule() const;
 | 
|---|
| [1363de] | 173 | 
 | 
|---|
 | 174 |    /** Erases the atom in atom::mol's list of atoms and sets it to zero.
 | 
|---|
 | 175 |     */
 | 
|---|
| [6cfa36] | 176 |    void removeFromMolecule();
 | 
|---|
 | 177 | 
 | 
|---|
| [560bbe] | 178 |    /** Changes the molecule internal ParticleInfo::Nr of this atom.
 | 
|---|
 | 179 |     *
 | 
|---|
 | 180 |     * @param newNr new ParticleInfo::Nr to set
 | 
|---|
 | 181 |     * @return true - change successful, false - changed not successful, id remains the old one
 | 
|---|
 | 182 |     */
 | 
|---|
 | 183 |    bool changeNr(int newNr);
 | 
|---|
 | 184 | 
 | 
|---|
| [1363de] | 185 |    /** Getter for ParticleInfo::Nr of the atom.
 | 
|---|
 | 186 |     *
 | 
|---|
 | 187 |     * @return index
 | 
|---|
 | 188 |     */
 | 
|---|
| [e8a21f] | 189 |    int getNr() const;
 | 
|---|
| [1f8337] | 190 | 
 | 
|---|
| [d74077] | 191 |    // Output operator
 | 
|---|
 | 192 |    std::ostream & operator << (std::ostream &ost) const;
 | 
|---|
 | 193 | 
 | 
|---|
| [46d958] | 194 |   protected:
 | 
|---|
| [6cfa36] | 195 | 
 | 
|---|
| [46d958] | 196 |     /**
 | 
|---|
 | 197 |      * Protected constructor to ensure construction of atoms through the world.
 | 
|---|
 | 198 |      * see World::createAtom()
 | 
|---|
 | 199 |      */
 | 
|---|
 | 200 |     atom();
 | 
|---|
 | 201 | 
 | 
|---|
 | 202 |     /**
 | 
|---|
 | 203 |      * Protected copy-constructor to ensure construction of atoms by cloning.
 | 
|---|
 | 204 |      * see atom::clone()
 | 
|---|
 | 205 |      */
 | 
|---|
 | 206 |     atom(class atom *pointer);
 | 
|---|
 | 207 | 
 | 
|---|
 | 208 |     /**
 | 
|---|
 | 209 |      * Protected destructor to ensure destruction of atoms through the world.
 | 
|---|
 | 210 |      * see World::destroyAtom()
 | 
|---|
 | 211 |      */
 | 
|---|
 | 212 |     virtual ~atom();
 | 
|---|
| [0d9546] | 213 |   private:
 | 
|---|
 | 214 |     friend class molecule;
 | 
|---|
 | 215 |     friend class AtomicInfo;
 | 
|---|
 | 216 |     /** Makes the atom be contained in the new molecule \a *_mol.
 | 
|---|
 | 217 |      * Uses atom::removeFromMolecule() to delist from old molecule.
 | 
|---|
 | 218 |      * \param *_mol pointer to new molecule
 | 
|---|
 | 219 |      */
 | 
|---|
 | 220 |     void setMolecule(molecule*);
 | 
|---|
 | 221 | 
 | 
|---|
 | 222 |     /** Makes the atom be contained in the no molecule.
 | 
|---|
 | 223 |      * Use atom::removeFromMolecule() to delist from old molecule,
 | 
|---|
 | 224 |      * this assume that the molecule already knows about it.
 | 
|---|
 | 225 |      */
 | 
|---|
 | 226 |     void unsetMolecule();
 | 
|---|
 | 227 | 
 | 
|---|
 | 228 | 
 | 
|---|
| [357fba] | 229 |   private:
 | 
|---|
| [6cfa36] | 230 |     molecule *mol; // !< the molecule this atom belongs to
 | 
|---|
| [46d958] | 231 |     World* world;
 | 
|---|
| [88d586] | 232 |     atomId_t id;
 | 
|---|
| [357fba] | 233 | };
 | 
|---|
 | 234 | 
 | 
|---|
| [d74077] | 235 | /**
 | 
|---|
 | 236 |  * Global output operator for class atom.
 | 
|---|
 | 237 |  */
 | 
|---|
 | 238 | std::ostream & operator << (std::ostream &ost, const atom &_atom);
 | 
|---|
 | 239 | 
 | 
|---|
| [46d958] | 240 | /**
 | 
|---|
 | 241 |  * internal method used by the world. Do not use if you don't know what you are doing.
 | 
|---|
 | 242 |  * You might get burned...
 | 
|---|
 | 243 |  * Use World::createAtom() instead.
 | 
|---|
 | 244 |  */
 | 
|---|
| [88d586] | 245 | atom* NewAtom(atomId_t _id);
 | 
|---|
| [46d958] | 246 | 
 | 
|---|
 | 247 | /**
 | 
|---|
 | 248 | * internal method used by the world. Do not use if you don't know what you are doing.
 | 
|---|
 | 249 |  * You might get burned...
 | 
|---|
 | 250 |  * Use World::destroyAtom() instead.
 | 
|---|
 | 251 |  */
 | 
|---|
 | 252 | void  DeleteAtom(atom*);
 | 
|---|
 | 253 | 
 | 
|---|
| [e5f64de] | 254 | /**
 | 
|---|
 | 255 |  * Simple function to compare atoms by their elements to allow sorting of atoms by this criteria
 | 
|---|
 | 256 |  */
 | 
|---|
 | 257 | bool compareAtomElements(atom* atom1,atom* atom2);
 | 
|---|
 | 258 | 
 | 
|---|
| [46d958] | 259 | 
 | 
|---|
| [357fba] | 260 | #endif /* ATOM_HPP_ */
 | 
|---|