| [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 | 
 | 
|---|
| [68d781] | 25 | #include "types.hpp"
 | 
|---|
| [f66195] | 26 | #include "graph.hpp"
 | 
|---|
| [ad011c] | 27 | #include "CodePatterns/Observer.hpp"
 | 
|---|
 | 28 | #include "CodePatterns/ObservedIterator.hpp"
 | 
|---|
 | 29 | #include "CodePatterns/Cacheable.hpp"
 | 
|---|
| [255829] | 30 | #include "Helpers/defs.hpp"
 | 
|---|
| [389cc8] | 31 | #include "Formula.hpp"
 | 
|---|
| [14d541] | 32 | #include "AtomSet.hpp"
 | 
|---|
| [14de469] | 33 | 
 | 
|---|
| [97ebf8] | 34 | #include "Descriptors/MoleculeDescriptor_impl.hpp"
 | 
|---|
 | 35 | 
 | 
|---|
| [f66195] | 36 | /****************************************** forward declarations *****************************/
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 | class atom;
 | 
|---|
 | 39 | class bond;
 | 
|---|
| [b70721] | 40 | class BondedParticle;
 | 
|---|
 | 41 | class BondGraph;
 | 
|---|
| [49c059] | 42 | class DepthFirstSearchAnalysis;
 | 
|---|
| [f66195] | 43 | class element;
 | 
|---|
 | 44 | class ForceMatrix;
 | 
|---|
 | 45 | class LinkedCell;
 | 
|---|
| [14de469] | 46 | class molecule;
 | 
|---|
| [2319ed] | 47 | class MoleculeLeafClass;
 | 
|---|
| [14de469] | 48 | class MoleculeListClass;
 | 
|---|
| [f66195] | 49 | class periodentafel;
 | 
|---|
| [1f91f4] | 50 | class RealSpaceMatrix;
 | 
|---|
| [f66195] | 51 | class Vector;
 | 
|---|
| [c550dd] | 52 | class Shape;
 | 
|---|
| [14de469] | 53 | 
 | 
|---|
 | 54 | /******************************** Some definitions for easier reading **********************************/
 | 
|---|
 | 55 | 
 | 
|---|
| [edb93c] | 56 | #define MoleculeList list <molecule *>
 | 
|---|
 | 57 | #define MoleculeListTest pair <MoleculeList::iterator, bool>
 | 
|---|
 | 58 | 
 | 
|---|
| [14de469] | 59 | /************************************* Class definitions ****************************************/
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 | /** The complete molecule.
 | 
|---|
 | 62 |  * Class incorporates number of types
 | 
|---|
 | 63 |  */
 | 
|---|
| [34c43a] | 64 | class molecule : public Observable
 | 
|---|
| [e4afb4] | 65 | {
 | 
|---|
| [cbc5fb] | 66 |   friend molecule *NewMolecule();
 | 
|---|
 | 67 |   friend void DeleteMolecule(molecule *);
 | 
|---|
| [bd58fb] | 68 | 
 | 
|---|
| [e4afb4] | 69 | public:
 | 
|---|
 | 70 |   typedef ATOMSET(std::list) atomSet;
 | 
|---|
 | 71 |   typedef std::set<atomId_t> atomIdSet;
 | 
|---|
 | 72 |   typedef ObservedIterator<atomSet> iterator;
 | 
|---|
 | 73 |   typedef atomSet::const_iterator const_iterator;
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 |   const periodentafel * const elemente; //!< periodic table with each element
 | 
|---|
 | 76 |   // old deprecated atom handling
 | 
|---|
 | 77 |   //atom *start;        //!< start of atom list
 | 
|---|
 | 78 |   //atom *end;          //!< end of atom list
 | 
|---|
 | 79 |   //bond *first;        //!< start of bond list
 | 
|---|
 | 80 |   //bond *last;         //!< end of bond list
 | 
|---|
 | 81 |   int MDSteps; //!< The number of MD steps in Trajectories
 | 
|---|
 | 82 |   mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
 | 
|---|
 | 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 |   //Vector Center;      //!< Center of molecule in a global box
 | 
|---|
 | 87 |   int IndexNr; //!< index of molecule in a MoleculeListClass
 | 
|---|
 | 88 |   char name[MAXSTRINGSIZE]; //!< arbitrary name
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 | private:
 | 
|---|
 | 91 |   Formula formula;
 | 
|---|
| [458c31] | 92 |   Cacheable<int> AtomCount; //!< number of atoms, brought up-to-date by doCountAtoms()
 | 
|---|
 | 93 |   Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
 | 
|---|
| [e4afb4] | 94 |   moleculeId_t id;
 | 
|---|
 | 95 |   atomSet atoms; //<!list of atoms
 | 
|---|
 | 96 |   atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
 | 
|---|
 | 97 | protected:
 | 
|---|
 | 98 |   //void CountAtoms();
 | 
|---|
 | 99 |   /**
 | 
|---|
 | 100 |    * this iterator type should be used for internal variables, \
 | 
|---|
| [d3347e] | 101 |      * since it will not lock
 | 
|---|
| [e4afb4] | 102 |    */
 | 
|---|
 | 103 |   typedef atomSet::iterator internal_iterator;
 | 
|---|
| [ac9b56] | 104 | 
 | 
|---|
| [e4afb4] | 105 |   molecule(const periodentafel * const teil);
 | 
|---|
 | 106 |   virtual ~molecule();
 | 
|---|
| [042f82] | 107 | 
 | 
|---|
| [cbc5fb] | 108 | public:
 | 
|---|
| [520c8b] | 109 |   //getter and setter
 | 
|---|
| [73a857] | 110 |   const std::string getName() const;
 | 
|---|
| [ea7176] | 111 |   int getAtomCount() const;
 | 
|---|
 | 112 |   int doCountAtoms();
 | 
|---|
| [458c31] | 113 |   int getBondCount() const;
 | 
|---|
 | 114 |   int doCountBonds() const;
 | 
|---|
| [73a857] | 115 |   moleculeId_t getId() const;
 | 
|---|
| [cbc5fb] | 116 |   void setId(moleculeId_t);
 | 
|---|
| [520c8b] | 117 |   void setName(const std::string);
 | 
|---|
| [73a857] | 118 |   const Formula &getFormula() const;
 | 
|---|
 | 119 |   unsigned int getElementCount() const;
 | 
|---|
| [389cc8] | 120 |   bool hasElement(const element*) const;
 | 
|---|
 | 121 |   bool hasElement(atomicNumber_t) const;
 | 
|---|
 | 122 |   bool hasElement(const std::string&) const;
 | 
|---|
 | 123 | 
 | 
|---|
| [a7a087] | 124 |   virtual bool changeId(atomId_t newId);
 | 
|---|
| [520c8b] | 125 | 
 | 
|---|
| [9317be] | 126 |   World::AtomComposite getAtomSet() const;
 | 
|---|
| [3738f0] | 127 | 
 | 
|---|
| [bd58fb] | 128 |   iterator begin();
 | 
|---|
 | 129 |   const_iterator begin() const;
 | 
|---|
| [e87acf] | 130 |   iterator end();
 | 
|---|
 | 131 |   const_iterator end() const;
 | 
|---|
| [9879f6] | 132 |   bool empty() const;
 | 
|---|
 | 133 |   size_t size() const;
 | 
|---|
| [e4afb4] | 134 |   const_iterator find(atom * key) const;
 | 
|---|
 | 135 |   pair<iterator, bool> insert(atom * const key);
 | 
|---|
| [6cfa36] | 136 |   bool containsAtom(atom* key);
 | 
|---|
| [bd58fb] | 137 | 
 | 
|---|
| [2e4105] | 138 | private:
 | 
|---|
 | 139 |   friend void atom::removeFromMolecule();
 | 
|---|
 | 140 |   /** Erase an atom from the list.
 | 
|---|
 | 141 |    * \note This should only be called by atom::removeFromMolecule(),
 | 
|---|
 | 142 |    * otherwise it is not assured that the atom knows about it.
 | 
|---|
 | 143 |    *
 | 
|---|
 | 144 |    * @param loc locator to atom in list
 | 
|---|
 | 145 |    * @return iterator to just after removed item (compliant with standard)
 | 
|---|
 | 146 |    */
 | 
|---|
 | 147 |   const_iterator erase(const_iterator loc);
 | 
|---|
 | 148 |   /** Erase an atom from the list.
 | 
|---|
 | 149 |    * \note This should only be called by atom::removeFromMolecule(),
 | 
|---|
 | 150 |    * otherwise it is not assured that the atom knows about it.
 | 
|---|
 | 151 |    *
 | 
|---|
 | 152 |    * @param *key key to atom in list
 | 
|---|
 | 153 |    * @return iterator to just after removed item (compliant with standard)
 | 
|---|
 | 154 |    */
 | 
|---|
 | 155 |   const_iterator erase(atom * key);
 | 
|---|
 | 156 | 
 | 
|---|
 | 157 | public:
 | 
|---|
 | 158 | 
 | 
|---|
| [042f82] | 159 |   /// remove atoms from molecule.
 | 
|---|
 | 160 |   bool AddAtom(atom *pointer);
 | 
|---|
 | 161 |   bool RemoveAtom(atom *pointer);
 | 
|---|
 | 162 |   bool UnlinkAtom(atom *pointer);
 | 
|---|
 | 163 |   bool CleanupMolecule();
 | 
|---|
| [9df680] | 164 |   void removeAtomsinMolecule();
 | 
|---|
| [042f82] | 165 | 
 | 
|---|
 | 166 |   /// Add/remove atoms to/from molecule.
 | 
|---|
 | 167 |   atom * AddCopyAtom(atom *pointer);
 | 
|---|
 | 168 |   bool AddXYZFile(string filename);
 | 
|---|
| [e138de] | 169 |   bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
 | 
|---|
| [cee0b57] | 170 |   bond * AddBond(atom *first, atom *second, int degree = 1);
 | 
|---|
| [042f82] | 171 |   bool RemoveBond(bond *pointer);
 | 
|---|
 | 172 |   bool RemoveBonds(atom *BondPartner);
 | 
|---|
| [e4afb4] | 173 |   bool hasBondStructure() const;
 | 
|---|
| [042f82] | 174 | 
 | 
|---|
 | 175 |   /// Find atoms.
 | 
|---|
 | 176 |   atom * FindAtom(int Nr) const;
 | 
|---|
 | 177 |   atom * AskAtom(string text);
 | 
|---|
 | 178 | 
 | 
|---|
 | 179 |   /// Count and change present atoms' coordination.
 | 
|---|
| [e138de] | 180 |   bool CenterInBox();
 | 
|---|
 | 181 |   bool BoundInBox();
 | 
|---|
 | 182 |   void CenterEdge(Vector *max);
 | 
|---|
 | 183 |   void CenterOrigin();
 | 
|---|
 | 184 |   void CenterPeriodic();
 | 
|---|
 | 185 |   void CenterAtVector(Vector *newcenter);
 | 
|---|
| [042f82] | 186 |   void Translate(const Vector *x);
 | 
|---|
 | 187 |   void TranslatePeriodically(const Vector *trans);
 | 
|---|
 | 188 |   void Mirror(const Vector *x);
 | 
|---|
 | 189 |   void Align(Vector *n);
 | 
|---|
| [776b64] | 190 |   void Scale(const double ** const factor);
 | 
|---|
| [437922] | 191 |   void DeterminePeriodicCenter(Vector ¢er);
 | 
|---|
| [4bb63c] | 192 |   Vector * DetermineCenterOfGravity() const;
 | 
|---|
| [e138de] | 193 |   Vector * DetermineCenterOfAll() const;
 | 
|---|
| [eddea2] | 194 |   Vector * DetermineCenterOfBox() const;
 | 
|---|
| [437922] | 195 |   void SetNameFromFilename(const char *filename);
 | 
|---|
| [042f82] | 196 |   void SetBoxDimension(Vector *dim);
 | 
|---|
| [3c58f8] | 197 |   bool ScanForPeriodicCorrection();
 | 
|---|
| [e138de] | 198 |   double VolumeOfConvexEnvelope(bool IsAngstroem);
 | 
|---|
| [1f91f4] | 199 |   RealSpaceMatrix getInertiaTensor() const;
 | 
|---|
 | 200 |   void RotateToPrincipalAxisSystem(Vector &Axis);
 | 
|---|
| [042f82] | 201 | 
 | 
|---|
 | 202 |   bool CheckBounds(const Vector *x) const;
 | 
|---|
 | 203 |   void GetAlignvector(struct lsq_params * par) const;
 | 
|---|
 | 204 | 
 | 
|---|
 | 205 |   /// Initialising routines in fragmentation
 | 
|---|
| [e138de] | 206 |   void OutputBondsList() const;
 | 
|---|
| [49c059] | 207 | 
 | 
|---|
| [266237] | 208 |   bond * CopyBond(atom *left, atom *right, bond *CopyBond);
 | 
|---|
 | 209 | 
 | 
|---|
| [e4afb4] | 210 |   molecule *CopyMolecule() const;
 | 
|---|
| [c550dd] | 211 |   molecule* CopyMoleculeFromSubRegion(const Shape&) const;
 | 
|---|
| [042f82] | 212 | 
 | 
|---|
 | 213 |   /// Fragment molecule by two different approaches:
 | 
|---|
| [49c059] | 214 |   int FragmentMolecule(int Order, std::string &prefix, DepthFirstSearchAnalysis &DFS);
 | 
|---|
| [e73ad9a] | 215 |   bool CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, std::string path = "");
 | 
|---|
| [e4afb4] | 216 |   bool StoreBondsToFile(std::string filename, std::string path = "");
 | 
|---|
 | 217 |   bool StoreAdjacencyToFile(std::string filename, std::string path = "");
 | 
|---|
| [35b698] | 218 |   bool ParseOrderAtSiteFromFile(std::string &path);
 | 
|---|
 | 219 |   bool StoreOrderAtSiteFile(std::string &path);
 | 
|---|
 | 220 |   bool StoreForcesFile(MoleculeListClass *BondFragments, std::string &path, int *SortIndex);
 | 
|---|
| [e138de] | 221 |   bool CreateMappingLabelsToConfigSequence(int *&SortIndex);
 | 
|---|
| [9879f6] | 222 |   bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
 | 
|---|
| [b9772a] | 223 | 
 | 
|---|
| [042f82] | 224 |   /// -# BOSSANOVA
 | 
|---|
| [e73ad9a] | 225 |   void FragmentBOSSANOVA(Graph *&FragmentList, KeyStack &RootStack);
 | 
|---|
| [e138de] | 226 |   int PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
 | 
|---|
 | 227 |   molecule * StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem);
 | 
