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