*/
class DensityFittingSimulationParameterSetup
{
- public:
- DensityFittingSimulationParameterSetup() = default;
-
- /*! \brief Set the local atom set for the density fitting.
- * \param[in] localAtomSet of atoms to be fitted
- */
- void setLocalAtomSet(const LocalAtomSet &localAtomSet)
+public:
+ DensityFittingSimulationParameterSetup() = default;
+
+ /*! \brief Set the local atom set for the density fitting.
+ * \param[in] localAtomSet of atoms to be fitted
+ */
+ void setLocalAtomSet(const LocalAtomSet& localAtomSet)
+ {
+ localAtomSet_ = std::make_unique<LocalAtomSet>(localAtomSet);
+ }
+
+ /*! \brief Return local atom set for density fitting.
+ * \throws InternalError if local atom set is not set
+ * \returns local atom set for density fitting
+ */
+ const LocalAtomSet& localAtomSet() const
+ {
+ if (localAtomSet_ == nullptr)
{
- localAtomSet_ = std::make_unique<LocalAtomSet>(localAtomSet);
+ GMX_THROW(
+ InternalError("Local atom set is not set for density "
+ "guided simulation."));
}
-
- /*! \brief Return local atom set for density fitting.
- * \throws InternalError if local atom set is not set
- * \returns local atom set for density fitting
- */
- const LocalAtomSet &localAtomSet() const
+ return *localAtomSet_;
+ }
+
+ /*! \brief Return transformation into density lattice.
+ * \throws InternalError if transformation into density lattice is not set
+ * \returns transformation into density lattice
+ */
+ const TranslateAndScale& transformationToDensityLattice() const
+ {
+ if (transformationToDensityLattice_ == nullptr)
{
- if (localAtomSet_ == nullptr)
- {
- GMX_THROW(
- InternalError("Local atom set is not set for density "
- "guided simulation."));
- }
- return *localAtomSet_;
+ GMX_THROW(InternalError(
+ "Transformation to reference density not set for density guided simulation."));
}
-
- /*! \brief Return transformation into density lattice.
- * \throws InternalError if transformation into density lattice is not set
- * \returns transformation into density lattice
- */
- const TranslateAndScale &transformationToDensityLattice() const
+ return *transformationToDensityLattice_;
+ }
+ /*! \brief Return reference density
+ * \throws InternalError if reference density is not set
+ * \returns the reference density
+ */
+ basic_mdspan<const float, dynamicExtents3D> referenceDensity() const
+ {
+ if (referenceDensity_ == nullptr)
{
- if (transformationToDensityLattice_ == nullptr)
- {
- GMX_THROW(
- InternalError("Transformation to reference density not set for density guided simulation."));
- }
- return *transformationToDensityLattice_;
+ GMX_THROW(InternalError("Reference density not set for density guided simulation."));
}
- /*! \brief Return reference density
- * \throws InternalError if reference density is not set
- * \returns the reference density
- */
- basic_mdspan<const float, dynamicExtents3D>
- referenceDensity() const
+ return referenceDensity_->asConstView();
+ }
+
+ /*! \brief Reads the reference density from file.
+ *
+ * Reads and check file, then set and communicate the internal
+ * parameters related to the reference density with the file data.
+ *
+ * \throws FileIOError if reading from file was not successful
+ */
+ void readReferenceDensityFromFile(const std::string& referenceDensityFileName)
+ {
+ MrcDensityMapOfFloatFromFileReader reader(referenceDensityFileName);
+ referenceDensity_ = std::make_unique<MultiDimArray<std::vector<float>, dynamicExtents3D>>(
+ reader.densityDataCopy());
+ transformationToDensityLattice_ =
+ std::make_unique<TranslateAndScale>(reader.transformationToDensityLattice());
+ }
+
+ //! Normalize the reference density so that the sum over all voxels is unity
+ void normalizeReferenceDensity()
+ {
+ if (referenceDensity_ == nullptr)
{
- if (referenceDensity_ == nullptr)
- {
- GMX_THROW(InternalError("Reference density not set for density guided simulation."));
- }
- return referenceDensity_->asConstView();
+ GMX_THROW(InternalError("Need to set reference density before normalizing it."));
}
- /*! \brief Reads the reference density from file.
- *
- * Reads and check file, then set and communicate the internal
- * parameters related to the reference density with the file data.
- *
- * \throws FileIOError if reading from file was not successful
- */
- void readReferenceDensityFromFile(const std::string &referenceDensityFileName)
+ const real sumOfDensityData = std::accumulate(begin(referenceDensity_->asView()),
+ end(referenceDensity_->asView()), 0.);
+ for (float& referenceDensityVoxel : referenceDensity_->asView())
{
- MrcDensityMapOfFloatFromFileReader reader(referenceDensityFileName);
- referenceDensity_ = std::make_unique<MultiDimArray<std::vector<float>, dynamicExtents3D> >
- (reader.densityDataCopy());
- transformationToDensityLattice_
- = std::make_unique<TranslateAndScale>(reader.transformationToDensityLattice());
+ referenceDensityVoxel /= sumOfDensityData;
}
-
- //! Normalize the reference density so that the sum over all voxels is unity
- void normalizeReferenceDensity()
+ }
+ /*! \brief Set the periodic boundary condition via MdModuleNotifier.
+ *
+ * The pbc type is wrapped in PeriodicBoundaryConditionType to
+ * allow the MdModuleNotifier to statically distinguish the callback
+ * function type from other 'int' function callbacks.
+ *
+ * \param[in] pbc MdModuleNotification class that contains a variable
+ * that enumerates the periodic boundary condition.
+ */
+ void setPeriodicBoundaryConditionType(PeriodicBoundaryConditionType pbc)
+ {
+ pbcType_ = std::make_unique<int>(pbc.pbcType);
+ }
+
+ //! Get the periodic boundary conditions
+ int periodicBoundaryConditionType()
+ {
+ if (pbcType_ == nullptr)
{
- if (referenceDensity_ == nullptr)
- {
- GMX_THROW(InternalError("Need to set reference density before normalizing it."));
- }
-
- const real sumOfDensityData = std::accumulate(begin(referenceDensity_->asView()), end(referenceDensity_->asView()), 0.);
- for (float &referenceDensityVoxel : referenceDensity_->asView())
- {
- referenceDensityVoxel /= sumOfDensityData;
- }
+ GMX_THROW(InternalError(
+ "Periodic boundary condition enum not set for density guided simulation."));
}
- /*! \brief Set the periodic boundary condition via MdModuleNotifier.
- *
- * The pbc type is wrapped in PeriodicBoundaryConditionType to
- * allow the MdModuleNotifier to statically distinguish the callback
- * function type from other 'int' function callbacks.
- *
- * \param[in] pbc MdModuleNotification class that contains a variable
- * that enumerates the periodic boundary condition.
- */
- void setPeriodicBoundaryConditionType(PeriodicBoundaryConditionType pbc)
- {
- pbcType_ = std::make_unique<int>(pbc.pbcType);
- }
-
- //! Get the periodic boundary conditions
- int periodicBoundaryConditionType()
- {
- if (pbcType_ == nullptr)
- {
- GMX_THROW(InternalError("Periodic boundary condition enum not set for density guided simulation."));
- }
- return *pbcType_;
- }
-
- //! Set the simulation time step
- void setSimulationTimeStep(double timeStep)
- {
- simulationTimeStep_ = timeStep;
- }
-
- //! Return the simulation time step
- double simulationTimeStep()
- {
- return simulationTimeStep_;
- }
-
- private:
- //! The reference density to fit to
- std::unique_ptr<MultiDimArray<std::vector<float>, dynamicExtents3D> > referenceDensity_;
- //! The coordinate transformation into the reference density
- std::unique_ptr<TranslateAndScale> transformationToDensityLattice_;
- //! The local atom set to act on
- std::unique_ptr<LocalAtomSet> localAtomSet_;
- //! The type of periodic boundary conditions in the simulation
- std::unique_ptr<int> pbcType_;
- //! The simulation time step
- double simulationTimeStep_ = 1;
-
- GMX_DISALLOW_COPY_AND_ASSIGN(DensityFittingSimulationParameterSetup);
+ return *pbcType_;
+ }
+
+ //! Set the simulation time step
+ void setSimulationTimeStep(double timeStep) { simulationTimeStep_ = timeStep; }
+
+ //! Return the simulation time step
+ double simulationTimeStep() { return simulationTimeStep_; }
+
+private:
+ //! The reference density to fit to
+ std::unique_ptr<MultiDimArray<std::vector<float>, dynamicExtents3D>> referenceDensity_;
+ //! The coordinate transformation into the reference density
+ std::unique_ptr<TranslateAndScale> transformationToDensityLattice_;
+ //! The local atom set to act on
+ std::unique_ptr<LocalAtomSet> localAtomSet_;
+ //! The type of periodic boundary conditions in the simulation
+ std::unique_ptr<int> pbcType_;
+ //! The simulation time step
+ double simulationTimeStep_ = 1;
+
+ GMX_DISALLOW_COPY_AND_ASSIGN(DensityFittingSimulationParameterSetup);
};
/*! \internal
*/
class DensityFitting final : public IMDModule
{
- public:
- /*! \brief Construct the density fitting module.
- *
- * \param[in] notifier allows the module to subscribe to notifications from MdModules.
- *
- * The density fitting code subscribes to these notifications:
- * - setting atom group indices in the densityFittingOptions_ by
- * taking a parmeter const IndexGroupsAndNames &
- * - storing its internal parameters in a tpr file by writing to a
- * key-value-tree during pre-processing by a function taking a
- * KeyValueTreeObjectBuilder as parameter
- * - reading its internal parameters from a key-value-tree during
- * simulation setup by taking a const KeyValueTreeObject & parameter
- * - constructing local atom sets in the simulation parameter setup
- * by taking a LocalAtomSetManager * as parameter
- * - the type of periodic boundary conditions that are used
- * by taking a PeriodicBoundaryConditionType as parameter
- * - the writing of checkpoint data
- * by taking a MdModulesWriteCheckpointData as parameter
- * - the reading of checkpoint data
- * by taking a MdModulesCheckpointReadingDataOnMaster as parameter
- * - the broadcasting of checkpoint data
- * by taking MdModulesCheckpointReadingBroadcast as parameter
- */
- explicit DensityFitting(MdModulesNotifier *notifier)
- {
- // Callbacks for several kinds of MdModuleNotification are created
- // and subscribed, and will be dispatched correctly at run time
- // based on the type of the parameter required by the lambda.
-
- // Setting atom group indices
- const auto setFitGroupIndicesFunction = [this](const IndexGroupsAndNames &indexGroupsAndNames) {
- densityFittingOptions_.setFitGroupIndices(indexGroupsAndNames);
- };
- notifier->notifier_.subscribe(setFitGroupIndicesFunction);
-
- // Writing internal parameters during pre-processing
- const auto writeInternalParametersFunction = [this](KeyValueTreeObjectBuilder treeBuilder) {
- densityFittingOptions_.writeInternalParametersToKvt(treeBuilder);
- };
- notifier->notifier_.subscribe(writeInternalParametersFunction);
-
- // Reading internal parameters during simulation setup
- const auto readInternalParametersFunction = [this](const KeyValueTreeObject &tree) {
- densityFittingOptions_.readInternalParametersFromKvt(tree);
- };
- notifier->notifier_.subscribe(readInternalParametersFunction);
-
- // Checking for consistency with all .mdp options
- const auto checkEnergyCaluclationFrequencyFunction = [this](EnergyCalculationFrequencyErrors * energyCalculationFrequencyErrors) {
+public:
+ /*! \brief Construct the density fitting module.
+ *
+ * \param[in] notifier allows the module to subscribe to notifications from MdModules.
+ *
+ * The density fitting code subscribes to these notifications:
+ * - setting atom group indices in the densityFittingOptions_ by
+ * taking a parmeter const IndexGroupsAndNames &
+ * - storing its internal parameters in a tpr file by writing to a
+ * key-value-tree during pre-processing by a function taking a
+ * KeyValueTreeObjectBuilder as parameter
+ * - reading its internal parameters from a key-value-tree during
+ * simulation setup by taking a const KeyValueTreeObject & parameter
+ * - constructing local atom sets in the simulation parameter setup
+ * by taking a LocalAtomSetManager * as parameter
+ * - the type of periodic boundary conditions that are used
+ * by taking a PeriodicBoundaryConditionType as parameter
+ * - the writing of checkpoint data
+ * by taking a MdModulesWriteCheckpointData as parameter
+ * - the reading of checkpoint data
+ * by taking a MdModulesCheckpointReadingDataOnMaster as parameter
+ * - the broadcasting of checkpoint data
+ * by taking MdModulesCheckpointReadingBroadcast as parameter
+ */
+ explicit DensityFitting(MdModulesNotifier* notifier)
+ {
+ // Callbacks for several kinds of MdModuleNotification are created
+ // and subscribed, and will be dispatched correctly at run time
+ // based on the type of the parameter required by the lambda.
+
+ // Setting atom group indices
+ const auto setFitGroupIndicesFunction = [this](const IndexGroupsAndNames& indexGroupsAndNames) {
+ densityFittingOptions_.setFitGroupIndices(indexGroupsAndNames);
+ };
+ notifier->notifier_.subscribe(setFitGroupIndicesFunction);
+
+ // Writing internal parameters during pre-processing
+ const auto writeInternalParametersFunction = [this](KeyValueTreeObjectBuilder treeBuilder) {
+ densityFittingOptions_.writeInternalParametersToKvt(treeBuilder);
+ };
+ notifier->notifier_.subscribe(writeInternalParametersFunction);
+
+ // Reading internal parameters during simulation setup
+ const auto readInternalParametersFunction = [this](const KeyValueTreeObject& tree) {
+ densityFittingOptions_.readInternalParametersFromKvt(tree);
+ };
+ notifier->notifier_.subscribe(readInternalParametersFunction);
+
+ // Checking for consistency with all .mdp options
+ const auto checkEnergyCaluclationFrequencyFunction =
+ [this](EnergyCalculationFrequencyErrors* energyCalculationFrequencyErrors) {
densityFittingOptions_.checkEnergyCaluclationFrequency(energyCalculationFrequencyErrors);
};
- notifier->notifier_.subscribe(checkEnergyCaluclationFrequencyFunction);
-
- // constructing local atom sets during simulation setup
- const auto setLocalAtomSetFunction = [this](LocalAtomSetManager *localAtomSetManager) {
- this->constructLocalAtomSet(localAtomSetManager);
- };
- notifier->notifier_.subscribe(setLocalAtomSetFunction);
-
- // constructing local atom sets during simulation setup
- const auto setPeriodicBoundaryContionsFunction = [this](PeriodicBoundaryConditionType pbc) {
- this->densityFittingSimulationParameters_.setPeriodicBoundaryConditionType(pbc);
- };
- notifier->notifier_.subscribe(setPeriodicBoundaryContionsFunction);
-
- // setting the simulation time step
- const auto setSimulationTimeStepFunction = [this](const SimulationTimeStep &simulationTimeStep) {
- this->densityFittingSimulationParameters_.setSimulationTimeStep(simulationTimeStep.delta_t);
- };
- notifier->notifier_.subscribe(setSimulationTimeStepFunction);
-
- // adding output to energy file
- const auto requestEnergyOutput
- = [this](MdModulesEnergyOutputToDensityFittingRequestChecker *energyOutputRequest) {
- this->setEnergyOutputRequest(energyOutputRequest);
- };
- notifier->notifier_.subscribe(requestEnergyOutput);
-
- // writing checkpoint data
- const auto checkpointDataWriting = [this](MdModulesWriteCheckpointData checkpointData) {
- this->writeCheckpointData(checkpointData);
- };
- notifier->notifier_.subscribe(checkpointDataWriting);
-
- // reading checkpoint data
- const auto checkpointDataReading = [this](MdModulesCheckpointReadingDataOnMaster checkpointData) {
- this->readCheckpointDataOnMaster(checkpointData);
- };
- notifier->notifier_.subscribe(checkpointDataReading);
-
- // broadcasting checkpoint data
- const auto checkpointDataBroadcast = [this](MdModulesCheckpointReadingBroadcast checkpointData) {
- this->broadcastCheckpointData(checkpointData);
+ notifier->notifier_.subscribe(checkEnergyCaluclationFrequencyFunction);
+
+ // constructing local atom sets during simulation setup
+ const auto setLocalAtomSetFunction = [this](LocalAtomSetManager* localAtomSetManager) {
+ this->constructLocalAtomSet(localAtomSetManager);
+ };
+ notifier->notifier_.subscribe(setLocalAtomSetFunction);
+
+ // constructing local atom sets during simulation setup
+ const auto setPeriodicBoundaryContionsFunction = [this](PeriodicBoundaryConditionType pbc) {
+ this->densityFittingSimulationParameters_.setPeriodicBoundaryConditionType(pbc);
+ };
+ notifier->notifier_.subscribe(setPeriodicBoundaryContionsFunction);
+
+ // setting the simulation time step
+ const auto setSimulationTimeStepFunction = [this](const SimulationTimeStep& simulationTimeStep) {
+ this->densityFittingSimulationParameters_.setSimulationTimeStep(simulationTimeStep.delta_t);
+ };
+ notifier->notifier_.subscribe(setSimulationTimeStepFunction);
+
+ // adding output to energy file
+ const auto requestEnergyOutput =
+ [this](MdModulesEnergyOutputToDensityFittingRequestChecker* energyOutputRequest) {
+ this->setEnergyOutputRequest(energyOutputRequest);
};
- notifier->notifier_.subscribe(checkpointDataBroadcast);
- }
-
- //! From IMDModule
- IMdpOptionProvider *mdpOptionProvider() override { return &densityFittingOptions_; }
-
- //! Add this module to the force providers if active
- void initForceProviders(ForceProviders *forceProviders) override
+ notifier->notifier_.subscribe(requestEnergyOutput);
+
+ // writing checkpoint data
+ const auto checkpointDataWriting = [this](MdModulesWriteCheckpointData checkpointData) {
+ this->writeCheckpointData(checkpointData);
+ };
+ notifier->notifier_.subscribe(checkpointDataWriting);
+
+ // reading checkpoint data
+ const auto checkpointDataReading = [this](MdModulesCheckpointReadingDataOnMaster checkpointData) {
+ this->readCheckpointDataOnMaster(checkpointData);
+ };
+ notifier->notifier_.subscribe(checkpointDataReading);
+
+ // broadcasting checkpoint data
+ const auto checkpointDataBroadcast = [this](MdModulesCheckpointReadingBroadcast checkpointData) {
+ this->broadcastCheckpointData(checkpointData);
+ };
+ notifier->notifier_.subscribe(checkpointDataBroadcast);
+ }
+
+ //! From IMDModule
+ IMdpOptionProvider* mdpOptionProvider() override { return &densityFittingOptions_; }
+
+ //! Add this module to the force providers if active
+ void initForceProviders(ForceProviders* forceProviders) override
+ {
+ if (densityFittingOptions_.active())
{
- if (densityFittingOptions_.active())
+ const auto& parameters = densityFittingOptions_.buildParameters();
+ densityFittingSimulationParameters_.readReferenceDensityFromFile(
+ densityFittingOptions_.referenceDensityFileName());
+ if (parameters.normalizeDensities_)
{
- const auto ¶meters = densityFittingOptions_.buildParameters();
- densityFittingSimulationParameters_.readReferenceDensityFromFile(densityFittingOptions_.referenceDensityFileName());
- if (parameters.normalizeDensities_)
- {
- densityFittingSimulationParameters_.normalizeReferenceDensity();
- }
- forceProvider_ = std::make_unique<DensityFittingForceProvider>(
- parameters,
- densityFittingSimulationParameters_.referenceDensity(),
- densityFittingSimulationParameters_.transformationToDensityLattice(),
- densityFittingSimulationParameters_.localAtomSet(),
- densityFittingSimulationParameters_.periodicBoundaryConditionType(),
- densityFittingSimulationParameters_.simulationTimeStep(),
- densityFittingState_);
- forceProviders->addForceProvider(forceProvider_.get());
+ densityFittingSimulationParameters_.normalizeReferenceDensity();
}
+ forceProvider_ = std::make_unique<DensityFittingForceProvider>(
+ parameters, densityFittingSimulationParameters_.referenceDensity(),
+ densityFittingSimulationParameters_.transformationToDensityLattice(),
+ densityFittingSimulationParameters_.localAtomSet(),
+ densityFittingSimulationParameters_.periodicBoundaryConditionType(),
+ densityFittingSimulationParameters_.simulationTimeStep(), densityFittingState_);
+ forceProviders->addForceProvider(forceProvider_.get());
}
-
- //! This MDModule provides its own output
- IMDOutputProvider *outputProvider() override { return &densityFittingOutputProvider_; }
-
- /*! \brief Set up the local atom sets that are used by this module.
- *
- * \note When density fitting is set up with MdModuleNotification in
- * the constructor, this function is called back.
- *
- * \param[in] localAtomSetManager the manager to add local atom sets.
- */
- void constructLocalAtomSet(LocalAtomSetManager * localAtomSetManager)
+ }
+
+ //! This MDModule provides its own output
+ IMDOutputProvider* outputProvider() override { return &densityFittingOutputProvider_; }
+
+ /*! \brief Set up the local atom sets that are used by this module.
+ *
+ * \note When density fitting is set up with MdModuleNotification in
+ * the constructor, this function is called back.
+ *
+ * \param[in] localAtomSetManager the manager to add local atom sets.
+ */
+ void constructLocalAtomSet(LocalAtomSetManager* localAtomSetManager)
+ {
+ if (densityFittingOptions_.active())
{
- if (densityFittingOptions_.active())
- {
- LocalAtomSet atomSet
- = localAtomSetManager->add(densityFittingOptions_.buildParameters().indices_);
- densityFittingSimulationParameters_.setLocalAtomSet(atomSet);
- }
+ LocalAtomSet atomSet =
+ localAtomSetManager->add(densityFittingOptions_.buildParameters().indices_);
+ densityFittingSimulationParameters_.setLocalAtomSet(atomSet);
}
-
- /*! \brief Request energy output to energy file during simulation.
- */
- void setEnergyOutputRequest(MdModulesEnergyOutputToDensityFittingRequestChecker *energyOutputRequest)
+ }
+
+ /*! \brief Request energy output to energy file during simulation.
+ */
+ void setEnergyOutputRequest(MdModulesEnergyOutputToDensityFittingRequestChecker* energyOutputRequest)
+ {
+ energyOutputRequest->energyOutputToDensityFitting_ = densityFittingOptions_.active();
+ }
+
+ /*! \brief Write internal density fitting data to checkpoint file.
+ * \param[in] checkpointWriting enables writing to the Key-Value-Tree
+ * that is used for storing the checkpoint
+ * information
+ */
+ void writeCheckpointData(MdModulesWriteCheckpointData checkpointWriting)
+ {
+ if (densityFittingOptions_.active())
{
- energyOutputRequest->energyOutputToDensityFitting_ = densityFittingOptions_.active();
+ const DensityFittingForceProviderState& state = forceProvider_->state();
+ checkpointWriting.builder_.addValue<std::int64_t>(
+ DensityFittingModuleInfo::name_ + "-stepsSinceLastCalculation",
+ state.stepsSinceLastCalculation_);
+ checkpointWriting.builder_.addValue<real>(
+ DensityFittingModuleInfo::name_ + "-adaptiveForceConstantScale",
+ state.adaptiveForceConstantScale_);
+ KeyValueTreeObjectBuilder exponentialMovingAverageKvtEntry =
+ checkpointWriting.builder_.addObject(DensityFittingModuleInfo::name_
+ + "-exponentialMovingAverageState");
+ exponentialMovingAverageStateAsKeyValueTree(exponentialMovingAverageKvtEntry,
+ state.exponentialMovingAverageState_);
}
-
- /*! \brief Write internal density fitting data to checkpoint file.
- * \param[in] checkpointWriting enables writing to the Key-Value-Tree
- * that is used for storing the checkpoint
- * information
- */
- void writeCheckpointData(MdModulesWriteCheckpointData checkpointWriting)
+ }
+
+ /*! \brief Read the internal parameters from the checkpoint file on master
+ * \param[in] checkpointReading holding the checkpoint information
+ */
+ void readCheckpointDataOnMaster(MdModulesCheckpointReadingDataOnMaster checkpointReading)
+ {
+ if (densityFittingOptions_.active())
{
- if (densityFittingOptions_.active())
+ if (checkpointReading.checkpointedData_.keyExists(DensityFittingModuleInfo::name_
+ + "-stepsSinceLastCalculation"))
{
- const DensityFittingForceProviderState &state =
- forceProvider_->state();
- checkpointWriting.builder_.addValue<std::int64_t>(
- DensityFittingModuleInfo::name_ + "-stepsSinceLastCalculation",
- state.stepsSinceLastCalculation_);
- checkpointWriting.builder_.addValue<real>(
- DensityFittingModuleInfo::name_ + "-adaptiveForceConstantScale",
- state.adaptiveForceConstantScale_);
- KeyValueTreeObjectBuilder exponentialMovingAverageKvtEntry =
- checkpointWriting.builder_.addObject(
- DensityFittingModuleInfo::name_ + "-exponentialMovingAverageState");
- exponentialMovingAverageStateAsKeyValueTree(exponentialMovingAverageKvtEntry, state.exponentialMovingAverageState_);
+ densityFittingState_.stepsSinceLastCalculation_ =
+ checkpointReading
+ .checkpointedData_[DensityFittingModuleInfo::name_
+ + "-stepsSinceLastCalculation"]
+ .cast<std::int64_t>();
}
- }
-
- /*! \brief Read the internal parameters from the checkpoint file on master
- * \param[in] checkpointReading holding the checkpoint information
- */
- void readCheckpointDataOnMaster(MdModulesCheckpointReadingDataOnMaster checkpointReading)
- {
- if (densityFittingOptions_.active())
+ if (checkpointReading.checkpointedData_.keyExists(DensityFittingModuleInfo::name_
+ + "-adaptiveForceConstantScale"))
{
- if (checkpointReading.checkpointedData_.keyExists(
- DensityFittingModuleInfo::name_ + "-stepsSinceLastCalculation"))
- {
- densityFittingState_.stepsSinceLastCalculation_ =
- checkpointReading.checkpointedData_[
- DensityFittingModuleInfo::name_ + "-stepsSinceLastCalculation"].cast<std::int64_t>();
- }
- if (checkpointReading.checkpointedData_.keyExists(DensityFittingModuleInfo::name_ + "-adaptiveForceConstantScale"))
- {
- densityFittingState_.adaptiveForceConstantScale_
- = checkpointReading
- .checkpointedData_[DensityFittingModuleInfo::name_ + "-adaptiveForceConstantScale"].cast<real>();
- }
- if (checkpointReading.checkpointedData_.keyExists(
- DensityFittingModuleInfo::name_ + "-exponentialMovingAverageState"))
- {
- densityFittingState_.exponentialMovingAverageState_ =
- exponentialMovingAverageStateFromKeyValueTree(checkpointReading
- .checkpointedData_[DensityFittingModuleInfo::name_ + "-exponentialMovingAverageState"].asObject());
- }
+ densityFittingState_.adaptiveForceConstantScale_ =
+ checkpointReading
+ .checkpointedData_[DensityFittingModuleInfo::name_
+ + "-adaptiveForceConstantScale"]
+ .cast<real>();
+ }
+ if (checkpointReading.checkpointedData_.keyExists(DensityFittingModuleInfo::name_
+ + "-exponentialMovingAverageState"))
+ {
+ densityFittingState_.exponentialMovingAverageState_ = exponentialMovingAverageStateFromKeyValueTree(
+ checkpointReading
+ .checkpointedData_[DensityFittingModuleInfo::name_ + "-exponentialMovingAverageState"]
+ .asObject());
}
}
-
- /*! \brief Broadcast the internal parameters.
- * \param[in] checkpointBroadcast containing the communication record to
- * broadcast the checkpoint information
- */
- void broadcastCheckpointData(MdModulesCheckpointReadingBroadcast checkpointBroadcast)
+ }
+
+ /*! \brief Broadcast the internal parameters.
+ * \param[in] checkpointBroadcast containing the communication record to
+ * broadcast the checkpoint information
+ */
+ void broadcastCheckpointData(MdModulesCheckpointReadingBroadcast checkpointBroadcast)
+ {
+ if (densityFittingOptions_.active())
{
- if (densityFittingOptions_.active())
+ if (PAR(&(checkpointBroadcast.cr_)))
{
- if (PAR(&(checkpointBroadcast.cr_)))
- {
- block_bc(&(checkpointBroadcast.cr_), densityFittingState_.stepsSinceLastCalculation_);
- block_bc(&(checkpointBroadcast.cr_), densityFittingState_.adaptiveForceConstantScale_);
- block_bc(&(checkpointBroadcast.cr_), densityFittingState_.exponentialMovingAverageState_);
- }
+ block_bc(&(checkpointBroadcast.cr_), densityFittingState_.stepsSinceLastCalculation_);
+ block_bc(&(checkpointBroadcast.cr_), densityFittingState_.adaptiveForceConstantScale_);
+ block_bc(&(checkpointBroadcast.cr_), densityFittingState_.exponentialMovingAverageState_);
}
}
-
- private:
- //! The output provider
- DensityFittingOutputProvider densityFittingOutputProvider_;
- //! The options provided for density fitting
- DensityFittingOptions densityFittingOptions_;
- //! Object that evaluates the forces
- std::unique_ptr<DensityFittingForceProvider> forceProvider_;
- /*! \brief Parameters for density fitting that become available at
- * simulation setup time.
- */
- DensityFittingSimulationParameterSetup densityFittingSimulationParameters_;
- //! The internal parameters of density fitting force provider
- DensityFittingForceProviderState densityFittingState_;
-
- GMX_DISALLOW_COPY_AND_ASSIGN(DensityFitting);
+ }
+
+private:
+ //! The output provider
+ DensityFittingOutputProvider densityFittingOutputProvider_;
+ //! The options provided for density fitting
+ DensityFittingOptions densityFittingOptions_;
+ //! Object that evaluates the forces
+ std::unique_ptr<DensityFittingForceProvider> forceProvider_;
+ /*! \brief Parameters for density fitting that become available at
+ * simulation setup time.
+ */
+ DensityFittingSimulationParameterSetup densityFittingSimulationParameters_;
+ //! The internal parameters of density fitting force provider
+ DensityFittingForceProviderState densityFittingState_;
+
+ GMX_DISALLOW_COPY_AND_ASSIGN(DensityFitting);
};
-} // namespace
+} // namespace
-std::unique_ptr<IMDModule> DensityFittingModuleInfo::create(MdModulesNotifier * notifier)
+std::unique_ptr<IMDModule> DensityFittingModuleInfo::create(MdModulesNotifier* notifier)
{
return std::make_unique<DensityFitting>(notifier);
}