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