OpenMD 3.2
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 following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48#include "RadialDistrFunc.hpp"
49
50#include <algorithm>
51
52#include "io/DumpReader.hpp"
54
55namespace OpenMD {
56
57 RadialDistrFunc::RadialDistrFunc(SimInfo* info, const std::string& filename,
58 const std::string& sele1,
59 const std::string& sele2,
60 unsigned int nbins) :
61 StaticAnalyser(info, filename, nbins),
62 selectionScript1_(sele1), selectionScript2_(sele2), evaluator1_(info),
63 evaluator2_(info), seleMan1_(info), seleMan2_(info),
64 sele1_minus_common_(info), sele2_minus_common_(info), common_(info) {
65 evaluator1_.loadScriptString(sele1);
66 evaluator2_.loadScriptString(sele2);
67
68 if (!evaluator1_.isDynamic()) {
69 seleMan1_.setSelectionSet(evaluator1_.evaluate());
70 validateSelection1(seleMan1_);
71 }
72 if (!evaluator2_.isDynamic()) {
73 seleMan2_.setSelectionSet(evaluator2_.evaluate());
74 validateSelection2(seleMan2_);
75 }
76
77 if (!evaluator1_.isDynamic() && !evaluator2_.isDynamic()) {
78 // If all selections are static, we can precompute the number
79 // of real pairs.
80 common_ = seleMan1_ & seleMan2_;
81 sele1_minus_common_ = seleMan1_ - common_;
82 sele2_minus_common_ = seleMan2_ - common_;
83
84 nSelected1_ = seleMan1_.getSelectionCount();
85 nSelected2_ = seleMan2_.getSelectionCount();
86 int nIntersect = common_.getSelectionCount();
87
88 nPairs_ = nSelected1_ * nSelected2_ - (nIntersect + 1) * nIntersect / 2;
89 }
90 }
91
92 void RadialDistrFunc::process() {
93 preProcess();
94
95 DumpReader reader(info_, dumpFilename_);
96 int nFrames = reader.getNFrames();
97 nProcessed_ = nFrames / step_;
98
99 for (int i = 0; i < nFrames; i += step_) {
100 reader.readFrame(i);
101 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
102
103 if (evaluator1_.isDynamic()) {
104 seleMan1_.setSelectionSet(evaluator1_.evaluate());
105 validateSelection1(seleMan1_);
106 }
107 if (evaluator2_.isDynamic()) {
108 seleMan2_.setSelectionSet(evaluator2_.evaluate());
109 validateSelection2(seleMan2_);
110 }
111
112 initializeHistogram();
113
114 // Selections may overlap, and we need a bit of logic to deal
115 // with this.
116 //
117 // | s1 |
118 // | s1 -c | c |
119 // | c | s2 - c |
120 // | s2 |
121 //
122 // s1 : Set of StuntDoubles in selection1
123 // s2 : Set of StuntDoubles in selection2
124 // c : Intersection of selection1 and selection2
125 //
126 // When we loop over the pairs, we can divide the looping into 3
127 // stages:
128 //
129 // Stage 1 : [s1-c] [s2]
130 // Stage 2 : [c] [s2 - c]
131 // Stage 3 : [c] [c]
132 // Stages 1 and 2 are completely non-overlapping.
133 // Stage 3 is completely overlapping.
134
135 if (evaluator1_.isDynamic() || evaluator2_.isDynamic()) {
136 common_ = seleMan1_ & seleMan2_;
137 sele1_minus_common_ = seleMan1_ - common_;
138 sele2_minus_common_ = seleMan2_ - common_;
139 nSelected1_ = seleMan1_.getSelectionCount();
140 nSelected2_ = seleMan2_.getSelectionCount();
141 int nIntersect = common_.getSelectionCount();
142
143 nPairs_ = nSelected1_ * nSelected2_ - (nIntersect + 1) * nIntersect / 2;
144 }
145
146 processNonOverlapping(sele1_minus_common_, seleMan2_);
147 processNonOverlapping(common_, sele2_minus_common_);
148 processOverlapping(common_);
149
150 processHistogram();
151 }
152
153 postProcess();
154
155 writeRdf();
156 }
157
158 void RadialDistrFunc::processNonOverlapping(SelectionManager& sman1,
159 SelectionManager& sman2) {
160 StuntDouble* sd1;
161 StuntDouble* sd2;
162 int i;
163 int j;
164
165 // This is the same as a non-overlapping pairwise loop structure:
166 // for (int i = 0; i < ni ; ++i ) {
167 // for (int j = 0; j < nj; ++j) {}
168 // }
169
170 for (sd1 = sman1.beginSelected(i); sd1 != NULL;
171 sd1 = sman1.nextSelected(i)) {
172 for (sd2 = sman2.beginSelected(j); sd2 != NULL;
173 sd2 = sman2.nextSelected(j)) {
174 collectHistogram(sd1, sd2);
175 }
176 }
177 }
178
179 void RadialDistrFunc::processOverlapping(SelectionManager& sman) {
180 StuntDouble* sd1;
181 StuntDouble* sd2;
182 int i;
183 int j;
184
185 // This is the same as a pairwise loop structure:
186 // for (int i = 0; i < n-1 ; ++i ) {
187 // for (int j = i + 1; j < n; ++j) {}
188 // }
189
190 for (sd1 = sman.beginSelected(i); sd1 != NULL; sd1 = sman.nextSelected(i)) {
191 for (j = i, sd2 = sman.nextSelected(j); sd2 != NULL;
192 sd2 = sman.nextSelected(j)) {
193 collectHistogram(sd1, sd2);
194 }
195 }
196 }
197} // namespace OpenMD
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:96
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.