From: M. Eric Irrgang Date: Wed, 11 Aug 2021 12:16:36 +0000 (+0000) Subject: Allow gmxapi Python package to build with all 2021 releases. X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=1894e04d148816e73237e76753e15c3e89f4f93e;p=alexxy%2Fgromacs.git Allow gmxapi Python package to build with all 2021 releases. --- diff --git a/docs/release-notes/2021/2021.3.rst b/docs/release-notes/2021/2021.3.rst index a9cccf969c..ef0cd80ca0 100644 --- a/docs/release-notes/2021/2021.3.rst +++ b/docs/release-notes/2021/2021.3.rst @@ -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 ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/python_packaging/src/CMakeLists.txt b/python_packaging/src/CMakeLists.txt index a389c415c7..3cc1385938 100644 --- a/python_packaging/src/CMakeLists.txt +++ b/python_packaging/src/CMakeLists.txt @@ -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 diff --git a/python_packaging/src/gmxapi/export_system.cpp b/python_packaging/src/gmxapi/export_system.cpp index 25d6206f38..273ad5087a 100644 --- a/python_packaging/src/gmxapi/export_system.cpp +++ b/python_packaging/src/gmxapi/export_system.cpp @@ -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(m, "MDSystem"); - system.def("launch", - [](System* system, std::shared_ptr 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 index 0000000000..65e5262a10 --- /dev/null +++ b/python_packaging/src/gmxapi/launch_020.cpp @@ -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 + */ + +#include "pycontext.h" +#include "pysystem.h" + +namespace gmxpy +{ + +std::shared_ptr 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 index 0000000000..44ad5a2381 --- /dev/null +++ b/python_packaging/src/gmxapi/launch_021.cpp @@ -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 + */ + +#include "pycontext.h" +#include "pysystem.h" + +namespace gmxpy +{ + +std::shared_ptr launch(::gmxapi::System* system, PyContext* context) +{ + auto work = gmxapi::getWork(*system->get()); + auto newSession = context->launch(*work); + return newSession; +} + +} // namespace gmxpy diff --git a/python_packaging/src/gmxapi/pycontext.cpp b/python_packaging/src/gmxapi/pycontext.cpp index a2640301d5..c77238ceba 100644 --- a/python_packaging/src/gmxapi/pycontext.cpp +++ b/python_packaging/src/gmxapi/pycontext.cpp @@ -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")) diff --git a/python_packaging/src/gmxapi/pysystem.h b/python_packaging/src/gmxapi/pysystem.h index 0cafe1ee84..2281df9d07 100644 --- a/python_packaging/src/gmxapi/pysystem.h +++ b/python_packaging/src/gmxapi/pysystem.h @@ -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 from_tpr(std::string filename); +class PyContext; + +std::shared_ptr launch(::gmxapi::System* system, PyContext* context); + } // end namespace gmxpy #endif // header guard diff --git a/python_packaging/src/setup.py b/python_packaging/src/setup.py index 254b373029..b5826a1656 100644 --- a/python_packaging/src/setup.py +++ b/python_packaging/src/setup.py @@ -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'],