Refactor md_enums
[alexxy/gromacs.git] / src / gromacs / mdlib / dispersioncorrection.cpp
index 3557950ddba1ba8bca9ce148450ba43b2fc2bd88..481c8597e79e9c96ff843df4f6a11838a216d356 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 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.
@@ -57,7 +57,8 @@
 DispersionCorrection::InteractionParams::~InteractionParams() = default;
 
 /* Returns a matrix, as flat list, of combination rule combined LJ parameters */
-static std::vector<real> mk_nbfp_combination_rule(const gmx_ffparams_t& ffparams, const int comb_rule)
+static std::vector<real> mk_nbfp_combination_rule(const gmx_ffparams_t& ffparams,
+                                                  const CombinationRule comb_rule)
 {
     const int atnr = ffparams.atnr;
 
@@ -73,7 +74,7 @@ static std::vector<real> mk_nbfp_combination_rule(const gmx_ffparams_t& ffparams
             const real c12j = ffparams.iparams[j * (atnr + 1)].lj.c12;
             real       c6   = std::sqrt(c6i * c6j);
             real       c12  = std::sqrt(c12i * c12j);
-            if (comb_rule == eCOMB_ARITHMETIC && !gmx_numzero(c6) && !gmx_numzero(c12))
+            if (comb_rule == CombinationRule::Arithmetic && !gmx_numzero(c6) && !gmx_numzero(c12))
             {
                 const real sigmai = gmx::sixthroot(c12i / c6i);
                 const real sigmaj = gmx::sixthroot(c12j / c6j);
@@ -121,9 +122,10 @@ DispersionCorrection::TopologyParams::TopologyParams(const gmx_mtop_t&         m
      * combination rules. */
     if (EVDW_PME(inputrec.vdwtype))
     {
-        nbfp_comb = mk_nbfp_combination_rule(
-                mtop.ffparams,
-                (inputrec.ljpme_combination_rule == eljpmeLB) ? eCOMB_ARITHMETIC : eCOMB_GEOMETRIC);
+        nbfp_comb = mk_nbfp_combination_rule(mtop.ffparams,
+                                             (inputrec.ljpme_combination_rule == LongRangeVdW::LB)
+                                                     ? CombinationRule::Arithmetic
+                                                     : CombinationRule::Geometric);
         for (int tpi = 0; tpi < ntp; ++tpi)
         {
             for (int tpj = 0; tpj < ntp; ++tpj)
@@ -135,7 +137,7 @@ DispersionCorrection::TopologyParams::TopologyParams(const gmx_mtop_t&         m
         nbfp = nbfp_comb;
     }
 
-    for (int q = 0; q < (inputrec.efep == efepNO ? 1 : 2); q++)
+    for (int q = 0; q < (inputrec.efep == FreeEnergyPerturbationType::No ? 1 : 2); q++)
     {
         double  csix    = 0;
         double  ctwelve = 0;
@@ -384,18 +386,20 @@ void DispersionCorrection::setInteractionParameters(InteractionParams*         i
     InteractionCorrection energy;
     InteractionCorrection virial;
 
-    if ((ic.vdw_modifier == eintmodPOTSHIFT) || (ic.vdw_modifier == eintmodPOTSWITCH)
-        || (ic.vdw_modifier == eintmodFORCESWITCH) || (ic.vdwtype == evdwSHIFT)
-        || (ic.vdwtype == evdwSWITCH))
+    if ((ic.vdw_modifier == InteractionModifiers::PotShift)
+        || (ic.vdw_modifier == InteractionModifiers::PotSwitch)
+        || (ic.vdw_modifier == InteractionModifiers::ForceSwitch)
+        || (ic.vdwtype == VanDerWaalsType::Shift) || (ic.vdwtype == VanDerWaalsType::Switch))
     {
-        if (((ic.vdw_modifier == eintmodPOTSWITCH) || (ic.vdw_modifier == eintmodFORCESWITCH)
-             || (ic.vdwtype == evdwSWITCH))
+        if (((ic.vdw_modifier == InteractionModifiers::PotSwitch)
+             || (ic.vdw_modifier == InteractionModifiers::ForceSwitch)
+             || (ic.vdwtype == VanDerWaalsType::Switch))
             && ic.rvdw_switch == 0)
         {
             gmx_fatal(FARGS,
                       "With dispersion correction rvdw-switch can not be zero "
                       "for vdw-type = %s",
-                      evdw_names[ic.vdwtype]);
+                      enumValueToString(ic.vdwtype));
         }
 
         GMX_ASSERT(iParams->dispersionCorrectionTable_, "We need an initialized table");
@@ -429,13 +433,13 @@ void DispersionCorrection::setInteractionParameters(InteractionParams*         i
          * we need to calculate the constant shift up to the point where we
          * start modifying the potential.
          */
-        ri0 = (ic.vdw_modifier == eintmodPOTSHIFT) ? ri1 : ri0;
+        ri0 = (ic.vdw_modifier == InteractionModifiers::PotShift) ? ri1 : ri0;
 
         const double r0  = ri0 / scale;
         const double rc3 = r0 * r0 * r0;
         const double rc9 = rc3 * rc3 * rc3;
 
-        if ((ic.vdw_modifier == eintmodFORCESWITCH) || (ic.vdwtype == evdwSHIFT))
+        if ((ic.vdw_modifier == InteractionModifiers::ForceSwitch) || (ic.vdwtype == VanDerWaalsType::Shift))
         {
             /* Determine the constant energy shift below rvdw_switch.
              * Table has a scale factor since we have scaled it down to compensate
@@ -444,7 +448,7 @@ void DispersionCorrection::setInteractionParameters(InteractionParams*         i
             iParams->enershiftsix_ = static_cast<real>(-1.0 / (rc3 * rc3)) - 6.0 * vdwtab[8 * ri0];
             iParams->enershifttwelve_ = static_cast<real>(1.0 / (rc9 * rc3)) - 12.0 * vdwtab[8 * ri0 + 4];
         }
-        else if (ic.vdw_modifier == eintmodPOTSHIFT)
+        else if (ic.vdw_modifier == InteractionModifiers::PotShift)
         {
             iParams->enershiftsix_    = static_cast<real>(-1.0 / (rc3 * rc3));
             iParams->enershifttwelve_ = static_cast<real>(1.0 / (rc9 * rc3));
@@ -482,7 +486,8 @@ void DispersionCorrection::setInteractionParameters(InteractionParams*         i
          */
         addCorrectionBeyondCutoff(&energy, &virial, r0);
     }
-    else if (ic.vdwtype == evdwCUT || EVDW_PME(ic.vdwtype) || ic.vdwtype == evdwUSER)
+    else if (ic.vdwtype == VanDerWaalsType::Cut || EVDW_PME(ic.vdwtype)
+             || ic.vdwtype == VanDerWaalsType::User)
     {
         /* Note that with LJ-PME, the dispersion correction is multiplied
          * by the difference between the actual C6 and the value of C6
@@ -493,7 +498,7 @@ void DispersionCorrection::setInteractionParameters(InteractionParams*         i
 
         const double rc3 = ic.rvdw * ic.rvdw * ic.rvdw;
         const double rc9 = rc3 * rc3 * rc3;
-        if (ic.vdw_modifier == eintmodPOTSHIFT)
+        if (ic.vdw_modifier == InteractionModifiers::PotShift)
         {
             /* Contribution within the cut-off */
             energy.dispersion += -4.0 * M_PI / (3.0 * rc3);
@@ -504,7 +509,9 @@ void DispersionCorrection::setInteractionParameters(InteractionParams*         i
     }
     else
     {
-        gmx_fatal(FARGS, "Dispersion correction is not implemented for vdw-type = %s", evdw_names[ic.vdwtype]);
+        gmx_fatal(FARGS,
+                  "Dispersion correction is not implemented for vdw-type = %s",
+                  enumValueToString(ic.vdwtype));
     }
 
     iParams->enerdiffsix_    = energy.dispersion;
@@ -526,7 +533,7 @@ DispersionCorrection::DispersionCorrection(const gmx_mtop_t&          mtop,
     eFep_(inputrec.efep),
     topParams_(mtop, inputrec, useBuckingham, numAtomTypes, nonbondedForceParameters)
 {
-    if (eDispCorr_ != edispcNO)
+    if (eDispCorr_ != DispersionCorrectionType::No)
     {
         GMX_RELEASE_ASSERT(tableFileName, "Need a table file name");
 
@@ -536,7 +543,8 @@ DispersionCorrection::DispersionCorrection(const gmx_mtop_t&          mtop,
 
 bool DispersionCorrection::correctFullInteraction() const
 {
-    return (eDispCorr_ == edispcAllEner || eDispCorr_ == edispcAllEnerPres);
+    return (eDispCorr_ == DispersionCorrectionType::AllEner
+            || eDispCorr_ == DispersionCorrectionType::AllEnerPres);
 }
 
 void DispersionCorrection::print(const gmx::MDLogger& mdlog) const
@@ -547,7 +555,7 @@ void DispersionCorrection::print(const gmx::MDLogger& mdlog) const
                 .asParagraph()
                 .appendText("WARNING: There are no atom pairs for dispersion correction");
     }
-    else if (vdwType_ == evdwUSER)
+    else if (vdwType_ == VanDerWaalsType::User)
     {
         GMX_LOG(mdlog.warning)
                 .asParagraph()
@@ -564,7 +572,7 @@ void DispersionCorrection::print(const gmx::MDLogger& mdlog) const
 
 void DispersionCorrection::setParameters(const interaction_const_t& ic)
 {
-    if (eDispCorr_ != edispcNO)
+    if (eDispCorr_ != DispersionCorrectionType::No)
     {
         setInteractionParameters(&iParams_, ic, nullptr);
     }
@@ -575,13 +583,14 @@ DispersionCorrection::Correction DispersionCorrection::calculate(const matrix bo
 {
     Correction corr;
 
-    if (eDispCorr_ == edispcNO)
+    if (eDispCorr_ == DispersionCorrectionType::No)
     {
         return corr;
     }
 
     const bool bCorrAll  = correctFullInteraction();
-    const bool bCorrPres = (eDispCorr_ == edispcEnerPres || eDispCorr_ == edispcAllEnerPres);
+    const bool bCorrPres = (eDispCorr_ == DispersionCorrectionType::EnerPres
+                            || eDispCorr_ == DispersionCorrectionType::AllEnerPres);
 
     const real invvol  = 1 / det(box);
     const real density = topParams_.numAtomsForDensity_ * invvol;
@@ -589,7 +598,7 @@ DispersionCorrection::Correction DispersionCorrection::calculate(const matrix bo
 
     real avcsix;
     real avctwelve;
-    if (eFep_ == efepNO)
+    if (eFep_ == FreeEnergyPerturbationType::No)
     {
         avcsix    = topParams_.avcsix_[0];
         avctwelve = topParams_.avctwelve_[0];
@@ -603,7 +612,7 @@ DispersionCorrection::Correction DispersionCorrection::calculate(const matrix bo
     const real enerdiff = numCorr * (density * iParams_.enerdiffsix_ - iParams_.enershiftsix_);
     corr.energy += avcsix * enerdiff;
     real dvdlambda = 0;
-    if (eFep_ != efepNO)
+    if (eFep_ != FreeEnergyPerturbationType::No)
     {
         dvdlambda += (topParams_.avcsix_[1] - topParams_.avcsix_[0]) * enerdiff;
     }
@@ -611,7 +620,7 @@ DispersionCorrection::Correction DispersionCorrection::calculate(const matrix bo
     {
         const real enerdiff = numCorr * (density * iParams_.enerdifftwelve_ - iParams_.enershifttwelve_);
         corr.energy += avctwelve * enerdiff;
-        if (eFep_ != efepNO)
+        if (eFep_ != FreeEnergyPerturbationType::No)
         {
             dvdlambda += (topParams_.avctwelve_[1] - topParams_.avctwelve_[0]) * enerdiff;
         }
@@ -620,7 +629,7 @@ DispersionCorrection::Correction DispersionCorrection::calculate(const matrix bo
     if (bCorrPres)
     {
         corr.virial = numCorr * density * avcsix * iParams_.virdiffsix_ / 3.0;
-        if (eDispCorr_ == edispcAllEnerPres)
+        if (eDispCorr_ == DispersionCorrectionType::AllEnerPres)
         {
             corr.virial += numCorr * density * avctwelve * iParams_.virdifftwelve_ / 3.0;
         }
@@ -628,7 +637,7 @@ DispersionCorrection::Correction DispersionCorrection::calculate(const matrix bo
         corr.pressure = -2.0 * invvol * corr.virial * PRESFAC;
     }
 
-    if (eFep_ != efepNO)
+    if (eFep_ != FreeEnergyPerturbationType::No)
     {
         corr.dvdl += dvdlambda;
     }