| 6 | 
  | 
 * redistribute this software in source and binary code form, provided | 
| 7 | 
  | 
 * that the following conditions are met: | 
| 8 | 
  | 
 * | 
| 9 | 
< | 
 * 1. Acknowledgement of the program authors must be made in any | 
| 10 | 
< | 
 *    publication of scientific results based in part on use of the | 
| 11 | 
< | 
 *    program.  An acceptable form of acknowledgement is citation of | 
| 12 | 
< | 
 *    the article in which the program was described (Matthew | 
| 13 | 
< | 
 *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher | 
| 14 | 
< | 
 *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented | 
| 15 | 
< | 
 *    Parallel Simulation Engine for Molecular Dynamics," | 
| 16 | 
< | 
 *    J. Comput. Chem. 26, pp. 252-271 (2005)) | 
| 17 | 
< | 
 * | 
| 18 | 
< | 
 * 2. Redistributions of source code must retain the above copyright | 
| 9 | 
> | 
 * 1. Redistributions of source code must retain the above copyright | 
| 10 | 
  | 
 *    notice, this list of conditions and the following disclaimer. | 
| 11 | 
  | 
 * | 
| 12 | 
< | 
 * 3. Redistributions in binary form must reproduce the above copyright | 
| 12 | 
> | 
 * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 | 
  | 
 *    notice, this list of conditions and the following disclaimer in the | 
| 14 | 
  | 
 *    documentation and/or other materials provided with the | 
| 15 | 
  | 
 *    distribution. | 
| 28 | 
  | 
 * arising out of the use of or inability to use software, even if the | 
| 29 | 
  | 
 * University of Notre Dame has been advised of the possibility of | 
| 30 | 
  | 
 * such damages. | 
| 31 | 
+ | 
 * | 
| 32 | 
+ | 
 * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your | 
| 33 | 
+ | 
 * research, please cite the appropriate papers when you publish your | 
| 34 | 
+ | 
 * work.  Good starting points are: | 
| 35 | 
+ | 
 *                                                                       | 
| 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]  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" | 
| 47 | 
– | 
namespace oopse { | 
| 48 | 
  | 
 | 
| 49 | 
< | 
RadialDistrFunc::        RadialDistrFunc(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2) | 
| 50 | 
< | 
        : info_(info), currentSnapshot_(NULL), dumpFilename_(filename), step_(1),  | 
| 51 | 
< | 
          selectionScript1_(sele1), selectionScript2_(sele2), evaluator1_(info), evaluator2_(info), seleMan1_(info), seleMan2_(info){ | 
| 49 | 
> | 
namespace OpenMD { | 
| 50 | 
> | 
 | 
| 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); | 
| 60 | 
> | 
      evaluator1_.loadScriptString(sele1); | 
| 61 | 
> | 
      evaluator2_.loadScriptString(sele2); | 
| 62 | 
  | 
 | 
| 63 | 
< | 
    if (!evaluator1_.isDynamic()) { | 
| 64 | 
< | 
            seleMan1_.setSelectionSet(evaluator1_.evaluate()); | 
| 65 | 
< | 
    } | 
| 66 | 
< | 
    if (!evaluator2_.isDynamic()) { | 
| 67 | 
< | 
            seleMan2_.setSelectionSet(evaluator2_.evaluate()); | 
| 68 | 
< | 
    } | 
| 63 | 
> | 
      if (!evaluator1_.isDynamic()) { | 
| 64 | 
> | 
        seleMan1_.setSelectionSet(evaluator1_.evaluate()); | 
| 65 | 
> | 
        validateSelection1(seleMan1_); | 
| 66 | 
> | 
      } | 
| 67 | 
> | 
      if (!evaluator2_.isDynamic()) { | 
| 68 | 
> | 
        seleMan2_.setSelectionSet(evaluator2_.evaluate()); | 
| 69 | 
> | 
        validateSelection2(seleMan2_); | 
| 70 | 
> | 
      } | 
| 71 | 
  | 
 | 
| 72 | 
< | 
    if (!evaluator1_.isDynamic() && !evaluator2_.isDynamic()) { | 
| 73 | 
< | 
        //if all selections are static,  we can precompute the number of real pairs     | 
| 72 | 
> | 
      if (!evaluator1_.isDynamic() && !evaluator2_.isDynamic()) { | 
| 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_;       | 
| 78 | 
  | 
 | 
| 79 | 
< | 
        int nSelected1 = seleMan1_->getSelectionCount(); | 
| 80 | 
< | 
        int nSelected2 = seleMan2_->getSelectionCount(); | 
| 81 | 
< | 
 | 
| 82 | 
< | 
        BitSet bs = seleMan1_.getSelectionSet(); | 
| 83 | 
< | 
        bs &= seleMan2_.getSelectionSet(); | 
| 84 | 
< | 
        int nIntersect = bs.countBits(); | 
| 72 | 
< | 
 | 
| 73 | 
< | 
        nRealPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2; | 
| 74 | 
< | 
    } | 
| 79 | 
> | 
        int nSelected1 = seleMan1_.getSelectionCount(); | 
| 80 | 
> | 
        int nSelected2 = seleMan2_.getSelectionCount(); | 
| 81 | 
> | 
        int nIntersect = common_.getSelectionCount(); | 
| 82 | 
> | 
         | 
| 83 | 
> | 
        nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2;   | 
| 84 | 
> | 
      } | 
| 85 | 
  | 
     | 
| 86 | 
< | 
} | 
| 86 | 
> | 
    } | 
