}
}
+std::unique_ptr<Awh>
+prepareAwhModule(FILE *fplog,
+ const t_inputrec &inputRecord,
+ t_state *stateGlobal,
+ const t_commrec *commRecord,
+ const gmx_multisim_t *multiSimRecord,
+ const bool startingFromCheckpoint,
+ const bool usingShellParticles,
+ const std::string &biasInitFilename,
+ pull_t *pull_work)
+{
+ if (!inputRecord.bDoAwh)
+ {
+ return nullptr;
+ }
+ if (usingShellParticles)
+ {
+ GMX_THROW(InvalidInputError("AWH biasing does not support shell particles."));
+ }
+
+ auto awh = compat::make_unique<Awh>(fplog, inputRecord, commRecord, multiSimRecord, *inputRecord.awhParams,
+ biasInitFilename, pull_work);
+
+ if (startingFromCheckpoint)
+ {
+ // Restore the AWH history read from checkpoint
+ awh->restoreStateFromHistory(MASTER(commRecord) ? stateGlobal->awhHistory.get() : nullptr);
+ }
+ else if (MASTER(commRecord))
+ {
+ // Initialize the AWH history here
+ stateGlobal->awhHistory = awh->initHistoryFromState();
+ }
+ return awh;
+}
+
} // namespace gmx
double potentialOffset_; /**< The offset of the bias potential which changes due to bias updates. */
};
+/*! \brief Makes an Awh and prepares to use it if the user input
+ * requests that
+ *
+ * Restores state from history in checkpoint if needed.
+ *
+ * \param[in,out] fplog General output file, normally md.log, can be nullptr.
+ * \param[in] inputRecord General input parameters (as set up by grompp).
+ * \param[in] stateGlobal A pointer to the global state structure.
+ * \param[in] commRecord Struct for communication, can be nullptr.
+ * \param[in] multiSimRecord Multi-sim handler
+ * \param[in] startingFromCheckpoint Whether the simulation is starting from a checkpoint
+ * \param[in] usingShellParticles Whether the user requested shell particles (which is unsupported)
+ * \param[in] biasInitFilename Name of file to read PMF and target from.
+ * \param[in,out] pull_work Pointer to a pull struct which AWH will couple to, has to be initialized,
+ * is assumed not to change during the lifetime of the Awh object.
+ * \returns An initialized Awh module, or nullptr if none was requested.
+ * \throws InvalidInputError If another active module is not supported.
+ */
+std::unique_ptr<Awh>
+prepareAwhModule(FILE *fplog,
+ const t_inputrec &inputRecord,
+ t_state *stateGlobal,
+ const t_commrec *commRecord,
+ const gmx_multisim_t *multiSimRecord,
+ const bool startingFromCheckpoint,
+ const bool usingShellParticles,
+ const std::string &biasInitFilename,
+ pull_t *pull_work);
+
} // namespace gmx
#endif /* GMX_AWH_H */
namespace gmx
{
+class Awh;
class ForceWithVirial;
class MDLogger;
}
const t_commrec *cr,
const gmx_multisim_t *ms,
const t_inputrec *inputrec,
+ gmx::Awh *awh,
gmx_int64_t step,
t_nrnb *nrnb,
gmx_wallcycle *wcycle,
{
pr_rvecs(debug, 0, "x b4 do_force", as_rvec_array(state->x.data()), homenr);
}
- do_force(fplog, cr, ms, inputrec, mdstep, nrnb, wcycle, top, groups,
+ do_force(fplog, cr, ms, inputrec, nullptr,
+ mdstep, nrnb, wcycle, top, groups,
state->box, state->x, &state->hist,
force[Min], force_vir, md, enerd, fcd,
state->lambda, graph,
pr_rvecs(debug, 0, "RELAX: pos[Try] ", as_rvec_array(pos[Try].data()), homenr);
}
/* Try the new positions */
- do_force(fplog, cr, ms, inputrec, 1, nrnb, wcycle,
+ do_force(fplog, cr, ms, inputrec, nullptr, 1, nrnb, wcycle,
top, groups, state->box, pos[Try], &state->hist,
force[Try], force_vir,
md, enerd, fcd, state->lambda, graph,
* \param[in] fplog The log file
* \param[in] cr The communication record
* \param[in] inputrec The input record
+ * \param[in] awh The Awh module (nullptr if none in use).
* \param[in] step The current MD step
* \param[in] t The current time
* \param[in,out] wcycle Wallcycle accounting struct
computeSpecialForces(FILE *fplog,
const t_commrec *cr,
const t_inputrec *inputrec,
+ gmx::Awh *awh,
gmx_int64_t step,
double t,
gmx_wallcycle_t wcycle,
mdatoms, enerd, lambda, t,
wcycle);
- if (inputrec->bDoAwh)
+ if (awh)
{
- Awh &awh = *inputrec->awh;
enerd->term[F_COM_PULL] +=
- awh.applyBiasForcesAndUpdateBias(inputrec->ePBC, *mdatoms, box,
- forceWithVirial,
- t, step, wcycle, fplog);
+ awh->applyBiasForcesAndUpdateBias(inputrec->ePBC, *mdatoms, box,
+ forceWithVirial,
+ t, step, wcycle, fplog);
}
}
const t_commrec *cr,
const gmx_multisim_t *ms,
const t_inputrec *inputrec,
+ gmx::Awh *awh,
gmx_int64_t step,
t_nrnb *nrnb,
gmx_wallcycle_t wcycle,
wallcycle_stop(wcycle, ewcFORCE);
- computeSpecialForces(fplog, cr, inputrec, step, t, wcycle,
+ computeSpecialForces(fplog, cr, inputrec, awh, step, t, wcycle,
fr->forceProviders, box, x, mdatoms, lambda,
flags, &forceWithVirial, enerd,
ed, bNS);
const t_commrec *cr,
const gmx_multisim_t *ms,
const t_inputrec *inputrec,
+ gmx::Awh *awh,
gmx_int64_t step,
t_nrnb *nrnb,
gmx_wallcycle_t wcycle,
}
}
- computeSpecialForces(fplog, cr, inputrec, step, t, wcycle,
+ computeSpecialForces(fplog, cr, inputrec, awh, step, t, wcycle,
fr->forceProviders, box, x, mdatoms, lambda,
flags, &forceWithVirial, enerd,
ed, bNS);
const t_commrec *cr,
const gmx_multisim_t *ms,
const t_inputrec *inputrec,
+ gmx::Awh *awh,
gmx_int64_t step,
t_nrnb *nrnb,
gmx_wallcycle_t wcycle,
{
case ecutsVERLET:
do_force_cutsVERLET(fplog, cr, ms, inputrec,
- step, nrnb, wcycle,
+ awh, step, nrnb, wcycle,
top,
groups,
box, x, hist,
break;
case ecutsGROUP:
do_force_cutsGROUP(fplog, cr, ms, inputrec,
- step, nrnb, wcycle,
+ awh, step, nrnb, wcycle,
top,
groups,
box, x, hist,
top_global, n_flexible_constraints(constr),
ir->nstcalcenergy, DOMAINDECOMP(cr));
- if (shellfc && ir->bDoAwh)
- {
- gmx_fatal(FARGS, "AWH biasing does not support shell particles.");
- }
-
if (inputrecDeform(ir))
{
tMPI_Thread_mutex_lock(&deform_init_box_mutex);
set_constraints(constr, top, ir, mdatoms, cr);
}
- /* Initialize AWH and restore state from history in checkpoint if needed. */
- if (ir->bDoAwh)
- {
- ir->awh = new gmx::Awh(fplog, *ir, cr, ms, *ir->awhParams, opt2fn("-awh", nfile, fnm), ir->pull_work);
-
- if (startingFromCheckpoint)
- {
- /* Restore the AWH history read from checkpoint */
- ir->awh->restoreStateFromHistory(MASTER(cr) ? state_global->awhHistory.get() : nullptr);
- }
- else if (MASTER(cr))
- {
- /* Initialize the AWH history here */
- state_global->awhHistory = ir->awh->initHistoryFromState();
- }
- }
+ // TODO: Remove this by converting AWH into a ForceProvider
+ auto awh = prepareAwhModule(fplog, *ir, state_global, cr, ms, startingFromCheckpoint,
+ shellfc != nullptr,
+ opt2fn("-awh", nfile, fnm), ir->pull_work);
const bool useReplicaExchange = (replExParams.exchangeInterval > 0);
if (useReplicaExchange && MASTER(cr))
do_md_trajectory_writing (then containing update_awh_history).
The checkpointing will in the future probably moved to the start of the md loop which will
rid of this issue. */
- if (ir->bDoAwh && bCPT && MASTER(cr))
+ if (awh && bCPT && MASTER(cr))
{
- ir->awh->updateHistory(state_global->awhHistory.get());
+ awh->updateHistory(state_global->awhHistory.get());
}
/* The coordinates (x) are shifted (to get whole molecules)
* This is parallellized as well, and does communication too.
* Check comments in sim_util.c
*/
- do_force(fplog, cr, ms, ir, step, nrnb, wcycle, top, groups,
+ do_force(fplog, cr, ms, ir, awh.get(),
+ step, nrnb, wcycle, top, groups,
state->box, state->x, &state->hist,
f, force_vir, mdatoms, enerd, fcd,
state->lambda, graph,
print_ebin(mdoutf_get_fp_ene(outf), do_ene, do_dr, do_or, do_log ? fplog : nullptr,
step, t,
- eprNORMAL, mdebin, fcd, groups, &(ir->opts), ir->awh);
+ eprNORMAL, mdebin, fcd, groups, &(ir->opts), awh.get());
if (ir->bPull)
{
if (ir->nstcalcenergy > 0 && !bRerunMD)
{
print_ebin(mdoutf_get_fp_ene(outf), FALSE, FALSE, FALSE, fplog, step, t,
- eprAVER, mdebin, fcd, groups, &(ir->opts), ir->awh);
+ eprAVER, mdebin, fcd, groups, &(ir->opts), awh.get());
}
}
done_mdebin(mdebin);
print_replica_exchange_statistics(fplog, repl_ex);
}
- if (ir->bDoAwh)
- {
- delete ir->awh;
- }
-
// Clean up swapcoords
if (ir->eSwapCoords != eswapNO)
{
/* do_force always puts the charge groups in the box and shifts again
* We do not unshift, so molecules are always whole in congrad.c
*/
- do_force(fplog, cr, ms, inputrec,
+ do_force(fplog, cr, ms, inputrec, nullptr,
count, nrnb, wcycle, top, &top_global->groups,
ems->s.box, ems->s.x, &ems->s.hist,
ems->f, force_vir, mdAtoms->mdatoms(), enerd, fcd,
* out of the box. */
/* Make do_force do a single node force calculation */
cr->nnodes = 1;
- do_force(fplog, cr, ms, inputrec,
+ do_force(fplog, cr, ms, inputrec, nullptr,
step, nrnb, wcycle, top, &top_global->groups,
state_global->box, state_global->x, &state_global->hist,
f, force_vir, mdatoms, enerd, fcd,
/* AWH bias data */
gmx_bool bDoAwh; /* Use awh biasing for PMF calculations? */
gmx::AwhParams *awhParams; /* AWH biasing parameters */
- // TODO: Remove this by converting AWH into a ForceProvider
- gmx::Awh *awh; /* AWH work object */
/* Enforced rotation data */
gmx_bool bRot; /* Calculate enforced rotation potential(s)? */