source: src/molecule.hpp@ e65246

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

New function atom::CorrectFactor() and atom::EqualsFather().

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