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