source: src/Analysis/analysis_correlation.cpp@ 3a1346

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 3a1346 was e791dc, checked in by Frederik Heber <heber@…>, 13 years ago

Removed molecule::doCountAtom() and added molecule::doCountNoNonHydrogen().

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