OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
RadialDistrFunc.cpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45#include "RadialDistrFunc.hpp"
46
47#include <algorithm>
48
49#include "io/DumpReader.hpp"
51
52namespace OpenMD {
53
54 RadialDistrFunc::RadialDistrFunc(SimInfo* info, const std::string& filename,
55 const std::string& sele1,
56 const std::string& sele2,
57 unsigned int nbins) :
58 StaticAnalyser(info, filename, nbins),
59 selectionScript1_(sele1), selectionScript2_(sele2), evaluator1_(info),
60 evaluator2_(info), seleMan1_(info), seleMan2_(info),
61 sele1_minus_common_(info), sele2_minus_common_(info), common_(info) {
62 evaluator1_.loadScriptString(sele1);
63 evaluator2_.loadScriptString(sele2);
64
65 if (!evaluator1_.isDynamic()) {
66 seleMan1_.setSelectionSet(evaluator1_.evaluate());
67 validateSelection1(seleMan1_);
68 }
69 if (!evaluator2_.isDynamic()) {
70 seleMan2_.setSelectionSet(evaluator2_.evaluate());
71 validateSelection2(seleMan2_);
72 }
73
74 if (!evaluator1_.isDynamic() && !evaluator2_.isDynamic()) {
75 // If all selections are static, we can precompute the number
76 // of real pairs.
77 common_ = seleMan1_ & seleMan2_;
78 sele1_minus_common_ = seleMan1_ - common_;
79 sele2_minus_common_ = seleMan2_ - common_;
80
81 nSelected1_ = seleMan1_.getSelectionCount();
82 nSelected2_ = seleMan2_.getSelectionCount();
83 int nIntersect = common_.getSelectionCount();
84
85 nPairs_ = nSelected1_ * nSelected2_ - (nIntersect + 1) * nIntersect / 2;
86 }
87 }
88
89 void RadialDistrFunc::process() {
90 preProcess();
91
92 DumpReader reader(info_, dumpFilename_);
93 int nFrames = reader.getNFrames();
94 nProcessed_ = nFrames / step_;
95
96 for (int i = 0; i < nFrames; i += step_) {
97 reader.readFrame(i);
98 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
99
100 if (evaluator1_.isDynamic()) {
101 seleMan1_.setSelectionSet(evaluator1_.evaluate());
102 validateSelection1(seleMan1_);
103 }
104 if (evaluator2_.isDynamic()) {
105 seleMan2_.setSelectionSet(evaluator2_.evaluate());
106 validateSelection2(seleMan2_);
107 }
108
109 initializeHistogram();
110
111 // Selections may overlap, and we need a bit of logic to deal
112 // with this.
113 //
114 // | s1 |
115 // | s1 -c | c |
116 // | c | s2 - c |
117 // | s2 |
118 //
119 // s1 : Set of StuntDoubles in selection1
120 // s2 : Set of StuntDoubles in selection2
121 // c : Intersection of selection1 and selection2
122 //
123 // When we loop over the pairs, we can divide the looping into 3
124 // stages:
125 //
126 // Stage 1 : [s1-c] [s2]
127 // Stage 2 : [c] [s2 - c]
128 // Stage 3 : [c] [c]
129 // Stages 1 and 2 are completely non-overlapping.
130 // Stage 3 is completely overlapping.
131
132 if (evaluator1_.isDynamic() || evaluator2_.isDynamic()) {
133 common_ = seleMan1_ & seleMan2_;
134 sele1_minus_common_ = seleMan1_ - common_;
135 sele2_minus_common_ = seleMan2_ - common_;
136 nSelected1_ = seleMan1_.getSelectionCount();
137 nSelected2_ = seleMan2_.getSelectionCount();
138 int nIntersect = common_.getSelectionCount();
139
140 nPairs_ = nSelected1_ * nSelected2_ - (nIntersect + 1) * nIntersect / 2;
141 }
142
143 processNonOverlapping(sele1_minus_common_, seleMan2_);
144 processNonOverlapping(common_, sele2_minus_common_);
145 processOverlapping(common_);
146
147 processHistogram();
148 }
149
150 postProcess();
151
152 writeRdf();
153 }
154
155 void RadialDistrFunc::processNonOverlapping(SelectionManager& sman1,
156 SelectionManager& sman2) {
157 StuntDouble* sd1;
158 StuntDouble* sd2;
159 int i;
160 int j;
161
162 // This is the same as a non-overlapping pairwise loop structure:
163 // for (int i = 0; i < ni ; ++i ) {
164 // for (int j = 0; j < nj; ++j) {}
165 // }
166
167 for (sd1 = sman1.beginSelected(i); sd1 != NULL;
168 sd1 = sman1.nextSelected(i)) {
169 for (sd2 = sman2.beginSelected(j); sd2 != NULL;
170 sd2 = sman2.nextSelected(j)) {
171 collectHistogram(sd1, sd2);
172 }
173 }
174 }
175
176 void RadialDistrFunc::processOverlapping(SelectionManager& sman) {
177 StuntDouble* sd1;
178 StuntDouble* sd2;
179 int i;
180 int j;
181
182 // This is the same as a pairwise loop structure:
183 // for (int i = 0; i < n-1 ; ++i ) {
184 // for (int j = i + 1; j < n; ++j) {}
185 // }
186
187 for (sd1 = sman.beginSelected(i); sd1 != NULL; sd1 = sman.nextSelected(i)) {
188 for (j = i, sd2 = sman.nextSelected(j); sd2 != NULL;
189 sd2 = sman.nextSelected(j)) {
190 collectHistogram(sd1, sd2);
191 }
192 }
193 }
194} // namespace OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.