source: src/Analysis/analysis_correlation.cpp@ df8759

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 Candidate_v1.7.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 df8759 was 208237b, checked in by Frederik Heber <heber@…>, 14 years ago

Renamed DipoleAngularCorrelation(Action) -> DipoleCorrelation(Action) and new DipoleAngularCorrelation(Action).

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