| [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);
|
|---|
| [c78d44] | 144 | periodicX = *(*iter)->node;
|
|---|
| 145 | periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
|
|---|
| 146 | // go through every range in xyz and get distance
|
|---|
| 147 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
|
|---|
| 148 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
|
|---|
| 149 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
|
|---|
| 150 | checkX = Vector(n[0], n[1], n[2]) + periodicX;
|
|---|
| 151 | checkX.MatrixMultiplication(FullMatrix);
|
|---|
| 152 | for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){
|
|---|
| 153 | if ((*MolOtherWalker)->ActiveFlag) {
|
|---|
| 154 | DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
|
|---|
| 155 | for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
|
|---|
| 156 | DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
|
|---|
| 157 | if ((*iter)->getId() < (*runner)->getId()){
|
|---|
| 158 | for (set <pair<element *, element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
|
|---|
| 159 | if ((PairRunner->first == (**iter).type) && (PairRunner->second == (**runner).type)) {
|
|---|
| [a7b761b] | 160 | periodicOtherX = *(*runner)->node;
|
|---|
| [7ea9e6] | 161 | periodicOtherX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
|
|---|
| 162 | // go through every range in xyz and get distance
|
|---|
| 163 | for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
|
|---|
| 164 | for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
|
|---|
| 165 | for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
|
|---|
| [273382] | 166 | checkOtherX = Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX;
|
|---|
| [7ea9e6] | 167 | checkOtherX.MatrixMultiplication(FullMatrix);
|
|---|
| [1513a74] | 168 | distance = checkX.distance(checkOtherX);
|
|---|
| [9879f6] | 169 | //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
|
|---|
| 170 | outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
|
|---|
| [7ea9e6] | 171 | }
|
|---|
| 172 | }
|
|---|
| [c78d44] | 173 | }
|
|---|
| [7ea9e6] | 174 | }
|
|---|
| [c78d44] | 175 | }
|
|---|
| [7ea9e6] | 176 | }
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 | }
|
|---|
| [c78d44] | 180 | }
|
|---|
| [7ea9e6] | 181 |
|
|---|
| 182 | return outmap;
|
|---|
| 183 | };
|
|---|
| 184 |
|
|---|
| [c4d4df] | 185 | /** Calculates the distance (pair) correlation between a given element and a point.
|
|---|
| [a5551b] | 186 | * \param *molecules list of molecules structure
|
|---|
| [c78d44] | 187 | * \param &elements vector of elements to correlate with point
|
|---|
| [c4d4df] | 188 | * \param *point vector to the correlation point
|
|---|
| 189 | * \return Map of dobules with values as pairs of atom and the vector
|
|---|
| 190 | */
|
|---|
| [c78d44] | 191 | CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point )
|
|---|
| [c4d4df] | 192 | {
|
|---|
| [3930eb] | 193 | Info FunctionInfo(__func__);
|
|---|
| [c4d4df] | 194 | CorrelationToPointMap *outmap = NULL;
|
|---|
| 195 | double distance = 0.;
|
|---|
| [58bbd3] | 196 | double *cell_size = World::getInstance().getDomain();
|
|---|
| [c4d4df] | 197 |
|
|---|
| [a5551b] | 198 | if (molecules->ListOfMolecules.empty()) {
|
|---|
| [a67d19] | 199 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
|---|
| [c4d4df] | 200 | return outmap;
|
|---|
| 201 | }
|
|---|
| [009607e] | 202 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
|---|
| 203 | (*MolWalker)->doCountAtoms();
|
|---|
| [c4d4df] | 204 | outmap = new CorrelationToPointMap;
|
|---|
| [a5551b] | 205 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
|---|
| 206 | if ((*MolWalker)->ActiveFlag) {
|
|---|
| [a67d19] | 207 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
|---|
| [9879f6] | 208 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
|---|
| [a7b761b] | 209 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
|---|
| [c78d44] | 210 | for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
|---|
| 211 | if ((*type == NULL) || ((*iter)->type == *type)) {
|
|---|
| [58bbd3] | 212 | distance = (*iter)->node->PeriodicDistance(*point, cell_size);
|
|---|
| [c78d44] | 213 | DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
|
|---|
| 214 | outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
|
|---|
| 215 | }
|
|---|
| [a5551b] | 216 | }
|
|---|
| [c4d4df] | 217 | }
|
|---|
| 218 |
|
|---|
| 219 | return outmap;
|
|---|
| 220 | };
|
|---|
| 221 |
|
|---|
| [7ea9e6] | 222 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
|
|---|
| 223 | * \param *molecules list of molecules structure
|
|---|
| [c78d44] | 224 | * \param &elements vector of elements to correlate to point
|
|---|
| [7ea9e6] | 225 | * \param *point vector to the correlation point
|
|---|
| 226 | * \param ranges[NDIM] interval boundaries for the periodic images to scan also
|
|---|
| 227 | * \return Map of dobules with values as pairs of atom and the vector
|
|---|
| 228 | */
|
|---|
| [c78d44] | 229 | CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point, const int ranges[NDIM] )
|
|---|
| [7ea9e6] | 230 | {
|
|---|
| [3930eb] | 231 | Info FunctionInfo(__func__);
|
|---|
| [7ea9e6] | 232 | CorrelationToPointMap *outmap = NULL;
|
|---|
| 233 | double distance = 0.;
|
|---|
| 234 | int n[NDIM];
|
|---|
| 235 | Vector periodicX;
|
|---|
| 236 | Vector checkX;
|
|---|
| 237 |
|
|---|
| 238 | if (molecules->ListOfMolecules.empty()) {
|
|---|
| [a67d19] | 239 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
|---|
| [7ea9e6] | 240 | return outmap;
|
|---|
| 241 | }
|
|---|
| [009607e] | 242 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
|---|
| 243 | (*MolWalker)->doCountAtoms();
|
|---|
| [7ea9e6] | 244 | outmap = new CorrelationToPointMap;
|
|---|
| 245 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
|---|
| 246 | if ((*MolWalker)->ActiveFlag) {
|
|---|
| [d10eb6] | 247 | Matrix FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
|
|---|
| [c94eeb] | 248 | Matrix FullInverseMatrix = FullMatrix.invert();
|
|---|
| [a67d19] | 249 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
|---|
| [9879f6] | 250 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
|---|
| [a7b761b] | 251 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
|---|
| [c78d44] | 252 | for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
|---|
| 253 | if ((*type == NULL) || ((*iter)->type == *type)) {
|
|---|
| 254 | periodicX = *(*iter)->node;
|
|---|
| 255 | periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
|
|---|
| 256 | // go through every range in xyz and get distance
|
|---|
| 257 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
|
|---|
| 258 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
|
|---|
| 259 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
|
|---|
| 260 | checkX = Vector(n[0], n[1], n[2]) + periodicX;
|
|---|
| 261 | checkX.MatrixMultiplication(FullMatrix);
|
|---|
| 262 | distance = checkX.distance(*point);
|
|---|
| 263 | DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
|
|---|
| 264 | outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
|
|---|
| 265 | }
|
|---|
| 266 | }
|
|---|
| [7ea9e6] | 267 | }
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | return outmap;
|
|---|
| 271 | };
|
|---|
| 272 |
|
|---|
| [c4d4df] | 273 | /** Calculates the distance (pair) correlation between a given element and a surface.
|
|---|
| [a5551b] | 274 | * \param *molecules list of molecules structure
|
|---|
| [c78d44] | 275 | * \param &elements vector of elements to correlate to surface
|
|---|
| [c4d4df] | 276 | * \param *Surface pointer to Tesselation class surface
|
|---|
| 277 | * \param *LC LinkedCell structure to quickly find neighbouring atoms
|
|---|
| 278 | * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
|
|---|
| 279 | */
|
|---|
| [c78d44] | 280 | CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
|
|---|
| [c4d4df] | 281 | {
|
|---|
| [3930eb] | 282 | Info FunctionInfo(__func__);
|
|---|
| [c4d4df] | 283 | CorrelationToSurfaceMap *outmap = NULL;
|
|---|
| [99593f] | 284 | double distance = 0;
|
|---|
| [c4d4df] | 285 | class BoundaryTriangleSet *triangle = NULL;
|
|---|
| 286 | Vector centroid;
|
|---|
| [7ea9e6] | 287 |
|
|---|
| 288 | if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
|
|---|
| [58ed4a] | 289 | DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
|---|
| [7ea9e6] | 290 | return outmap;
|
|---|
| 291 | }
|
|---|
| [009607e] | 292 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
|---|
| 293 | (*MolWalker)->doCountAtoms();
|
|---|
| [7ea9e6] | 294 | outmap = new CorrelationToSurfaceMap;
|
|---|
| 295 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
|---|
| 296 | if ((*MolWalker)->ActiveFlag) {
|
|---|
| [a67d19] | 297 | DoLog(1) && (Log() << Verbose(1) << "Current molecule is " << (*MolWalker)->name << "." << endl);
|
|---|
| [7fd416] | 298 | if ((*MolWalker)->empty())
|
|---|
| 299 | DoLog(1) && (1) && (Log() << Verbose(1) << "\t is empty." << endl);
|
|---|
| [9879f6] | 300 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
|---|
| [7fd416] | 301 | DoLog(1) && (Log() << Verbose(1) << "\tCurrent atom is " << *(*iter) << "." << endl);
|
|---|
| [c78d44] | 302 | for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
|---|
| 303 | if ((*type == NULL) || ((*iter)->type == *type)) {
|
|---|
| 304 | TriangleIntersectionList Intersections((*iter)->node,Surface,LC);
|
|---|
| 305 | distance = Intersections.GetSmallestDistance();
|
|---|
| 306 | triangle = Intersections.GetClosestTriangle();
|
|---|
| 307 | outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
|
|---|
| 308 | }
|
|---|
| [7ea9e6] | 309 | }
|
|---|
| [7fd416] | 310 | } else {
|
|---|
| [a67d19] | 311 | DoLog(1) && (Log() << Verbose(1) << "molecule " << (*MolWalker)->name << " is not active." << endl);
|
|---|
| [7fd416] | 312 | }
|
|---|
| [7ea9e6] | 313 |
|
|---|
| 314 | return outmap;
|
|---|
| 315 | };
|
|---|
| 316 |
|
|---|
| 317 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
|
|---|
| 318 | * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
|
|---|
| 319 | * 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
|
|---|
| 320 | * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
|
|---|
| 321 | * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
|
|---|
| 322 | * \param *molecules list of molecules structure
|
|---|
| [c78d44] | 323 | * \param &elements vector of elements to correlate to surface
|
|---|
| [7ea9e6] | 324 | * \param *Surface pointer to Tesselation class surface
|
|---|
| 325 | * \param *LC LinkedCell structure to quickly find neighbouring atoms
|
|---|
| 326 | * \param ranges[NDIM] interval boundaries for the periodic images to scan also
|
|---|
| 327 | * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
|
|---|
| 328 | */
|
|---|
| [c78d44] | 329 | CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
|
|---|
| [7ea9e6] | 330 | {
|
|---|
| [3930eb] | 331 | Info FunctionInfo(__func__);
|
|---|
| [7ea9e6] | 332 | CorrelationToSurfaceMap *outmap = NULL;
|
|---|
| 333 | double distance = 0;
|
|---|
| 334 | class BoundaryTriangleSet *triangle = NULL;
|
|---|
| 335 | Vector centroid;
|
|---|
| [99593f] | 336 | int n[NDIM];
|
|---|
| 337 | Vector periodicX;
|
|---|
| 338 | Vector checkX;
|
|---|
| [c4d4df] | 339 |
|
|---|
| [a5551b] | 340 | if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
|
|---|
| [a67d19] | 341 | DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
|---|
| [c4d4df] | 342 | return outmap;
|
|---|
| 343 | }
|
|---|
| [009607e] | 344 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
|---|
| 345 | (*MolWalker)->doCountAtoms();
|
|---|
| [c4d4df] | 346 | outmap = new CorrelationToSurfaceMap;
|
|---|
| [244a84] | 347 | double ShortestDistance = 0.;
|
|---|
| 348 | BoundaryTriangleSet *ShortestTriangle = NULL;
|
|---|
| [a5551b] | 349 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
|---|
| 350 | if ((*MolWalker)->ActiveFlag) {
|
|---|
| [d10eb6] | 351 | Matrix FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
|
|---|
| [c94eeb] | 352 | Matrix FullInverseMatrix = FullMatrix.invert();
|
|---|
| [a67d19] | 353 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
|---|
| [9879f6] | 354 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
|---|
| [a7b761b] | 355 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
|---|
| [c78d44] | 356 | for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
|---|
| 357 | if ((*type == NULL) || ((*iter)->type == *type)) {
|
|---|
| 358 | periodicX = *(*iter)->node;
|
|---|
| 359 | periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
|
|---|
| 360 | // go through every range in xyz and get distance
|
|---|
| 361 | ShortestDistance = -1.;
|
|---|
| 362 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
|
|---|
| 363 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
|
|---|
| 364 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
|
|---|
| 365 | checkX = Vector(n[0], n[1], n[2]) + periodicX;
|
|---|
| 366 | checkX.MatrixMultiplication(FullMatrix);
|
|---|
| 367 | TriangleIntersectionList Intersections(&checkX,Surface,LC);
|
|---|
| 368 | distance = Intersections.GetSmallestDistance();
|
|---|
| 369 | triangle = Intersections.GetClosestTriangle();
|
|---|
| 370 | if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
|
|---|
| 371 | ShortestDistance = distance;
|
|---|
| 372 | ShortestTriangle = triangle;
|
|---|
| 373 | }
|
|---|
| [99593f] | 374 | }
|
|---|
| [c78d44] | 375 | // insert
|
|---|
| 376 | outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
|
|---|
| 377 | //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
|
|---|
| 378 | }
|
|---|
| [c4d4df] | 379 | }
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | return outmap;
|
|---|
| 383 | };
|
|---|
| 384 |
|
|---|
| [bd61b41] | 385 | /** Returns the index of the bin for a given value.
|
|---|
| [c4d4df] | 386 | * \param value value whose bin to look for
|
|---|
| 387 | * \param BinWidth width of bin
|
|---|
| 388 | * \param BinStart first bin
|
|---|
| 389 | */
|
|---|
| [bd61b41] | 390 | int GetBin ( const double value, const double BinWidth, const double BinStart )
|
|---|
| [c4d4df] | 391 | {
|
|---|
| [3930eb] | 392 | Info FunctionInfo(__func__);
|
|---|
| [bd61b41] | 393 | int bin =(int) (floor((value - BinStart)/BinWidth));
|
|---|
| 394 | return (bin);
|
|---|
| [c4d4df] | 395 | };
|
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 | /** Prints correlation (double, int) pairs to file.
|
|---|
| 399 | * \param *file file to write to
|
|---|
| 400 | * \param *map map to write
|
|---|
| 401 | */
|
|---|
| [a5551b] | 402 | void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
|
|---|
| [c4d4df] | 403 | {
|
|---|
| [3930eb] | 404 | Info FunctionInfo(__func__);
|
|---|
| [790807] | 405 | *file << "BinStart\tCount" << endl;
|
|---|
| [776b64] | 406 | for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
|---|
| [775d133] | 407 | *file << setprecision(8) << runner->first << "\t" << runner->second << endl;
|
|---|
| [c4d4df] | 408 | }
|
|---|
| 409 | };
|
|---|
| [b1f254] | 410 |
|
|---|
| 411 | /** Prints correlation (double, (atom*,atom*) ) pairs to file.
|
|---|
| 412 | * \param *file file to write to
|
|---|
| 413 | * \param *map map to write
|
|---|
| 414 | */
|
|---|
| [a5551b] | 415 | void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
|
|---|
| [b1f254] | 416 | {
|
|---|
| [3930eb] | 417 | Info FunctionInfo(__func__);
|
|---|
| [790807] | 418 | *file << "BinStart\tAtom1\tAtom2" << endl;
|
|---|
| [776b64] | 419 | for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
|---|
| [775d133] | 420 | *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
|
|---|
| [b1f254] | 421 | }
|
|---|
| 422 | };
|
|---|
| 423 |
|
|---|
| 424 | /** Prints correlation (double, int) pairs to file.
|
|---|
| 425 | * \param *file file to write to
|
|---|
| 426 | * \param *map map to write
|
|---|
| 427 | */
|
|---|
| [a5551b] | 428 | void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
|
|---|
| [b1f254] | 429 | {
|
|---|
| [3930eb] | 430 | Info FunctionInfo(__func__);
|
|---|
| [790807] | 431 | *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
|
|---|
| [776b64] | 432 | for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
|---|
| [b1f254] | 433 | *file << runner->first;
|
|---|
| 434 | for (int i=0;i<NDIM;i++)
|
|---|
| [8cbb97] | 435 | *file << "\t" << setprecision(8) << (runner->second.first->node->at(i) - runner->second.second->at(i));
|
|---|
| [b1f254] | 436 | *file << endl;
|
|---|
| 437 | }
|
|---|
| 438 | };
|
|---|
| 439 |
|
|---|
| 440 | /** Prints correlation (double, int) pairs to file.
|
|---|
| 441 | * \param *file file to write to
|
|---|
| 442 | * \param *map map to write
|
|---|
| 443 | */
|
|---|
| [a5551b] | 444 | void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
|
|---|
| [b1f254] | 445 | {
|
|---|
| [3930eb] | 446 | Info FunctionInfo(__func__);
|
|---|
| [790807] | 447 | *file << "BinStart\tTriangle" << endl;
|
|---|
| [8db598] | 448 | if (!map->empty())
|
|---|
| 449 | for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
|---|
| 450 | *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
|
|---|
| 451 | }
|
|---|
| [b1f254] | 452 | };
|
|---|
| 453 |
|
|---|