* \param[in] checkpointWriting enables writing to the Key-Value-Tree
* that is used for storing the checkpoint
* information
+ *
+ * \note The provided state to checkpoint has to change if checkpointing
+ * is moved before the force provider call in the MD-loop.
*/
void writeCheckpointData(MdModulesWriteCheckpointData checkpointWriting)
{
if (densityFittingOptions_.active())
{
- const DensityFittingForceProviderState& state = forceProvider_->state();
+ const DensityFittingForceProviderState& state = forceProvider_->stateToCheckpoint();
checkpointWriting.builder_.addValue<std::int64_t>(
DensityFittingModuleInfo::name_ + "-stepsSinceLastCalculation",
state.stepsSinceLastCalculation_);
~Impl();
void calculateForces(const ForceProviderInput& forceProviderInput,
ForceProviderOutput* forceProviderOutput);
-
- DensityFittingForceProviderState state();
+ const DensityFittingForceProviderState& stateToCheckpoint();
private:
+ DensityFittingForceProviderState state();
const DensityFittingParameters& parameters_;
DensityFittingForceProviderState state_;
+ DensityFittingForceProviderState stateToCheckpoint_;
LocalAtomSet localAtomSet_;
GaussianSpreadKernelParameters::Shape spreadKernel_;
void DensityFittingForceProvider::Impl::calculateForces(const ForceProviderInput& forceProviderInput,
ForceProviderOutput* forceProviderOutput)
{
+ // TODO change if checkpointing moves to the start of the md loop
+ stateToCheckpoint_ = state();
// do nothing but count number of steps when not in density fitting step
if (state_.stepsSinceLastCalculation_ % parameters_.calculationIntervalInSteps_ != 0)
{
return state_;
}
+const DensityFittingForceProviderState& DensityFittingForceProvider::Impl::stateToCheckpoint()
+{
+ return stateToCheckpoint_;
+}
/********************************************************************
* DensityFittingForceProvider
*/
impl_->calculateForces(forceProviderInput, forceProviderOutput);
}
-DensityFittingForceProviderState DensityFittingForceProvider::state()
+const DensityFittingForceProviderState& DensityFittingForceProvider::stateToCheckpoint()
{
- return impl_->state();
+ return impl_->stateToCheckpoint();
}
} // namespace gmx
void calculateForces(const ForceProviderInput& forceProviderInput,
ForceProviderOutput* forceProviderOutput) override;
- //! Return the state of the forceprovider.
- DensityFittingForceProviderState state();
+ /*! \brief Return the state of the forceprovider to be checkpointed
+ * TODO update this routine if checkpointing is moved to the beginning of
+ * the md loop
+ */
+ const DensityFittingForceProviderState& stateToCheckpoint();
private:
class Impl;
const std::string mdpEnergyAndDensityfittingIntervalMismatch_ = formatString(
"nstcalcenergy = 7\n"
"density-guided-simulation-nst = 3\n");
+ //! Set mdp values so that we skip every other step
+ const std::string mdpSkipDensityfittingEveryOtherStep_ = formatString(
+ "nstenergy = 2\n"
+ "density-guided-simulation-nst = 2\n");
//! The command line to call mdrun
CommandLine commandLineForMdrun_;
};
".*is not a multiple of density-guided-simulation-nst.*");
}
+/* Fit a subset of three of twelve argon atoms into a reference density
+ * whose origin is offset from the simulation box origin. Stop the simulation,
+ * then restart.
+ *
+ * All density fitting mdp parameters are set to defaults
+ */
+TEST_F(DensityFittingTest, CheckpointWorks)
+{
+ runner_.useStringAsMdpFile(mdpMdDensfitYesUnsetValues + mdpSkipDensityfittingEveryOtherStep_);
+ runner_.cptFileName_ = fileManager_.getTemporaryFilePath(".cpt");
+ commandLineForMdrun_.addOption("-cpo", runner_.cptFileName_);
+
+ ASSERT_EQ(0, runner_.callGrompp());
+ ASSERT_EQ(0, runner_.callMdrun(commandLineForMdrun_));
+
+ // checkMdrun(expectedEnergyTermMagnitude);
+
+ CommandLine commandLineForRestart;
+ commandLineForRestart.addOption("-cpi", runner_.cptFileName_);
+ commandLineForRestart.addOption("-noappend");
+ runner_.nsteps_ = 4;
+ ASSERT_EQ(0, runner_.callMdrun(commandLineForRestart));
+
+ const real expectedEnergyTermMagnitude = -3378.825928;
+ checkMdrun(expectedEnergyTermMagnitude);
+}
+
+
} // namespace test
} // namespace gmx
--- /dev/null
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+ <Energy Name="Potential">
+ <Real Name="Time 0.000000 Step 0 in frame 0">-3379.9202</Real>
+ <Real Name="Time 0.002000 Step 2 in frame 1">-3390.9541</Real>
+ </Energy>
+ <Energy Name="Density fitting">
+ <Real Name="Time 0.000000 Step 0 in frame 0">-3378.9026</Real>
+ <Real Name="Time 0.002000 Step 2 in frame 1">-3389.9324</Real>
+ </Energy>
+</ReferenceData>