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 | */
|
---|
58 | Vector 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 | for (BondList::const_iterator bonditer = ListOfBonds.begin();
|
---|
69 | bonditer != 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 |
|
---|
90 | /** Calculates the dipole angular correlation for given molecule type.
|
---|
91 | * Calculate the change of the dipole orientation angle over time.
|
---|
92 | * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
|
---|
93 | * Angles are given in degrees.
|
---|
94 | * \param *molecules vector of molecules
|
---|
95 | * \return Map of doubles with values the pair of the two atoms.
|
---|
96 | */
|
---|
97 | DipoleAngularCorrelationMap *DipoleAngularCorrelation(std::vector<molecule *> &molecules)
|
---|
98 | {
|
---|
99 | Info FunctionInfo(__func__);
|
---|
100 | DipoleAngularCorrelationMap *outmap = new DipoleAngularCorrelationMap;
|
---|
101 | // double distance = 0.;
|
---|
102 | // Box &domain = World::getInstance().getDomain();
|
---|
103 | //
|
---|
104 | if (molecules.empty()) {
|
---|
105 | DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
|
---|
106 | return outmap;
|
---|
107 | }
|
---|
108 |
|
---|
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 | */
|
---|
163 | DipoleCorrelationMap *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 |
|
---|
175 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
|
---|
176 | MolWalker != molecules.end(); ++MolWalker) {
|
---|
177 | DoLog(2) && (Log()<< Verbose(2) << "Current molecule is "
|
---|
178 | << (*MolWalker)->getId() << "." << endl);
|
---|
179 | const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
|
---|
180 | std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker;
|
---|
181 | for (++MolOtherWalker;
|
---|
182 | MolOtherWalker != molecules.end();
|
---|
183 | ++MolOtherWalker) {
|
---|
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 | }
|
---|
192 | return outmap;
|
---|
193 | };
|
---|
194 |
|
---|
195 |
|
---|
196 | /** Calculates the pair correlation between given elements.
|
---|
197 | * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
|
---|
198 | * \param *molecules vector of molecules
|
---|
199 | * \param &elements vector of elements to correlate
|
---|
200 | * \return Map of doubles with values the pair of the two atoms.
|
---|
201 | */
|
---|
202 | PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements)
|
---|
203 | {
|
---|
204 | Info FunctionInfo(__func__);
|
---|
205 | PairCorrelationMap *outmap = new PairCorrelationMap;
|
---|
206 | double distance = 0.;
|
---|
207 | Box &domain = World::getInstance().getDomain();
|
---|
208 |
|
---|
209 | if (molecules.empty()) {
|
---|
210 | DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
|
---|
211 | return outmap;
|
---|
212 | }
|
---|
213 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
214 | (*MolWalker)->doCountAtoms();
|
---|
215 |
|
---|
216 | // create all possible pairs of elements
|
---|
217 | set <pair<const element *,const element *> > PairsOfElements;
|
---|
218 | if (elements.size() >= 2) {
|
---|
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)
|
---|
221 | if (type1 != type2) {
|
---|
222 | PairsOfElements.insert( make_pair(*type1,*type2) );
|
---|
223 | DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
|
---|
224 | }
|
---|
225 | } else if (elements.size() == 1) { // one to all are valid
|
---|
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) );
|
---|
229 | } else { // all elements valid
|
---|
230 | PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
|
---|
231 | }
|
---|
232 |
|
---|
233 | outmap = new PairCorrelationMap;
|
---|
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()){
|
---|
243 | for (set <pair<const element *, const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
|
---|
244 | if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
|
---|
245 | distance = domain.periodicDistance((*iter)->getPosition(),(*runner)->getPosition());
|
---|
246 | //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
|
---|
247 | outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
|
---|
248 | }
|
---|
249 | }
|
---|
250 | }
|
---|
251 | }
|
---|
252 | }
|
---|
253 | }
|
---|
254 | return outmap;
|
---|
255 | };
|
---|
256 |
|
---|
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
|
---|
260 | * \param &elements vector of elements to correlate
|
---|
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 | */
|
---|
264 | PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] )
|
---|
265 | {
|
---|
266 | Info FunctionInfo(__func__);
|
---|
267 | PairCorrelationMap *outmap = new PairCorrelationMap;
|
---|
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 |
|
---|
276 | if (molecules.empty()) {
|
---|
277 | DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
|
---|
278 | return outmap;
|
---|
279 | }
|
---|
280 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
281 | (*MolWalker)->doCountAtoms();
|
---|
282 |
|
---|
283 | // create all possible pairs of elements
|
---|
284 | set <pair<const element *,const element *> > PairsOfElements;
|
---|
285 | if (elements.size() >= 2) {
|
---|
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)
|
---|
288 | if (type1 != type2) {
|
---|
289 | PairsOfElements.insert( make_pair(*type1,*type2) );
|
---|
290 | DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
|
---|
291 | }
|
---|
292 | } else if (elements.size() == 1) { // one to all are valid
|
---|
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) );
|
---|
296 | } else { // all elements valid
|
---|
297 | PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
|
---|
298 | }
|
---|
299 |
|
---|
300 | outmap = new PairCorrelationMap;
|
---|
301 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
|
---|
302 | RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
303 | RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
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);
|
---|
307 | periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
|
---|
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()){
|
---|
318 | for (set <pair<const element *,const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
|
---|
319 | if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
|
---|
320 | periodicOtherX = FullInverseMatrix * ((*runner)->getPosition()); // x now in [0,1)^3
|
---|
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 | }
|
---|
331 | }
|
---|
332 | }
|
---|
333 | }
|
---|
334 | }
|
---|
335 | }
|
---|
336 | }
|
---|
337 |
|
---|
338 | return outmap;
|
---|
339 | };
|
---|
340 |
|
---|
341 | /** Calculates the distance (pair) correlation between a given element and a point.
|
---|
342 | * \param *molecules list of molecules structure
|
---|
343 | * \param &elements vector of elements to correlate with point
|
---|
344 | * \param *point vector to the correlation point
|
---|
345 | * \return Map of dobules with values as pairs of atom and the vector
|
---|
346 | */
|
---|
347 | CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
|
---|
348 | {
|
---|
349 | Info FunctionInfo(__func__);
|
---|
350 | CorrelationToPointMap *outmap = new CorrelationToPointMap;
|
---|
351 | double distance = 0.;
|
---|
352 | Box &domain = World::getInstance().getDomain();
|
---|
353 |
|
---|
354 | if (molecules.empty()) {
|
---|
355 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
---|
356 | return outmap;
|
---|
357 | }
|
---|
358 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
359 | (*MolWalker)->doCountAtoms();
|
---|
360 | outmap = new CorrelationToPointMap;
|
---|
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);
|
---|
365 | for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
366 | if ((*type == NULL) || ((*iter)->getType() == *type)) {
|
---|
367 | distance = domain.periodicDistance((*iter)->getPosition(),*point);
|
---|
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 | }
|
---|
371 | }
|
---|
372 | }
|
---|
373 |
|
---|
374 | return outmap;
|
---|
375 | };
|
---|
376 |
|
---|
377 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
|
---|
378 | * \param *molecules list of molecules structure
|
---|
379 | * \param &elements vector of elements to correlate to point
|
---|
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 | */
|
---|
384 | CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
|
---|
385 | {
|
---|
386 | Info FunctionInfo(__func__);
|
---|
387 | CorrelationToPointMap *outmap = new CorrelationToPointMap;
|
---|
388 | double distance = 0.;
|
---|
389 | int n[NDIM];
|
---|
390 | Vector periodicX;
|
---|
391 | Vector checkX;
|
---|
392 |
|
---|
393 | if (molecules.empty()) {
|
---|
394 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
---|
395 | return outmap;
|
---|
396 | }
|
---|
397 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
398 | (*MolWalker)->doCountAtoms();
|
---|
399 | outmap = new CorrelationToPointMap;
|
---|
400 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
|
---|
401 | RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
402 | RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
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);
|
---|
406 | for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
407 | if ((*type == NULL) || ((*iter)->getType() == *type)) {
|
---|
408 | periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
|
---|
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 | }
|
---|
419 | }
|
---|
420 | }
|
---|
421 |
|
---|
422 | return outmap;
|
---|
423 | };
|
---|
424 |
|
---|
425 | /** Calculates the distance (pair) correlation between a given element and a surface.
|
---|
426 | * \param *molecules list of molecules structure
|
---|
427 | * \param &elements vector of elements to correlate to surface
|
---|
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 | */
|
---|
432 | CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
|
---|
433 | {
|
---|
434 | Info FunctionInfo(__func__);
|
---|
435 | CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
|
---|
436 | double distance = 0;
|
---|
437 | class BoundaryTriangleSet *triangle = NULL;
|
---|
438 | Vector centroid;
|
---|
439 |
|
---|
440 | if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
|
---|
441 | DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
---|
442 | return outmap;
|
---|
443 | }
|
---|
444 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
445 | (*MolWalker)->doCountAtoms();
|
---|
446 | outmap = new CorrelationToSurfaceMap;
|
---|
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);
|
---|
453 | for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
454 | if ((*type == NULL) || ((*iter)->getType() == *type)) {
|
---|
455 | TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
|
---|
456 | distance = Intersections.GetSmallestDistance();
|
---|
457 | triangle = Intersections.GetClosestTriangle();
|
---|
458 | outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
|
---|
459 | }
|
---|
460 | }
|
---|
461 | }
|
---|
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
|
---|
472 | * \param &elements vector of elements to correlate to surface
|
---|
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 | */
|
---|
478 | CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
|
---|
479 | {
|
---|
480 | Info FunctionInfo(__func__);
|
---|
481 | CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
|
---|
482 | double distance = 0;
|
---|
483 | class BoundaryTriangleSet *triangle = NULL;
|
---|
484 | Vector centroid;
|
---|
485 | int n[NDIM];
|
---|
486 | Vector periodicX;
|
---|
487 | Vector checkX;
|
---|
488 |
|
---|
489 | if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
|
---|
490 | DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
---|
491 | return outmap;
|
---|
492 | }
|
---|
493 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
494 | (*MolWalker)->doCountAtoms();
|
---|
495 | outmap = new CorrelationToSurfaceMap;
|
---|
496 | double ShortestDistance = 0.;
|
---|
497 | BoundaryTriangleSet *ShortestTriangle = NULL;
|
---|
498 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
|
---|
499 | RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
500 | RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
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);
|
---|
504 | for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
505 | if ((*type == NULL) || ((*iter)->getType() == *type)) {
|
---|
506 | periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
|
---|
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);
|
---|
513 | TriangleIntersectionList Intersections(checkX,Surface,LC);
|
---|
514 | distance = Intersections.GetSmallestDistance();
|
---|
515 | triangle = Intersections.GetClosestTriangle();
|
---|
516 | if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
|
---|
517 | ShortestDistance = distance;
|
---|
518 | ShortestTriangle = triangle;
|
---|
519 | }
|
---|
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 | }
|
---|
525 | }
|
---|
526 | }
|
---|
527 |
|
---|
528 | return outmap;
|
---|
529 | };
|
---|
530 |
|
---|
531 | /** Returns the index of the bin for a given value.
|
---|
532 | * \param value value whose bin to look for
|
---|
533 | * \param BinWidth width of bin
|
---|
534 | * \param BinStart first bin
|
---|
535 | */
|
---|
536 | int GetBin ( const double value, const double BinWidth, const double BinStart )
|
---|
537 | {
|
---|
538 | //Info FunctionInfo(__func__);
|
---|
539 | int bin =(int) (floor((value - BinStart)/BinWidth));
|
---|
540 | return (bin);
|
---|
541 | };
|
---|
542 |
|
---|
543 |
|
---|
544 | /** Adds header part that is unique to BinPairMap.
|
---|
545 | *
|
---|
546 | * @param file stream to print to
|
---|
547 | */
|
---|
548 | void OutputCorrelation_Header( ofstream * const file )
|
---|
549 | {
|
---|
550 | *file << "\tCount";
|
---|
551 | };
|
---|
552 |
|
---|
553 | /** Prints values stored in BinPairMap iterator.
|
---|
554 | *
|
---|
555 | * @param file stream to print to
|
---|
556 | * @param runner iterator pointing at values to print
|
---|
557 | */
|
---|
558 | void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner )
|
---|
559 | {
|
---|
560 | *file << runner->second;
|
---|
561 | };
|
---|
562 |
|
---|
563 |
|
---|
564 | /** Adds header part that is unique to DipoleAngularCorrelationMap.
|
---|
565 | *
|
---|
566 | * @param file stream to print to
|
---|
567 | */
|
---|
568 | void OutputDipoleAngularCorrelation_Header( ofstream * const file )
|
---|
569 | {
|
---|
570 | *file << "\tMolecule1\tMolecule2";
|
---|
571 | };
|
---|
572 |
|
---|
573 | /** Prints values stored in DipoleCorrelationMap iterator.
|
---|
574 | *
|
---|
575 | * @param file stream to print to
|
---|
576 | * @param runner iterator pointing at values to print
|
---|
577 | */
|
---|
578 | void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner )
|
---|
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 | */
|
---|
588 | void 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 | */
|
---|
598 | void OutputDipoleCorrelation_Value( ofstream * const file, DipoleCorrelationMap::const_iterator &runner )
|
---|
599 | {
|
---|
600 | *file << runner->second.first->getId() << "\t" << runner->second.second->getId();
|
---|
601 | };
|
---|
602 |
|
---|
603 |
|
---|
604 | /** Adds header part that is unique to PairCorrelationMap.
|
---|
605 | *
|
---|
606 | * @param file stream to print to
|
---|
607 | */
|
---|
608 | void OutputPairCorrelation_Header( ofstream * const file )
|
---|
609 | {
|
---|
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 | */
|
---|
618 | void 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 | */
|
---|
628 | void 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 | */
|
---|
638 | void 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));
|
---|
642 | };
|
---|
643 |
|
---|
644 |
|
---|
645 | /** Adds header part that is unique to CorrelationToSurfaceMap.
|
---|
646 | *
|
---|
647 | * @param file stream to print to
|
---|
648 | */
|
---|
649 | void 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 | */
|
---|
659 | void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner )
|
---|
660 | {
|
---|
661 | *file << *(runner->second.first) << "\t" << *(runner->second.second);
|
---|
662 | };
|
---|