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