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