OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
Globals.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 "io/Globals.hpp"
49
50#include <cstdio>
51#include <cstdlib>
52#include <cstring>
53#include <string>
54
55#include "io/ParamConstraint.hpp"
56#include "utils/MemoryUtils.hpp"
57#include "utils/simError.h"
58
59namespace OpenMD {
60 Globals::Globals() {
61 flucQpars_ = new FluctuatingChargeParameters();
62 rnemdPars_ = new RNEMD::RNEMDParameters();
63 lightPars_ = new Perturbations::LightParameters();
64 vfPars_ = new Perturbations::VelocityFieldParameters();
65 minimizerPars_ = new MinimizerParameters();
66
67 DefineParameter(ForceField, "forceField");
68
69 DefineOptionalParameter(TargetTemp, "targetTemp");
70 DefineOptionalParameter(Ensemble, "ensemble");
71 DefineOptionalParameter(Dt, "dt");
72 DefineOptionalParameter(RunTime, "runTime");
73 DefineOptionalParameter(FinalConfig, "finalConfig");
74 DefineOptionalParameter(SampleTime, "sampleTime");
75 DefineOptionalParameter(ResetTime, "resetTime");
76 DefineOptionalParameter(StatusTime, "statusTime");
77 DefineOptionalParameter(CutoffRadius, "cutoffRadius");
78 DefineOptionalParameter(SwitchingRadius, "switchingRadius");
79 DefineOptionalParameter(TempSet, "tempSet");
80 DefineOptionalParameter(ThermalTime, "thermalTime");
81 DefineOptionalParameter(TargetPressure, "targetPressure");
82 DefineOptionalParameter(TauThermostat, "tauThermostat");
83 DefineOptionalParameter(TauBarostat, "tauBarostat");
84 DefineOptionalParameter(LangevinPistonDrag, "langevinPistonDrag");
85 DefineOptionalParameter(ZconsTime, "zconsTime");
86 DefineOptionalParameter(ZconsTol, "zconsTol");
87 DefineOptionalParameter(ZconsForcePolicy, "zconsForcePolicy");
88 DefineOptionalParameter(Seed, "seed");
89 DefineOptionalParameter(ZconsGap, "zconsGap");
90 DefineOptionalParameter(ZconsFixtime, "zconsFixtime");
91 DefineOptionalParameter(ZconsUsingSMD, "zconsUsingSMD");
92 DefineOptionalParameter(ThermodynamicIntegrationLambda,
93 "thermodynamicIntegrationLambda");
94 DefineOptionalParameter(ThermodynamicIntegrationK,
95 "thermodynamicIntegrationK");
96 DefineOptionalParameter(ForceFieldVariant, "forceFieldVariant");
97 DefineOptionalParameter(ForceFieldFileName, "forceFieldFileName");
98 DefineOptionalParameter(DampingAlpha, "dampingAlpha");
99 DefineOptionalParameter(SurfaceTension, "surfaceTension");
100 DefineOptionalParameter(PrintPressureTensor, "printPressureTensor");
101 DefineOptionalParameter(PrintVirialTensor, "printVirialTensor");
102 DefineOptionalParameter(ElectricField, "electricField");
103 DefineOptionalParameter(UniformField, "uniformField");
104 // magnetic field optional parameter added
105 DefineOptionalParameter(MagneticField, "magneticField");
106 DefineOptionalParameter(UniformGradientStrength, "uniformGradientStrength");
107 DefineOptionalParameter(UniformGradientDirection1,
108 "uniformGradientDirection1");
109 DefineOptionalParameter(UniformGradientDirection2,
110 "uniformGradientDirection2");
111 // DefineOptionalParameter(PeriodicField, "periodicField");
112 // DefineOptionalParameter(PeriodicFieldStrength, "periodicFieldStrength");
113
114 DefineOptionalParameter(TaggedAtomPair, "taggedAtomPair");
115 DefineOptionalParameter(PrintTaggedPairDistance, "printTaggedPairDistance");
116 DefineOptionalParameter(SwitchingFunctionType, "switchingFunctionType");
117 DefineOptionalParameter(HydroPropFile, "HydroPropFile");
118 DefineOptionalParameter(Viscosity, "viscosity");
119 DefineOptionalParameter(BeadSize, "beadSize");
120 DefineOptionalParameter(FrozenBufferRadius, "frozenBufferRadius");
121 DefineOptionalParameter(LangevinBufferRadius, "langevinBufferRadius");
122 DefineOptionalParameter(NeighborListNeighbors, "NeighborListNeighbors");
123 DefineOptionalParameter(UseMultipleTemperatureMethod,
124 "useMultipleTemperatureMethod");
125 DefineOptionalParameter(ElectrostaticSummationMethod,
126 "electrostaticSummationMethod");
127 DefineOptionalParameter(MTM_Ce, "MTM_Ce");
128 DefineOptionalParameter(MTM_G, "MTM_G");
129 DefineOptionalParameter(MTM_Io, "MTM_Io");
130 DefineOptionalParameter(MTM_Sigma, "MTM_Sigma");
131 DefineOptionalParameter(MTM_R, "MTM_R");
132 DefineOptionalParameter(Alpha, "alpha");
133 DefineOptionalParameter(ConstraintTime, "constraintTime");
134
135 DefineOptionalParameter(PotentialSelection, "potentialSelection");
136
137 DefineOptionalParameterWithDefaultValue(SkipPairLoop, "skipPairLoop",
138 false);
139 DefineOptionalParameterWithDefaultValue(
140 UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true);
141 DefineOptionalParameterWithDefaultValue(ConserveLinearMomentum,
142 "conserveLinearMomentum", true);
143 DefineOptionalParameterWithDefaultValue(ConserveAngularMomentum,
144 "conserveAngularMomentum", true);
145 DefineOptionalParameterWithDefaultValue(UseAtomicVirial, "useAtomicVirial",
146 true);
147 DefineOptionalParameterWithDefaultValue(UseLongRangeCorrections,
148 "useLongRangeCorrections", true);
149 DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime",
150 false);
151 DefineOptionalParameterWithDefaultValue(
152 UseIntialExtendedSystemState, "useInitialExtendedSystemState", false);
153 DefineOptionalParameterWithDefaultValue(OrthoBoxTolerance,
154 "orthoBoxTolerance", 1E-6);
155 DefineOptionalParameterWithDefaultValue(CutoffMethod, "cutoffMethod",
156 "SHIFTED_FORCE");
157 DefineOptionalParameterWithDefaultValue(
158 ElectrostaticScreeningMethod, "electrostaticScreeningMethod", "DAMPED");
159 DefineOptionalParameter(UseSurfaceTerm, "useSurfaceTerm");
160 DefineOptionalParameter(UseSlabGeometry, "useSlabGeometry");
161 DefineOptionalParameterWithDefaultValue(Dielectric, "dielectric", 80.0);
162 DefineOptionalParameterWithDefaultValue(CompressDumpFile,
163 "compressDumpFile", false);
164 DefineOptionalParameterWithDefaultValue(PrintHeatFlux, "printHeatFlux",
165 false);
166 DefineOptionalParameterWithDefaultValue(OutputForceVector,
167 "outputForceVector", false);
168 DefineOptionalParameterWithDefaultValue(OutputParticlePotential,
169 "outputParticlePotential", false);
170 DefineOptionalParameterWithDefaultValue(OutputElectricField,
171 "outputElectricField", false);
172 DefineOptionalParameterWithDefaultValue(OutputFluctuatingCharges,
173 "outputFluctuatingCharges", false);
174 DefineOptionalParameterWithDefaultValue(OutputSitePotential,
175 "outputSitePotential", false);
176 DefineOptionalParameterWithDefaultValue(OutputDensity, "outputDensity",
177 false);
178 DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness",
179 1.0);
180 DefineOptionalParameterWithDefaultValue(
181 StatFileFormat, "statFileFormat",
182 "TIME|TOTAL_ENERGY|POTENTIAL_ENERGY|KINETIC_ENERGY|TEMPERATURE|"
183 "PRESSURE|"
184 "VOLUME|"
185 "CONSERVED_QUANTITY");
186 DefineOptionalParameterWithDefaultValue(StatFilePrecision,
187 "statFilePrecision", 8);
188 DefineOptionalParameterWithDefaultValue(UseSphericalBoundaryConditions,
189 "useSphericalBoundaryConditions",
190 false);
191 DefineOptionalParameterWithDefaultValue(AccumulateBoxDipole,
192 "accumulateBoxDipole", false);
193 DefineOptionalParameterWithDefaultValue(AccumulateBoxQuadrupole,
194 "accumulateBoxQuadrupole", false);
195 DefineOptionalParameterWithDefaultValue(UseRestraints, "useRestraints",
196 false);
197 DefineOptionalParameterWithDefaultValue(Restraint_file, "Restraint_file",
198 "idealCrystal.in");
199 DefineOptionalParameterWithDefaultValue(
200 UseThermodynamicIntegration, "useThermodynamicIntegration", false);
201 DefineOptionalParameterWithDefaultValue(HULL_Method, "HULL_Method",
202 "Convex");
203
204 DefineOptionalParameterWithDefaultValue(PrivilegedAxis, "privilegedAxis",
205 "z");
206
207 deprecatedKeywords_.insert("nComponents");
208 deprecatedKeywords_.insert("nZconstraints");
209 deprecatedKeywords_.insert("initialConfig");
210 deprecatedKeywords_.insert("thermIntDistSpringConst");
211 deprecatedKeywords_.insert("thermIntThetaSpringConst");
212 deprecatedKeywords_.insert("thermIntOmegaSpringConst");
213 deprecatedKeywords_.insert("useSolidThermInt");
214 deprecatedKeywords_.insert("useLiquidThermInt");
215 deprecatedKeywords_.insert("minimizerMaxIter");
216 deprecatedKeywords_.insert("minimizerWriteFreq");
217 deprecatedKeywords_.insert("minimizerStepSize");
218 deprecatedKeywords_.insert("minimizerFTol");
219 deprecatedKeywords_.insert("minimizerGTol");
220 deprecatedKeywords_.insert("minimizerLSTol");
221 deprecatedKeywords_.insert("minimizerLSMaxIter");
222 deprecatedKeywords_.insert("electricField");
223 deprecatedKeywords_.insert("cutoffPolicy");
224 deprecatedKeywords_.insert("beadSize");
225 }
226
227 Globals::~Globals() {
228 Utils::deletePointers(moleculeStamps_);
229
230 Utils::deletePointers(components_);
231 Utils::deletePointers(zconstraints_);
232 Utils::deletePointers(restraints_);
233
234 delete flucQpars_;
235 delete rnemdPars_;
236 delete lightPars_;
237 delete vfPars_;
238 delete minimizerPars_;
239 }
240
241 void Globals::validate() {
242 DataHolder::validate();
243
244 CheckParameter(ForceField, isNotEmpty());
245 CheckParameter(TargetTemp, isPositive());
246 CheckParameter(
247 Ensemble,
248 isEqualIgnoreCase("NVE") || isEqualIgnoreCase("NVT") ||
249 isEqualIgnoreCase("NPTi") || isEqualIgnoreCase("NPTf") ||
250 isEqualIgnoreCase("NPTxyz") || isEqualIgnoreCase("NPTsz") ||
251 isEqualIgnoreCase("NPAT") || isEqualIgnoreCase("NPA") ||
252 isEqualIgnoreCase("LANGEVINDYNAMICS") || isEqualIgnoreCase("LD") ||
253 isEqualIgnoreCase("NPRT") || isEqualIgnoreCase("NPGT") ||
254 isEqualIgnoreCase("NGammaT") || isEqualIgnoreCase("NGT") ||
255 isEqualIgnoreCase("LANGEVINHULL") || isEqualIgnoreCase("LHULL") ||
256 isEqualIgnoreCase("SMIPD") || isEqualIgnoreCase("LANGEVINPISTON") ||
257 isEqualIgnoreCase("RPY") || isEqualIgnoreCase("RPYDYNAMICS") ||
258 isEqualIgnoreCase("LHD") || isEqualIgnoreCase("LANGEVINHYDRODYNAMICS"));
259
260 CheckParameter(Dt, isPositive());
261 CheckParameter(RunTime, isPositive());
262 CheckParameter(FinalConfig, isNotEmpty());
263 CheckParameter(SampleTime, isNonNegative());
264 CheckParameter(ResetTime, isNonNegative());
265 CheckParameter(StatusTime, isNonNegative());
266 CheckParameter(CutoffRadius, isPositive());
267 CheckParameter(SwitchingRadius, isNonNegative());
268 CheckParameter(Dielectric, isPositive());
269 CheckParameter(ThermalTime, isNonNegative());
270 CheckParameter(TauThermostat, isPositive());
271 CheckParameter(TauBarostat, isPositive());
272 CheckParameter(ZconsTime, isPositive());
273 CheckParameter(ZconsTol, isPositive());
274 CheckParameter(Seed, isPositive());
275 CheckParameter(ZconsGap, isPositive());
276 CheckParameter(ZconsFixtime, isPositive());
277 CheckParameter(ThermodynamicIntegrationLambda, isNonNegative());
278 CheckParameter(ThermodynamicIntegrationK, isPositive());
279 CheckParameter(ForceFieldVariant, isNotEmpty());
280 CheckParameter(ForceFieldFileName, isNotEmpty());
281 CheckParameter(CutoffMethod, isEqualIgnoreCase("HARD") ||
282 isEqualIgnoreCase("SWITCHED") ||
283 isEqualIgnoreCase("SHIFTED_POTENTIAL") ||
284 isEqualIgnoreCase("SHIFTED_FORCE") ||
285 isEqualIgnoreCase("TAYLOR_SHIFTED") ||
286 isEqualIgnoreCase("EWALD_FULL"));
287 CheckParameter(ElectrostaticSummationMethod,
288 isEqualIgnoreCase("NONE") || isEqualIgnoreCase("HARD") ||
289 isEqualIgnoreCase("SWITCHED") ||
290 isEqualIgnoreCase("SHIFTED_POTENTIAL") ||
291 isEqualIgnoreCase("SHIFTED_FORCE") ||
292 isEqualIgnoreCase("REACTION_FIELD") ||
293 isEqualIgnoreCase("TAYLOR_SHIFTED") ||
294 isEqualIgnoreCase("EWALD_FULL"));
295 CheckParameter(
296 ElectrostaticScreeningMethod,
297 isEqualIgnoreCase("UNDAMPED") || isEqualIgnoreCase("DAMPED"));
298 CheckParameter(SwitchingFunctionType,
299 isEqualIgnoreCase("CUBIC") ||
300 isEqualIgnoreCase("FIFTH_ORDER_POLYNOMIAL"));
301 CheckParameter(OrthoBoxTolerance, isPositive());
302 CheckParameter(DampingAlpha, isNonNegative());
303 CheckParameter(SkinThickness, isPositive());
304 CheckParameter(Viscosity, isNonNegative());
305 CheckParameter(BeadSize, isPositive());
306 CheckParameter(FrozenBufferRadius, isPositive());
307 CheckParameter(LangevinBufferRadius, isPositive());
308 CheckParameter(NeighborListNeighbors, isPositive());
309 CheckParameter(HULL_Method, isEqualIgnoreCase("Convex") ||
310 isEqualIgnoreCase("AlphaShape"));
311 CheckParameter(Alpha, isPositive());
312 CheckParameter(StatFilePrecision, isPositive());
313 CheckParameter(PrivilegedAxis, isEqualIgnoreCase("x") ||
314 isEqualIgnoreCase("y") ||
315 isEqualIgnoreCase("z"));
316
317 for (std::vector<Component*>::iterator i = components_.begin();
318 i != components_.end(); ++i) {
319 if (!(*i)->findMoleculeStamp(moleculeStamps_)) {
320 std::ostringstream oss;
321 oss << "Globals Error: can not find molecule stamp for component "
322 << (*i)->getType() << std::endl;
323 throw OpenMDException(oss.str());
324 }
325 }
326 }
327
328 bool Globals::addComponent(Component* comp) {
329 components_.push_back(comp);
330 return true;
331 }
332
333 bool Globals::addZConsStamp(ZConsStamp* zcons) {
334 zconstraints_.push_back(zcons);
335 return true;
336 }
337
338 bool Globals::addRestraintStamp(RestraintStamp* rest) {
339 restraints_.push_back(rest);
340 return true;
341 }
342
343 bool Globals::addFluctuatingChargeParameters(
345 if (flucQpars_ != NULL) delete flucQpars_;
346
347 flucQpars_ = fqp;
348 return true;
349 }
350
351 bool Globals::addRNEMDParameters(RNEMD::RNEMDParameters* rnemdPars) {
352 if (rnemdPars_ != NULL) delete rnemdPars_;
353
354 rnemdPars_ = rnemdPars;
355 return true;
356 }
357
358 bool Globals::addLightParameters(Perturbations::LightParameters* lightPars) {
359 if (lightPars_ != NULL) delete lightPars_;
360
361 lightPars_ = lightPars;
362 return true;
363 }
364
365 bool Globals::addVelocityFieldParameters(Perturbations::VelocityFieldParameters* vfPars) {
366 if (vfPars_ != NULL) delete vfPars_;
367
368 vfPars_ = vfPars;
369 return true;
370 }
371
372 bool Globals::addMinimizerParameters(MinimizerParameters* miniPars) {
373 if (minimizerPars_ != NULL) delete minimizerPars_;
374
375 minimizerPars_ = miniPars;
376 return true;
377 }
378
379 bool Globals::addMoleculeStamp(MoleculeStamp* molStamp) {
380 std::string molStampName = molStamp->getName();
381 std::map<std::string, MoleculeStamp*>::iterator i;
382 bool ret = false;
383 i = moleculeStamps_.find(molStampName);
384 if (i == moleculeStamps_.end()) {
385 moleculeStamps_.insert(std::map<std::string, MoleculeStamp*>::value_type(
386 molStampName, molStamp));
387 ret = true;
388 } else {
389 std::ostringstream oss;
390 oss << "Globals Error: Molecule Stamp " << molStamp->getName()
391 << "appears multiple times\n";
392 throw OpenMDException(oss.str());
393 }
394 return ret;
395 }
396
397 bool Globals::addFragmentStamp(FragmentStamp* fragStamp) {
398 std::string fragStampName = fragStamp->getName();
399 std::map<std::string, FragmentStamp*>::iterator i;
400 bool ret = false;
401 i = fragmentStamps_.find(fragStampName);
402 if (i == fragmentStamps_.end()) {
403 fragmentStamps_.insert(std::map<std::string, FragmentStamp*>::value_type(
404 fragStampName, fragStamp));
405 ret = true;
406 } else {
407 std::ostringstream oss;
408 oss << "Globals Error: Fragment Stamp " << fragStamp->getName()
409 << "appears multiple times\n";
410 throw OpenMDException(oss.str());
411 }
412 return ret;
413 }
414} // namespace OpenMD
Parsed contents of the velocityField{ ... } block.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
ElectrostaticSummationMethod