| [cee0b57] | 1 | /** \file molecule.hpp
 | 
|---|
| [14de469] | 2 |  *
 | 
|---|
| [69eb71] | 3 |  * Class definitions of atom and molecule, element and periodentafel
 | 
|---|
| [14de469] | 4 |  */
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 | #ifndef MOLECULES_HPP_
 | 
|---|
 | 7 | #define MOLECULES_HPP_
 | 
|---|
 | 8 | 
 | 
|---|
| [f66195] | 9 | /*********************************************** includes ***********************************/
 | 
|---|
 | 10 | 
 | 
|---|
| [962d8d] | 11 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 12 | #include <config.h>
 | 
|---|
 | 13 | #endif
 | 
|---|
 | 14 | 
 | 
|---|
| [edb93c] | 15 | //// STL headers
 | 
|---|
| [14de469] | 16 | #include <map>
 | 
|---|
 | 17 | #include <set>
 | 
|---|
| [a564be] | 18 | #include <stack>
 | 
|---|
| [14de469] | 19 | #include <deque>
 | 
|---|
| [d7e30c] | 20 | #include <list>
 | 
|---|
| [5e0d1f] | 21 | #include <vector>
 | 
|---|
| [14de469] | 22 | 
 | 
|---|
| [520c8b] | 23 | #include <string>
 | 
|---|
 | 24 | 
 | 
|---|
| [8e1f901] | 25 | #include "AtomIdSet.hpp"
 | 
|---|
| [6f0841] | 26 | #include "Atom/AtomSet.hpp"
 | 
|---|
| [ad011c] | 27 | #include "CodePatterns/Cacheable.hpp"
 | 
|---|
| [02ce36] | 28 | #include "CodePatterns/Observer/Observable.hpp"
 | 
|---|
| [30c753] | 29 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
| [07a47e] | 30 | #include "Fragmentation/HydrogenSaturation_enum.hpp"
 | 
|---|
| [389cc8] | 31 | #include "Formula.hpp"
 | 
|---|
| [30c753] | 32 | #include "Helpers/defs.hpp"
 | 
|---|
| [560bbe] | 33 | #include "IdPool_policy.hpp"
 | 
|---|
 | 34 | #include "IdPool.hpp"
 | 
|---|
| [c67ff9] | 35 | #include "Shapes/Shape.hpp"
 | 
|---|
| [30c753] | 36 | #include "types.hpp"
 | 
|---|
| [14de469] | 37 | 
 | 
|---|
| [f66195] | 38 | /****************************************** forward declarations *****************************/
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 | class atom;
 | 
|---|
 | 41 | class bond;
 | 
|---|
| [b70721] | 42 | class BondedParticle;
 | 
|---|
 | 43 | class BondGraph;
 | 
|---|
| [49c059] | 44 | class DepthFirstSearchAnalysis;
 | 
|---|
| [f66195] | 45 | class element;
 | 
|---|
 | 46 | class ForceMatrix;
 | 
|---|
| [dadc74] | 47 | class Graph;
 | 
|---|
| [6bd7e0] | 48 | class LinkedCell_deprecated;
 | 
|---|
| [6d551c] | 49 | class ListOfLocalAtoms_t;
 | 
|---|
| [14de469] | 50 | class molecule;
 | 
|---|
| [2319ed] | 51 | class MoleculeLeafClass;
 | 
|---|
| [14de469] | 52 | class MoleculeListClass;
 | 
|---|
| [c67ff9] | 53 | class MoleculeUnittest;
 | 
|---|
| [1f91f4] | 54 | class RealSpaceMatrix;
 | 
|---|
| [f66195] | 55 | class Vector;
 | 
|---|
| [14de469] | 56 | 
 | 
|---|
 | 57 | /************************************* Class definitions ****************************************/
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 | /** The complete molecule.
 | 
|---|
 | 60 |  * Class incorporates number of types
 | 
|---|
 | 61 |  */
 | 
|---|
| [34c43a] | 62 | class molecule : public Observable
 | 
