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