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
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
[c4d4df]22#include <iostream>
[36166d]23#include <iomanip>
[505d05]24#include <limits>
[c4d4df]25
[6f0841]26#include "Atom/atom.hpp"
[129204]27#include "Bond/bond.hpp"
[d127c8]28#include "Tesselation/BoundaryTriangleSet.hpp"
[be945c]29#include "Box.hpp"
[3bdb6d]30#include "Element/element.hpp"
[ad011c]31#include "CodePatterns/Info.hpp"
32#include "CodePatterns/Log.hpp"
[208237b]33#include "CodePatterns/Verbose.hpp"
[e65878]34#include "Descriptors/AtomOfMoleculeSelectionDescriptor.hpp"
35#include "Descriptors/MoleculeFormulaDescriptor.hpp"
[4b8630]36#include "Descriptors/MoleculeOfAtomSelectionDescriptor.hpp"
[ea430a]37#include "Formula.hpp"
[208237b]38#include "LinearAlgebra/Vector.hpp"
39#include "LinearAlgebra/RealSpaceMatrix.hpp"
[c4d4df]40#include "molecule.hpp"
[d127c8]41#include "Tesselation/tesselation.hpp"
42#include "Tesselation/tesselationhelpers.hpp"
43#include "Tesselation/triangleintersectionlist.hpp"
[be945c]44#include "World.hpp"
[208237b]45#include "WorldTime.hpp"
[c4d4df]46
[be945c]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
[d1912f]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
[be945c]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;
[8fc1a6]66 Box &domain = World::getInstance().getDomain();
67
68 // go through all atoms
[be945c]69 for (molecule::const_iterator atomiter = atomsbegin;
70 atomiter != atomsend;
71 ++atomiter) {
72 // go through all bonds
[9d83b6]73 const BondList& ListOfBonds = (*atomiter)->getListOfBonds();
[4fc828]74 ASSERT(ListOfBonds.begin() != ListOfBonds.end(),
75 "getDipole() - no bonds in molecule!");
[9d83b6]76 for (BondList::const_iterator bonditer = ListOfBonds.begin();
77 bonditer != ListOfBonds.end();
[be945c]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();
[8fc1a6]83 // get distance and correct for boundary conditions
84 Vector BondDipoleVector = domain.periodicDistanceVector(
85 (*atomiter)->getPosition(),
86 Otheratom->getPosition());
[be945c]87 // DeltaEN is always positive, gives correct orientation of vector
88 BondDipoleVector.Normalize();
89 BondDipoleVector *= DeltaEN;
[4fc828]90 LOG(3,"INFO: Dipole vector from bond " << **bonditer << " is " << BondDipoleVector);
[be945c]91 DipoleVector += BondDipoleVector;
92 SumOfVectors++;
93 }
94 }
95 }
[4fc828]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;
[44f53e]100 LOG(2, "INFO: Resulting dipole vector is " << DipoleVector);
[be945c]101
102 return DipoleVector;
103};
104
[1cc661]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 */
[e65878]109range<size_t> getMaximumTrajectoryBounds(const std::vector<atom *> &atoms)
[1cc661]110{
111 // get highest trajectory size
112 LOG(0,"STATUS: Retrieving maximum amount of time steps ...");
[505d05]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();
[1cc661]117 BOOST_FOREACH(atom *_atom, atoms) {
118 if (_atom->getTrajectorySize() > max_timesteps)
119 max_timesteps = _atom->getTrajectorySize();
[505d05]120 if (_atom->getTrajectorySize() < min_timesteps)
[1cc661]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
[0a7fad]129/** Calculates the angular dipole zero orientation from current time step.
[e65878]130 * \param molecules vector of molecules to calculate dipoles of
[0a7fad]131 * \return map with orientation vector for each atomic id given in \a atoms.
132 */
[e65878]133std::map<atomId_t, Vector> CalculateZeroAngularDipole(const std::vector<molecule *> &molecules)
[0a7fad]134{
135 // get zero orientation for each molecule.
[e65878]136 LOG(0,"STATUS: Calculating dipoles for current time step ...");
[0a7fad]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}
[1cc661]148
[ea430a]149/** Calculates the dipole angular correlation for given molecule type.
[208237b]150 * Calculate the change of the dipole orientation angle over time.
[ea430a]151 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
[be945c]152 * Angles are given in degrees.
[4b8630]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)
[cda81d]155 * \param timestep time step to calculate angular correlation for (relative to
156 * \a ZeroVector)
[325687]157 * \param ZeroVector map with Zero orientation vector for each atom in \a atoms.
[99b87a]158 * \param DontResetTime don't reset time to old value (triggers re-creation of bond system)
[ea430a]159 * \return Map of doubles with values the pair of the two atoms.
160 */
[325687]161DipoleAngularCorrelationMap *DipoleAngularCorrelation(
[e65878]162 const Formula &DipoleFormula,
[cda81d]163 const size_t timestep,
[e65878]164 const std::map<atomId_t, Vector> &ZeroVector,
[99b87a]165 const enum ResetWorldTime DoTimeReset
[325687]166 )
[ea430a]167{
168 Info FunctionInfo(__func__);
[caa30b]169 DipoleAngularCorrelationMap *outmap = new DipoleAngularCorrelationMap;
[be945c]170
[99b87a]171 unsigned int oldtime = 0;
172 if (DoTimeReset == DoResetTime) {
173 // store original time step
174 oldtime = WorldTime::getTime();
175 }
[0a7fad]176
[cda81d]177 // set time step
[505d05]178 LOG(0,"STATUS: Stepping onto to time step " << timestep << ".");
[cda81d]179 World::getInstance().setTime(timestep);
180
181 // get all molecules for this time step
[e65878]182 World::getInstance().clearMoleculeSelection();
183 World::getInstance().selectAllMolecules(MoleculeByFormula(DipoleFormula));
184 std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules();
[870b4b]185 LOG(1,"INFO: There are " << molecules.size() << " molecules for time step " << timestep << ".");
[208237b]186
[cda81d]187 // calculate dipoles for each
[870b4b]188 LOG(0,"STATUS: Calculating dipoles for time step " << timestep << " ...");
[cda81d]189 size_t i=0;
[870b4b]190 size_t Counter_rejections = 0;
[cda81d]191 BOOST_FOREACH(molecule *_mol, molecules) {
192 const Vector Dipole = getDipole(_mol->begin(), _mol->end());
[e65878]193 LOG(3,"INFO: Dipole vector at time step " << timestep << " for for molecule "
[cda81d]194 << _mol->getId() << " is " << Dipole);
[e65878]195 // check that all atoms are valid (zeroVector known)
[cda81d]196 molecule::const_iterator iter = _mol->begin();
[e65878]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.");
[870b4b]203 ++Counter_rejections;
[e65878]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
[cda81d]208 double angle = 0.;
209 LOG(2, "INFO: ZeroVector of first atom " << **iter << " is "
[e65878]210 << zeroValue->second << ".");
[cda81d]211 LOG(4, "INFO: Squared norm of difference vector is "
[e65878]212 << (zeroValue->second - Dipole).NormSquared() << ".");
213 if ((zeroValue->second - Dipole).NormSquared() > MYEPSILON)
214 angle = Dipole.Angle(zeroValue->second) * (180./M_PI);
[cda81d]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 << ".");
[59fff1]219 outmap->insert ( std::make_pair (angle, *iter ) );
[cda81d]220 ++i;
[208237b]221 }
[870b4b]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.");
[208237b]228
[99b87a]229 if (DoTimeReset == DoResetTime) {
230 // re-set to original time step again
231 World::getInstance().setTime(oldtime);
232 }
[208237b]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()) {
[47d041]255 ELOG(1, "No molecule given.");
[208237b]256 return outmap;
257 }
258
[be945c]259 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
[92e5cb]260 MolWalker != molecules.end(); ++MolWalker) {
[47d041]261 LOG(2, "INFO: Current molecule is " << (*MolWalker)->getId() << ".");
[be945c]262 const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
[92e5cb]263 std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker;
264 for (++MolOtherWalker;
[be945c]265 MolOtherWalker != molecules.end();
[92e5cb]266 ++MolOtherWalker) {
[47d041]267 LOG(2, "INFO: Current other molecule is " << (*MolOtherWalker)->getId() << ".");
[be945c]268 const Vector OtherDipole = getDipole((*MolOtherWalker)->begin(), (*MolOtherWalker)->end());
269 const double angle = Dipole.Angle(OtherDipole) * (180./M_PI);
[47d041]270 LOG(1, "Angle is " << angle << ".");
[be945c]271 outmap->insert ( make_pair (angle, make_pair ((*MolWalker), (*MolOtherWalker)) ) );
272 }
273 }
[ea430a]274 return outmap;
275};
276
[c4d4df]277
278/** Calculates the pair correlation between given elements.
279 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
[e65de8]280 * \param *molecules vector of molecules
[c78d44]281 * \param &elements vector of elements to correlate
[c4d4df]282 * \return Map of doubles with values the pair of the two atoms.
283 */
[e5c0a1]284PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements)
[c4d4df]285{
[3930eb]286 Info FunctionInfo(__func__);
[caa30b]287 PairCorrelationMap *outmap = new PairCorrelationMap;
[c4d4df]288 double distance = 0.;
[014475]289 Box &domain = World::getInstance().getDomain();
[c4d4df]290
[e65de8]291 if (molecules.empty()) {
[47d041]292 ELOG(1, "No molecule given.");
[c4d4df]293 return outmap;
294 }
[e65de8]295 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
[009607e]296 (*MolWalker)->doCountAtoms();
[c78d44]297
298 // create all possible pairs of elements
[e5c0a1]299 set <pair<const element *,const element *> > PairsOfElements;
[c78d44]300 if (elements.size() >= 2) {
[e5c0a1]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)
[c78d44]303 if (type1 != type2) {
[e5c0a1]304 PairsOfElements.insert( make_pair(*type1,*type2) );
[47d041]305 LOG(1, "Creating element pair " << *(*type1) << " and " << *(*type2) << ".");
[c78d44]306 }
307 } else if (elements.size() == 1) { // one to all are valid
[e5c0a1]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) );
[c78d44]311 } else { // all elements valid
312 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
313 }
314
[c4d4df]315 outmap = new PairCorrelationMap;
[e65de8]316 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
[47d041]317 LOG(2, "Current molecule is " << (*MolWalker)->getName() << ".");
[e65de8]318 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
[47d041]319 LOG(3, "Current atom is " << **iter << ".");
[e65de8]320 for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
[47d041]321 LOG(2, "Current other molecule is " << (*MolOtherWalker)->getName() << ".");
[e65de8]322 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
[47d041]323 LOG(3, "Current otheratom is " << **runner << ".");
[e65de8]324 if ((*iter)->getId() < (*runner)->getId()){
[b5c53d]325 for (set <pair<const element *, const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
[d74077]326 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
327 distance = domain.periodicDistance((*iter)->getPosition(),(*runner)->getPosition());
[47d041]328 //LOG(1, "Inserting " << *(*iter) << " and " << *(*runner));
[59fff1]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 );
[a5551b]335 }
[c4d4df]336 }
[a5551b]337 }
[c4d4df]338 }
339 }
[24725c]340 }
[c4d4df]341 return outmap;
342};
343
[7ea9e6]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
[c78d44]347 * \param &elements vector of elements to correlate
[7ea9e6]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 */
[e5c0a1]351PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] )
[7ea9e6]352{
[3930eb]353 Info FunctionInfo(__func__);
[caa30b]354 PairCorrelationMap *outmap = new PairCorrelationMap;
[7ea9e6]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
[e65de8]363 if (molecules.empty()) {
[47d041]364 ELOG(1, "No molecule given.");
[7ea9e6]365 return outmap;
366 }
[e65de8]367 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
[009607e]368 (*MolWalker)->doCountAtoms();
[c78d44]369
370 // create all possible pairs of elements
[e5c0a1]371 set <pair<const element *,const element *> > PairsOfElements;
[c78d44]372 if (elements.size() >= 2) {
[e5c0a1]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)
[c78d44]375 if (type1 != type2) {
[e5c0a1]376 PairsOfElements.insert( make_pair(*type1,*type2) );
[47d041]377 LOG(1, "Creating element pair " << *(*type1) << " and " << *(*type2) << ".");
[c78d44]378 }
379 } else if (elements.size() == 1) { // one to all are valid
[e5c0a1]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) );
[c78d44]383 } else { // all elements valid
384 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
385 }
386
[7ea9e6]387 outmap = new PairCorrelationMap;
[e65de8]388 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
[cca9ef]389 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
390 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
[47d041]391 LOG(2, "Current molecule is " << *MolWalker << ".");
[e65de8]392 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
[47d041]393 LOG(3, "Current atom is " << **iter << ".");
[d74077]394 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
[e65de8]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++){
[47d041]401 LOG(2, "Current other molecule is " << *MolOtherWalker << ".");
[e65de8]402 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
[47d041]403 LOG(3, "Current otheratom is " << **runner << ".");
[e65de8]404 if ((*iter)->getId() < (*runner)->getId()){
[e5c0a1]405 for (set <pair<const element *,const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
[d74077]406 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
407 periodicOtherX = FullInverseMatrix * ((*runner)->getPosition()); // x now in [0,1)^3
[e65de8]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);
[47d041]414 //LOG(1, "Inserting " << *(*iter) << " and " << *(*runner));
[59fff1]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 );
[e65de8]423 }
424 }
[c78d44]425 }
[7ea9e6]426 }
[c78d44]427 }
[7ea9e6]428 }
429 }
[c78d44]430 }
[7ea9e6]431
432 return outmap;
433};
434
[c4d4df]435/** Calculates the distance (pair) correlation between a given element and a point.
[a5551b]436 * \param *molecules list of molecules structure
[c78d44]437 * \param &elements vector of elements to correlate with point
[c4d4df]438 * \param *point vector to the correlation point
439 * \return Map of dobules with values as pairs of atom and the vector
440 */
[e5c0a1]441CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
[c4d4df]442{
[3930eb]443 Info FunctionInfo(__func__);
[caa30b]444 CorrelationToPointMap *outmap = new CorrelationToPointMap;
[c4d4df]445 double distance = 0.;
[014475]446 Box &domain = World::getInstance().getDomain();
[c4d4df]447
[e65de8]448 if (molecules.empty()) {
[47d041]449 LOG(1, "No molecule given.");
[c4d4df]450 return outmap;
451 }
[e65de8]452 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
[009607e]453 (*MolWalker)->doCountAtoms();
[c4d4df]454 outmap = new CorrelationToPointMap;
[e65de8]455 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
[47d041]456 LOG(2, "Current molecule is " << *MolWalker << ".");
[e65de8]457 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
[47d041]458 LOG(3, "Current atom is " << **iter << ".");
[e5c0a1]459 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]460 if ((*type == NULL) || ((*iter)->getType() == *type)) {
461 distance = domain.periodicDistance((*iter)->getPosition(),*point);
[47d041]462 LOG(4, "Current distance is " << distance << ".");
[59fff1]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 );
[e65de8]471 }
[c4d4df]472 }
[e65de8]473 }
[c4d4df]474
475 return outmap;
476};
477
[7ea9e6]478/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
479 * \param *molecules list of molecules structure
[c78d44]480 * \param &elements vector of elements to correlate to point
[7ea9e6]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 */
[e5c0a1]485CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
[7ea9e6]486{
[3930eb]487 Info FunctionInfo(__func__);
[caa30b]488 CorrelationToPointMap *outmap = new CorrelationToPointMap;
[7ea9e6]489 double distance = 0.;
490 int n[NDIM];
491 Vector periodicX;
492 Vector checkX;
493
[e65de8]494 if (molecules.empty()) {
[47d041]495 LOG(1, "No molecule given.");
[7ea9e6]496 return outmap;
497 }
[e65de8]498 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
[009607e]499 (*MolWalker)->doCountAtoms();
[7ea9e6]500 outmap = new CorrelationToPointMap;
[e65de8]501 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
[cca9ef]502 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
503 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
[47d041]504 LOG(2, "Current molecule is " << *MolWalker << ".");
[e65de8]505 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
[47d041]506 LOG(3, "Current atom is " << **iter << ".");
[e5c0a1]507 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]508 if ((*type == NULL) || ((*iter)->getType() == *type)) {
509 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
[e65de8]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);
[47d041]516 LOG(4, "Current distance is " << distance << ".");
[59fff1]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 );
[e65de8]526 }
527 }
[7ea9e6]528 }
[e65de8]529 }
[7ea9e6]530
531 return outmap;
532};
533
[c4d4df]534/** Calculates the distance (pair) correlation between a given element and a surface.
[a5551b]535 * \param *molecules list of molecules structure
[c78d44]536 * \param &elements vector of elements to correlate to surface
[c4d4df]537 * \param *Surface pointer to Tesselation class surface
[6bd7e0]538 * \param *LC LinkedCell_deprecated structure to quickly find neighbouring atoms
[c4d4df]539 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
540 */
[6bd7e0]541CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell_deprecated *LC )
[c4d4df]542{
[3930eb]543 Info FunctionInfo(__func__);
[caa30b]544 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
[99593f]545 double distance = 0;
[c4d4df]546 class BoundaryTriangleSet *triangle = NULL;
547 Vector centroid;
[7ea9e6]548
[e65de8]549 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
[47d041]550 ELOG(1, "No Tesselation, no LinkedCell or no molecule given.");
[7ea9e6]551 return outmap;
552 }
[e65de8]553 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
[009607e]554 (*MolWalker)->doCountAtoms();
[7ea9e6]555 outmap = new CorrelationToSurfaceMap;
[e65de8]556 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
[47d041]557 LOG(2, "Current molecule is " << (*MolWalker)->name << ".");
[e65de8]558 if ((*MolWalker)->empty())
[47d041]559 LOG(2, "\t is empty.");
[e65de8]560 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
[47d041]561 LOG(3, "\tCurrent atom is " << *(*iter) << ".");
[e5c0a1]562 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]563 if ((*type == NULL) || ((*iter)->getType() == *type)) {
564 TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
[e65de8]565 distance = Intersections.GetSmallestDistance();
566 triangle = Intersections.GetClosestTriangle();
[59fff1]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 );
[e65de8]576 }
[7fd416]577 }
[e65de8]578 }
[7ea9e6]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
[c78d44]589 * \param &elements vector of elements to correlate to surface
[7ea9e6]590 * \param *Surface pointer to Tesselation class surface
[6bd7e0]591 * \param *LC LinkedCell_deprecated structure to quickly find neighbouring atoms
[7ea9e6]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 */
[6bd7e0]595CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell_deprecated *LC, const int ranges[NDIM] )
[7ea9e6]596{
[3930eb]597 Info FunctionInfo(__func__);
[caa30b]598 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
[7ea9e6]599 double distance = 0;
600 class BoundaryTriangleSet *triangle = NULL;
601 Vector centroid;
[99593f]602 int n[NDIM];
603 Vector periodicX;
604 Vector checkX;
[c4d4df]605
[e65de8]606 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
[47d041]607 LOG(1, "No Tesselation, no LinkedCell or no molecule given.");
[c4d4df]608 return outmap;
609 }
[e65de8]610 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
[009607e]611 (*MolWalker)->doCountAtoms();
[c4d4df]612 outmap = new CorrelationToSurfaceMap;
[244a84]613 double ShortestDistance = 0.;
614 BoundaryTriangleSet *ShortestTriangle = NULL;
[e65de8]615 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
[cca9ef]616 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
617 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
[47d041]618 LOG(2, "Current molecule is " << *MolWalker << ".");
[e65de8]619 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
[47d041]620 LOG(3, "Current atom is " << **iter << ".");
[e5c0a1]621 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]622 if ((*type == NULL) || ((*iter)->getType() == *type)) {
623 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
[e65de8]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);
[d74077]630 TriangleIntersectionList Intersections(checkX,Surface,LC);
[e65de8]631 distance = Intersections.GetSmallestDistance();
632 triangle = Intersections.GetClosestTriangle();
633 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
634 ShortestDistance = distance;
635 ShortestTriangle = triangle;
[99593f]636 }
[e65de8]637 }
638 // insert
[59fff1]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 );
[47d041]648 //LOG(1, "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << ".");
[e65de8]649 }
[c4d4df]650 }
[e65de8]651 }
[c4d4df]652
653 return outmap;
654};
655
[bd61b41]656/** Returns the index of the bin for a given value.
[c4d4df]657 * \param value value whose bin to look for
658 * \param BinWidth width of bin
659 * \param BinStart first bin
660 */
[bd61b41]661int GetBin ( const double value, const double BinWidth, const double BinStart )
[c4d4df]662{
[92e5cb]663 //Info FunctionInfo(__func__);
[bd61b41]664 int bin =(int) (floor((value - BinStart)/BinWidth));
665 return (bin);
[c4d4df]666};
667
668
[92e5cb]669/** Adds header part that is unique to BinPairMap.
670 *
671 * @param file stream to print to
[c4d4df]672 */
[92e5cb]673void OutputCorrelation_Header( ofstream * const file )
[c4d4df]674{
[92e5cb]675 *file << "\tCount";
[c4d4df]676};
[b1f254]677
[92e5cb]678/** Prints values stored in BinPairMap iterator.
679 *
680 * @param file stream to print to
681 * @param runner iterator pointing at values to print
[be945c]682 */
[92e5cb]683void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner )
[be945c]684{
[92e5cb]685 *file << runner->second;
[be945c]686};
687
[92e5cb]688
689/** Adds header part that is unique to DipoleAngularCorrelationMap.
690 *
691 * @param file stream to print to
[b1f254]692 */
[92e5cb]693void OutputDipoleAngularCorrelation_Header( ofstream * const file )
[b1f254]694{
[4b8630]695 *file << "\tFirstAtomOfMolecule";
[b1f254]696};
697
[208237b]698/** Prints values stored in DipoleCorrelationMap iterator.
[92e5cb]699 *
700 * @param file stream to print to
701 * @param runner iterator pointing at values to print
[b1f254]702 */
[92e5cb]703void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner )
[208237b]704{
[505d05]705 *file << *(runner->second);
[208237b]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 )
[b1f254]724{
[92e5cb]725 *file << runner->second.first->getId() << "\t" << runner->second.second->getId();
[b1f254]726};
727
[92e5cb]728
729/** Adds header part that is unique to PairCorrelationMap.
730 *
731 * @param file stream to print to
[b1f254]732 */
[92e5cb]733void OutputPairCorrelation_Header( ofstream * const file )
[b1f254]734{
[92e5cb]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));
[b1f254]767};
768
[92e5cb]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.