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