source: molecuilder/src/molecule.hpp@ 104cf4

Last change on this file since 104cf4 was 104cf4, checked in by Frederik Heber <heber@…>, 16 years ago

First half of molecule_dynamics.cpp is refactored into smaller parts.

  • Property mode set to 100755
File size: 19.2 KB
Line 
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
9using namespace std;
10
11/*********************************************** includes ***********************************/
12
13// GSL headers
14#include <gsl/gsl_eigen.h>
15#include <gsl/gsl_heapsort.h>
16#include <gsl/gsl_linalg.h>
17#include <gsl/gsl_matrix.h>
18#include <gsl/gsl_multimin.h>
19#include <gsl/gsl_vector.h>
20#include <gsl/gsl_randist.h>
21
22//// STL headers
23#include <map>
24#include <set>
25#include <deque>
26#include <list>
27#include <vector>
28
29#include "graph.hpp"
30#include "stackclass.hpp"
31#include "tesselation.hpp"
32
33/****************************************** forward declarations *****************************/
34
35class atom;
36class bond;
37class element;
38class ForceMatrix;
39class LinkedCell;
40class molecule;
41class MoleculeLeafClass;
42class MoleculeListClass;
43class periodentafel;
44class Vector;
45
46/******************************** Some definitions for easier reading **********************************/
47
48#define MoleculeList list <molecule *>
49#define MoleculeListTest pair <MoleculeList::iterator, bool>
50
51#define DistancePair pair < double, atom* >
52#define DistanceMap multimap < double, atom* >
53#define DistanceTestPair pair < DistanceMap::iterator, bool>
54
55
56/************************************* Class definitions ****************************************/
57
58/** Structure to contain parameters needed for evaluation of constraint potential.
59 */
60struct EvaluatePotential
61{
62 int startstep; //!< start configuration (MDStep in atom::trajectory)
63 int endstep; //!< end configuration (MDStep in atom::trajectory)
64 atom **PermutationMap; //!< gives target ptr for each atom, array of size molecule::AtomCount (this is "x" in \f$ V^{con}(x) \f$ )
65 DistanceMap **DistanceList; //!< distance list of each atom to each atom
66 DistanceMap::iterator *StepList; //!< iterator to ascend through NearestNeighbours \a **DistanceList
67 int *DoubleList; //!< count of which sources want to move to this target, basically the injective measure (>1 -> not injective)
68 DistanceMap::iterator *DistanceIterators; //!< marks which was the last picked target as injective candidate with smallest distance
69 bool IsAngstroem; //!< whether coordinates are in angstroem (true) or bohrradius (false)
70 double *PenaltyConstants; //!< penalty constant in front of each term
71};
72
73#define MaxThermostats 6 //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented
74enum thermostats { None, Woodcock, Gaussian, Langevin, Berendsen, NoseHoover }; //!< Thermostat names for output
75
76
77/** The complete molecule.
78 * Class incorporates number of types
79 */
80class molecule : public PointCloud {
81 public:
82 double cell_size[6];//!< cell size
83 periodentafel *elemente; //!< periodic table with each element
84 atom *start; //!< start of atom list
85 atom *end; //!< end of atom list
86 bond *first; //!< start of bond list
87 bond *last; //!< end of bond list
88 bond ***ListOfBondsPerAtom; //!< pointer list for each atom and each bond it has
89 int MDSteps; //!< The number of MD steps in Trajectories
90 int *NumberOfBondsPerAtom; //!< Number of Bonds each atom has
91 int AtomCount; //!< number of atoms, brought up-to-date by CountAtoms()
92 int BondCount; //!< number of atoms, brought up-to-date by CountBonds()
93 int ElementCount; //!< how many unique elements are therein
94 int ElementsInMolecule[MAX_ELEMENTS]; //!< list whether element (sorted by atomic number) is alread present or not
95 int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
96 int NoNonBonds; //!< number of non-hydrogen bonds in molecule
97 int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
98 double BondDistance; //!< typical bond distance used in CreateAdjacencyList() and furtheron
99 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
100 Vector Center; //!< Center of molecule in a global box
101 char name[MAXSTRINGSIZE]; //!< arbitrary name
102 int IndexNr; //!< index of molecule in a MoleculeListClass
103 class Tesselation *TesselStruct;
104
105 molecule(periodentafel *teil);
106 virtual ~molecule();
107
108 // re-definition of virtual functions from PointCloud
109 Vector *GetCenter(ofstream *out);
110 TesselPoint *GetPoint();
111 TesselPoint *GetTerminalPoint();
112 void GoToNext();
113 void GoToPrevious();
114 void GoToFirst();
115 void GoToLast();
116 bool IsEmpty();
117 bool IsEnd();
118
119 // templates for allowing global manipulation of all vectors
120 template <typename res> void ActOnAllVectors( res (Vector::*f)() );
121 template <typename res> void ActOnAllVectors( res (Vector::*f)() const);
122 template <typename res> void ActOnAllVectors( res (Vector::*f)() ) const;
123 template <typename res> void ActOnAllVectors( res (Vector::*f)() const) const;
124 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T), T t );
125 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T) const, T t );
126 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T), T t ) const;
127 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T) const, T t ) const;
128 template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U), T t, U u );
129 template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u );
130 template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const;
131 template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const;
132 template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v);
133 template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V) const, T t, U u, V v);
134 template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v) const;
135 template <typename res, typename T, typename U, typename V> void ActOnAllVectors( res (Vector::*f)(T, U, V) const, T t, U u, V v) const;
136
137 // templates for allowing global manipulation of molecule with each atom as single argument
138 template <typename res> void ActWithEachAtom( res (molecule::*f)(atom *) );
139 template <typename res> void ActWithEachAtom( res (molecule::*f)(atom *) const);
140 template <typename res> void ActWithEachAtom( res (molecule::*f)(atom *) ) const;
141 template <typename res> void ActWithEachAtom( res (molecule::*f)(atom *) const) const;
142
143 // templates for allowing global copying of molecule with each atom as single argument
144 template <typename res> void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy);
145 template <typename res> void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const , molecule *copy);
146 template <typename res> void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy) const;
147 template <typename res> void ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const, molecule *copy) const;
148
149 // templates for allowing global manipulation of all atoms
150 template <typename res> void ActOnAllAtoms( res (atom::*f)() );
151 template <typename res> void ActOnAllAtoms( res (atom::*f)() const );
152 template <typename res> void ActOnAllAtoms( res (atom::*f)() ) const;
153 template <typename res> void ActOnAllAtoms( res (atom::*f)() const) const;
154 template <typename res, typename T> void ActOnAllAtoms( res (atom::*f)(T), T t );
155 template <typename res, typename T> void ActOnAllAtoms( res (atom::*f)(T) const, T t );
156 template <typename res, typename T> void ActOnAllAtoms( res (atom::*f)(T), T t ) const;
157 template <typename res, typename T> void ActOnAllAtoms( res (atom::*f)(T) const, T t ) const;
158 template <typename res, typename T, typename U> void ActOnAllAtoms( res (atom::*f)(T, U), T t, U u );
159 template <typename res, typename T, typename U> void ActOnAllAtoms( res (atom::*f)(T, U) const, T t, U u );
160 template <typename res, typename T, typename U> void ActOnAllAtoms( res (atom::*f)(T, U), T t, U u ) const;
161 template <typename res, typename T, typename U> void ActOnAllAtoms( res (atom::*f)(T, U) const, T t, U u ) const;
162 template <typename res, typename T, typename U, typename V> void ActOnAllAtoms( res (atom::*f)(T, U, V), T t, U u, V v);
163 template <typename res, typename T, typename U, typename V> void ActOnAllAtoms( res (atom::*f)(T, U, V) const, T t, U u, V v);
164 template <typename res, typename T, typename U, typename V> void ActOnAllAtoms( res (atom::*f)(T, U, V), T t, U u, V v) const;
165 template <typename res, typename T, typename U, typename V> void ActOnAllAtoms( res (atom::*f)(T, U, V) const, T t, U u, V v) const;
166 template <typename res, typename T, typename U, typename V, typename W> void ActOnAllAtoms( res (atom::*f)(T, U, V, W), T t, U u, V v, W w);
167 template <typename res, typename T, typename U, typename V, typename W> void ActOnAllAtoms( res (atom::*f)(T, U, V, W) const, T t, U u, V v, W w);
168 template <typename res, typename T, typename U, typename V, typename W> void ActOnAllAtoms( res (atom::*f)(T, U, V, W), T t, U u, V v, W w) const;
169 template <typename res, typename T, typename U, typename V, typename W> void ActOnAllAtoms( res (atom::*f)(T, U, V, W) const, T t, U u, V v, W w) const;
170
171 // templates for allowing conditional global copying of molecule with each atom as single argument
172 template <typename res> void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () );
173 template <typename res, typename T> void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T), T t );
174 template <typename res, typename T, typename U> void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U), T t, U u );
175 template <typename res, typename T, typename U, typename V> void ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v );
176
177 // templates for allowing global manipulation of an array with one entry per atom
178 template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::* index, void (*Setor)(T *, T));
179 template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::* index, void (*Setor)(T *, T), T t);
180 template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T));
181 template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T), T t);
182 template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::* index, T (atom::*Setor)(Vector &), Vector atom::*value);
183 template <typename T> void SetIndexedArrayForEachAtomTo ( T *array, int TesselPoint::*index, T (atom::*Setor)(Vector &), Vector &vect );
184
185 /// remove atoms from molecule.
186 bool AddAtom(atom *pointer);
187 bool RemoveAtom(atom *pointer);
188 bool UnlinkAtom(atom *pointer);
189 bool CleanupMolecule();
190
191 /// Add/remove atoms to/from molecule.
192 atom * AddCopyAtom(atom *pointer);
193 bool AddXYZFile(string filename);
194 bool AddHydrogenReplacementAtom(ofstream *out, bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bond **BondList, int NumBond, bool IsAngstroem);
195 bond * AddBond(atom *first, atom *second, int degree = 1);
196 bool RemoveBond(bond *pointer);
197 bool RemoveBonds(atom *BondPartner);
198
199 /// Find atoms.
200 atom * FindAtom(int Nr) const;
201 atom * AskAtom(string text);
202
203 /// Count and change present atoms' coordination.
204 void CountAtoms(ofstream *out);
205 void CountElements();
206 void CalculateOrbitals(class config &configuration);
207 bool CenterInBox(ofstream *out);
208 bool BoundInBox(ofstream *out);
209 void CenterEdge(ofstream *out, Vector *max);
210 void CenterOrigin(ofstream *out);
211 void CenterPeriodic(ofstream *out);
212 void CenterAtVector(ofstream *out, Vector *newcenter);
213 void Translate(const Vector *x);
214 void TranslatePeriodically(const Vector *trans);
215 void Mirror(const Vector *x);
216 void Align(Vector *n);
217 void Scale(double **factor);
218 void DeterminePeriodicCenter(Vector &center);
219 Vector * DetermineCenterOfGravity(ofstream *out);
220 Vector * DetermineCenterOfAll(ofstream *out);
221 void SetNameFromFilename(const char *filename);
222 void SetBoxDimension(Vector *dim);
223 void ScanForPeriodicCorrection(ofstream *out);
224 bool VerletForceIntegration(ofstream *out, char *file, config &configuration);
225 void Thermostats(config &configuration, double ActualTemp, int Thermostat);
226 void PrincipalAxisSystem(ofstream *out, bool DoRotate);
227 double VolumeOfConvexEnvelope(ofstream *out, bool IsAngstroem);
228 Vector* FindEmbeddingHole(ofstream *out, molecule *srcmol);
229
230
231 double ConstrainedPotential(ofstream *out, struct EvaluatePotential &Params);
232 double MinimiseConstrainedPotential(ofstream *out, atom **&permutation, int startstep, int endstep, bool IsAngstroem);
233 void EvaluateConstrainedForces(ofstream *out, int startstep, int endstep, atom **PermutationMap, ForceMatrix *Force);
234 bool LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration, bool MapByIdentity);
235
236 bool CheckBounds(const Vector *x) const;
237 void GetAlignvector(struct lsq_params * par) const;
238
239 /// Initialising routines in fragmentation
240 void CreateAdjacencyList2(ofstream *out, ifstream *output);
241 void CreateAdjacencyList(ofstream *out, double bonddistance, bool IsAngstroem);
242 void CreateListOfBondsPerAtom(ofstream *out);
243
244 // Graph analysis
245 MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, class StackClass<bond *> *&BackEdgeStack);
246 void CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *BackEdgeStack, int *&MinimumRingSize);
247 bool PickLocalBackEdges(ofstream *out, atom **ListOfLocalAtoms, class StackClass<bond *> *&ReferenceStack, class StackClass<bond *> *&LocalStack);
248 bond * FindNextUnused(atom *vertex);
249 void SetNextComponentNumber(atom *vertex, int nr);
250 void InitComponentNumbers();
251 void OutputComponentNumber(ofstream *out, atom *vertex);
252 void ResetAllBondsToUnused();
253 void ResetAllAtomNumbers();
254 int CountCyclicBonds(ofstream *out);
255 bool CheckForConnectedSubgraph(ofstream *out, KeySet *Fragment);
256 string GetColor(enum Shading color);
257
258 molecule *CopyMolecule();
259 molecule* CopyMoleculeFromSubRegion(Vector offset, double *parallelepiped);
260
261 /// Fragment molecule by two different approaches:
262 int FragmentMolecule(ofstream *out, int Order, config *configuration);
263 bool CheckOrderAtSite(ofstream *out, bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path = NULL);
264 bool StoreAdjacencyToFile(ofstream *out, char *path);
265 bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms);
266 bool ParseOrderAtSiteFromFile(ofstream *out, char *path);
267 bool StoreOrderAtSiteFile(ofstream *out, char *path);
268 bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList);
269 bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path);
270 bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex);
271 bool CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex);
272 bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet);
273 void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
274 /// -# BOSSANOVA
275 void FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
276 int PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
277 bool BuildInducedSubgraph(ofstream *out, const molecule *Father);
278 molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem);
279 void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder);
280 int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList);
281 int GuesstimateFragmentCount(ofstream *out, int order);
282
283 // Recognize doubly appearing molecules in a list of them
284 int * IsEqualToWithinThreshold(ofstream *out, molecule *OtherMolecule, double threshold);
285 int * GetFatherSonAtomicMap(ofstream *out, molecule *OtherMolecule);
286
287 // Output routines.
288 bool Output(ofstream *out);
289 bool OutputTrajectories(ofstream *out);
290 void OutputListOfBonds(ofstream *out) const;
291 bool OutputXYZ(ofstream *out) const;
292 bool OutputTrajectoriesXYZ(ofstream *out);
293 bool Checkout(ofstream *out) const;
294 bool OutputTemperatureFromTrajectories(ofstream *out, int startstep, int endstep, ofstream *output);
295
296 private:
297 int last_atom; //!< number given to last atom
298 atom *InternalPointer; //!< internal pointer for PointCloud
299};
300
301#include "molecule_template.hpp"
302
303/** A list of \a molecule classes.
304 */
305class MoleculeListClass {
306 public:
307 MoleculeList ListOfMolecules; //!< List of the contained molecules
308 int MaxIndex;
309
310 MoleculeListClass();
311 ~MoleculeListClass();
312
313 bool AddHydrogenCorrection(ofstream *out, char *path);
314 bool StoreForcesFile(ofstream *out, char *path, int *SortIndex);
315 void insert(molecule *mol);
316 molecule * ReturnIndex(int index);
317 bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex);
318 int NumberOfActiveMolecules();
319 void Enumerate(ofstream *out);
320 void Output(ofstream *out);
321
322 // merging of molecules
323 bool SimpleMerge(molecule *mol, molecule *srcmol);
324 bool SimpleAdd(molecule *mol, molecule *srcmol);
325 bool SimpleMultiMerge(molecule *mol, int *src, int N);
326 bool SimpleMultiAdd(molecule *mol, int *src, int N);
327 bool ScatterMerge(molecule *mol, int *src, int N);
328 bool EmbedMerge(molecule *mol, molecule *srcmol);
329
330 private:
331};
332
333
334/** A leaf for a tree of \a molecule class
335 * Wraps molecules in a tree structure
336 */
337class MoleculeLeafClass {
338 public:
339 molecule *Leaf; //!< molecule of this leaf
340 //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
341 //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
342 MoleculeLeafClass *previous; //!< Previous leaf on this level
343 MoleculeLeafClass *next; //!< Next leaf on this level
344
345 //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
346 MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
347 ~MoleculeLeafClass();
348
349 bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
350 bool FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList = false);
351 bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
352 bool AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
353 bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList);
354 void TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
355 int Count() const;
356};
357
358
359#endif /*MOLECULES_HPP_*/
360
Note: See TracBrowser for help on using the repository browser.