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 "AtomIdSet.hpp"
|
---|
26 | #include "Atom/AtomSet.hpp"
|
---|
27 | #include "CodePatterns/Cacheable.hpp"
|
---|
28 | #include "CodePatterns/Observer/Observable.hpp"
|
---|
29 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
30 | #include "Fragmentation/HydrogenSaturation_enum.hpp"
|
---|
31 | #include "Formula.hpp"
|
---|
32 | #include "Helpers/defs.hpp"
|
---|
33 | #include "IdPool_policy.hpp"
|
---|
34 | #include "IdPool.hpp"
|
---|
35 | #include "Shapes/Shape.hpp"
|
---|
36 | #include "types.hpp"
|
---|
37 |
|
---|
38 | /****************************************** forward declarations *****************************/
|
---|
39 |
|
---|
40 | class atom;
|
---|
41 | class bond;
|
---|
42 | class BondedParticle;
|
---|
43 | class BondGraph;
|
---|
44 | class DepthFirstSearchAnalysis;
|
---|
45 | class element;
|
---|
46 | class ForceMatrix;
|
---|
47 | class Graph;
|
---|
48 | class LinkedCell_deprecated;
|
---|
49 | class ListOfLocalAtoms_t;
|
---|
50 | class molecule;
|
---|
51 | class MoleculeLeafClass;
|
---|
52 | class MoleculeListClass;
|
---|
53 | class MoleculeUnittest;
|
---|
54 | class RealSpaceMatrix;
|
---|
55 | class Vector;
|
---|
56 |
|
---|
57 | /************************************* Class definitions ****************************************/
|
---|
58 |
|
---|
59 | /** The complete molecule.
|
---|
60 | * Class incorporates number of types
|
---|
61 | */
|
---|
62 | class molecule : public Observable
|
---|
63 | {
|
---|
64 | //!> grant unit test access
|
---|
65 | friend class MoleculeUnittest;
|
---|
66 | //!> function may access cstor
|
---|
67 | friend molecule *NewMolecule();
|
---|
68 | //!> function may access dstor
|
---|
69 | friend void DeleteMolecule(molecule *);
|
---|
70 |
|
---|
71 | public:
|
---|
72 | typedef AtomIdSet::atomIdSet atomIdSet;
|
---|
73 | typedef AtomIdSet::iterator iterator;
|
---|
74 | typedef AtomIdSet::const_iterator const_iterator;
|
---|
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;
|
---|
85 | Cacheable<size_t> NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
|
---|
86 | Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
|
---|
87 | moleculeId_t id;
|
---|
88 | AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
|
---|
89 | IdPool<atomId_t, uniqueId> atomIdPool; //!< pool of internal ids such that way may guarantee uniqueness
|
---|
90 | typedef std::map<atomId_t,atom *> LocalToGlobalId_t;
|
---|
91 | LocalToGlobalId_t LocalToGlobalId; //!< internal map to ease FindAtom
|
---|
92 |
|
---|
93 | protected:
|
---|
94 |
|
---|
95 | molecule();
|
---|
96 | virtual ~molecule();
|
---|
97 |
|
---|
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,
|
---|
107 | MoleculeNameChanged,
|
---|
108 | NotificationType_MAX
|
---|
109 | };
|
---|
110 |
|
---|
111 | public:
|
---|
112 | //getter and setter
|
---|
113 | const std::string getName() const;
|
---|
114 | int getAtomCount() const;
|
---|
115 | size_t doCountNoNonHydrogen() const;
|
---|
116 | size_t getNoNonHydrogen() const;
|
---|
117 | int getBondCount() const;
|
---|
118 | int doCountBonds() const;
|
---|
119 | moleculeId_t getId() const;
|
---|
120 | void setId(moleculeId_t);
|
---|
121 | void setName(const std::string);
|
---|
122 | const Formula &getFormula() const;
|
---|
123 | unsigned int getElementCount() const;
|
---|
124 | bool hasElement(const element*) const;
|
---|
125 | bool hasElement(atomicNumber_t) const;
|
---|
126 | bool hasElement(const std::string&) const;
|
---|
127 |
|
---|
128 | virtual bool changeId(atomId_t newId);
|
---|
129 |
|
---|
130 | World::AtomComposite getAtomSet() const;
|
---|
131 |
|
---|
132 | // simply pass on all functions to AtomIdSet
|
---|
133 | iterator begin() {
|
---|
134 | return atomIds.begin();
|
---|
135 | }
|
---|
136 | const_iterator begin() const
|
---|
137 | {
|
---|
138 | return atomIds.begin();
|
---|
139 | }
|
---|
140 | iterator end()
|
---|
141 | {
|
---|
142 | return atomIds.end();
|
---|
143 | }
|
---|
144 | const_iterator end() const
|
---|
145 | {
|
---|
146 | return atomIds.end();
|
---|
147 | }
|
---|
148 | bool empty() const
|
---|
149 | {
|
---|
150 | return atomIds.empty();
|
---|
151 | }
|
---|
152 | size_t size() const
|
---|
153 | {
|
---|
154 | return atomIds.size();
|
---|
155 | }
|
---|
156 | const_iterator find(atom * key) const
|
---|
157 | {
|
---|
158 | return atomIds.find(key);
|
---|
159 | }
|
---|
160 |
|
---|
161 | /** Returns the set of atomic ids contained in this molecule.
|
---|
162 | *
|
---|
163 | * @return set of atomic ids
|
---|
164 | */
|
---|
165 | const atomIdSet & getAtomIds() const {
|
---|
166 | return atomIds.getAtomIds();
|
---|
167 | }
|
---|
168 |
|
---|
169 | std::pair<iterator, bool> insert(atom * const key);
|
---|
170 |
|
---|
171 | /** Predicate whether given \a key is contained in this molecule.
|
---|
172 | *
|
---|
173 | * @param key atom to check
|
---|
174 | * @return true - is contained, false - else
|
---|
175 | */
|
---|
176 | bool containsAtom(const atom* key) const
|
---|
177 | {
|
---|
178 | return atomIds.contains(key);
|
---|
179 | }
|
---|
180 |
|
---|
181 | /** Predicate whether given \a id is contained in this molecule.
|
---|
182 | *
|
---|
183 | * @param id atomic id to check
|
---|
184 | * @return true - is contained, false - else
|
---|
185 | */
|
---|
186 | bool containsAtom(const atomId_t id) const
|
---|
187 | {
|
---|
188 | return atomIds.contains(id);
|
---|
189 | }
|
---|
190 |
|
---|
191 | private:
|
---|
192 | friend void atom::removeFromMolecule();
|
---|
193 | /** Erase an atom from the list.
|
---|
194 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
195 | * otherwise it is not assured that the atom knows about it.
|
---|
196 | *
|
---|
197 | * @param loc locator to atom in list
|
---|
198 | * @return iterator to just after removed item (compliant with standard)
|
---|
199 | */
|
---|
200 | const_iterator erase(const_iterator loc);
|
---|
201 |
|
---|
202 | /** Erase an atom from the list.
|
---|
203 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
204 | * otherwise it is not assured that the atom knows about it.
|
---|
205 | *
|
---|
206 | * @param *key key to atom in list
|
---|
207 | * @return iterator to just after removed item (compliant with standard)
|
---|
208 | */
|
---|
209 | const_iterator erase(atom * key);
|
---|
210 |
|
---|
211 | private:
|
---|
212 | friend bool atom::changeNr(int newId);
|
---|
213 | /**
|
---|
214 | * used when changing an ParticleInfo::Nr.
|
---|
215 | * Note that this number is local with this molecule.
|
---|
216 | * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
|
---|
217 | *
|
---|
218 | * @param oldNr old Nr
|
---|
219 | * @param newNr new Nr to set
|
---|
220 | * @param *target ref to atom
|
---|
221 | * @return indicates wether the change could be done or not.
|
---|
222 | */
|
---|
223 | bool changeAtomNr(int oldNr, int newNr, atom* target=0);
|
---|
224 |
|
---|
225 | /** Updates the internal lookup fro local to global indices.
|
---|
226 | *
|
---|
227 | * \param pointer pointer to atom
|
---|
228 | */
|
---|
229 | void InsertLocalToGlobalId(atom * const pointer);
|
---|
230 |
|
---|
231 | /** Sets the name of the atom.
|
---|
232 | *
|
---|
233 | * The name is set via its element symbol and its internal ParticleInfo::Nr.
|
---|
234 | *
|
---|
235 | * @param _atom atom whose name to set
|
---|
236 | */
|
---|
237 | void setAtomName(atom *_atom) const;
|
---|
238 |
|
---|
239 | public:
|
---|
240 |
|
---|
241 | /** Function to create a bounding spherical shape for the currently associated atoms.
|
---|
242 | *
|
---|
243 | * \param boundary extra boundary of shape around (i.e. distance between outermost atom
|
---|
244 | * and the shape's surface)
|
---|
245 | */
|
---|
246 | Shape getBoundingSphere(const double boundary = 0.) const;
|
---|
247 |
|
---|
248 | /** Creates the bounding box by adding van der Waals-Spheres around every atom.
|
---|
249 | *
|
---|
250 | * \param scale extra scale parameter to enlarge the spheres artifically
|
---|
251 | */
|
---|
252 | Shape getBoundingShape(const double scale = 1.) const;
|
---|
253 |
|
---|
254 | /// remove atoms from molecule.
|
---|
255 | bool AddAtom(atom *pointer);
|
---|
256 | bool RemoveAtom(atom *pointer);
|
---|
257 | bool UnlinkAtom(atom *pointer);
|
---|
258 | bool CleanupMolecule();
|
---|
259 | void removeAtomsinMolecule();
|
---|
260 |
|
---|
261 | /// Add/remove atoms to/from molecule.
|
---|
262 | atom * AddCopyAtom(atom *pointer);
|
---|
263 | // bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
|
---|
264 | bond::ptr AddBond(atom *first, atom *second, int degree = 1);
|
---|
265 | bool hasBondStructure() const;
|
---|
266 |
|
---|
267 | /// Find atoms.
|
---|
268 | atom * FindAtom(int Nr) const;
|
---|
269 | atom * AskAtom(std::string text);
|
---|
270 | bool isInMolecule(const atom * const _atom);
|
---|
271 |
|
---|
272 | /// Count and change present atoms' coordination.
|
---|
273 | bool CenterInBox();
|
---|
274 | bool BoundInBox();
|
---|
275 | void CenterEdge(Vector *max);
|
---|
276 | void CenterOrigin();
|
---|
277 | void CenterPeriodic();
|
---|
278 | void CenterAtVector(Vector *newcenter);
|
---|
279 | void Translate(const Vector *x);
|
---|
280 | void TranslatePeriodically(const Vector *trans);
|
---|
281 | void Mirror(const Vector *x);
|
---|
282 | void Align(Vector *n);
|
---|
283 | void Scale(const double ** const factor);
|
---|
284 | void DeterminePeriodicCenter(Vector ¢er, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
|
---|
285 | Vector * DetermineCenterOfGravity() const;
|
---|
286 | Vector * DetermineCenterOfAll() const;
|
---|
287 | Vector * DetermineCenterOfBox() const;
|
---|
288 | void SetNameFromFilename(const char *filename);
|
---|
289 | void SetBoxDimension(Vector *dim);
|
---|
290 | bool ScanForPeriodicCorrection();
|
---|
291 | double VolumeOfConvexEnvelope(bool IsAngstroem);
|
---|
292 | RealSpaceMatrix getInertiaTensor() const;
|
---|
293 | void RotateToPrincipalAxisSystem(const Vector &Axis);
|
---|
294 |
|
---|
295 | bool CheckBounds(const Vector *x) const;
|
---|
296 | void GetAlignvector(struct lsq_params * par) const;
|
---|
297 |
|
---|
298 | /// Initialising routines in fragmentation
|
---|
299 | void OutputBondsList() const;
|
---|
300 |
|
---|
301 | bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
|
---|
302 |
|
---|
303 | molecule *CopyMolecule(const Vector &offset = zeroVec) const;
|
---|
304 | molecule* CopyMoleculeFromSubRegion(const Shape&) const;
|
---|
305 |
|
---|
306 | /// Fragment molecule by two different approaches:
|
---|
307 | bool StoreBondsToFile(std::string filename, std::string path = "");
|
---|
308 | bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
|
---|
309 |
|
---|
310 | // Recognize doubly appearing molecules in a list of them
|
---|
311 | int * GetFatherSonAtomicMap(molecule *OtherMolecule);
|
---|
312 | bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
|
---|
313 | bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
|
---|
314 |
|
---|
315 | // Output routines.
|
---|
316 | bool Output(std::ostream * const output) const;
|
---|
317 | void OutputListOfBonds() const;
|
---|
318 |
|
---|
319 | // Manipulation routines
|
---|
320 | void flipActiveFlag();
|
---|
321 |
|
---|
322 | private:
|
---|
323 | int last_atom; //!< number given to last atom
|
---|
324 | };
|
---|
325 |
|
---|
326 | molecule *NewMolecule();
|
---|
327 | void DeleteMolecule(molecule* mol);
|
---|
328 |
|
---|
329 |
|
---|
330 |
|
---|
331 | #endif /*MOLECULES_HPP_*/
|
---|
332 |
|
---|