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