|---|
| [03c77c] | 228 |   void SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder);
 | 
|---|
| [e138de] | 229 |   int LookForRemovalCandidate(KeySet *&Leaf, int *&ShortestPathList);
 | 
|---|
 | 230 |   int GuesstimateFragmentCount(int order);
 | 
|---|
| [042f82] | 231 | 
 | 
|---|
 | 232 |   // Recognize doubly appearing molecules in a list of them
 | 
|---|
| [e138de] | 233 |   int * GetFatherSonAtomicMap(molecule *OtherMolecule);
 | 
|---|
| [99752a] | 234 |   bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
 | 
|---|
| [c6123b] | 235 |   bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount);
 | 
|---|
| [042f82] | 236 | 
 | 
|---|
 | 237 |   // Output routines.
 | 
|---|
| [e4afb4] | 238 |   bool Output(std::ostream * const output) const;
 | 
|---|
 | 239 |   bool OutputTrajectories(ofstream * const output) const;
 | 
|---|
| [e138de] | 240 |   void OutputListOfBonds() const;
 | 
|---|
 | 241 |   bool OutputXYZ(ofstream * const output) const;
 | 
|---|
 | 242 |   bool OutputTrajectoriesXYZ(ofstream * const output);
 | 
|---|
 | 243 |   bool Checkout(ofstream * const output) const;
 | 
