| 36 | 
  | 
 * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).              | 
| 37 | 
  | 
 * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).           | 
| 38 | 
  | 
 * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).           | 
| 39 | 
< | 
 * [4]  Vardeman & Gezelter, in progress (2009).                         | 
| 39 | 
> | 
 * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 | 
> | 
 * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 | 
  | 
 */ | 
| 42 | 
  | 
 | 
| 43 | 
  | 
#include <algorithm> | 
| 45 | 
  | 
#include "RadialDistrFunc.hpp" | 
| 46 | 
  | 
#include "io/DumpReader.hpp" | 
| 47 | 
  | 
#include "primitives/Molecule.hpp" | 
| 48 | 
+ | 
 | 
| 49 | 
  | 
namespace OpenMD { | 
| 50 | 
  | 
 | 
| 51 | 
< | 
  RadialDistrFunc::RadialDistrFunc(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2) | 
| 52 | 
< | 
    : StaticAnalyser(info, filename),  | 
| 53 | 
< | 
      selectionScript1_(sele1), selectionScript2_(sele2), evaluator1_(info), evaluator2_(info),  | 
| 54 | 
< | 
      seleMan1_(info), seleMan2_(info), common_(info), sele1_minus_common_(info), sele2_minus_common_(info){ | 
| 51 | 
> | 
  RadialDistrFunc::RadialDistrFunc(SimInfo* info,  | 
| 52 | 
> | 
                                   const std::string& filename,  | 
| 53 | 
> | 
                                   const std::string& sele1,  | 
| 54 | 
> | 
                                   const std::string& sele2) | 
| 55 | 
> | 
    : StaticAnalyser(info, filename), selectionScript1_(sele1),  | 
| 56 | 
> | 
      selectionScript2_(sele2), evaluator1_(info), evaluator2_(info),  | 
| 57 | 
> | 
      seleMan1_(info), seleMan2_(info), common_(info),  | 
| 58 | 
> | 
      sele1_minus_common_(info), sele2_minus_common_(info) { | 
| 59 | 
  | 
           | 
| 60 | 
  | 
      evaluator1_.loadScriptString(sele1); | 
| 61 | 
  | 
      evaluator2_.loadScriptString(sele2); | 
| 70 | 
  | 
      } | 
| 71 | 
  | 
 | 
| 72 | 
  | 
      if (!evaluator1_.isDynamic() && !evaluator2_.isDynamic()) { | 
| 73 | 
< | 
        //if all selections are static,  we can precompute the number of real pairs     | 
| 73 | 
> | 
        // If all selections are static, we can precompute the number | 
| 74 | 
> | 
        // of real pairs. | 
| 75 | 
  | 
        common_ = seleMan1_ & seleMan2_; | 
| 76 | 
  | 
        sele1_minus_common_ = seleMan1_ - common_; | 
| 77 | 
  | 
        sele2_minus_common_ = seleMan2_ - common_;       | 
| 80 | 
  | 
        int nSelected2 = seleMan2_.getSelectionCount(); | 
| 81 | 
  | 
        int nIntersect = common_.getSelectionCount(); | 
| 82 | 
  | 
         | 
| 83 | 
< | 
        nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2;             | 
| 83 | 
> | 
        nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2;   | 
| 84 | 
  | 
      } | 
| 85 | 
  | 
     | 
| 86 | 
  | 
    } | 
| 110 | 
  | 
        validateSelection2(seleMan2_); | 
| 111 | 
  | 
      } | 
| 112 | 
  | 
 | 
| 113 | 
< | 
      for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 113 | 
