From c154e32174cbfcf8cd16a9272140541febb5f0f7 Mon Sep 17 00:00:00 2001 From: Christian Blau Date: Tue, 13 Aug 2019 15:44:36 +0200 Subject: [PATCH] Activation of density fitting and move of module notifications The densityfitting code is activated by adding it to the MDModules. Moved the MdModuleNotifications to mdrunutility to break cyclic module dependencies between mdrun and applied_forces via MdModules and DensityFittingModuleInfo. Observe that this patch changes the default .mdp output. Updated reference data accordingly. Note that the changes in .mdp output lead to "check mdp file differences" warning in the regression tests. refs #2283 Change-Id: I93c0dd85285cac3f9e94d2dfc7c7fcc434aa81db --- docs/doxygen/lib/mdmodules.md | 14 ++++----- src/gromacs/applied_forces/densityfitting.cpp | 10 ++++-- src/gromacs/applied_forces/densityfitting.h | 3 +- .../applied_forces/tests/CMakeLists.txt | 1 + .../applied_forces/tests/densityfitting.cpp | 4 ++- src/gromacs/gmxpreprocess/grompp.cpp | 3 +- src/gromacs/gmxpreprocess/readir.cpp | 5 +-- src/gromacs/gmxpreprocess/readir.h | 4 +-- ...GetIrTest_DefineHandlesAssignmentOnRhs.xml | 1 + .../refdata/GetIrTest_EmptyInputWorks.xml | 1 + ...IrTest_HandlesDifferentKindsOfMdpLines.xml | 1 + .../tests/refdata/GetIrTest_HandlesMimic.xml | 1 + .../GetIrTest_HandlesOnlyCutoffScheme.xml | 1 + .../GetIrTest_ImplicitSolventNoWorks.xml | 1 + ...IrTest_ProducesOutputFromElectricField.xml | 1 + ...ucesOutputFromElectricFieldOscillating.xml | 1 + ..._ProducesOutputFromElectricFieldPulsed.xml | 1 + .../GetIrTest_UserErrorsSilentlyTolerated.xml | 1 + src/gromacs/mdrun/mdmodules.cpp | 16 ++++++++-- src/gromacs/mdrun/mdmodules.h | 31 +++---------------- src/gromacs/mdrun/runner.cpp | 11 ++++--- .../mdmodulenotification.h | 22 +++++++++++-- .../mdrun/tests/mdmodulenotification.cpp | 2 +- 23 files changed, 80 insertions(+), 56 deletions(-) rename src/gromacs/{mdrun => mdrunutility}/mdmodulenotification.h (93%) diff --git a/docs/doxygen/lib/mdmodules.md b/docs/doxygen/lib/mdmodules.md index a531b5a1b5..9d6ea6bf9c 100644 --- a/docs/doxygen/lib/mdmodules.md +++ b/docs/doxygen/lib/mdmodules.md @@ -159,13 +159,13 @@ Callbacks to modules during setup and simulation During setup and simulation, modules receive required information like topologies and local atom sets by subscribing to callback functions. -To include a notification for your module, +To include a notification for your module -* Add the function signature for the callback function to the `notifier_type` - in the MdModules class +* Add the function signature for the callback function to the + `MdModulesNotifier` in `mdmodulenotification.h`, ```C++ - notifier_type = registerMdModuleNotification<..., + registerMdModulesNotification<..., YourCallbackSignature, ..., ``` @@ -177,11 +177,11 @@ To include a notification for your module, * Add the function you want to subscribe with in the builder, `notifier->subscribe(yourFunction)` - + * To subscribe class member functions of your module, you can use lambda expressions ```C++ - notifier->subscribe([modulePointer = yourModule.get()] + notifier->notifier_.subscribe([modulePointer = yourModule.get()] (YourCallbackSignature argument){modulePointer(argument);}); ``` @@ -189,7 +189,7 @@ To include a notification for your module, ```C++ YourCallbackSignature argument(); - mdModules_.notifier().notify(argument); + mdModules_.notifier().notifier_.notify(argument); ``` Storing non-mdp option module parameters diff --git a/src/gromacs/applied_forces/densityfitting.cpp b/src/gromacs/applied_forces/densityfitting.cpp index be7dbbc1d4..7b8b9fb2ea 100644 --- a/src/gromacs/applied_forces/densityfitting.cpp +++ b/src/gromacs/applied_forces/densityfitting.cpp @@ -43,6 +43,7 @@ #include "densityfitting.h" +#include "gromacs/mdrunutility/mdmodulenotification.h" #include "gromacs/mdtypes/imdmodule.h" #include "densityfittingforceprovider.h" @@ -67,7 +68,10 @@ namespace class DensityFitting final : public IMDModule { public: - DensityFitting() = default; + /*! \brief Construct the density fitting module. + * Allow the module to subscribe to notifications from MdModules + */ + explicit DensityFitting(MdModulesNotifier * /*notifier*/){} //! From IMDModule; this class provides the mdpOptions itself IMdpOptionProvider *mdpOptionProvider() override { return &densityFittingOptions_; } @@ -97,9 +101,9 @@ class DensityFitting final : public IMDModule } // namespace -std::unique_ptr DensityFittingModuleInfo::create() +std::unique_ptr DensityFittingModuleInfo::create(MdModulesNotifier * notifier) { - return std::unique_ptr(new DensityFitting()); + return std::make_unique(notifier); } const std::string DensityFittingModuleInfo::name_ = "density-guided-simulation"; diff --git a/src/gromacs/applied_forces/densityfitting.h b/src/gromacs/applied_forces/densityfitting.h index 5be641f315..ebdf321641 100644 --- a/src/gromacs/applied_forces/densityfitting.h +++ b/src/gromacs/applied_forces/densityfitting.h @@ -42,6 +42,7 @@ namespace gmx { class IMDModule; +struct MdModulesNotifier; /*! \libinternal \brief Information about the density fitting module. * @@ -55,7 +56,7 @@ struct DensityFittingModuleInfo * Fitting an all-atom structure into an experimental cryo-EM density map is a * typical application. */ - static std::unique_ptr create(); + static std::unique_ptr create(MdModulesNotifier * notifier); //! The name of the module static const std::string name_; }; diff --git a/src/gromacs/applied_forces/tests/CMakeLists.txt b/src/gromacs/applied_forces/tests/CMakeLists.txt index d9cd94c6da..87c0275638 100644 --- a/src/gromacs/applied_forces/tests/CMakeLists.txt +++ b/src/gromacs/applied_forces/tests/CMakeLists.txt @@ -33,6 +33,7 @@ # the research papers on the package. Check out http://www.gromacs.org. gmx_add_unit_test(AppliedForcesUnitTest applied_forces-test + densityfitting.cpp densityfittingoptions.cpp densityfittingamplitudelookup.cpp electricfield.cpp diff --git a/src/gromacs/applied_forces/tests/densityfitting.cpp b/src/gromacs/applied_forces/tests/densityfitting.cpp index ddf9502372..a85a7d2e46 100644 --- a/src/gromacs/applied_forces/tests/densityfitting.cpp +++ b/src/gromacs/applied_forces/tests/densityfitting.cpp @@ -48,6 +48,7 @@ #include "gromacs/gmxlib/network.h" #include "gromacs/math/paddedvector.h" #include "gromacs/math/vec.h" +#include "gromacs/mdrunutility/mdmodulenotification.h" #include "gromacs/mdtypes/enerdata.h" #include "gromacs/mdtypes/forceoutput.h" #include "gromacs/mdtypes/iforceprovider.h" @@ -73,7 +74,8 @@ namespace TEST(DensityFittingTest, ForceOnSingleOption) { - auto densityFittingModule(DensityFittingModuleInfo::create()); + MdModulesNotifier notifier; + auto densityFittingModule(DensityFittingModuleInfo::create(¬ifier)); // Prepare MDP inputs KeyValueTreeBuilder mdpValueBuilder; diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index 45bc7aa83a..f15c17ba7d 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -82,6 +82,7 @@ #include "gromacs/mdlib/qmmm.h" #include "gromacs/mdlib/vsite.h" #include "gromacs/mdrun/mdmodules.h" +#include "gromacs/mdrunutility/mdmodulenotification.h" #include "gromacs/mdtypes/inputrec.h" #include "gromacs/mdtypes/md_enums.h" #include "gromacs/mdtypes/nblist.h" @@ -2424,7 +2425,7 @@ int gmx_grompp(int argc, char *argv[]) { gmx::KeyValueTreeBuilder internalParameterBuilder; - mdModules.notifier().notify(&internalParameterBuilder); + mdModules.notifier().notifier_.notify(&internalParameterBuilder); ir->internalParameters = std::make_unique(internalParameterBuilder.build()); } diff --git a/src/gromacs/gmxpreprocess/readir.cpp b/src/gromacs/gmxpreprocess/readir.cpp index 235aec60ec..954dcffaa9 100644 --- a/src/gromacs/gmxpreprocess/readir.cpp +++ b/src/gromacs/gmxpreprocess/readir.cpp @@ -57,6 +57,7 @@ #include "gromacs/math/vec.h" #include "gromacs/mdlib/calc_verletbuf.h" #include "gromacs/mdrun/mdmodules.h" +#include "gromacs/mdrunutility/mdmodulenotification.h" #include "gromacs/mdtypes/inputrec.h" #include "gromacs/mdtypes/md_enums.h" #include "gromacs/mdtypes/pull_params.h" @@ -3051,7 +3052,7 @@ static void make_IMD_group(t_IMD *IMDgroup, char *IMDgname, t_blocka *grps, char void do_index(const char* mdparin, const char *ndx, gmx_mtop_t *mtop, bool bVerbose, - const gmx::MDModules::notifier_type ¬ifier, + const gmx::MdModulesNotifier ¬ifier, t_inputrec *ir, warninp_t wi) { @@ -3400,7 +3401,7 @@ void do_index(const char* mdparin, const char *ndx, gmx::IndexGroupsAndNames defaultIndexGroupsAndNames( *defaultIndexGroups, gmx::arrayRefFromArray(gnames, defaultIndexGroups->nr)); - notifier.notify(defaultIndexGroupsAndNames); + notifier.notifier_.notify(defaultIndexGroupsAndNames); auto accelerations = gmx::splitString(is->acc); auto accelerationGroupNames = gmx::splitString(is->accgrps); diff --git a/src/gromacs/gmxpreprocess/readir.h b/src/gromacs/gmxpreprocess/readir.h index d6a25eca5f..3be50585b5 100644 --- a/src/gromacs/gmxpreprocess/readir.h +++ b/src/gromacs/gmxpreprocess/readir.h @@ -40,12 +40,12 @@ #include "gromacs/fileio/readinp.h" #include "gromacs/math/vectypes.h" -#include "gromacs/mdrun/mdmodules.h" #include "gromacs/utility/real.h" namespace gmx { class MDModules; +struct MdModulesNotifier; } struct gmx_mtop_t; @@ -128,7 +128,7 @@ void do_index(const char * mdparin, const char *ndx, gmx_mtop_t *mtop, bool bVerbose, - const gmx::MDModules::notifier_type ¬ifier, + const gmx::MdModulesNotifier ¬ifier, t_inputrec *ir, warninp_t wi); /* Read the index file and assign grp numbers to atoms. diff --git a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_DefineHandlesAssignmentOnRhs.xml b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_DefineHandlesAssignmentOnRhs.xml index 95038d7d53..d6a6c525a8 100644 --- a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_DefineHandlesAssignmentOnRhs.xml +++ b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_DefineHandlesAssignmentOnRhs.xml @@ -317,5 +317,6 @@ userreal4 = 0 electric-field-x = 0 0 0 0 electric-field-y = 0 0 0 0 electric-field-z = 0 0 0 0 +density-guided-simulation-active = false diff --git a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_EmptyInputWorks.xml b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_EmptyInputWorks.xml index c0edc1f5e2..1ad5d1e06d 100644 --- a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_EmptyInputWorks.xml +++ b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_EmptyInputWorks.xml @@ -317,5 +317,6 @@ userreal4 = 0 electric-field-x = 0 0 0 0 electric-field-y = 0 0 0 0 electric-field-z = 0 0 0 0 +density-guided-simulation-active = false diff --git a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesDifferentKindsOfMdpLines.xml b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesDifferentKindsOfMdpLines.xml index 538864d80b..e643904413 100644 --- a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesDifferentKindsOfMdpLines.xml +++ b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesDifferentKindsOfMdpLines.xml @@ -317,5 +317,6 @@ userreal4 = 0 electric-field-x = 0 0 0 0 electric-field-y = 0 0 0 0 electric-field-z = 0 0 0 0 +density-guided-simulation-active = false diff --git a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesMimic.xml b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesMimic.xml index 55c0ed7e3b..b9f5f4b6db 100644 --- a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesMimic.xml +++ b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesMimic.xml @@ -317,5 +317,6 @@ userreal4 = 0 electric-field-x = 0 0 0 0 electric-field-y = 0 0 0 0 electric-field-z = 0 0 0 0 +density-guided-simulation-active = false diff --git a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesOnlyCutoffScheme.xml b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesOnlyCutoffScheme.xml index cc6a71bdc6..5e82a41212 100644 --- a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesOnlyCutoffScheme.xml +++ b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_HandlesOnlyCutoffScheme.xml @@ -317,5 +317,6 @@ userreal4 = 0 electric-field-x = 0 0 0 0 electric-field-y = 0 0 0 0 electric-field-z = 0 0 0 0 +density-guided-simulation-active = false diff --git a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ImplicitSolventNoWorks.xml b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ImplicitSolventNoWorks.xml index c0edc1f5e2..1ad5d1e06d 100644 --- a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ImplicitSolventNoWorks.xml +++ b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ImplicitSolventNoWorks.xml @@ -317,5 +317,6 @@ userreal4 = 0 electric-field-x = 0 0 0 0 electric-field-y = 0 0 0 0 electric-field-z = 0 0 0 0 +density-guided-simulation-active = false diff --git a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricField.xml b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricField.xml index 9f2bcabde7..8317682570 100644 --- a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricField.xml +++ b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricField.xml @@ -317,5 +317,6 @@ userreal4 = 0 electric-field-x = 1.2 0 0 0 electric-field-y = 0 0 0 0 electric-field-z = 0 0 0 0 +density-guided-simulation-active = false diff --git a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricFieldOscillating.xml b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricFieldOscillating.xml index 8b52b14d80..2041c81ec1 100644 --- a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricFieldOscillating.xml +++ b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricFieldOscillating.xml @@ -317,5 +317,6 @@ userreal4 = 0 electric-field-x = 0 0 0 0 electric-field-y = 0 0 0 0 electric-field-z = 3.7 7.5 0 0 +density-guided-simulation-active = false diff --git a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricFieldPulsed.xml b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricFieldPulsed.xml index 4b2df698fa..518fe2c5e8 100644 --- a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricFieldPulsed.xml +++ b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_ProducesOutputFromElectricFieldPulsed.xml @@ -317,5 +317,6 @@ userreal4 = 0 electric-field-x = 0 0 0 0 electric-field-y = 3.7 2 6.5 1 electric-field-z = 0 0 0 0 +density-guided-simulation-active = false diff --git a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_UserErrorsSilentlyTolerated.xml b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_UserErrorsSilentlyTolerated.xml index c0edc1f5e2..1ad5d1e06d 100644 --- a/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_UserErrorsSilentlyTolerated.xml +++ b/src/gromacs/gmxpreprocess/tests/refdata/GetIrTest_UserErrorsSilentlyTolerated.xml @@ -317,5 +317,6 @@ userreal4 = 0 electric-field-x = 0 0 0 0 electric-field-y = 0 0 0 0 electric-field-z = 0 0 0 0 +density-guided-simulation-active = false diff --git a/src/gromacs/mdrun/mdmodules.cpp b/src/gromacs/mdrun/mdmodules.cpp index afc285a141..2f1119c06e 100644 --- a/src/gromacs/mdrun/mdmodules.cpp +++ b/src/gromacs/mdrun/mdmodules.cpp @@ -38,8 +38,10 @@ #include +#include "gromacs/applied_forces/densityfitting.h" #include "gromacs/applied_forces/electricfield.h" #include "gromacs/imd/imd.h" +#include "gromacs/mdrunutility/mdmodulenotification.h" #include "gromacs/mdtypes/iforceprovider.h" #include "gromacs/mdtypes/imdmodule.h" #include "gromacs/mdtypes/imdoutputprovider.h" @@ -62,7 +64,8 @@ class MDModules::Impl : public IMDOutputProvider public: Impl() - : field_(createElectricFieldModule()), + : densityFitting_(DensityFittingModuleInfo::create(¬ifier_)), + field_(createElectricFieldModule()), imd_(createInteractiveMolecularDynamicsModule()), swapCoordinates_(createSwapCoordinatesModule()) { @@ -73,6 +76,7 @@ class MDModules::Impl : public IMDOutputProvider // Create a section for applied-forces modules auto appliedForcesOptions = options->addSection(OptionSection("applied-forces")); field_->mdpOptionProvider()->initMdpOptions(&appliedForcesOptions); + densityFitting_->mdpOptionProvider()->initMdpOptions(&appliedForcesOptions); // In future, other sections would also go here. } @@ -81,12 +85,15 @@ class MDModules::Impl : public IMDOutputProvider bool bAppendFiles, const gmx_output_env_t *oenv) override { field_->outputProvider()->initOutput(fplog, nfile, fnm, bAppendFiles, oenv); + densityFitting_->outputProvider()->initOutput(fplog, nfile, fnm, bAppendFiles, oenv); } void finishOutput() override { field_->outputProvider()->finishOutput(); + densityFitting_->outputProvider()->finishOutput(); } + std::unique_ptr densityFitting_; std::unique_ptr field_; std::unique_ptr forceProviders_; std::unique_ptr imd_; @@ -104,7 +111,7 @@ class MDModules::Impl : public IMDOutputProvider std::vector< std::shared_ptr > modules_; //! Manages resources and notifies the MD modules when available - MDModules::notifier_type notifier_; + MdModulesNotifier notifier_; }; MDModules::MDModules() : impl_(new Impl) @@ -119,11 +126,13 @@ void MDModules::initMdpTransform(IKeyValueTreeTransformRules *rules) { auto appliedForcesScope = rules->scopedTransform("/applied-forces"); impl_->field_->mdpOptionProvider()->initMdpTransform(appliedForcesScope.rules()); + impl_->densityFitting_->mdpOptionProvider()->initMdpTransform(appliedForcesScope.rules()); } void MDModules::buildMdpOutput(KeyValueTreeObjectBuilder *builder) { impl_->field_->mdpOptionProvider()->buildMdpOutput(builder); + impl_->densityFitting_->mdpOptionProvider()->buildMdpOutput(builder); } void MDModules::assignOptionsToModules(const KeyValueTreeObject ¶ms, @@ -161,6 +170,7 @@ ForceProviders *MDModules::initForceProviders() "Force providers initialized multiple times"); impl_->forceProviders_ = std::make_unique(); impl_->field_->initForceProviders(impl_->forceProviders_.get()); + impl_->densityFitting_->initForceProviders(impl_->forceProviders_.get()); for (auto && module : impl_->modules_) { module->initForceProviders(impl_->forceProviders_.get()); @@ -173,7 +183,7 @@ void MDModules::add(std::shared_ptr module) impl_->modules_.emplace_back(std::move(module)); } -const MDModules::notifier_type &MDModules::notifier() +const MdModulesNotifier &MDModules::notifier() { return impl_->notifier_; } diff --git a/src/gromacs/mdrun/mdmodules.h b/src/gromacs/mdrun/mdmodules.h index 1e4745198c..6f0aee6e5f 100644 --- a/src/gromacs/mdrun/mdmodules.h +++ b/src/gromacs/mdrun/mdmodules.h @@ -43,7 +43,6 @@ #ifndef GMX_MDRUN_MDMODULES_H #define GMX_MDRUN_MDMODULES_H -#include "gromacs/mdrun/mdmodulenotification.h" #include "gromacs/utility/classhelpers.h" struct ForceProviders; @@ -57,22 +56,9 @@ class KeyValueTreeObjectBuilder; class KeyValueTreeObject; class IKeyValueTreeErrorHandler; class IKeyValueTreeTransformRules; -class IMDOutputProvider; -class KeyValueTreeObject; -class KeyValueTreeBuilder; class IMDModule; -class LocalAtomSetManager; -class IndexGroupsAndNames; - -/*! \libinternal \brief - * \brief Signals that the communication record is set up and provides this record. - */ -struct CommunicationIsSetup -{ - //! The communication record that is set up. - const t_commrec &communicationRecord_; -}; - +class IMDOutputProvider; +struct MdModulesNotifier; /*! \libinternal \brief * Manages the collection of all modules used for mdrun. @@ -109,15 +95,6 @@ class MDModules MDModules(); ~MDModules(); - //! Register callback function types for MDModules - using notifier_type = registerMdModuleNotification< - CommunicationIsSetup, - IndexGroupsAndNames, - KeyValueTreeBuilder*, - const KeyValueTreeObject &, - LocalAtomSetManager * - >::type; - /*! \brief * Initializes a transform from mdp values to sectioned options. * @@ -190,11 +167,11 @@ class MDModules * MDModules should not change after some point, we should move this * to a builder class. */ - void add(std::shared_ptr module); + void add(std::shared_ptr module); /*! \brief Return a handle to the callbacks. */ - const notifier_type ¬ifier(); + const MdModulesNotifier ¬ifier(); private: class Impl; diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp index 4a7622c19b..7155d71228 100644 --- a/src/gromacs/mdrun/runner.cpp +++ b/src/gromacs/mdrun/runner.cpp @@ -98,11 +98,11 @@ #include "gromacs/mdlib/qmmm.h" #include "gromacs/mdlib/sighandler.h" #include "gromacs/mdlib/stophandler.h" -#include "gromacs/mdrun/mdmodulenotification.h" #include "gromacs/mdrun/mdmodules.h" #include "gromacs/mdrun/simulationcontext.h" #include "gromacs/mdrunutility/handlerestart.h" #include "gromacs/mdrunutility/logging.h" +#include "gromacs/mdrunutility/mdmodulenotification.h" #include "gromacs/mdrunutility/multisim.h" #include "gromacs/mdrunutility/printtime.h" #include "gromacs/mdrunutility/threadaffinity.h" @@ -799,9 +799,11 @@ int Mdrunner::mdrunner() // TODO: Error handling mdModules_->assignOptionsToModules(*inputrec->params, nullptr); + const auto &mdModulesNotifier = mdModules_->notifier().notifier_; + if (inputrec->internalParameters != nullptr) { - mdModules_->notifier().notify(*inputrec->internalParameters); + mdModulesNotifier.notify(*inputrec->internalParameters); } if (fplog != nullptr) @@ -984,7 +986,6 @@ int Mdrunner::mdrunner() useGpuForNonbonded || (emulateGpuNonbonded == EmulateGpuNonbonded::Yes), *hwinfo->cpuInfo); LocalAtomSetManager atomSets; - if (PAR(cr) && !(EI_TPI(inputrec->eI) || inputrec->eI == eiNM)) { @@ -992,7 +993,7 @@ int Mdrunner::mdrunner() &mtop, inputrec, box, positionsFromStatePointer(globalState.get()), &atomSets); - mdModules_->notifier().notify(&atomSets); + mdModulesNotifier.notify(&atomSets); // Note that local state still does not exist yet. } else @@ -1287,7 +1288,7 @@ int Mdrunner::mdrunner() t_nrnb nrnb; if (thisRankHasDuty(cr, DUTY_PP)) { - mdModules_->notifier().notify(CommunicationIsSetup {*cr}); + mdModulesNotifier.notify(*cr); /* Initiate forcerecord */ fr = new t_forcerec; fr->forceProviders = mdModules_->initForceProviders(); diff --git a/src/gromacs/mdrun/mdmodulenotification.h b/src/gromacs/mdrunutility/mdmodulenotification.h similarity index 93% rename from src/gromacs/mdrun/mdmodulenotification.h rename to src/gromacs/mdrunutility/mdmodulenotification.h index dcb273a617..dea6e1637f 100644 --- a/src/gromacs/mdrun/mdmodulenotification.h +++ b/src/gromacs/mdrunutility/mdmodulenotification.h @@ -38,11 +38,11 @@ * * \author Christian Blau * \inlibraryapi - * \ingroup module_mdrun + * \ingroup module_mdrunutility */ -#ifndef GMX_MDRUN_MDMODULENOTIFICATION_H -#define GMX_MDRUN_MDMODULENOTIFICATION_H +#ifndef GMX_MDRUNUTILITY_MDMODULENOTIFICATION_H +#define GMX_MDRUNUTILITY_MDMODULENOTIFICATION_H #include #include @@ -194,6 +194,22 @@ struct registerMdModuleNotification using type = MdModuleNotification; }; +class KeyValueTreeObject; +class KeyValueTreeBuilder; +class LocalAtomSetManager; +class IndexGroupsAndNames; + +struct MdModulesNotifier +{ +//! Register callback function types for MdModule + registerMdModuleNotification< + const t_commrec &, + IndexGroupsAndNames, + KeyValueTreeBuilder *, + const KeyValueTreeObject &, + LocalAtomSetManager *>::type notifier_; +}; + } // namespace gmx #endif diff --git a/src/programs/mdrun/tests/mdmodulenotification.cpp b/src/programs/mdrun/tests/mdmodulenotification.cpp index da70de70b7..c7356f1a19 100644 --- a/src/programs/mdrun/tests/mdmodulenotification.cpp +++ b/src/programs/mdrun/tests/mdmodulenotification.cpp @@ -43,7 +43,7 @@ #include -#include "gromacs/mdrun/mdmodulenotification.h" +#include "gromacs/mdrunutility/mdmodulenotification.h" namespace gmx { -- 2.22.0