| 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 <boost/iterator/transform_iterator.hpp>
|
|---|
| 24 |
|
|---|
| 25 | #include <string>
|
|---|
| 26 |
|
|---|
| 27 | #include "AtomSet.hpp"
|
|---|
| 28 | #include "CodePatterns/Observer.hpp"
|
|---|
| 29 | #include "CodePatterns/ObservedIterator.hpp"
|
|---|
| 30 | #include "CodePatterns/Cacheable.hpp"
|
|---|
| 31 | #include "Descriptors/AtomIdDescriptor.hpp"
|
|---|
| 32 | #include "Fragmentation/HydrogenSaturation_enum.hpp"
|
|---|
| 33 | #include "Formula.hpp"
|
|---|
| 34 | #include "Helpers/defs.hpp"
|
|---|
| 35 | #include "types.hpp"
|
|---|
| 36 |
|
|---|
| 37 | // TODO: Was is the include of MoleculeDescriptor_impl.hpp doing in molecule.hpp
|
|---|
| 38 | #include "Descriptors/MoleculeDescriptor_impl.hpp"
|
|---|
| 39 |
|
|---|
| 40 | /****************************************** forward declarations *****************************/
|
|---|
| 41 |
|
|---|
| 42 | class atom;
|
|---|
| 43 | class bond;
|
|---|
| 44 | class BondedParticle;
|
|---|
| 45 | class BondGraph;
|
|---|
| 46 | class DepthFirstSearchAnalysis;
|
|---|
| 47 | class element;
|
|---|
| 48 | class ForceMatrix;
|
|---|
| 49 | class Graph;
|
|---|
| 50 | class LinkedCell;
|
|---|
| 51 | class molecule;
|
|---|
| 52 | class MoleculeLeafClass;
|
|---|
| 53 | class MoleculeListClass;
|
|---|
| 54 | class periodentafel;
|
|---|
| 55 | class RealSpaceMatrix;
|
|---|
| 56 | class Vector;
|
|---|
| 57 | class Shape;
|
|---|
| 58 |
|
|---|
| 59 | /******************************** Some definitions for easier reading **********************************/
|
|---|
| 60 |
|
|---|
| 61 | struct FromIdToAtom :
|
|---|
| 62 | public std::unary_function<atom *, atomId_t>
|
|---|
| 63 | {
|
|---|
| 64 | atom * operator()(atomId_t id) const {
|
|---|
| 65 | return World::getInstance().getAtom(AtomById(id));
|
|---|
| 66 | }
|
|---|
| 67 | };
|
|---|
| 68 |
|
|---|
| 69 | /************************************* Class definitions ****************************************/
|
|---|
| 70 |
|
|---|
| 71 | /** The complete molecule.
|
|---|
| 72 | * Class incorporates number of types
|
|---|
| 73 | */
|
|---|
| 74 | class molecule : public Observable
|
|---|
| 75 | {
|
|---|
| 76 | friend molecule *NewMolecule();
|
|---|
| 77 | friend void DeleteMolecule(molecule *);
|
|---|
| 78 |
|
|---|
| 79 | public:
|
|---|
| 80 | typedef ATOMSET(std::set) atomSet;
|
|---|
| 81 | typedef std::set<atomId_t> atomIdSet;
|
|---|
| 82 | typedef boost::transform_iterator<FromIdToAtom, atomIdSet::iterator, atom *, atomId_t> iterator;
|
|---|
| 83 | typedef iterator const_iterator;
|
|---|
| 84 |
|
|---|
| 85 | const periodentafel * const elemente; //!< periodic table with each element
|
|---|
| 86 | // old deprecated atom handling
|
|---|
| 87 | //atom *start; //!< start of atom list
|
|---|
| 88 | //atom *end; //!< end of atom list
|
|---|
| 89 | //bond *first; //!< start of bond list
|
|---|
| 90 | //bond *last; //!< end of bond list
|
|---|
| 91 | int MDSteps; //!< The number of MD steps in Trajectories
|
|---|
| 92 | mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
|
|---|
| 93 | mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
|
|---|
| 94 | mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
|
|---|
| 95 | bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
|
|---|
| 96 | //Vector Center; //!< Center of molecule in a global box
|
|---|
| 97 | int IndexNr; //!< index of molecule in a MoleculeListClass
|
|---|
| 98 | char name[MAXSTRINGSIZE]; //!< arbitrary name
|
|---|
| 99 |
|
|---|
| 100 | private:
|
|---|
| 101 | Formula formula;
|
|---|
| 102 | Cacheable<int> AtomCount; //!< number of atoms, brought up-to-date by doCountAtoms()
|
|---|
| 103 | Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
|
|---|
| 104 | moleculeId_t id;
|
|---|
| 105 | atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
|
|---|
| 106 | protected:
|
|---|
| 107 | //void CountAtoms();
|
|---|
| 108 | /**
|
|---|
| 109 | * this iterator type should be used for internal variables, \
|
|---|
| 110 | * since it will not lock
|
|---|
| 111 | */
|
|---|
| 112 | typedef atomSet::iterator internal_iterator;
|
|---|
| 113 |
|
|---|
| 114 | molecule(const periodentafel * const teil);
|
|---|
| 115 | virtual ~molecule();
|
|---|
| 116 |
|
|---|
| 117 | public:
|
|---|
| 118 | //getter and setter
|
|---|
| 119 | const std::string getName() const;
|
|---|
| 120 | int getAtomCount() const;
|
|---|
| 121 | int doCountAtoms();
|
|---|
| 122 | int getBondCount() const;
|
|---|
| 123 | int doCountBonds() const;
|
|---|
| 124 | moleculeId_t getId() const;
|
|---|
| 125 | void setId(moleculeId_t);
|
|---|
| 126 | void setName(const std::string);
|
|---|
| 127 | const Formula &getFormula() const;
|
|---|
| 128 | unsigned int getElementCount() const;
|
|---|
| 129 | bool hasElement(const element*) const;
|
|---|
| 130 | bool hasElement(atomicNumber_t) const;
|
|---|
| 131 | bool hasElement(const std::string&) const;
|
|---|
| 132 |
|
|---|
| 133 | virtual bool changeId(atomId_t newId);
|
|---|
| 134 |
|
|---|
| 135 | World::AtomComposite getAtomSet() const;
|
|---|
| 136 |
|
|---|
| 137 | iterator begin();
|
|---|
| 138 | const_iterator begin() const;
|
|---|
| 139 | iterator end();
|
|---|
| 140 | const_iterator end() const;
|
|---|
| 141 | bool empty() const;
|
|---|
| 142 | size_t size() const;
|
|---|
| 143 | const_iterator find(atom * key) const;
|
|---|
| 144 | pair<iterator, bool> insert(atom * const key);
|
|---|
| 145 | bool containsAtom(atom* key);
|
|---|
| 146 |
|
|---|
| 147 | private:
|
|---|
| 148 | friend void atom::removeFromMolecule();
|
|---|
| 149 | /** Erase an atom from the list.
|
|---|
| 150 | * \note This should only be called by atom::removeFromMolecule(),
|
|---|
| 151 | * otherwise it is not assured that the atom knows about it.
|
|---|
| 152 | *
|
|---|
| 153 | * @param loc locator to atom in list
|
|---|
| 154 | * @return iterator to just after removed item (compliant with standard)
|
|---|
| 155 | */
|
|---|
| 156 | const_iterator erase(const_iterator loc);
|
|---|
| 157 | /** Erase an atom from the list.
|
|---|
| 158 | * \note This should only be called by atom::removeFromMolecule(),
|
|---|
| 159 | * otherwise it is not assured that the atom knows about it.
|
|---|
| 160 | *
|
|---|
| 161 | * @param *key key to atom in list
|
|---|
| 162 | * @return iterator to just after removed item (compliant with standard)
|
|---|
| 163 | */
|
|---|
| 164 | const_iterator erase(atom * key);
|
|---|
| 165 |
|
|---|
| 166 | public:
|
|---|
| 167 |
|
|---|
| 168 | /// remove atoms from molecule.
|
|---|
| 169 | bool AddAtom(atom *pointer);
|
|---|
| 170 | bool RemoveAtom(atom *pointer);
|
|---|
| 171 | bool UnlinkAtom(atom *pointer);
|
|---|
| 172 | bool CleanupMolecule();
|
|---|
| 173 | void removeAtomsinMolecule();
|
|---|
| 174 |
|
|---|
| 175 | /// Add/remove atoms to/from molecule.
|
|---|
| 176 | atom * AddCopyAtom(atom *pointer);
|
|---|
| 177 | bool AddXYZFile(string filename);
|
|---|
| 178 | bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
|
|---|
| 179 | bond * AddBond(atom *first, atom *second, int degree = 1);
|
|---|
| 180 | bool RemoveBond(bond *pointer);
|
|---|
| 181 | bool RemoveBonds(atom *BondPartner);
|
|---|
| 182 | bool hasBondStructure() const;
|
|---|
| 183 |
|
|---|
| 184 | /// Find atoms.
|
|---|
| 185 | atom * FindAtom(int Nr) const;
|
|---|
| 186 | atom * AskAtom(string text);
|
|---|
| 187 |
|
|---|
| 188 | /// Count and change present atoms' coordination.
|
|---|
| 189 | bool CenterInBox();
|
|---|
| 190 | bool BoundInBox();
|
|---|
| 191 | void CenterEdge(Vector *max);
|
|---|
| 192 | void CenterOrigin();
|
|---|
| 193 | void CenterPeriodic();
|
|---|
| 194 | void CenterAtVector(Vector *newcenter);
|
|---|
| 195 | void Translate(const Vector *x);
|
|---|
| 196 | void TranslatePeriodically(const Vector *trans);
|
|---|
| 197 | void Mirror(const Vector *x);
|
|---|
| 198 | void Align(Vector *n);
|
|---|
| 199 | void Scale(const double ** const factor);
|
|---|
| 200 | void DeterminePeriodicCenter(Vector ¢er, const enum HydrogenSaturation _saturation = DoSaturate);
|
|---|
| 201 | Vector * DetermineCenterOfGravity() const;
|
|---|
| 202 | Vector * DetermineCenterOfAll() const;
|
|---|
| 203 | Vector * DetermineCenterOfBox() const;
|
|---|
| 204 | void SetNameFromFilename(const char *filename);
|
|---|
| 205 | void SetBoxDimension(Vector *dim);
|
|---|
| 206 | bool ScanForPeriodicCorrection();
|
|---|
| 207 | double VolumeOfConvexEnvelope(bool IsAngstroem);
|
|---|
| 208 | RealSpaceMatrix getInertiaTensor() const;
|
|---|
| 209 | void RotateToPrincipalAxisSystem(Vector &Axis);
|
|---|
| 210 |
|
|---|
| 211 | bool CheckBounds(const Vector *x) const;
|
|---|
| 212 | void GetAlignvector(struct lsq_params * par) const;
|
|---|
| 213 |
|
|---|
| 214 | /// Initialising routines in fragmentation
|
|---|
| 215 | void OutputBondsList() const;
|
|---|
| 216 |
|
|---|
| 217 | bond * CopyBond(atom *left, atom *right, bond *CopyBond);
|
|---|
| 218 |
|
|---|
| 219 | molecule *CopyMolecule() const;
|
|---|
| 220 | molecule* CopyMoleculeFromSubRegion(const Shape&) const;
|
|---|
| 221 |
|
|---|
| 222 | /// Fragment molecule by two different approaches:
|
|---|
| 223 | bool StoreBondsToFile(std::string filename, std::string path = "");
|
|---|
| 224 | bool StoreAdjacencyToFile(std::string filename, std::string path = "");
|
|---|
| 225 | bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
|
|---|
| 226 |
|
|---|
| 227 | // Recognize doubly appearing molecules in a list of them
|
|---|
| 228 | int * GetFatherSonAtomicMap(molecule *OtherMolecule);
|
|---|
| 229 | bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
|
|---|
| 230 | bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount);
|
|---|
| 231 |
|
|---|
| 232 | // Output routines.
|
|---|
| 233 | bool Output(std::ostream * const output) const;
|
|---|
| 234 | bool OutputTrajectories(ofstream * const output) const;
|
|---|
| 235 | void OutputListOfBonds() const;
|
|---|
| 236 | bool OutputXYZ(ofstream * const output) const;
|
|---|
| 237 | bool OutputTrajectoriesXYZ(ofstream * const output);
|
|---|
| 238 | bool Checkout(ofstream * const output) const;
|
|---|
| 239 |
|
|---|
| 240 | // Manipulation routines
|
|---|
| 241 | void flipActiveFlag();
|
|---|
| 242 |
|
|---|
| 243 | private:
|
|---|
| 244 | int last_atom; //!< number given to last atom
|
|---|
| 245 | };
|
|---|
| 246 |
|
|---|
| 247 | molecule *NewMolecule();
|
|---|
| 248 | void DeleteMolecule(molecule* mol);
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 | #endif /*MOLECULES_HPP_*/
|
|---|
| 253 |
|
|---|