source: src/analysis_correlation.cpp@ 273382

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 273382 was 273382, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Prepared interface of Vector Class for transition to VectorComposites

  • Property mode set to 100644
File size: 18.7 KB
Line 
1/*
2 * analysis.cpp
3 *
4 * Created on: Oct 13, 2009
5 * Author: heber
6 */
7
8#include <iostream>
9
10#include "analysis_correlation.hpp"
11#include "element.hpp"
12#include "info.hpp"
13#include "log.hpp"
14#include "molecule.hpp"
15#include "tesselation.hpp"
16#include "tesselationhelpers.hpp"
17#include "vector.hpp"
18#include "verbose.hpp"
19
20
21/** Calculates the pair correlation between given elements.
22 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
23 * \param *out output stream for debugging
24 * \param *molecules list of molecules structure
25 * \param *type1 first element or NULL (if any element)
26 * \param *type2 second element or NULL (if any element)
27 * \return Map of doubles with values the pair of the two atoms.
28 */
29PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2 )
30{
31 Info FunctionInfo(__func__);
32 PairCorrelationMap *outmap = NULL;
33 double distance = 0.;
34
35 if (molecules->ListOfMolecules.empty()) {
36 eLog() << Verbose(1) <<"No molecule given." << endl;
37 return outmap;
38 }
39 outmap = new PairCorrelationMap;
40 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
41 if ((*MolWalker)->ActiveFlag) {
42 eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
43 atom *Walker = (*MolWalker)->start;
44 while (Walker->next != (*MolWalker)->end) {
45 Walker = Walker->next;
46 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
47 if ((type1 == NULL) || (Walker->type == type1)) {
48 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
49 if ((*MolOtherWalker)->ActiveFlag) {
50 Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl;
51 atom *OtherWalker = (*MolOtherWalker)->start;
52 while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
53 OtherWalker = OtherWalker->next;
54 Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;
55 if (Walker->nr < OtherWalker->nr)
56 if ((type2 == NULL) || (OtherWalker->type == type2)) {
57 distance = Walker->node->PeriodicDistance(*(OtherWalker->node), (*MolWalker)->cell_size);
58 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
59 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
60 }
61 }
62 }
63 }
64 }
65 }
66
67 return outmap;
68};
69
70/** Calculates the pair correlation between given elements.
71 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
72 * \param *out output stream for debugging
73 * \param *molecules list of molecules structure
74 * \param *type1 first element or NULL (if any element)
75 * \param *type2 second element or NULL (if any element)
76 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
77 * \return Map of doubles with values the pair of the two atoms.
78 */
79PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] )
80{
81 Info FunctionInfo(__func__);
82 PairCorrelationMap *outmap = NULL;
83 double distance = 0.;
84 int n[NDIM];
85 Vector checkX;
86 Vector periodicX;
87 int Othern[NDIM];
88 Vector checkOtherX;
89 Vector periodicOtherX;
90
91 if (molecules->ListOfMolecules.empty()) {
92 eLog() << Verbose(1) <<"No molecule given." << endl;
93 return outmap;
94 }
95 outmap = new PairCorrelationMap;
96 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
97 if ((*MolWalker)->ActiveFlag) {
98 double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
99 double * FullInverseMatrix = InverseMatrix(FullMatrix);
100 eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
101 atom *Walker = (*MolWalker)->start;
102 while (Walker->next != (*MolWalker)->end) {
103 Walker = Walker->next;
104 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
105 if ((type1 == NULL) || (Walker->type == type1)) {
106 periodicX = *(Walker->node);
107 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
108 // go through every range in xyz and get distance
109 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
110 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
111 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
112 checkX = Vector(n[0], n[1], n[2]) + periodicX;
113 checkX.MatrixMultiplication(FullMatrix);
114 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
115 if ((*MolOtherWalker)->ActiveFlag) {
116 Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl;
117 atom *OtherWalker = (*MolOtherWalker)->start;
118 while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
119 OtherWalker = OtherWalker->next;
120 Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;
121 if (Walker->nr < OtherWalker->nr)
122 if ((type2 == NULL) || (OtherWalker->type == type2)) {
123 periodicOtherX = *(OtherWalker->node);
124 periodicOtherX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
125 // go through every range in xyz and get distance
126 for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
127 for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
128 for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
129 checkOtherX = Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX;
130 checkOtherX.MatrixMultiplication(FullMatrix);
131 distance = checkX.Distance(checkOtherX);
132 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
133 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
134 }
135 }
136 }
137 }
138 }
139 }
140 }
141 Free(&FullMatrix);
142 Free(&FullInverseMatrix);
143 }
144
145 return outmap;
146};
147
148/** Calculates the distance (pair) correlation between a given element and a point.
149 * \param *out output stream for debugging
150 * \param *molecules list of molecules structure
151 * \param *type element or NULL (if any element)
152 * \param *point vector to the correlation point
153 * \return Map of dobules with values as pairs of atom and the vector
154 */
155CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point )
156{
157 Info FunctionInfo(__func__);
158 CorrelationToPointMap *outmap = NULL;
159 double distance = 0.;
160
161 if (molecules->ListOfMolecules.empty()) {
162 Log() << Verbose(1) <<"No molecule given." << endl;
163 return outmap;
164 }
165 outmap = new CorrelationToPointMap;
166 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
167 if ((*MolWalker)->ActiveFlag) {
168 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
169 atom *Walker = (*MolWalker)->start;
170 while (Walker->next != (*MolWalker)->end) {
171 Walker = Walker->next;
172 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
173 if ((type == NULL) || (Walker->type == type)) {
174 distance = Walker->node->PeriodicDistance(*point, (*MolWalker)->cell_size);
175 Log() << Verbose(4) << "Current distance is " << distance << "." << endl;
176 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
177 }
178 }
179 }
180
181 return outmap;
182};
183
184/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
185 * \param *out output stream for debugging
186 * \param *molecules list of molecules structure
187 * \param *type element or NULL (if any element)
188 * \param *point vector to the correlation point
189 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
190 * \return Map of dobules with values as pairs of atom and the vector
191 */
192CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] )
193{
194 Info FunctionInfo(__func__);
195 CorrelationToPointMap *outmap = NULL;
196 double distance = 0.;
197 int n[NDIM];
198 Vector periodicX;
199 Vector checkX;
200
201 if (molecules->ListOfMolecules.empty()) {
202 Log() << Verbose(1) <<"No molecule given." << endl;
203 return outmap;
204 }
205 outmap = new CorrelationToPointMap;
206 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
207 if ((*MolWalker)->ActiveFlag) {
208 double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
209 double * FullInverseMatrix = InverseMatrix(FullMatrix);
210 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
211 atom *Walker = (*MolWalker)->start;
212 while (Walker->next != (*MolWalker)->end) {
213 Walker = Walker->next;
214 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
215 if ((type == NULL) || (Walker->type == type)) {
216 periodicX = *(Walker->node);
217 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
218 // go through every range in xyz and get distance
219 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
220 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
221 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
222 checkX = Vector(n[0], n[1], n[2]) + periodicX;
223 checkX.MatrixMultiplication(FullMatrix);
224 distance = checkX.Distance(*point);
225 Log() << Verbose(4) << "Current distance is " << distance << "." << endl;
226 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
227 }
228 }
229 }
230 Free(&FullMatrix);
231 Free(&FullInverseMatrix);
232 }
233
234 return outmap;
235};
236
237/** Calculates the distance (pair) correlation between a given element and a surface.
238 * \param *out output stream for debugging
239 * \param *molecules list of molecules structure
240 * \param *type element or NULL (if any element)
241 * \param *Surface pointer to Tesselation class surface
242 * \param *LC LinkedCell structure to quickly find neighbouring atoms
243 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
244 */
245CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC )
246{
247 Info FunctionInfo(__func__);
248 CorrelationToSurfaceMap *outmap = NULL;
249 double distance = 0;
250 class BoundaryTriangleSet *triangle = NULL;
251 Vector centroid;
252
253 if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
254 Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl;
255 return outmap;
256 }
257 outmap = new CorrelationToSurfaceMap;
258 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
259 if ((*MolWalker)->ActiveFlag) {
260 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
261 atom *Walker = (*MolWalker)->start;
262 while (Walker->next != (*MolWalker)->end) {
263 Walker = Walker->next;
264 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
265 if ((type == NULL) || (Walker->type == type)) {
266 triangle = Surface->FindClosestTriangleToVector(Walker->node, LC );
267 if (triangle != NULL) {
268 distance = DistanceToTrianglePlane(Walker->node, triangle);
269 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
270 }
271 }
272 }
273 }
274
275 return outmap;
276};
277
278/** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
279 * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
280 * I.e. We multiply the atom::node with the inverse of the domain matrix, i.e. transform it to \f$[0,0^3\f$, then add per
281 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
282 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
283 * \param *out output stream for debugging
284 * \param *molecules list of molecules structure
285 * \param *type element or NULL (if any element)
286 * \param *Surface pointer to Tesselation class surface
287 * \param *LC LinkedCell structure to quickly find neighbouring atoms
288 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
289 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
290 */
291CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
292{
293 Info FunctionInfo(__func__);
294 CorrelationToSurfaceMap *outmap = NULL;
295 double distance = 0;
296 class BoundaryTriangleSet *triangle = NULL;
297 Vector centroid;
298 int n[NDIM];
299 Vector periodicX;
300 Vector checkX;
301
302 if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
303 Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl;
304 return outmap;
305 }
306 outmap = new CorrelationToSurfaceMap;
307 double ShortestDistance = 0.;
308 BoundaryTriangleSet *ShortestTriangle = NULL;
309 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
310 if ((*MolWalker)->ActiveFlag) {
311 double * FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
312 double * FullInverseMatrix = InverseMatrix(FullMatrix);
313 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
314 atom *Walker = (*MolWalker)->start;
315 while (Walker->next != (*MolWalker)->end) {
316 Walker = Walker->next;
317 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
318 if ((type == NULL) || (Walker->type == type)) {
319 periodicX = *(Walker->node);
320 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
321 // go through every range in xyz and get distance
322 ShortestDistance = -1.;
323 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
324 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
325 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
326 checkX = Vector(n[0], n[1], n[2]) + periodicX;
327 checkX.MatrixMultiplication(FullMatrix);
328 triangle = Surface->FindClosestTriangleToVector(&checkX, LC);
329 distance = Surface->GetDistanceSquaredToTriangle(checkX, triangle);
330 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
331 ShortestDistance = distance;
332 ShortestTriangle = triangle;
333 }
334 }
335 // insert
336 ShortestDistance = sqrt(ShortestDistance);
337 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (Walker, ShortestTriangle) ) );
338 //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
339 }
340 }
341 Free(&FullMatrix);
342 Free(&FullInverseMatrix);
343 }
344
345 return outmap;
346};
347
348/** Returns the start of the bin for a given value.
349 * \param value value whose bin to look for
350 * \param BinWidth width of bin
351 * \param BinStart first bin
352 */
353double GetBin ( const double value, const double BinWidth, const double BinStart )
354{
355 Info FunctionInfo(__func__);
356 double bin =(double) (floor((value - BinStart)/BinWidth));
357 return (bin*BinWidth+BinStart);
358};
359
360
361/** Prints correlation (double, int) pairs to file.
362 * \param *file file to write to
363 * \param *map map to write
364 */
365void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
366{
367 Info FunctionInfo(__func__);
368 *file << "BinStart\tCount" << endl;
369 for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
370 *file << runner->first << "\t" << runner->second << endl;
371 }
372};
373
374/** Prints correlation (double, (atom*,atom*) ) pairs to file.
375 * \param *file file to write to
376 * \param *map map to write
377 */
378void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
379{
380 Info FunctionInfo(__func__);
381 *file << "BinStart\tAtom1\tAtom2" << endl;
382 for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
383 *file << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
384 }
385};
386
387/** Prints correlation (double, int) pairs to file.
388 * \param *file file to write to
389 * \param *map map to write
390 */
391void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
392{
393 Info FunctionInfo(__func__);
394 *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
395 for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
396 *file << runner->first;
397 for (int i=0;i<NDIM;i++)
398 *file << "\t" << (runner->second.first->node->at(i) - runner->second.second->at(i));
399 *file << endl;
400 }
401};
402
403/** Prints correlation (double, int) pairs to file.
404 * \param *file file to write to
405 * \param *map map to write
406 */
407void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
408{
409 Info FunctionInfo(__func__);
410 *file << "BinStart\tTriangle" << endl;
411 for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
412 *file << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
413 }
414};
415
Note: See TracBrowser for help on using the repository browser.