> | 
      for (mol = info_->beginMolecule(mi); mol != NULL;  | 
| 114 | 
> | 
           mol = info_->nextMolecule(mi)) { | 
| 115 | 
  | 
 | 
| 116 | 
< | 
        //change the positions of atoms which belong to the rigidbodies | 
| 117 | 
< | 
        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 116 | 
> | 
        // Change the positions of atoms which belong to the RigidBodies | 
| 117 | 
> | 
        for (rb = mol->beginRigidBody(rbIter); rb != NULL;  | 
| 118 | 
> | 
             rb = mol->nextRigidBody(rbIter)) { | 
| 119 | 
  | 
          rb->updateAtoms(); | 
| 120 | 
  | 
        } | 
| 121 | 
  | 
      } | 
| 122 | 
  | 
         | 
| 123 | 
  | 
      initalizeHistogram(); | 
| 115 | 
– | 
 | 
| 116 | 
– | 
 | 
| 124 | 
  | 
         | 
| 125 | 
< | 
      //selections may overlap. | 
| 125 | 
> | 
      // Selections may overlap, and we need a bit of logic to deal | 
| 126 | 
> | 
      // with this. | 
| 127 | 
  | 
      // | 
| 128 | 
< | 
      // |s1 -c | c | | 
| 129 | 
< | 
      //            | c |s2 - c| | 
| 128 | 
> | 
      // |     s1    | | 
| 129 | 
> | 
      // | s1 -c | c | | 
| 130 | 
> | 
      //         | c | s2 - c | | 
| 131 | 
> | 
      //         |    s2      | | 
| 132 | 
  | 
      // | 
| 133 | 
< | 
      // s1 : number of selected stuntdoubles in selection1 | 
| 134 | 
< | 
      // s2 : number of selected stuntdoubles in selection2 | 
| 135 | 
< | 
      // c   : number of intersect stuntdouble between selection1 and selection2 | 
| 136 | 
< | 
      //when loop over the pairs, we can divide the looping into 3 stages | 
| 137 | 
< | 
      //stage 1 :     [s1-c]      [s2] | 
| 138 | 
< | 
      //stage 2 :     [c]            [s2 - c] | 
| 139 | 
< | 
      //stage 3 :     [c]            [c] | 
| 140 | 
< | 
      //stage 1 and stage 2 are completly non-overlapping | 
| 141 | 
< | 
      //stage 3 are completely overlapping | 
| 133 | 
> | 
      // s1 : Set of StuntDoubles in selection1 | 
| 134 | 
> | 
      // s2 : Set of StuntDoubles in selection2 | 
| 135 | 
> | 
      // c  : Intersection of selection1 and selection2 | 
| 136 | 
> | 
      //  | 
| 137 | 
> | 
      // When we loop over the pairs, we can divide the looping into 3 | 
| 138 | 
> | 
      // stages: | 
| 139 | 
> | 
      // | 
| 140 | 
> | 
      // Stage 1 :     [s1-c]      [s2] | 
| 141 | 
> | 
      // Stage 2 :     [c]         [s2 - c] | 
| 142 | 
> | 
      // Stage 3 :     [c]         [c] | 
| 143 | 
> | 
      // Stages 1 and 2 are completely non-overlapping. | 
| 144 | 
> | 
      // Stage 3 is completely overlapping. | 
| 145 | 
  | 
 | 
| 146 | 
  | 
      if (evaluator1_.isDynamic() || evaluator2_.isDynamic()) { | 
| 147 | 
  | 
        common_ = seleMan1_ & seleMan2_; | 
| 153 | 
  | 
             | 
| 154 | 
  | 
        nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2; | 
| 155 | 
  | 
      } | 
| 156 | 
+ | 
       | 
| 157 | 
  | 
      processNonOverlapping(sele1_minus_common_, seleMan2_); | 
| 158 | 
< | 
      processNonOverlapping(common_, sele2_minus_common_);         | 
| 158 | 
> | 
      processNonOverlapping(common_,             sele2_minus_common_); | 
| 159 | 
  | 
      processOverlapping(common_); | 
| 160 | 
  | 
       | 
| 161 | 
  | 
      processHistogram(); | 
| 167 | 
  | 
    writeRdf(); | 
| 168 | 
  | 
  } | 
