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