|---|
| [042f82] | 244 | 
 | 
|---|
| [c68025] | 245 |   // Manipulation routines
 | 
|---|
 | 246 |   void flipActiveFlag();
 | 
|---|
 | 247 | 
 | 
|---|
| [e4afb4] | 248 | private:
 | 
|---|
 | 249 |   int last_atom; //!< number given to last atom
 | 
|---|
| [14de469] | 250 | };
 | 
|---|
 | 251 | 
 | 
|---|
| [cbc5fb] | 252 | molecule *NewMolecule();
 | 
|---|
 | 253 | void DeleteMolecule(molecule* mol);
 | 
|---|
 | 254 | 
 | 
|---|
| [14de469] | 255 | /** A list of \a molecule classes.
 | 
|---|
 | 256 |  */
 | 
|---|
| [e4afb4] | 257 | class MoleculeListClass : public Observable
 | 
|---|
 | 258 | {
 | 
|---|
 | 259 | public:
 | 
|---|
 | 260 |   MoleculeList ListOfMolecules; //!< List of the contained molecules
 | 
|---|
 | 261 |   int MaxIndex;
 | 
|---|
| [042f82] | 262 | 
 | 
|---|
| [cbc5fb] | 263 |   MoleculeListClass(World *world);
 | 
|---|
| [042f82] | 264 |   ~MoleculeListClass();
 | 
|---|
 | 265 | 
 | 
|---|
| [35b698] | 266 |   bool AddHydrogenCorrection(std::string &path);
 | 
|---|
 | 267 |   bool StoreForcesFile(std::string &path, int *SortIndex);
 | 
|---|
| [437922] | 268 |   void insert(molecule *mol);
 | 
|---|
| [bd6bfa] | 269 |   void erase(molecule *mol);
 | 
|---|
| [042f82] | 270 |   molecule * ReturnIndex(int index);
 | 
|---|
| [35b698] | 271 |   bool OutputConfigForListOfFragments(std::string &prefix, int *SortIndex);
 | 
|---|
| [042f82] | 272 |   int NumberOfActiveMolecules();
 | 
|---|
| [24a5e0] | 273 |   void Enumerate(ostream *out);
 | 
|---|
| [042f82] | 274 |   void Output(ofstream *out);
 | 
|---|
| [568be7] | 275 |   int CountAllAtoms() const;
 | 
|---|
| [042f82] | 276 | 
 | 
|---|
| [477bb2] | 277 |   // Methods moved here from the menus
 | 
|---|
 | 278 |   // TODO: more refactoring needed on these methods
 | 
|---|
 | 279 |   void createNewMolecule(periodentafel *periode);
 | 
|---|
 | 280 |   void loadFromXYZ(periodentafel *periode);
 | 
|---|
 | 281 |   void setMoleculeFilename();
 | 
|---|
 | 282 |   void parseXYZIntoMolecule();
 | 
|---|
 | 283 |   void eraseMolecule();
 | 
|---|
 | 284 | 
 | 
|---|
| [e4afb4] | 285 | private:
 | 
|---|
| [cbc5fb] | 286 |   World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor
 | 
|---|
| [14de469] | 287 | };
 | 
