From: Dmitry Morozov Date: Wed, 2 Jun 2021 09:41:44 +0000 (+0000) Subject: Add notifications for MDModules that will be used in QMMM X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=0e870da00caf73114c41772af125c08b42eb0123;p=alexxy%2Fgromacs.git Add notifications for MDModules that will be used in QMMM --- diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index 64d6de8c58..d33220a6f6 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -1930,6 +1930,8 @@ int gmx_grompp(int argc, char* argv[]) // to eventual notifications during pre-processing their data mdModules.subscribeToPreProcessingNotifications(); + // And notify MdModules of existing logger + mdModules.notifiers().preProcessingNotifier_.notify(logger); if (bVerbose) { @@ -2210,6 +2212,9 @@ int gmx_grompp(int argc, char* argv[]) } do_index(mdparin, ftp2fn_null(efNDX, NFILE, fnm), &sys, bVerbose, mdModules.notifiers(), ir, wi); + // Notify topology to MdModules for pre-processing after all indexes were built + mdModules.notifiers().preProcessingNotifier_.notify(&sys); + if (ir->cutoff_scheme == CutoffScheme::Verlet && ir->verletbuf_tol > 0) { if (EI_DYNAMICS(ir->eI) && inputrec2nboundeddim(ir) == 3) @@ -2489,6 +2494,15 @@ int gmx_grompp(int argc, char* argv[]) } } + // Hand over box and coordiantes to MdModules before they evaluate their final parameters + { + gmx::CoordinatesAndBoxPreprocessed coordinatesAndBoxPreprocessed; + coordinatesAndBoxPreprocessed.coordinates_ = state.x.arrayRefWithPadding(); + copy_mat(state.box, coordinatesAndBoxPreprocessed.box_); + coordinatesAndBoxPreprocessed.pbc_ = ir->pbcType; + mdModules.notifiers().preProcessingNotifier_.notify(coordinatesAndBoxPreprocessed); + } + // Add the md modules internal parameters that are not mdp options // e.g., atom indices diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp index 20c0c3e136..0fdd4d8f7c 100644 --- a/src/gromacs/mdrun/runner.cpp +++ b/src/gromacs/mdrun/runner.cpp @@ -1059,11 +1059,21 @@ int Mdrunner::mdrunner() mdModules_->subscribeToSimulationSetupNotifications(); const auto& setupNotifier = mdModules_->notifiers().simulationSetupNotifier_; + // Notify MdModules of existing logger + setupNotifier.notify(mdlog); + + // Notify MdModules of internal parameters, saved into KVT if (inputrec->internalParameters != nullptr) { setupNotifier.notify(*inputrec->internalParameters); } + // Let MdModules know the .tpr filename + { + gmx::MdRunInputFilename mdRunInputFilename = { ftp2fn(efTPR, filenames.size(), filenames.data()) }; + setupNotifier.notify(mdRunInputFilename); + } + if (fplog != nullptr) { pr_inputrec(fplog, 0, "Input Parameters", inputrec.get(), FALSE); diff --git a/src/gromacs/utility/mdmodulesnotifiers.h b/src/gromacs/utility/mdmodulesnotifiers.h index 012527fa96..9800efe324 100644 --- a/src/gromacs/utility/mdmodulesnotifiers.h +++ b/src/gromacs/utility/mdmodulesnotifiers.h @@ -47,6 +47,8 @@ #include #include +#include "gromacs/math/arrayrefwithpadding.h" +#include "gromacs/math/vectypes.h" #include "gromacs/utility/mdmodulesnotifier.h" struct t_commrec; @@ -59,6 +61,7 @@ namespace gmx class KeyValueTreeObject; class KeyValueTreeObjectBuilder; class LocalAtomSetManager; +class MDLogger; class IndexGroupsAndNames; class SeparatePmeRanksPermitted; struct MDModulesCheckpointReadingDataOnMaster; @@ -118,6 +121,23 @@ struct SimulationTimeStep const double delta_t; }; +/*! \libinternal \brief Provides coordinates and simulation box. + */ +struct CoordinatesAndBoxPreprocessed +{ + ArrayRefWithPadding coordinates_; + matrix box_; + PbcType pbc_; +}; + +/*! \libinternal \brief Mdrun input filename. + */ +struct MdRunInputFilename +{ + //! The name of the run input file (.tpr) as output by grompp + std::string mdRunFilename_; +}; + /*! \libinternal * \brief Group of notifers to organize that MDModules * can receive callbacks they subscribe to. @@ -210,17 +230,25 @@ notifier =>> moduleC [label="returns"]; */ struct MDModulesNotifiers { - /*! \brief Handles subscribing and calling pre-processing callback functions. - * + /*! \brief Pre-processing callback functions. + * const CoordinatesAndBoxPreprocessed Allows modules to access coordinates, + * box and pbc during grompp + * const MDLogger& Allows MdModule to use standard logging class for messages output * EnergyCalculationFrequencyErrors* allows modules to check if they match * their required calculation frequency * and add their error message if needed * to the collected error messages + * gmx_mtop_t * Allows modules to modify the topology during pre-processing * IndexGroupsAndNames provides modules with atom indices and their names * KeyValueTreeObjectBuilder enables writing of module internal data to * .tpr files. */ - BuildMDModulesNotifier::type preProcessingNotifier_; + BuildMDModulesNotifier::type preProcessingNotifier_; /*! \brief Handles subscribing and calling checkpointing callback functions. * @@ -243,6 +271,7 @@ struct MDModulesNotifiers * wrote to .tpr files * LocalAtomSetManager* enables modules to add atom indices to local atom sets * to be managed + * const MDLogger& Allows MdModule to use standard logging class for messages output * const gmx_mtop_t& provides the topology of the system to the modules * MDModulesEnergyOutputToDensityFittingRequestChecker* enables modules to * report if they want to write their energy output @@ -256,15 +285,18 @@ struct MDModulesNotifiers * time information * const t_commrec& provides a communicator to the modules during simulation * setup + * MdRunInputFilename Allows modules to know .tpr filename during mdrun */ BuildMDModulesNotifier::type simulationSetupNotifier_; + const t_commrec&, + MdRunInputFilename>::type simulationSetupNotifier_; }; } // namespace gmx