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