|---|
| [e4afb4] | 63 | {
 | 
|---|
| [c67ff9] | 64 |   //!> grant unit test access
 | 
|---|
 | 65 |   friend class MoleculeUnittest;
 | 
|---|
 | 66 |   //!> function may access cstor
 | 
|---|
| [cbc5fb] | 67 |   friend molecule *NewMolecule();
 | 
|---|
| [c67ff9] | 68 |   //!> function may access dstor
 | 
|---|
| [cbc5fb] | 69 |   friend void DeleteMolecule(molecule *);
 | 
|---|
| [bd58fb] | 70 | 
 | 
|---|
| [e4afb4] | 71 | public:
 | 
|---|
| [8e1f901] | 72 |   typedef AtomIdSet::atomIdSet atomIdSet;
 | 
|---|
 | 73 |   typedef AtomIdSet::iterator iterator;
 | 
|---|
 | 74 |   typedef AtomIdSet::const_iterator const_iterator;
 | 
|---|
| [e4afb4] | 75 | 
 | 
|---|
 | 76 |   int MDSteps; //!< The number of MD steps in Trajectories
 | 
|---|
 | 77 |   mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
 | 
|---|
 | 78 |   mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
 | 
|---|
 | 79 |   bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
 | 
|---|
 | 80 |   int IndexNr; //!< index of molecule in a MoleculeListClass
 | 
|---|
 | 81 |   char name[MAXSTRINGSIZE]; //!< arbitrary name
 | 
|---|
 | 82 | 
 | 
|---|
 | 83 | private:
 | 
|---|
 | 84 |   Formula formula;
 | 
|---|
| [e791dc] | 85 |   Cacheable<size_t> NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
 | 
|---|
| [458c31] | 86 |   Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
 | 
|---|
| [e4afb4] | 87 |   moleculeId_t id;
 | 
|---|
| [8e1f901] | 88 |   AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
 | 
|---|
| [560bbe] | 89 |   IdPool<atomId_t, uniqueId> atomIdPool;  //!< pool of internal ids such that way may guarantee uniqueness
 | 
|---|
 | 90 | 
 | 
|---|
| [e4afb4] | 91 | protected:
 | 
|---|
| [ac9b56] | 92 | 
 | 
|---|
| [4d2b33] | 93 |   molecule();
 | 
|---|
| [e4afb4] | 94 |   virtual ~molecule();
 | 
|---|
| [042f82] | 95 | 
 | 
|---|
| [6a3c83] | 96 | public:
 | 
|---|
 | 97 | 
 | 
|---|
 | 98 |   /******* Notifications *******/
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 |   //!> enumeration of present notification types: only insertion/removal of atoms or molecules
 | 
|---|
 | 101 |   enum NotificationType {
 | 
|---|
 | 102 |     AtomInserted,
 | 
|---|
 | 103 |     AtomRemoved,
 | 
|---|
 | 104 |     AtomNrChanged,
 | 
|---|
 | 105 |     MoleculeNameChanged,
 | 
|---|
 | 106 |     NotificationType_MAX
 | 
|---|
 | 107 |   };
 | 
|---|
 | 108 | 
 | 
|---|
| [cbc5fb] | 109 | public:
 | 
|---|
| [520c8b] | 110 |   //getter and setter
 | 
|---|
| [73a857] | 111 |   const std::string getName() const;
 | 
|---|
| [ea7176] | 112 |   int getAtomCount() const;
 | 
|---|
| [e791dc] | 113 |   size_t doCountNoNonHydrogen() const;
 | 
|---|
 | 114 |   size_t getNoNonHydrogen() const;
 | 
|---|
| [458c31] | 115 |   int getBondCount() const;
 | 
|---|
 | 116 |   int doCountBonds() const;
 | 
|---|
| [73a857] | 117 |   moleculeId_t getId() const;
 | 
|---|
| [cbc5fb] | 118 |   void setId(moleculeId_t);
 | 
|---|
| [520c8b] | 119 |   void setName(const std::string);
 | 
|---|
| [73a857] | 120 |   const Formula &getFormula() const;
 | 
|---|
 | 121 |   unsigned int getElementCount() const;
 | 
|---|
| [389cc8] | 122 |   bool hasElement(const element*) const;
 | 
|---|
 | 123 |   bool hasElement(atomicNumber_t) const;
 | 
|---|
 | 124 |   bool hasElement(const std::string&) const;
 | 
|---|
 | 125 | 
 | 
|---|
| [a7a087] | 126 |   virtual bool changeId(atomId_t newId);
 | 
|---|
| [520c8b] | 127 | 
 | 
|---|
| [9317be] | 128 |   World::AtomComposite getAtomSet() const;
 | 
|---|
| [3738f0] | 129 | 
 | 
|---|
| [8e1f901] | 130 |   // simply pass on all functions to AtomIdSet
 | 
|---|
 | 131 |   iterator begin() {
 | 
|---|
 | 132 |     return atomIds.begin();
 | 
|---|
 | 133 |   }
 | 
|---|
 | 134 |   const_iterator begin() const
 | 
|---|
 | 135 |   {
 | 
|---|
 | 136 |     return atomIds.begin();
 | 
|---|
 | 137 |   }
 | 
|---|
 | 138 |   iterator end()
 | 
|---|
 | 139 |   {
 | 
|---|
 | 140 |     return atomIds.end();
 | 
|---|
 | 141 |   }
 | 
|---|
 | 142 |   const_iterator end() const
 | 
|---|
 | 143 |   {
 | 
|---|
 | 144 |     return atomIds.end();
 | 
|---|
 | 145 |   }
 | 
|---|
 | 146 |   bool empty() const
 | 
|---|
 | 147 |   {
 | 
|---|
 | 148 |     return atomIds.empty();
 | 
|---|
 | 149 |   }
 | 
|---|
 | 150 |   size_t size() const
 | 
|---|
 | 151 |   {
 | 
|---|
 | 152 |     return atomIds.size();
 | 
|---|
 | 153 |   }
 | 
|---|
 | 154 |   const_iterator find(atom * key) const
 | 
|---|
 | 155 |   {
 | 
|---|
 | 156 |     return atomIds.find(key);
 | 
|---|
 | 157 |   }
 | 
|---|
| [c67ff9] | 158 | 
 | 
|---|
 | 159 |   /** Returns the set of atomic ids contained in this molecule.
 | 
|---|
 | 160 |    *
 | 
|---|
 | 161 |    * @return set of atomic ids
 | 
|---|
 | 162 |    */
 | 
|---|
| [8e1f901] | 163 |   const atomIdSet & getAtomIds() const {
 | 
|---|
 | 164 |     return atomIds.getAtomIds();
 | 
|---|
 | 165 |   }
 | 
|---|
 | 166 | 
 | 
|---|
 | 167 |   std::pair<iterator, bool> insert(atom * const key);
 | 
|---|
 | 168 | 
 | 
|---|
| [6aad6f] | 169 |   /** Predicate whether given \a key is contained in this molecule.
 | 
|---|
 | 170 |    *
 | 
|---|
 | 171 |    * @param key atom to check
 | 
|---|
 | 172 |    * @return true - is contained, false - else
 | 
|---|
 | 173 |    */
 | 
|---|
 | 174 |   bool containsAtom(const atom* key) const
 | 
|---|
 | 175 |   {
 | 
|---|
 | 176 |     return atomIds.contains(key);
 | 
|---|
 | 177 |   }
 | 
|---|
 | 178 | 
 | 
|---|
 | 179 |   /** Predicate whether given \a id is contained in this molecule.
 | 
|---|
 | 180 |    *
 | 
|---|
 | 181 |    * @param id atomic id to check
 | 
|---|
 | 182 |    * @return true - is contained, false - else
 | 
|---|
 | 183 |    */
 | 
|---|
 | 184 |   bool containsAtom(const atomId_t id) const
 | 
|---|
 | 185 |   {
 | 
|---|
 | 186 |     return atomIds.contains(id);
 | 
|---|
 | 187 |   }
 | 
|---|
| [bd58fb] | 188 | 
 | 
|---|
| [2e4105] | 189 | private:
 | 
|---|
 | 190 |   friend void atom::removeFromMolecule();
 | 
|---|
 | 191 |   /** Erase an atom from the list.
 | 
|---|
 | 192 |    * \note This should only be called by atom::removeFromMolecule(),
 | 
|---|
 | 193 |    * otherwise it is not assured that the atom knows about it.
 | 
|---|
 | 194 |    *
 | 
|---|
 | 195 |    * @param loc locator to atom in list
 | 
|---|
 | 196 |    * @return iterator to just after removed item (compliant with standard)
 | 
|---|
 | 197 |    */
 | 
|---|
 | 198 |   const_iterator erase(const_iterator loc);
 | 
|---|
| [8e1f901] | 199 | 
 | 
|---|
| [2e4105] | 200 |   /** Erase an atom from the list.
 | 
|---|
 | 201 |    * \note This should only be called by atom::removeFromMolecule(),
 | 
|---|
 | 202 |    * otherwise it is not assured that the atom knows about it.
 | 
|---|
 | 203 |    *
 | 
|---|
 | 204 |    * @param *key key to atom in list
 | 
|---|
 | 205 |    * @return iterator to just after removed item (compliant with standard)
 | 
|---|
 | 206 |    */
 | 
|---|
 | 207 |   const_iterator erase(atom * key);
 | 
|---|
 | 208 | 
 | 
|---|
| [560bbe] | 209 | private:
 | 
|---|
 | 210 |   friend bool atom::changeNr(int newId);
 | 
|---|
 | 211 |   /**
 | 
|---|
 | 212 |    * used when changing an ParticleInfo::Nr.
 | 
|---|
 | 213 |    * Note that this number is local with this molecule.
 | 
|---|
 | 214 |    * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
 | 
|---|
 | 215 |    *
 | 
|---|
 | 216 |    * @param oldNr old Nr
 | 
|---|
 | 217 |    * @param newNr new Nr to set
 | 
|---|
 | 218 |    * @param *target ref to atom
 | 
|---|
 | 219 |    * @return indicates wether the change could be done or not.
 | 
|---|
 | 220 |    */
 | 
|---|
 | 221 |   bool changeAtomNr(int oldNr, int newNr, atom* target=0);
 | 
|---|
 | 222 | 
 | 
|---|
 | 223 |   /** Sets the name of the atom.
 | 
|---|
 | 224 |    *
 | 
|---|
 | 225 |    * The name is set via its element symbol and its internal ParticleInfo::Nr.
 | 
|---|
 | 226 |    *
 | 
|---|
 | 227 |    * @param _atom atom whose name to set
 | 
|---|
 | 228 |    */
 | 
|---|
 | 229 |   void setAtomName(atom *_atom) const;
 | 
|---|
 | 230 | 
 | 
|---|
| [2e4105] | 231 | public:
 | 
|---|
 | 232 | 
 | 
|---|
| [c67ff9] | 233 |   /** Function to create a bounding spherical shape for the currently associated atoms.
 | 
|---|
 | 234 |    *
 | 
|---|
| [55feea1] | 235 |    * \param boundary extra boundary of shape around (i.e. distance between outermost atom
 | 
|---|
 | 236 |    *        and the shape's surface)
 | 
|---|
| [c67ff9] | 237 |    */
 | 
|---|
| [55feea1] | 238 |   Shape getBoundingShape(const double boundary = 0.) const;
 | 
|---|
| [c67ff9] | 239 | 
 | 
|---|
| [042f82] | 240 |   /// remove atoms from molecule.
 | 
|---|
 | 241 |   bool AddAtom(atom *pointer);
 | 
|---|
 | 242 |   bool RemoveAtom(atom *pointer);
 | 
|---|
 | 243 |   bool UnlinkAtom(atom *pointer);
 | 
|---|
 | 244 |   bool CleanupMolecule();
 | 
|---|
| [9df680] | 245 |   void removeAtomsinMolecule();
 | 
|---|
| [042f82] | 246 | 
 | 
|---|
 | 247 |   /// Add/remove atoms to/from molecule.
 | 
|---|
 | 248 |   atom * AddCopyAtom(atom *pointer);
 | 
|---|
| [88c8ec] | 249 |   bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
 | 
|---|
 | 250 |   bond::ptr AddBond(atom *first, atom *second, int degree = 1);
 | 
|---|
| [e4afb4] | 251 |   bool hasBondStructure() const;
 | 
|---|
| [042f82] | 252 | 
 | 
|---|
 | 253 |   /// Find atoms.
 | 
|---|
 | 254 |   atom * FindAtom(int Nr) const;
 | 
|---|
| [955b91] | 255 |   atom * AskAtom(std::string text);
 | 
|---|
| [59fff1] | 256 |   bool isInMolecule(const atom * const _atom);
 | 
|---|
| [042f82] | 257 | 
 | 
|---|
 | 258 |   /// Count and change present atoms' coordination.
 | 
|---|
| [e138de] | 259 |   bool CenterInBox();
 | 
|---|
 | 260 |   bool BoundInBox();
 | 
|---|
 | 261 |   void CenterEdge(Vector *max);
 | 
|---|
 | 262 |   void CenterOrigin();
 | 
|---|
 | 263 |   void CenterPeriodic();
 | 
|---|
 | 264 |   void CenterAtVector(Vector *newcenter);
 | 
|---|
| [042f82] | 265 |   void Translate(const Vector *x);
 | 
|---|
 | 266 |   void TranslatePeriodically(const Vector *trans);
 | 
|---|
 | 267 |   void Mirror(const Vector *x);
 | 
|---|
 | 268 |   void Align(Vector *n);
 | 
|---|
| [776b64] | 269 |   void Scale(const double ** const factor);
 | 
|---|
| [9291d04] | 270 |   void DeterminePeriodicCenter(Vector ¢er, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
 | 
|---|
| [4bb63c] | 271 |   Vector * DetermineCenterOfGravity() const;
 | 
|---|
| [e138de] | 272 |   Vector * DetermineCenterOfAll() const;
 | 
|---|
| [eddea2] | 273 |   Vector * DetermineCenterOfBox() const;
 | 
|---|
| [437922] | 274 |   void SetNameFromFilename(const char *filename);
 | 
|---|
| [042f82] | 275 |   void SetBoxDimension(Vector *dim);
 | 
|---|
| [3c58f8] | 276 |   bool ScanForPeriodicCorrection();
 | 
|---|
| [e138de] | 277 |   double VolumeOfConvexEnvelope(bool IsAngstroem);
 | 
|---|
| [1f91f4] | 278 |   RealSpaceMatrix getInertiaTensor() const;
 | 
|---|
| [5b6a4b7] | 279 |   void RotateToPrincipalAxisSystem(const Vector &Axis);
 | 
|---|
| [042f82] | 280 | 
 | 
|---|
 | 281 |   bool CheckBounds(const Vector *x) const;
 | 
|---|
 | 282 |   void GetAlignvector(struct lsq_params * par) const;
 | 
|---|
 | 283 | 
 | 
|---|
 | 284 |   /// Initialising routines in fragmentation
 | 
|---|
| [e138de] | 285 |   void OutputBondsList() const;
 | 
|---|
| [49c059] | 286 | 
 | 
|---|
| [88c8ec] | 287 |   bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
 | 
|---|
| [266237] | 288 | 
 | 
|---|
| [c67ff9] | 289 |   molecule *CopyMolecule(const Vector &offset = zeroVec) const;
 | 
|---|
| [c550dd] | 290 |   molecule* CopyMoleculeFromSubRegion(const Shape&) const;
 | 
|---|
| [042f82] | 291 | 
 | 
|---|
 | 292 |   /// Fragment molecule by two different approaches:
 | 
|---|
| [e4afb4] | 293 |   bool StoreBondsToFile(std::string filename, std::string path = "");
 | 
|---|
| [6d551c] | 294 |   bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
 | 
|---|
| [b9772a] | 295 | 
 | 
|---|
| [042f82] | 296 |   // Recognize doubly appearing molecules in a list of them
 | 
|---|
| [e138de] | 297 |   int * GetFatherSonAtomicMap(molecule *OtherMolecule);
 | 
|---|
| [6d551c] | 298 |   bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
 | 
|---|
 | 299 |   bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
 | 
|---|
| [042f82] | 300 | 
 | 
|---|
 | 301 |   // Output routines.
 | 
|---|
| [e4afb4] | 302 |   bool Output(std::ostream * const output) const;
 | 
|---|
| [e138de] | 303 |   void OutputListOfBonds() const;
 | 
|---|
| [042f82] | 304 | 
 | 
|---|
| [c68025] | 305 |   // Manipulation routines
 | 
|---|
 | 306 |   void flipActiveFlag();
 | 
|---|
 | 307 | 
 | 
|---|
| [e4afb4] | 308 | private:
 | 
|---|
 | 309 |   int last_atom; //!< number given to last atom
 | 
|---|
| [14de469] | 310 | };
 | 
|---|
 | 311 | 
 | 
|---|
| [cbc5fb] | 312 | molecule *NewMolecule();
 | 
|---|
 | 313 | void DeleteMolecule(molecule* mol);
 | 
|---|
 | 314 | 
 | 
|---|
| [14de469] | 315 | 
 | 
|---|
 | 316 | 
 | 
|---|
 | 317 | #endif /*MOLECULES_HPP_*/
 | 
|---|
 | 318 | 
 | 
|---|