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