| 1 |  | /* | 
| 2 | < | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | 
| 2 | > | * Copyright (c) 2005, 2010 The University of Notre Dame. All Rights Reserved. | 
| 3 |  | * | 
| 4 |  | * The University of Notre Dame grants you ("Licensee") a | 
| 5 |  | * non-exclusive, royalty free, license to use, modify and | 
| 6 |  | * redistribute this software in source and binary code form, provided | 
| 7 |  | * that the following conditions are met: | 
| 8 |  | * | 
| 9 | < | * 1. Acknowledgement of the program authors must be made in any | 
| 10 | < | *    publication of scientific results based in part on use of the | 
| 11 | < | *    program.  An acceptable form of acknowledgement is citation of | 
| 12 | < | *    the article in which the program was described (Matthew | 
| 13 | < | *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher | 
| 14 | < | *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented | 
| 15 | < | *    Parallel Simulation Engine for Molecular Dynamics," | 
| 16 | < | *    J. Comput. Chem. 26, pp. 252-271 (2005)) | 
| 17 | < | * | 
| 18 | < | * 2. Redistributions of source code must retain the above copyright | 
| 9 | > | * 1. Redistributions of source code must retain the above copyright | 
| 10 |  | *    notice, this list of conditions and the following disclaimer. | 
| 11 |  | * | 
| 12 | < | * 3. Redistributions in binary form must reproduce the above copyright | 
| 12 | > | * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 |  | *    notice, this list of conditions and the following disclaimer in the | 
| 14 |  | *    documentation and/or other materials provided with the | 
| 15 |  | *    distribution. | 
| 28 |  | * arising out of the use of or inability to use software, even if the | 
| 29 |  | * University of Notre Dame has been advised of the possibility of | 
| 30 |  | * such damages. | 
| 31 | + | * | 
| 32 | + | * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your | 
| 33 | + | * research, please cite the appropriate papers when you publish your | 
| 34 | + | * work.  Good starting points are: | 
| 35 | + | * | 
| 36 | + | * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | 
| 37 | + | * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | 
| 38 | + | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). | 
| 39 | + | * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 | + | * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 |  | */ | 
| 42 |  |  | 
| 43 |  | #include <stdlib.h> | 
| 46 |  | #include <string> | 
| 47 |  |  | 
| 48 |  | #include "io/Globals.hpp" | 
| 49 | + | #include "io/ParamConstraint.hpp" | 
| 50 | + | #include "utils/MemoryUtils.hpp" | 
| 51 |  | #include "utils/simError.h" | 
| 49 | – | #ifdef IS_MPI | 
| 50 | – | #include "io/mpiBASS.h" | 
| 51 | – | #endif // is_mpi | 
| 52 |  |  | 
| 53 | < | #include "io/ParamConstraint.hpp" | 
| 53 | > | namespace OpenMD { | 
| 54 | > | Globals::Globals() { | 
| 55 | > |  | 
| 56 | > | flucQpars_ = new FluctuatingChargeParameters(); | 
| 57 | > | rnemdPars_ = new RNEMDParameters(); | 
| 58 | > | minimizerPars_ = new MinimizerParameters(); | 
| 59 |  |  | 
| 60 | < | #define DefineParameter(NAME,KEYWORD)                              \ | 
| 61 | < | NAME.setKeyword(KEYWORD);                  \ | 
| 62 | < | parameters_.insert(std::make_pair(std::string(KEYWORD),  &NAME)); | 
| 60 | > | DefineParameter(ForceField, "forceField"); | 
| 61 | > |  | 
| 62 | > | DefineOptionalParameter(TargetTemp, "targetTemp"); | 
| 63 | > | DefineOptionalParameter(Ensemble, "ensemble"); | 
| 64 | > | DefineOptionalParameter(Dt, "dt"); | 
| 65 | > | DefineOptionalParameter(RunTime, "runTime"); | 
| 66 | > | DefineOptionalParameter(FinalConfig, "finalConfig"); | 
| 67 | > | DefineOptionalParameter(SampleTime, "sampleTime"); | 
| 68 | > | DefineOptionalParameter(ResetTime, "resetTime"); | 
| 69 | > | DefineOptionalParameter(StatusTime, "statusTime"); | 
| 70 | > | DefineOptionalParameter(CutoffRadius, "cutoffRadius"); | 
| 71 | > | DefineOptionalParameter(SwitchingRadius, "switchingRadius"); | 
| 72 | > | DefineOptionalParameter(TempSet, "tempSet"); | 
| 73 | > | DefineOptionalParameter(ThermalTime, "thermalTime"); | 
| 74 | > | DefineOptionalParameter(TargetPressure, "targetPressure"); | 
| 75 | > | DefineOptionalParameter(TauThermostat, "tauThermostat"); | 
| 76 | > | DefineOptionalParameter(TauBarostat, "tauBarostat"); | 
| 77 | > | DefineOptionalParameter(ZconsTime, "zconsTime"); | 
| 78 | > | DefineOptionalParameter(ZconsTol, "zconsTol"); | 
| 79 | > | DefineOptionalParameter(ZconsForcePolicy, "zconsForcePolicy"); | 
| 80 | > | DefineOptionalParameter(Seed, "seed"); | 
| 81 | > | DefineOptionalParameter(ZconsGap, "zconsGap"); | 
| 82 | > | DefineOptionalParameter(ZconsFixtime, "zconsFixtime"); | 
| 83 | > | DefineOptionalParameter(ZconsUsingSMD, "zconsUsingSMD"); | 
| 84 | > | DefineOptionalParameter(ThermodynamicIntegrationLambda, | 
| 85 | > | "thermodynamicIntegrationLambda"); | 
| 86 | > | DefineOptionalParameter(ThermodynamicIntegrationK, | 
| 87 | > | "thermodynamicIntegrationK"); | 
| 88 | > | DefineOptionalParameter(ForceFieldVariant, "forceFieldVariant"); | 
| 89 | > | DefineOptionalParameter(ForceFieldFileName, "forceFieldFileName"); | 
| 90 | > | DefineOptionalParameter(DampingAlpha, "dampingAlpha"); | 
| 91 | > | DefineOptionalParameter(SurfaceTension, "surfaceTension"); | 
| 92 | > | DefineOptionalParameter(PrintPressureTensor, "printPressureTensor"); | 
| 93 | > | DefineOptionalParameter(ElectricField, "electricField"); | 
| 94 |  |  | 
| 95 | < | #define DefineOptionalParameter(NAME,KEYWORD)                              \ | 
| 96 | < | NAME.setKeyword(KEYWORD); NAME.setOptional(true);                    \ | 
| 97 | < | parameters_.insert(std::make_pair(std::string(KEYWORD),  &NAME)); | 
| 95 | > | DefineOptionalParameter(TaggedAtomPair, "taggedAtomPair"); | 
| 96 | > | DefineOptionalParameter(PrintTaggedPairDistance, "printTaggedPairDistance"); | 
| 97 | > | DefineOptionalParameter(SwitchingFunctionType, "switchingFunctionType"); | 
| 98 | > | DefineOptionalParameter(HydroPropFile, "HydroPropFile"); | 
| 99 | > | DefineOptionalParameter(Viscosity, "viscosity"); | 
| 100 | > | DefineOptionalParameter(BeadSize, "beadSize"); | 
| 101 | > | DefineOptionalParameter(FrozenBufferRadius, "frozenBufferRadius"); | 
| 102 | > | DefineOptionalParameter(LangevinBufferRadius, "langevinBufferRadius"); | 
| 103 | > | DefineOptionalParameter(NeighborListNeighbors,"NeighborListNeighbors"); | 
| 104 | > | DefineOptionalParameter(UseMultipleTemperatureMethod, | 
| 105 | > | "useMultipleTemperatureMethod"); | 
| 106 | > | DefineOptionalParameter(ElectrostaticSummationMethod, | 
| 107 | > | "electrostaticSummationMethod"); | 
| 108 | > | DefineOptionalParameter(MTM_Ce, "MTM_Ce"); | 
| 109 | > | DefineOptionalParameter(MTM_G, "MTM_G"); | 
| 110 | > | DefineOptionalParameter(MTM_Io, "MTM_Io"); | 
| 111 | > | DefineOptionalParameter(MTM_Sigma, "MTM_Sigma"); | 
| 112 | > | DefineOptionalParameter(MTM_R, "MTM_R"); | 
| 113 | > | DefineOptionalParameter(Alpha, "alpha"); | 
| 114 | > | DefineOptionalParameter(ConstraintTime, "constraintTime"); | 
| 115 |  |  | 
| 63 | – | #define DefineOptionalParameterWithDefaultValue(NAME,KEYWORD, DEFAULTVALUE)                              \ | 
| 64 | – | NAME.setKeyword(KEYWORD); NAME.setOptional(true); NAME.setDefaultValue(DEFAULTVALUE);                      \ | 
| 65 | – | parameters_.insert(std::make_pair(std::string(KEYWORD),  &NAME)); | 
| 66 | – |  | 
| 67 | – | #define CheckParameter(NAME, CONSTRAINT)                              \ | 
| 68 | – | if (!NAME.empty()) { if (!(CONSTRAINT)(NAME.getData())) { sprintf(painCave.errMsg,"Error in checking %s : should be %s\n",NAME.getKeyword().c_str(),(CONSTRAINT).getConstraintDescription().c_str()); painCave.isFatal = 1; painCave.severity = OOPSE_ERROR; simError();} } | 
| 69 | – |  | 
| 70 | – | Globals::Globals(){ | 
| 71 | – |  | 
| 72 | – | DefineParameter(ForceField, "forceField") | 
| 73 | – | DefineParameter(NComponents, "nComponents") | 
| 74 | – |  | 
| 75 | – | DefineOptionalParameter(TargetTemp, "targetTemp"); | 
| 76 | – | DefineOptionalParameter(Ensemble, "ensemble"); | 
| 77 | – | DefineOptionalParameter(Dt, "dt"); | 
| 78 | – | DefineOptionalParameter(RunTime, "runTime"); | 
| 79 | – | DefineOptionalParameter(InitialConfig, "initialConfig"); | 
| 80 | – | DefineOptionalParameter(FinalConfig, "finalConfig"); | 
| 81 | – | DefineOptionalParameter(NMol, "nMol"); | 
| 82 | – | DefineOptionalParameter(Density, "density"); | 
| 83 | – | DefineOptionalParameter(Box, "box"); | 
| 84 | – | DefineOptionalParameter(BoxX, "boxX"); | 
| 85 | – | DefineOptionalParameter(BoxY, "boxY"); | 
| 86 | – | DefineOptionalParameter(BoxZ, "boxZ"); | 
| 87 | – | DefineOptionalParameter(SampleTime, "sampleTime"); | 
| 88 | – | DefineOptionalParameter(ResetTime, "resetTime"); | 
| 89 | – | DefineOptionalParameter(StatusTime, "statusTime"); | 
| 90 | – | DefineOptionalParameter(CutoffRadius, "cutoffRadius"); | 
| 91 | – | DefineOptionalParameter(SwitchingRadius, "switchingRadius"); | 
| 92 | – | DefineOptionalParameter(Dielectric, "dielectric"); | 
| 93 | – | DefineOptionalParameter(TempSet, "tempSet"); | 
| 94 | – | DefineOptionalParameter(ThermalTime, "thermalTime"); | 
| 95 | – | DefineOptionalParameter(TargetPressure, "targetPressure"); | 
| 96 | – | DefineOptionalParameter(TauThermostat, "tauThermostat"); | 
| 97 | – | DefineOptionalParameter(TauBarostat, "tauBarostat"); | 
| 98 | – | DefineOptionalParameter(ZconsTime, "zconsTime"); | 
| 99 | – | DefineOptionalParameter(NZconstraints, "nZconstraints"); | 
| 100 | – | DefineOptionalParameter(ZconsTol, "zconsTol"); | 
| 101 | – | DefineOptionalParameter(ZconsForcePolicy, "zconsForcePolicy"); | 
| 102 | – | DefineOptionalParameter(Seed, "seed"); | 
| 103 | – | DefineOptionalParameter(Minimizer, "minimizer"); | 
| 104 | – | DefineOptionalParameter(MinimizerMaxIter,"minimizerMaxIter"); | 
| 105 | – | DefineOptionalParameter(MinimizerWriteFrq, "minimizerWriteFrq"); | 
| 106 | – | DefineOptionalParameter(MinimizerStepSize, "minimizerStepSize"); | 
| 107 | – | DefineOptionalParameter(MinimizerFTol, "minimizerFTol"); | 
| 108 | – | DefineOptionalParameter(MinimizerGTol, "minimizerGTol"); | 
| 109 | – | DefineOptionalParameter(MinimizerLSTol, "minimizerLSTol"); | 
| 110 | – | DefineOptionalParameter(MinimizerLSMaxIter, "minimizerLSMaxIter"); | 
| 111 | – | DefineOptionalParameter(ZconsGap, "zconsGap"); | 
| 112 | – | DefineOptionalParameter(ZconsFixtime, "zconsFixtime"); | 
| 113 | – | DefineOptionalParameter(ZconsUsingSMD, "zconsUsingSMD"); | 
| 114 | – | DefineOptionalParameter(ThermodynamicIntegrationLambda, "thermodynamicIntegrationLambda"); | 
| 115 | – | DefineOptionalParameter(ThermodynamicIntegrationK, "thermodynamicIntegrationK"); | 
| 116 | – | DefineOptionalParameter(ForceFieldVariant, "forceFieldVariant"); | 
| 117 | – | DefineOptionalParameter(ForceFieldFileName, "forceFieldFileName"); | 
| 118 | – | DefineOptionalParameter(ThermIntDistSpringConst, "thermIntDistSpringConst"); | 
| 119 | – | DefineOptionalParameter(ThermIntThetaSpringConst, "thermIntThetaSpringConst"); | 
| 120 | – | DefineOptionalParameter(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst"); | 
| 121 | – | DefineOptionalParameter(SurfaceTension, "surfaceTension"); | 
| 122 | – | DefineOptionalParameter(PrintPressureTensor, "printPressureTensor"); | 
| 123 | – | DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod"); | 
| 124 | – | DefineOptionalParameter(CutoffPolicy, "cutoffPolicy"); | 
| 125 | – | DefineOptionalParameter(StatFileFormat, "statFileFormat"); | 
| 116 |  |  | 
| 117 | < | DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard"); | 
| 118 | < | DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true); | 
| 119 | < | DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", false); | 
| 120 | < | DefineOptionalParameterWithDefaultValue(UseIntialExtendedSystemState, "useInitialExtendedSystemState", false); | 
| 121 | < | DefineOptionalParameterWithDefaultValue(OrthoBoxTolerance, "orthoBoxTolerance", 1E-6); | 
| 122 | < | DefineOptionalParameterWithDefaultValue(UseSolidThermInt, "useSolidThermInt", false); | 
| 123 | < | DefineOptionalParameterWithDefaultValue(UseLiquidThermInt, "useLiquidThermInt", false); | 
| 124 | < | DefineOptionalParameterWithDefaultValue(ThermIntDistSpringConst, "thermIntDistSpringConst", 6.0); | 
| 125 | < | DefineOptionalParameterWithDefaultValue(ThermIntThetaSpringConst, "thermIntThetaSpringConst", 7.5); | 
| 126 | < | DefineOptionalParameterWithDefaultValue(ThermIntOmegaSpringConst, "thermIntOmegaSpringConst", 13.5); | 
| 127 | < | DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 1.5); | 
| 128 | < | DefineOptionalParameterWithDefaultValue(CompressDumpFile, "compressDumpFile", 0); | 
| 129 | < | DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness", 1.0); | 
| 130 | < |  | 
| 131 | < | } | 
| 117 | > | DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, | 
| 118 | > | "usePeriodicBoundaryConditions", | 
| 119 | > | true); | 
| 120 | > | DefineOptionalParameterWithDefaultValue(UseAtomicVirial, "useAtomicVirial", | 
| 121 | > | true); | 
| 122 | > | DefineOptionalParameterWithDefaultValue(UseLongRangeCorrections, | 
| 123 | > | "useLongRangeCorrections", true); | 
| 124 | > | DefineOptionalParameterWithDefaultValue(UseInitalTime, "useInitialTime", | 
| 125 | > | false); | 
| 126 | > | DefineOptionalParameterWithDefaultValue(UseIntialExtendedSystemState, | 
| 127 | > | "useInitialExtendedSystemState", | 
| 128 | > | false); | 
| 129 | > | DefineOptionalParameterWithDefaultValue(OrthoBoxTolerance, | 
| 130 | > | "orthoBoxTolerance", 1E-6); | 
| 131 | > | DefineOptionalParameterWithDefaultValue(CutoffMethod, "cutoffMethod", | 
| 132 | > | "SHIFTED_FORCE"); | 
| 133 | > | DefineOptionalParameterWithDefaultValue(ElectrostaticScreeningMethod, | 
| 134 | > | "electrostaticScreeningMethod", | 
| 135 | > | "DAMPED"); | 
| 136 | > | DefineOptionalParameterWithDefaultValue(Dielectric, "dielectric", 80.0); | 
| 137 | > | DefineOptionalParameterWithDefaultValue(CompressDumpFile, | 
| 138 | > | "compressDumpFile", false); | 
| 139 | > | DefineOptionalParameterWithDefaultValue(PrintHeatFlux, "printHeatFlux", | 
| 140 | > | false); | 
| 141 | > | DefineOptionalParameterWithDefaultValue(OutputForceVector, | 
| 142 | > | "outputForceVector", false); | 
| 143 | > | DefineOptionalParameterWithDefaultValue(OutputParticlePotential, | 
| 144 | > | "outputParticlePotential", false); | 
| 145 | > | DefineOptionalParameterWithDefaultValue(OutputElectricField, | 
| 146 | > | "outputElectricField", false); | 
| 147 | > | DefineOptionalParameterWithDefaultValue(OutputFluctuatingCharges, | 
| 148 | > | "outputFluctuatingCharges", false); | 
| 149 | > | DefineOptionalParameterWithDefaultValue(OutputSitePotential, | 
| 150 | > | "outputSitePotential", false); | 
| 151 | > | DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness", | 
| 152 | > | 1.0); | 
| 153 | > | DefineOptionalParameterWithDefaultValue(StatFileFormat, | 
| 154 | > | "statFileFormat", | 
| 155 | > | "TIME|TOTAL_ENERGY|POTENTIAL_ENERGY|KINETIC_ENERGY|TEMPERATURE|PRESSURE|VOLUME|CONSERVED_QUANTITY"); | 
| 156 | > | DefineOptionalParameterWithDefaultValue(UseSphericalBoundaryConditions, | 
| 157 | > | "useSphericalBoundaryConditions", | 
| 158 | > | false); | 
| 159 | > | DefineOptionalParameterWithDefaultValue(AccumulateBoxDipole, | 
| 160 | > | "accumulateBoxDipole", false); | 
| 161 | > | DefineOptionalParameterWithDefaultValue(UseRestraints, "useRestraints", | 
| 162 | > | false); | 
| 163 | > | DefineOptionalParameterWithDefaultValue(Restraint_file, "Restraint_file", | 
| 164 | > | "idealCrystal.in"); | 
| 165 | > | DefineOptionalParameterWithDefaultValue(UseThermodynamicIntegration, | 
| 166 | > | "useThermodynamicIntegration", | 
| 167 | > | false); | 
| 168 | > | DefineOptionalParameterWithDefaultValue(HULL_Method,"HULL_Method","Convex"); | 
| 169 |  |  | 
| 170 | < | int Globals::globalAssign( event* the_event ){ | 
| 171 | < | char errorMessage[65535]; | 
| 172 | < | int key; | 
| 173 | < | interface_assign_type the_type =  the_event->evt.asmt.asmt_type; | 
| 174 | < | char* lhs = the_event->evt.asmt.lhs; | 
| 175 | < | std::string keyword(lhs); | 
| 170 | > | deprecatedKeywords_.insert("nComponents"); | 
| 171 | > | deprecatedKeywords_.insert("nZconstraints"); | 
| 172 | > | deprecatedKeywords_.insert("initialConfig"); | 
| 173 | > | deprecatedKeywords_.insert("thermIntDistSpringConst"); | 
| 174 | > | deprecatedKeywords_.insert("thermIntThetaSpringConst"); | 
| 175 | > | deprecatedKeywords_.insert("thermIntOmegaSpringConst"); | 
| 176 | > | deprecatedKeywords_.insert("useSolidThermInt"); | 
| 177 | > | deprecatedKeywords_.insert("useLiquidThermInt"); | 
| 178 | > | deprecatedKeywords_.insert("minimizerMaxIter"); | 
| 179 | > | deprecatedKeywords_.insert("minimizerWriteFreq"); | 
| 180 | > | deprecatedKeywords_.insert("minimizerStepSize"); | 
| 181 | > | deprecatedKeywords_.insert("minimizerFTol"); | 
| 182 | > | deprecatedKeywords_.insert("minimizerGTol"); | 
| 183 | > | deprecatedKeywords_.insert("minimizerLSTol"); | 
| 184 | > | deprecatedKeywords_.insert("minimizerLSMaxIter"); | 
| 185 |  |  | 
| 186 | < | bool result = false; | 
| 151 | < |  | 
| 152 | < | /**@todo fix memory leak */ | 
| 153 | < | ParamMap::iterator i =parameters_.find(keyword); | 
| 154 | < | if (i != parameters_.end()) { | 
| 155 | < | if( the_type == STRING ){ | 
| 156 | < | result = i->second->setData(std::string(the_event->evt.asmt.rhs.sval)); | 
| 157 | < | if (!result ) { | 
| 158 | < | sprintf(errorMessage, "Error in parsing %s: expect %s, but get a string \"%s\".\n", keyword.c_str(), i->second->getParamType().c_str(), the_event->evt.asmt.rhs.sval); | 
| 159 | < | the_event->err_msg = strdup(errorMessage); | 
| 160 | < | } | 
| 161 | < | } else if( the_type == DOUBLE ){ | 
| 162 | < | result = i->second->setData(the_event->evt.asmt.rhs.dval); | 
| 163 | < | if (!result ) | 
| 164 | < | sprintf(errorMessage, "Error in parsing %s: expect %s, but get a double %f.\n", keyword.c_str(), i->second->getParamType().c_str(), the_event->evt.asmt.rhs.dval ); | 
| 165 | < | the_event->err_msg = strdup(errorMessage); | 
| 166 | < | } | 
| 167 | < | else if (the_type == INT ){ | 
| 168 | < | result = i->second->setData(the_event->evt.asmt.rhs.ival); | 
| 169 | < | if (!result ) | 
| 170 | < | sprintf(errorMessage,  "Error in parsing %s: expect %s, but get an int %d.\n", keyword.c_str(), i->second->getParamType().c_str(), the_event->evt.asmt.rhs.ival ); | 
| 171 | < | the_event->err_msg = strdup(errorMessage); | 
| 172 | < |  | 
| 173 | < | } else { | 
| 174 | < | sprintf(errorMessage,  "Internal error of parser\n"); | 
| 175 | < | the_event->err_msg = strdup(errorMessage); | 
| 176 | < | } | 
| 177 | < | } else { | 
| 178 | < | sprintf(errorMessage,  "%s is an unrecognized keyword\n", keyword.c_str() ); | 
| 179 | < | the_event->err_msg = strdup(errorMessage); | 
| 186 | > |  | 
| 187 |  | } | 
| 188 |  |  | 
| 189 | < | if (keyword == "nComponents" && getNComponents() > 0) { | 
| 190 | < | components = new Component*[getNComponents()]; | 
| 191 | < | }else if (keyword == "nZconstraints" && getNZconstraints() > 0) { | 
| 192 | < | zConstraints = new ZconStamp*[getNZconstraints()]; | 
| 189 | > | Globals::~Globals() { | 
| 190 | > | MemoryUtils::deletePointers(components_); | 
| 191 | > | MemoryUtils::deletePointers(zconstraints_); | 
| 192 | > | MemoryUtils::deletePointers(restraints_); | 
| 193 | > | delete flucQpars_; | 
| 194 | > | delete rnemdPars_; | 
| 195 | > | delete minimizerPars_; | 
| 196 |  | } | 
| 187 | – |  | 
| 188 | – | return result; | 
| 189 | – | } | 
| 197 |  |  | 
| 198 | < | int Globals::newComponent( event* the_event ){ | 
| 199 | < |  | 
| 200 | < | current_component = new Component; | 
| 201 | < | int index = the_event->evt.blk_index; | 
| 202 | < | char err[200]; | 
| 203 | < |  | 
| 204 | < | if( haveNComponents() && index < getNComponents() ) | 
| 205 | < | components[index] = current_component; | 
| 206 | < | else{ | 
| 207 | < | if( haveNComponents()  ){ | 
| 208 | < | sprintf( err, "meta-data parsing error: %d out of nComponents range", | 
| 209 | < | index ); | 
| 210 | < | the_event->err_msg = strdup( err ); | 
| 211 | < | return 0; | 
| 212 | < | } | 
| 213 | < | else{ | 
| 214 | < | the_event->err_msg = strdup("meta-data parsing error: nComponents not given before" | 
| 215 | < | " first component declaration." ); | 
| 216 | < | return 0; | 
| 217 | < | } | 
| 218 | < | } | 
| 219 | < |  | 
| 220 | < | return 1; | 
| 221 | < | } | 
| 198 | > | void Globals::validate() { | 
| 199 | > | DataHolder::validate(); | 
| 200 | > |  | 
| 201 | > | CheckParameter(ForceField, isNotEmpty()); | 
| 202 | > | CheckParameter(TargetTemp, isPositive()); | 
| 203 | > | CheckParameter(Ensemble, isEqualIgnoreCase("NVE") || | 
| 204 | > | isEqualIgnoreCase("NVT") || isEqualIgnoreCase("NPTi") || | 
| 205 | > | isEqualIgnoreCase("NPTf") || isEqualIgnoreCase("NPTxyz") || | 
| 206 | > | isEqualIgnoreCase("NPTsz") || isEqualIgnoreCase("NPAT")  || | 
| 207 | > | isEqualIgnoreCase("NPA") || | 
| 208 | > | isEqualIgnoreCase("LANGEVINDYNAMICS") || | 
| 209 | > | isEqualIgnoreCase("LD") || isEqualIgnoreCase("NPRT") || | 
| 210 | > | isEqualIgnoreCase("NPGT") || isEqualIgnoreCase("NGammaT") || | 
| 211 | > | isEqualIgnoreCase("NGT") || | 
| 212 | > | isEqualIgnoreCase("LANGEVINHULL") || | 
| 213 | > | isEqualIgnoreCase("LHULL") || isEqualIgnoreCase("SMIPD")); | 
| 214 | > | CheckParameter(Dt, isPositive()); | 
| 215 | > | CheckParameter(RunTime, isPositive()); | 
| 216 | > | CheckParameter(FinalConfig, isNotEmpty()); | 
| 217 | > | CheckParameter(SampleTime, isNonNegative()); | 
| 218 | > | CheckParameter(ResetTime, isNonNegative()); | 
| 219 | > | CheckParameter(StatusTime, isNonNegative()); | 
| 220 | > | CheckParameter(CutoffRadius, isPositive()); | 
| 221 | > | CheckParameter(SwitchingRadius, isNonNegative()); | 
| 222 | > | CheckParameter(Dielectric, isPositive()); | 
| 223 | > | CheckParameter(ThermalTime,  isNonNegative()); | 
| 224 | > | CheckParameter(TauThermostat, isPositive()); | 
| 225 | > | CheckParameter(TauBarostat, isPositive()); | 
| 226 | > | CheckParameter(ZconsTime, isPositive()); | 
| 227 | > | CheckParameter(ZconsTol, isPositive()); | 
| 228 | > | CheckParameter(Seed, isPositive()); | 
| 229 | > | CheckParameter(ZconsGap, isPositive()); | 
| 230 | > | CheckParameter(ZconsFixtime, isPositive()); | 
| 231 | > | CheckParameter(ThermodynamicIntegrationLambda, isNonNegative()); | 
| 232 | > | CheckParameter(ThermodynamicIntegrationK, isPositive()); | 
| 233 | > | CheckParameter(ForceFieldVariant, isNotEmpty()); | 
| 234 | > | CheckParameter(ForceFieldFileName, isNotEmpty()); | 
| 235 | > | CheckParameter(CutoffMethod, isEqualIgnoreCase("HARD") || | 
| 236 | > | isEqualIgnoreCase("SWITCHED") || | 
| 237 | > | isEqualIgnoreCase("SHIFTED_POTENTIAL") || | 
| 238 | > | isEqualIgnoreCase("SHIFTED_FORCE") || | 
| 239 | > | isEqualIgnoreCase("TAYLOR_SHIFTED") || | 
| 240 | > | isEqualIgnoreCase("EWALD_FULL")); | 
| 241 | > | CheckParameter(CutoffPolicy, isEqualIgnoreCase("MIX") || | 
| 242 | > | isEqualIgnoreCase("MAX") || | 
| 243 | > | isEqualIgnoreCase("TRADITIONAL")); | 
| 244 | > | CheckParameter(ElectrostaticSummationMethod, isEqualIgnoreCase("NONE") || | 
| 245 | > | isEqualIgnoreCase("HARD") || isEqualIgnoreCase("SWITCHED") || | 
| 246 | > | isEqualIgnoreCase("SHIFTED_POTENTIAL") || | 
| 247 | > | isEqualIgnoreCase("SHIFTED_FORCE") || | 
| 248 | > | isEqualIgnoreCase("REACTION_FIELD") || | 
| 249 | > | isEqualIgnoreCase("TAYLOR_SHIFTED")); | 
| 250 | > | CheckParameter(ElectrostaticScreeningMethod, | 
| 251 | > | isEqualIgnoreCase("UNDAMPED") || isEqualIgnoreCase("DAMPED")); | 
| 252 | > | CheckParameter(SwitchingFunctionType, isEqualIgnoreCase("CUBIC") || | 
| 253 | > | isEqualIgnoreCase("FIFTH_ORDER_POLYNOMIAL")); | 
| 254 | > | CheckParameter(OrthoBoxTolerance, isPositive()); | 
| 255 | > | CheckParameter(DampingAlpha,isNonNegative()); | 
| 256 | > | CheckParameter(SkinThickness, isPositive()); | 
| 257 | > | CheckParameter(Viscosity, isNonNegative()); | 
| 258 | > | CheckParameter(BeadSize, isPositive()); | 
| 259 | > | CheckParameter(FrozenBufferRadius, isPositive()); | 
| 260 | > | CheckParameter(LangevinBufferRadius, isPositive()); | 
| 261 | > | CheckParameter(NeighborListNeighbors, isPositive()); | 
| 262 | > | CheckParameter(HULL_Method, isEqualIgnoreCase("Convex") || | 
| 263 | > | isEqualIgnoreCase("AlphaShape")); | 
| 264 | > | CheckParameter(Alpha, isPositive()); | 
| 265 | > |  | 
| 266 | > | for(std::vector<Component*>::iterator i = components_.begin(); | 
| 267 | > | i != components_.end(); ++i) { | 
| 268 | > | if (!(*i)->findMoleculeStamp(moleculeStamps_)) { | 
| 269 | > | std::ostringstream oss; | 
| 270 | > | oss << "Globals Error: can not find molecule stamp for component " | 
| 271 | > | << (*i)->getType() << std::endl; | 
| 272 | > | throw OpenMDException(oss.str()); | 
| 273 | > | } | 
| 274 | > | } | 
| 275 | > | } | 
| 276 | > |  | 
| 277 | > | bool Globals::addComponent(Component* comp) { | 
| 278 | > | components_.push_back(comp); | 
| 279 | > | return true; | 
| 280 | > | } | 
| 281 |  |  | 
| 282 | + | bool Globals::addZConsStamp(ZConsStamp* zcons) { | 
| 283 | + | zconstraints_.push_back(zcons); | 
| 284 | + | return true; | 
| 285 | + | } | 
| 286 |  |  | 
| 287 | + | bool Globals::addRestraintStamp(RestraintStamp* rest) { | 
| 288 | + | restraints_.push_back(rest); | 
| 289 | + | return true; | 
| 290 | + | } | 
| 291 |  |  | 
| 292 | < | int Globals::componentAssign( event* the_event ){ | 
| 292 | > | bool Globals::addFluctuatingChargeParameters(FluctuatingChargeParameters* fqp) { | 
| 293 | > | if (flucQpars_ != NULL) | 
| 294 | > | delete flucQpars_; | 
| 295 | > |  | 
| 296 | > | flucQpars_ = fqp; | 
| 297 | > | return true; | 
| 298 | > | } | 
| 299 |  |  | 
| 300 | < | switch( the_event->evt.asmt.asmt_type ){ | 
| 300 | > | bool Globals::addRNEMDParameters(RNEMDParameters* rnemdPars) { | 
| 301 | > | if (rnemdPars_ != NULL) | 
| 302 | > | delete rnemdPars_; | 
| 303 |  |  | 
| 304 | < | case STRING: | 
| 305 | < | return current_component->assignString( the_event->evt.asmt.lhs, | 
| 224 | < | the_event->evt.asmt.rhs.sval, | 
| 225 | < | &(the_event->err_msg)); | 
| 226 | < | break; | 
| 227 | < |  | 
| 228 | < | case DOUBLE: | 
| 229 | < | return current_component->assignDouble( the_event->evt.asmt.lhs, | 
| 230 | < | the_event->evt.asmt.rhs.dval, | 
| 231 | < | &(the_event->err_msg)); | 
| 232 | < | break; | 
| 233 | < |  | 
| 234 | < | case INT: | 
| 235 | < | return current_component->assignInt( the_event->evt.asmt.lhs, | 
| 236 | < | the_event->evt.asmt.rhs.ival, | 
| 237 | < | &(the_event->err_msg)); | 
| 238 | < | break; | 
| 239 | < |  | 
| 240 | < | default: | 
| 241 | < | the_event->err_msg = strdup( "Globals error. Invalid component" | 
| 242 | < | " assignment type" ); | 
| 243 | < | return 0; | 
| 244 | < | break; | 
| 304 | > | rnemdPars_ = rnemdPars; | 
| 305 | > | return true; | 
| 306 |  | } | 
| 246 | – | return 0; | 
| 247 | – | } | 
| 307 |  |  | 
| 308 | < | int Globals::componentEnd( event* the_event ){ | 
| 309 | < |  | 
| 310 | < | the_event->err_msg = current_component->checkMe(); | 
| 252 | < | if( the_event->err_msg != NULL ) return 0; | 
| 253 | < |  | 
| 254 | < | return 1; | 
| 255 | < | } | 
| 256 | < |  | 
| 257 | < | int Globals::newZconstraint( event* the_event ){ | 
| 258 | < |  | 
| 259 | < |  | 
| 260 | < | int index = the_event->evt.blk_index; | 
| 261 | < | char err[200]; | 
| 262 | < | current_zConstraint = new ZconStamp( index ); | 
| 263 | < |  | 
| 264 | < | if( haveNZconstraints() && index < getNZconstraints() ) | 
| 265 | < | zConstraints[index] = current_zConstraint; | 
| 266 | < | else{ | 
| 267 | < | if( haveNZconstraints() ){ | 
| 268 | < | sprintf( err, "meta-data parsing error: %d out of nZconstraints range", | 
| 269 | < | index ); | 
| 270 | < | the_event->err_msg = strdup( err ); | 
| 271 | < | return 0; | 
| 272 | < | } | 
| 273 | < | else{ | 
| 274 | < | the_event->err_msg = strdup("meta-data parsing error: nZconstraints" | 
| 275 | < | " not given before" | 
| 276 | < | " first zConstraint declaration." ); | 
| 277 | < | return 0; | 
| 278 | < | } | 
| 279 | < | } | 
| 280 | < |  | 
| 281 | < | return 1; | 
| 282 | < | } | 
| 283 | < |  | 
| 284 | < |  | 
| 285 | < |  | 
| 286 | < | int Globals::zConstraintAssign( event* the_event ){ | 
| 287 | < |  | 
| 288 | < | switch( the_event->evt.asmt.asmt_type ){ | 
| 308 | > | bool Globals::addMinimizerParameters(MinimizerParameters* miniPars) { | 
| 309 | > | if (minimizerPars_ != NULL) | 
| 310 | > | delete minimizerPars_; | 
| 311 |  |  | 
| 312 | < | case STRING: | 
| 313 | < | return current_zConstraint->assignString( the_event->evt.asmt.lhs, | 
| 292 | < | the_event->evt.asmt.rhs.sval, | 
| 293 | < | &(the_event->err_msg)); | 
| 294 | < | break; | 
| 295 | < |  | 
| 296 | < | case DOUBLE: | 
| 297 | < | return current_zConstraint->assignDouble( the_event->evt.asmt.lhs, | 
| 298 | < | the_event->evt.asmt.rhs.dval, | 
| 299 | < | &(the_event->err_msg)); | 
| 300 | < | break; | 
| 301 | < |  | 
| 302 | < | case INT: | 
| 303 | < | return current_zConstraint->assignInt( the_event->evt.asmt.lhs, | 
| 304 | < | the_event->evt.asmt.rhs.ival, | 
| 305 | < | &(the_event->err_msg)); | 
| 306 | < | break; | 
| 307 | < |  | 
| 308 | < | default: | 
| 309 | < | the_event->err_msg = strdup( "Globals error. Invalid zConstraint" | 
| 310 | < | " assignment type" ); | 
| 311 | < | return 0; | 
| 312 | < | break; | 
| 312 | > | minimizerPars_ = miniPars; | 
| 313 | > | return true; | 
| 314 |  | } | 
| 314 | – | return 0; | 
| 315 | – | } | 
| 315 |  |  | 
| 316 | < | int Globals::zConstraintEnd( event* the_event ){ | 
| 317 | < |  | 
| 318 | < | the_event->err_msg = current_zConstraint->checkMe(); | 
| 319 | < | if( the_event->err_msg != NULL ) return 0; | 
| 320 | < |  | 
| 321 | < | return 1; | 
| 322 | < | } | 
| 323 | < |  | 
| 324 | < | char* Globals::checkMe( void ){ | 
| 325 | < |  | 
| 326 | < |  | 
| 327 | < | std::string err("The following required keywords are missing:\n"); | 
| 328 | < | short int have_err = 0; | 
| 330 | < |  | 
| 331 | < | ParamMap::iterator i; | 
| 332 | < | for (i = parameters_.begin(); i != parameters_.end(); ++i) { | 
| 333 | < | if (!i->second->isOptional() && i->second->empty()) { | 
| 334 | < | err +=  i->second->getKeyword() + "\n"; | 
| 316 | > | bool Globals::addMoleculeStamp(MoleculeStamp* molStamp) { | 
| 317 | > | std::string molStampName = molStamp->getName(); | 
| 318 | > | std::map<std::string, MoleculeStamp*>::iterator i; | 
| 319 | > | bool ret = false; | 
| 320 | > | i = moleculeStamps_.find(molStampName); | 
| 321 | > | if (i == moleculeStamps_.end()) { | 
| 322 | > | moleculeStamps_.insert(std::map<std::string, MoleculeStamp*>::value_type(molStampName, molStamp)); | 
| 323 | > | ret = true; | 
| 324 | > | } else { | 
| 325 | > | std::ostringstream oss; | 
| 326 | > | oss << "Globals Error: Molecule Stamp " << molStamp->getName() | 
| 327 | > | << "appears multiple times\n"; | 
| 328 | > | throw OpenMDException(oss.str()); | 
| 329 |  | } | 
| 330 | + | return ret; | 
| 331 |  | } | 
| 337 | – |  | 
| 338 | – | CheckParameter(ForceField, isNotEmpty()); | 
| 339 | – | CheckParameter(NComponents,isPositive()); | 
| 340 | – | CheckParameter(TargetTemp, isPositive()); | 
| 341 | – | CheckParameter(Ensemble, isEqualIgnoreCase(std::string("NVE")) || isEqualIgnoreCase(std::string("NVT")) || | 
| 342 | – | isEqualIgnoreCase(std::string("NPTi")) || isEqualIgnoreCase(std::string("NPTf"))|| | 
| 343 | – | isEqualIgnoreCase(std::string("NPTxyz")) ); | 
| 344 | – |  | 
| 345 | – | CheckParameter(Dt, isPositive()); | 
| 346 | – | CheckParameter(RunTime, isPositive()); | 
| 347 | – | CheckParameter(InitialConfig, isNotEmpty()); | 
| 348 | – | CheckParameter(FinalConfig, isNotEmpty()); | 
| 349 | – | CheckParameter(NMol, isPositive()); | 
| 350 | – | CheckParameter(Density, isPositive()); | 
| 351 | – | CheckParameter(Box, isPositive()); | 
| 352 | – | CheckParameter(BoxX, isPositive()); | 
| 353 | – | CheckParameter(BoxY, isPositive()); | 
| 354 | – | CheckParameter(BoxZ, isPositive()); | 
| 355 | – | CheckParameter(SampleTime, isNonNegative()); | 
| 356 | – | CheckParameter(ResetTime, isNonNegative()); | 
| 357 | – | CheckParameter(StatusTime, isNonNegative()); | 
| 358 | – | CheckParameter(CutoffRadius, isPositive()); | 
| 359 | – | CheckParameter(SwitchingRadius, isNonNegative()); | 
| 360 | – | CheckParameter(Dielectric, isPositive()); | 
| 361 | – | CheckParameter(ThermalTime,  isNonNegative()); | 
| 362 | – | CheckParameter(TargetPressure,  isPositive()); | 
| 363 | – | CheckParameter(TauThermostat, isPositive()); | 
| 364 | – | CheckParameter(TauBarostat, isPositive()); | 
| 365 | – | CheckParameter(ZconsTime, isPositive()); | 
| 366 | – | CheckParameter(NZconstraints, isPositive()); | 
| 367 | – | CheckParameter(ZconsTol, isPositive()); | 
| 368 | – | //CheckParameter(ZconsForcePolicy,); | 
| 369 | – | CheckParameter(Seed, isPositive()); | 
| 370 | – | CheckParameter(Minimizer, isEqualIgnoreCase(std::string("SD")) || isEqualIgnoreCase(std::string("CG"))); | 
| 371 | – | CheckParameter(MinimizerMaxIter, isPositive()); | 
| 372 | – | CheckParameter(MinimizerWriteFrq, isPositive()); | 
| 373 | – | CheckParameter(MinimizerStepSize, isPositive()); | 
| 374 | – | CheckParameter(MinimizerFTol, isPositive()); | 
| 375 | – | CheckParameter(MinimizerGTol, isPositive()); | 
| 376 | – | CheckParameter(MinimizerLSTol, isPositive()); | 
| 377 | – | CheckParameter(MinimizerLSMaxIter, isPositive()); | 
| 378 | – | CheckParameter(ZconsGap, isPositive()); | 
| 379 | – | CheckParameter(ZconsFixtime, isPositive()); | 
| 380 | – | CheckParameter(ThermodynamicIntegrationLambda, isPositive()); | 
| 381 | – | CheckParameter(ThermodynamicIntegrationK, isPositive()); | 
| 382 | – | CheckParameter(ForceFieldVariant, isNotEmpty()); | 
| 383 | – | CheckParameter(ForceFieldFileName, isNotEmpty()); | 
| 384 | – | CheckParameter(ThermIntDistSpringConst, isPositive()); | 
| 385 | – | CheckParameter(ThermIntThetaSpringConst, isPositive()); | 
| 386 | – | CheckParameter(ThermIntOmegaSpringConst, isPositive()); | 
| 387 | – | CheckParameter(SurfaceTension, isPositive()); | 
| 388 | – | CheckParameter(ElectrostaticSummationMethod, isEqualIgnoreCase(std::string("NONE")) || isEqualIgnoreCase(std::string("UNDAMPED_WOLF")) || isEqualIgnoreCase(std::string("DAMPED_WOLF")) || isEqualIgnoreCase(std::string("REACTION_FIELD")) ); | 
| 389 | – | CheckParameter(CutoffPolicy, isEqualIgnoreCase(std::string("MIX")) || isEqualIgnoreCase(std::string("MAX")) || isEqualIgnoreCase(std::string("TRADITIONAL"))); | 
| 390 | – | //CheckParameter(StatFileFormat,); | 
| 391 | – | //CheckParameter(MixingRule,); | 
| 392 | – | CheckParameter(OrthoBoxTolerance, isPositive()); | 
| 393 | – | CheckParameter(ThermIntDistSpringConst, isPositive()); | 
| 394 | – | CheckParameter(ThermIntThetaSpringConst, isPositive()); | 
| 395 | – | CheckParameter(ThermIntOmegaSpringConst, isPositive()); | 
| 396 | – | CheckParameter(DampingAlpha,isPositive()); | 
| 397 | – | CheckParameter(SkinThickness, isPositive()); | 
| 398 | – |  | 
| 399 | – | //@todo memory leak | 
| 400 | – | if( have_err ) | 
| 401 | – | return strdup( err.c_str() ); | 
| 402 | – |  | 
| 403 | – | return NULL; | 
| 404 | – |  | 
| 405 | – |  | 
| 332 |  | } | 
| 407 | – |  | 
| 408 | – | int Globals::globalEnd( event* the_event ){ | 
| 409 | – |  | 
| 410 | – | the_event->err_msg = checkMe(); | 
| 411 | – | if( the_event->err_msg != NULL ) return 0; | 
| 412 | – |  | 
| 413 | – | return 1; | 
| 414 | – | } |