From 67f8f21c9ca84967891a4ed8cd529fdc0d27a352 Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Fri, 15 Dec 2017 08:24:07 +0100
Subject: [PATCH] Backported gmx-2016.4 patch from plumed 2.4

---
 patches/gromacs-5.1.4.diff/src/programs/mdrun/md.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/patches/gromacs-5.1.4.diff/src/programs/mdrun/md.cpp b/patches/gromacs-5.1.4.diff/src/programs/mdrun/md.cpp
index 1e2c620ea..d4bb5960f 100644
--- a/patches/gromacs-5.1.4.diff/src/programs/mdrun/md.cpp
+++ b/patches/gromacs-5.1.4.diff/src/programs/mdrun/md.cpp
@@ -1055,7 +1055,7 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[],
 
 /* PLUMED HREX */
         gmx_bool bHREX;
-        bHREX= repl_ex_nst > 0 && (step>0) && !bLastStep && do_per_step(step,repl_ex_nst) && plumed_hrex;
+        bHREX = bDoReplEx && plumed_hrex;
 
         if(plumedswitch) if(bHREX){
           gmx_enerdata_t *hrex_enerd;
@@ -1249,6 +1249,7 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[],
               if(pversion>3) plumed_cmd(plumedmain,"doCheckPoint",&checkp);
               plumed_cmd(plumedmain,"setForces",&f[0][0]);
               plumed_cmd(plumedmain,"isEnergyNeeded",&plumedNeedsEnergy);
+              if(plumedNeedsEnergy) force_flags |= (GMX_FORCE_ENERGY | GMX_FORCE_VIRIAL);
               clear_mat(plumed_vir);
               plumed_cmd(plumedmain,"setVirial",&plumed_vir[0][0]);
             }
@@ -1270,11 +1271,9 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[],
                 msmul(plumed_vir,0.5,plumed_vir);
                 m_add(force_vir,plumed_vir,force_vir);
               }
-              if ((repl_ex_nst > 0) && (step > 0) && !bLastStep &&
-                 do_per_step(step,repl_ex_nst)) plumed_cmd(plumedmain,"GREX savePositions",NULL);
+              if(bDoReplEx) plumed_cmd(plumedmain,"GREX savePositions",NULL);
               if(plumedWantsToStop) ir->nsteps=step_rel+1;
-              if(bHREX)
-                 plumed_cmd(plumedmain,"GREX cacheLocalUNow",&enerd->term[F_EPOT]);
+              if(bHREX) plumed_cmd(plumedmain,"GREX cacheLocalUNow",&enerd->term[F_EPOT]);
             }
             /* END PLUMED */
         }
-- 
GitLab