:issue:`3677`
+Bug fix for FEP calculations with modular simulator and domain decomposition
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+When using the modular simulator, domain decomposition and free energy
+calculations with perturbed masses, the simulation would always be
+performed using the masses at lambda=0 instead of the actual lambda value.
+
Fixes for ``gmx`` tools
^^^^^^^^^^^^^^^^^^^^^^^
#include "gromacs/mdtypes/state.h"
#include "gromacs/pbcutil/pbc.h"
+#include "freeenergyperturbationelement.h"
#include "statepropagatordata.h"
#include "topologyholder.h"
DomDecHelper::DomDecHelper(bool isVerbose,
int verbosePrintInterval,
StatePropagatorData* statePropagatorData,
+ FreeEnergyPerturbationElement* freeEnergyPerturbationElement,
TopologyHolder* topologyHolder,
CheckBondedInteractionsCallbackPtr checkBondedInteractionsCallback,
int nstglobalcomm,
verbosePrintInterval_(verbosePrintInterval),
nstglobalcomm_(nstglobalcomm),
statePropagatorData_(statePropagatorData),
+ freeEnergyPerturbationElement_(freeEnergyPerturbationElement),
topologyHolder_(topologyHolder),
checkBondedInteractionsCallback_(std::move(checkBondedInteractionsCallback)),
fplog_(fplog),
void DomDecHelper::setup()
{
- std::unique_ptr<t_state> localState = statePropagatorData_->localState();
- t_state* globalState = statePropagatorData_->globalState();
- PaddedHostVector<RVec>* forcePointer = statePropagatorData_->forcePointer();
-
// constant choices for this call to dd_partition_system
const bool verbose = false;
const bool isMasterState = true;
gmx_wallcycle* wcycle = nullptr;
// Distribute the charge groups over the nodes from the master node
- dd_partition_system(fplog_, mdlog_, inputrec_->init_step, cr_, isMasterState, nstglobalcomm,
- globalState, topologyHolder_->globalTopology(), inputrec_, imdSession_,
- pull_work_, localState.get(), forcePointer, mdAtoms_,
- topologyHolder_->localTopology_.get(), fr_, vsite_, constr_, nrnb_, wcycle,
- verbose);
- topologyHolder_->updateLocalTopology();
- (*checkBondedInteractionsCallback_)();
- statePropagatorData_->setLocalState(std::move(localState));
+ partitionSystem(verbose, isMasterState, nstglobalcomm, wcycle,
+ statePropagatorData_->localState(), statePropagatorData_->globalState());
}
void DomDecHelper::run(Step step, Time gmx_unused time)
{
return;
}
- std::unique_ptr<t_state> localState = statePropagatorData_->localState();
- t_state* globalState = statePropagatorData_->globalState();
- PaddedHostVector<RVec>* forcePointer = statePropagatorData_->forcePointer();
+ std::unique_ptr<t_state> localState = statePropagatorData_->localState();
+ t_state* globalState = statePropagatorData_->globalState();
// constant choices for this call to dd_partition_system
const bool verbose = isVerbose_ && (step % verbosePrintInterval_ == 0 || step == inputrec_->init_step);
}
// Distribute the charge groups over the nodes from the master node
- dd_partition_system(fplog_, mdlog_, step, cr_, isMasterState, nstglobalcomm_, globalState,
- topologyHolder_->globalTopology(), inputrec_, imdSession_, pull_work_,
- localState.get(), forcePointer, mdAtoms_, topologyHolder_->localTopology_.get(),
- fr_, vsite_, constr_, nrnb_, wcycle_, verbose);
+ partitionSystem(verbose, isMasterState, nstglobalcomm_, wcycle_, std::move(localState), globalState);
+}
+
+void DomDecHelper::partitionSystem(bool verbose,
+ bool isMasterState,
+ int nstglobalcomm,
+ gmx_wallcycle* wcycle,
+ std::unique_ptr<t_state> localState,
+ t_state* globalState)
+{
+ PaddedHostVector<RVec>* forcePointer = statePropagatorData_->forcePointer();
+
+ // Distribute the charge groups over the nodes from the master node
+ dd_partition_system(fplog_, mdlog_, inputrec_->init_step, cr_, isMasterState, nstglobalcomm,
+ globalState, topologyHolder_->globalTopology(), inputrec_, imdSession_,
+ pull_work_, localState.get(), forcePointer, mdAtoms_,
+ topologyHolder_->localTopology_.get(), fr_, vsite_, constr_, nrnb_, wcycle,
+ verbose);
topologyHolder_->updateLocalTopology();
(*checkBondedInteractionsCallback_)();
statePropagatorData_->setLocalState(std::move(localState));
+ if (freeEnergyPerturbationElement_)
+ {
+ freeEnergyPerturbationElement_->updateMDAtoms();
+ }
}
SignallerCallbackPtr DomDecHelper::registerNSCallback()
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2019, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
namespace gmx
{
class Constraints;
+class FreeEnergyPerturbationElement;
class ImdSession;
class MDAtoms;
class MDLogger;
DomDecHelper(bool isVerbose,
int verbosePrintInterval,
StatePropagatorData* statePropagatorData,
+ FreeEnergyPerturbationElement* freeEnergyPerturbationElement,
TopologyHolder* topologyHolder,
CheckBondedInteractionsCallbackPtr checkBondedInteractionsCallback,
int nstglobalcomm,
//! Pointer to the micro state
StatePropagatorData* statePropagatorData_;
+ //! Pointer to the free energy element
+ FreeEnergyPerturbationElement* freeEnergyPerturbationElement_;
//! Pointer to the topology
TopologyHolder* topologyHolder_;
//! Pointer to the ComputeGlobalsHelper object - to ask for # of bonded interaction checking
CheckBondedInteractionsCallbackPtr checkBondedInteractionsCallback_;
+ //! Helper function unifying the DD partitioning calls in setup() and run()
+ void partitionSystem(bool verbose,
+ bool isMasterState,
+ int nstglobalcomm,
+ gmx_wallcycle* wcycle,
+ std::unique_ptr<t_state> localState,
+ t_state* globalState);
+
// Access to ISimulator data
//! Handles logging.
FILE* fplog_;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2019, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "gromacs/mdlib/md_support.h"
#include "gromacs/mdlib/mdatoms.h"
#include "gromacs/mdtypes/inputrec.h"
+#include "gromacs/mdtypes/mdatom.h"
#include "gromacs/mdtypes/state.h"
namespace gmx
lambda_.fill(0);
lambda0_.fill(0);
initialize_lambdas(fplog_, *inputrec_, true, ¤tFEPState_, lambda_, lambda0_.data());
- update_mdatoms(mdAtoms_->mdatoms(), lambda_[efptMASS]);
+ updateMDAtoms();
}
void FreeEnergyPerturbationElement::scheduleTask(Step step,
{
// at beginning of step (if lambdas change...)
setCurrentLambdasLocal(step, inputrec_->fepvals, lambda0_.data(), lambda_, currentFEPState_);
- update_mdatoms(mdAtoms_->mdatoms(), lambda_[efptMASS]);
+ updateMDAtoms();
}
ArrayRef<real> FreeEnergyPerturbationElement::lambdaView()
return currentFEPState_;
}
+void FreeEnergyPerturbationElement::updateMDAtoms()
+{
+ update_mdatoms(mdAtoms_->mdatoms(), lambda_[efptMASS]);
+}
+
void FreeEnergyPerturbationElement::writeCheckpoint(t_state* localState, t_state gmx_unused* globalState)
{
localState->fep_state = currentFEPState_;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2019, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
ArrayRef<const real> constLambdaView();
//! Get the current FEP state
int currentFEPState();
+ //! Update MDAtoms (public because it's called by DomDec - see #3700)
+ void updateMDAtoms();
//! Update lambda and mdatoms
void scheduleTask(Step step, Time time, const RegisterRunFunctionPtr& registerRunFunction) override;
"interactions.");
domDecHelper_ = std::make_unique<DomDecHelper>(
mdrunOptions.verbose, mdrunOptions.verboseStepPrintInterval, statePropagatorDataPtr,
- topologyHolder_.get(), std::move(checkBondedInteractionsCallback), nstglobalcomm_, fplog,
- cr, mdlog, constr, inputrec, mdAtoms, nrnb, wcycle, fr, vsite, imdSession, pull_work);
+ freeEnergyPerturbationElementPtr, topologyHolder_.get(),
+ std::move(checkBondedInteractionsCallback), nstglobalcomm_, fplog, cr, mdlog,
+ constr, inputrec, mdAtoms, nrnb, wcycle, fr, vsite, imdSession, pull_work);
neighborSearchSignallerBuilder.registerSignallerClient(compat::make_not_null(domDecHelper_.get()));
}