source: src/molecules.hpp@ a1fe77

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since a1fe77 was a1fe77, checked in by Frederik Heber <heber@…>, 16 years ago

Basic implementation of Constrained MD is done, missing testing.

  • Property mode set to 100644
File size: 17.7 KB
Line 
1/** \file molecules.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// GSL headers
12#include <gsl/gsl_eigen.h>
13#include <gsl/gsl_heapsort.h>
14#include <gsl/gsl_linalg.h>
15#include <gsl/gsl_matrix.h>
16#include <gsl/gsl_multimin.h>
17#include <gsl/gsl_vector.h>
18
19// STL headers
20#include <map>
21#include <set>
22#include <deque>
23#include <list>
24#include <vector>
25
26#include "helpers.hpp"
27#include "parser.hpp"
28#include "periodentafel.hpp"
29#include "stackclass.hpp"
30#include "vector.hpp"
31
32class atom;
33class bond;
34class config;
35class molecule;
36class MoleculeListClass;
37class Verbose;
38
39/******************************** Some definitions for easier reading **********************************/
40
41#define KeyStack deque<int>
42#define KeySet set<int>
43#define NumberValuePair pair<int, double>
44#define Graph map <KeySet, NumberValuePair, KeyCompare >
45#define GraphPair pair <KeySet, NumberValuePair >
46#define KeySetTestPair pair<KeySet::iterator, bool>
47#define GraphTestPair pair<Graph::iterator, bool>
48
49#define DistancePair pair < double, atom* >
50#define DistanceMap multimap < double, atom* >
51#define DistanceTestPair pair < DistanceMap::iterator, bool>
52
53#define Boundaries map <double, DistancePair >
54#define BoundariesPair pair<double, DistancePair >
55#define BoundariesTestPair pair< Boundaries::iterator, bool>
56
57#define PointMap map < int, class BoundaryPointSet * >
58#define PointPair pair < int, class BoundaryPointSet * >
59#define PointTestPair pair < PointMap::iterator, bool >
60
61#define LineMap map < int, class BoundaryLineSet * >
62#define LinePair pair < int, class BoundaryLineSet * >
63#define LineTestPair pair < LinePair::iterator, bool >
64
65#define TriangleMap map < int, class BoundaryTriangleSet * >
66#define TrianglePair pair < int, class BoundaryTriangleSet * >
67#define TriangleTestPair pair < TrianglePair::iterator, bool >
68
69#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
70#define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
71
72/******************************** Some small functions and/or structures **********************************/
73
74struct KeyCompare
75{
76 bool operator() (const KeySet SubgraphA, const KeySet SubgraphB) const;
77};
78
79struct Trajectory
80{
81 vector<Vector> R; //!< position vector
82 vector<Vector> U; //!< velocity vector
83 vector<Vector> F; //!< last force vector
84 atom *ptr; //!< pointer to atom whose trajectory we contain
85};
86
87//bool operator < (KeySet SubgraphA, KeySet SubgraphB); //note: this declaration is important, otherwise normal < is used (producing wrong order)
88inline void InsertFragmentIntoGraph(ofstream *out, struct UniqueFragments *Fragment); // Insert a KeySet into a Graph
89inline void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter); // Insert all KeySet's in a Graph into another Graph
90int CompareDoubles (const void * a, const void * b);
91
92
93/************************************* Class definitions ****************************************/
94
95
96// some algebraic matrix stuff
97#define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3]) //!< hard-coded determinant of a 3x3 matrix
98#define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2)) //!< hard-coded determinant of a 2x2 matrix
99
100
101/** Parameter structure for least square minimsation.
102 */
103struct LSQ_params {
104 Vector **vectors;
105 int num;
106};
107
108double LSQ(const gsl_vector * x, void * params);
109
110/** Parameter structure for least square minimsation.
111 */
112struct lsq_params {
113 gsl_vector *x;
114 const molecule *mol;
115 element *type;
116};
117
118
119
120/** Single atom.
121 * Class incoporates position, type
122 */
123class atom {
124 public:
125 Vector x; //!< coordinate array of atom, giving position within cell
126 Vector v; //!< velocity array of atom
127 element *type; //!< pointing to element
128 atom *previous; //!< previous atom in molecule list
129 atom *next; //!< next atom in molecule list
130 atom *father; //!< In many-body bond order fragmentations points to originating atom
131 atom *Ancestor; //!< "Father" in Depth-First-Search
132 char *Name; //!< unique name used during many-body bond-order fragmentation
133 int FixedIon; //!< config variable that states whether forces act on the ion or not
134 int *sort; //!< sort criteria
135 int nr; //!< continuous, unique number
136 int GraphNr; //!< unique number, given in DepthFirstSearchAnalysis()
137 int *ComponentNr;//!< belongs to this nonseparable components, given in DepthFirstSearchAnalysis() (if more than one, then is SeparationVertex)
138 int LowpointNr; //!< needed in DepthFirstSearchAnalysis() to detect nonseparable components, is the lowest possible number of an atom to reach via tree edges only followed by at most one back edge.
139 bool SeparationVertex; //!< whether this atom separates off subsets of atoms or not, determined in DepthFirstSearchAnalysis()
140 bool IsCyclic; //!< whether atom belong to as cycle or not, determined in DepthFirstSearchAnalysis()
141 unsigned char AdaptiveOrder; //!< current present bond order at site (0 means "not set")
142 bool MaxOrder; //!< whether this atom as a root in fragmentation still creates more fragments on higher orders or not
143
144 atom();
145 ~atom();
146
147 bool Output(int ElementNo, int AtomNo, ofstream *out) const;
148 bool OutputXYZLine(ofstream *out) const;
149 atom *GetTrueFather();
150 bool Compare(atom &ptr);
151
152 private:
153};
154
155ostream & operator << (ostream &ost, atom &a);
156
157/** Bonds between atoms.
158 * Class incorporates bonds between atoms in a molecule,
159 * used to derive tge fragments in many-body bond order
160 * calculations.
161 */
162class bond {
163 public:
164 atom *leftatom; //!< first bond partner
165 atom *rightatom; //!< second bond partner
166 bond *previous; //!< previous atom in molecule list
167 bond *next; //!< next atom in molecule list
168 int HydrogenBond; //!< Number of hydrogen atoms in the bond
169 int BondDegree; //!< single, double, triple, ... bond
170 int nr; //!< unique number in a molecule, updated by molecule::CreateAdjacencyList()
171 bool Cyclic; //!< flag whether bond is part of a cycle or not, given in DepthFirstSearchAnalysis()
172 enum EdgeType Type;//!< whether this is a tree or back edge
173
174 atom * GetOtherAtom(atom *Atom) const;
175 bond * GetFirstBond();
176 bond * GetLastBond();
177
178 bool MarkUsed(enum Shading color);
179 enum Shading IsUsed();
180 void ResetUsed();
181 bool Contains(const atom *ptr);
182 bool Contains(const int nr);
183
184 bond();
185 bond(atom *left, atom *right);
186 bond(atom *left, atom *right, int degree);
187 bond(atom *left, atom *right, int degree, int number);
188 ~bond();
189
190 private:
191 enum Shading Used; //!< marker in depth-first search, DepthFirstSearchAnalysis()
192};
193
194ostream & operator << (ostream &ost, bond &b);
195
196class MoleculeLeafClass;
197
198/** The complete molecule.
199 * Class incorporates number of types
200 */
201class molecule {
202 public:
203 double cell_size[6];//!< cell size
204 periodentafel *elemente; //!< periodic table with each element
205 atom *start; //!< start of atom list
206 atom *end; //!< end of atom list
207 bond *first; //!< start of bond list
208 bond *last; //!< end of bond list
209 bond ***ListOfBondsPerAtom; //!< pointer list for each atom and each bond it has
210 map<atom *, struct Trajectory> Trajectories; //!< contains old trajectory points
211 int MDSteps; //!< The number of MD steps in Trajectories
212 int *NumberOfBondsPerAtom; //!< Number of Bonds each atom has
213 int AtomCount; //!< number of atoms, brought up-to-date by CountAtoms()
214 int BondCount; //!< number of atoms, brought up-to-date by CountBonds()
215 int ElementCount; //!< how many unique elements are therein
216 int ElementsInMolecule[MAX_ELEMENTS]; //!< list whether element (sorted by atomic number) is alread present or not
217 int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
218 int NoNonBonds; //!< number of non-hydrogen bonds in molecule
219 int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
220 double BondDistance; //!< typical bond distance used in CreateAdjacencyList() and furtheron
221
222 molecule(periodentafel *teil);
223 ~molecule();
224
225 /// remove atoms from molecule.
226 bool AddAtom(atom *pointer);
227 bool RemoveAtom(atom *pointer);
228 bool CleanupMolecule();
229
230 /// Add/remove atoms to/from molecule.
231 atom * AddCopyAtom(atom *pointer);
232 bool AddXYZFile(string filename);
233 bool AddHydrogenReplacementAtom(ofstream *out, bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bond **BondList, int NumBond, bool IsAngstroem);
234 bond * AddBond(atom *first, atom *second, int degree);
235 bool RemoveBond(bond *pointer);
236 bool RemoveBonds(atom *BondPartner);
237
238 /// Find atoms.
239 atom * FindAtom(int Nr) const;
240 atom * AskAtom(string text);
241
242 /// Count and change present atoms' coordination.
243 void CountAtoms(ofstream *out);
244 void CountElements();
245 void CalculateOrbitals(class config &configuration);
246 bool CenterInBox(ofstream *out, Vector *BoxLengths);
247 void CenterEdge(ofstream *out, Vector *max);
248 void CenterOrigin(ofstream *out, Vector *max);
249 void CenterGravity(ofstream *out, Vector *max);
250 void Translate(const Vector *x);
251 void Mirror(const Vector *x);
252 void Align(Vector *n);
253 void Scale(double **factor);
254 void DetermineCenter(Vector &center);
255 Vector * DetermineCenterOfGravity(ofstream *out);
256 Vector * DetermineCenterOfAll(ofstream *out);
257 void SetBoxDimension(Vector *dim);
258 double * ReturnFullMatrixforSymmetric(double *cell_size);
259 void ScanForPeriodicCorrection(ofstream *out);
260 void PrincipalAxisSystem(ofstream *out, bool DoRotate);
261 double VolumeOfConvexEnvelope(ofstream *out, bool IsAngstroem);
262 bool VerletForceIntegration(ofstream *out, char *file, double delta_t, bool IsAngstroem, int DoConstrained);
263 double ConstrainedPotential(ofstream *out, atom **permutation, int start, int end, double *constants, bool IsAngstroem);
264 double MinimiseConstrainedPotential(ofstream *out, ForceMatrix *Force, int startstep, int endstep, bool IsAngstroem);
265
266 bool CheckBounds(const Vector *x) const;
267 void GetAlignvector(struct lsq_params * par) const;
268
269 /// Initialising routines in fragmentation
270 void CreateAdjacencyList(ofstream *out, double bonddistance, bool IsAngstroem);
271 void CreateListOfBondsPerAtom(ofstream *out);
272
273 // Graph analysis
274 MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, int *&MinimumRingSize);
275 void CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *BackEdgeStack, int *&MinimumRingSize);
276 bond * FindNextUnused(atom *vertex);
277 void SetNextComponentNumber(atom *vertex, int nr);
278 void InitComponentNumbers();
279 void OutputComponentNumber(ofstream *out, atom *vertex);
280 void ResetAllBondsToUnused();
281 void ResetAllAtomNumbers();
282 int CountCyclicBonds(ofstream *out);
283 bool CheckForConnectedSubgraph(ofstream *out, KeySet *Fragment);
284 string GetColor(enum Shading color);
285
286 molecule *CopyMolecule();
287
288 /// Fragment molecule by two different approaches:
289 int FragmentMolecule(ofstream *out, int Order, config *configuration);
290 bool CheckOrderAtSite(ofstream *out, bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path = NULL);
291 bool StoreAdjacencyToFile(ofstream *out, char *path);
292 bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms);
293 bool ParseOrderAtSiteFromFile(ofstream *out, char *path);
294 bool StoreOrderAtSiteFile(ofstream *out, char *path);
295 bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList);
296 bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path);
297 bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex);
298 bool CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex);
299 bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet);
300 void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
301 /// -# BOSSANOVA
302 void FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
303 int PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
304 bool BuildInducedSubgraph(ofstream *out, const molecule *Father);
305 molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem);
306 void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder);
307 int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList);
308 int GuesstimateFragmentCount(ofstream *out, int order);
309
310 // Recognize doubly appearing molecules in a list of them
311 int * IsEqualToWithinThreshold(ofstream *out, molecule *OtherMolecule, double threshold);
312 int * GetFatherSonAtomicMap(ofstream *out, molecule *OtherMolecule);
313
314 // Output routines.
315 bool Output(ofstream *out);
316 bool OutputTrajectories(ofstream *out);
317 void OutputListOfBonds(ofstream *out) const;
318 bool OutputXYZ(ofstream *out) const;
319 bool OutputTrajectoriesXYZ(ofstream *out);
320 bool Checkout(ofstream *out) const;
321 bool OutputTemperatureFromTrajectories(ofstream *out, int startstep, int endstep, ofstream *output);
322
323 private:
324 int last_atom; //!< number given to last atom
325};
326
327/** A list of \a molecule classes.
328 */
329class MoleculeListClass {
330 public:
331 molecule **ListOfMolecules; //!< pointer list of fragment molecules to check for equality
332 int NumberOfMolecules; //!< Number of entries in \a **FragmentList and of to be returned one.
333 int NumberOfTopAtoms; //!< Number of atoms in the molecule from which all fragments originate
334
335 MoleculeListClass();
336 MoleculeListClass(int Num, int NumAtoms);
337 ~MoleculeListClass();
338
339 /// Output configs.
340 bool AddHydrogenCorrection(ofstream *out, char *path);
341 bool StoreForcesFile(ofstream *out, char *path, int *SortIndex);
342 bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex);
343 void Output(ofstream *out);
344
345 private:
346};
347
348
349/** A leaf for a tree of \a molecule class
350 * Wraps molecules in a tree structure
351 */
352class MoleculeLeafClass {
353 public:
354 molecule *Leaf; //!< molecule of this leaf
355 //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
356 //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
357 MoleculeLeafClass *previous; //!< Previous leaf on this level
358 MoleculeLeafClass *next; //!< Next leaf on this level
359
360 //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
361 MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
362 ~MoleculeLeafClass();
363
364 bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
365 bool FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList = false);
366 bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
367 bool AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
368 bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, int &FragmentCounter, int GlobalAtomCount, bool &FreeList);
369 void TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
370 int Count() const;
371};
372
373/** The config file.
374 * The class contains all parameters that control a dft run also functions to load and save.
375 */
376class config {
377 public:
378 int PsiType;
379 int MaxPsiDouble;
380 int PsiMaxNoUp;
381 int PsiMaxNoDown;
382 int MaxMinStopStep;
383 int InitMaxMinStopStep;
384 int ProcPEGamma;
385 int ProcPEPsi;
386 char *configpath;
387 char *configname;
388 bool FastParsing;
389 double Deltat;
390 int DoConstrainedMD;
391
392 private:
393 char *mainname;
394 char *defaultpath;
395 char *pseudopotpath;
396
397 int DoOutVis;
398 int DoOutMes;
399 int DoOutNICS;
400 int DoOutOrbitals;
401 int DoOutCurrent;
402 int DoFullCurrent;
403 int DoPerturbation;
404 int DoWannier;
405 int CommonWannier;
406 double SawtoothStart;
407 int VectorPlane;
408 double VectorCut;
409 int UseAddGramSch;
410 int Seed;
411
412 int MaxOuterStep;
413 int OutVisStep;
414 int OutSrcStep;
415 double TargetTemp;
416 int ScaleTempStep;
417 int MaxPsiStep;
418 double EpsWannier;
419
420 int MaxMinStep;
421 double RelEpsTotalEnergy;
422 double RelEpsKineticEnergy;
423 int MaxMinGapStopStep;
424 int MaxInitMinStep;
425 double InitRelEpsTotalEnergy;
426 double InitRelEpsKineticEnergy;
427 int InitMaxMinGapStopStep;
428
429 //double BoxLength[NDIM*NDIM];
430
431 double ECut;
432 int MaxLevel;
433 int RiemannTensor;
434 int LevRFactor;
435 int RiemannLevel;
436 int Lev0Factor;
437 int RTActualUse;
438 int AddPsis;
439
440 double RCut;
441 int StructOpt;
442 int IsAngstroem;
443 int RelativeCoord;
444 int MaxTypes;
445
446
447 int ParseForParameter(int verbose, ifstream *file, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical);
448
449 public:
450 config();
451 ~config();
452
453 int TestSyntax(char *filename, periodentafel *periode, molecule *mol);
454 void Load(char *filename, periodentafel *periode, molecule *mol);
455 void LoadOld(char *filename, periodentafel *periode, molecule *mol);
456 void RetrieveConfigPathAndName(string filename);
457 bool Save(ofstream *file, periodentafel *periode, molecule *mol) const;
458 bool SaveMPQC(ofstream *file, molecule *mol) const;
459 void Edit(molecule *mol);
460 bool GetIsAngstroem() const;
461 char *GetDefaultPath() const;
462 void SetDefaultPath(const char *path);
463};
464
465#endif /*MOLECULES_HPP_*/
466
Note: See TracBrowser for help on using the repository browser.