fixed mdrun -cpi SD and pcoupl initialization
authorBerk Hess <hess@kth.se>
Tue, 8 May 2012 09:21:56 +0000 (11:21 +0200)
committerBerk Hess <hess@kth.se>
Tue, 8 May 2012 09:21:56 +0000 (11:21 +0200)
With mdrun -cpi and no previous output files present SD and pressure
coupling were initialized incorrectly, leading to minor differences
at the start of a simulation. Fixes #939

Change-Id: I1ea3797ceb39760341c7c11cf74425c02dcaf235

src/kernel/md.c

index c5dd33da726eb6538a5f982390a9e56998b96f24..6071b15d6bcf67f2b41027dfd973e2ddea8c44b1 100644 (file)
@@ -123,7 +123,7 @@ double do_md(FILE *fplog,t_commrec *cr,int nfile,const t_filenm fnm[],
     double     t,t0,lam0;
     gmx_bool       bGStatEveryStep,bGStat,bNstEner,bCalcEnerPres;
     gmx_bool       bNS,bNStList,bSimAnn,bStopCM,bRerunMD,bNotLastFrame=FALSE,
-               bFirstStep,bStateFromTPX,bInitStep,bLastStep,
+               bFirstStep,bStateFromCP,bStateFromTPX,bInitStep,bLastStep,
                bBornRadii,bStartingFromCpt;
     gmx_bool       bDoDHDL=FALSE;
     gmx_bool       do_ene,do_log,do_verbose,bRerunWarnNoV=TRUE,
@@ -374,9 +374,18 @@ double do_md(FILE *fplog,t_commrec *cr,int nfile,const t_filenm fnm[],
 
     update_mdatoms(mdatoms,state->lambda);
 
+    if (opt2bSet("-cpi",nfile,fnm))
+    {
+        bStateFromCP = gmx_fexist_master(opt2fn_master("-cpi",nfile,fnm,cr),cr);
+    }
+    else
+    {
+        bStateFromCP = FALSE;
+    }
+
     if (MASTER(cr))
     {
-        if (opt2bSet("-cpi",nfile,fnm))
+        if (bStateFromCP)
         {
             /* Update mdebin with energy history if appending to output files */
             if ( Flags & MD_APPENDFILES )
@@ -650,7 +659,7 @@ double do_md(FILE *fplog,t_commrec *cr,int nfile,const t_filenm fnm[],
     /* loop over MD steps or if rerunMD to end of input trajectory */
     bFirstStep = TRUE;
     /* Skip the first Nose-Hoover integration when we get the state from tpx */
-    bStateFromTPX = !opt2bSet("-cpi",nfile,fnm);
+    bStateFromTPX = !bStateFromCP;
     bInitStep = bFirstStep && (bStateFromTPX || bVV);
     bStartingFromCpt = (Flags & MD_STARTFROMCPT) && bInitStep;
     bLastStep    = FALSE;