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