OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
TimeCorrFunc.hpp
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#ifndef APPLICATIONS_DYNAMICPROPS_TIMECORRFUNC_HPP
46#define APPLICATIONS_DYNAMICPROPS_TIMECORRFUNC_HPP
47
48#include <string>
49#include <vector>
50
51#include "applications/dynamicProps/DynamicProperty.hpp"
52#include "brains/SimInfo.hpp"
53#include "io/DumpReader.hpp"
55#include "selection/SelectionEvaluator.hpp"
56#include "selection/SelectionManager.hpp"
57#include "utils/ProgressBar.hpp"
58
59namespace OpenMD {
60
61 //! Computes a correlation function by scanning a trajectory once to
62 //! precompute quantities to be correlated
63
64 template<typename T>
66 public:
67 TimeCorrFunc(SimInfo* info, const std::string& filename,
68 const std::string& sele1, const std::string& sele2);
69
70 virtual ~TimeCorrFunc() { delete reader_; }
71 virtual void doCorrelate();
72
73 const std::string& getCorrFuncType() const { return corrFuncType_; }
74
75 void setCorrFuncType(const std::string& type) { corrFuncType_ = type; }
76
77 void setParameterString(const std::string& params) {
78 paramString_ = params;
79 }
80
81 void setLabelString(const std::string& label) { labelString_ = label; }
82
83 protected:
84 virtual void preCorrelate();
85 virtual void correlation();
86 virtual void postCorrelate();
87 virtual void computeFrame(int frame);
88 virtual void validateSelection(SelectionManager& seleMan);
89 virtual void correlateFrames(int frame1, int frame2, int timeBin);
90 virtual void writeCorrelate();
91
92 // The pure virtual functions that must be implemented.
93
94 // For System Properties:
95 virtual void computeProperty1(int frame) = 0;
96 virtual void computeProperty2(int frame) = 0;
97 virtual T calcCorrVal(int frame1, int frame2) = 0;
98 // For Molecular Properties
99 virtual int computeProperty1(int frame, Molecule* mol) = 0;
100 virtual int computeProperty2(int frame, Molecule* mol) = 0;
101 // For Object
102 virtual int computeProperty1(int frame, StuntDouble* sd) = 0;
103 virtual int computeProperty2(int frame, StuntDouble* sd) = 0;
104 // For Bond properties
105 virtual int computeProperty1(int frame, Bond* b) = 0;
106 virtual int computeProperty2(int frame, Bond* b) = 0;
107 // For everything except System properties:
108 virtual T calcCorrVal(int frame1, int frame2, int id1, int id2) = 0;
109
110 RealType deltaTime_;
111 unsigned int nTimeBins_;
112 int nFrames_;
113 std::vector<T> histogram_;
114 std::vector<int> count_;
115 std::vector<RealType> times_;
116
117 SimInfo* info_ {nullptr};
118 DumpReader* reader_;
119 std::string dumpFilename_;
120 SelectionManager seleMan1_;
121 SelectionManager seleMan2_;
122
123 Snapshot* currentSnapshot_;
124
125 std::string selectionScript1_;
126 std::string selectionScript2_;
127
128 SelectionEvaluator evaluator1_;
129 SelectionEvaluator evaluator2_;
130
131 bool uniqueSelections_;
132 bool autoCorrFunc_;
133 bool doSystemProperties_;
134 bool doMolecularProperties_;
135 bool doObjectProperties_;
136 bool doAtomicProperties_;
137 bool doBondProperties_;
138
139 std::string corrFuncType_;
140 std::string paramString_;
141 std::string labelString_;
142
143 std::vector<std::vector<int>> sele1ToIndex_;
144 std::vector<std::vector<int>> sele2ToIndex_;
145
146 ProgressBarPtr progressBar_;
147 };
148
149 template<typename T>
150 class AutoCorrFunc : public TimeCorrFunc<T> {
151 public:
152 AutoCorrFunc(SimInfo* info, const std::string& filename,
153 const std::string& sele1, const std::string& sele2);
154
155 protected:
156 virtual void computeProperty1(int frame) = 0;
157 virtual int computeProperty1(int frame, Molecule* mol) = 0;
158 virtual int computeProperty1(int frame, StuntDouble* sd) = 0;
159 virtual int computeProperty1(int frame, Bond* bond) = 0;
160
161 virtual void computeProperty2(int) {}
162 virtual int computeProperty2(int, Molecule*) { return -1; }
163 virtual int computeProperty2(int, StuntDouble*) { return -1; }
164 virtual int computeProperty2(int, Bond*) { return -1; }
165 };
166
167 template<typename T>
168 class CrossCorrFunc : public TimeCorrFunc<T> {
169 public:
170 CrossCorrFunc(SimInfo* info, const std::string& filename,
171 const std::string& sele1, const std::string& sele2);
172
173 protected:
174 virtual void computeProperty1(int frame) = 0;
175 virtual int computeProperty1(int frame, Molecule* mol) = 0;
176 virtual int computeProperty1(int frame, StuntDouble* sd) = 0;
177 virtual int computeProperty1(int frame, Bond* bond) = 0;
178 virtual void computeProperty2(int frame) = 0;
179 virtual int computeProperty2(int frame, Molecule* mol) = 0;
180 virtual int computeProperty2(int frame, StuntDouble* sd) = 0;
181 virtual int computeProperty2(int frame, Bond* bond) = 0;
182 };
183
184 template<typename T>
185 class SystemACF : public AutoCorrFunc<T> {
186 public:
187 SystemACF(SimInfo* info, const std::string& filename,
188 const std::string& sele1, const std::string& sele2);
189
190 protected:
191 virtual void computeProperty1(int frame) = 0;
192 virtual T calcCorrVal(int frame1, int frame2) = 0;
193
194 virtual int computeProperty1(int, Molecule*) { return -1; }
195 virtual int computeProperty1(int, StuntDouble*) { return -1; }
196 virtual int computeProperty1(int, Bond*) { return -1; }
197
198 virtual void computeProperty2(int) {}
199 virtual int computeProperty2(int, Molecule*) { return -1; }
200 virtual int computeProperty2(int, StuntDouble*) { return -1; }
201 virtual int computeProperty2(int, Bond*) { return -1; }
202
203 T calcCorrVal(int, int, int, int) { return T(0.0); }
204 };
205
206 template<typename T>
207 class SystemCCF : public CrossCorrFunc<T> {
208 public:
209 SystemCCF(SimInfo* info, const std::string& filename,
210 const std::string& sele1, const std::string& sele2);
211
212 protected:
213 virtual void computeProperty1(int frame) = 0;
214 virtual void computeProperty2(int frame) = 0;
215 virtual T calcCorrVal(int frame1, int frame2) = 0;
216
217 virtual int computeProperty1(int, Molecule*) { return -1; }
218 virtual int computeProperty1(int, StuntDouble*) { return -1; }
219 virtual int computeProperty1(int, Bond*) { return -1; }
220
221 virtual int computeProperty2(int, Molecule*) { return -1; }
222 virtual int computeProperty2(int, StuntDouble*) { return -1; }
223 virtual int computeProperty2(int, Bond*) { return -1; }
224
225 T calcCorrVal(int, int, int, int) { return T(0.0); }
226 };
227
228 template<typename T>
229 class ObjectACF : public AutoCorrFunc<T> {
230 public:
231 ObjectACF(SimInfo* info, const std::string& filename,
232 const std::string& sele1, const std::string& sele2);
233
234 protected:
235 virtual int computeProperty1(int frame, StuntDouble* sd) = 0;
236 virtual T calcCorrVal(int frame1, int frame2, int id1, int id2) = 0;
237
238 virtual void computeProperty1(int) { return; }
239 virtual int computeProperty1(int, Molecule*) { return -1; }
240 virtual int computeProperty1(int, Bond*) { return -1; }
241
242 virtual void computeProperty2(int) { return; }
243 virtual int computeProperty2(int, Molecule*) { return -1; }
244 virtual int computeProperty2(int, StuntDouble*) { return -1; }
245 virtual int computeProperty2(int, Bond*) { return -1; }
246
247 virtual T calcCorrVal(int, int) { return T(0.0); }
248 };
249
250 template<typename T>
251 class ObjectCCF : public CrossCorrFunc<T> {
252 public:
253 ObjectCCF(SimInfo* info, const std::string& filename,
254 const std::string& sele1, const std::string& sele2);
255
256 protected:
257 virtual int computeProperty1(int frame, StuntDouble* sd) = 0;
258 virtual int computeProperty2(int frame, StuntDouble* sd) = 0;
259 virtual T calcCorrVal(int frame1, int frame2, int id1, int id2) = 0;
260
261 virtual void computeProperty1(int) { return; }
262 virtual int computeProperty1(int, Molecule*) { return -1; }
263 virtual int computeProperty1(int, Bond*) { return -1; }
264
265 virtual void computeProperty2(int) {}
266 virtual int computeProperty2(int, Molecule*) { return -1; }
267 virtual int computeProperty2(int, Bond*) { return -1; }
268
269 virtual T calcCorrVal(int, int) { return T(0.0); }
270 };
271
272 template<typename T>
273 class MoleculeACF : public AutoCorrFunc<T> {
274 public:
275 MoleculeACF(SimInfo* info, const std::string& filename,
276 const std::string& sele1, const std::string& sele2);
277
278 protected:
279 virtual int computeProperty1(int frame, Molecule* mol) = 0;
280 virtual T calcCorrVal(int frame1, int frame2, int id1, int id2) = 0;
281
282 virtual void computeProperty1(int) { return; }
283 virtual int computeProperty1(int, StuntDouble*) { return -1; }
284 virtual int computeProperty1(int, Bond*) { return -1; }
285
286 virtual void computeProperty2(int) { return; }
287 virtual int computeProperty2(int, Molecule*) { return -1; }
288 virtual int computeProperty2(int, StuntDouble*) { return -1; }
289 virtual int computeProperty2(int, Bond*) { return -1; }
290
291 virtual T calcCorrVal(int, int) { return T(0.0); }
292 };
293
294 template<typename T>
295 class MoleculeCCF : public CrossCorrFunc<T> {
296 public:
297 MoleculeCCF(SimInfo* info, const std::string& filename,
298 const std::string& sele1, const std::string& sele2);
299
300 protected:
301 virtual int computeProperty1(int frame, Molecule* mol) = 0;
302 virtual int computeProperty2(int frame, Molecule* mol) = 0;
303 virtual T calcCorrVal(int frame1, int frame2, int id1, int id2) = 0;
304
305 virtual void computeProperty1(int) { return; }
306 virtual int computeProperty1(int, StuntDouble*) { return -1; }
307 virtual int computeProperty1(int, Bond*) { return -1; }
308
309 virtual void computeProperty2(int) {}
310 virtual int computeProperty2(int, StuntDouble*) { return -1; }
311 virtual int computeProperty2(int, Bond*) { return -1; }
312
313 virtual T calcCorrVal(int, int) { return T(0.0); }
314 };
315} // namespace OpenMD
316
317#endif
"applications/dynamicProps/DynamicProperty"
"selection/SelectionEvaluator"
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:93
The Snapshot class is a repository storing dynamic data during a Simulation.
Definition Snapshot.hpp:147
"Don't move, or you're dead! Stand up! Captain, we've got them!"
Computes a correlation function by scanning a trajectory once to precompute quantities to be correlat...
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.