Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/analysis_correlation.cpp

    r58bbd3 r112b09  
    55 *      Author: heber
    66 */
     7
     8#include "Helpers/MemDebug.hpp"
    79
    810#include <iostream>
     
    2325/** Calculates the pair correlation between given elements.
    2426 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
    25  * \param *molecules list of molecules structure
    26  * \param &elements vector of elements to correlate
     27 * \param *out output stream for debugging
     28 * \param *molecules list of molecules structure
     29 * \param *type1 first element or NULL (if any element)
     30 * \param *type2 second element or NULL (if any element)
    2731 * \return Map of doubles with values the pair of the two atoms.
    2832 */
    29 PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const std::vector<element *> &elements)
     33PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2 )
    3034{
    3135  Info FunctionInfo(__func__);
    3236  PairCorrelationMap *outmap = NULL;
    3337  double distance = 0.;
    34   double *domain = World::getInstance().getDomain();
    3538
    3639  if (molecules->ListOfMolecules.empty()) {
     
    4043  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    4144    (*MolWalker)->doCountAtoms();
    42 
    43   // create all possible pairs of elements
    44   set <pair<element *, element *> > PairsOfElements;
    45   if (elements.size() >= 2) {
    46     for (vector<element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
    47       for (vector<element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
    48         if (type1 != type2) {
    49           PairsOfElements.insert( pair<element *, element*>(*type1,*type2) );
    50           DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << (*type1)->symbol << " and " << (*type2)->symbol << "." << endl);
    51         }
    52   } else if (elements.size() == 1) { // one to all are valid
    53     element *elemental = *elements.begin();
    54     PairsOfElements.insert( pair<element *, element*>(elemental,(element *)NULL) );
    55     PairsOfElements.insert( pair<element *, element*>((element *)NULL,elemental) );
    56   } else { // all elements valid
    57     PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
    58   }
    59 
    6045  outmap = new PairCorrelationMap;
    6146  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++){
     
    6550      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    6651        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
    67         for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){
    68           if ((*MolOtherWalker)->ActiveFlag) {
    69             DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
    70             for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
    71               DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
    72               if ((*iter)->getId() < (*runner)->getId()){
    73                 for (set <pair<element *, element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
    74                   if ((PairRunner->first == (**iter).type) && (PairRunner->second == (**runner).type)) {
    75                     distance = (*iter)->node->PeriodicDistance(*(*runner)->node,  domain);
     52        if ((type1 == NULL) || ((*iter)->type == type1)) {
     53          for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){
     54            if ((*MolOtherWalker)->ActiveFlag) {
     55              DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
     56              for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
     57                DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
     58                if ((*iter)->getId() < (*runner)->getId()){
     59                  if ((type2 == NULL) || ((*runner)->type == type2)) {
     60                    distance = (*iter)->node->PeriodicDistance(*(*runner)->node,  World::getInstance().getDomain());
    7661                    //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
    7762                    outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
    7863                  }
     64                }
    7965              }
    8066            }
     
    8975/** Calculates the pair correlation between given elements.
    9076 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
    91  * \param *molecules list of molecules structure
    92  * \param &elements vector of elements to correlate
     77 * \param *out output stream for debugging
     78 * \param *molecules list of molecules structure
     79 * \param *type1 first element or NULL (if any element)
     80 * \param *type2 second element or NULL (if any element)
    9381 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
    9482 * \return Map of doubles with values the pair of the two atoms.
    9583 */
    96 PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const int ranges[NDIM] )
     84PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] )
    9785{
    9886  Info FunctionInfo(__func__);
     
    112100  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    113101    (*MolWalker)->doCountAtoms();
    114 
    115   // create all possible pairs of elements
    116   set <pair<element *, element *> > PairsOfElements;
    117   if (elements.size() >= 2) {
    118     for (vector<element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
    119       for (vector<element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
    120         if (type1 != type2) {
    121           PairsOfElements.insert( pair<element *, element*>(*type1,*type2) );
    122           DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << (*type1)->symbol << " and " << (*type2)->symbol << "." << endl);
    123         }
    124   } else if (elements.size() == 1) { // one to all are valid
    125     element *elemental = *elements.begin();
    126     PairsOfElements.insert( pair<element *, element*>(elemental,(element *)NULL) );
    127     PairsOfElements.insert( pair<element *, element*>((element *)NULL,elemental) );
    128   } else { // all elements valid
    129     PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
    130   }
    131 
    132102  outmap = new PairCorrelationMap;
    133   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++){
     103  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    134104    if ((*MolWalker)->ActiveFlag) {
    135105      double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
    136106      double * FullInverseMatrix = InverseMatrix(FullMatrix);
    137107      DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
    138       eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
    139108      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    140109        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
    141         periodicX = *(*iter)->node;
    142         periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    143         // go through every range in xyz and get distance
    144         for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
    145           for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
    146             for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
    147               checkX = Vector(n[0], n[1], n[2]) + periodicX;
    148               checkX.MatrixMultiplication(FullMatrix);
    149               for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){
    150                 if ((*MolOtherWalker)->ActiveFlag) {
    151                   DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
    152                   for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
    153                     DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
    154                     if ((*iter)->getId() < (*runner)->getId()){
    155                       for (set <pair<element *, element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
    156                         if ((PairRunner->first == (**iter).type) && (PairRunner->second == (**runner).type)) {
     110        if ((type1 == NULL) || ((*iter)->type == type1)) {
     111          periodicX = *(*iter)->node;
     112          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
     113          // go through every range in xyz and get distance
     114          for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
     115            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     116              for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
     117                checkX = Vector(n[0], n[1], n[2]) + periodicX;
     118                checkX.MatrixMultiplication(FullMatrix);
     119                for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
     120                  if ((*MolOtherWalker)->ActiveFlag) {
     121                    DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
     122                    for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
     123                      DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
     124                      if ((*iter)->nr < (*runner)->nr)
     125                        if ((type2 == NULL) || ((*runner)->type == type2)) {
    157126                          periodicOtherX = *(*runner)->node;
    158127                          periodicOtherX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
     
    168137                              }
    169138                        }
    170                     }
    171139                  }
    172                 }
    173140              }
    174141            }
     142        }
    175143      }
    176144      delete[](FullMatrix);
    177145      delete[](FullInverseMatrix);
    178146    }
    179   }
    180147
    181148  return outmap;
     
    183150
    184151/** Calculates the distance (pair) correlation between a given element and a point.
    185  * \param *molecules list of molecules structure
    186  * \param &elements vector of elements to correlate with point
     152 * \param *out output stream for debugging
     153 * \param *molecules list of molecules structure
     154 * \param *type element or NULL (if any element)
    187155 * \param *point vector to the correlation point
    188156 * \return Map of dobules with values as pairs of atom and the vector
    189157 */
    190 CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point )
     158CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point )
    191159{
    192160  Info FunctionInfo(__func__);
    193161  CorrelationToPointMap *outmap = NULL;
    194162  double distance = 0.;
    195   double *cell_size = World::getInstance().getDomain();
    196163
    197164  if (molecules->ListOfMolecules.empty()) {
     
    207174      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    208175        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
    209         for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
    210           if ((*type == NULL) || ((*iter)->type == *type)) {
    211             distance = (*iter)->node->PeriodicDistance(*point, cell_size);
    212             DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    213             outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
    214           }
     176        if ((type == NULL) || ((*iter)->type == type)) {
     177          distance = (*iter)->node->PeriodicDistance(*point, World::getInstance().getDomain());
     178          DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
     179          outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
     180        }
    215181      }
    216182    }
     
    220186
    221187/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
    222  * \param *molecules list of molecules structure
    223  * \param &elements vector of elements to correlate to point
     188 * \param *out output stream for debugging
     189 * \param *molecules list of molecules structure
     190 * \param *type element or NULL (if any element)
    224191 * \param *point vector to the correlation point
    225192 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
    226193 * \return Map of dobules with values as pairs of atom and the vector
    227194 */
    228 CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point, const int ranges[NDIM] )
     195CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] )
    229196{
    230197  Info FunctionInfo(__func__);
     
    249216      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    250217        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
    251         for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
    252           if ((*type == NULL) || ((*iter)->type == *type)) {
    253             periodicX = *(*iter)->node;
    254             periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    255             // go through every range in xyz and get distance
    256             for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
    257               for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
    258                 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
    259                   checkX = Vector(n[0], n[1], n[2]) + periodicX;
    260                   checkX.MatrixMultiplication(FullMatrix);
    261                   distance = checkX.distance(*point);
    262                   DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    263                   outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
    264                 }
    265           }
     218        if ((type == NULL) || ((*iter)->type == type)) {
     219          periodicX = *(*iter)->node;
     220          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
     221          // go through every range in xyz and get distance
     222          for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
     223            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     224              for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
     225                checkX = Vector(n[0], n[1], n[2]) + periodicX;
     226                checkX.MatrixMultiplication(FullMatrix);
     227                distance = checkX.distance(*point);
     228                DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
     229                outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
     230              }
     231        }
    266232      }
    267233      delete[](FullMatrix);
     
    273239
    274240/** Calculates the distance (pair) correlation between a given element and a surface.
    275  * \param *molecules list of molecules structure
    276  * \param &elements vector of elements to correlate to surface
     241 * \param *out output stream for debugging
     242 * \param *molecules list of molecules structure
     243 * \param *type element or NULL (if any element)
    277244 * \param *Surface pointer to Tesselation class surface
    278245 * \param *LC LinkedCell structure to quickly find neighbouring atoms
    279246 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
    280247 */
    281 CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
     248CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC )
    282249{
    283250  Info FunctionInfo(__func__);
     
    301268      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    302269        DoLog(1) && (Log() << Verbose(1) << "\tCurrent atom is " << *(*iter) << "." << endl);
    303         for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
    304           if ((*type == NULL) || ((*iter)->type == *type)) {
    305             TriangleIntersectionList Intersections((*iter)->node,Surface,LC);
    306             distance = Intersections.GetSmallestDistance();
    307             triangle = Intersections.GetClosestTriangle();
    308             outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
    309           }
     270        if ((type == NULL) || ((*iter)->type == type)) {
     271          TriangleIntersectionList Intersections((*iter)->node,Surface,LC);
     272          distance = Intersections.GetSmallestDistance();
     273          triangle = Intersections.GetClosestTriangle();
     274          outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
     275        }
    310276      }
    311277    } else {
     
    321287 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
    322288 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
    323  * \param *molecules list of molecules structure
    324  * \param &elements vector of elements to correlate to surface
     289 * \param *out output stream for debugging
     290 * \param *molecules list of molecules structure
     291 * \param *type element or NULL (if any element)
    325292 * \param *Surface pointer to Tesselation class surface
    326293 * \param *LC LinkedCell structure to quickly find neighbouring atoms
     
    328295 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
    329296 */
    330 CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
     297CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
    331298{
    332299  Info FunctionInfo(__func__);
     
    355322      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    356323        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
    357         for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
    358           if ((*type == NULL) || ((*iter)->type == *type)) {
    359             periodicX = *(*iter)->node;
    360             periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    361             // go through every range in xyz and get distance
    362             ShortestDistance = -1.;
    363             for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
    364               for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
    365                 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
    366                   checkX = Vector(n[0], n[1], n[2]) + periodicX;
    367                   checkX.MatrixMultiplication(FullMatrix);
    368                   TriangleIntersectionList Intersections(&checkX,Surface,LC);
    369                   distance = Intersections.GetSmallestDistance();
    370                   triangle = Intersections.GetClosestTriangle();
    371                   if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
    372                     ShortestDistance = distance;
    373                     ShortestTriangle = triangle;
    374                   }
     324        if ((type == NULL) || ((*iter)->type == type)) {
     325          periodicX = *(*iter)->node;
     326          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
     327          // go through every range in xyz and get distance
     328          ShortestDistance = -1.;
     329          for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
     330            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     331              for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
     332                checkX = Vector(n[0], n[1], n[2]) + periodicX;
     333                checkX.MatrixMultiplication(FullMatrix);
     334                TriangleIntersectionList Intersections(&checkX,Surface,LC);
     335                distance = Intersections.GetSmallestDistance();
     336                triangle = Intersections.GetClosestTriangle();
     337                if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
     338                  ShortestDistance = distance;
     339                  ShortestTriangle = triangle;
    375340                }
    376             // insert
    377             outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
    378             //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
    379           }
     341              }
     342          // insert
     343          outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
     344          //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
     345        }
    380346      }
    381347      delete[](FullMatrix);
Note: See TracChangeset for help on using the changeset viewer.