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