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