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 "types.hpp"
|
---|
36 |
|
---|
37 | /****************************************** forward declarations *****************************/
|
---|
38 |
|
---|
39 | class atom;
|
---|
40 | class bond;
|
---|
41 | class BondedParticle;
|
---|
42 | class BondGraph;
|
---|
43 | class DepthFirstSearchAnalysis;
|
---|
44 | class element;
|
---|
45 | class ForceMatrix;
|
---|
46 | class Graph;
|
---|
47 | class LinkedCell_deprecated;
|
---|
48 | class molecule;
|
---|
49 | class MoleculeLeafClass;
|
---|
50 | class MoleculeListClass;
|
---|
51 | class periodentafel;
|
---|
52 | class RealSpaceMatrix;
|
---|
53 | class Vector;
|
---|
54 | class Shape;
|
---|
55 |
|
---|
56 | /************************************* Class definitions ****************************************/
|
---|
57 |
|
---|
58 | /** The complete molecule.
|
---|
59 | * Class incorporates number of types
|
---|
60 | */
|
---|
61 | class molecule : public Observable
|
---|
62 | {
|
---|
63 | friend molecule *NewMolecule();
|
---|
64 | friend void DeleteMolecule(molecule *);
|
---|
65 |
|
---|
66 | public:
|
---|
67 | typedef AtomIdSet::atomIdSet atomIdSet;
|
---|
68 | typedef AtomIdSet::iterator iterator;
|
---|
69 | typedef AtomIdSet::const_iterator const_iterator;
|
---|
70 |
|
---|
71 | int MDSteps; //!< The number of MD steps in Trajectories
|
---|
72 | mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
|
---|
73 | mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
|
---|
74 | mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
|
---|
75 | bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
|
---|
76 | int IndexNr; //!< index of molecule in a MoleculeListClass
|
---|
77 | char name[MAXSTRINGSIZE]; //!< arbitrary name
|
---|
78 |
|
---|
79 | private:
|
---|
80 | Formula formula;
|
---|
81 | Cacheable<int> AtomCount; //!< number of atoms, brought up-to-date by doCountAtoms()
|
---|
82 | Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
|
---|
83 | moleculeId_t id;
|
---|
84 | AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
|
---|
85 | IdPool<atomId_t, uniqueId> atomIdPool; //!< pool of internal ids such that way may guarantee uniqueness
|
---|
86 |
|
---|
87 | protected:
|
---|
88 |
|
---|
89 | molecule();
|
---|
90 | virtual ~molecule();
|
---|
91 |
|
---|
92 | public:
|
---|
93 | //getter and setter
|
---|
94 | const std::string getName() const;
|
---|
95 | int getAtomCount() const;
|
---|
96 | int doCountAtoms();
|
---|
97 | int getBondCount() const;
|
---|
98 | int doCountBonds() const;
|
---|
99 | moleculeId_t getId() const;
|
---|
100 | void setId(moleculeId_t);
|
---|
101 | void setName(const std::string);
|
---|
102 | const Formula &getFormula() const;
|
---|
103 | unsigned int getElementCount() const;
|
---|
104 | bool hasElement(const element*) const;
|
---|
105 | bool hasElement(atomicNumber_t) const;
|
---|
106 | bool hasElement(const std::string&) const;
|
---|
107 |
|
---|
108 | virtual bool changeId(atomId_t newId);
|
---|
109 |
|
---|
110 | World::AtomComposite getAtomSet() const;
|
---|
111 |
|
---|
112 | // simply pass on all functions to AtomIdSet
|
---|
113 | iterator begin() {
|
---|
114 | return atomIds.begin();
|
---|
115 | }
|
---|
116 | const_iterator begin() const
|
---|
117 | {
|
---|
118 | return atomIds.begin();
|
---|
119 | }
|
---|
120 | iterator end()
|
---|
121 | {
|
---|
122 | return atomIds.end();
|
---|
123 | }
|
---|
124 | const_iterator end() const
|
---|
125 | {
|
---|
126 | return atomIds.end();
|
---|
127 | }
|
---|
128 | bool empty() const
|
---|
129 | {
|
---|
130 | return atomIds.empty();
|
---|
131 | }
|
---|
132 | size_t size() const
|
---|
133 | {
|
---|
134 | return atomIds.size();
|
---|
135 | }
|
---|
136 | const_iterator find(atom * key) const
|
---|
137 | {
|
---|
138 | return atomIds.find(key);
|
---|
139 | }
|
---|
140 | const atomIdSet & getAtomIds() const {
|
---|
141 | return atomIds.getAtomIds();
|
---|
142 | }
|
---|
143 |
|
---|
144 | std::pair<iterator, bool> insert(atom * const key);
|
---|
145 |
|
---|
146 | bool containsAtom(atom* key);
|
---|
147 |
|
---|
148 | private:
|
---|
149 | friend void atom::removeFromMolecule();
|
---|
150 | /** Erase an atom from the list.
|
---|
151 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
152 | * otherwise it is not assured that the atom knows about it.
|
---|
153 | *
|
---|
154 | * @param loc locator to atom in list
|
---|
155 | * @return iterator to just after removed item (compliant with standard)
|
---|
156 | */
|
---|
157 | const_iterator erase(const_iterator loc);
|
---|
158 |
|
---|
159 | /** Erase an atom from the list.
|
---|
160 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
161 | * otherwise it is not assured that the atom knows about it.
|
---|
162 | *
|
---|
163 | * @param *key key to atom in list
|
---|
164 | * @return iterator to just after removed item (compliant with standard)
|
---|
165 | */
|
---|
166 | const_iterator erase(atom * key);
|
---|
167 |
|
---|
168 | private:
|
---|
169 | friend bool atom::changeNr(int newId);
|
---|
170 | /**
|
---|
171 | * used when changing an ParticleInfo::Nr.
|
---|
172 | * Note that this number is local with this molecule.
|
---|
173 | * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
|
---|
174 | *
|
---|
175 | * @param oldNr old Nr
|
---|
176 | * @param newNr new Nr to set
|
---|
177 | * @param *target ref to atom
|
---|
178 | * @return indicates wether the change could be done or not.
|
---|
179 | */
|
---|
180 | bool changeAtomNr(int oldNr, int newNr, atom* target=0);
|
---|
181 |
|
---|
182 | /** Sets the name of the atom.
|
---|
183 | *
|
---|
184 | * The name is set via its element symbol and its internal ParticleInfo::Nr.
|
---|
185 | *
|
---|
186 | * @param _atom atom whose name to set
|
---|
187 | */
|
---|
188 | void setAtomName(atom *_atom) const;
|
---|
189 |
|
---|
190 | public:
|
---|
191 |
|
---|
192 | /// remove atoms from molecule.
|
---|
193 | bool AddAtom(atom *pointer);
|
---|
194 | bool RemoveAtom(atom *pointer);
|
---|
195 | bool UnlinkAtom(atom *pointer);
|
---|
196 | bool CleanupMolecule();
|
---|
197 | void removeAtomsinMolecule();
|
---|
198 |
|
---|
199 | /// Add/remove atoms to/from molecule.
|
---|
200 | atom * AddCopyAtom(atom *pointer);
|
---|
201 | bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
|
---|
202 | bond * AddBond(atom *first, atom *second, int degree = 1);
|
---|
203 | bool RemoveBond(bond *pointer);
|
---|
204 | bool RemoveBonds(atom *BondPartner);
|
---|
205 | bool hasBondStructure() const;
|
---|
206 |
|
---|
207 | /// Find atoms.
|
---|
208 | atom * FindAtom(int Nr) const;
|
---|
209 | atom * AskAtom(std::string text);
|
---|
210 | bool isInMolecule(const atom * const _atom);
|
---|
211 |
|
---|
212 | /// Count and change present atoms' coordination.
|
---|
213 | bool CenterInBox();
|
---|
214 | bool BoundInBox();
|
---|
215 | void CenterEdge(Vector *max);
|
---|
216 | void CenterOrigin();
|
---|
217 | void CenterPeriodic();
|
---|
218 | void CenterAtVector(Vector *newcenter);
|
---|
219 | void Translate(const Vector *x);
|
---|
220 | void TranslatePeriodically(const Vector *trans);
|
---|
221 | void Mirror(const Vector *x);
|
---|
222 | void Align(Vector *n);
|
---|
223 | void Scale(const double ** const factor);
|
---|
224 | void DeterminePeriodicCenter(Vector ¢er, const enum HydrogenSaturation _saturation = DoSaturate);
|
---|
225 | Vector * DetermineCenterOfGravity() const;
|
---|
226 | Vector * DetermineCenterOfAll() const;
|
---|
227 | Vector * DetermineCenterOfBox() const;
|
---|
228 | void SetNameFromFilename(const char *filename);
|
---|
229 | void SetBoxDimension(Vector *dim);
|
---|
230 | bool ScanForPeriodicCorrection();
|
---|
231 | double VolumeOfConvexEnvelope(bool IsAngstroem);
|
---|
232 | RealSpaceMatrix getInertiaTensor() const;
|
---|
233 | void RotateToPrincipalAxisSystem(Vector &Axis);
|
---|
234 |
|
---|
235 | bool CheckBounds(const Vector *x) const;
|
---|
236 | void GetAlignvector(struct lsq_params * par) const;
|
---|
237 |
|
---|
238 | /// Initialising routines in fragmentation
|
---|
239 | void OutputBondsList() const;
|
---|
240 |
|
---|
241 | bond * CopyBond(atom *left, atom *right, bond *CopyBond);
|
---|
242 |
|
---|
243 | molecule *CopyMolecule() const;
|
---|
244 | molecule* CopyMoleculeFromSubRegion(const Shape&) const;
|
---|
245 |
|
---|
246 | /// Fragment molecule by two different approaches:
|
---|
247 | bool StoreBondsToFile(std::string filename, std::string path = "");
|
---|
248 | bool StoreAdjacencyToFile(std::string filename, std::string path = "");
|
---|
249 | bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
|
---|
250 |
|
---|
251 | // Recognize doubly appearing molecules in a list of them
|
---|
252 | int * GetFatherSonAtomicMap(molecule *OtherMolecule);
|
---|
253 | bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
|
---|
254 | bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount);
|
---|
255 |
|
---|
256 | // Output routines.
|
---|
257 | bool Output(std::ostream * const output) const;
|
---|
258 | bool OutputTrajectories(ofstream * const output) const;
|
---|
259 | void OutputListOfBonds() const;
|
---|
260 | bool OutputXYZ(ofstream * const output) const;
|
---|
261 | bool OutputTrajectoriesXYZ(ofstream * const output);
|
---|
262 | bool Checkout(ofstream * const output) const;
|
---|
263 |
|
---|
264 | // Manipulation routines
|
---|
265 | void flipActiveFlag();
|
---|
266 |
|
---|
267 | private:
|
---|
268 | int last_atom; //!< number given to last atom
|
---|
269 | };
|
---|
270 |
|
---|
271 | molecule *NewMolecule();
|
---|
272 | void DeleteMolecule(molecule* mol);
|
---|
273 |
|
---|
274 |
|
---|
275 |
|
---|
276 | #endif /*MOLECULES_HPP_*/
|
---|
277 |
|
---|