| 87 | 
  | 
 | 
| 88 | 
< | 
void RadialDistrFunc::process() { | 
| 88 | 
> | 
  void RadialDistrFunc::process() { | 
| 89 | 
  | 
    Molecule* mol; | 
| 90 | 
  | 
    RigidBody* rb; | 
| 91 | 
  | 
    SimInfo::MoleculeIterator mi; | 
| 95 | 
  | 
     | 
| 96 | 
  | 
    DumpReader reader(info_, dumpFilename_);     | 
| 97 | 
  | 
    int nFrames = reader.getNFrames(); | 
| 98 | 
< | 
    nProcessed_ = nFrames / step_ + 1; | 
| 98 | 
> | 
    nProcessed_ = nFrames / step_; | 
| 99 | 
> | 
 | 
| 100 | 
  | 
    for (int i = 0; i < nFrames; i += step_) { | 
| 101 | 
< | 
        reader.readFrame(i); | 
| 102 | 
< | 
        currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 101 | 
> | 
      reader.readFrame(i); | 
| 102 | 
> | 
      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 103 | 
  | 
 | 
| 104 | 
< | 
        if (evaluator1_.isDynamic()) { | 
| 105 | 
< | 
            seleMan1_.setSelectionSet(evaluator1_.evaluate()); | 
| 106 | 
< | 
        } | 
| 107 | 
< | 
        if (evaluator2_.isDynamic()) { | 
| 108 | 
< | 
            seleMan2_.setSelectionSet(evaluator2_.evaluate()); | 
| 109 | 
< | 
        } | 
| 104 | 
> | 
      if (evaluator1_.isDynamic()) { | 
| 105 | 
> | 
        seleMan1_.setSelectionSet(evaluator1_.evaluate()); | 
| 106 | 
> | 
        validateSelection1(seleMan1_); | 
| 107 | 
> | 
      } | 
| 108 | 
> | 
      if (evaluator2_.isDynamic()) { | 
| 109 | 
> | 
        seleMan2_.setSelectionSet(evaluator2_.evaluate()); | 
| 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)) { | 
| 118 | 
< | 
                rb->updateAtoms(); | 
| 119 | 
< | 
            } | 
| 120 | 
< | 
        } | 
| 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(); | 
| 123 | 
> | 
      initalizeHistogram(); | 
| 124 | 
> | 
         | 
| 125 | 
> | 
      // Selections may overlap, and we need a bit of logic to deal | 
| 126 | 
> | 
      // with this. | 
| 127 | 
> | 
      // | 
| 128 | 
> | 
      // |     s1    | | 
| 129 | 
> | 
      // | s1 -c | c | | 
| 130 | 
> | 
      //         | c | s2 - c | | 
| 131 | 
> | 
      //         |    s2      | | 
| 132 | 
> | 
      // | 
| 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 | 
< | 
        StuntDouble* sd1; | 
| 147 | 
< | 
        int j; | 
| 148 | 
< | 
        for (sd1 = seleMan1_.beginSelected(j); sd1 != NULL; sd1 = seleMan1_.nextSelected(j)) { | 
| 149 | 
< | 
 | 
| 150 | 
< | 
            StuntDouble* sd2; | 
| 151 | 
< | 
            int k; | 
| 152 | 
< | 
            for (sd2 = seleMan2_.beginSelected(k); sd2 != NULL; sd2 = seleMan2_.nextSelected(k)) { | 
| 153 | 
< | 
                if (sd1 != sd2) { | 
| 154 | 
< | 
                    collectHistogram(sd1, sd2); | 
| 155 | 
< | 
                } | 
| 156 | 
< | 
            }             | 
| 157 | 
< | 
        } | 
| 158 | 
< | 
 | 
| 159 | 
< | 
        processHistogram(); | 
| 146 | 
> | 
      if (evaluator1_.isDynamic() || evaluator2_.isDynamic()) { | 
| 147 | 
> | 
        common_ = seleMan1_ & seleMan2_; | 
| 148 | 
> | 
        sele1_minus_common_ = seleMan1_ - common_; | 
| 149 | 
> | 
        sele2_minus_common_ = seleMan2_ - common_;             | 
| 150 | 
> | 
        int nSelected1 = seleMan1_.getSelectionCount(); | 
| 151 | 
> | 
        int nSelected2 = seleMan2_.getSelectionCount(); | 
| 152 | 
> | 
        int nIntersect = common_.getSelectionCount(); | 
| 153 | 
> | 
             | 
| 154 | 
> | 
        nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2; | 
| 155 | 
> | 
      } | 
| 156 | 
> | 
       | 
| 157 | 
> | 
      processNonOverlapping(sele1_minus_common_, seleMan2_); | 
| 158 | 
> | 
      processNonOverlapping(common_,             sele2_minus_common_); | 
| 159 | 
> | 
      processOverlapping(common_); | 
| 160 | 
> | 
       | 
| 161 | 
> | 
      processHistogram(); | 
| 162 | 
  | 
         | 
| 163 | 
  | 
    } | 
