[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
|
---|
[c6ab91] | 90 | typedef std::map<atomId_t,atom *> LocalToGlobalId_t;
|
---|
| 91 | LocalToGlobalId_t LocalToGlobalId; //!< internal map to ease FindAtom
|
---|
[560bbe] | 92 |
|
---|
[e4afb4] | 93 | protected:
|
---|
[ac9b56] | 94 |
|
---|
[4d2b33] | 95 | molecule();
|
---|
[e4afb4] | 96 | virtual ~molecule();
|
---|
[042f82] | 97 |
|
---|
[6a3c83] | 98 | public:
|
---|
| 99 |
|
---|
| 100 | /******* Notifications *******/
|
---|
| 101 |
|
---|
| 102 | //!> enumeration of present notification types: only insertion/removal of atoms or molecules
|
---|
| 103 | enum NotificationType {
|
---|
| 104 | AtomInserted,
|
---|
| 105 | AtomRemoved,
|
---|
| 106 | AtomNrChanged,
|
---|
[c32d21] | 107 | AtomMoved,
|
---|
[6a3c83] | 108 | MoleculeNameChanged,
|
---|
| 109 | NotificationType_MAX
|
---|
| 110 | };
|
---|
| 111 |
|
---|
[8c001a] | 112 | //>! access to last changed element (atom)
|
---|
| 113 | const atom* lastChanged() const
|
---|
| 114 | { return _lastchangedatom; }
|
---|
| 115 |
|
---|
[cbc5fb] | 116 | public:
|
---|
[520c8b] | 117 | //getter and setter
|
---|
[73a857] | 118 | const std::string getName() const;
|
---|
[ea7176] | 119 | int getAtomCount() const;
|
---|
[e791dc] | 120 | size_t doCountNoNonHydrogen() const;
|
---|
| 121 | size_t getNoNonHydrogen() const;
|
---|
[458c31] | 122 | int getBondCount() const;
|
---|
| 123 | int doCountBonds() const;
|
---|
[73a857] | 124 | moleculeId_t getId() const;
|
---|
[cbc5fb] | 125 | void setId(moleculeId_t);
|
---|
[520c8b] | 126 | void setName(const std::string);
|
---|
[73a857] | 127 | const Formula &getFormula() const;
|
---|
| 128 | unsigned int getElementCount() const;
|
---|
[389cc8] | 129 | bool hasElement(const element*) const;
|
---|
| 130 | bool hasElement(atomicNumber_t) const;
|
---|
| 131 | bool hasElement(const std::string&) const;
|
---|
| 132 |
|
---|
[a7a087] | 133 | virtual bool changeId(atomId_t newId);
|
---|
[520c8b] | 134 |
|
---|
[9317be] | 135 | World::AtomComposite getAtomSet() const;
|
---|
[3738f0] | 136 |
|
---|
[8e1f901] | 137 | // simply pass on all functions to AtomIdSet
|
---|
| 138 | iterator begin() {
|
---|
| 139 | return atomIds.begin();
|
---|
| 140 | }
|
---|
| 141 | const_iterator begin() const
|
---|
| 142 | {
|
---|
| 143 | return atomIds.begin();
|
---|
| 144 | }
|
---|
| 145 | iterator end()
|
---|
| 146 | {
|
---|
| 147 | return atomIds.end();
|
---|
| 148 | }
|
---|
| 149 | const_iterator end() const
|
---|
| 150 | {
|
---|
| 151 | return atomIds.end();
|
---|
| 152 | }
|
---|
| 153 | bool empty() const
|
---|
| 154 | {
|
---|
| 155 | return atomIds.empty();
|
---|
| 156 | }
|
---|
| 157 | size_t size() const
|
---|
| 158 | {
|
---|
| 159 | return atomIds.size();
|
---|
| 160 | }
|
---|
| 161 | const_iterator find(atom * key) const
|
---|
| 162 | {
|
---|
| 163 | return atomIds.find(key);
|
---|
| 164 | }
|
---|
[c67ff9] | 165 |
|
---|
| 166 | /** Returns the set of atomic ids contained in this molecule.
|
---|
| 167 | *
|
---|
| 168 | * @return set of atomic ids
|
---|
| 169 | */
|
---|
[8e1f901] | 170 | const atomIdSet & getAtomIds() const {
|
---|
| 171 | return atomIds.getAtomIds();
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | std::pair<iterator, bool> insert(atom * const key);
|
---|
| 175 |
|
---|
[6aad6f] | 176 | /** Predicate whether given \a key is contained in this molecule.
|
---|
| 177 | *
|
---|
| 178 | * @param key atom to check
|
---|
| 179 | * @return true - is contained, false - else
|
---|
| 180 | */
|
---|
| 181 | bool containsAtom(const atom* key) const
|
---|
| 182 | {
|
---|
| 183 | return atomIds.contains(key);
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | /** Predicate whether given \a id is contained in this molecule.
|
---|
| 187 | *
|
---|
| 188 | * @param id atomic id to check
|
---|
| 189 | * @return true - is contained, false - else
|
---|
| 190 | */
|
---|
| 191 | bool containsAtom(const atomId_t id) const
|
---|
| 192 | {
|
---|
| 193 | return atomIds.contains(id);
|
---|
| 194 | }
|
---|
[bd58fb] | 195 |
|
---|
[2e4105] | 196 | private:
|
---|
| 197 | friend void atom::removeFromMolecule();
|
---|
| 198 | /** Erase an atom from the list.
|
---|
| 199 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
| 200 | * otherwise it is not assured that the atom knows about it.
|
---|
| 201 | *
|
---|
| 202 | * @param loc locator to atom in list
|
---|
| 203 | * @return iterator to just after removed item (compliant with standard)
|
---|
| 204 | */
|
---|
| 205 | const_iterator erase(const_iterator loc);
|
---|
[8e1f901] | 206 |
|
---|
[2e4105] | 207 | /** Erase an atom from the list.
|
---|
| 208 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
| 209 | * otherwise it is not assured that the atom knows about it.
|
---|
| 210 | *
|
---|
| 211 | * @param *key key to atom in list
|
---|
| 212 | * @return iterator to just after removed item (compliant with standard)
|
---|
| 213 | */
|
---|
| 214 | const_iterator erase(atom * key);
|
---|
| 215 |
|
---|
[560bbe] | 216 | private:
|
---|
| 217 | friend bool atom::changeNr(int newId);
|
---|
| 218 | /**
|
---|
| 219 | * used when changing an ParticleInfo::Nr.
|
---|
| 220 | * Note that this number is local with this molecule.
|
---|
| 221 | * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
|
---|
| 222 | *
|
---|
| 223 | * @param oldNr old Nr
|
---|
| 224 | * @param newNr new Nr to set
|
---|
| 225 | * @param *target ref to atom
|
---|
| 226 | * @return indicates wether the change could be done or not.
|
---|
| 227 | */
|
---|
| 228 | bool changeAtomNr(int oldNr, int newNr, atom* target=0);
|
---|
| 229 |
|
---|
[c6ab91] | 230 | /** Updates the internal lookup fro local to global indices.
|
---|
| 231 | *
|
---|
| 232 | * \param pointer pointer to atom
|
---|
| 233 | */
|
---|
| 234 | void InsertLocalToGlobalId(atom * const pointer);
|
---|
| 235 |
|
---|
[560bbe] | 236 | /** Sets the name of the atom.
|
---|
| 237 | *
|
---|
| 238 | * The name is set via its element symbol and its internal ParticleInfo::Nr.
|
---|
| 239 | *
|
---|
| 240 | * @param _atom atom whose name to set
|
---|
| 241 | */
|
---|
| 242 | void setAtomName(atom *_atom) const;
|
---|
| 243 |
|
---|
[2e4105] | 244 | public:
|
---|
| 245 |
|
---|
[c67ff9] | 246 | /** Function to create a bounding spherical shape for the currently associated atoms.
|
---|
| 247 | *
|
---|
[55feea1] | 248 | * \param boundary extra boundary of shape around (i.e. distance between outermost atom
|
---|
| 249 | * and the shape's surface)
|
---|
[c67ff9] | 250 | */
|
---|
[aeb694] | 251 | Shape getBoundingSphere(const double boundary = 0.) const;
|
---|
| 252 |
|
---|
| 253 | /** Creates the bounding box by adding van der Waals-Spheres around every atom.
|
---|
| 254 | *
|
---|
| 255 | * \param scale extra scale parameter to enlarge the spheres artifically
|
---|
| 256 | */
|
---|
| 257 | Shape getBoundingShape(const double scale = 1.) const;
|
---|
[c67ff9] | 258 |
|
---|
[042f82] | 259 | /// remove atoms from molecule.
|
---|
| 260 | bool AddAtom(atom *pointer);
|
---|
| 261 | bool RemoveAtom(atom *pointer);
|
---|
| 262 | bool UnlinkAtom(atom *pointer);
|
---|
| 263 | bool CleanupMolecule();
|
---|
[9df680] | 264 | void removeAtomsinMolecule();
|
---|
[042f82] | 265 |
|
---|
| 266 | /// Add/remove atoms to/from molecule.
|
---|
| 267 | atom * AddCopyAtom(atom *pointer);
|
---|
[06804b] | 268 | // bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
|
---|
[88c8ec] | 269 | bond::ptr AddBond(atom *first, atom *second, int degree = 1);
|
---|
[e4afb4] | 270 | bool hasBondStructure() const;
|
---|
[042f82] | 271 |
|
---|
| 272 | /// Find atoms.
|
---|
| 273 | atom * FindAtom(int Nr) const;
|
---|
[955b91] | 274 | atom * AskAtom(std::string text);
|
---|
[59fff1] | 275 | bool isInMolecule(const atom * const _atom);
|
---|
[042f82] | 276 |
|
---|
| 277 | /// Count and change present atoms' coordination.
|
---|
[e138de] | 278 | bool CenterInBox();
|
---|
| 279 | bool BoundInBox();
|
---|
[833b15] | 280 | void CenterEdge();
|
---|
[e138de] | 281 | void CenterOrigin();
|
---|
| 282 | void CenterPeriodic();
|
---|
[833b15] | 283 | void CenterAtVector(const Vector &newcenter);
|
---|
| 284 | void Translate(const Vector &x);
|
---|
| 285 | void TranslatePeriodically(const Vector &trans);
|
---|
| 286 | void Mirror(const Vector &x);
|
---|
| 287 | void Align(const Vector &n);
|
---|
| 288 | void Scale(const double *factor);
|
---|
[9291d04] | 289 | void DeterminePeriodicCenter(Vector ¢er, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
|
---|
[833b15] | 290 | const Vector DetermineCenterOfGravity() const;
|
---|
| 291 | const Vector DetermineCenterOfAll() const;
|
---|
[437922] | 292 | void SetNameFromFilename(const char *filename);
|
---|
[3c58f8] | 293 | bool ScanForPeriodicCorrection();
|
---|
[e138de] | 294 | double VolumeOfConvexEnvelope(bool IsAngstroem);
|
---|
[1f91f4] | 295 | RealSpaceMatrix getInertiaTensor() const;
|
---|
[5b6a4b7] | 296 | void RotateToPrincipalAxisSystem(const Vector &Axis);
|
---|
[042f82] | 297 |
|
---|
| 298 | bool CheckBounds(const Vector *x) const;
|
---|
| 299 | void GetAlignvector(struct lsq_params * par) const;
|
---|
| 300 |
|
---|
| 301 | /// Initialising routines in fragmentation
|
---|
[e138de] | 302 | void OutputBondsList() const;
|
---|
[49c059] | 303 |
|
---|
[88c8ec] | 304 | bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
|
---|
[266237] | 305 |
|
---|
[c67ff9] | 306 | molecule *CopyMolecule(const Vector &offset = zeroVec) const;
|
---|
[c550dd] | 307 | molecule* CopyMoleculeFromSubRegion(const Shape&) const;
|
---|
[042f82] | 308 |
|
---|
| 309 | /// Fragment molecule by two different approaches:
|
---|
[e4afb4] | 310 | bool StoreBondsToFile(std::string filename, std::string path = "");
|
---|
[6d551c] | 311 | bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
|
---|
[b9772a] | 312 |
|
---|
[042f82] | 313 | // Recognize doubly appearing molecules in a list of them
|
---|
[e138de] | 314 | int * GetFatherSonAtomicMap(molecule *OtherMolecule);
|
---|
[6d551c] | 315 | bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
|
---|
| 316 | bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
|
---|
[042f82] | 317 |
|
---|
| 318 | // Output routines.
|
---|
[e4afb4] | 319 | bool Output(std::ostream * const output) const;
|
---|
[e138de] | 320 | void OutputListOfBonds() const;
|
---|
[042f82] | 321 |
|
---|
[c68025] | 322 | // Manipulation routines
|
---|
| 323 | void flipActiveFlag();
|
---|
| 324 |
|
---|
[c32d21] | 325 | virtual void update(Observable *publisher);
|
---|
| 326 | virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
| 327 | virtual void subjectKilled(Observable *publisher);
|
---|
| 328 |
|
---|
[e4afb4] | 329 | private:
|
---|
[8c001a] | 330 | friend const atom *detail::lastChanged<atom>();
|
---|
| 331 | atom *_lastchangedatom;
|
---|
| 332 |
|
---|
[e4afb4] | 333 | int last_atom; //!< number given to last atom
|
---|
[14de469] | 334 | };
|
---|
| 335 |
|
---|
[cbc5fb] | 336 | molecule *NewMolecule();
|
---|
| 337 | void DeleteMolecule(molecule* mol);
|
---|
| 338 |
|
---|
[14de469] | 339 |
|
---|
| 340 |
|
---|
| 341 | #endif /*MOLECULES_HPP_*/
|
---|
| 342 |
|
---|