| 169 | 
  | 
 | 
| 170 | 
< | 
  void RadialDistrFunc::processNonOverlapping( SelectionManager& sman1, SelectionManager& sman2) { | 
| 170 | 
> | 
  void RadialDistrFunc::processNonOverlapping( SelectionManager& sman1,  | 
| 171 | 
> | 
                                               SelectionManager& sman2) { | 
| 172 | 
  | 
    StuntDouble* sd1; | 
| 173 | 
  | 
    StuntDouble* sd2; | 
| 174 | 
  | 
    int i;     | 
| 175 | 
  | 
    int j; | 
| 176 | 
  | 
     | 
| 177 | 
< | 
    for (sd1 = sman1.beginSelected(i); sd1 != NULL; sd1 = sman1.nextSelected(i)) { | 
| 177 | 
> | 
    // This is the same as a non-overlapping pairwise loop structure: | 
| 178 | 
> | 
    // for (int i = 0;  i < ni ; ++i ) { | 
| 179 | 
> | 
    //   for (int j = 0; j < nj; ++j) {}  | 
| 180 | 
> | 
    // } | 
| 181 | 
  | 
 | 
| 182 | 
< | 
      for (sd2 = sman2.beginSelected(j); sd2 != NULL; sd2 = sman2.nextSelected(j)) { | 
| 182 | 
> | 
    for (sd1 = sman1.beginSelected(i); sd1 != NULL;  | 
| 183 | 
> | 
         sd1 = sman1.nextSelected(i)) { | 
| 184 | 
> | 
      for (sd2 = sman2.beginSelected(j); sd2 != NULL;  | 
| 185 | 
> | 
           sd2 = sman2.nextSelected(j)) { | 
| 186 | 
  | 
        collectHistogram(sd1, sd2); | 
| 187 | 
< | 
      }             | 
| 187 | 
> | 
      } | 
| 188 | 
  | 
    } | 
| 168 | 
– | 
 | 
| 189 | 
  | 
  } | 
| 190 | 
  | 
 | 
| 191 | 
  | 
  void RadialDistrFunc::processOverlapping( SelectionManager& sman) { | 
| 194 | 
  | 
    int i;     | 
| 195 | 
  | 
    int j; | 
| 196 | 
  | 
 | 
| 197 | 
< | 
    //basically, it is the same as below loop | 
| 198 | 
< | 
    //for (int i = 0;  i < n; ++i ) | 
| 199 | 
< | 
    //  for (int j = i + 1; j < n; ++j) {} | 
| 197 | 
> | 
    // This is the same as a pairwise loop structure: | 
| 198 | 
> | 
    // for (int i = 0;  i < n-1 ; ++i ) { | 
| 199 | 
> | 
    //   for (int j = i + 1; j < n; ++j) {}  | 
| 200 | 
> | 
    // } | 
| 201 | 
  | 
     | 
| 202 | 
< | 
    for (sd1 = sman.beginSelected(i); sd1 != NULL; sd1 = sman.nextSelected(i)) {                     | 
| 203 | 
< | 
      for (j  = i, sd2 = sman.nextSelected(j); sd2 != NULL; sd2 = sman.nextSelected(j)) { | 
| 202 | 
> | 
    for (sd1 = sman.beginSelected(i); sd1 != NULL;  | 
| 203 | 
> | 
         sd1 = sman.nextSelected(i)) {                     | 
| 204 | 
> | 
      for (j  = i, sd2 = sman.nextSelected(j); sd2 != NULL;  | 
| 205 | 
> | 
           sd2 = sman.nextSelected(j)) { | 
| 206 | 
  | 
        collectHistogram(sd1, sd2); | 
| 207 | 
  | 
      }             | 
| 208 | 
  | 
    } | 
| 186 | 
– | 
 | 
| 209 | 
  | 
  } | 
| 188 | 
– | 
 | 
| 210 | 
  | 
} |