Add notifications for MDModules that will be used in QMMM
authorDmitry Morozov <aracsmd@gmail.com>
Wed, 2 Jun 2021 09:41:44 +0000 (09:41 +0000)
committerPaul Bauer <paul.bauer.q@gmail.com>
Wed, 2 Jun 2021 09:41:44 +0000 (09:41 +0000)
src/gromacs/gmxpreprocess/grompp.cpp
src/gromacs/mdrun/runner.cpp
src/gromacs/utility/mdmodulesnotifiers.h

index 64d6de8c58bfc06a776db0ecabe2000de861df0f..d33220a6f68ae93ad370141f7051cc94afcf0c83 100644 (file)
@@ -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
 
index 20c0c3e136ce036e67b3a38f57125d3bb83a1791..0fdd4d8f7cdcb17f5d7a72dc77bb3068861b41ff 100644 (file)
@@ -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);
index 012527fa9609bb6574c024239c305fbdaf9a6993..9800efe324890ea7919585e8be61250b3c3c1054 100644 (file)
@@ -47,6 +47,8 @@
 #include <string>
 #include <vector>
 
+#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<RVec> 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<EnergyCalculationFrequencyErrors*, const IndexGroupsAndNames&, KeyValueTreeObjectBuilder>::type preProcessingNotifier_;
+    BuildMDModulesNotifier<const CoordinatesAndBoxPreprocessed,
+                           const MDLogger&,
+                           EnergyCalculationFrequencyErrors*,
+                           gmx_mtop_t*,
+                           const IndexGroupsAndNames&,
+                           KeyValueTreeObjectBuilder>::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<const KeyValueTreeObject&,
                            LocalAtomSetManager*,
+                           const MDLogger&,
                            const gmx_mtop_t&,
                            MDModulesEnergyOutputToDensityFittingRequestChecker*,
                            SeparatePmeRanksPermitted*,
                            const PbcType&,
                            const SimulationTimeStep&,
-                           const t_commrec&>::type simulationSetupNotifier_;
+                           const t_commrec&,
+                           MdRunInputFilename>::type simulationSetupNotifier_;
 };
 
 } // namespace gmx