source: src/Analysis/analysis_correlation.cpp@ 8fc1a6

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 Candidate_v1.7.0 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 8fc1a6 was 8fc1a6, checked in by Frederik Heber <heber@…>, 14 years ago

FIX: getDipole() was broken under periodic boundary conditions.

  • getDipole() now uses Box::periodicDistanceVector() to get the distance vector corrected for periodic boundary conditions.
  • Property mode set to 100644
File size: 32.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 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#include <limits>
25
26#include "Atom/atom.hpp"
27#include "Bond/bond.hpp"
28#include "Tesselation/BoundaryTriangleSet.hpp"
29#include "Box.hpp"
30#include "Element/element.hpp"
31#include "CodePatterns/Info.hpp"
32#include "CodePatterns/Log.hpp"
33#include "CodePatterns/Verbose.hpp"
34#include "Descriptors/AtomOfMoleculeSelectionDescriptor.hpp"
35#include "Descriptors/MoleculeFormulaDescriptor.hpp"
36#include "Descriptors/MoleculeOfAtomSelectionDescriptor.hpp"
37#include "Formula.hpp"
38#include "LinearAlgebra/Vector.hpp"
39#include "LinearAlgebra/RealSpaceMatrix.hpp"
40#include "molecule.hpp"
41#include "Tesselation/tesselation.hpp"
42#include "Tesselation/tesselationhelpers.hpp"
43#include "Tesselation/triangleintersectionlist.hpp"
44#include "World.hpp"
45#include "WorldTime.hpp"
46
47#include "analysis_correlation.hpp"
48
49/** Calculates the dipole vector of a given atomSet.
50 *
51 * Note that we use the following procedure as rule of thumb:
52 * -# go through every bond of the atom
53 * -# calculate the difference of electronegativities \f$\Delta\mathrm{EN}\f$
54 * -# if \f$\Delta\mathrm{EN} > 0.5\f$, we align the bond vector in direction of the more negative element
55 * -# sum up all vectors
56 * -# finally, divide by the number of summed vectors
57 *
58 * @param atomsbegin begin iterator of atomSet
59 * @param atomsend end iterator of atomset
60 * @return dipole vector
61 */
62Vector getDipole(molecule::const_iterator atomsbegin, molecule::const_iterator atomsend)
63{
64 Vector DipoleVector;
65 size_t SumOfVectors = 0;
66 Box &domain = World::getInstance().getDomain();
67
68 // go through all atoms
69 for (molecule::const_iterator atomiter = atomsbegin;
70 atomiter != atomsend;
71 ++atomiter) {
72 // go through all bonds
73 const BondList& ListOfBonds = (*atomiter)->getListOfBonds();
74 ASSERT(ListOfBonds.begin() != ListOfBonds.end(),
75 "getDipole() - no bonds in molecule!");
76 for (BondList::const_iterator bonditer = ListOfBonds.begin();
77 bonditer != ListOfBonds.end();
78 ++bonditer) {
79 const atom * Otheratom = (*bonditer)->GetOtherAtom(*atomiter);
80 if (Otheratom->getId() > (*atomiter)->getId()) {
81 const double DeltaEN = (*atomiter)->getType()->getElectronegativity()
82 -Otheratom->getType()->getElectronegativity();
83 // get distance and correct for boundary conditions
84 Vector BondDipoleVector = domain.periodicDistanceVector(
85 (*atomiter)->getPosition(),
86 Otheratom->getPosition());
87 // DeltaEN is always positive, gives correct orientation of vector
88 BondDipoleVector.Normalize();
89 BondDipoleVector *= DeltaEN;
90 LOG(3,"INFO: Dipole vector from bond " << **bonditer << " is " << BondDipoleVector);
91 DipoleVector += BondDipoleVector;
92 SumOfVectors++;
93 }
94 }
95 }
96 LOG(3,"INFO: Sum over all bond dipole vectors is "
97 << DipoleVector << " with " << SumOfVectors << " in total.");
98 if (SumOfVectors != 0)
99 DipoleVector *= 1./(double)SumOfVectors;
100 LOG(2, "INFO: Resulting dipole vector is " << DipoleVector);
101
102 return DipoleVector;
103};
104
105/** Calculate minimum and maximum amount of trajectory steps by going through given atomic trajectories.
106 * \param vector of atoms whose trajectories to check for [min,max]
107 * \return range with [min, max]
108 */
109range<size_t> getMaximumTrajectoryBounds(const std::vector<atom *> &atoms)
110{
111 // get highest trajectory size
112 LOG(0,"STATUS: Retrieving maximum amount of time steps ...");
113 if (atoms.size() == 0)
114 return range<size_t>(0,0);
115 size_t max_timesteps = std::numeric_limits<size_t>::min();
116 size_t min_timesteps = std::numeric_limits<size_t>::max();
117 BOOST_FOREACH(atom *_atom, atoms) {
118 if (_atom->getTrajectorySize() > max_timesteps)
119 max_timesteps = _atom->getTrajectorySize();
120 if (_atom->getTrajectorySize() < min_timesteps)
121 min_timesteps = _atom->getTrajectorySize();
122 }
123 LOG(1,"INFO: Minimum number of time steps found is " << min_timesteps);
124 LOG(1,"INFO: Maximum number of time steps found is " << max_timesteps);
125
126 return range<size_t>(min_timesteps, max_timesteps);
127}
128
129/** Calculates the angular dipole zero orientation from current time step.
130 * \param molecules vector of molecules to calculate dipoles of
131 * \return map with orientation vector for each atomic id given in \a atoms.
132 */
133std::map<atomId_t, Vector> CalculateZeroAngularDipole(const std::vector<molecule *> &molecules)
134{
135 // get zero orientation for each molecule.
136 LOG(0,"STATUS: Calculating dipoles for current time step ...");
137 std::map<atomId_t, Vector> ZeroVector;
138 BOOST_FOREACH(molecule *_mol, molecules) {
139 const Vector Dipole = getDipole(_mol->begin(), _mol->end());
140 for(molecule::const_iterator iter = _mol->begin(); iter != _mol->end(); ++iter)
141 ZeroVector[(*iter)->getId()] = Dipole;
142 LOG(2,"INFO: Zero alignment for molecule " << _mol->getId() << " is " << Dipole);
143 }
144 LOG(1,"INFO: We calculated zero orientation for a total of " << molecules.size() << " molecule(s).");
145
146 return ZeroVector;
147}
148
149/** Calculates the dipole angular correlation for given molecule type.
150 * Calculate the change of the dipole orientation angle over time.
151 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
152 * Angles are given in degrees.
153 * \param &atoms list of atoms of the molecules taking part (Note: molecules may
154 * change over time as bond structure is recalculated, hence we need the atoms)
155 * \param timestep time step to calculate angular correlation for (relative to
156 * \a ZeroVector)
157 * \param ZeroVector map with Zero orientation vector for each atom in \a atoms.
158 * \param DontResetTime don't reset time to old value (triggers re-creation of bond system)
159 * \return Map of doubles with values the pair of the two atoms.
160 */
161DipoleAngularCorrelationMap *DipoleAngularCorrelation(
162 const Formula &DipoleFormula,
163 const size_t timestep,
164 const std::map<atomId_t, Vector> &ZeroVector,
165 const enum ResetWorldTime DoTimeReset
166 )
167{
168 Info FunctionInfo(__func__);
169 DipoleAngularCorrelationMap *outmap = new DipoleAngularCorrelationMap;
170
171 unsigned int oldtime = 0;
172 if (DoTimeReset == DoResetTime) {
173 // store original time step
174 oldtime = WorldTime::getTime();
175 }
176
177 // set time step
178 LOG(0,"STATUS: Stepping onto to time step " << timestep << ".");
179 World::getInstance().setTime(timestep);
180
181 // get all molecules for this time step
182 World::getInstance().clearMoleculeSelection();
183 World::getInstance().selectAllMolecules(MoleculeByFormula(DipoleFormula));
184 std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules();
185 LOG(1,"INFO: There are " << molecules.size() << " molecules for time step " << timestep << ".");
186
187 // calculate dipoles for each
188 LOG(0,"STATUS: Calculating dipoles for time step " << timestep << " ...");
189 size_t i=0;
190 size_t Counter_rejections = 0;
191 BOOST_FOREACH(molecule *_mol, molecules) {
192 const Vector Dipole = getDipole(_mol->begin(), _mol->end());
193 LOG(3,"INFO: Dipole vector at time step " << timestep << " for for molecule "
194 << _mol->getId() << " is " << Dipole);
195 // check that all atoms are valid (zeroVector known)
196 molecule::const_iterator iter = _mol->begin();
197 for(; iter != _mol->end(); ++iter) {
198 if (!ZeroVector.count((*iter)->getId()))
199 break;
200 }
201 if (iter != _mol->end()) {
202 ELOG(2, "Skipping molecule " << _mol->getName() << " as not all atoms have a valid zeroVector.");
203 ++Counter_rejections;
204 continue;
205 } else
206 iter = _mol->begin();
207 std::map<atomId_t, Vector>::const_iterator zeroValue = ZeroVector.find((*iter)->getId()); //due to iter is const
208 double angle = 0.;
209 LOG(2, "INFO: ZeroVector of first atom " << **iter << " is "
210 << zeroValue->second << ".");
211 LOG(4, "INFO: Squared norm of difference vector is "
212 << (zeroValue->second - Dipole).NormSquared() << ".");
213 if ((zeroValue->second - Dipole).NormSquared() > MYEPSILON)
214 angle = Dipole.Angle(zeroValue->second) * (180./M_PI);
215 else
216 LOG(2, "INFO: Both vectors (almost) coincide, numerically unstable, angle set to zero.");
217 LOG(1,"INFO: Resulting relative angle for molecule " << _mol->getName()
218 << " is " << angle << ".");
219 outmap->insert ( std::make_pair (angle, *iter ) );
220 ++i;
221 }
222 ASSERT(Counter_rejections <= molecules.size(),
223 "DipoleAngularCorrelation() - more rejections ("+toString(Counter_rejections)
224 +") than there are molecules ("+toString(molecules.size())+").");
225 LOG(1,"INFO: " << Counter_rejections << " molecules have been rejected in time step " << timestep << ".");
226
227 LOG(0,"STATUS: Done with calculating dipoles.");
228
229 if (DoTimeReset == DoResetTime) {
230 // re-set to original time step again
231 World::getInstance().setTime(oldtime);
232 }
233
234 // and return results
235 return outmap;
236};
237
238/** Calculates the dipole correlation for given molecule type.
239 * I.e. we calculate how the angle between any two given dipoles in the
240 * systems behaves. Sort of pair correlation but distance is replaced by
241 * the orientation distance, i.e. an angle.
242 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
243 * Angles are given in degrees.
244 * \param *molecules vector of molecules
245 * \return Map of doubles with values the pair of the two atoms.
246 */
247DipoleCorrelationMap *DipoleCorrelation(std::vector<molecule *> &molecules)
248{
249 Info FunctionInfo(__func__);
250 DipoleCorrelationMap *outmap = new DipoleCorrelationMap;
251// double distance = 0.;
252// Box &domain = World::getInstance().getDomain();
253//
254 if (molecules.empty()) {
255 ELOG(1, "No molecule given.");
256 return outmap;
257 }
258
259 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
260 MolWalker != molecules.end(); ++MolWalker) {
261 LOG(2, "INFO: Current molecule is " << (*MolWalker)->getId() << ".");
262 const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
263 std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker;
264 for (++MolOtherWalker;
265 MolOtherWalker != molecules.end();
266 ++MolOtherWalker) {
267 LOG(2, "INFO: Current other molecule is " << (*MolOtherWalker)->getId() << ".");
268 const Vector OtherDipole = getDipole((*MolOtherWalker)->begin(), (*MolOtherWalker)->end());
269 const double angle = Dipole.Angle(OtherDipole) * (180./M_PI);
270 LOG(1, "Angle is " << angle << ".");
271 outmap->insert ( make_pair (angle, make_pair ((*MolWalker), (*MolOtherWalker)) ) );
272 }
273 }
274 return outmap;
275};
276
277
278/** Calculates the pair correlation between given elements.
279 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
280 * \param *molecules vector of molecules
281 * \param &elements vector of elements to correlate
282 * \return Map of doubles with values the pair of the two atoms.
283 */
284PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements)
285{
286 Info FunctionInfo(__func__);
287 PairCorrelationMap *outmap = new PairCorrelationMap;
288 double distance = 0.;
289 Box &domain = World::getInstance().getDomain();
290
291 if (molecules.empty()) {
292 ELOG(1, "No molecule given.");
293 return outmap;
294 }
295 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
296 (*MolWalker)->doCountAtoms();
297
298 // create all possible pairs of elements
299 set <pair<const element *,const element *> > PairsOfElements;
300 if (elements.size() >= 2) {
301 for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
302 for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
303 if (type1 != type2) {
304 PairsOfElements.insert( make_pair(*type1,*type2) );
305 LOG(1, "Creating element pair " << *(*type1) << " and " << *(*type2) << ".");
306 }
307 } else if (elements.size() == 1) { // one to all are valid
308 const element *elemental = *elements.begin();
309 PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
310 PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
311 } else { // all elements valid
312 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
313 }
314
315 outmap = new PairCorrelationMap;
316 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
317 LOG(2, "Current molecule is " << (*MolWalker)->getName() << ".");
318 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
319 LOG(3, "Current atom is " << **iter << ".");
320 for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
321 LOG(2, "Current other molecule is " << (*MolOtherWalker)->getName() << ".");
322 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
323 LOG(3, "Current otheratom is " << **runner << ".");
324 if ((*iter)->getId() < (*runner)->getId()){
325 for (set <pair<const element *, const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
326 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
327 distance = domain.periodicDistance((*iter)->getPosition(),(*runner)->getPosition());
328 //LOG(1, "Inserting " << *(*iter) << " and " << *(*runner));
329 outmap->insert (
330 std::pair<double, std::pair <const atom *, const atom*> > (
331 distance,
332 std::pair<const atom *, const atom*> ((*iter), (*runner))
333 )
334 );
335 }
336 }
337 }
338 }
339 }
340 }
341 return outmap;
342};
343
344/** Calculates the pair correlation between given elements.
345 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
346 * \param *molecules list of molecules structure
347 * \param &elements vector of elements to correlate
348 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
349 * \return Map of doubles with values the pair of the two atoms.
350 */
351PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] )
352{
353 Info FunctionInfo(__func__);
354 PairCorrelationMap *outmap = new PairCorrelationMap;
355 double distance = 0.;
356 int n[NDIM];
357 Vector checkX;
358 Vector periodicX;
359 int Othern[NDIM];
360 Vector checkOtherX;
361 Vector periodicOtherX;
362
363 if (molecules.empty()) {
364 ELOG(1, "No molecule given.");
365 return outmap;
366 }
367 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
368 (*MolWalker)->doCountAtoms();
369
370 // create all possible pairs of elements
371 set <pair<const element *,const element *> > PairsOfElements;
372 if (elements.size() >= 2) {
373 for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
374 for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
375 if (type1 != type2) {
376 PairsOfElements.insert( make_pair(*type1,*type2) );
377 LOG(1, "Creating element pair " << *(*type1) << " and " << *(*type2) << ".");
378 }
379 } else if (elements.size() == 1) { // one to all are valid
380 const element *elemental = *elements.begin();
381 PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
382 PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
383 } else { // all elements valid
384 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
385 }
386
387 outmap = new PairCorrelationMap;
388 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
389 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
390 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
391 LOG(2, "Current molecule is " << *MolWalker << ".");
392 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
393 LOG(3, "Current atom is " << **iter << ".");
394 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
395 // go through every range in xyz and get distance
396 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
397 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
398 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
399 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
400 for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
401 LOG(2, "Current other molecule is " << *MolOtherWalker << ".");
402 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
403 LOG(3, "Current otheratom is " << **runner << ".");
404 if ((*iter)->getId() < (*runner)->getId()){
405 for (set <pair<const element *,const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
406 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
407 periodicOtherX = FullInverseMatrix * ((*runner)->getPosition()); // x now in [0,1)^3
408 // go through every range in xyz and get distance
409 for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
410 for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
411 for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
412 checkOtherX = FullMatrix * (Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX);
413 distance = checkX.distance(checkOtherX);
414 //LOG(1, "Inserting " << *(*iter) << " and " << *(*runner));
415 outmap->insert (
416 std::pair<double, std::pair <const atom *, const atom*> > (
417 distance,
418 std::pair<const atom *, const atom*> (
419 (*iter),
420 (*runner))
421 )
422 );
423 }
424 }
425 }
426 }
427 }
428 }
429 }
430 }
431
432 return outmap;
433};
434
435/** Calculates the distance (pair) correlation between a given element and a point.
436 * \param *molecules list of molecules structure
437 * \param &elements vector of elements to correlate with point
438 * \param *point vector to the correlation point
439 * \return Map of dobules with values as pairs of atom and the vector
440 */
441CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
442{
443 Info FunctionInfo(__func__);
444 CorrelationToPointMap *outmap = new CorrelationToPointMap;
445 double distance = 0.;
446 Box &domain = World::getInstance().getDomain();
447
448 if (molecules.empty()) {
449 LOG(1, "No molecule given.");
450 return outmap;
451 }
452 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
453 (*MolWalker)->doCountAtoms();
454 outmap = new CorrelationToPointMap;
455 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
456 LOG(2, "Current molecule is " << *MolWalker << ".");
457 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
458 LOG(3, "Current atom is " << **iter << ".");
459 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
460 if ((*type == NULL) || ((*iter)->getType() == *type)) {
461 distance = domain.periodicDistance((*iter)->getPosition(),*point);
462 LOG(4, "Current distance is " << distance << ".");
463 outmap->insert (
464 std::pair<double, std::pair<const atom *, const Vector*> >(
465 distance,
466 std::pair<const atom *, const Vector*> (
467 (*iter),
468 point)
469 )
470 );
471 }
472 }
473 }
474
475 return outmap;
476};
477
478/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
479 * \param *molecules list of molecules structure
480 * \param &elements vector of elements to correlate to point
481 * \param *point vector to the correlation point
482 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
483 * \return Map of dobules with values as pairs of atom and the vector
484 */
485CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
486{
487 Info FunctionInfo(__func__);
488 CorrelationToPointMap *outmap = new CorrelationToPointMap;
489 double distance = 0.;
490 int n[NDIM];
491 Vector periodicX;
492 Vector checkX;
493
494 if (molecules.empty()) {
495 LOG(1, "No molecule given.");
496 return outmap;
497 }
498 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
499 (*MolWalker)->doCountAtoms();
500 outmap = new CorrelationToPointMap;
501 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
502 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
503 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
504 LOG(2, "Current molecule is " << *MolWalker << ".");
505 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
506 LOG(3, "Current atom is " << **iter << ".");
507 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
508 if ((*type == NULL) || ((*iter)->getType() == *type)) {
509 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
510 // go through every range in xyz and get distance
511 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
512 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
513 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
514 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
515 distance = checkX.distance(*point);
516 LOG(4, "Current distance is " << distance << ".");
517 outmap->insert (
518 std::pair<double,
519 std::pair<const atom *, const Vector*> >(
520 distance,
521 std::pair<const atom *, const Vector*> (
522 *iter,
523 point)
524 )
525 );
526 }
527 }
528 }
529 }
530
531 return outmap;
532};
533
534/** Calculates the distance (pair) correlation between a given element and a surface.
535 * \param *molecules list of molecules structure
536 * \param &elements vector of elements to correlate to surface
537 * \param *Surface pointer to Tesselation class surface
538 * \param *LC LinkedCell_deprecated structure to quickly find neighbouring atoms
539 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
540 */
541CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell_deprecated *LC )
542{
543 Info FunctionInfo(__func__);
544 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
545 double distance = 0;
546 class BoundaryTriangleSet *triangle = NULL;
547 Vector centroid;
548
549 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
550 ELOG(1, "No Tesselation, no LinkedCell or no molecule given.");
551 return outmap;
552 }
553 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
554 (*MolWalker)->doCountAtoms();
555 outmap = new CorrelationToSurfaceMap;
556 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
557 LOG(2, "Current molecule is " << (*MolWalker)->name << ".");
558 if ((*MolWalker)->empty())
559 LOG(2, "\t is empty.");
560 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
561 LOG(3, "\tCurrent atom is " << *(*iter) << ".");
562 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
563 if ((*type == NULL) || ((*iter)->getType() == *type)) {
564 TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
565 distance = Intersections.GetSmallestDistance();
566 triangle = Intersections.GetClosestTriangle();
567 outmap->insert (
568 std::pair<double,
569 std::pair<const atom *, BoundaryTriangleSet*> >(
570 distance,
571 std::pair<const atom *, BoundaryTriangleSet*> (
572 (*iter),
573 triangle)
574 )
575 );
576 }
577 }
578 }
579
580 return outmap;
581};
582
583/** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
584 * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
585 * 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
586 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
587 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
588 * \param *molecules list of molecules structure
589 * \param &elements vector of elements to correlate to surface
590 * \param *Surface pointer to Tesselation class surface
591 * \param *LC LinkedCell_deprecated structure to quickly find neighbouring atoms
592 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
593 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
594 */
595CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell_deprecated *LC, const int ranges[NDIM] )
596{
597 Info FunctionInfo(__func__);
598 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
599 double distance = 0;
600 class BoundaryTriangleSet *triangle = NULL;
601 Vector centroid;
602 int n[NDIM];
603 Vector periodicX;
604 Vector checkX;
605
606 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
607 LOG(1, "No Tesselation, no LinkedCell or no molecule given.");
608 return outmap;
609 }
610 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
611 (*MolWalker)->doCountAtoms();
612 outmap = new CorrelationToSurfaceMap;
613 double ShortestDistance = 0.;
614 BoundaryTriangleSet *ShortestTriangle = NULL;
615 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
616 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
617 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
618 LOG(2, "Current molecule is " << *MolWalker << ".");
619 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
620 LOG(3, "Current atom is " << **iter << ".");
621 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
622 if ((*type == NULL) || ((*iter)->getType() == *type)) {
623 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
624 // go through every range in xyz and get distance
625 ShortestDistance = -1.;
626 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
627 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
628 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
629 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
630 TriangleIntersectionList Intersections(checkX,Surface,LC);
631 distance = Intersections.GetSmallestDistance();
632 triangle = Intersections.GetClosestTriangle();
633 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
634 ShortestDistance = distance;
635 ShortestTriangle = triangle;
636 }
637 }
638 // insert
639 outmap->insert (
640 std::pair<double,
641 std::pair<const atom *, BoundaryTriangleSet*> >(
642 ShortestDistance,
643 std::pair<const atom *, BoundaryTriangleSet*> (
644 *iter,
645 ShortestTriangle)
646 )
647 );
648 //LOG(1, "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << ".");
649 }
650 }
651 }
652
653 return outmap;
654};
655
656/** Returns the index of the bin for a given value.
657 * \param value value whose bin to look for
658 * \param BinWidth width of bin
659 * \param BinStart first bin
660 */
661int GetBin ( const double value, const double BinWidth, const double BinStart )
662{
663 //Info FunctionInfo(__func__);
664 int bin =(int) (floor((value - BinStart)/BinWidth));
665 return (bin);
666};
667
668
669/** Adds header part that is unique to BinPairMap.
670 *
671 * @param file stream to print to
672 */
673void OutputCorrelation_Header( ofstream * const file )
674{
675 *file << "\tCount";
676};
677
678/** Prints values stored in BinPairMap iterator.
679 *
680 * @param file stream to print to
681 * @param runner iterator pointing at values to print
682 */
683void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner )
684{
685 *file << runner->second;
686};
687
688
689/** Adds header part that is unique to DipoleAngularCorrelationMap.
690 *
691 * @param file stream to print to
692 */
693void OutputDipoleAngularCorrelation_Header( ofstream * const file )
694{
695 *file << "\tFirstAtomOfMolecule";
696};
697
698/** Prints values stored in DipoleCorrelationMap iterator.
699 *
700 * @param file stream to print to
701 * @param runner iterator pointing at values to print
702 */
703void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner )
704{
705 *file << *(runner->second);
706};
707
708
709/** Adds header part that is unique to DipoleAngularCorrelationMap.
710 *
711 * @param file stream to print to
712 */
713void OutputDipoleCorrelation_Header( ofstream * const file )
714{
715 *file << "\tMolecule";
716};
717
718/** Prints values stored in DipoleCorrelationMap iterator.
719 *
720 * @param file stream to print to
721 * @param runner iterator pointing at values to print
722 */
723void OutputDipoleCorrelation_Value( ofstream * const file, DipoleCorrelationMap::const_iterator &runner )
724{
725 *file << runner->second.first->getId() << "\t" << runner->second.second->getId();
726};
727
728
729/** Adds header part that is unique to PairCorrelationMap.
730 *
731 * @param file stream to print to
732 */
733void OutputPairCorrelation_Header( ofstream * const file )
734{
735 *file << "\tAtom1\tAtom2";
736};
737
738/** Prints values stored in PairCorrelationMap iterator.
739 *
740 * @param file stream to print to
741 * @param runner iterator pointing at values to print
742 */
743void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner )
744{
745 *file << *(runner->second.first) << "\t" << *(runner->second.second);
746};
747
748
749/** Adds header part that is unique to CorrelationToPointMap.
750 *
751 * @param file stream to print to
752 */
753void OutputCorrelationToPoint_Header( ofstream * const file )
754{
755 *file << "\tAtom::x[i]-point.x[i]";
756};
757
758/** Prints values stored in CorrelationToPointMap iterator.
759 *
760 * @param file stream to print to
761 * @param runner iterator pointing at values to print
762 */
763void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner )
764{
765 for (int i=0;i<NDIM;i++)
766 *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
767};
768
769
770/** Adds header part that is unique to CorrelationToSurfaceMap.
771 *
772 * @param file stream to print to
773 */
774void OutputCorrelationToSurface_Header( ofstream * const file )
775{
776 *file << "\tTriangle";
777};
778
779/** Prints values stored in CorrelationToSurfaceMap iterator.
780 *
781 * @param file stream to print to
782 * @param runner iterator pointing at values to print
783 */
784void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner )
785{
786 *file << *(runner->second.first) << "\t" << *(runner->second.second);
787};
Note: See TracBrowser for help on using the repository browser.