source: src/analysis_correlation.cpp@ be945c

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 be945c was be945c, checked in by Frederik Heber <heber@…>, 15 years ago

New DipoleAngularCorrelationAction that calculates angular correlation between dipoles.

  • Property mode set to 100644
File size: 25.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"
26#include "bond.hpp"
[d74077]27#include "BoundaryTriangleSet.hpp"
[be945c]28#include "Box.hpp"
[c4d4df]29#include "element.hpp"
[ad011c]30#include "CodePatterns/Info.hpp"
31#include "CodePatterns/Log.hpp"
[ea430a]32#include "Formula.hpp"
[c4d4df]33#include "molecule.hpp"
34#include "tesselation.hpp"
35#include "tesselationhelpers.hpp"
[8db598]36#include "triangleintersectionlist.hpp"
[be945c]37#include "World.hpp"
[57f243]38#include "LinearAlgebra/Vector.hpp"
[cca9ef]39#include "LinearAlgebra/RealSpaceMatrix.hpp"
[ad011c]40#include "CodePatterns/Verbose.hpp"
[b34306]41#include "World.hpp"
[84c494]42#include "Box.hpp"
[c4d4df]43
[be945c]44#include "analysis_correlation.hpp"
45
46/** Calculates the dipole vector of a given atomSet.
47 *
48 * Note that we use the following procedure as rule of thumb:
49 * -# go through every bond of the atom
50 * -# calculate the difference of electronegativities \f$\Delta\text{EN}\f$
51 * -# if \f$\Delta\text{EN} > 0.5\f$, we align the bond vector in direction of the more negative element
52 * -# sum up all vectors
53 * -# finally, divide by the number of summed vectors
54 *
55 * @param atomsbegin begin iterator of atomSet
56 * @param atomsend end iterator of atomset
57 * @return dipole vector
58 */
59Vector getDipole(molecule::const_iterator atomsbegin, molecule::const_iterator atomsend)
60{
61 Vector DipoleVector;
62 size_t SumOfVectors = 0;
63 // go through all atoms
64 for (molecule::const_iterator atomiter = atomsbegin;
65 atomiter != atomsend;
66 ++atomiter) {
67 // go through all bonds
68 for (BondList::const_iterator bonditer = (*atomiter)->ListOfBonds.begin();
69 bonditer != (*atomiter)->ListOfBonds.end();
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.
91 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
[be945c]92 * Angles are given in degrees.
[ea430a]93 * \param *molecules vector of molecules
94 * \return Map of doubles with values the pair of the two atoms.
95 */
[be945c]96DipoleAngularCorrelationMap *DipoleAngularCorrelation(std::vector<molecule *> &molecules)
[ea430a]97{
98 Info FunctionInfo(__func__);
99 DipoleAngularCorrelationMap *outmap = NULL;
100// double distance = 0.;
101// Box &domain = World::getInstance().getDomain();
102//
[be945c]103 if (molecules.empty()) {
104 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
105 return outmap;
106 }
107
108 outmap = new DipoleAngularCorrelationMap;
109 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
110 MolWalker != molecules.end();) {
111 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is "
112 << (*MolWalker)->getId() << "." << endl);
113 const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
114 for (std::vector<molecule *>::const_iterator MolOtherWalker = ++MolWalker;
115 MolOtherWalker != molecules.end();
116 MolOtherWalker++) {
117 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is "
118 << (*MolOtherWalker)->getId() << "." << endl);
119 const Vector OtherDipole = getDipole((*MolOtherWalker)->begin(), (*MolOtherWalker)->end());
120 const double angle = Dipole.Angle(OtherDipole) * (180./M_PI);
121 DoLog(1) && (Log() << Verbose(1) << "Angle is " << angle << "." << endl);
122 outmap->insert ( make_pair (angle, make_pair ((*MolWalker), (*MolOtherWalker)) ) );
123 }
124 }
[ea430a]125 return outmap;
126};
127
[c4d4df]128
129/** Calculates the pair correlation between given elements.
130 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
[e65de8]131 * \param *molecules vector of molecules
[c78d44]132 * \param &elements vector of elements to correlate
[c4d4df]133 * \return Map of doubles with values the pair of the two atoms.
134 */
[e5c0a1]135PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements)
[c4d4df]136{
[3930eb]137 Info FunctionInfo(__func__);
[c4d4df]138 PairCorrelationMap *outmap = NULL;
139 double distance = 0.;
[014475]140 Box &domain = World::getInstance().getDomain();
[c4d4df]141
[e65de8]142 if (molecules.empty()) {
[58ed4a]143 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
[c4d4df]144 return outmap;
145 }
[e65de8]146 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
[009607e]147 (*MolWalker)->doCountAtoms();
[c78d44]148
149 // create all possible pairs of elements
[e5c0a1]150 set <pair<const element *,const element *> > PairsOfElements;
[c78d44]151 if (elements.size() >= 2) {
[e5c0a1]152 for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
153 for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
[c78d44]154 if (type1 != type2) {
[e5c0a1]155 PairsOfElements.insert( make_pair(*type1,*type2) );
[2fe971]156 DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
[c78d44]157 }
158 } else if (elements.size() == 1) { // one to all are valid
[e5c0a1]159 const element *elemental = *elements.begin();
160 PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
161 PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
[c78d44]162 } else { // all elements valid
163 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
164 }
165
[c4d4df]166 outmap = new PairCorrelationMap;
[e65de8]167 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
168 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
169 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
170 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
171 for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
172 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
173 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
174 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
175 if ((*iter)->getId() < (*runner)->getId()){
[b5c53d]176 for (set <pair<const element *, const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
[d74077]177 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
178 distance = domain.periodicDistance((*iter)->getPosition(),(*runner)->getPosition());
[e65de8]179 //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
180 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
[a5551b]181 }
[c4d4df]182 }
[a5551b]183 }
[c4d4df]184 }
185 }
[24725c]186 }
[c4d4df]187 return outmap;
188};
189
[7ea9e6]190/** Calculates the pair correlation between given elements.
191 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
192 * \param *molecules list of molecules structure
[c78d44]193 * \param &elements vector of elements to correlate
[7ea9e6]194 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
195 * \return Map of doubles with values the pair of the two atoms.
196 */
[e5c0a1]197PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] )
[7ea9e6]198{
[3930eb]199 Info FunctionInfo(__func__);
[7ea9e6]200 PairCorrelationMap *outmap = NULL;
201 double distance = 0.;
202 int n[NDIM];
203 Vector checkX;
204 Vector periodicX;
205 int Othern[NDIM];
206 Vector checkOtherX;
207 Vector periodicOtherX;
208
[e65de8]209 if (molecules.empty()) {
[58ed4a]210 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
[7ea9e6]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
[7ea9e6]233 outmap = new PairCorrelationMap;
[e65de8]234 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
[cca9ef]235 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
236 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
[e65de8]237 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
238 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
239 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
[d74077]240 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
[e65de8]241 // go through every range in xyz and get distance
242 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
243 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
244 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
245 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
246 for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
247 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
248 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
249 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
250 if ((*iter)->getId() < (*runner)->getId()){
[e5c0a1]251 for (set <pair<const element *,const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
[d74077]252 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
253 periodicOtherX = FullInverseMatrix * ((*runner)->getPosition()); // x now in [0,1)^3
[e65de8]254 // go through every range in xyz and get distance
255 for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
256 for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
257 for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
258 checkOtherX = FullMatrix * (Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX);
259 distance = checkX.distance(checkOtherX);
260 //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
261 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
262 }
263 }
[c78d44]264 }
[7ea9e6]265 }
[c78d44]266 }
[7ea9e6]267 }
268 }
[c78d44]269 }
[7ea9e6]270
271 return outmap;
272};
273
[c4d4df]274/** Calculates the distance (pair) correlation between a given element and a point.
[a5551b]275 * \param *molecules list of molecules structure
[c78d44]276 * \param &elements vector of elements to correlate with point
[c4d4df]277 * \param *point vector to the correlation point
278 * \return Map of dobules with values as pairs of atom and the vector
279 */
[e5c0a1]280CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
[c4d4df]281{
[3930eb]282 Info FunctionInfo(__func__);
[c4d4df]283 CorrelationToPointMap *outmap = NULL;
284 double distance = 0.;
[014475]285 Box &domain = World::getInstance().getDomain();
[c4d4df]286
[e65de8]287 if (molecules.empty()) {
[a67d19]288 DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
[c4d4df]289 return outmap;
290 }
[e65de8]291 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
[009607e]292 (*MolWalker)->doCountAtoms();
[c4d4df]293 outmap = new CorrelationToPointMap;
[e65de8]294 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
295 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
296 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
297 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
[e5c0a1]298 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]299 if ((*type == NULL) || ((*iter)->getType() == *type)) {
300 distance = domain.periodicDistance((*iter)->getPosition(),*point);
[e65de8]301 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
302 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
303 }
[c4d4df]304 }
[e65de8]305 }
[c4d4df]306
307 return outmap;
308};
309
[7ea9e6]310/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
311 * \param *molecules list of molecules structure
[c78d44]312 * \param &elements vector of elements to correlate to point
[7ea9e6]313 * \param *point vector to the correlation point
314 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
315 * \return Map of dobules with values as pairs of atom and the vector
316 */
[e5c0a1]317CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
[7ea9e6]318{
[3930eb]319 Info FunctionInfo(__func__);
[7ea9e6]320 CorrelationToPointMap *outmap = NULL;
321 double distance = 0.;
322 int n[NDIM];
323 Vector periodicX;
324 Vector checkX;
325
[e65de8]326 if (molecules.empty()) {
[a67d19]327 DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
[7ea9e6]328 return outmap;
329 }
[e65de8]330 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
[009607e]331 (*MolWalker)->doCountAtoms();
[7ea9e6]332 outmap = new CorrelationToPointMap;
[e65de8]333 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
[cca9ef]334 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
335 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
[e65de8]336 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
337 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
338 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
[e5c0a1]339 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]340 if ((*type == NULL) || ((*iter)->getType() == *type)) {
341 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
[e65de8]342 // go through every range in xyz and get distance
343 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
344 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
345 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
346 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
347 distance = checkX.distance(*point);
348 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
349 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
350 }
351 }
[7ea9e6]352 }
[e65de8]353 }
[7ea9e6]354
355 return outmap;
356};
357
[c4d4df]358/** Calculates the distance (pair) correlation between a given element and a surface.
[a5551b]359 * \param *molecules list of molecules structure
[c78d44]360 * \param &elements vector of elements to correlate to surface
[c4d4df]361 * \param *Surface pointer to Tesselation class surface
362 * \param *LC LinkedCell structure to quickly find neighbouring atoms
363 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
364 */
[e5c0a1]365CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
[c4d4df]366{
[3930eb]367 Info FunctionInfo(__func__);
[c4d4df]368 CorrelationToSurfaceMap *outmap = NULL;
[99593f]369 double distance = 0;
[c4d4df]370 class BoundaryTriangleSet *triangle = NULL;
371 Vector centroid;
[7ea9e6]372
[e65de8]373 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
[58ed4a]374 DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
[7ea9e6]375 return outmap;
376 }
[e65de8]377 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
[009607e]378 (*MolWalker)->doCountAtoms();
[7ea9e6]379 outmap = new CorrelationToSurfaceMap;
[e65de8]380 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
381 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << (*MolWalker)->name << "." << endl);
382 if ((*MolWalker)->empty())
383 DoLog(2) && (2) && (Log() << Verbose(2) << "\t is empty." << endl);
384 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
385 DoLog(3) && (Log() << Verbose(3) << "\tCurrent atom is " << *(*iter) << "." << endl);
[e5c0a1]386 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]387 if ((*type == NULL) || ((*iter)->getType() == *type)) {
388 TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
[e65de8]389 distance = Intersections.GetSmallestDistance();
390 triangle = Intersections.GetClosestTriangle();
391 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
392 }
[7fd416]393 }
[e65de8]394 }
[7ea9e6]395
396 return outmap;
397};
398
399/** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
400 * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
401 * 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
402 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
403 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
404 * \param *molecules list of molecules structure
[c78d44]405 * \param &elements vector of elements to correlate to surface
[7ea9e6]406 * \param *Surface pointer to Tesselation class surface
407 * \param *LC LinkedCell structure to quickly find neighbouring atoms
408 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
409 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
410 */
[e5c0a1]411CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
[7ea9e6]412{
[3930eb]413 Info FunctionInfo(__func__);
[7ea9e6]414 CorrelationToSurfaceMap *outmap = NULL;
415 double distance = 0;
416 class BoundaryTriangleSet *triangle = NULL;
417 Vector centroid;
[99593f]418 int n[NDIM];
419 Vector periodicX;
420 Vector checkX;
[c4d4df]421
[e65de8]422 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
[a67d19]423 DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
[c4d4df]424 return outmap;
425 }
[e65de8]426 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
[009607e]427 (*MolWalker)->doCountAtoms();
[c4d4df]428 outmap = new CorrelationToSurfaceMap;
[244a84]429 double ShortestDistance = 0.;
430 BoundaryTriangleSet *ShortestTriangle = NULL;
[e65de8]431 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
[cca9ef]432 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
433 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
[e65de8]434 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
435 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
436 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
[e5c0a1]437 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]438 if ((*type == NULL) || ((*iter)->getType() == *type)) {
439 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
[e65de8]440 // go through every range in xyz and get distance
441 ShortestDistance = -1.;
442 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
443 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
444 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
445 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
[d74077]446 TriangleIntersectionList Intersections(checkX,Surface,LC);
[e65de8]447 distance = Intersections.GetSmallestDistance();
448 triangle = Intersections.GetClosestTriangle();
449 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
450 ShortestDistance = distance;
451 ShortestTriangle = triangle;
[99593f]452 }
[e65de8]453 }
454 // insert
455 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
456 //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
457 }
[c4d4df]458 }
[e65de8]459 }
[c4d4df]460
461 return outmap;
462};
463
[bd61b41]464/** Returns the index of the bin for a given value.
[c4d4df]465 * \param value value whose bin to look for
466 * \param BinWidth width of bin
467 * \param BinStart first bin
468 */
[bd61b41]469int GetBin ( const double value, const double BinWidth, const double BinStart )
[c4d4df]470{
[3930eb]471 Info FunctionInfo(__func__);
[bd61b41]472 int bin =(int) (floor((value - BinStart)/BinWidth));
473 return (bin);
[c4d4df]474};
475
476
477/** Prints correlation (double, int) pairs to file.
478 * \param *file file to write to
479 * \param *map map to write
480 */
[a5551b]481void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
[c4d4df]482{
[3930eb]483 Info FunctionInfo(__func__);
[790807]484 *file << "BinStart\tCount" << endl;
[776b64]485 for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
[775d133]486 *file << setprecision(8) << runner->first << "\t" << runner->second << endl;
[c4d4df]487 }
488};
[b1f254]489
[be945c]490/** Prints correlation (double, (atom*,atom*) ) pairs to file.
491 * \param *file file to write to
492 * \param *map map to write
493 */
494void OutputDipoleAngularCorrelation( ofstream * const file, const DipoleAngularCorrelationMap * const map )
495{
496 Info FunctionInfo(__func__);
497 *file << "BinStart\tMolecule1\tMolecule2" << endl;
498 for (DipoleAngularCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
499 *file << setprecision(8) << runner->first << "\t" << runner->second.first->getId() << "\t" << runner->second.second->getId() << endl;
500 }
501};
502
[b1f254]503/** Prints correlation (double, (atom*,atom*) ) pairs to file.
504 * \param *file file to write to
505 * \param *map map to write
506 */
[a5551b]507void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
[b1f254]508{
[3930eb]509 Info FunctionInfo(__func__);
[790807]510 *file << "BinStart\tAtom1\tAtom2" << endl;
[776b64]511 for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
[775d133]512 *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
[b1f254]513 }
514};
515
516/** Prints correlation (double, int) pairs to file.
517 * \param *file file to write to
518 * \param *map map to write
519 */
[a5551b]520void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
[b1f254]521{
[3930eb]522 Info FunctionInfo(__func__);
[790807]523 *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
[776b64]524 for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
[b1f254]525 *file << runner->first;
526 for (int i=0;i<NDIM;i++)
[d74077]527 *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
[b1f254]528 *file << endl;
529 }
530};
531
532/** Prints correlation (double, int) pairs to file.
533 * \param *file file to write to
534 * \param *map map to write
535 */
[a5551b]536void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
[b1f254]537{
[3930eb]538 Info FunctionInfo(__func__);
[790807]539 *file << "BinStart\tTriangle" << endl;
[8db598]540 if (!map->empty())
541 for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
[d74077]542 *file << setprecision(8) << runner->first << "\t";
543 *file << *(runner->second.first) << "\t";
544 *file << *(runner->second.second) << endl;
[8db598]545 }
[b1f254]546};
547
Note: See TracBrowser for help on using the repository browser.