Allow gmxapi Python package to build with all 2021 releases.
authorM. Eric Irrgang <mei2n@virginia.edu>
Wed, 11 Aug 2021 12:16:36 +0000 (12:16 +0000)
committerM. Eric Irrgang <mei2n@virginia.edu>
Wed, 11 Aug 2021 12:16:36 +0000 (12:16 +0000)
docs/release-notes/2021/2021.3.rst
python_packaging/src/CMakeLists.txt
python_packaging/src/gmxapi/export_system.cpp
python_packaging/src/gmxapi/launch_020.cpp [new file with mode: 0644]
python_packaging/src/gmxapi/launch_021.cpp [new file with mode: 0644]
python_packaging/src/gmxapi/pycontext.cpp
python_packaging/src/gmxapi/pysystem.h
python_packaging/src/setup.py

index a9cccf969c0043e85d35b2c822bb2e5ba10a0022..ef0cd80ca0c82c12a4f980659addf78a65080f4d 100644 (file)
@@ -24,12 +24,17 @@ simulation through the gmxapi Python interface.
 This meant that restraint potentials would silently fail to be applied with
 gmxapi versions >= 0.1.
 Updates have been applied internally to gmxapi.
+
+The gmxapi 0.2.2 Python package supports the updated GROMACS API and will
+issue errors if a simulation attempts to bind external plugin code with
+a compatible-but-broken API (GROMACS 2021 through 2021.2).
+
 Third party code should not need to be updated, but developers will
 note an additional "null restraint" in
 https://gitlab.com/gromacs/gromacs/-/tree/master/python_packaging/sample_restraint
 (for illustration and testing purposes).
 
-:issue:`4078`
+:issue:`4078` and :issue:`4102`
 
 Fixes for ``gmx`` tools
 ^^^^^^^^^^^^^^^^^^^^^^^
index a389c415c737fdf7f3f8ccdf706b9c770a7aa63b..3cc138593877da16b9f4c492a63a02937f81e640 100644 (file)
@@ -76,9 +76,13 @@ if(POLICY CMP0074) #3.12
 endif()
 
 if(GMXAPI_MASTER_PROJECT)
