diff --git a/doc/src/Library_utility.rst b/doc/src/Library_utility.rst index da64e3b8f0..9d16daae0b 100644 --- a/doc/src/Library_utility.rst +++ b/doc/src/Library_utility.rst @@ -19,6 +19,7 @@ functions. They do not directly call the LAMMPS library. - :cpp:func:`lammps_force_timeout` - :cpp:func:`lammps_has_error` - :cpp:func:`lammps_get_last_error_message` +- :cpp:func:`lammps_python_api_version` The :cpp:func:`lammps_free` function is a clean-up function to free memory that the library had allocated previously via other function @@ -100,3 +101,9 @@ where such memory buffers were allocated that require the use of .. doxygenfunction:: lammps_get_last_error_message :project: progguide + +----------------------- + +.. doxygenfunction:: lammps_python_api_version + :project: progguide + diff --git a/python/lammps/mliap/loader.py b/python/lammps/mliap/loader.py index b2d0079220..0e76568e2c 100644 --- a/python/lammps/mliap/loader.py +++ b/python/lammps/mliap/loader.py @@ -58,7 +58,7 @@ def activate_mliappy(lmp): try: library = lmp.lib module_names = ["mliap_model_python_couple", "mliap_unified_couple"] - api_version = library.lammps_PYTHON_API_VERSION() + api_version = library.lammps_python_api_version() for module_name in module_names: # Make Machinery diff --git a/src/library.cpp b/src/library.cpp index bba0d293f4..6b3d9f484c 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -57,6 +57,10 @@ #include "exceptions.h" #endif +#if defined(LMP_PYTHON) +#include +#endif + using namespace LAMMPS_NS; // for printing the non-null pointer argument warning only once @@ -5571,12 +5575,28 @@ int lammps_get_last_error_message(void *handle, char *buffer, int buf_size) { return 0; } -#ifdef LMP_PYTHON -#include -int lammps_PYTHON_API_VERSION(){ +/* ---------------------------------------------------------------------- */ + +/** Return API version of embedded Python interpreter + +\verbatim embed:rst +This function is used by the ML-IAP python code (mliappy) to verify +the API version of the embedded python interpreter of the PYTHON +package. It returns -1 if the PYTHON package is not enabled. + +.. versionadded:: TBD + +\endverbatim + * + * \return PYTHON_API_VERSION constant of the python interpreter or -1 */ + +int lammps_python_api_version() { +#if defined(LMP_PYTHON) return PYTHON_API_VERSION; -} +#else + return -1; #endif +} // Local Variables: // fill-column: 72 diff --git a/src/library.h b/src/library.h index 477091cd4c..bc59ada9df 100644 --- a/src/library.h +++ b/src/library.h @@ -256,9 +256,7 @@ void lammps_force_timeout(void *handle); int lammps_has_error(void *handle); int lammps_get_last_error_message(void *handle, char *buffer, int buf_size); -#ifdef LMP_PYTHON -int lammps_PYTHON_API_VERSION(); -#endif +int lammps_python_api_version(); #ifdef __cplusplus }