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