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.hpp"
|
---|
27 | #include "BoundaryTriangleSet.hpp"
|
---|
28 | #include "Box.hpp"
|
---|
29 | #include "element.hpp"
|
---|
30 | #include "CodePatterns/Info.hpp"
|
---|
31 | #include "CodePatterns/Log.hpp"
|
---|
32 | #include "Formula.hpp"
|
---|
33 | #include "molecule.hpp"
|
---|
34 | #include "tesselation.hpp"
|
---|
35 | #include "tesselationhelpers.hpp"
|
---|
36 | #include "triangleintersectionlist.hpp"
|
---|
37 | #include "World.hpp"
|
---|
38 | #include "LinearAlgebra/Vector.hpp"
|
---|
39 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
|
---|
40 | #include "CodePatterns/Verbose.hpp"
|
---|
41 | #include "World.hpp"
|
---|
42 | #include "Box.hpp"
|
---|
43 |
|
---|
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 | */
|
---|
59 | Vector 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 |
|
---|
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))
|
---|
92 | * Angles are given in degrees.
|
---|
93 | * \param *molecules vector of molecules
|
---|
94 | * \return Map of doubles with values the pair of the two atoms.
|
---|
95 | */
|
---|
96 | DipoleAngularCorrelationMap *DipoleAngularCorrelation(std::vector<molecule *> &molecules)
|
---|
97 | {
|
---|
98 | Info FunctionInfo(__func__);
|
---|
99 | DipoleAngularCorrelationMap *outmap = new DipoleAngularCorrelationMap;
|
---|
100 | // double distance = 0.;
|
---|
101 | // Box &domain = World::getInstance().getDomain();
|
---|
102 | //
|
---|
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 | }
|
---|
125 | return outmap;
|
---|
126 | };
|
---|
127 |
|
---|
128 |
|
---|
129 | /** Calculates the pair correlation between given elements.
|
---|
130 | * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
|
---|
131 | * \param *molecules vector of molecules
|
---|
132 | * \param &elements vector of elements to correlate
|
---|
133 | * \return Map of doubles with values the pair of the two atoms.
|
---|
134 | */
|
---|
135 | PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements)
|
---|
136 | {
|
---|
137 | Info FunctionInfo(__func__);
|
---|
138 | PairCorrelationMap *outmap = new PairCorrelationMap;
|
---|
139 | double distance = 0.;
|
---|
140 | Box &domain = World::getInstance().getDomain();
|
---|
141 |
|
---|
142 | if (molecules.empty()) {
|
---|
143 | DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
|
---|
144 | return outmap;
|
---|
145 | }
|
---|
146 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
147 | (*MolWalker)->doCountAtoms();
|
---|
148 |
|
---|
149 | // create all possible pairs of elements
|
---|
150 | set <pair<const element *,const element *> > PairsOfElements;
|
---|
151 | if (elements.size() >= 2) {
|
---|
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)
|
---|
154 | if (type1 != type2) {
|
---|
155 | PairsOfElements.insert( make_pair(*type1,*type2) );
|
---|
156 | DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
|
---|
157 | }
|
---|
158 | } else if (elements.size() == 1) { // one to all are valid
|
---|
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) );
|
---|
162 | } else { // all elements valid
|
---|
163 | PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
|
---|
164 | }
|
---|
165 |
|
---|
166 | outmap = new PairCorrelationMap;
|
---|
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()){
|
---|
176 | for (set <pair<const element *, const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
|
---|
177 | if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
|
---|
178 | distance = domain.periodicDistance((*iter)->getPosition(),(*runner)->getPosition());
|
---|
179 | //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
|
---|
180 | outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
|
---|
181 | }
|
---|
182 | }
|
---|
183 | }
|
---|
184 | }
|
---|
185 | }
|
---|
186 | }
|
---|
187 | return outmap;
|
---|
188 | };
|
---|
189 |
|
---|
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
|
---|
193 | * \param &elements vector of elements to correlate
|
---|
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 | */
|
---|
197 | PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] )
|
---|
198 | {
|
---|
199 | Info FunctionInfo(__func__);
|
---|
200 | PairCorrelationMap *outmap = new PairCorrelationMap;
|
---|
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 |
|
---|
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 | RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
236 | RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
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);
|
---|
240 | periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
|
---|
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()){
|
---|
251 | for (set <pair<const element *,const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
|
---|
252 | if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
|
---|
253 | periodicOtherX = FullInverseMatrix * ((*runner)->getPosition()); // x now in [0,1)^3
|
---|
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 | }
|
---|
264 | }
|
---|
265 | }
|
---|
266 | }
|
---|
267 | }
|
---|
268 | }
|
---|
269 | }
|
---|
270 |
|
---|
271 | return outmap;
|
---|
272 | };
|
---|
273 |
|
---|
274 | /** Calculates the distance (pair) correlation between a given element and a point.
|
---|
275 | * \param *molecules list of molecules structure
|
---|
276 | * \param &elements vector of elements to correlate with point
|
---|
277 | * \param *point vector to the correlation point
|
---|
278 | * \return Map of dobules with values as pairs of atom and the vector
|
---|
279 | */
|
---|
280 | CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
|
---|
281 | {
|
---|
282 | Info FunctionInfo(__func__);
|
---|
283 | CorrelationToPointMap *outmap = new CorrelationToPointMap;
|
---|
284 | double distance = 0.;
|
---|
285 | Box &domain = World::getInstance().getDomain();
|
---|
286 |
|
---|
287 | if (molecules.empty()) {
|
---|
288 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
---|
289 | return outmap;
|
---|
290 | }
|
---|
291 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
292 | (*MolWalker)->doCountAtoms();
|
---|
293 | outmap = new CorrelationToPointMap;
|
---|
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);
|
---|
298 | for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
299 | if ((*type == NULL) || ((*iter)->getType() == *type)) {
|
---|
300 | distance = domain.periodicDistance((*iter)->getPosition(),*point);
|
---|
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 | }
|
---|
304 | }
|
---|
305 | }
|
---|
306 |
|
---|
307 | return outmap;
|
---|
308 | };
|
---|
309 |
|
---|
310 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
|
---|
311 | * \param *molecules list of molecules structure
|
---|
312 | * \param &elements vector of elements to correlate to point
|
---|
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 | */
|
---|
317 | CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
|
---|
318 | {
|
---|
319 | Info FunctionInfo(__func__);
|
---|
320 | CorrelationToPointMap *outmap = new CorrelationToPointMap;
|
---|
321 | double distance = 0.;
|
---|
322 | int n[NDIM];
|
---|
323 | Vector periodicX;
|
---|
324 | Vector checkX;
|
---|
325 |
|
---|
326 | if (molecules.empty()) {
|
---|
327 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
---|
328 | return outmap;
|
---|
329 | }
|
---|
330 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
331 | (*MolWalker)->doCountAtoms();
|
---|
332 | outmap = new CorrelationToPointMap;
|
---|
333 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
|
---|
334 | RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
335 | RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
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);
|
---|
339 | for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
340 | if ((*type == NULL) || ((*iter)->getType() == *type)) {
|
---|
341 | periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
|
---|
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 | }
|
---|
352 | }
|
---|
353 | }
|
---|
354 |
|
---|
355 | return outmap;
|
---|
356 | };
|
---|
357 |
|
---|
358 | /** Calculates the distance (pair) correlation between a given element and a surface.
|
---|
359 | * \param *molecules list of molecules structure
|
---|
360 | * \param &elements vector of elements to correlate to surface
|
---|
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 | */
|
---|
365 | CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
|
---|
366 | {
|
---|
367 | Info FunctionInfo(__func__);
|
---|
368 | CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
|
---|
369 | double distance = 0;
|
---|
370 | class BoundaryTriangleSet *triangle = NULL;
|
---|
371 | Vector centroid;
|
---|
372 |
|
---|
373 | if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
|
---|
374 | DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
---|
375 | return outmap;
|
---|
376 | }
|
---|
377 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
378 | (*MolWalker)->doCountAtoms();
|
---|
379 | outmap = new CorrelationToSurfaceMap;
|
---|
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);
|
---|
386 | for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
387 | if ((*type == NULL) || ((*iter)->getType() == *type)) {
|
---|
388 | TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
|
---|
389 | distance = Intersections.GetSmallestDistance();
|
---|
390 | triangle = Intersections.GetClosestTriangle();
|
---|
391 | outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
|
---|
392 | }
|
---|
393 | }
|
---|
394 | }
|
---|
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
|
---|
405 | * \param &elements vector of elements to correlate to surface
|
---|
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 | */
|
---|
411 | CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
|
---|
412 | {
|
---|
413 | Info FunctionInfo(__func__);
|
---|
414 | CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
|
---|
415 | double distance = 0;
|
---|
416 | class BoundaryTriangleSet *triangle = NULL;
|
---|
417 | Vector centroid;
|
---|
418 | int n[NDIM];
|
---|
419 | Vector periodicX;
|
---|
420 | Vector checkX;
|
---|
421 |
|
---|
422 | if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
|
---|
423 | DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
---|
424 | return outmap;
|
---|
425 | }
|
---|
426 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
427 | (*MolWalker)->doCountAtoms();
|
---|
428 | outmap = new CorrelationToSurfaceMap;
|
---|
429 | double ShortestDistance = 0.;
|
---|
430 | BoundaryTriangleSet *ShortestTriangle = NULL;
|
---|
431 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
|
---|
432 | RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
433 | RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
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);
|
---|
437 | for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
438 | if ((*type == NULL) || ((*iter)->getType() == *type)) {
|
---|
439 | periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
|
---|
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);
|
---|
446 | TriangleIntersectionList Intersections(checkX,Surface,LC);
|
---|
447 | distance = Intersections.GetSmallestDistance();
|
---|
448 | triangle = Intersections.GetClosestTriangle();
|
---|
449 | if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
|
---|
450 | ShortestDistance = distance;
|
---|
451 | ShortestTriangle = triangle;
|
---|
452 | }
|
---|
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 | }
|
---|
458 | }
|
---|
459 | }
|
---|
460 |
|
---|
461 | return outmap;
|
---|
462 | };
|
---|
463 |
|
---|
464 | /** Returns the index of the bin for a given value.
|
---|
465 | * \param value value whose bin to look for
|
---|
466 | * \param BinWidth width of bin
|
---|
467 | * \param BinStart first bin
|
---|
468 | */
|
---|
469 | int GetBin ( const double value, const double BinWidth, const double BinStart )
|
---|
470 | {
|
---|
471 | Info FunctionInfo(__func__);
|
---|
472 | int bin =(int) (floor((value - BinStart)/BinWidth));
|
---|
473 | return (bin);
|
---|
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 | */
|
---|
481 | void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
|
---|
482 | {
|
---|
483 | Info FunctionInfo(__func__);
|
---|
484 | *file << "BinStart\tCount" << endl;
|
---|
485 | for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
486 | *file << setprecision(8) << runner->first << "\t" << runner->second << endl;
|
---|
487 | }
|
---|
488 | };
|
---|
489 |
|
---|
490 | /** Prints correlation (double, (atom*,atom*) ) pairs to file.
|
---|
491 | * \param *file file to write to
|
---|
492 | * \param *map map to write
|
---|
493 | */
|
---|
494 | void 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 |
|
---|
503 | /** Prints correlation (double, (atom*,atom*) ) pairs to file.
|
---|
504 | * \param *file file to write to
|
---|
505 | * \param *map map to write
|
---|
506 | */
|
---|
507 | void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
|
---|
508 | {
|
---|
509 | Info FunctionInfo(__func__);
|
---|
510 | *file << "BinStart\tAtom1\tAtom2" << endl;
|
---|
511 | for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
512 | *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
|
---|
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 | */
|
---|
520 | void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
|
---|
521 | {
|
---|
522 | Info FunctionInfo(__func__);
|
---|
523 | *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
|
---|
524 | for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
525 | *file << runner->first;
|
---|
526 | for (int i=0;i<NDIM;i++)
|
---|
527 | *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
|
---|
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 | */
|
---|
536 | void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
|
---|
537 | {
|
---|
538 | Info FunctionInfo(__func__);
|
---|
539 | *file << "BinStart\tTriangle" << endl;
|
---|
540 | if (!map->empty())
|
---|
541 | for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
542 | *file << setprecision(8) << runner->first << "\t";
|
---|
543 | *file << *(runner->second.first) << "\t";
|
---|
544 | *file << *(runner->second.second) << endl;
|
---|
545 | }
|
---|
546 | };
|
---|
547 |
|
---|