Allow extensible MDModules and forceProviders.
authorM. Eric Irrgang <ericirrgang@gmail.com>
Fri, 24 Aug 2018 13:49:40 +0000 (16:49 +0300)
committerKasson <kasson@gmail.com>
Wed, 29 Aug 2018 12:32:34 +0000 (14:32 +0200)
supports gmxapi milestone 6, described at #2585.

MDModules::Impl gets a std::vector for (shared) ownership of objects
providing the IMDModule interface. An add() method is added to the
MDModules public member functions, but the binding protocols are
separated into separate issues to allow minimal changes and varying
dependencies on other pending changes.

Relates to #1972, #2229, #2492, #2574, #2590.

Refs #2623

Change-Id: Ibb16d1453003213a49622810ed8bad4ed4b06e2d

src/gromacs/mdrunutility/mdmodules.cpp
src/gromacs/mdrunutility/mdmodules.h

index 62de105da3bcd378cad7f7e31d93231011e7feeb..b867b42640763868998373d95e1f55ba7acf2e88 100644 (file)
@@ -86,6 +86,9 @@ class MDModules::Impl : public IMDOutputProvider
 
         std::unique_ptr<IMDModule>      field_;
         std::unique_ptr<ForceProviders> forceProviders_;
+
+        /*! \brief List of registered MDModules */
+        std::vector < std::shared_ptr < IMDModule>> modules_;
 };
 
 MDModules::MDModules() : impl_(new Impl)
@@ -142,7 +145,16 @@ ForceProviders *MDModules::initForceProviders()
                        "Force providers initialized multiple times");
     impl_->forceProviders_ = compat::make_unique<ForceProviders>();
     impl_->field_->initForceProviders(impl_->forceProviders_.get());
+    for (auto && module : impl_->modules_)
+    {
+        module->initForceProviders(impl_->forceProviders_.get());
+    }
     return impl_->forceProviders_.get();
 }
 
+void MDModules::add(std::shared_ptr<gmx::IMDModule> module)
+{
+    impl_->modules_.emplace_back(std::move(module));
+}
+
 } // namespace gmx
index fe0b75fc058511526929d9e8e472729b83d09c7e..2230a555c40820886649c3ff46d585914f5425c2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -58,6 +58,7 @@ class IKeyValueTreeErrorHandler;
 class IKeyValueTreeTransformRules;
 class IMDOutputProvider;
 class KeyValueTreeObject;
+class IMDModule;
 
 /*! \libinternal \brief
  * Manages the collection of all modules used for mdrun.
@@ -144,6 +145,30 @@ class MDModules
          */
         ForceProviders *initForceProviders();
 
+        /*!
+         * \brief Add a module to the container.
+         *
+         * An object may be added by a client to the bound MD Modules at run time.
+         * Both the client and the MDModules object may need to extend the life
+         * of the provided object. However, the MDModules container guarantees
+         * to extend the life of a provided object for as long as its consumers
+         * may attempt to use its the interfaces accessible through IMDModule
+         * methods.
+         *
+         * \param module implements some sort of modular functionality for MD.
+         *
+         * \note: There is not yet a way to add a IMDModule object between
+         * creation of the MDModules container and the execution of the various
+         * initialization protocols it supports.
+         *
+         * \internal
+         * Adding a module at an arbitrary point in the MDModules life breaks
+         * some assumptions in the protocol of the other member functions. If
+         * MDModules should not change after some point, we should move this
+         * to a builder class.
+         */
+        void add(std::shared_ptr<gmx::IMDModule> module);
+
     private:
         class Impl;