source: src/molecules.hpp@ 958457

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 958457 was 958457, checked in by Frederik Heber <heber@…>, 17 years ago

CheckOrderAtSite: BUGFIX - Added MinimumRingSize to parameter list, as otherwise infinite loop

If FragmentBOSSANOVA checks for remaining below MinimumRingSize per atom, CheckOrderAtSite however does not and fills AtomMask with values for atoms not to be included, we end up with an endless loop. Hence, MinimumRingSize is given as an additional parameter and CheckOrderAtSite checks for it for adaptive and for global increase (for stepwise we don't have the loop problem and FragmentBOSSANOVA will do the right thing).

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