source: src/Analysis/analysis_correlation.cpp@ c3a70d

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 c3a70d was 870b4b, checked in by Frederik Heber <heber@…>, 14 years ago

Added rejected molecule counting to DipoleAngularCorrelation().

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