| 1 |
/* |
| 2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
* |
| 4 |
* The University of Notre Dame grants you ("Licensee") a |
| 5 |
* non-exclusive, royalty free, license to use, modify and |
| 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 |
| 19 |
* notice, this list of conditions and the following disclaimer. |
| 20 |
* |
| 21 |
* 3. Redistributions in binary form must reproduce the above copyright |
| 22 |
* notice, this list of conditions and the following disclaimer in the |
| 23 |
* documentation and/or other materials provided with the |
| 24 |
* distribution. |
| 25 |
* |
| 26 |
* This software is provided "AS IS," without a warranty of any |
| 27 |
* kind. All express or implied conditions, representations and |
| 28 |
* warranties, including any implied warranty of merchantability, |
| 29 |
* fitness for a particular purpose or non-infringement, are hereby |
| 30 |
* excluded. The University of Notre Dame and its licensors shall not |
| 31 |
* be liable for any damages suffered by licensee as a result of |
| 32 |
* using, modifying or distributing the software or its |
| 33 |
* derivatives. In no event will the University of Notre Dame or its |
| 34 |
* licensors be liable for any lost revenue, profit or data, or for |
| 35 |
* direct, indirect, special, consequential, incidental or punitive |
| 36 |
* damages, however caused and regardless of the theory of liability, |
| 37 |
* arising out of the use of or inability to use software, even if the |
| 38 |
* University of Notre Dame has been advised of the possibility of |
| 39 |
* such damages. |
| 40 |
*/ |
| 41 |
|
| 42 |
#include <algorithm> |
| 43 |
|
| 44 |
#include "RadialDistrFunc.hpp" |
| 45 |
#include "io/DumpReader.hpp" |
| 46 |
#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), |
| 52 |
seleMan1_(info), seleMan2_(info), common_(info), sele1_minus_common_(info), sele2_minus_common_(info){ |
| 53 |
|
| 54 |
evaluator1_.loadScriptString(sele1); |
| 55 |
evaluator2_.loadScriptString(sele2); |
| 56 |
|
| 57 |
if (!evaluator1_.isDynamic()) { |
| 58 |
seleMan1_.setSelectionSet(evaluator1_.evaluate()); |
| 59 |
} |
| 60 |
if (!evaluator2_.isDynamic()) { |
| 61 |
seleMan2_.setSelectionSet(evaluator2_.evaluate()); |
| 62 |
} |
| 63 |
|
| 64 |
if (!evaluator1_.isDynamic() && !evaluator2_.isDynamic()) { |
| 65 |
//if all selections are static, we can precompute the number of real pairs |
| 66 |
common_ = seleMan1_ & seleMan2_; |
| 67 |
sele1_minus_common_ = seleMan1_ - common_; |
| 68 |
sele2_minus_common_ = seleMan2_ - common_; |
| 69 |
|
| 70 |
int nSelected1 = seleMan1_.getSelectionCount(); |
| 71 |
int nSelected2 = seleMan2_.getSelectionCount(); |
| 72 |
int nIntersect = common_.getSelectionCount(); |
| 73 |
|
| 74 |
nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2; |
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
void RadialDistrFunc::process() { |
| 80 |
Molecule* mol; |
| 81 |
RigidBody* rb; |
| 82 |
SimInfo::MoleculeIterator mi; |
| 83 |
Molecule::RigidBodyIterator rbIter; |
| 84 |
|
| 85 |
preProcess(); |
| 86 |
|
| 87 |
DumpReader reader(info_, dumpFilename_); |
| 88 |
int nFrames = reader.getNFrames(); |
| 89 |
nProcessed_ = nFrames / step_; |
| 90 |
|
| 91 |
for (int i = 0; i < nFrames; i += step_) { |
| 92 |
reader.readFrame(i); |
| 93 |
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 94 |
|
| 95 |
if (evaluator1_.isDynamic()) { |
| 96 |
seleMan1_.setSelectionSet(evaluator1_.evaluate()); |
| 97 |
} |
| 98 |
if (evaluator2_.isDynamic()) { |
| 99 |
seleMan2_.setSelectionSet(evaluator2_.evaluate()); |
| 100 |
} |
| 101 |
|
| 102 |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
| 103 |
|
| 104 |
//change the positions of atoms which belong to the rigidbodies |
| 105 |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
| 106 |
rb->updateAtoms(); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
initalizeHistogram(); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
//selections may overlap. |
| 115 |
// |
| 116 |
// |s1 -c | c | |
| 117 |
// | c |s2 - c| |
| 118 |
// |
| 119 |
// s1 : number of selected stuntdoubles in selection1 |
| 120 |
// s2 : number of selected stuntdoubles in selection2 |
| 121 |
// c : number of intersect stuntdouble between selection1 and selection2 |
| 122 |
//when loop over the pairs, we can divide the looping into 3 stages |
| 123 |
//stage 1 : [s1-c] [s2] |
| 124 |
//stage 2 : [c] [s2 - c] |
| 125 |
//stage 3 : [c] [c] |
| 126 |
//stage 1 and stage 2 are completly non-overlapping |
| 127 |
//stage 3 are completely overlapping |
| 128 |
|
| 129 |
if (evaluator1_.isDynamic() || evaluator2_.isDynamic()) { |
| 130 |
|
| 131 |
common_ = seleMan1_ & seleMan2_; |
| 132 |
sele1_minus_common_ = seleMan1_ - common_; |
| 133 |
sele2_minus_common_ = seleMan2_ - common_; |
| 134 |
int nSelected1 = seleMan1_.getSelectionCount(); |
| 135 |
int nSelected2 = seleMan2_.getSelectionCount(); |
| 136 |
int nIntersect = common_.getSelectionCount(); |
| 137 |
|
| 138 |
nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2; |
| 139 |
} |
| 140 |
|
| 141 |
processNonOverlapping(sele1_minus_common_, seleMan2_); |
| 142 |
processNonOverlapping(common_, sele2_minus_common_); |
| 143 |
processOverlapping(common_); |
| 144 |
|
| 145 |
|
| 146 |
processHistogram(); |
| 147 |
|
| 148 |
} |
| 149 |
|
| 150 |
postProcess(); |
| 151 |
|
| 152 |
writeRdf(); |
| 153 |
} |
| 154 |
|
| 155 |
void RadialDistrFunc::processNonOverlapping( SelectionManager& sman1, SelectionManager& sman2) { |
| 156 |
StuntDouble* sd1; |
| 157 |
StuntDouble* sd2; |
| 158 |
int i; |
| 159 |
int j; |
| 160 |
|
| 161 |
for (sd1 = sman1.beginSelected(i); sd1 != NULL; sd1 = sman1.nextSelected(i)) { |
| 162 |
|
| 163 |
for (sd2 = sman2.beginSelected(j); sd2 != NULL; sd2 = sman2.nextSelected(j)) { |
| 164 |
collectHistogram(sd1, sd2); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
void RadialDistrFunc::processOverlapping( SelectionManager& sman) { |
| 171 |
StuntDouble* sd1; |
| 172 |
StuntDouble* sd2; |
| 173 |
int i; |
| 174 |
int j; |
| 175 |
|
| 176 |
//basically, it is the same as below loop |
| 177 |
//for (int i = 0; i < n; ++i ) |
| 178 |
// for (int j = i + 1; j < n; ++j) {} |
| 179 |
|
| 180 |
for (sd1 = sman.beginSelected(i); sd1 != NULL; sd1 = sman.nextSelected(i)) { |
| 181 |
for (j = i, sd2 = sman.nextSelected(j); sd2 != NULL; sd2 = sman.nextSelected(j)) { |
| 182 |
collectHistogram(sd1, sd2); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
} |
| 187 |
|
| 188 |
} |