Merge branch release-2018
[alexxy/gromacs.git] / src / programs / mdrun / md.cpp
index 1695e0b72d53729f4ece973596131895d9a122b8..a8319e4bf8c89905242648c97b6766d92a4ec039 100644 (file)
@@ -281,7 +281,9 @@ static void prepareRerunState(const t_trxframe  &rerunFrame,
 }
 
 /*! \libinternal
-    \copydoc integrator_t (FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
+    \copydoc integrator_t (FILE *fplog, t_commrec *cr,
+                           const gmx_multisim_t *ms,
+                           const gmx::MDLogger &mdlog,
                            int nfile, const t_filenm fnm[],
                            const gmx_output_env_t *oenv,
                            const MdrunOptions &mdrunOptions,
@@ -297,7 +299,9 @@ static void prepareRerunState(const t_trxframe  &rerunFrame,
                            gmx_membed_t *membed,
                            gmx_walltime_accounting_t walltime_accounting)
  */
-double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
+double gmx::do_md(FILE *fplog, t_commrec *cr,
+                  const gmx_multisim_t *ms,
+                  const gmx::MDLogger &mdlog,
                   int nfile, const t_filenm fnm[],
                   const gmx_output_env_t *oenv,
                   const MdrunOptions &mdrunOptions,
@@ -315,14 +319,13 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                   gmx_membed_t *membed,
                   gmx_walltime_accounting_t walltime_accounting)
 {
-    gmx_mdoutf_t    outf = nullptr;
-    gmx_int64_t     step, step_rel;
-    double          elapsed_time;
-    double          t, t0, lam0[efptNR];
-    gmx_bool        bGStatEveryStep, bGStat, bCalcVir, bCalcEnerStep, bCalcEner;
-    gmx_bool        bNS, bNStList, bSimAnn, bStopCM,
-                    bFirstStep, bInitStep, bLastStep = FALSE,
-                    bBornRadii;
+    gmx_mdoutf_t      outf = nullptr;
+    gmx_int64_t       step, step_rel;
+    double            elapsed_time;
+    double            t, t0, lam0[efptNR];
+    gmx_bool          bGStatEveryStep, bGStat, bCalcVir, bCalcEnerStep, bCalcEner;
+    gmx_bool          bNS, bNStList, bSimAnn, bStopCM,
+                      bFirstStep, bInitStep, bLastStep = FALSE;
     gmx_bool          bDoDHDL = FALSE, bDoFEP = FALSE, bDoExpanded = FALSE;
     gmx_bool          do_ene, do_log, do_verbose, bRerunWarnNoV = TRUE,
                       bForceUpdate = FALSE, bCPT;
@@ -390,7 +393,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     SimulationSignals signals;
     // Most global communnication stages don't propagate mdrun
     // signals, and will use this object to achieve that.
-    SimulationSignaller nullSignaller(nullptr, nullptr, false, false);
+    SimulationSignaller nullSignaller(nullptr, nullptr, nullptr, false, false);
 
     if (!mdrunOptions.writeConfout)
     {
@@ -550,7 +553,8 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     }
 
     /* Set up interactive MD (IMD) */
-    init_IMD(ir, cr, top_global, fplog, ir->nstcalcenergy, MASTER(cr) ? as_rvec_array(state_global->x.data()) : nullptr,
+    init_IMD(ir, cr, ms, top_global, fplog, ir->nstcalcenergy,
+             MASTER(cr) ? as_rvec_array(state_global->x.data()) : nullptr,
              nfile, fnm, oenv, mdrunOptions);
 
     if (DOMAINDECOMP(cr))
@@ -617,7 +621,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     /* Initialize AWH and restore state from history in checkpoint if needed. */
     if (ir->bDoAwh)
     {
-        ir->awh = new gmx::Awh(fplog, *ir, cr, *ir->awhParams, opt2fn("-awh", nfile, fnm), ir->pull_work);
+        ir->awh = new gmx::Awh(fplog, *ir, cr, ms, *ir->awhParams, opt2fn("-awh", nfile, fnm), ir->pull_work);
 
         if (startingFromCheckpoint)
         {
@@ -634,10 +638,9 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     const bool useReplicaExchange = (replExParams.exchangeInterval > 0);
     if (useReplicaExchange && MASTER(cr))
     {
-        repl_ex = init_replica_exchange(fplog, cr->ms, top_global->natoms, ir,
+        repl_ex = init_replica_exchange(fplog, ms, top_global->natoms, ir,
                                         replExParams);
     }
-
     /* PME tuning is only supported in the Verlet scheme, with PME for
      * Coulomb. It is not supported with only LJ PME, or for
      * reruns. */
@@ -679,7 +682,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
         {
             /* Constrain the initial coordinates and velocities */
             do_constrain_first(fplog, constr, ir, mdatoms, state,
-                               cr, nrnb, fr, top);
+                               cr, ms, nrnb, fr, top);
         }
         if (vsite)
         {
@@ -921,8 +924,8 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     {
         // TODO This implementation of ensemble orientation restraints is nasty because
         // a user can't just do multi-sim with single-sim orientation restraints.
-        bool usingEnsembleRestraints = (fcd->disres.nsystems > 1) || (cr->ms && fcd->orires.nr);
-        bool awhUsesMultiSim         = (ir->bDoAwh && ir->awhParams->shareBiasMultisim && cr->ms);
+        bool usingEnsembleRestraints = (fcd->disres.nsystems > 1) || (ms && fcd->orires.nr);
+        bool awhUsesMultiSim         = (ir->bDoAwh && ir->awhParams->shareBiasMultisim && ms);
 
         // Replica exchange, ensemble restraints and AWH need all
         // simulations to remain synchronized, so they need
@@ -952,15 +955,15 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
     step_rel = 0;
 
     // TODO extract this to new multi-simulation module
-    if (MASTER(cr) && MULTISIM(cr) && !useReplicaExchange)
+    if (MASTER(cr) && isMultiSim(ms) && !useReplicaExchange)
     {
-        if (!multisim_int_all_are_equal(cr->ms, ir->nsteps))
+        if (!multisim_int_all_are_equal(ms, ir->nsteps))
         {
             GMX_LOG(mdlog.warning).appendText(
                     "Note: The number of steps is not consistent across multi simulations,\n"
                     "but we are proceeding anyway!");
         }
-        if (!multisim_int_all_are_equal(cr->ms, ir->init_step))
+        if (!multisim_int_all_are_equal(ms, ir->init_step))
         {
             GMX_LOG(mdlog.warning).appendText(
                     "Note: The initial step is not consistent across multi simulations,\n"
@@ -1073,13 +1076,6 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
             bLastStep = TRUE;
         }
 
-        /* Determine whether or not to update the Born radii if doing GB */
-        bBornRadii = bFirstStep;
-        if (ir->implicit_solvent && (step % ir->nstgbradii == 0))
-        {
-            bBornRadii = TRUE;
-        }
-
         /* do_log triggers energy and virial calculation. Because this leads
          * to different code paths, forces can be different. Thus for exact
          * continuation we should avoid extra log output.
@@ -1215,12 +1211,12 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
         if (shellfc)
         {
             /* Now is the time to relax the shells */
-            relax_shell_flexcon(fplog, cr, mdrunOptions.verbose, step,
+            relax_shell_flexcon(fplog, cr, ms, mdrunOptions.verbose, step,
                                 ir, bNS, force_flags, top,
                                 constr, enerd, fcd,
                                 state, &f, force_vir, mdatoms,
                                 nrnb, wcycle, graph, groups,
-                                shellfc, fr, bBornRadii, t, mu_tot,
+                                shellfc, fr, t, mu_tot,
                                 vsite,
                                 ddOpenBalanceRegion, ddCloseBalanceRegion);
         }
@@ -1244,11 +1240,11 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
              * This is parallellized as well, and does communication too.
              * Check comments in sim_util.c
              */
-            do_force(fplog, cr, ir, step, nrnb, wcycle, top, groups,
+            do_force(fplog, cr, ms, ir, step, nrnb, wcycle, top, groups,
                      state->box, state->x, &state->hist,
                      f, force_vir, mdatoms, enerd, fcd,
                      state->lambda, graph,
-                     fr, vsite, mu_tot, t, ed, bBornRadii,
+                     fr, vsite, mu_tot, t, ed,
                      (bNS ? GMX_FORCE_NS : 0) | force_flags,
                      ddOpenBalanceRegion, ddCloseBalanceRegion);
         }
@@ -1286,7 +1282,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                 update_constraints(fplog, step, nullptr, ir, mdatoms,
                                    state, fr->bMolPBC, graph, f,
                                    &top->idef, shake_vir,
-                                   cr, nrnb, wcycle, upd, constr,
+                                   cr, ms, nrnb, wcycle, upd, constr,
                                    TRUE, bCalcVir);
                 wallcycle_start(wcycle, ewcUPDATE);
             }
@@ -1541,7 +1537,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                 update_constraints(fplog, step, nullptr, ir, mdatoms,
                                    state, fr->bMolPBC, graph, f,
                                    &top->idef, tmp_vir,
-                                   cr, nrnb, wcycle, upd, constr,
+                                   cr, ms, nrnb, wcycle, upd, constr,
                                    TRUE, bCalcVir);
             }
         }
@@ -1606,7 +1602,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
             update_constraints(fplog, step, &dvdl_constr, ir, mdatoms, state,
                                fr->bMolPBC, graph, f,
                                &top->idef, shake_vir,
-                               cr, nrnb, wcycle, upd, constr,
+                               cr, ms, nrnb, wcycle, upd, constr,
                                FALSE, bCalcVir);
 
             if (ir->eI == eiVVAK)
@@ -1636,7 +1632,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                 update_constraints(fplog, step, nullptr, ir, mdatoms,
                                    state, fr->bMolPBC, graph, f,
                                    &top->idef, tmp_vir,
-                                   cr, nrnb, wcycle, upd, nullptr,
+                                   cr, ms, nrnb, wcycle, upd, nullptr,
                                    FALSE, bCalcVir);
             }
             if (EI_VV(ir->eI))
@@ -1706,7 +1702,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                 // situation where e.g. checkpointing can't be
                 // signalled.
                 bool                doIntraSimSignal = true;
-                SimulationSignaller signaller(&signals, cr, doInterSimSignal, doIntraSimSignal);
+                SimulationSignaller signaller(&signals, cr, ms, doInterSimSignal, doIntraSimSignal);
 
                 compute_globals(fplog, gstat, cr, ir, fr, ekind, state, mdatoms, nrnb, vcm,
                                 wcycle, enerd, force_vir, shake_vir, total_vir, pres, mu_tot,
@@ -1832,7 +1828,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
             state->fep_state = lamnew;
         }
         /* Print the remaining wall clock time for the run */
-        if (MULTIMASTER(cr) &&
+        if (isMasterSimMasterRank(ms, cr) &&
             (do_verbose || gmx_got_usr_signal()) &&
             !bPMETunePrinting)
         {
@@ -1866,7 +1862,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
         bExchanged = FALSE;
         if (bDoReplEx)
         {
-            bExchanged = replica_exchange(fplog, cr, repl_ex,
+            bExchanged = replica_exchange(fplog, cr, ms, repl_ex,
                                           state_global, enerd,
                                           state, step, t);
         }
@@ -2004,8 +2000,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog,
                        eprAVER, mdebin, fcd, groups, &(ir->opts), ir->awh);
         }
     }
-    // TODO Enable the next line when merging to master branch
-    // done_ebin(mdebin->ebin);
+    done_ebin(mdebin->ebin);
     done_mdoutf(outf);
 
     if (bPMETune)