source: src/molecules.hpp@ 357fba

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

Huge refactoring of Tesselation routines, but not finished yet.

  • new file tesselation.cpp with all of classes tesselation, Boundary..Set and CandidatesForTesselationOB
  • new file tesselationhelper.cpp with all auxiliary functions.
  • boundary.cpp just contains super functions, combininb molecule and Tesselation pointers
  • new pointer molecule::TesselStruct
  • PointMap, LineMap, TriangleMap DistanceMap have been moved from molecules.hpp to tesselation.hpp
  • new abstract class PointCloud and TesselPoint
  • atom inherits TesselPoint
  • molecule inherits PointCloud (i.e. a set of TesselPoints) and implements all virtual functions for the chained list
  • TriangleFilesWritten is thrown out, intermediate steps are written in find_nonconvex_border and not in find_next_triangle()
  • LinkedCell class uses TesselPoint as its nodes, i.e. as long as any class inherits TesselPoint, it may make use of LinkedCell as well and a PointCloud is used to initialize
  • class atom and bond definitions have been moved to own header files

NOTE: This is not bugfree yet. Tesselation of heptan produces way too many triangles, but runs without faults or leaks.

  • Property mode set to 100755
File size: 16.6 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#include <gsl/gsl_randist.h>
19
20// STL headers
21#include <map>
22#include <set>
23#include <deque>
24#include <list>
25#include <vector>
26
27#include "atom.hpp"
28#include "bond.hpp"
29#include "helpers.hpp"
30#include "linkedcell.hpp"
31#include "parser.hpp"
32#include "periodentafel.hpp"
33#include "stackclass.hpp"
34#include "tesselation.hpp"
35#include "vector.hpp"
36
37class config;
38class molecule;
39class MoleculeLeafClass;
40class MoleculeListClass;
41class Verbose;
42
43/******************************** Some definitions for easier reading **********************************/
44
45#define KeyStack deque<int>
46#define KeySet set<int>
47#define NumberValuePair pair<int, double>
48#define Graph map <KeySet, NumberValuePair, KeyCompare >
49#define GraphPair pair <KeySet, NumberValuePair >
50#define KeySetTestPair pair<KeySet::iterator, bool>
51#define GraphTestPair pair<Graph::iterator, bool>
52
53#define DistancePair pair < double, atom* >
54#define DistanceMap multimap < double, atom* >
55#define DistanceTestPair pair < DistanceMap::iterator, bool>
56
57#define Boundaries map <double, DistancePair >
58#define BoundariesPair pair<double, DistancePair >
59#define BoundariesTestPair pair< Boundaries::iterator, bool>
60
61#define MoleculeList list <molecule *>
62#define MoleculeListTest pair <MoleculeList::iterator, bool>
63
64#define LinkedAtoms list <atom *>
65
66/******************************** Some small functions and/or structures **********************************/
67
68struct KeyCompare
69{
70 bool operator() (const KeySet SubgraphA, const KeySet SubgraphB) const;
71};
72
73struct Trajectory
74{
75 vector<Vector> R; //!< position vector
76 vector<Vector> U; //!< velocity vector
77 vector<Vector> F; //!< last force vector
78 atom *ptr; //!< pointer to atom whose trajectory we contain
79};
80
81//bool operator < (KeySet SubgraphA, KeySet SubgraphB); //note: this declaration is important, otherwise normal < is used (producing wrong order)
82inline void InsertFragmentIntoGraph(ofstream *out, struct UniqueFragments *Fragment); // Insert a KeySet into a Graph
83inline void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter); // Insert all KeySet's in a Graph into another Graph
84int CompareDoubles (const void * a, const void * b);
85
86
87/************************************* Class definitions ****************************************/
88
89
90// some algebraic matrix stuff
91#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
92#define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2)) //!< hard-coded determinant of a 2x2 matrix
93
94
95/** Parameter structure for least square minimsation.
96 */
97struct LSQ_params {
98 Vector **vectors;
99 int num;
100};
101
102double LSQ(const gsl_vector * x, void * params);
103
104/** Parameter structure for least square minimsation.
105 */
106struct lsq_params {
107 gsl_vector *x;
108 const molecule *mol;
109 element *type;
110};
111
112
113#define MaxThermostats 6 //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented
114enum thermostats { None, Woodcock, Gaussian, Langevin, Berendsen, NoseHoover }; //!< Thermostat names for output
115
116
117/** The complete molecule.
118 * Class incorporates number of types
119 */
120class molecule : public PointCloud {
121 public:
122 double cell_size[6];//!< cell size
123 periodentafel *elemente; //!< periodic table with each element
124 atom *start; //!< start of atom list
125 atom *end; //!< end of atom list
126 bond *first; //!< start of bond list
127 bond *last; //!< end of bond list
128 bond ***ListOfBondsPerAtom; //!< pointer list for each atom and each bond it has
129 map<atom *, struct Trajectory> Trajectories; //!< contains old trajectory points
130 int MDSteps; //!< The number of MD steps in Trajectories
131 int *NumberOfBondsPerAtom; //!< Number of Bonds each atom has
132 int AtomCount; //!< number of atoms, brought up-to-date by CountAtoms()
133 int BondCount; //!< number of atoms, brought up-to-date by CountBonds()
134 int ElementCount; //!< how many unique elements are therein
135 int ElementsInMolecule[MAX_ELEMENTS]; //!< list whether element (sorted by atomic number) is alread present or not
136 int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
137 int NoNonBonds; //!< number of non-hydrogen bonds in molecule
138 int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
139 double BondDistance; //!< typical bond distance used in CreateAdjacencyList() and furtheron
140 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
141 Vector Center; //!< Center of molecule in a global box
142 char name[MAXSTRINGSIZE]; //!< arbitrary name
143 int IndexNr; //!< index of molecule in a MoleculeListClass
144 class Tesselation *TesselStruct;
145
146 molecule(periodentafel *teil);
147 ~molecule();
148
149 // re-definition of virtual functions from PointCloud
150 Vector *GetCenter(ofstream *out);
151 TesselPoint *GetPoint();
152 TesselPoint *GetTerminalPoint();
153 void GoToNext();
154 void GoToPrevious();
155 void GoToFirst();
156 void GoToLast();
157 bool IsEmpty();
158 bool IsLast();
159
160 /// remove atoms from molecule.
161 bool AddAtom(atom *pointer);
162 bool RemoveAtom(atom *pointer);
163 bool UnlinkAtom(atom *pointer);
164 bool CleanupMolecule();
165
166 /// Add/remove atoms to/from molecule.
167 atom * AddCopyAtom(atom *pointer);
168 bool AddXYZFile(string filename);
169 bool AddHydrogenReplacementAtom(ofstream *out, bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bond **BondList, int NumBond, bool IsAngstroem);
170 bond * AddBond(atom *first, atom *second, int degree);
171 bool RemoveBond(bond *pointer);
172 bool RemoveBonds(atom *BondPartner);
173
174 /// Find atoms.
175 atom * FindAtom(int Nr) const;
176 atom * AskAtom(string text);
177
178 /// Count and change present atoms' coordination.
179 void CountAtoms(ofstream *out);
180 void CountElements();
181 void CalculateOrbitals(class config &configuration);
182 bool CenterInBox(ofstream *out);
183 void CenterEdge(ofstream *out, Vector *max);
184 void CenterOrigin(ofstream *out);
185 void CenterPeriodic(ofstream *out);
186 void CenterAtVector(ofstream *out, Vector *newcenter);
187 void Translate(const Vector *x);
188 void TranslatePeriodically(const Vector *trans);
189 void Mirror(const Vector *x);
190 void Align(Vector *n);
191 void Scale(double **factor);
192 void DeterminePeriodicCenter(Vector &center);
193 Vector * DetermineCenterOfGravity(ofstream *out);
194 Vector * DetermineCenterOfAll(ofstream *out);
195 void SetNameFromFilename(const char *filename);
196 void SetBoxDimension(Vector *dim);
197 double * ReturnFullMatrixforSymmetric(double *cell_size);
198 void ScanForPeriodicCorrection(ofstream *out);
199 bool VerletForceIntegration(ofstream *out, char *file, config &configuration);
200 void Thermostats(config &configuration, double ActualTemp, int Thermostat);
201 void PrincipalAxisSystem(ofstream *out, bool DoRotate);
202 double VolumeOfConvexEnvelope(ofstream *out, bool IsAngstroem);
203 Vector* FindEmbeddingHole(ofstream *out, molecule *srcmol);
204
205
206 double ConstrainedPotential(ofstream *out, atom **permutation, int start, int end, double *constants, bool IsAngstroem);
207 double MinimiseConstrainedPotential(ofstream *out, atom **&permutation, int startstep, int endstep, bool IsAngstroem);
208 void EvaluateConstrainedForces(ofstream *out, int startstep, int endstep, atom **PermutationMap, ForceMatrix *Force);
209 bool LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration);
210
211 bool CheckBounds(const Vector *x) const;
212 void GetAlignvector(struct lsq_params * par) const;
213
214 /// Initialising routines in fragmentation
215 void CreateAdjacencyList2(ofstream *out, ifstream *output);
216 void CreateAdjacencyList(ofstream *out, double bonddistance, bool IsAngstroem);
217 void CreateListOfBondsPerAtom(ofstream *out);
218
219 // Graph analysis
220 MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, class StackClass<bond *> *&BackEdgeStack);
221 void CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *BackEdgeStack, int *&MinimumRingSize);
222 bool PickLocalBackEdges(ofstream *out, atom **ListOfLocalAtoms, class StackClass<bond *> *&ReferenceStack, class StackClass<bond *> *&LocalStack);
223 bond * FindNextUnused(atom *vertex);
224 void SetNextComponentNumber(atom *vertex, int nr);
225 void InitComponentNumbers();
226 void OutputComponentNumber(ofstream *out, atom *vertex);
227 void ResetAllBondsToUnused();
228 void ResetAllAtomNumbers();
229 int CountCyclicBonds(ofstream *out);
230 bool CheckForConnectedSubgraph(ofstream *out, KeySet *Fragment);
231 string GetColor(enum Shading color);
232
233 molecule *CopyMolecule();
234
235 /// Fragment molecule by two different approaches:
236 int FragmentMolecule(ofstream *out, int Order, config *configuration);
237 bool CheckOrderAtSite(ofstream *out, bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path = NULL);
238 bool StoreAdjacencyToFile(ofstream *out, char *path);
239 bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms);
240 bool ParseOrderAtSiteFromFile(ofstream *out, char *path);
241 bool StoreOrderAtSiteFile(ofstream *out, char *path);
242 bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList);
243 bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path);
244 bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex);
245 bool CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex);
246 bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet);
247 void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
248 /// -# BOSSANOVA
249 void FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
250 int PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
251 bool BuildInducedSubgraph(ofstream *out, const molecule *Father);
252 molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem);
253 void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder);
254 int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList);
255 int GuesstimateFragmentCount(ofstream *out, int order);
256
257 // Recognize doubly appearing molecules in a list of them
258 int * IsEqualToWithinThreshold(ofstream *out, molecule *OtherMolecule, double threshold);
259 int * GetFatherSonAtomicMap(ofstream *out, molecule *OtherMolecule);
260
261 // Output routines.
262 bool Output(ofstream *out);
263 bool OutputTrajectories(ofstream *out);
264 void OutputListOfBonds(ofstream *out) const;
265 bool OutputXYZ(ofstream *out) const;
266 bool OutputTrajectoriesXYZ(ofstream *out);
267 bool Checkout(ofstream *out) const;
268 bool OutputTemperatureFromTrajectories(ofstream *out, int startstep, int endstep, ofstream *output);
269
270 private:
271 int last_atom; //!< number given to last atom
272 atom *InternalPointer; //!< internal pointer for PointCloud
273};
274
275/** A list of \a molecule classes.
276 */
277class MoleculeListClass {
278 public:
279 MoleculeList ListOfMolecules; //!< List of the contained molecules
280 int MaxIndex;
281
282 MoleculeListClass();
283 ~MoleculeListClass();
284
285 bool AddHydrogenCorrection(ofstream *out, char *path);
286 bool StoreForcesFile(ofstream *out, char *path, int *SortIndex);
287 void insert(molecule *mol);
288 molecule * ReturnIndex(int index);
289 bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex);
290 int NumberOfActiveMolecules();
291 void Enumerate(ofstream *out);
292 void Output(ofstream *out);
293
294 // merging of molecules
295 bool SimpleMerge(molecule *mol, molecule *srcmol);
296 bool SimpleAdd(molecule *mol, molecule *srcmol);
297 bool SimpleMultiMerge(molecule *mol, int *src, int N);
298 bool SimpleMultiAdd(molecule *mol, int *src, int N);
299 bool ScatterMerge(molecule *mol, int *src, int N);
300 bool EmbedMerge(molecule *mol, molecule *srcmol);
301
302 private:
303};
304
305
306/** A leaf for a tree of \a molecule class
307 * Wraps molecules in a tree structure
308 */
309class MoleculeLeafClass {
310 public:
311 molecule *Leaf; //!< molecule of this leaf
312 //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
313 //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
314 MoleculeLeafClass *previous; //!< Previous leaf on this level
315 MoleculeLeafClass *next; //!< Next leaf on this level
316
317 //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
318 MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
319 ~MoleculeLeafClass();
320
321 bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
322 bool FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList = false);
323 bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
324 bool AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
325 bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList);
326 void TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
327 int Count() const;
328};
329
330class ConfigFileBuffer {
331 public:
332 char **buffer;
333 int *LineMapping;
334 int CurrentLine;
335 int NoLines;
336
337 ConfigFileBuffer();
338 ConfigFileBuffer(char *filename);
339 ~ConfigFileBuffer();
340
341 void InitMapping();
342 void MapIonTypesInBuffer(int NoAtoms);
343};
344
345
346/** The config file.
347 * The class contains all parameters that control a dft run also functions to load and save.
348 */
349class config {
350 public:
351 int PsiType;
352 int MaxPsiDouble;
353 int PsiMaxNoUp;
354 int PsiMaxNoDown;
355 int MaxMinStopStep;
356 int InitMaxMinStopStep;
357 int ProcPEGamma;
358 int ProcPEPsi;
359 char *configpath;
360 char *configname;
361 bool FastParsing;
362 double Deltat;
363 string basis;
364
365 char *databasepath;
366
367 int DoConstrainedMD;
368 int MaxOuterStep;
369 int Thermostat;
370 int *ThermostatImplemented;
371 char **ThermostatNames;
372 double TempFrequency;
373 double alpha;
374 double HooverMass;
375 double TargetTemp;
376 int ScaleTempStep;
377
378 private:
379 char *mainname;
380 char *defaultpath;
381 char *pseudopotpath;
382
383 int DoOutVis;
384 int DoOutMes;
385 int DoOutNICS;
386 int DoOutOrbitals;
387 int DoOutCurrent;
388 int DoFullCurrent;
389 int DoPerturbation;
390 int DoWannier;
391 int CommonWannier;
392 double SawtoothStart;
393 int VectorPlane;
394 double VectorCut;
395 int UseAddGramSch;
396 int Seed;
397
398 int OutVisStep;
399 int OutSrcStep;
400 int MaxPsiStep;
401 double EpsWannier;
402
403 int MaxMinStep;
404 double RelEpsTotalEnergy;
405 double RelEpsKineticEnergy;
406 int MaxMinGapStopStep;
407 int MaxInitMinStep;
408 double InitRelEpsTotalEnergy;
409 double InitRelEpsKineticEnergy;
410 int InitMaxMinGapStopStep;
411
412 //double BoxLength[NDIM*NDIM];
413
414 double ECut;
415 int MaxLevel;
416 int RiemannTensor;
417 int LevRFactor;
418 int RiemannLevel;
419 int Lev0Factor;
420 int RTActualUse;
421 int AddPsis;
422
423 double RCut;
424 int StructOpt;
425 int IsAngstroem;
426 int RelativeCoord;
427 int MaxTypes;
428
429
430 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);
431 int ParseForParameter(int verbose, struct ConfigFileBuffer *FileBuffer, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical);
432
433 public:
434 config();
435 ~config();
436
437 int TestSyntax(char *filename, periodentafel *periode, molecule *mol);
438 void Load(char *filename, periodentafel *periode, molecule *mol);
439 void LoadOld(char *filename, periodentafel *periode, molecule *mol);
440 void RetrieveConfigPathAndName(string filename);
441 bool Save(const char *filename, periodentafel *periode, molecule *mol) const;
442 bool SaveMPQC(const char *filename, molecule *mol) const;
443 void Edit();
444 bool GetIsAngstroem() const;
445 char *GetDefaultPath() const;
446 void SetDefaultPath(const char *path);
447 void InitThermostats(class ConfigFileBuffer *fb);
448};
449
450#endif /*MOLECULES_HPP_*/
451
Note: See TracBrowser for help on using the repository browser.