Add new FEP perturbation check functions
authorBerk Hess <hess@kth.se>
Thu, 13 Aug 2020 13:13:10 +0000 (15:13 +0200)
committerBerk Hess <hess@kth.se>
Thu, 13 Aug 2020 13:15:27 +0000 (15:15 +0200)
Added functions to check whether the system has perturbed masses
and perturbed constraints. Simplified the perturbed atoms check.

src/gromacs/nbnxm/nbnxm_setup.cpp
src/gromacs/topology/mtop_util.cpp
src/gromacs/topology/mtop_util.h

index e7994d84bac46560035ffc9b5e3d746a0dbd0cdc..bcb0b7d92686ce35f54152d615c170e9c3472061 100644 (file)
@@ -392,7 +392,7 @@ std::unique_ptr<nonbonded_verlet_t> init_nb_verlet(const gmx::MDLogger& mdlog,
 
     const bool haveMultipleDomains = havePPDomainDecomposition(cr);
 
-    bool           bFEP_NonBonded = (fr->efep != efepNO) && haveFepPerturbedNBInteractions(mtop);
+    bool           bFEP_NonBonded = (fr->efep != efepNO) && haveFepPerturbedNBInteractions(*mtop);
     PairlistParams pairlistParams(kernelSetup.kernelType, bFEP_NonBonded, ir->rlist, haveMultipleDomains);
 
     setupDynamicPairlistPruning(mdlog, ir, mtop, box, fr->ic, &pairlistParams);
index fb4a6ea7d615dbaf76fa20424e701b254a482d80..789a35eced49199550f9f64bb52dc9bcce53028a 100644 (file)
@@ -1051,23 +1051,55 @@ void convertAtomsToMtop(t_symtab* symtab, char** name, t_atoms* atoms, gmx_mtop_
     mtop->finalize();
 }
 
-bool haveFepPerturbedNBInteractions(const gmx_mtop_t* mtop)
+bool haveFepPerturbedNBInteractions(const gmx_mtop_t& mtop)
 {
-    for (size_t mb = 0; mb < mtop->molblock.size(); mb++)
+    for (const gmx_moltype_t& molt : mtop.moltype)
     {
-        const gmx_molblock_t& molb = mtop->molblock[mb];
-        const gmx_moltype_t&  molt = mtop->moltype[molb.type];
-        for (int m = 0; m < molb.nmol; m++)
+        for (int a = 0; a < molt.atoms.nr; a++)
         {
-            for (int a = 0; a < molt.atoms.nr; a++)
+            if (PERTURBED(molt.atoms.atom[a]))
             {
-                const t_atom& atom = molt.atoms.atom[a];
-                if (PERTURBED(atom))
-                {
-                    return true;
-                }
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
+
+bool haveFepPerturbedMasses(const gmx_mtop_t& mtop)
+{
+    for (const gmx_moltype_t& molt : mtop.moltype)
+    {
+        for (int a = 0; a < molt.atoms.nr; a++)
+        {
+            const t_atom& atom = molt.atoms.atom[a];
+            if (atom.m != atom.mB)
+            {
+                return true;
             }
         }
     }
+
+    return false;
+}
+
+bool havePerturbedConstraints(const gmx_mtop_t& mtop)
+{
+    // This code assumes that all perturbed constraints parameters are actually used
+    const auto& ffparams = mtop.ffparams;
+
+    for (gmx::index i = 0; i < gmx::ssize(ffparams.functype); i++)
+    {
+        if (ffparams.functype[i] == F_CONSTR || ffparams.functype[i] == F_CONSTRNC)
+        {
+            const auto& iparams = ffparams.iparams[i];
+            if (iparams.constr.dA != iparams.constr.dB)
+            {
+                return true;
+            }
+        }
+    }
+
     return false;
 }
index 9a027bac7dd99e970fc751c5e2fd74b46a261f6f..7d0527e654cfa4f844f39acb30ed06111e7b1a91 100644 (file)
@@ -277,11 +277,13 @@ std::vector<int> get_atom_index(const gmx_mtop_t* mtop);
  */
 void convertAtomsToMtop(t_symtab* symtab, char** name, t_atoms* atoms, gmx_mtop_t* mtop);
 
-/*! \brief Checks if the non-bonded FEP should be performed in this run.
- *
- * \param[in]  mtop  Molecular topology.
- * \returns Whether FEP non-bonded is requested.
- */
-bool haveFepPerturbedNBInteractions(const gmx_mtop_t* mtop);
+//! Checks and returns whether non-bonded interactions are perturbed for free-energy calculations
+bool haveFepPerturbedNBInteractions(const gmx_mtop_t& mtop);
+
+//! Checks whether masses are perturbed for free-energy calculations
+bool haveFepPerturbedMasses(const gmx_mtop_t& mtop);
+
+//! Checks whether constraints are perturbed for free-energy calculations
+bool havePerturbedConstraints(const gmx_mtop_t& mtop);
 
 #endif