OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
SequentialProps.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 <fstream>
49#include <iostream>
50#include <string>
51
53#include "applications/sequentialProps/COMVel.hpp"
54#include "applications/sequentialProps/CountDifference.hpp"
55#include "applications/sequentialProps/CenterOfMass.hpp"
56#include "applications/sequentialProps/ContactAngle1.hpp"
57#include "applications/sequentialProps/ContactAngle2.hpp"
58#include "applications/sequentialProps/FluxOut.hpp"
59#include "applications/sequentialProps/GCNSeq.hpp"
60#include "applications/sequentialProps/Qsurf.hpp"
61#include "applications/sequentialProps/SequentialAnalyzer.hpp"
62#include "applications/sequentialProps/equipartitionTest.hpp"
63#include "brains/SimCreator.hpp"
64#include "brains/SimInfo.hpp"
65#include "utils/StringUtils.hpp"
66#include "utils/simError.h"
67
68using namespace OpenMD;
69
70int main(int argc, char* argv[]) {
71 gengetopt_args_info args_info;
72
73 // parse the command line option
74 if (cmdline_parser(argc, argv, &args_info) != 0) { exit(1); }
75
76 // get the dumpfile name and meta-data file name
77 std::string dumpFileName = args_info.input_arg;
78
79 std::string sele1;
80 std::string sele2;
81
82 // check the first selection argument, or set it to the environment
83 // variable, or failing that, set it to "select all"
84
85 if (args_info.sele1_given) {
86 sele1 = args_info.sele1_arg;
87 } else {
88 char* sele1Env = getenv("SELECTION1");
89 if (sele1Env) {
90 sele1 = sele1Env;
91 } else {
92 sele1 = "select all";
93 }
94 }
95
96 // check the second selection argument, or set it to the environment
97 // variable, or failing that, set it to the first selection
98
99 if (args_info.sele2_given) {
100 sele2 = args_info.sele2_arg;
101 } else {
102 char* sele2Env = getenv("SELECTION2");
103 if (sele2Env) {
104 sele2 = sele2Env;
105 } else {
106 // If sele2 is not specified, then the default behavior
107 // should be what is already intended for sele1
108 sele2 = sele1;
109 }
110 }
111
112 // parse md file and set up the system
113 SimCreator creator;
114 SimInfo* info = creator.createSim(dumpFileName, false);
115
116 // convert privilegedAxis to corresponding integer
117 // x axis -> 0
118 // y axis -> 1
119 // z axis -> 2 (default)
120
121 int privilegedAxis;
122 switch (args_info.privilegedAxis_arg) {
123 case privilegedAxis_arg_x:
124 privilegedAxis = 0;
125 break;
126 case privilegedAxis_arg_y:
127 privilegedAxis = 1;
128 break;
129 case privilegedAxis_arg_z:
130 default:
131 privilegedAxis = 2;
132 break;
133 }
134
135 std::unique_ptr<SequentialAnalyzer> analyzer {nullptr};
136
137 if (args_info.com_given) {
138 analyzer = std::make_unique<CenterOfMass>(info, dumpFileName, sele1, sele2);
139 } else if (args_info.comvel_given) {
140 analyzer = std::make_unique<COMVel>(info, dumpFileName, sele1, sele2);
141 } else if (args_info.fluxOut_given) {
142 analyzer = std::make_unique<FluxOut>(info, dumpFileName, sele1,
143 privilegedAxis);
144 } else if (args_info.deltaCount_given) {
145 analyzer = std::make_unique<CountDifference>(info, dumpFileName, sele1,
146 sele2);
147 } else if (args_info.testequi_given) {
148 analyzer = std::make_unique<Equipartition>(info, dumpFileName, sele1,
149 sele2);
150 } else if (args_info.gcn_given) {
151 if (args_info.rcut_given) {
152 analyzer = std::make_unique<GCNSeq>(info, dumpFileName, sele1, sele2,
153 args_info.rcut_arg,
154 args_info.nbins_arg);
155 } else {
156 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
157 "A cutoff radius (rcut) must be specified when calculating\n"
158 "\tGeneralized Coordinate Number");
159 painCave.severity = OPENMD_ERROR;
160 painCave.isFatal = 1;
161 simError();
162 }
163 } else if (args_info.ca1_given) {
164 RealType solidZ(0.0);
165 if (args_info.referenceZ_given)
166 solidZ = args_info.referenceZ_arg;
167 else {
168 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
169 "--referenceZ must be set if --ca1 is used\n");
170 painCave.severity = OPENMD_ERROR;
171 painCave.isFatal = 1;
172 simError();
173 }
174 RealType dropletR(0.0);
175 if (args_info.dropletR_given)
176 dropletR = args_info.dropletR_arg;
177 else {
178 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
179 "--dropletR must be set if --ca1 is used\n");
180 painCave.severity = OPENMD_ERROR;
181 painCave.isFatal = 1;
182 simError();
183 }
184
185 analyzer =
186 std::make_unique<ContactAngle1>(info, dumpFileName, sele1, sele2,
187 solidZ, dropletR);
188 } else if (args_info.ca2_given) {
189 RealType solidZ(0.0);
190 if (args_info.referenceZ_given)
191 solidZ = args_info.referenceZ_arg;
192 else {
193 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
194 "--referenceZ must be set if --ca2 is used\n");
195 painCave.severity = OPENMD_ERROR;
196 painCave.isFatal = 1;
197 simError();
198 }
199 RealType centroidX(0.0);
200 if (args_info.centroidX_given)
201 centroidX = args_info.centroidX_arg;
202 else {
203 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
204 "--centroidX must be set if --ca2 is used\n");
205 painCave.severity = OPENMD_ERROR;
206 painCave.isFatal = 1;
207 simError();
208 }
209 RealType centroidY(0.0);
210 if (args_info.centroidY_given)
211 centroidY = args_info.centroidY_arg;
212 else {
213 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
214 "--centroidY must be set if --ca2 is used\n");
215 painCave.severity = OPENMD_ERROR;
216 painCave.isFatal = 1;
217 simError();
218 }
219 RealType threshDens(0.0);
220 if (args_info.threshDens_given)
221 threshDens = args_info.threshDens_arg;
222 else {
223 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
224 "--threshDens must be set if --ca2 is used\n");
225 painCave.severity = OPENMD_ERROR;
226 painCave.isFatal = 1;
227 simError();
228 }
229 RealType bufferLength(0.0);
230 if (args_info.bufferLength_given)
231 bufferLength = args_info.bufferLength_arg;
232 else {
233 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
234 "--bufferLength must be set if --ca2 is used\n");
235 painCave.severity = OPENMD_ERROR;
236 painCave.isFatal = 1;
237 simError();
238 }
239
240 analyzer = std::make_unique<ContactAngle2>(info, dumpFileName, sele1,
241 sele2, solidZ, centroidX,
242 centroidY, threshDens,
243 bufferLength,
244 args_info.nbins_arg,
245 args_info.nbins_z_arg);
246 } else if (args_info.qsurf_given) {
247 if (!args_info.rcut_given) {
248 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
249 "A cutoff radius (--rcut) must be specified when using\n"
250 "\t--qsurf for the neighbor search.");
251 painCave.severity = OPENMD_ERROR;
252 painCave.isFatal = 1;
253 simError();
254 }
255
256 analyzer = std::make_unique<Qsurf>(info, dumpFileName, sele1, sele2,
257 args_info.rcut_arg,
258 args_info.voxelSize_arg,
259 args_info.gaussWidth_arg);
260 }
261
262 if (analyzer != NULL) {
263
264 if (args_info.output_given) {
265 analyzer->setOutputName(args_info.output_arg);
266 }
267
268 analyzer->doSequence();
269 } else {
270 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
271 "SequentialProps: No Analyzer was created, nothing to do!");
272 painCave.severity = OPENMD_ERROR;
273 painCave.isFatal = 1;
274 simError();
275 }
276
277 delete info;
278
279 return 0;
280}
The header file for the command line option parser generated by GNU Gengetopt version 2....
The only responsibility of SimCreator is to parse the meta-data file and create a SimInfo instance ba...
SimInfo * createSim(const std::string &mdFileName, bool loadInitCoords=true)
Setup Simulation.
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.
Where the command line options are stored.
unsigned int comvel_given
Whether comvel was given.
char * sele2_arg
select second stuntdouble set (if sele2 is not set, use script from sele1).
unsigned int output_given
Whether output was given.
double gaussWidth_arg
Gaussian width for coarse graining (Angstroms) (default='3.0').
double centroidX_arg
Location of droplet centroid in x.
unsigned int referenceZ_given
Whether referenceZ was given.
unsigned int dropletR_given
Whether dropletR was given.
unsigned int fluxOut_given
Whether fluxOut was given.
unsigned int threshDens_given
Whether threshDens was given.
double bufferLength_arg
Buffer length in angstroms.
double referenceZ_arg
Reference z-height of solid surface.
unsigned int ca2_given
Whether ca2 was given.
char * output_arg
output file name.
unsigned int centroidY_given
Whether centroidY was given.
unsigned int testequi_given
Whether testequi was given.
char * input_arg
input dump file.
int nbins_z_arg
number of bins in z axis (default='100').
unsigned int sele1_given
Whether sele1 was given.
unsigned int gcn_given
Whether gcn was given.
unsigned int com_given
Whether com was given.
double rcut_arg
cutoff radius (angstroms).
unsigned int deltaCount_given
Whether deltaCount was given.
unsigned int ca1_given
Whether ca1 was given.
double voxelSize_arg
voxel size for coarse graining (Angstroms) (default='2.0').
char * sele1_arg
select first stuntdouble set.
double centroidY_arg
Location of droplet centroid in y.
unsigned int rcut_given
Whether rcut was given.
unsigned int bufferLength_given
Whether bufferLength was given.
double threshDens_arg
Threshold Density in g/cm^3.
unsigned int qsurf_given
Whether qsurf was given.
int nbins_arg
Number of bins (default='100').
enum enum_privilegedAxis privilegedAxis_arg
which axis is special for spatial analysis (default = z axis) (default='z').
unsigned int centroidX_given
Whether centroidX was given.
unsigned int sele2_given
Whether sele2 was given.
double dropletR_arg
Droplet radius in angstroms.