| 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 UpdateSteps();
|
|---|
| 68 |
|
|---|
| 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 | */
|
|---|
| 76 | bool OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment = NULL) const;
|
|---|
| 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 | */
|
|---|
| 85 | bool OutputArrayIndexed(ostream * const out,const enumeration<const element*>&, int *AtomNo, const char *comment = NULL) const;
|
|---|
| 86 |
|
|---|
| 87 | /** Output of a single atom as one line in xyz file.
|
|---|
| 88 | * \param *out stream to output to
|
|---|
| 89 | * \return true - \a *out present, false - \a *out is NULL
|
|---|
| 90 | */
|
|---|
| 91 | bool OutputXYZLine(ofstream *out) const;
|
|---|
| 92 |
|
|---|
| 93 | /** Output of a single atom as one line in xyz file.
|
|---|
| 94 | * \param *out stream to output to
|
|---|
| 95 | * \param *ElementNo array with ion type number in the config file this atom's element shall have
|
|---|
| 96 | * \param *AtomNo array with atom number in the config file this atom shall have, is increase by one automatically
|
|---|
| 97 | * \param step Trajectory time step to output
|
|---|
| 98 | * \return true - \a *out present, false - \a *out is NULL
|
|---|
| 99 | */
|
|---|
| 100 | bool OutputTrajectory(ofstream * const out, const enumeration<const element*>&, int *AtomNo, const int step) const;
|
|---|
| 101 |
|
|---|
| 102 | /** Output of a single atom as one lin in xyz file.
|
|---|
| 103 | * \param *out stream to output to
|
|---|
| 104 | * \param step Trajectory time step to output
|
|---|
| 105 | * \return true - \a *out present, false - \a *out is NULL
|
|---|
| 106 | */
|
|---|
| 107 | bool OutputTrajectoryXYZ(ofstream * const out, const int step) const;
|
|---|
| 108 |
|
|---|
| 109 | /** Outputs the MPQC configuration line for this atom.
|
|---|
| 110 | * \param *out output stream
|
|---|
| 111 | * \param *center center of molecule subtracted from position
|
|---|
| 112 | * \param *AtomNo pointer to atom counter that is increased by one
|
|---|
| 113 | */
|
|---|
| 114 | void OutputMPQCLine(ostream * const out, const Vector *center) const;
|
|---|
| 115 |
|
|---|
| 116 | /** Outputs the Psi3 configuration line for this atom.
|
|---|
| 117 | * \param *out output stream
|
|---|
| 118 | * \param *center center of molecule subtracted from position
|
|---|
| 119 | * \param *AtomNo pointer to atom counter that is increased by one
|
|---|
| 120 | */
|
|---|
| 121 | void OutputPsi3Line(ostream * const out, const Vector *center) const;
|
|---|
| 122 |
|
|---|
| 123 | /** Initialises the component number array.
|
|---|
| 124 | * Size is set to atom::ListOfBonds.size()+1 (last is th encode end by -1)
|
|---|
| 125 | */
|
|---|
| 126 | void InitComponentNr();
|
|---|
| 127 |
|
|---|
| 128 | /** Resets GraphNr to -1.
|
|---|
| 129 | *
|
|---|
| 130 | */
|
|---|
| 131 | void resetGraphNr();
|
|---|
| 132 |
|
|---|
| 133 | /** Check whether father is equal to given atom.
|
|---|
| 134 | * \param *ptr atom to compare father to
|
|---|
| 135 | * \param **res return value (only set if atom::father is equal to \a *ptr)
|
|---|
| 136 | */
|
|---|
| 137 | void EqualsFather ( const atom *ptr, const atom **res ) const;
|
|---|
| 138 |
|
|---|
| 139 | /** States whether the given \a *ptr is our father.
|
|---|
| 140 | *
|
|---|
| 141 | * @param ptr atom to compare atom::Father with
|
|---|
| 142 | * @return true - \a *ptr is father, false - not
|
|---|
| 143 | */
|
|---|
| 144 | bool isFather(const atom *ptr);
|
|---|
| 145 |
|
|---|
| 146 | /** If we are copy of copy, we are linked to be just a copy.
|
|---|
| 147 | *
|
|---|
| 148 | */
|
|---|
| 149 | void CorrectFather();
|
|---|
| 150 |
|
|---|
| 151 | /** Climbs up the father list until NULL, last is returned.
|
|---|
| 152 | * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
|
|---|
| 153 | */
|
|---|
| 154 | atom *GetTrueFather();
|
|---|
| 155 |
|
|---|
| 156 | /** Const version of \sa GetTrueFather().
|
|---|
| 157 | * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
|
|---|
| 158 | */
|
|---|
| 159 | const atom *GetTrueFather() const;
|
|---|
| 160 |
|
|---|
| 161 | /** Compares the indices of \a this atom with a given \a ptr.
|
|---|
| 162 | * \param ptr atom to compare index against
|
|---|
| 163 | * \return true - this one's is smaller, false - not
|
|---|
| 164 | */
|
|---|
| 165 | bool Compare(const atom &ptr) const;
|
|---|
| 166 |
|
|---|
| 167 | /** Returns distance to a given vector.
|
|---|
| 168 | * \param origin vector to calculate distance to
|
|---|
| 169 | * \return distance
|
|---|
| 170 | */
|
|---|
| 171 | double DistanceToVector(const Vector &origin) const;
|
|---|
| 172 |
|
|---|
| 173 | /** Returns squared distance to a given vector.
|
|---|
| 174 | * \param origin vector to calculate distance to
|
|---|
| 175 | * \return distance squared
|
|---|
| 176 | */
|
|---|
| 177 | double DistanceSquaredToVector(const Vector &origin) const;
|
|---|
| 178 | /** Checks whether atom is within the given box.
|
|---|
| 179 | * \param offset offset to box origin
|
|---|
| 180 | * \param *parallelepiped box matrix
|
|---|
| 181 | * \return true - is inside, false - is not
|
|---|
| 182 | */
|
|---|
| 183 | bool IsInShape(const Shape&) const;
|
|---|
| 184 |
|
|---|
| 185 | // getter and setter
|
|---|
| 186 |
|
|---|
| 187 | /**
|
|---|
| 188 | * returns the World that contains this atom.
|
|---|
| 189 | * Use this if you need to get the world without locking
|
|---|
| 190 | * the singleton for example.
|
|---|
| 191 | *
|
|---|
| 192 | */
|
|---|
| 193 | World *getWorld();
|
|---|
| 194 | void setWorld(World*);
|
|---|
| 195 |
|
|---|
| 196 | virtual atomId_t getId() const;
|
|---|
| 197 | virtual bool changeId(atomId_t newId);
|
|---|
| 198 |
|
|---|
| 199 | /**
|
|---|
| 200 | * this function sets the Id without notifying the world. Only use it, if the world has already
|
|---|
| 201 | * gotten an ID for this Atom.
|
|---|
| 202 | */
|
|---|
| 203 | virtual void setId(atomId_t);
|
|---|
| 204 |
|
|---|
| 205 | /** Returns pointer to the molecule which atom belongs to.
|
|---|
| 206 | * \return containing molecule
|
|---|
| 207 | */
|
|---|
| 208 | molecule* getMolecule() const;
|
|---|
| 209 |
|
|---|
| 210 | /** Erases the atom in atom::mol's list of atoms and sets it to zero.
|
|---|
| 211 | */
|
|---|
| 212 | void removeFromMolecule();
|
|---|
| 213 |
|
|---|
| 214 | /** Getter for ParticleInfo::Nr of the atom.
|
|---|
| 215 | *
|
|---|
| 216 | * @return index
|
|---|
| 217 | */
|
|---|
| 218 | int getNr() const;
|
|---|
| 219 |
|
|---|
| 220 | // Output operator
|
|---|
| 221 | std::ostream & operator << (std::ostream &ost) const;
|
|---|
| 222 |
|
|---|
| 223 | protected:
|
|---|
| 224 |
|
|---|
| 225 | /**
|
|---|
| 226 | * Protected constructor to ensure construction of atoms through the world.
|
|---|
| 227 | * see World::createAtom()
|
|---|
| 228 | */
|
|---|
| 229 | atom();
|
|---|
| 230 |
|
|---|
| 231 | /**
|
|---|
| 232 | * Protected copy-constructor to ensure construction of atoms by cloning.
|
|---|
| 233 | * see atom::clone()
|
|---|
| 234 | */
|
|---|
| 235 | atom(class atom *pointer);
|
|---|
| 236 |
|
|---|
| 237 | /**
|
|---|
| 238 | * Protected destructor to ensure destruction of atoms through the world.
|
|---|
| 239 | * see World::destroyAtom()
|
|---|
| 240 | */
|
|---|
| 241 | virtual ~atom();
|
|---|
| 242 | private:
|
|---|
| 243 | friend class molecule;
|
|---|
| 244 | friend class AtomicInfo;
|
|---|
| 245 | /** Makes the atom be contained in the new molecule \a *_mol.
|
|---|
| 246 | * Uses atom::removeFromMolecule() to delist from old molecule.
|
|---|
| 247 | * \param *_mol pointer to new molecule
|
|---|
| 248 | */
|
|---|
| 249 | void setMolecule(molecule*);
|
|---|
| 250 |
|
|---|
| 251 | /** Makes the atom be contained in the no molecule.
|
|---|
| 252 | * Use atom::removeFromMolecule() to delist from old molecule,
|
|---|
| 253 | * this assume that the molecule already knows about it.
|
|---|
| 254 | */
|
|---|
| 255 | void unsetMolecule();
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 | private:
|
|---|
| 259 | molecule *mol; // !< the molecule this atom belongs to
|
|---|
| 260 | World* world;
|
|---|
| 261 | atomId_t id;
|
|---|
| 262 | };
|
|---|
| 263 |
|
|---|
| 264 | /**
|
|---|
| 265 | * Global output operator for class atom.
|
|---|
| 266 | */
|
|---|
| 267 | std::ostream & operator << (std::ostream &ost, const atom &_atom);
|
|---|
| 268 |
|
|---|
| 269 | /**
|
|---|
| 270 | * internal method used by the world. Do not use if you don't know what you are doing.
|
|---|
| 271 | * You might get burned...
|
|---|
| 272 | * Use World::createAtom() instead.
|
|---|
| 273 | */
|
|---|
| 274 | atom* NewAtom(atomId_t _id);
|
|---|
| 275 |
|
|---|
| 276 | /**
|
|---|
| 277 | * internal method used by the world. Do not use if you don't know what you are doing.
|
|---|
| 278 | * You might get burned...
|
|---|
| 279 | * Use World::destroyAtom() instead.
|
|---|
| 280 | */
|
|---|
| 281 | void DeleteAtom(atom*);
|
|---|
| 282 |
|
|---|
| 283 | /**
|
|---|
| 284 | * Simple function to compare atoms by their elements to allow sorting of atoms by this criteria
|
|---|
| 285 | */
|
|---|
| 286 | bool compareAtomElements(atom* atom1,atom* atom2);
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 | #endif /* ATOM_HPP_ */
|
|---|