source: src/analysis_correlation.cpp@ febef3

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 febef3 was 92e5cb, checked in by Frederik Heber <heber@…>, 14 years ago

Refactored Output..Correlation...() code into a single templated one.

  • template function OutputCorrelationMap() that accepts two function pointers for header and value to print the map's specifics.
  • all other function have been refactored into these two output functions per CorrelationMap type.

TESTFIXES:

  • Property mode set to 100644
File size: 25.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * analysis.cpp
10 *
11 * Created on: Oct 13, 2009
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include <iostream>
23#include <iomanip>
24
25#include "atom.hpp"
26#include "bond.hpp"
27#include "BoundaryTriangleSet.hpp"
28#include "Box.hpp"
29#include "element.hpp"
30#include "CodePatterns/Info.hpp"
31#include "CodePatterns/Log.hpp"
32#include "Formula.hpp"
33#include "molecule.hpp"
34#include "tesselation.hpp"
35#include "tesselationhelpers.hpp"
36#include "triangleintersectionlist.hpp"
37#include "World.hpp"
38#include "LinearAlgebra/Vector.hpp"
39#include "LinearAlgebra/RealSpaceMatrix.hpp"
40#include "CodePatterns/Verbose.hpp"
41#include "World.hpp"
42#include "Box.hpp"
43
44#include "analysis_correlation.hpp"
45
46/** Calculates the dipole vector of a given atomSet.
47 *
48 * Note that we use the following procedure as rule of thumb:
49 * -# go through every bond of the atom
50 * -# calculate the difference of electronegativities \f$\Delta\text{EN}\f$
51 * -# if \f$\Delta\text{EN} > 0.5\f$, we align the bond vector in direction of the more negative element
52 * -# sum up all vectors
53 * -# finally, divide by the number of summed vectors
54 *
55 * @param atomsbegin begin iterator of atomSet
56 * @param atomsend end iterator of atomset
57 * @return dipole vector
58 */
59Vector getDipole(molecule::const_iterator atomsbegin, molecule::const_iterator atomsend)
60{
61 Vector DipoleVector;
62 size_t SumOfVectors = 0;
63 // go through all atoms
64 for (molecule::const_iterator atomiter = atomsbegin;
65 atomiter != atomsend;
66 ++atomiter) {
67 // go through all bonds
68 for (BondList::const_iterator bonditer = (*atomiter)->ListOfBonds.begin();
69 bonditer != (*atomiter)->ListOfBonds.end();
70 ++bonditer) {
71 const atom * Otheratom = (*bonditer)->GetOtherAtom(*atomiter);
72 if (Otheratom->getId() > (*atomiter)->getId()) {
73 const double DeltaEN = (*atomiter)->getType()->getElectronegativity()
74 -Otheratom->getType()->getElectronegativity();
75 Vector BondDipoleVector = (*atomiter)->getPosition() - Otheratom->getPosition();
76 // DeltaEN is always positive, gives correct orientation of vector
77 BondDipoleVector.Normalize();
78 BondDipoleVector *= DeltaEN;
79 DipoleVector += BondDipoleVector;
80 SumOfVectors++;
81 }
82 }
83 }
84 DipoleVector *= 1./(double)SumOfVectors;
85 DoLog(1) && (Log() << Verbose(1) << "Resulting dipole vector is " << DipoleVector << std::endl);
86
87 return DipoleVector;
88};
89
90/** Calculates the dipole angular correlation for given molecule type.
91 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
92 * Angles are given in degrees.
93 * \param *molecules vector of molecules
94 * \return Map of doubles with values the pair of the two atoms.
95 */
96DipoleAngularCorrelationMap *DipoleAngularCorrelation(std::vector<molecule *> &molecules)
97{
98 Info FunctionInfo(__func__);
99 DipoleAngularCorrelationMap *outmap = new DipoleAngularCorrelationMap;
100// double distance = 0.;
101// Box &domain = World::getInstance().getDomain();
102//
103 if (molecules.empty()) {
104 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
105 return outmap;
106 }
107
108 outmap = new DipoleAngularCorrelationMap;
109 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
110 MolWalker != molecules.end(); ++MolWalker) {
111 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is "
112 << (*MolWalker)->getId() << "." << endl);
113 const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
114 std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker;
115 for (++MolOtherWalker;
116 MolOtherWalker != molecules.end();
117 ++MolOtherWalker) {
118 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is "
119 << (*MolOtherWalker)->getId() << "." << endl);
120 const Vector OtherDipole = getDipole((*MolOtherWalker)->begin(), (*MolOtherWalker)->end());
121 const double angle = Dipole.Angle(OtherDipole) * (180./M_PI);
122 DoLog(1) && (Log() << Verbose(1) << "Angle is " << angle << "." << endl);
123 outmap->insert ( make_pair (angle, make_pair ((*MolWalker), (*MolOtherWalker)) ) );
124 }
125 }
126 return outmap;
127};
128
129
130/** Calculates the pair correlation between given elements.
131 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
132 * \param *molecules vector of molecules
133 * \param &elements vector of elements to correlate
134 * \return Map of doubles with values the pair of the two atoms.
135 */
136PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements)
137{
138 Info FunctionInfo(__func__);
139 PairCorrelationMap *outmap = new PairCorrelationMap;
140 double distance = 0.;
141 Box &domain = World::getInstance().getDomain();
142
143 if (molecules.empty()) {
144 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
145 return outmap;
146 }
147 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
148 (*MolWalker)->doCountAtoms();
149
150 // create all possible pairs of elements
151 set <pair<const element *,const element *> > PairsOfElements;
152 if (elements.size() >= 2) {
153 for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
154 for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
155 if (type1 != type2) {
156 PairsOfElements.insert( make_pair(*type1,*type2) );
157 DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
158 }
159 } else if (elements.size() == 1) { // one to all are valid
160 const element *elemental = *elements.begin();
161 PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
162 PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
163 } else { // all elements valid
164 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
165 }
166
167 outmap = new PairCorrelationMap;
168 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
169 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
170 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
171 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
172 for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
173 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
174 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
175 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
176 if ((*iter)->getId() < (*runner)->getId()){
177 for (set <pair<const element *, const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
178 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
179 distance = domain.periodicDistance((*iter)->getPosition(),(*runner)->getPosition());
180 //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
181 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
182 }
183 }
184 }
185 }
186 }
187 }
188 return outmap;
189};
190
191/** Calculates the pair correlation between given elements.
192 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
193 * \param *molecules list of molecules structure
194 * \param &elements vector of elements to correlate
195 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
196 * \return Map of doubles with values the pair of the two atoms.
197 */
198PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] )
199{
200 Info FunctionInfo(__func__);
201 PairCorrelationMap *outmap = new PairCorrelationMap;
202 double distance = 0.;
203 int n[NDIM];
204 Vector checkX;
205 Vector periodicX;
206 int Othern[NDIM];
207 Vector checkOtherX;
208 Vector periodicOtherX;
209
210 if (molecules.empty()) {
211 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
212 return outmap;
213 }
214 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
215 (*MolWalker)->doCountAtoms();
216
217 // create all possible pairs of elements
218 set <pair<const element *,const element *> > PairsOfElements;
219 if (elements.size() >= 2) {
220 for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
221 for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
222 if (type1 != type2) {
223 PairsOfElements.insert( make_pair(*type1,*type2) );
224 DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
225 }
226 } else if (elements.size() == 1) { // one to all are valid
227 const element *elemental = *elements.begin();
228 PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
229 PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
230 } else { // all elements valid
231 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
232 }
233
234 outmap = new PairCorrelationMap;
235 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
236 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
237 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
238 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
239 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
240 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
241 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
242 // go through every range in xyz and get distance
243 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
244 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
245 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
246 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
247 for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
248 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
249 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
250 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
251 if ((*iter)->getId() < (*runner)->getId()){
252 for (set <pair<const element *,const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
253 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
254 periodicOtherX = FullInverseMatrix * ((*runner)->getPosition()); // x now in [0,1)^3
255 // go through every range in xyz and get distance
256 for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
257 for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
258 for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
259 checkOtherX = FullMatrix * (Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX);
260 distance = checkX.distance(checkOtherX);
261 //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
262 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
263 }
264 }
265 }
266 }
267 }
268 }
269 }
270 }
271
272 return outmap;
273};
274
275/** Calculates the distance (pair) correlation between a given element and a point.
276 * \param *molecules list of molecules structure
277 * \param &elements vector of elements to correlate with point
278 * \param *point vector to the correlation point
279 * \return Map of dobules with values as pairs of atom and the vector
280 */
281CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
282{
283 Info FunctionInfo(__func__);
284 CorrelationToPointMap *outmap = new CorrelationToPointMap;
285 double distance = 0.;
286 Box &domain = World::getInstance().getDomain();
287
288 if (molecules.empty()) {
289 DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
290 return outmap;
291 }
292 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
293 (*MolWalker)->doCountAtoms();
294 outmap = new CorrelationToPointMap;
295 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
296 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
297 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
298 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
299 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
300 if ((*type == NULL) || ((*iter)->getType() == *type)) {
301 distance = domain.periodicDistance((*iter)->getPosition(),*point);
302 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
303 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
304 }
305 }
306 }
307
308 return outmap;
309};
310
311/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
312 * \param *molecules list of molecules structure
313 * \param &elements vector of elements to correlate to point
314 * \param *point vector to the correlation point
315 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
316 * \return Map of dobules with values as pairs of atom and the vector
317 */
318CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
319{
320 Info FunctionInfo(__func__);
321 CorrelationToPointMap *outmap = new CorrelationToPointMap;
322 double distance = 0.;
323 int n[NDIM];
324 Vector periodicX;
325 Vector checkX;
326
327 if (molecules.empty()) {
328 DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
329 return outmap;
330 }
331 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
332 (*MolWalker)->doCountAtoms();
333 outmap = new CorrelationToPointMap;
334 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
335 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
336 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
337 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
338 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
339 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
340 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
341 if ((*type == NULL) || ((*iter)->getType() == *type)) {
342 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
343 // go through every range in xyz and get distance
344 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
345 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
346 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
347 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
348 distance = checkX.distance(*point);
349 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
350 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
351 }
352 }
353 }
354 }
355
356 return outmap;
357};
358
359/** Calculates the distance (pair) correlation between a given element and a surface.
360 * \param *molecules list of molecules structure
361 * \param &elements vector of elements to correlate to surface
362 * \param *Surface pointer to Tesselation class surface
363 * \param *LC LinkedCell structure to quickly find neighbouring atoms
364 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
365 */
366CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
367{
368 Info FunctionInfo(__func__);
369 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
370 double distance = 0;
371 class BoundaryTriangleSet *triangle = NULL;
372 Vector centroid;
373
374 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
375 DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
376 return outmap;
377 }
378 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
379 (*MolWalker)->doCountAtoms();
380 outmap = new CorrelationToSurfaceMap;
381 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
382 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << (*MolWalker)->name << "." << endl);
383 if ((*MolWalker)->empty())
384 DoLog(2) && (2) && (Log() << Verbose(2) << "\t is empty." << endl);
385 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
386 DoLog(3) && (Log() << Verbose(3) << "\tCurrent atom is " << *(*iter) << "." << endl);
387 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
388 if ((*type == NULL) || ((*iter)->getType() == *type)) {
389 TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
390 distance = Intersections.GetSmallestDistance();
391 triangle = Intersections.GetClosestTriangle();
392 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
393 }
394 }
395 }
396
397 return outmap;
398};
399
400/** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
401 * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
402 * 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
403 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
404 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
405 * \param *molecules list of molecules structure
406 * \param &elements vector of elements to correlate to surface
407 * \param *Surface pointer to Tesselation class surface
408 * \param *LC LinkedCell structure to quickly find neighbouring atoms
409 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
410 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
411 */
412CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
413{
414 Info FunctionInfo(__func__);
415 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
416 double distance = 0;
417 class BoundaryTriangleSet *triangle = NULL;
418 Vector centroid;
419 int n[NDIM];
420 Vector periodicX;
421 Vector checkX;
422
423 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
424 DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
425 return outmap;
426 }
427 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
428 (*MolWalker)->doCountAtoms();
429 outmap = new CorrelationToSurfaceMap;
430 double ShortestDistance = 0.;
431 BoundaryTriangleSet *ShortestTriangle = NULL;
432 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
433 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
434 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
435 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
436 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
437 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
438 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
439 if ((*type == NULL) || ((*iter)->getType() == *type)) {
440 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
441 // go through every range in xyz and get distance
442 ShortestDistance = -1.;
443 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
444 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
445 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
446 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
447 TriangleIntersectionList Intersections(checkX,Surface,LC);
448 distance = Intersections.GetSmallestDistance();
449 triangle = Intersections.GetClosestTriangle();
450 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
451 ShortestDistance = distance;
452 ShortestTriangle = triangle;
453 }
454 }
455 // insert
456 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
457 //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
458 }
459 }
460 }
461
462 return outmap;
463};
464
465/** Returns the index of the bin for a given value.
466 * \param value value whose bin to look for
467 * \param BinWidth width of bin
468 * \param BinStart first bin
469 */
470int GetBin ( const double value, const double BinWidth, const double BinStart )
471{
472 //Info FunctionInfo(__func__);
473 int bin =(int) (floor((value - BinStart)/BinWidth));
474 return (bin);
475};
476
477
478/** Adds header part that is unique to BinPairMap.
479 *
480 * @param file stream to print to
481 */
482void OutputCorrelation_Header( ofstream * const file )
483{
484 *file << "\tCount";
485};
486
487/** Prints values stored in BinPairMap iterator.
488 *
489 * @param file stream to print to
490 * @param runner iterator pointing at values to print
491 */
492void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner )
493{
494 *file << runner->second;
495};
496
497
498/** Adds header part that is unique to DipoleAngularCorrelationMap.
499 *
500 * @param file stream to print to
501 */
502void OutputDipoleAngularCorrelation_Header( ofstream * const file )
503{
504 *file << "\tAtom1\tAtom2";
505};
506
507/** Prints values stored in DipoleAngularCorrelationMap iterator.
508 *
509 * @param file stream to print to
510 * @param runner iterator pointing at values to print
511 */
512void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner )
513{
514 *file << runner->second.first->getId() << "\t" << runner->second.second->getId();
515};
516
517
518/** Adds header part that is unique to PairCorrelationMap.
519 *
520 * @param file stream to print to
521 */
522void OutputPairCorrelation_Header( ofstream * const file )
523{
524 *file << "\tAtom1\tAtom2";
525};
526
527/** Prints values stored in PairCorrelationMap iterator.
528 *
529 * @param file stream to print to
530 * @param runner iterator pointing at values to print
531 */
532void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner )
533{
534 *file << *(runner->second.first) << "\t" << *(runner->second.second);
535};
536
537
538/** Adds header part that is unique to CorrelationToPointMap.
539 *
540 * @param file stream to print to
541 */
542void OutputCorrelationToPoint_Header( ofstream * const file )
543{
544 *file << "\tAtom::x[i]-point.x[i]";
545};
546
547/** Prints values stored in CorrelationToPointMap iterator.
548 *
549 * @param file stream to print to
550 * @param runner iterator pointing at values to print
551 */
552void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner )
553{
554 for (int i=0;i<NDIM;i++)
555 *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
556};
557
558
559/** Adds header part that is unique to CorrelationToSurfaceMap.
560 *
561 * @param file stream to print to
562 */
563void OutputCorrelationToSurface_Header( ofstream * const file )
564{
565 *file << "\tTriangle";
566};
567
568/** Prints values stored in CorrelationToSurfaceMap iterator.
569 *
570 * @param file stream to print to
571 * @param runner iterator pointing at values to print
572 */
573void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner )
574{
575 *file << *(runner->second.first) << "\t" << *(runner->second.second);
576};
Note: See TracBrowser for help on using the repository browser.