source: src/molecules.hpp@ e9b8bb

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

Rename of class vector to Vector to avoid conflict with vector from STL.

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