From aac8cbf732ad384cdd65563e3845620d24896cc4 Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Wed, 19 Jan 2022 10:51:10 -0500 Subject: [PATCH 1/4] Fix #405 Force RCutLow = 0 (with warning) for free energy calculations --- src/ConfigSetup.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/ConfigSetup.cpp b/src/ConfigSetup.cpp index 34ade259b..27ed1de72 100644 --- a/src/ConfigSetup.cpp +++ b/src/ConfigSetup.cpp @@ -607,7 +607,16 @@ void ConfigSetup::Init(const char *fileName, MultiSim const*const& multisim) printf("%-40s %-4.4f A\n", "Info: Cutoff", sys.ff.cutoff); } else if(CheckString(line[0], "RcutLow")) { sys.ff.cutoffLow = stringtod(line[1]); - printf("%-40s %-4.4f A\n", "Info: Short Range Cutoff", sys.ff.cutoffLow); + if (sys.ff.cutoffLow < 0.0) { + printf("Warning: Short Range Cutoff cannot be set to less than zero. Initializing to zero.\n"); + sys.ff.cutoffLow) = 0.0; + } else if (sys.ff.cutoffLow > 0.0 && sys.freeEn.enable) { + printf("Warning: Free energy calculations are being used when RcutLow is not zero (0),\n"); + printf(" which would produce incorrect free energy results.\n"); + printf(" Resetting RcutLow to zero (RcutLow=0) for free energy calculations!\n"); + sys.ff.cutoffLow = 0.0; + } + printf("%-40s %-4.4lf A\n", "Info: Short Range Cutoff", sys.ff.cutoffLow); } else if(CheckString(line[0], "Exclude")) { if(line[1] == sys.exclude.EXC_ONETWO) { sys.exclude.EXCLUDE_KIND = sys.exclude.EXC_ONETWO_KIND; @@ -720,7 +729,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const*const& multisim) sys.moves.displace); } else if(CheckString(line[0], "MultiParticleFreq")) { sys.moves.multiParticle = stringtod(line[1]); - if(sys.moves.multiParticle > 0.00) { + if(sys.moves.multiParticle > 0.0) { sys.moves.multiParticleEnabled = true; } printf("%-40s %-4.4f \n", @@ -728,7 +737,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const*const& multisim) sys.moves.multiParticle); } else if(CheckString(line[0], "MultiParticleBrownianFreq")) { sys.moves.multiParticleBrownian = stringtod(line[1]); - if(sys.moves.multiParticleBrownian > 0.00) { + if(sys.moves.multiParticleBrownian > 0.0) { sys.moves.multiParticleEnabled = true; } printf("%-40s %-4.4f \n", @@ -1086,6 +1095,12 @@ void ConfigSetup::Init(const char *fileName, MultiSim const*const& multisim) printf("%-40s %-4d \n", "Info: Free Energy Frequency", sys.freeEn.frequency); } + if (sys.ff.cutoffLow != 0.0 && sys.ff.cutoffLow != DBL_MAX) { + printf("Warning: Free energy calculations are being used when RcutLow is not zero,\n"); + printf(" which would produce incorrect free energy results.\n"); + printf(" Resetting RcutLow to zero (RcutLow=0.0) for free energy calculations!\n"); + sys.ff.cutoffLow = 0.0; + } } else { printf("%-40s %-s \n", "Info: Free Energy Calculation", "Inactive"); } @@ -1569,8 +1584,8 @@ void ConfigSetup::fillDefaults(void) } if(sys.ff.cutoffLow == DBL_MAX) { - sys.ff.cutoffLow = 0.00; - printf("%-40s %-4.4f \n", "Default: Short Range Cutoff", sys.ff.cutoffLow); + sys.ff.cutoffLow = 0.0; + printf("%-40s %-4.4lf \n", "Default: Short Range Cutoff", sys.ff.cutoffLow); } if(out.statistics.settings.block.enable && in.restart.recalcTrajectory) { From 68e8feeda45f82aa64582a9aceb60e40fce9d326 Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Wed, 19 Jan 2022 10:53:38 -0500 Subject: [PATCH 2/4] Fix #405 Correct typo in patch --- src/ConfigSetup.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConfigSetup.cpp b/src/ConfigSetup.cpp index 27ed1de72..b6cbaa833 100644 --- a/src/ConfigSetup.cpp +++ b/src/ConfigSetup.cpp @@ -609,7 +609,7 @@ void ConfigSetup::Init(const char *fileName, MultiSim const*const& multisim) sys.ff.cutoffLow = stringtod(line[1]); if (sys.ff.cutoffLow < 0.0) { printf("Warning: Short Range Cutoff cannot be set to less than zero. Initializing to zero.\n"); - sys.ff.cutoffLow) = 0.0; + sys.ff.cutoffLow = 0.0; } else if (sys.ff.cutoffLow > 0.0 && sys.freeEn.enable) { printf("Warning: Free energy calculations are being used when RcutLow is not zero (0),\n"); printf(" which would produce incorrect free energy results.\n"); From be3a380eeecaa09e61f62e09ec404112dc63de94 Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Wed, 19 Jan 2022 11:51:19 -0500 Subject: [PATCH 3/4] Fix #405 Move check to verifyInputs --- src/ConfigSetup.cpp | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/ConfigSetup.cpp b/src/ConfigSetup.cpp index b6cbaa833..ef1d4bf3e 100644 --- a/src/ConfigSetup.cpp +++ b/src/ConfigSetup.cpp @@ -607,15 +607,6 @@ void ConfigSetup::Init(const char *fileName, MultiSim const*const& multisim) printf("%-40s %-4.4f A\n", "Info: Cutoff", sys.ff.cutoff); } else if(CheckString(line[0], "RcutLow")) { sys.ff.cutoffLow = stringtod(line[1]); - if (sys.ff.cutoffLow < 0.0) { - printf("Warning: Short Range Cutoff cannot be set to less than zero. Initializing to zero.\n"); - sys.ff.cutoffLow = 0.0; - } else if (sys.ff.cutoffLow > 0.0 && sys.freeEn.enable) { - printf("Warning: Free energy calculations are being used when RcutLow is not zero (0),\n"); - printf(" which would produce incorrect free energy results.\n"); - printf(" Resetting RcutLow to zero (RcutLow=0) for free energy calculations!\n"); - sys.ff.cutoffLow = 0.0; - } printf("%-40s %-4.4lf A\n", "Info: Short Range Cutoff", sys.ff.cutoffLow); } else if(CheckString(line[0], "Exclude")) { if(line[1] == sys.exclude.EXC_ONETWO) { @@ -1095,12 +1086,6 @@ void ConfigSetup::Init(const char *fileName, MultiSim const*const& multisim) printf("%-40s %-4d \n", "Info: Free Energy Frequency", sys.freeEn.frequency); } - if (sys.ff.cutoffLow != 0.0 && sys.ff.cutoffLow != DBL_MAX) { - printf("Warning: Free energy calculations are being used when RcutLow is not zero,\n"); - printf(" which would produce incorrect free energy results.\n"); - printf(" Resetting RcutLow to zero (RcutLow=0.0) for free energy calculations!\n"); - sys.ff.cutoffLow = 0.0; - } } else { printf("%-40s %-s \n", "Info: Free Energy Calculation", "Inactive"); } @@ -1338,26 +1323,26 @@ void ConfigSetup::fillDefaults(void) } if(sys.moves.rotate == DBL_MAX) { - sys.moves.rotate = 0.000; + sys.moves.rotate = 0.0; printf("%-40s %-4.4f \n", "Default: Rotation move frequency", sys.moves.rotate); } if(sys.moves.intraSwap == DBL_MAX) { - sys.moves.intraSwap = 0.000; + sys.moves.intraSwap = 0.0; printf("%-40s %-4.4f \n", "Default: Intra-Swap move frequency", sys.moves.intraSwap); } if(sys.moves.multiParticle == DBL_MAX) { - sys.moves.multiParticle = 0.000; + sys.moves.multiParticle = 0.0; printf("%-40s %-4.4f \n", "Default: Multi-Particle move frequency", sys.moves.multiParticle); } if(sys.moves.multiParticleBrownian == DBL_MAX) { - sys.moves.multiParticleBrownian = 0.000; + sys.moves.multiParticleBrownian = 0.0; printf("%-40s %-4.4f \n", "Default: Multi-Particle Brownian move frequency", sys.moves.multiParticleBrownian); @@ -1370,13 +1355,13 @@ void ConfigSetup::fillDefaults(void) } if(sys.moves.regrowth == DBL_MAX) { - sys.moves.regrowth = 0.000; + sys.moves.regrowth = 0.0; printf("%-40s %-4.4f \n", "Default: Regrowth move frequency", sys.moves.regrowth); } if(sys.moves.crankShaft == DBL_MAX) { - sys.moves.crankShaft = 0.000; + sys.moves.crankShaft = 0.0; printf("%-40s %-4.4f \n", "Default: Crank-Shaft move frequency", sys.moves.crankShaft); } @@ -1587,7 +1572,7 @@ void ConfigSetup::fillDefaults(void) sys.ff.cutoffLow = 0.0; printf("%-40s %-4.4lf \n", "Default: Short Range Cutoff", sys.ff.cutoffLow); } - + if(out.statistics.settings.block.enable && in.restart.recalcTrajectory) { out.statistics.settings.block.enable = false; printf("%-40s \n", "Warning: Average output is activated but it will be ignored."); @@ -2180,6 +2165,13 @@ void ConfigSetup::verifyInputs(void) #endif #if ENSEMBLE == NVT || ENSEMBLE == NPT if(sys.freeEn.enable) { + if(sys.ff.cutoffLow > 0.0) { + sys.ff.cutoffLow = 0.0; + printf("Warning: Free energy calculations are being used when RcutLow is not zero (0),\n"); + printf(" which would produce incorrect free energy results.\n"); + printf(" Resetting RcutLow to zero (RcutLow=0) for free energy calculations!\n"); + } + if(!sys.freeEn.readLambdaCoulomb) { std::cout << "Error: Lambda Coulomb states were not defined for " << "Free Energy Calculation! \n"; From 2731215fad361dfc35fc084be020639aa00a1ca5 Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Wed, 19 Jan 2022 12:10:54 -0500 Subject: [PATCH 4/4] Fix #405 Check that RCut and RCutLow are not negative --- src/ConfigSetup.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ConfigSetup.cpp b/src/ConfigSetup.cpp index ef1d4bf3e..51a528c22 100644 --- a/src/ConfigSetup.cpp +++ b/src/ConfigSetup.cpp @@ -1746,7 +1746,14 @@ void ConfigSetup::verifyInputs(void) std::cout << "Error: Cutoff is not specified!" << std::endl; exit(EXIT_FAILURE); } - + if(sys.ff.cutoff < 0.0) { + std::cout << "Error: Cutoff cannot be negative!" << std::endl; + exit(EXIT_FAILURE); + } + if(sys.ff.cutoffLow < 0.0) { + sys.ff.cutoffLow = 0.0; + printf("Warning: Short Range Cutoff cannot be negative. Initializing to zero.\n"); + } if(sys.elect.ewald && (sys.elect.tolerance == DBL_MAX)) { std::cout << "Error: Tolerance is not specified!" << std::endl; exit(EXIT_FAILURE);