Changed enums to enum classes.
Use EnumerationArray for strings.
for (int d = 0; d < awhBiasParams.ndim; d++)
{
const AwhDimParams& awhDimParams = awhBiasParams.dimParams[d];
- if (awhDimParams.eCoordProvider == eawhcoordproviderPULL)
+ if (awhDimParams.eCoordProvider == AwhCoordinateProviderType::Pull)
{
return true;
}
for (int d = 0; d < awhBiasParams.ndim; d++)
{
const AwhDimParams& awhDimParams = awhBiasParams.dimParams[d];
- if (awhDimParams.eCoordProvider != eawhcoordproviderPULL
- && awhDimParams.eCoordProvider != eawhcoordproviderFREE_ENERGY_LAMBDA)
+ if (awhDimParams.eCoordProvider != AwhCoordinateProviderType::Pull
+ && awhDimParams.eCoordProvider != AwhCoordinateProviderType::FreeEnergyLambda)
{
GMX_THROW(
InvalidInputError("Currently only the pull code and lambda are supported "
"as coordinate providers"));
}
- if (awhDimParams.eCoordProvider == eawhcoordproviderPULL)
+ if (awhDimParams.eCoordProvider == AwhCoordinateProviderType::Pull)
{
const t_pull_coord& pullCoord = inputRecord.pull->coord[awhDimParams.coordIndex];
if (pullCoord.eGeom == PullGroupGeometry::DirectionPBC)
for (int d = 0; d < biasParams.ndim; d++)
{
- if (biasParams.dimParams[d].eCoordProvider == eawhcoordproviderPULL)
+ if (biasParams.dimParams[d].eCoordProvider == AwhCoordinateProviderType::Pull)
{
register_external_pull_potential(
pull_work, biasParams.dimParams[d].coordIndex, Awh::externalPotentialString());
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
{
double origin = dimParams[d].scaleUserInputToInternal(awhDimParams[d].origin);
double end = dimParams[d].scaleUserInputToInternal(awhDimParams[d].end);
- if (awhDimParams[d].eCoordProvider == eawhcoordproviderPULL)
+ if (awhDimParams[d].eCoordProvider == AwhCoordinateProviderType::Pull)
{
period[d] = dimParams[d].scaleUserInputToInternal(awhDimParams[d].period);
static_assert(
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
*/
switch (awhBiasParams.eTarget)
{
- case eawhtargetCONSTANT: numStepsUpdateTarget = 0; break;
- case eawhtargetCUTOFF:
- case eawhtargetBOLTZMANN:
+ case AwhTargetType::Constant: numStepsUpdateTarget = 0; break;
+ case AwhTargetType::Cutoff:
+ case AwhTargetType::Boltzmann:
/* Updating the target generally requires updating the whole grid so to keep the cost
down we generally update the target less often than the free energy (unless the free
energy update step is set to > 100 samples). */
awhParams.numSamplesUpdateFreeEnergy)
* awhParams.nstSampleCoord;
break;
- case eawhtargetLOCALBOLTZMANN:
+ case AwhTargetType::LocalBoltzmann:
/* The target distribution is set equal to the reference histogram which is updated every free energy update.
So the target has to be updated at the same time. This leads to a global update each time because it is
assumed that a target distribution update can take any form. This is a bit unfortunate for a "local"
eTarget(awhBiasParams.eTarget),
freeEnergyCutoffInKT(beta * awhBiasParams.targetCutoff),
temperatureScaleFactor(awhBiasParams.targetBetaScaling),
- idealWeighthistUpdate(eTarget != eawhtargetLOCALBOLTZMANN),
+ idealWeighthistUpdate(eTarget != AwhTargetType::LocalBoltzmann),
numSharedUpdate(getNumSharedUpdate(awhBiasParams, numSharingSimulations)),
updateWeight(numSamplesUpdateFreeEnergy_ * numSharedUpdate),
- localWeightScaling(eTarget == eawhtargetLOCALBOLTZMANN ? temperatureScaleFactor : 1),
+ localWeightScaling(eTarget == AwhTargetType::LocalBoltzmann ? temperatureScaleFactor : 1),
initialErrorInKT(beta * awhBiasParams.errorInitial),
initialHistogramSize(
getInitialHistogramSizeEstimate(awhBiasParams, gridAxis, beta, numStepsSampleCoord_ * mdTimeStep)),
- convolveForce(awhParams.ePotential == eawhpotentialCONVOLVED),
+ convolveForce(awhParams.ePotential == AwhPotentialType::Convolved),
biasIndex(biasIndex),
disableUpdateSkips_(disableUpdateSkips == DisableUpdateSkips::yes)
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
struct AwhParams;
struct DimParams;
class GridAxis;
+enum class AwhTargetType : int;
/*! \internal \brief Constant parameters for the bias.
*/
const int64_t numStepsUpdateTarget_; /**< Number of steps per updating the target distribution. */
const int64_t numStepsCheckCovering_; /**< Number of steps per checking for covering. */
public:
- const int eTarget; /**< Type of target distribution. */
- const double freeEnergyCutoffInKT; /**< Free energy cut-off in kT for cut-off target distribution. */
- const double temperatureScaleFactor; /**< Temperature scaling factor for temperature scaled targed distributions. */
- const bool idealWeighthistUpdate; /**< Update reference weighthistogram using the target distribution? Otherwise use the realized distribution. */
+ const AwhTargetType eTarget; /**< Type of target distribution. */
+ const double freeEnergyCutoffInKT; /**< Free energy cut-off in kT for cut-off target distribution. */
+ const double temperatureScaleFactor; /**< Temperature scaling factor for temperature scaled targed distributions. */
+ const bool idealWeighthistUpdate; /**< Update reference weighthistogram using the target distribution? Otherwise use the realized distribution. */
const int numSharedUpdate; /**< The number of (multi-)simulations sharing the bias update */
const double updateWeight; /**< The probability weight accumulated for each update. */
const double localWeightScaling; /**< Scaling factor applied to a sample before adding it to the reference weight histogram (= 1, usually). */
void updateTargetDistribution(gmx::ArrayRef<PointState> pointState, const BiasParams& params)
{
double freeEnergyCutoff = 0;
- if (params.eTarget == eawhtargetCUTOFF)
+ if (params.eTarget == AwhTargetType::Cutoff)
{
freeEnergyCutoff = freeEnergyMinimumValue(pointState) + params.freeEnergyCutoffInKT;
}
/* Set the free energy cutoff */
double maxFreeEnergy = GMX_FLOAT_MAX;
- if (params.eTarget == eawhtargetCUTOFF)
+ if (params.eTarget == AwhTargetType::Cutoff)
{
maxFreeEnergy = freeEnergyMinimumValue(points_) + params.freeEnergyCutoffInKT;
}
/* Update target distribution? */
bool needToUpdateTargetDistribution =
- (params.eTarget != eawhtargetCONSTANT && params.isUpdateTargetStep(step));
+ (params.eTarget != AwhTargetType::Constant && params.isUpdateTargetStep(step));
/* In the initial stage, the histogram grows dynamically as a function of the number of coverings. */
bool detectedCovering = false;
}
/* The local Boltzmann distribution is special because the target distribution is updated as a function of the reference weighthistogram. */
- GMX_RELEASE_ASSERT(params.eTarget != eawhtargetLOCALBOLTZMANN || points_[0].weightSumRef() != 0,
+ GMX_RELEASE_ASSERT(params.eTarget != AwhTargetType::LocalBoltzmann || points_[0].weightSumRef() != 0,
"AWH reference weight histogram not initialized properly with local "
"Boltzmann target distribution.");
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
HistogramSize::HistogramSize(const AwhBiasParams& awhBiasParams, double histogramSizeInitial) :
numUpdates_(0),
histogramSize_(histogramSizeInitial),
- inInitialStage_(awhBiasParams.eGrowth == eawhgrowthEXP_LINEAR),
+ inInitialStage_(awhBiasParams.eGrowth == AwhHistogramGrowthType::ExponentialLinear),
equilibrateHistogram_(awhBiasParams.equilibrateHistogram),
logScaledSampleWeight_(0),
maxLogScaledSampleWeight_(0),
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
{
switch (params.eTarget)
{
- case eawhtargetCONSTANT: target_ = 1; break;
- case eawhtargetCUTOFF:
+ case AwhTargetType::Constant: target_ = 1; break;
+ case AwhTargetType::Cutoff:
{
double df = freeEnergy_ - freeEnergyCutoff;
target_ = 1 / (1 + std::exp(df));
break;
}
- case eawhtargetBOLTZMANN:
+ case AwhTargetType::Boltzmann:
target_ = std::exp(-params.temperatureScaleFactor * freeEnergy_);
break;
- case eawhtargetLOCALBOLTZMANN: target_ = weightSumRef_; break;
+ case AwhTargetType::LocalBoltzmann: target_ = weightSumRef_; break;
+ default: GMX_RELEASE_ASSERT(false, "Unhandled enum");
}
/* All target types can be modulated by a constant factor. */
#include "gromacs/random/seed.h"
#include "gromacs/topology/mtop_util.h"
#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/enumerationhelpers.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
namespace gmx
{
-const char* eawhtarget_names[eawhtargetNR + 1] = { "constant",
- "cutoff",
- "boltzmann",
- "local-boltzmann",
- nullptr };
+const char* enumValueToString(AwhTargetType enumValue)
+{
+ constexpr gmx::EnumerationArray<AwhTargetType, const char*> awhTargetTypeNames = {
+ "constant", "cutoff", "boltzmann", "local-boltzmann"
+ };
+ return awhTargetTypeNames[enumValue];
+}
-const char* eawhgrowth_names[eawhgrowthNR + 1] = { "exp-linear", "linear", nullptr };
+const char* enumValueToString(AwhHistogramGrowthType enumValue)
+{
+ constexpr gmx::EnumerationArray<AwhHistogramGrowthType, const char*> awhHistogramGrowthTypeNames = {
+ "exp-linear", "linear"
+ };
+ return awhHistogramGrowthTypeNames[enumValue];
+}
-const char* eawhpotential_names[eawhpotentialNR + 1] = { "convolved", "umbrella", nullptr };
+const char* enumValueToString(AwhPotentialType enumValue)
+{
+ constexpr gmx::EnumerationArray<AwhPotentialType, const char*> awhPotentialTypeNames = {
+ "convolved", "umbrella"
+ };
+ return awhPotentialTypeNames[enumValue];
+}
-const char* eawhcoordprovider_names[eawhcoordproviderNR + 1] = { "pull", "fep-lambda", nullptr };
+const char* enumValueToString(AwhCoordinateProviderType enumValue)
+{
+ constexpr gmx::EnumerationArray<AwhCoordinateProviderType, const char*> awhCoordinateProviderTypeNames = {
+ "pull", "fep-lambda"
+ };
+ return awhCoordinateProviderTypeNames[enumValue];
+}
namespace
{
{
switch (biasParams.dimParams[d].eCoordProvider)
{
- case eawhcoordproviderPULL: usesPull = true; break;
- case eawhcoordproviderFREE_ENERGY_LAMBDA: usesFep = true; break;
+ case AwhCoordinateProviderType::Pull: usesPull = true; break;
+ case AwhCoordinateProviderType::FreeEnergyLambda: usesFep = true; break;
default: GMX_RELEASE_ASSERT(false, "Unsupported coord provider");
}
}
"currently only 'pull' and 'fep-lambda' (free energy lambda state) is supported");
}
opt = prefix + "-coord-provider";
- dimParams->eCoordProvider = get_eeenum(inp, opt, eawhcoordprovider_names, wi);
+ dimParams->eCoordProvider = getEnum<AwhCoordinateProviderType>(inp, opt.c_str(), wi);
if (bComment)
{
*/
void checkDimParams(const std::string& prefix, AwhDimParams* dimParams, const t_inputrec* ir, warninp_t wi)
{
- if (dimParams->eCoordProvider == eawhcoordproviderPULL)
+ if (dimParams->eCoordProvider == AwhCoordinateProviderType::Pull)
{
if (!ir->bPull)
{
}
checkPullDimParams(prefix, dimParams, *ir->pull, wi);
}
- else if (dimParams->eCoordProvider == eawhcoordproviderFREE_ENERGY_LAMBDA)
+ else if (dimParams->eCoordProvider == AwhCoordinateProviderType::FreeEnergyLambda)
{
if (ir->efep == FreeEnergyPerturbationType::No)
{
"size: exp-linear or linear");
}
opt = prefix + "-growth";
- awhBiasParams->eGrowth = get_eeenum(inp, opt, eawhgrowth_names, wi);
+ awhBiasParams->eGrowth = getEnum<AwhHistogramGrowthType>(inp, opt.c_str(), wi);
if (bComment)
{
inp, "Target distribution type: constant, cutoff, boltzmann or local-boltzmann");
}
opt = prefix + "-target";
- awhBiasParams->eTarget = get_eeenum(inp, opt, eawhtarget_names, wi);
+ awhBiasParams->eTarget = getEnum<AwhTargetType>(inp, opt.c_str(), wi);
if (bComment)
{
}
opt = prefix + "-equilibrate-histogram";
- if (awhBiasParams->equilibrateHistogram && awhBiasParams->eGrowth != eawhgrowthEXP_LINEAR)
+ if (awhBiasParams->equilibrateHistogram && awhBiasParams->eGrowth != AwhHistogramGrowthType::ExponentialLinear)
{
auto message =
formatString("Option %s will only have an effect for histogram growth type '%s'.",
opt.c_str(),
- EAWHGROWTH(eawhgrowthEXP_LINEAR));
+ enumValueToString(AwhHistogramGrowthType::ExponentialLinear));
warning(wi, message);
}
- if ((awhBiasParams->eTarget == eawhtargetLOCALBOLTZMANN)
- && (awhBiasParams->eGrowth == eawhgrowthEXP_LINEAR))
+ if ((awhBiasParams->eTarget == AwhTargetType::LocalBoltzmann)
+ && (awhBiasParams->eGrowth == AwhHistogramGrowthType::ExponentialLinear))
{
auto message = formatString(
"Target type '%s' combined with histogram growth type '%s' is not "
"expected to give stable bias updates. You probably want to use growth type "
"'%s' instead.",
- EAWHTARGET(eawhtargetLOCALBOLTZMANN),
- EAWHGROWTH(eawhgrowthEXP_LINEAR),
- EAWHGROWTH(eawhgrowthLINEAR));
+ enumValueToString(AwhTargetType::LocalBoltzmann),
+ enumValueToString(AwhHistogramGrowthType::ExponentialLinear),
+ enumValueToString(AwhHistogramGrowthType::Linear));
warning(wi, message);
}
opt = prefix + "-target-beta-scaling";
switch (awhBiasParams->eTarget)
{
- case eawhtargetBOLTZMANN:
- case eawhtargetLOCALBOLTZMANN:
+ case AwhTargetType::Boltzmann:
+ case AwhTargetType::LocalBoltzmann:
if (awhBiasParams->targetBetaScaling < 0 || awhBiasParams->targetBetaScaling > 1)
{
gmx_fatal(FARGS,
"%s = %g is not useful for target type %s.",
opt.c_str(),
awhBiasParams->targetBetaScaling,
- EAWHTARGET(awhBiasParams->eTarget));
+ enumValueToString(awhBiasParams->eTarget));
}
break;
default:
"Value for %s (%g) set explicitly but will not be used for target type %s.",
opt.c_str(),
awhBiasParams->targetBetaScaling,
- EAWHTARGET(awhBiasParams->eTarget));
+ enumValueToString(awhBiasParams->eTarget));
}
break;
}
opt = prefix + "-target-cutoff";
switch (awhBiasParams->eTarget)
{
- case eawhtargetCUTOFF:
+ case AwhTargetType::Cutoff:
if (awhBiasParams->targetCutoff <= 0)
{
gmx_fatal(FARGS,
"%s = %g is not useful for target type %s.",
opt.c_str(),
awhBiasParams->targetCutoff,
- EAWHTARGET(awhBiasParams->eTarget));
+ enumValueToString(awhBiasParams->eTarget));
}
break;
default:
"Value for %s (%g) set explicitly but will not be used for target type %s.",
opt.c_str(),
awhBiasParams->targetCutoff,
- EAWHTARGET(awhBiasParams->eTarget));
+ enumValueToString(awhBiasParams->eTarget));
}
break;
}
{
for (int d1 = 0; d1 < awhBiasParams1.ndim; d1++)
{
- if (awhBiasParams1.dimParams[d1].eCoordProvider == eawhcoordproviderFREE_ENERGY_LAMBDA)
+ if (awhBiasParams1.dimParams[d1].eCoordProvider == AwhCoordinateProviderType::FreeEnergyLambda)
{
continue;
}
/* d1 is the reference dimension of the reference AWH. d2 is the dim index of the AWH to compare with. */
for (int d2 = 0; d2 < awhBiasParams2.ndim; d2++)
{
- if (awhBiasParams2.dimParams[d2].eCoordProvider == eawhcoordproviderFREE_ENERGY_LAMBDA)
+ if (awhBiasParams2.dimParams[d2].eCoordProvider == AwhCoordinateProviderType::FreeEnergyLambda)
{
continue;
}
printStringNoNewline(inp, "The way to apply the biasing potential: convolved or umbrella");
opt = "awh-potential";
- awhParams->ePotential = get_eeenum(inp, opt, eawhpotential_names, wi);
+ awhParams->ePotential = getEnum<AwhPotentialType>(inp, opt.c_str(), wi);
printStringNoNewline(inp,
"The random seed used for sampling the umbrella center in the case of "
for (int d = 0; d < awhBiasParams->ndim; d++)
{
AwhDimParams* dimParams = &awhBiasParams->dimParams[d];
- if (dimParams->eCoordProvider == eawhcoordproviderPULL)
+ if (dimParams->eCoordProvider == AwhCoordinateProviderType::Pull)
{
setStateDependentAwhPullDimParams(
dimParams, k, d, &pull_params, pull_work, pbc, compressibility, wi);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
};
//! Helper function to set up the C-style AWH parameters for the test
-static AwhTestParameters getAwhTestParameters(int eawhgrowth, int eawhpotential)
+static AwhTestParameters getAwhTestParameters(AwhHistogramGrowthType eawhgrowth, AwhPotentialType eawhpotential)
{
AwhTestParameters params;
awhDimParams.end = 1.5;
awhDimParams.coordValueInit = awhDimParams.origin;
awhDimParams.coverDiameter = 0;
- awhDimParams.eCoordProvider = eawhcoordproviderPULL;
+ awhDimParams.eCoordProvider = AwhCoordinateProviderType::Pull;
AwhBiasParams& awhBiasParams = params.awhBiasParams;
awhBiasParams.ndim = 1;
awhBiasParams.dimParams = &awhDimParams;
- awhBiasParams.eTarget = eawhtargetCONSTANT;
+ awhBiasParams.eTarget = AwhTargetType::Constant;
awhBiasParams.targetBetaScaling = 0;
awhBiasParams.targetCutoff = 0;
awhBiasParams.eGrowth = eawhgrowth;
0.86, 0.88, 0.79, 0.75, 0.82, 0.74, 0.70, 0.68, 0.71, 0.73 };
//! Convenience typedef: growth type enum, potential type enum, disable update skips
-typedef std::tuple<int, int, BiasParams::DisableUpdateSkips> BiasTestParameters;
+typedef std::tuple<AwhHistogramGrowthType, AwhPotentialType, BiasParams::DisableUpdateSkips> BiasTestParameters;
/*! \brief Test fixture for testing Bias updates
*/
* and disableUpdateSkips do not affect the point state.
* But the reference data will also ensure this.
*/
- int eawhgrowth;
- int eawhpotential;
+ AwhHistogramGrowthType eawhgrowth;
+ AwhPotentialType eawhpotential;
BiasParams::DisableUpdateSkips disableUpdateSkips;
std::tie(eawhgrowth, eawhpotential, disableUpdateSkips) = GetParam();
*/
INSTANTIATE_TEST_CASE_P(WithParameters,
BiasTest,
- ::testing::Combine(::testing::Values(eawhgrowthLINEAR, eawhgrowthEXP_LINEAR),
- ::testing::Values(eawhpotentialUMBRELLA, eawhpotentialCONVOLVED),
+ ::testing::Combine(::testing::Values(AwhHistogramGrowthType::Linear,
+ AwhHistogramGrowthType::ExponentialLinear),
+ ::testing::Values(AwhPotentialType::Umbrella,
+ AwhPotentialType::Convolved),
::testing::Values(BiasParams::DisableUpdateSkips::yes,
BiasParams::DisableUpdateSkips::no)));
// Test that we detect coverings and exit the initial stage at the correct step
TEST(BiasTest, DetectsCovering)
{
- const AwhTestParameters params = getAwhTestParameters(eawhgrowthEXP_LINEAR, eawhpotentialCONVOLVED);
+ const AwhTestParameters params = getAwhTestParameters(AwhHistogramGrowthType::ExponentialLinear,
+ AwhPotentialType::Convolved);
const AwhDimParams& awhDimParams = params.awhParams.awhBiasParams[0].dimParams[0];
const double mdTimeStep = 0.1;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
};
//! Helper function to set up the C-style AWH parameters for the test
-static AwhFepLambdaStateTestParameters getAwhFepLambdaTestParameters(int eawhgrowth, int eawhpotential)
+static AwhFepLambdaStateTestParameters getAwhFepLambdaTestParameters(AwhHistogramGrowthType eawhgrowth,
+ AwhPotentialType eawhpotential)
{
AwhFepLambdaStateTestParameters params;
awhDimParams.end = numLambdaStates - 1;
awhDimParams.coordValueInit = awhDimParams.origin;
awhDimParams.coverDiameter = 0;
- awhDimParams.eCoordProvider = eawhcoordproviderFREE_ENERGY_LAMBDA;
+ awhDimParams.eCoordProvider = AwhCoordinateProviderType::FreeEnergyLambda;
AwhBiasParams& awhBiasParams = params.awhBiasParams;
awhBiasParams.ndim = 1;
awhBiasParams.dimParams = &awhDimParams;
- awhBiasParams.eTarget = eawhtargetCONSTANT;
+ awhBiasParams.eTarget = AwhTargetType::Constant;
awhBiasParams.targetBetaScaling = 0;
awhBiasParams.targetCutoff = 0;
awhBiasParams.eGrowth = eawhgrowth;
}
//! Convenience typedef: growth type enum, potential type enum, disable update skips
-typedef std::tuple<int, int, BiasParams::DisableUpdateSkips> BiasTestParameters;
+typedef std::tuple<AwhHistogramGrowthType, AwhPotentialType, BiasParams::DisableUpdateSkips> BiasTestParameters;
/*! \brief Test fixture for testing Bias updates
*/
* and disableUpdateSkips do not affect the point state.
* But the reference data will also ensure this.
*/
- int eawhgrowth;
- int eawhpotential;
+ AwhHistogramGrowthType eawhgrowth;
+ AwhPotentialType eawhpotential;
BiasParams::DisableUpdateSkips disableUpdateSkips;
std::tie(eawhgrowth, eawhpotential, disableUpdateSkips) = GetParam();
*/
INSTANTIATE_TEST_CASE_P(WithParameters,
BiasFepLambdaStateTest,
- ::testing::Combine(::testing::Values(eawhgrowthLINEAR, eawhgrowthEXP_LINEAR),
- ::testing::Values(eawhpotentialUMBRELLA, eawhpotentialCONVOLVED),
+ ::testing::Combine(::testing::Values(AwhHistogramGrowthType::Linear,
+ AwhHistogramGrowthType::ExponentialLinear),
+ ::testing::Values(AwhPotentialType::Umbrella,
+ AwhPotentialType::Convolved),
::testing::Values(BiasParams::DisableUpdateSkips::yes,
BiasParams::DisableUpdateSkips::no)));
// Test that we detect coverings and exit the initial stage at the correct step
TEST(BiasFepLambdaStateTest, DetectsCovering)
{
- const AwhFepLambdaStateTestParameters params =
- getAwhFepLambdaTestParameters(eawhgrowthEXP_LINEAR, eawhpotentialCONVOLVED);
+ const AwhFepLambdaStateTestParameters params = getAwhFepLambdaTestParameters(
+ AwhHistogramGrowthType::ExponentialLinear, AwhPotentialType::Convolved);
const double mdTimeStep = 0.1;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
awhDimParams0.end = 1.5;
awhDimParams0.coordValueInit = awhDimParams0.origin;
awhDimParams0.coverDiameter = 0;
- awhDimParams0.eCoordProvider = eawhcoordproviderPULL;
+ awhDimParams0.eCoordProvider = AwhCoordinateProviderType::Pull;
AwhDimParams& awhDimParams1 = awhBiasParams.dimParams[1];
awhDimParams1.end = 1.3;
awhDimParams1.coordValueInit = awhDimParams1.origin;
awhDimParams1.coverDiameter = 0;
- awhDimParams1.eCoordProvider = eawhcoordproviderPULL;
+ awhDimParams1.eCoordProvider = AwhCoordinateProviderType::Pull;
awhBiasParams.ndim = 2;
- awhBiasParams.eTarget = eawhtargetCONSTANT;
+ awhBiasParams.eTarget = AwhTargetType::Constant;
awhBiasParams.targetBetaScaling = 0;
awhBiasParams.targetCutoff = 0;
- awhBiasParams.eGrowth = eawhgrowthLINEAR;
+ awhBiasParams.eGrowth = AwhHistogramGrowthType::Linear;
awhBiasParams.bUserData = TRUE;
awhBiasParams.errorInitial = 0.5;
awhBiasParams.shareGroup = 0;
awhParams.nstOut = 0;
awhParams.nstSampleCoord = 1;
awhParams.numSamplesUpdateFreeEnergy = 10;
- awhParams.ePotential = eawhpotentialCONVOLVED;
+ awhParams.ePotential = AwhPotentialType::Convolved;
awhParams.shareBiasMultisim = FALSE;
return params;
static void do_awhBias(gmx::ISerializer* serializer, gmx::AwhBiasParams* awhBiasParams, int gmx_unused file_version)
{
- serializer->doInt(&awhBiasParams->eTarget);
+ serializer->doEnumAsInt(&awhBiasParams->eTarget);
serializer->doDouble(&awhBiasParams->targetBetaScaling);
serializer->doDouble(&awhBiasParams->targetCutoff);
- serializer->doInt(&awhBiasParams->eGrowth);
+ serializer->doEnumAsInt(&awhBiasParams->eGrowth);
if (serializer->reading())
{
int temp = 0;
{
gmx::AwhDimParams* dimParams = &awhBiasParams->dimParams[d];
- serializer->doInt(&dimParams->eCoordProvider);
+ serializer->doEnumAsInt(&dimParams->eCoordProvider);
serializer->doInt(&dimParams->coordIndex);
serializer->doDouble(&dimParams->origin);
serializer->doDouble(&dimParams->end);
serializer->doInt64(&awhParams->seed);
serializer->doInt(&awhParams->nstSampleCoord);
serializer->doInt(&awhParams->numSamplesUpdateFreeEnergy);
- serializer->doInt(&awhParams->ePotential);
+ serializer->doEnumAsInt(&awhParams->ePotential);
serializer->doBool(&awhParams->shareBiasMultisim);
if (awhParams->numBias > 0)
{
//! Target distribution enum.
-enum
+enum class AwhTargetType : int
{
- eawhtargetCONSTANT,
- eawhtargetCUTOFF,
- eawhtargetBOLTZMANN,
- eawhtargetLOCALBOLTZMANN,
- eawhtargetNR
+ Constant,
+ Cutoff,
+ Boltzmann,
+ LocalBoltzmann,
+ Count,
+ Default = Constant
};
//! String for target distribution.
-extern const char* eawhtarget_names[eawhtargetNR + 1];
-//! Macro for target distribution string.
-#define EAWHTARGET(e) enum_name(e, gmx::eawhtargetNR, gmx::eawhtarget_names)
+const char* enumValueToString(AwhTargetType enumValue);
//! Weight histogram growth enum.
-enum
+enum class AwhHistogramGrowthType : int
{
- eawhgrowthEXP_LINEAR,
- eawhgrowthLINEAR,
- eawhgrowthNR
+ ExponentialLinear,
+ Linear,
+ Count,
+ Default = ExponentialLinear
};
//! String for weight histogram growth
-extern const char* eawhgrowth_names[eawhgrowthNR + 1];
-//! Macro for weight histogram growth string.
-#define EAWHGROWTH(e) enum_name(e, gmx::eawhgrowthNR, gmx::eawhgrowth_names)
+const char* enumValueToString(AwhHistogramGrowthType enumValue);
//! AWH potential type enum.
-enum
+enum class AwhPotentialType : int
{
- eawhpotentialCONVOLVED,
- eawhpotentialUMBRELLA,
- eawhpotentialNR
+ Convolved,
+ Umbrella,
+ Count,
+ Default = Convolved
};
//! String for AWH potential type
-extern const char* eawhpotential_names[eawhpotentialNR + 1];
-//! Macro for AWH potential type string.
-#define EAWHPOTENTIAL(e) enum_name(e, gmx::eawhpotentialNR, gmx::eawhpotential_names)
+const char* enumValueToString(AwhPotentialType enumValue);
//! AWH bias reaction coordinate provider
-enum
+enum class AwhCoordinateProviderType : int
{
- eawhcoordproviderPULL,
- eawhcoordproviderFREE_ENERGY_LAMBDA,
- eawhcoordproviderNR
+ Pull,
+ FreeEnergyLambda,
+ Count,
+ Default = Pull
};
//! String for AWH bias reaction coordinate provider.
-extern const char* eawhcoordprovider_names[eawhcoordproviderNR + 1];
-//! Macro for AWH bias reaction coordinate provider.
-#define EAWHCOORDPROVIDER(e) enum_name(e, gmx::eawhcoordproviderNR, gmx::eawhcoordprovider_names)
+const char* enumValueToString(AwhCoordinateProviderType enumValue);
/*! \cond INTERNAL */
//! Parameters for an AWH coordinate dimension.
struct AwhDimParams
{
- int eCoordProvider; /**< The module providing the reaction coordinate. */
- int coordIndex; /**< Index of reaction coordinate in the provider. */
- double origin; /**< Start value of the interval. */
- double end; /**< End value of the interval. */
- double period; /**< The period of this dimension (= 0 if not periodic). */
- double forceConstant; /**< The force constant in kJ/mol/nm^2, kJ/mol/rad^2 */
+ AwhCoordinateProviderType eCoordProvider; /**< The module providing the reaction coordinate. */
+ int coordIndex; /**< Index of reaction coordinate in the provider. */
+ double origin; /**< Start value of the interval. */
+ double end; /**< End value of the interval. */
+ double period; /**< The period of this dimension (= 0 if not periodic). */
+ double forceConstant; /**< The force constant in kJ/mol/nm^2, kJ/mol/rad^2 */
double diffusion; /**< Estimated diffusion constant in units of nm^2/ps, rad^2/ps or ps^-1. */
double coordValueInit; /**< The initial coordinate value. */
double coverDiameter; /**< The diameter that needs to be sampled around a point before it is considered covered. */
struct AwhBiasParams
{
// TODO: Turn dimParams into a std::vector when moved into AWH module
- int ndim; /**< Dimension of the coordinate space. */
- AwhDimParams* dimParams; /**< AWH parameters per dimension. */
- int eTarget; /**< Type of target distribution. */
- double targetBetaScaling; /**< Beta scaling value for Boltzmann type target distributions. */
- double targetCutoff; /**< Free energy cutoff value for cutoff type target distribution in kJ/mol.*/
- int eGrowth; /**< How the biasing histogram grows. */
+ int ndim; /**< Dimension of the coordinate space. */
+ AwhDimParams* dimParams; /**< AWH parameters per dimension. */
+ AwhTargetType eTarget; /**< Type of target distribution. */
+ double targetBetaScaling; /**< Beta scaling value for Boltzmann type target distributions. */
+ double targetCutoff; /**< Free energy cutoff value for cutoff type target distribution in kJ/mol.*/
+ AwhHistogramGrowthType eGrowth; /**< How the biasing histogram grows. */
bool bUserData; /**< Is there a user-defined initial PMF estimate and target estimate? */
double errorInitial; /**< Estimated initial free energy error in kJ/mol. */
int shareGroup; /**< When >0, the bias is shared with biases of the same group and across multiple simulations when shareBiasMultisim=true */
AwhBiasParams* awhBiasParams; /**< AWH bias parameters.*/
int64_t seed; /**< Random seed.*/
int nstOut; /**< Output step interval.*/
- int nstSampleCoord; /**< Number of samples per coordinate sample (also used for PMF) */
- int numSamplesUpdateFreeEnergy; /**< Number of samples per free energy update. */
- int ePotential; /**< Type of potential. */
- gmx_bool shareBiasMultisim; /**< When true, share biases with shareGroup>0 between multi-simulations */
+ int nstSampleCoord; /**< Number of samples per coordinate sample (also used for PMF) */
+ int numSamplesUpdateFreeEnergy; /**< Number of samples per free energy update. */
+ AwhPotentialType ePotential; /**< Type of potential. */
+ gmx_bool shareBiasMultisim; /**< When true, share biases with shareGroup>0 between multi-simulations */
};
/*! \endcond */
pr_indent(fp, indent);
indent++;
fprintf(fp, "%s:\n", prefix);
- PS("coord-provider", EAWHCOORDPROVIDER(awhDimParams->eCoordProvider));
+ PS("coord-provider", enumValueToString(awhDimParams->eCoordProvider));
PI("coord-index", awhDimParams->coordIndex + 1);
PR("start", awhDimParams->origin);
PR("end", awhDimParams->end);
sprintf(opt, "%s-error-init", prefix);
PR(opt, awhBiasParams->errorInitial);
sprintf(opt, "%s-growth", prefix);
- PS(opt, EAWHGROWTH(awhBiasParams->eGrowth));
+ PS(opt, enumValueToString(awhBiasParams->eGrowth));
sprintf(opt, "%s-target", prefix);
- PS(opt, EAWHTARGET(awhBiasParams->eTarget));
+ PS(opt, enumValueToString(awhBiasParams->eTarget));
sprintf(opt, "%s-target-beta-scalng", prefix);
PR(opt, awhBiasParams->targetBetaScaling);
sprintf(opt, "%s-target-cutoff", prefix);
static void pr_awh(FILE* fp, int indent, gmx::AwhParams* awhParams)
{
- PS("awh-potential", EAWHPOTENTIAL(awhParams->ePotential));
+ PS("awh-potential", enumValueToString(awhParams->ePotential));
PI("awh-seed", awhParams->seed);
PI("awh-nstout", awhParams->nstOut);
PI("awh-nstsample", awhParams->nstSampleCoord);
real abstol)
{
cmp_int(fp, "inputrec->awhParams->ndim", biasIndex, bias1->ndim, bias2->ndim);
- cmp_int(fp, "inputrec->awhParams->biaseTarget", biasIndex, bias1->eTarget, bias2->eTarget);
+ cmpEnum<gmx::AwhTargetType>(fp, "inputrec->awhParams->biaseTarget", bias1->eTarget, bias2->eTarget);
cmp_double(fp,
"inputrec->awhParams->biastargetBetaScaling",
biasIndex,
bias2->targetCutoff,
ftol,
abstol);
- cmp_int(fp, "inputrec->awhParams->biaseGrowth", biasIndex, bias1->eGrowth, bias2->eGrowth);
+ cmpEnum<gmx::AwhHistogramGrowthType>(
+ fp, "inputrec->awhParams->biaseGrowth", bias1->eGrowth, bias2->eGrowth);
cmp_bool(fp, "inputrec->awhParams->biasbUserData", biasIndex, bias1->bUserData, bias2->bUserData);
cmp_double(fp,
"inputrec->awhParams->biaserror_initial",
-1,
awh1->numSamplesUpdateFreeEnergy,
awh2->numSamplesUpdateFreeEnergy);
- cmp_int(fp, "inputrec->awhParams->ePotential", -1, awh1->ePotential, awh2->ePotential);
+ cmpEnum<gmx::AwhPotentialType>(fp, "inputrec->awhParams->ePotential", awh1->ePotential, awh2->ePotential);
cmp_bool(fp, "inputrec->awhParams->shareBiasMultisim", -1, awh1->shareBiasMultisim, awh2->shareBiasMultisim);
if (awh1->numBias == awh2->numBias)