| 164 | 
  | 
 | 
| 165 | 
  | 
    postProcess(); | 
| 166 | 
  | 
 | 
| 167 | 
  | 
    writeRdf(); | 
| 168 | 
< | 
} | 
| 168 | 
> | 
  } | 
| 169 | 
  | 
 | 
| 170 | 
< | 
int RadialDistrFunc::getNRealPairs() { | 
| 171 | 
< | 
    if (evaluator1_.isDynamic() || evaluator2_.isDynamic()) { | 
| 172 | 
< | 
        //if one of the selection is static,  need to recompute it     | 
| 170 | 
> | 
  void RadialDistrFunc::processNonOverlapping( SelectionManager& sman1,  | 
| 171 | 
> | 
                                               SelectionManager& sman2) { | 
| 172 | 
> | 
    StuntDouble* sd1; | 
| 173 | 
> | 
    StuntDouble* sd2; | 
| 174 | 
> | 
    int i;     | 
| 175 | 
> | 
    int j; | 
| 176 | 
> | 
     | 
| 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 | 
< | 
        int nSelected1 = seleMan1_->getSelectionCount(); | 
| 183 | 
< | 
        int nSelected2 = seleMan2_->getSelectionCount(); | 
| 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 | 
> | 
      } | 
| 188 | 
> | 
    } | 
| 189 | 
> | 
  } | 
| 190 | 
  | 
 | 
| 191 | 
< | 
        BitSet bs = seleMan1_.getSelectionSet(); | 
| 192 | 
< | 
        bs &= seleMan2_.getSelectionSet(); | 
| 193 | 
< | 
        int nIntersect = bs.countBits(); | 
| 191 | 
> | 
  void RadialDistrFunc::processOverlapping( SelectionManager& sman) { | 
| 192 | 
> | 
    StuntDouble* sd1; | 
| 193 | 
> | 
    StuntDouble* sd2; | 
| 194 | 
> | 
    int i;     | 
| 195 | 
> | 
    int j; | 
| 196 | 
  | 
 | 
| 197 | 
< | 
        nRealPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2; | 
| 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;  | 
| 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 | 
  | 
    } | 
| 209 | 
< | 
 | 
| 146 | 
< | 
    return nRealPairs_ | 
| 209 | 
> | 
  } | 
| 210 | 
  | 
} | 
| 148 | 
– | 
 | 
| 149 | 
– | 
} |