|---|
 | 288 | 
 | 
|---|
 | 289 | /** A leaf for a tree of \a molecule class
 | 
|---|
 | 290 |  * Wraps molecules in a tree structure
 | 
|---|
 | 291 |  */
 | 
|---|
| [e4afb4] | 292 | class MoleculeLeafClass
 | 
|---|
 | 293 | {
 | 
|---|
 | 294 | public:
 | 
|---|
 | 295 |   molecule *Leaf; //!< molecule of this leaf
 | 
|---|
 | 296 |   //MoleculeLeafClass *UpLeaf;        //!< Leaf one level up
 | 
|---|
 | 297 |   //MoleculeLeafClass *DownLeaf;      //!< First leaf one level down
 | 
|---|
 | 298 |   MoleculeLeafClass *previous; //!< Previous leaf on this level
 | 
|---|
 | 299 |   MoleculeLeafClass *next; //!< Next leaf on this level
 | 
|---|
| [042f82] | 300 | 
 | 
|---|
 | 301 |   //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
 | 
|---|
 | 302 |   MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
 | 
|---|
 | 303 |   ~MoleculeLeafClass();
 | 
|---|
 | 304 | 
 | 
|---|
 | 305 |   bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
 | 
|---|
| [e138de] | 306 |   bool FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
 | 
|---|
 | 307 |   bool AssignKeySetsToFragment(molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
 | 
|---|
 | 308 |   void TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
 | 
|---|
| [042f82] | 309 |   int Count() const;
 | 
|---|
| [14de469] | 310 | };
 | 
|---|
 | 311 | 
 | 
|---|
 | 312 | #endif /*MOLECULES_HPP_*/
 | 
|---|
 | 313 | 
 | 
|---|