source: src/Analysis/analysis_correlation.cpp@ 4fc828

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

DipoleAngularCorrelation working with multi-timestep PDBs with CONECT entries.

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