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 "Helpers/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include <iostream>
|
---|
23 | #include <iomanip>
|
---|
24 |
|
---|
25 | #include "BoundaryTriangleSet.hpp"
|
---|
26 | #include "analysis_correlation.hpp"
|
---|
27 | #include "element.hpp"
|
---|
28 | #include "Helpers/Info.hpp"
|
---|
29 | #include "Helpers/Log.hpp"
|
---|
30 | #include "molecule.hpp"
|
---|
31 | #include "tesselation.hpp"
|
---|
32 | #include "tesselationhelpers.hpp"
|
---|
33 | #include "triangleintersectionlist.hpp"
|
---|
34 | #include "LinearAlgebra/Vector.hpp"
|
---|
35 | #include "LinearAlgebra/Matrix.hpp"
|
---|
36 | #include "Helpers/Verbose.hpp"
|
---|
37 | #include "World.hpp"
|
---|
38 | #include "Box.hpp"
|
---|
39 |
|
---|
40 |
|
---|
41 | /** Calculates the pair correlation between given elements.
|
---|
42 | * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
|
---|
43 | * \param *molecules vector of molecules
|
---|
44 | * \param &elements vector of elements to correlate
|
---|
45 | * \return Map of doubles with values the pair of the two atoms.
|
---|
46 | */
|
---|
47 | PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements)
|
---|
48 | {
|
---|
49 | Info FunctionInfo(__func__);
|
---|
50 | PairCorrelationMap *outmap = NULL;
|
---|
51 | double distance = 0.;
|
---|
52 | Box &domain = World::getInstance().getDomain();
|
---|
53 |
|
---|
54 | if (molecules.empty()) {
|
---|
55 | DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
|
---|
56 | return outmap;
|
---|
57 | }
|
---|
58 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
59 | (*MolWalker)->doCountAtoms();
|
---|
60 |
|
---|
61 | // create all possible pairs of elements
|
---|
62 | set <pair<const element *,const element *> > PairsOfElements;
|
---|
63 | if (elements.size() >= 2) {
|
---|
64 | for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
|
---|
65 | for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
|
---|
66 | if (type1 != type2) {
|
---|
67 | PairsOfElements.insert( make_pair(*type1,*type2) );
|
---|
68 | DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
|
---|
69 | }
|
---|
70 | } else if (elements.size() == 1) { // one to all are valid
|
---|
71 | const element *elemental = *elements.begin();
|
---|
72 | PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
|
---|
73 | PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
|
---|
74 | } else { // all elements valid
|
---|
75 | PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
|
---|
76 | }
|
---|
77 |
|
---|
78 | outmap = new PairCorrelationMap;
|
---|
79 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
|
---|
80 | DoLog(2) && (Log()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
81 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
82 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
83 | for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
|
---|
84 | DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
|
---|
85 | for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
|
---|
86 | DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
|
---|
87 | if ((*iter)->getId() < (*runner)->getId()){
|
---|
88 | for (set <pair<const element *, const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
|
---|
89 | if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
|
---|
90 | distance = domain.periodicDistance((*iter)->getPosition(),(*runner)->getPosition());
|
---|
91 | //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
|
---|
92 | outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | return outmap;
|
---|
100 | };
|
---|
101 |
|
---|
102 | /** Calculates the pair correlation between given elements.
|
---|
103 | * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
|
---|
104 | * \param *molecules list of molecules structure
|
---|
105 | * \param &elements vector of elements to correlate
|
---|
106 | * \param ranges[NDIM] interval boundaries for the periodic images to scan also
|
---|
107 | * \return Map of doubles with values the pair of the two atoms.
|
---|
108 | */
|
---|
109 | PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] )
|
---|
110 | {
|
---|
111 | Info FunctionInfo(__func__);
|
---|
112 | PairCorrelationMap *outmap = NULL;
|
---|
113 | double distance = 0.;
|
---|
114 | int n[NDIM];
|
---|
115 | Vector checkX;
|
---|
116 | Vector periodicX;
|
---|
117 | int Othern[NDIM];
|
---|
118 | Vector checkOtherX;
|
---|
119 | Vector periodicOtherX;
|
---|
120 |
|
---|
121 | if (molecules.empty()) {
|
---|
122 | DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
|
---|
123 | return outmap;
|
---|
124 | }
|
---|
125 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
126 | (*MolWalker)->doCountAtoms();
|
---|
127 |
|
---|
128 | // create all possible pairs of elements
|
---|
129 | set <pair<const element *,const element *> > PairsOfElements;
|
---|
130 | if (elements.size() >= 2) {
|
---|
131 | for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
|
---|
132 | for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
|
---|
133 | if (type1 != type2) {
|
---|
134 | PairsOfElements.insert( make_pair(*type1,*type2) );
|
---|
135 | DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
|
---|
136 | }
|
---|
137 | } else if (elements.size() == 1) { // one to all are valid
|
---|
138 | const element *elemental = *elements.begin();
|
---|
139 | PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
|
---|
140 | PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
|
---|
141 | } else { // all elements valid
|
---|
142 | PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
|
---|
143 | }
|
---|
144 |
|
---|
145 | outmap = new PairCorrelationMap;
|
---|
146 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
|
---|
147 | Matrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
148 | Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
149 | DoLog(2) && (Log()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
150 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
151 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
152 | periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
|
---|
153 | // go through every range in xyz and get distance
|
---|
154 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
|
---|
155 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
|
---|
156 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
|
---|
157 | checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
|
---|
158 | for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
|
---|
159 | DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
|
---|
160 | for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
|
---|
161 | DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
|
---|
162 | if ((*iter)->getId() < (*runner)->getId()){
|
---|
163 | for (set <pair<const element *,const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
|
---|
164 | if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
|
---|
165 | periodicOtherX = FullInverseMatrix * ((*runner)->getPosition()); // x now in [0,1)^3
|
---|
166 | // go through every range in xyz and get distance
|
---|
167 | for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
|
---|
168 | for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
|
---|
169 | for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
|
---|
170 | checkOtherX = FullMatrix * (Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX);
|
---|
171 | distance = checkX.distance(checkOtherX);
|
---|
172 | //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
|
---|
173 | outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
|
---|
174 | }
|
---|
175 | }
|
---|
176 | }
|
---|
177 | }
|
---|
178 | }
|
---|
179 | }
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | return outmap;
|
---|
184 | };
|
---|
185 |
|
---|
186 | /** Calculates the distance (pair) correlation between a given element and a point.
|
---|
187 | * \param *molecules list of molecules structure
|
---|
188 | * \param &elements vector of elements to correlate with point
|
---|
189 | * \param *point vector to the correlation point
|
---|
190 | * \return Map of dobules with values as pairs of atom and the vector
|
---|
191 | */
|
---|
192 | CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
|
---|
193 | {
|
---|
194 | Info FunctionInfo(__func__);
|
---|
195 | CorrelationToPointMap *outmap = NULL;
|
---|
196 | double distance = 0.;
|
---|
197 | Box &domain = World::getInstance().getDomain();
|
---|
198 |
|
---|
199 | if (molecules.empty()) {
|
---|
200 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
---|
201 | return outmap;
|
---|
202 | }
|
---|
203 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
204 | (*MolWalker)->doCountAtoms();
|
---|
205 | outmap = new CorrelationToPointMap;
|
---|
206 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
|
---|
207 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
208 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
209 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
210 | for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
211 | if ((*type == NULL) || ((*iter)->getType() == *type)) {
|
---|
212 | distance = domain.periodicDistance((*iter)->getPosition(),*point);
|
---|
213 | DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
|
---|
214 | outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
|
---|
215 | }
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 | return outmap;
|
---|
220 | };
|
---|
221 |
|
---|
222 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
|
---|
223 | * \param *molecules list of molecules structure
|
---|
224 | * \param &elements vector of elements to correlate to point
|
---|
225 | * \param *point vector to the correlation point
|
---|
226 | * \param ranges[NDIM] interval boundaries for the periodic images to scan also
|
---|
227 | * \return Map of dobules with values as pairs of atom and the vector
|
---|
228 | */
|
---|
229 | CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
|
---|
230 | {
|
---|
231 | Info FunctionInfo(__func__);
|
---|
232 | CorrelationToPointMap *outmap = NULL;
|
---|
233 | double distance = 0.;
|
---|
234 | int n[NDIM];
|
---|
235 | Vector periodicX;
|
---|
236 | Vector checkX;
|
---|
237 |
|
---|
238 | if (molecules.empty()) {
|
---|
239 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
---|
240 | return outmap;
|
---|
241 | }
|
---|
242 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
243 | (*MolWalker)->doCountAtoms();
|
---|
244 | outmap = new CorrelationToPointMap;
|
---|
245 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
|
---|
246 | Matrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
247 | Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
248 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
249 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
250 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
251 | for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
252 | if ((*type == NULL) || ((*iter)->getType() == *type)) {
|
---|
253 | periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
|
---|
254 | // go through every range in xyz and get distance
|
---|
255 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
|
---|
256 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
|
---|
257 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
|
---|
258 | checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
|
---|
259 | distance = checkX.distance(*point);
|
---|
260 | DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
|
---|
261 | outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
|
---|
262 | }
|
---|
263 | }
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | return outmap;
|
---|
268 | };
|
---|
269 |
|
---|
270 | /** Calculates the distance (pair) correlation between a given element and a surface.
|
---|
271 | * \param *molecules list of molecules structure
|
---|
272 | * \param &elements vector of elements to correlate to surface
|
---|
273 | * \param *Surface pointer to Tesselation class surface
|
---|
274 | * \param *LC LinkedCell structure to quickly find neighbouring atoms
|
---|
275 | * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
|
---|
276 | */
|
---|
277 | CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
|
---|
278 | {
|
---|
279 | Info FunctionInfo(__func__);
|
---|
280 | CorrelationToSurfaceMap *outmap = NULL;
|
---|
281 | double distance = 0;
|
---|
282 | class BoundaryTriangleSet *triangle = NULL;
|
---|
283 | Vector centroid;
|
---|
284 |
|
---|
285 | if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
|
---|
286 | DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
---|
287 | return outmap;
|
---|
288 | }
|
---|
289 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
290 | (*MolWalker)->doCountAtoms();
|
---|
291 | outmap = new CorrelationToSurfaceMap;
|
---|
292 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
|
---|
293 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << (*MolWalker)->name << "." << endl);
|
---|
294 | if ((*MolWalker)->empty())
|
---|
295 | DoLog(2) && (2) && (Log() << Verbose(2) << "\t is empty." << endl);
|
---|
296 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
297 | DoLog(3) && (Log() << Verbose(3) << "\tCurrent 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 | TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
|
---|
301 | distance = Intersections.GetSmallestDistance();
|
---|
302 | triangle = Intersections.GetClosestTriangle();
|
---|
303 | outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
|
---|
304 | }
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | return outmap;
|
---|
309 | };
|
---|
310 |
|
---|
311 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
|
---|
312 | * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
|
---|
313 | * 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
|
---|
314 | * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
|
---|
315 | * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
|
---|
316 | * \param *molecules list of molecules structure
|
---|
317 | * \param &elements vector of elements to correlate to surface
|
---|
318 | * \param *Surface pointer to Tesselation class surface
|
---|
319 | * \param *LC LinkedCell structure to quickly find neighbouring atoms
|
---|
320 | * \param ranges[NDIM] interval boundaries for the periodic images to scan also
|
---|
321 | * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
|
---|
322 | */
|
---|
323 | CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
|
---|
324 | {
|
---|
325 | Info FunctionInfo(__func__);
|
---|
326 | CorrelationToSurfaceMap *outmap = NULL;
|
---|
327 | double distance = 0;
|
---|
328 | class BoundaryTriangleSet *triangle = NULL;
|
---|
329 | Vector centroid;
|
---|
330 | int n[NDIM];
|
---|
331 | Vector periodicX;
|
---|
332 | Vector checkX;
|
---|
333 |
|
---|
334 | if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
|
---|
335 | DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
---|
336 | return outmap;
|
---|
337 | }
|
---|
338 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
|
---|
339 | (*MolWalker)->doCountAtoms();
|
---|
340 | outmap = new CorrelationToSurfaceMap;
|
---|
341 | double ShortestDistance = 0.;
|
---|
342 | BoundaryTriangleSet *ShortestTriangle = NULL;
|
---|
343 | for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
|
---|
344 | Matrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
345 | Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
346 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
347 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
348 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
349 | for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
350 | if ((*type == NULL) || ((*iter)->getType() == *type)) {
|
---|
351 | periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
|
---|
352 | // go through every range in xyz and get distance
|
---|
353 | ShortestDistance = -1.;
|
---|
354 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
|
---|
355 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
|
---|
356 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
|
---|
357 | checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
|
---|
358 | TriangleIntersectionList Intersections(checkX,Surface,LC);
|
---|
359 | distance = Intersections.GetSmallestDistance();
|
---|
360 | triangle = Intersections.GetClosestTriangle();
|
---|
361 | if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
|
---|
362 | ShortestDistance = distance;
|
---|
363 | ShortestTriangle = triangle;
|
---|
364 | }
|
---|
365 | }
|
---|
366 | // insert
|
---|
367 | outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
|
---|
368 | //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
|
---|
369 | }
|
---|
370 | }
|
---|
371 | }
|
---|
372 |
|
---|
373 | return outmap;
|
---|
374 | };
|
---|
375 |
|
---|
376 | /** Returns the index of the bin for a given value.
|
---|
377 | * \param value value whose bin to look for
|
---|
378 | * \param BinWidth width of bin
|
---|
379 | * \param BinStart first bin
|
---|
380 | */
|
---|
381 | int GetBin ( const double value, const double BinWidth, const double BinStart )
|
---|
382 | {
|
---|
383 | Info FunctionInfo(__func__);
|
---|
384 | int bin =(int) (floor((value - BinStart)/BinWidth));
|
---|
385 | return (bin);
|
---|
386 | };
|
---|
387 |
|
---|
388 |
|
---|
389 | /** Prints correlation (double, int) pairs to file.
|
---|
390 | * \param *file file to write to
|
---|
391 | * \param *map map to write
|
---|
392 | */
|
---|
393 | void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
|
---|
394 | {
|
---|
395 | Info FunctionInfo(__func__);
|
---|
396 | *file << "BinStart\tCount" << endl;
|
---|
397 | for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
398 | *file << setprecision(8) << runner->first << "\t" << runner->second << endl;
|
---|
399 | }
|
---|
400 | };
|
---|
401 |
|
---|
402 | /** Prints correlation (double, (atom*,atom*) ) pairs to file.
|
---|
403 | * \param *file file to write to
|
---|
404 | * \param *map map to write
|
---|
405 | */
|
---|
406 | void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
|
---|
407 | {
|
---|
408 | Info FunctionInfo(__func__);
|
---|
409 | *file << "BinStart\tAtom1\tAtom2" << endl;
|
---|
410 | for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
411 | *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
|
---|
412 | }
|
---|
413 | };
|
---|
414 |
|
---|
415 | /** Prints correlation (double, int) pairs to file.
|
---|
416 | * \param *file file to write to
|
---|
417 | * \param *map map to write
|
---|
418 | */
|
---|
419 | void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
|
---|
420 | {
|
---|
421 | Info FunctionInfo(__func__);
|
---|
422 | *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
|
---|
423 | for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
424 | *file << runner->first;
|
---|
425 | for (int i=0;i<NDIM;i++)
|
---|
426 | *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
|
---|
427 | *file << endl;
|
---|
428 | }
|
---|
429 | };
|
---|
430 |
|
---|
431 | /** Prints correlation (double, int) pairs to file.
|
---|
432 | * \param *file file to write to
|
---|
433 | * \param *map map to write
|
---|
434 | */
|
---|
435 | void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
|
---|
436 | {
|
---|
437 | Info FunctionInfo(__func__);
|
---|
438 | *file << "BinStart\tTriangle" << endl;
|
---|
439 | if (!map->empty())
|
---|
440 | for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
441 | *file << setprecision(8) << runner->first << "\t";
|
---|
442 | *file << *(runner->second.first) << "\t";
|
---|
443 | *file << *(runner->second.second) << endl;
|
---|
444 | }
|
---|
445 | };
|
---|
446 |
|
---|