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