[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
|
---|
[8c6b68] | 81 | * the real functions, \sa removeTrajectorySteps(), by all necessary subclasses.
|
---|
| 82 | *
|
---|
| 83 | * \param _firststep first step in interval to be removed
|
---|
| 84 | * \param _laststep last step in interval to be removed
|
---|
[7e51e1] | 85 | */
|
---|
[8c6b68] | 86 | virtual void removeSteps(const unsigned int _firststep, const unsigned int _laststep);
|
---|
[7e51e1] | 87 |
|
---|
[1363de] | 88 | /** Output of a single atom with given numbering.
|
---|
| 89 | * \param ElementNo cardinal number of the element
|
---|
| 90 | * \param AtomNo cardinal number among these atoms of the same element
|
---|
| 91 | * \param *out stream to output to
|
---|
| 92 | * \param *comment commentary after '#' sign
|
---|
| 93 | * \return true - \a *out present, false - \a *out is NULL
|
---|
| 94 | */
|
---|
[e138de] | 95 | bool OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment = NULL) const;
|
---|
[1363de] | 96 |
|
---|
| 97 | /** Output of a single atom with numbering from array according to atom::type.
|
---|
| 98 | * \param *ElementNo cardinal number of the element
|
---|
| 99 | * \param *AtomNo cardinal number among these atoms of the same element
|
---|
| 100 | * \param *out stream to output to
|
---|
| 101 | * \param *comment commentary after '#' sign
|
---|
| 102 | * \return true - \a *out present, false - \a *out is NULL
|
---|
| 103 | */
|
---|
[0ba410] | 104 | bool OutputArrayIndexed(ostream * const out,const enumeration<const element*>&, int *AtomNo, const char *comment = NULL) const;
|
---|
[1363de] | 105 |
|
---|
| 106 | /** Initialises the component number array.
|
---|
| 107 | * Size is set to atom::ListOfBonds.size()+1 (last is th encode end by -1)
|
---|
| 108 | */
|
---|
[4455f4] | 109 | void InitComponentNr();
|
---|
[1363de] | 110 |
|
---|
| 111 | /** Resets GraphNr to -1.
|
---|
| 112 | *
|
---|
| 113 | */
|
---|
[14b65e] | 114 | void resetGraphNr();
|
---|
[681a8a] | 115 |
|
---|
[1363de] | 116 | /** Check whether father is equal to given atom.
|
---|
| 117 | * \param *ptr atom to compare father to
|
---|
| 118 | * \param **res return value (only set if atom::father is equal to \a *ptr)
|
---|
| 119 | */
|
---|
[b453f9] | 120 | void EqualsFather ( const atom *ptr, const atom **res ) const;
|
---|
[1363de] | 121 |
|
---|
| 122 | /** States whether the given \a *ptr is our father.
|
---|
| 123 | *
|
---|
| 124 | * @param ptr atom to compare atom::Father with
|
---|
| 125 | * @return true - \a *ptr is father, false - not
|
---|
| 126 | */
|
---|
[00abfc] | 127 | bool isFather(const atom *ptr);
|
---|
[1363de] | 128 |
|
---|
| 129 | /** If we are copy of copy, we are linked to be just a copy.
|
---|
| 130 | *
|
---|
| 131 | */
|
---|
[e65246] | 132 | void CorrectFather();
|
---|
[1363de] | 133 |
|
---|
| 134 | /** Climbs up the father list until NULL, last is returned.
|
---|
| 135 | * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
|
---|
| 136 | */
|
---|
[357fba] | 137 | atom *GetTrueFather();
|
---|
[1363de] | 138 |
|
---|
[59fff1] | 139 | /** Const version of \sa GetTrueFather().
|
---|
| 140 | * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
|
---|
| 141 | */
|
---|
| 142 | const atom *GetTrueFather() const;
|
---|
| 143 |
|
---|
[910a5d] | 144 | /** Const getter for the atoms father.
|
---|
| 145 | *
|
---|
| 146 | * \return father of this atom
|
---|
| 147 | */
|
---|
| 148 | atom * const getFather() const
|
---|
| 149 | { return father; }
|
---|
| 150 |
|
---|
| 151 | /** Sets the father for this atom.
|
---|
| 152 | *
|
---|
| 153 | * \param _father ptr to father atom
|
---|
| 154 | */
|
---|
| 155 | void setFather(atom * const _father);
|
---|
| 156 |
|
---|
[1363de] | 157 | /** Compares the indices of \a this atom with a given \a ptr.
|
---|
| 158 | * \param ptr atom to compare index against
|
---|
| 159 | * \return true - this one's is smaller, false - not
|
---|
| 160 | */
|
---|
[b453f9] | 161 | bool Compare(const atom &ptr) const;
|
---|
[357fba] | 162 |
|
---|
[1363de] | 163 | /** Returns distance to a given vector.
|
---|
| 164 | * \param origin vector to calculate distance to
|
---|
| 165 | * \return distance
|
---|
| 166 | */
|
---|
[b453f9] | 167 | double DistanceToVector(const Vector &origin) const;
|
---|
[1363de] | 168 |
|
---|
| 169 | /** Returns squared distance to a given vector.
|
---|
| 170 | * \param origin vector to calculate distance to
|
---|
| 171 | * \return distance squared
|
---|
| 172 | */
|
---|
[b453f9] | 173 | double DistanceSquaredToVector(const Vector &origin) const;
|
---|
[4a7776a] | 174 |
|
---|
[46d958] | 175 | // getter and setter
|
---|
| 176 |
|
---|
| 177 | /**
|
---|
| 178 | * returns the World that contains this atom.
|
---|
| 179 | * Use this if you need to get the world without locking
|
---|
| 180 | * the singleton for example.
|
---|
| 181 | *
|
---|
| 182 | */
|
---|
| 183 | World *getWorld();
|
---|
| 184 | void setWorld(World*);
|
---|
| 185 |
|
---|
[ad2b411] | 186 | virtual atomId_t getId() const;
|
---|
[88d586] | 187 | virtual bool changeId(atomId_t newId);
|
---|
| 188 |
|
---|
| 189 | /**
|
---|
| 190 | * this function sets the Id without notifying the world. Only use it, if the world has already
|
---|
| 191 | * gotten an ID for this Atom.
|
---|
| 192 | */
|
---|
| 193 | virtual void setId(atomId_t);
|
---|
| 194 |
|
---|
[1363de] | 195 | /** Returns pointer to the molecule which atom belongs to.
|
---|
| 196 | * \return containing molecule
|
---|
| 197 | */
|
---|
[270bdf] | 198 | const molecule* getMolecule() const;
|
---|
[1363de] | 199 |
|
---|
| 200 | /** Erases the atom in atom::mol's list of atoms and sets it to zero.
|
---|
| 201 | */
|
---|
[6cfa36] | 202 | void removeFromMolecule();
|
---|
| 203 |
|
---|
[560bbe] | 204 | /** Changes the molecule internal ParticleInfo::Nr of this atom.
|
---|
| 205 | *
|
---|
| 206 | * @param newNr new ParticleInfo::Nr to set
|
---|
| 207 | * @return true - change successful, false - changed not successful, id remains the old one
|
---|
| 208 | */
|
---|
| 209 | bool changeNr(int newNr);
|
---|
| 210 |
|
---|
[1363de] | 211 | /** Getter for ParticleInfo::Nr of the atom.
|
---|
| 212 | *
|
---|
| 213 | * @return index
|
---|
| 214 | */
|
---|
[e8a21f] | 215 | int getNr() const;
|
---|
[1f8337] | 216 |
|
---|
[d74077] | 217 | // Output operator
|
---|
| 218 | std::ostream & operator << (std::ostream &ost) const;
|
---|
| 219 |
|
---|
[46d958] | 220 | protected:
|
---|
[6cfa36] | 221 |
|
---|
[46d958] | 222 | /**
|
---|
| 223 | * Protected constructor to ensure construction of atoms through the world.
|
---|
| 224 | * see World::createAtom()
|
---|
| 225 | */
|
---|
| 226 | atom();
|
---|
| 227 |
|
---|
| 228 | /**
|
---|
| 229 | * Protected copy-constructor to ensure construction of atoms by cloning.
|
---|
| 230 | * see atom::clone()
|
---|
| 231 | */
|
---|
| 232 | atom(class atom *pointer);
|
---|
| 233 |
|
---|
| 234 | /**
|
---|
| 235 | * Protected destructor to ensure destruction of atoms through the world.
|
---|
| 236 | * see World::destroyAtom()
|
---|
| 237 | */
|
---|
| 238 | virtual ~atom();
|
---|
[0d9546] | 239 | private:
|
---|
| 240 | friend class molecule;
|
---|
| 241 | friend class AtomicInfo;
|
---|
| 242 | /** Makes the atom be contained in the new molecule \a *_mol.
|
---|
| 243 | * Uses atom::removeFromMolecule() to delist from old molecule.
|
---|
| 244 | * \param *_mol pointer to new molecule
|
---|
| 245 | */
|
---|
| 246 | void setMolecule(molecule*);
|
---|
| 247 |
|
---|
[b71881] | 248 | //!> grant World (only) access to selection state changers
|
---|
| 249 | friend class World;
|
---|
| 250 |
|
---|
| 251 | /** Sets the internal selection state to true.
|
---|
| 252 | *
|
---|
| 253 | */
|
---|
| 254 | void select();
|
---|
| 255 |
|
---|
| 256 | /** Unsets the internal selection state to true.
|
---|
| 257 | *
|
---|
| 258 | */
|
---|
| 259 | void unselect();
|
---|
| 260 |
|
---|
[d05088] | 261 | // virtual void update(Observable *publisher);
|
---|
| 262 | // virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
| 263 | virtual void subjectKilled(Observable *publisher);
|
---|
[0d9546] | 264 |
|
---|
[b71881] | 265 | public:
|
---|
| 266 |
|
---|
| 267 | /** Getter to internal selection status.
|
---|
| 268 | *
|
---|
| 269 | * \return true - atom is selected, false - else
|
---|
| 270 | */
|
---|
| 271 | bool getSelected() const { return selected; }
|
---|
| 272 |
|
---|
[357fba] | 273 | private:
|
---|
[6cfa36] | 274 | molecule *mol; // !< the molecule this atom belongs to
|
---|
[46d958] | 275 | World* world;
|
---|
[88d586] | 276 | atomId_t id;
|
---|
[b71881] | 277 | //!> internal state whether atom is selected or not
|
---|
| 278 | bool selected;
|
---|
[357fba] | 279 | };
|
---|
| 280 |
|
---|
[d74077] | 281 | /**
|
---|
| 282 | * Global output operator for class atom.
|
---|
| 283 | */
|
---|
| 284 | std::ostream & operator << (std::ostream &ost, const atom &_atom);
|
---|
| 285 |
|
---|
[46d958] | 286 | /**
|
---|
| 287 | * internal method used by the world. Do not use if you don't know what you are doing.
|
---|
| 288 | * You might get burned...
|
---|
| 289 | * Use World::createAtom() instead.
|
---|
| 290 | */
|
---|
[88d586] | 291 | atom* NewAtom(atomId_t _id);
|
---|
[46d958] | 292 |
|
---|
| 293 | /**
|
---|
| 294 | * internal method used by the world. Do not use if you don't know what you are doing.
|
---|
| 295 | * You might get burned...
|
---|
| 296 | * Use World::destroyAtom() instead.
|
---|
| 297 | */
|
---|
| 298 | void DeleteAtom(atom*);
|
---|
| 299 |
|
---|
[e5f64de] | 300 | /**
|
---|
| 301 | * Simple function to compare atoms by their elements to allow sorting of atoms by this criteria
|
---|
| 302 | */
|
---|
| 303 | bool compareAtomElements(atom* atom1,atom* atom2);
|
---|
| 304 |
|
---|
[46d958] | 305 |
|
---|
[357fba] | 306 | #endif /* ATOM_HPP_ */
|
---|