-    find_package(gmxapi 0.2.1 REQUIRED
+    find_package(gmxapi 0.2 REQUIRED
                  HINTS "$ENV{GROMACS_DIR}"
                  )
+    if (gmxapi_VERSION VERSION_LESS 0.2.1)
+        message(WARNING "Your GROMACS installation does not support custom MD plugins. "
+                "If you need this feature, please install GROMACS 2021.3 or higher.")
+    endif ()
 endif()
 if(gmxapi_FOUND)
     set(_suffix "")
@@ -132,6 +136,12 @@ pybind11_add_module(_gmxapi
                     ${GMXAPI_PYTHON_EXTENSION_SOURCES}
                     )
 
+if (gmxapi_VERSION VERSION_GREATER_EQUAL 0.2.1)
+    target_sources(_gmxapi PRIVATE gmxapi/launch_021.cpp)
+else()
+    target_sources(_gmxapi PRIVATE gmxapi/launch_020.cpp)
+endif()
+
 target_include_directories(_gmxapi PRIVATE
                            ${CMAKE_CURRENT_SOURCE_DIR}/gmxapi
                            ${CMAKE_CURRENT_BINARY_DIR}/gmxapi
index 25d6206f384b23908754014a6092d4129b54a8d9..273ad5087afe05000f2157bb144404c78b1958ce 100644 (file)
@@ -44,6 +44,7 @@
 #include "gmxapi/session.h"
 #include "gmxapi/status.h"
 #include "gmxapi/system.h"
+#include "gmxapi/version.h"
 
 #include "pycontext.h"
 #include "pysystem.h"
@@ -80,13 +81,7 @@ void export_system(py::module& m)
 
     // Export system container class
     py::class_<System, std::shared_ptr<System>> system(m, "MDSystem");
-    system.def("launch",
-               [](System* system, std::shared_ptr<PyContext> context) {
-                   auto work       = gmxapi::getWork(*system->get());
-                   auto newSession = context->launch(*work);
-                   return newSession;
-               },
-               "Launch the configured workflow in the provided context.");
+    system.def("launch", &launch, "Launch the configured workflow in the provided context.");
 
     // Module-level function
     m.def("from_tpr", &gmxpy::from_tpr,
diff --git a/python_packaging/src/gmxapi/launch_020.cpp b/python_packaging/src/gmxapi/launch_020.cpp
new file mode 100644 (file)
index 0000000..65e5262
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2021, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \file
+ * \brief Implement Session launcher.
+ *
+ * \ingroup module_python
+ * \author M. Eric Irrgang <ericirrgang@gmail.com>
+ */
+
+#include "pycontext.h"
+#include "pysystem.h"
+
+namespace gmxpy
+{
+
+std::shared_ptr<gmxapi::Session> launch(::gmxapi::System* system, PyContext* context)
+{
+    auto newSession = system->launch(context->get());
+    return newSession;
+}
+
+} // namespace gmxpy
diff --git a/python_packaging/src/gmxapi/launch_021.cpp b/python_packaging/src/gmxapi/launch_021.cpp
new file mode 100644 (file)
index 0000000..44ad5a2
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2021, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \file
+ * \brief Implement Session launcher.
+ *
+ * \ingroup module_python
+ * \author M. Eric Irrgang <ericirrgang@gmail.com>
+ */
+
+#include "pycontext.h"
+#include "pysystem.h"
+
+namespace gmxpy
+{
+
+std::shared_ptr<gmxapi::Session> launch(::gmxapi::System* system, PyContext* context)
+{
+    auto work       = gmxapi::getWork(*system->get());
+    auto newSession = context->launch(*work);
+    return newSession;
+}
+
+} // namespace gmxpy
index a2640301d5f5e4e362e2db84fe573fee9c9e25e7..c77238cebadef29b39397ffce39bb93dea9e8fda 100644 (file)
@@ -45,7 +45,7 @@
 #include "gmxapi/md.h"
 #include "gmxapi/session.h"
 #include "gmxapi/status.h"
-
+#include "gmxapi/version.h"
 
 namespace py = pybind11;
 
@@ -102,6 +102,10 @@ PyContext::PyContext() :
 
 void PyContext::addMDModule(const pybind11::object& force_object) const
 {
+    if (!::gmxapi::Version::isAtLeast(0, 2, 1))
+    {
+        throw ::gmxapi::NotImplementedError("Feature requires gmxapi 0.2.1 with GROMACS 2021.3.");
+    }
     // If force_object has a bind method, give it a PyCapsule with a pointer
     // to our C++ object.
     if (py::hasattr(force_object, "bind"))
index 0cafe1ee8499c2a04f31c4cfd4d964f5c079d627..2281df9d0753e6642722282735c04c2590d2b29a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2019, by the GROMACS development team, led by
+ * Copyright (c) 2019,2021, 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.
@@ -53,6 +53,10 @@ namespace gmxpy
 
 std::shared_ptr<gmxapi::System> from_tpr(std::string filename);
 
+class PyContext;
+
+std::shared_ptr<gmxapi::Session> launch(::gmxapi::System* system, PyContext* context);
+
 } // end namespace gmxpy
 
 #endif // header guard
index 254b37302927446a253ca34b612a498b42c4be04..b5826a16566451fe46c5c182a5eaaa3ae7a3ea46 100644 (file)
@@ -172,7 +172,7 @@ setup(
     name='gmxapi',
 
     # TODO: single-source version information (currently repeated in gmxapi/version.py and CMakeLists.txt)
-    version='0.2.1',
+    version='0.2.2',
     python_requires='>=3.6',
     install_requires=['networkx>=2.0',
                       'numpy>=1'],