From 73304a2ebbbeffc825911be23387dbd1ceac859e Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:22:51 +0200 Subject: [PATCH 01/33] setting up a way for calling pycv wit the python module --- plugins/pycv/.gitignore | 3 ++- plugins/pycv/CMakeLists.txt | 21 +++++++++++++++++++++ plugins/pycv/PlumedPythonEmbeddedModule.cpp | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 plugins/pycv/CMakeLists.txt diff --git a/plugins/pycv/.gitignore b/plugins/pycv/.gitignore index 7df00fe885..ff5992fcf8 100644 --- a/plugins/pycv/.gitignore +++ b/plugins/pycv/.gitignore @@ -1,4 +1,5 @@ /Makefile.conf *.o *.so -env +/env/ +/build*/ diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt new file mode 100644 index 0000000000..f4b551e61f --- /dev/null +++ b/plugins/pycv/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.20) +project(PYCV VERSION 0.1.0 LANGUAGES CXX) +set (CMAKE_CXX_STANDARD 17) + +find_package(Python COMPONENTS Interpreter Development) +find_package(pybind11 CONFIG) +message(STATUS "pybind11 found: ${pybind11_VERSION}") + +exec_program(plumed +ARGS info --include-dir +OUTPUT_VARIABLE PLUMED_INCLUDE_DIR +) +message(STATUS "Plumed include dir: ${PLUMED_INCLUDE_DIR}") + +pybind11_add_module(plumedCommunications PlumedPythonEmbeddedModule.cpp) +add_library(PythonCVInterface SHARED ActionWithPython.cpp PythonCVInterface.cpp PythonFunction.cpp) +target_link_libraries(PythonCVInterface PUBLIC pybind11::embed plumedKernel) +target_link_libraries(plumedCommunications PUBLIC plumedKernel PythonCVInterface) + +target_include_directories(PythonCVInterface PUBLIC ${PLUMED_INCLUDE_DIR}/plumed) +target_include_directories(plumedCommunications PUBLIC ${PLUMED_INCLUDE_DIR}/plumed) \ No newline at end of file diff --git a/plugins/pycv/PlumedPythonEmbeddedModule.cpp b/plugins/pycv/PlumedPythonEmbeddedModule.cpp index 60ed89aca9..c0b2f5feb7 100644 --- a/plugins/pycv/PlumedPythonEmbeddedModule.cpp +++ b/plugins/pycv/PlumedPythonEmbeddedModule.cpp @@ -35,7 +35,7 @@ namespace py=pybind11; //NB: the action methods are written two times due to the diamond inheritance -PYBIND11_EMBEDDED_MODULE(plumedCommunications, m) { +PYBIND11_MODULE(plumedCommunications, m) { /*******************************default submodule****************************/ py::module_ defaults = m.def_submodule("defaults", "Submodule with the default definitions"); defaults.attr("COMPONENT") = py::dict(py::arg("period")=py::none(),py::arg("derivative")=true); From 3754faf4318b343ef4136770a30c2ef6a7c71650 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:49:51 +0200 Subject: [PATCH 02/33] Now pycv works with pip --- plugins/pycv/CMakeLists.txt | 34 ++++++++++++++++----- plugins/pycv/pyproject.toml | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 plugins/pycv/pyproject.toml diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index f4b551e61f..a644a0ab5a 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -1,9 +1,12 @@ -cmake_minimum_required(VERSION 3.20) -project(PYCV VERSION 0.1.0 LANGUAGES CXX) +cmake_minimum_required(VERSION 3.15...3.27) +project( + ${SKBUILD_PROJECT_NAME} + VERSION ${SKBUILD_PROJECT_VERSION} + LANGUAGES CXX) set (CMAKE_CXX_STANDARD 17) -find_package(Python COMPONENTS Interpreter Development) -find_package(pybind11 CONFIG) +find_package(Python REQUIRED COMPONENTS Interpreter Development) +find_package(pybind11 CONFIG REQUIRED) message(STATUS "pybind11 found: ${pybind11_VERSION}") exec_program(plumed @@ -12,10 +15,25 @@ OUTPUT_VARIABLE PLUMED_INCLUDE_DIR ) message(STATUS "Plumed include dir: ${PLUMED_INCLUDE_DIR}") -pybind11_add_module(plumedCommunications PlumedPythonEmbeddedModule.cpp) +python_add_library(_core MODULE PlumedPythonEmbeddedModule.cpp WITH_SOABI) +target_link_libraries(_core PRIVATE pybind11::headers) +target_link_libraries(_core PUBLIC plumedKernel) + +# This is passing in the version as a define just as an example +target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION}) + +# The install directory is the output (wheel) directory +install(TARGETS _core DESTINATION plumedCommunications) + +#the pycv library add_library(PythonCVInterface SHARED ActionWithPython.cpp PythonCVInterface.cpp PythonFunction.cpp) -target_link_libraries(PythonCVInterface PUBLIC pybind11::embed plumedKernel) -target_link_libraries(plumedCommunications PUBLIC plumedKernel PythonCVInterface) +target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) +target_link_libraries(PythonCVInterface PUBLIC plumedKernel) + +target_link_libraries(_core PUBLIC PythonCVInterface) target_include_directories(PythonCVInterface PUBLIC ${PLUMED_INCLUDE_DIR}/plumed) -target_include_directories(plumedCommunications PUBLIC ${PLUMED_INCLUDE_DIR}/plumed) \ No newline at end of file +target_include_directories(_core PUBLIC ${PLUMED_INCLUDE_DIR}/plumed) + +#TBD +#install(TARGETS PythonCVInterface DESTINATION ) diff --git a/plugins/pycv/pyproject.toml b/plugins/pycv/pyproject.toml new file mode 100644 index 0000000000..45c7185f7c --- /dev/null +++ b/plugins/pycv/pyproject.toml @@ -0,0 +1,60 @@ +[build-system] +requires = ["scikit-build-core>=0.10", "pybind11"] +build-backend = "scikit_build_core.build" + + +[project] +name = "pyCV" +version = "0.0.1" +description="PyCV as a package for PLUMED" +readme = "README.md" +authors = [ + { name = "My Name", email = "me@email.com" }, +] +requires-python = ">=3.9" +classifiers = [ + "Development Status :: 4 - Beta", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", +] + +[project.optional-dependencies] +test = ["pytest", "plumed"] + + +[tool.scikit-build] +wheel.expand-macos-universal-tags = true +minimum-version = "build-system.requires" + + +[tool.pytest.ini_options] +minversion = "8.0" +addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"] +xfail_strict = true +log_cli_level = "INFO" +filterwarnings = [ + "error", + "ignore::pytest.PytestCacheWarning", +] +testpaths = ["tests"] + + +[tool.cibuildwheel] +build-frontend = "build[uv]" +test-command = "pytest {project}/tests" +test-extras = ["test"] + +[tool.cibuildwheel.pyodide] +build-frontend = {name = "build", args = ["--exports", "whole_archive"]} + + + +[tool.ruff.lint.per-file-ignores] +"tests/**" = ["T20"] \ No newline at end of file From d15ab273a24652a96ce8a411434b11d8fffae01a Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:38:21 +0200 Subject: [PATCH 03/33] now the action is included within the wheel --- plugins/pycv/.gitignore | 2 ++ plugins/pycv/CMakeLists.txt | 20 +++++++++++--------- plugins/pycv/pyproject.toml | 16 +++++----------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/plugins/pycv/.gitignore b/plugins/pycv/.gitignore index ff5992fcf8..fe6a462721 100644 --- a/plugins/pycv/.gitignore +++ b/plugins/pycv/.gitignore @@ -3,3 +3,5 @@ *.so /env/ /build*/ +/dist*/ +*.whl \ No newline at end of file diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index a644a0ab5a..ea6722be80 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -15,25 +15,27 @@ OUTPUT_VARIABLE PLUMED_INCLUDE_DIR ) message(STATUS "Plumed include dir: ${PLUMED_INCLUDE_DIR}") -python_add_library(_core MODULE PlumedPythonEmbeddedModule.cpp WITH_SOABI) -target_link_libraries(_core PRIVATE pybind11::headers) -target_link_libraries(_core PUBLIC plumedKernel) +pybind11_add_module(plumedCommunications PlumedPythonEmbeddedModule.cpp) +#python_add_library(plumedCommunications MODULE PlumedPythonEmbeddedModule.cpp WITH_SOABI) +# target_link_libraries(plumedCommunications PRIVATE pybind11::headers) +target_link_libraries(plumedCommunications PUBLIC plumedKernel) # This is passing in the version as a define just as an example -target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION}) +target_compile_definitions(plumedCommunications PRIVATE VERSION_INFO=${PROJECT_VERSION}) # The install directory is the output (wheel) directory -install(TARGETS _core DESTINATION plumedCommunications) +install(TARGETS plumedCommunications DESTINATION .) #the pycv library +#TODO: removhe the "lib" prefix add_library(PythonCVInterface SHARED ActionWithPython.cpp PythonCVInterface.cpp PythonFunction.cpp) target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) target_link_libraries(PythonCVInterface PUBLIC plumedKernel) -target_link_libraries(_core PUBLIC PythonCVInterface) +target_link_libraries(plumedCommunications PUBLIC PythonCVInterface) target_include_directories(PythonCVInterface PUBLIC ${PLUMED_INCLUDE_DIR}/plumed) -target_include_directories(_core PUBLIC ${PLUMED_INCLUDE_DIR}/plumed) +target_include_directories(plumedCommunications PUBLIC ${PLUMED_INCLUDE_DIR}/plumed) -#TBD -#install(TARGETS PythonCVInterface DESTINATION ) + +install(TARGETS PythonCVInterface DESTINATION .) diff --git a/plugins/pycv/pyproject.toml b/plugins/pycv/pyproject.toml index 45c7185f7c..28b3f196eb 100644 --- a/plugins/pycv/pyproject.toml +++ b/plugins/pycv/pyproject.toml @@ -6,18 +6,17 @@ build-backend = "scikit_build_core.build" [project] name = "pyCV" version = "0.0.1" -description="PyCV as a package for PLUMED" +description="PyCV support module for plumed" readme = "README.md" authors = [ - { name = "My Name", email = "me@email.com" }, + { name = "Toni Giorgino", email = "toni.giorgino@gmail.com" }, + { name = "Daniele Rapetti", email = "daniele.rapetti@sissa.it" }, ] requires-python = ">=3.9" classifiers = [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -43,18 +42,13 @@ filterwarnings = [ "error", "ignore::pytest.PytestCacheWarning", ] -testpaths = ["tests"] +testpaths = ["pythontests"] [tool.cibuildwheel] build-frontend = "build[uv]" -test-command = "pytest {project}/tests" +test-command = "pytest {project}/pythontests" test-extras = ["test"] [tool.cibuildwheel.pyodide] build-frontend = {name = "build", args = ["--exports", "whole_archive"]} - - - -[tool.ruff.lint.per-file-ignores] -"tests/**" = ["T20"] \ No newline at end of file From e99df2f375152fd322cffee81bbaded8c52f73e7 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:40:39 +0200 Subject: [PATCH 04/33] now pycv looks more like a package --- plugins/pycv/CMakeLists.txt | 8 +-- plugins/pycv/Makefile | 53 ------------------ plugins/pycv/compileConfiguration.sh | 54 ------------------- plugins/pycv/{ => src}/ActionWithPython.cpp | 0 plugins/pycv/{ => src}/ActionWithPython.h | 0 .../{ => src}/PlumedPythonEmbeddedModule.cpp | 0 plugins/pycv/{ => src}/PythonCVInterface.cpp | 0 plugins/pycv/{ => src}/PythonCVInterface.h | 0 plugins/pycv/{ => src}/PythonFunction.cpp | 0 plugins/pycv/{ => src}/PythonFunction.h | 0 plugins/pycv/standaloneCompile.sh | 16 ------ 11 files changed, 4 insertions(+), 127 deletions(-) delete mode 100644 plugins/pycv/Makefile delete mode 100644 plugins/pycv/compileConfiguration.sh rename plugins/pycv/{ => src}/ActionWithPython.cpp (100%) rename plugins/pycv/{ => src}/ActionWithPython.h (100%) rename plugins/pycv/{ => src}/PlumedPythonEmbeddedModule.cpp (100%) rename plugins/pycv/{ => src}/PythonCVInterface.cpp (100%) rename plugins/pycv/{ => src}/PythonCVInterface.h (100%) rename plugins/pycv/{ => src}/PythonFunction.cpp (100%) rename plugins/pycv/{ => src}/PythonFunction.h (100%) delete mode 100755 plugins/pycv/standaloneCompile.sh diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index ea6722be80..2746bcc82c 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -15,7 +15,7 @@ OUTPUT_VARIABLE PLUMED_INCLUDE_DIR ) message(STATUS "Plumed include dir: ${PLUMED_INCLUDE_DIR}") -pybind11_add_module(plumedCommunications PlumedPythonEmbeddedModule.cpp) +pybind11_add_module(plumedCommunications src/PlumedPythonEmbeddedModule.cpp) #python_add_library(plumedCommunications MODULE PlumedPythonEmbeddedModule.cpp WITH_SOABI) # target_link_libraries(plumedCommunications PRIVATE pybind11::headers) target_link_libraries(plumedCommunications PUBLIC plumedKernel) @@ -28,14 +28,14 @@ install(TARGETS plumedCommunications DESTINATION .) #the pycv library #TODO: removhe the "lib" prefix -add_library(PythonCVInterface SHARED ActionWithPython.cpp PythonCVInterface.cpp PythonFunction.cpp) +add_library(PythonCVInterface SHARED src/ActionWithPython.cpp src/PythonCVInterface.cpp src/PythonFunction.cpp) target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) target_link_libraries(PythonCVInterface PUBLIC plumedKernel) target_link_libraries(plumedCommunications PUBLIC PythonCVInterface) -target_include_directories(PythonCVInterface PUBLIC ${PLUMED_INCLUDE_DIR}/plumed) -target_include_directories(plumedCommunications PUBLIC ${PLUMED_INCLUDE_DIR}/plumed) +target_include_directories(PythonCVInterface PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) +target_include_directories(plumedCommunications PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) install(TARGETS PythonCVInterface DESTINATION .) diff --git a/plugins/pycv/Makefile b/plugins/pycv/Makefile deleted file mode 100644 index 9e9ee703cf..0000000000 --- a/plugins/pycv/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# include the machine dependent configuration -ifneq ($(MAKECMDGOALS),clean) - -include ../../Makefile.conf - ifndef canPyCV - include ./Makefile.conf - endif -endif - -.PHONY: clean check all -#Dependency tracking based on https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr -#this assumes gcc -DEPDIR := .deps -DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d -PYBIND11FLAG = -ADDCPPFLAGS:=$(python_cf_embedded) $(pybind11_cflags) $(ADDCPPFLAGS) -ADDCLDFLAGS:=$(ADDCLDFLAGS) $(python_ld_embedded) -OBJS = ActionWithPython.o PythonCVInterface.o PythonFunction.o PlumedPythonEmbeddedModule.o - -ifeq ($(SOEXT),dylib) - SONAME_OPTION:=-Wl,-install_name -else - SONAME_OPTION:=-Wl,-soname -endif - -all: PythonCVInterface.$(SOEXT) - -#-fvisibility=hidden is needed for pybind11 (to not conflict with different pybind11 versions) -#I think I enforced this nearly everywhere I set up a flag for the compiler -ActionWithPython.o PythonCVInterface.o PythonFunction.o PlumedPythonEmbeddedModule.o: PYBIND11FLAG= -fvisibility=hidden - -%.o: %.cpp $(DEPDIR)/%.d | $(DEPDIR) - @echo Compiling object $@ - @$(CXX) -c $(DEPFLAGS) $(CPPFLAGS) $(PYBIND11FLAG) $(ADDCPPFLAGS) $(CXXFLAGS) $< -o $@ - - -$(DEPDIR): ; @mkdir -p $@ - -DEPFILES := $(OBJS:%.o=$(DEPDIR)/%.d) -$(DEPFILES): -include $(wildcard $(DEPFILES)) - -#-Wl,--no-as-needed forces the python library to be linked, without this in a WSL does not work -#TODO: seems that $PLUMED_KERNEL is not needed, check -PythonCVInterface.$(SOEXT): $(OBJS) - @echo Linking $@ - $(LDSHARED) $(SONAME_OPTION),"$(notdir $@)" $(DYNAMIC_LIBS) $(PLUMED_KERNEL) $(ADDCLDFLAGS) $^ -o $@ - -clean: - rm -f $(OBJS) PythonCVInterface.$(SOEXT) - -check: all - $(MAKE) -C regtest testclean - $(MAKE) -C regtest checkfail diff --git a/plugins/pycv/compileConfiguration.sh b/plugins/pycv/compileConfiguration.sh deleted file mode 100644 index e9eac1fdbe..0000000000 --- a/plugins/pycv/compileConfiguration.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/env bash - -#formatted with shfmt https://github.com/mvdan/sh/releases -#checked with shellcheck -# shellcheck disable=SC2034 # The unused variables will be used in sourcer files - -#please source this file - -#for some reason, on the WSL I need to compile with -# `export PYCV_EXTRA_LDFLAGS="-Wl,--no-as-needed"` -#-Wl,--no-as-needed forces the python library to be linked -#I do not undestand why, since -as-needed should be disabled by default - -plumed_program_name=${plumed_program_name:-plumed} - -#check if during config time the settings for compiling PyCV where got -plumed_canPyCV=$( - ${plumed_program_name} --no-mpi config makefile_conf | grep canPyCV | sed -e s/^canPyCV=// -) - -if [[ $plumed_canPyCV = yes ]]; then - pybind11_cflags=$(plumed --no-mpi config makefile_conf | grep pybind11_cflags | sed -e s/^pybind11_cflags=//) - python_cf_embedded=$(plumed --no-mpi config makefile_conf | grep python_cf_embedded | sed -e s/^python_cf_embedded=//) - python_ld_embedded=$(plumed --no-mpi config makefile_conf | grep python_ld_embedded | sed -e s/^python_ld_embedded=//) -else - #assign a default value to python bin and plumed - python_bin=${python_bin:-python} - #python3-config may be any python3.* version, this should avoid contamination from other environments - #and use pythonX.Y-config, as suggested in the manual - pyver=$($python_bin -c "import sysconfig;print(sysconfig.get_config_var('VERSION'))") - python_config=python${pyver}-config - - # Note that in conda libpython3xx is not found in the path returned by ldflags. IMHO it is a bug. - # The workaround is to -L appropriately. Will be fixed here. - conda_fixup=${CONDA_PREFIX+-L$CONDA_PREFIX/lib} - if [ -n "$conda_fixup" ]; then - echo "CONDA_PREFIX is set. Assuming conda and enabling a workaround for missing -L in ${python_config} --ldflags --embed" - fi - - if ! ${python_config} --embed >/dev/null 2>/dev/null; then - #TODO: verify that this does not give problems with conda - echo "PyCV needs python to be built to be embedable" - echo "(compiling python with --enable-shared should be enough)" - exit 1 - fi - if ! ${python_bin} -m pybind11 --includes >/dev/null; then - #python will automatically say that there is non pybind11 - exit 1 - fi - #-fvisibility=hidden is needed to correct the warnings for the visibility of some pybind11 functionalities - pybind11_cflags="$(${python_bin} -m pybind11 --includes) -fvisibility=hidden" - python_cf_embedded=$(${python_config} --cflags --embed) - python_ld_embedded=$(${python_config} --ldflags --embed) -fi diff --git a/plugins/pycv/ActionWithPython.cpp b/plugins/pycv/src/ActionWithPython.cpp similarity index 100% rename from plugins/pycv/ActionWithPython.cpp rename to plugins/pycv/src/ActionWithPython.cpp diff --git a/plugins/pycv/ActionWithPython.h b/plugins/pycv/src/ActionWithPython.h similarity index 100% rename from plugins/pycv/ActionWithPython.h rename to plugins/pycv/src/ActionWithPython.h diff --git a/plugins/pycv/PlumedPythonEmbeddedModule.cpp b/plugins/pycv/src/PlumedPythonEmbeddedModule.cpp similarity index 100% rename from plugins/pycv/PlumedPythonEmbeddedModule.cpp rename to plugins/pycv/src/PlumedPythonEmbeddedModule.cpp diff --git a/plugins/pycv/PythonCVInterface.cpp b/plugins/pycv/src/PythonCVInterface.cpp similarity index 100% rename from plugins/pycv/PythonCVInterface.cpp rename to plugins/pycv/src/PythonCVInterface.cpp diff --git a/plugins/pycv/PythonCVInterface.h b/plugins/pycv/src/PythonCVInterface.h similarity index 100% rename from plugins/pycv/PythonCVInterface.h rename to plugins/pycv/src/PythonCVInterface.h diff --git a/plugins/pycv/PythonFunction.cpp b/plugins/pycv/src/PythonFunction.cpp similarity index 100% rename from plugins/pycv/PythonFunction.cpp rename to plugins/pycv/src/PythonFunction.cpp diff --git a/plugins/pycv/PythonFunction.h b/plugins/pycv/src/PythonFunction.h similarity index 100% rename from plugins/pycv/PythonFunction.h rename to plugins/pycv/src/PythonFunction.h diff --git a/plugins/pycv/standaloneCompile.sh b/plugins/pycv/standaloneCompile.sh deleted file mode 100755 index e5ce28ec29..0000000000 --- a/plugins/pycv/standaloneCompile.sh +++ /dev/null @@ -1,16 +0,0 @@ -#! /usr/bin/env bash - -#formatted with shfmt https://github.com/mvdan/sh/releases -#checked with shellcheck -# the SC2154 warnings are variables present in the sourced file - -source compileConfiguration.sh - - -export PLUMED_MKLIB_CFLAGS="${python_cf_embedded} ${pybind11_cflags}" -export PLUMED_MKLIB_LDFLAGS="${PYCV_EXTRA_LDFLAGS} ${python_ld_embedded} ${conda_fixup}" - -echo "PLUMED_MKLIB_CFLAGS=$PLUMED_MKLIB_CFLAGS" -echo "PLUMED_MKLIB_LDFLAGS=$PLUMED_MKLIB_LDFLAGS" - -${plumed_program_name} mklib PythonCVInterface.cpp ActionWithPython.cpp PythonFunction.cpp PlumedPythonEmbeddedModule.cpp From 0484d68794c572f731ce5ddbdf72f5a9283ad428 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:49:11 +0200 Subject: [PATCH 05/33] Reordering the installation procedure --- plugins/pycv/CMakeLists.txt | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index 2746bcc82c..a7fb27a3d8 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -15,27 +15,27 @@ OUTPUT_VARIABLE PLUMED_INCLUDE_DIR ) message(STATUS "Plumed include dir: ${PLUMED_INCLUDE_DIR}") -pybind11_add_module(plumedCommunications src/PlumedPythonEmbeddedModule.cpp) -#python_add_library(plumedCommunications MODULE PlumedPythonEmbeddedModule.cpp WITH_SOABI) -# target_link_libraries(plumedCommunications PRIVATE pybind11::headers) -target_link_libraries(plumedCommunications PUBLIC plumedKernel) - -# This is passing in the version as a define just as an example -target_compile_definitions(plumedCommunications PRIVATE VERSION_INFO=${PROJECT_VERSION}) - -# The install directory is the output (wheel) directory -install(TARGETS plumedCommunications DESTINATION .) - -#the pycv library +################################################################################ +################################the pycv library################################ +################################################################################ #TODO: removhe the "lib" prefix add_library(PythonCVInterface SHARED src/ActionWithPython.cpp src/PythonCVInterface.cpp src/PythonFunction.cpp) target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) target_link_libraries(PythonCVInterface PUBLIC plumedKernel) +target_include_directories(PythonCVInterface PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) -target_link_libraries(plumedCommunications PUBLIC PythonCVInterface) +install(TARGETS PythonCVInterface DESTINATION .) -target_include_directories(PythonCVInterface PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) -target_include_directories(plumedCommunications PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) +################################################################################ +############################The pvCV companion module########################### +################################################################################ +pybind11_add_module(plumedCommunications src/PlumedPythonEmbeddedModule.cpp) +#python_add_library(plumedCommunications MODULE PlumedPythonEmbeddedModule.cpp WITH_SOABI) +# target_link_libraries(plumedCommunications PRIVATE pybind11::headers) +target_link_libraries(plumedCommunications PUBLIC plumedKernel) +target_link_libraries(plumedCommunications PUBLIC PythonCVInterface) +target_include_directories(plumedCommunications PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) -install(TARGETS PythonCVInterface DESTINATION .) +# The install directory is the output (wheel) directory +install(TARGETS plumedCommunications DESTINATION .) From 2fa0fa3664e164ca4e07e7aedcc31c0988531ac7 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:08:32 +0200 Subject: [PATCH 06/33] added a sort of "FIND PLUMED" that does not work --- plugins/pycv/CMakeLists.txt | 43 ++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index a7fb27a3d8..baa1324a87 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -13,15 +13,51 @@ exec_program(plumed ARGS info --include-dir OUTPUT_VARIABLE PLUMED_INCLUDE_DIR ) -message(STATUS "Plumed include dir: ${PLUMED_INCLUDE_DIR}") +exec_program(plumed +ARGS info --configuration +OUTPUT_VARIABLE PLUMED_CONFIG +) +set(PLUMED_CXX_FLAGS "") +set(PLUMED_CPP_FLAGS "") +set(PLUMED_DYNAMIC_LIBS "") + +string(REPLACE "\n" ";" ProcessFile_LINES "${PLUMED_CONFIG}") +foreach(_line ${ProcessFile_LINES}) + # message(STATUS "Found PLUMED :${_line}") + if (${_line} MATCHES "CXXFLAGS=.*") + set(PLUMED_CXX_FLAGS ${_line}) + string(REPLACE "CXXFLAGS= *" "" PLUMED_CXX_FLAGS ${PLUMED_CXX_FLAGS}) + message(STATUS "Found PLUMED CXX_FLAGS: \"${PLUMED_CXX_FLAGS}\"") + # string(REPLACE " " ";" PLUMED_CXX_FLAGS ${PLUMED_CXX_FLAGS}) + endif() + if (${_line} MATCHES "CPPFLAGS=.*") + set(PLUMED_CPP_FLAGS ${_line}) + string(REPLACE "CPPFLAGS= *" "" PLUMED_CPP_FLAGS ${PLUMED_CPP_FLAGS}) + message(STATUS "Found PLUMED CPP_FLAGS: \"${PLUMED_CPP_FLAGS}\"") + # string(REPLACE " " ";" PLUMED_CPP_FLAGS ${PLUMED_CPP_FLAGS}) + endif() + if (${_line} MATCHES "DYNAMIC_LIBS=.*") + set(PLUMED_DYNAMIC_LIBS ${_line}) + string(REPLACE "DYNAMIC_LIBS= *" "" PLUMED_DYNAMIC_LIBS ${PLUMED_DYNAMIC_LIBS}) + message(STATUS "Found PLUMED DYNAMIC_LIBS: \"${PLUMED_DYNAMIC_LIBS}\"") + # string(REPLACE " " ";" PLUMED_DYNAMIC_LIBS ${PLUMED_DYNAMIC_LIBS}) + endif() + +endforeach() + +message(STATUS "Plumed include dir: ${PLUMED_INCLUDE_DIR}") +set(CMAke__extra) ################################################################################ ################################the pycv library################################ ################################################################################ #TODO: removhe the "lib" prefix add_library(PythonCVInterface SHARED src/ActionWithPython.cpp src/PythonCVInterface.cpp src/PythonFunction.cpp) +#public, so they trickle down to the python module +target_compile_definitions(PythonCVInterface PUBLIC ${PLUMED_CPP_FLAGS}) +target_compile_options(PythonCVInterface PUBLIC ${PLUMED_CXX_FLAGS}) target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) -target_link_libraries(PythonCVInterface PUBLIC plumedKernel) +target_link_libraries(PythonCVInterface PUBLIC plumedKernel ${PLUMED_DYNAMIC_LIBS}) target_include_directories(PythonCVInterface PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) install(TARGETS PythonCVInterface DESTINATION .) @@ -33,7 +69,8 @@ install(TARGETS PythonCVInterface DESTINATION .) pybind11_add_module(plumedCommunications src/PlumedPythonEmbeddedModule.cpp) #python_add_library(plumedCommunications MODULE PlumedPythonEmbeddedModule.cpp WITH_SOABI) # target_link_libraries(plumedCommunications PRIVATE pybind11::headers) -target_link_libraries(plumedCommunications PUBLIC plumedKernel) +#target_compile_definitions(plumedCommunications PUBLIC ${PLUMED_CPP_FLAGS}) +target_link_libraries(plumedCommunications PUBLIC plumedKernel ${PLUMED_DYNAMIC_LIBS}) target_link_libraries(plumedCommunications PUBLIC PythonCVInterface) target_include_directories(plumedCommunications PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) From f64b088f3e4d49d8c5b00a8bdf6f64c6102891a6 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Mon, 14 Oct 2024 10:41:21 +0200 Subject: [PATCH 07/33] some cleaning --- plugins/pycv/.gitignore | 2 +- plugins/pycv/CMakeLists.txt | 36 +++++++++++++++++++-------- plugins/pycv/prepareMakeForDevelop.sh | 27 -------------------- plugins/pycv/pyproject.toml | 7 +++++- plugins/pycv/pythontests/.gitignore | 4 +++ 5 files changed, 37 insertions(+), 39 deletions(-) delete mode 100755 plugins/pycv/prepareMakeForDevelop.sh create mode 100644 plugins/pycv/pythontests/.gitignore diff --git a/plugins/pycv/.gitignore b/plugins/pycv/.gitignore index fe6a462721..9b90bc2d91 100644 --- a/plugins/pycv/.gitignore +++ b/plugins/pycv/.gitignore @@ -1,7 +1,7 @@ /Makefile.conf *.o *.so -/env/ +/env*/ /build*/ /dist*/ *.whl \ No newline at end of file diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index baa1324a87..8e8fd5701e 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -27,21 +27,35 @@ foreach(_line ${ProcessFile_LINES}) # message(STATUS "Found PLUMED :${_line}") if (${_line} MATCHES "CXXFLAGS=.*") set(PLUMED_CXX_FLAGS ${_line}) - string(REPLACE "CXXFLAGS= *" "" PLUMED_CXX_FLAGS ${PLUMED_CXX_FLAGS}) - message(STATUS "Found PLUMED CXX_FLAGS: \"${PLUMED_CXX_FLAGS}\"") - # string(REPLACE " " ";" PLUMED_CXX_FLAGS ${PLUMED_CXX_FLAGS}) + string(REGEX REPLACE "CXXFLAGS= *" "" PLUMED_CXX_FLAGS ${PLUMED_CXX_FLAGS}) + string(REPLACE " " ";" PLUMED_CXX_FLAGS ${PLUMED_CXX_FLAGS}) + # message(STATUS "Found PLUMED CXX_FLAGS: \"${PLUMED_CXX_FLAGS}\"") + message(STATUS "Found PLUMED CXX_FLAGS: ") + foreach (_flag ${PLUMED_CXX_FLAGS}) + message(STATUS " \"${_flag}\"") + endforeach() endif() if (${_line} MATCHES "CPPFLAGS=.*") set(PLUMED_CPP_FLAGS ${_line}) - string(REPLACE "CPPFLAGS= *" "" PLUMED_CPP_FLAGS ${PLUMED_CPP_FLAGS}) - message(STATUS "Found PLUMED CPP_FLAGS: \"${PLUMED_CPP_FLAGS}\"") - # string(REPLACE " " ";" PLUMED_CPP_FLAGS ${PLUMED_CPP_FLAGS}) + string(REGEX REPLACE "CPPFLAGS= *" "" PLUMED_CPP_FLAGS ${PLUMED_CPP_FLAGS}) + string(REPLACE "\\" "" PLUMED_CPP_FLAGS ${PLUMED_CPP_FLAGS}) + string(REPLACE "-D" ";" PLUMED_CPP_FLAGS ${PLUMED_CPP_FLAGS}) + # message(STATUS "Found PLUMED CPP_FLAGS: \"${PLUMED_CPP_FLAGS}\"") + message(STATUS "Found PLUMED CPP_FLAGS:") + foreach(_flag ${PLUMED_CPP_FLAGS}) + message(STATUS " \"${_flag}\"") + endforeach() + endif() if (${_line} MATCHES "DYNAMIC_LIBS=.*") set(PLUMED_DYNAMIC_LIBS ${_line}) - string(REPLACE "DYNAMIC_LIBS= *" "" PLUMED_DYNAMIC_LIBS ${PLUMED_DYNAMIC_LIBS}) - message(STATUS "Found PLUMED DYNAMIC_LIBS: \"${PLUMED_DYNAMIC_LIBS}\"") - # string(REPLACE " " ";" PLUMED_DYNAMIC_LIBS ${PLUMED_DYNAMIC_LIBS}) + string(REGEX REPLACE "DYNAMIC_LIBS= *" "" PLUMED_DYNAMIC_LIBS ${PLUMED_DYNAMIC_LIBS}) + string(REPLACE " " ";" PLUMED_DYNAMIC_LIBS ${PLUMED_DYNAMIC_LIBS}) + # message(STATUS "Found PLUMED DYNAMIC_LIBS: \"${PLUMED_DYNAMIC_LIBS}\"") + message(STATUS "Found PLUMED DYNAMIC_LIBS:") + foreach(_flag ${PLUMED_DYNAMIC_LIBS}) + message(STATUS " \"${_flag}\"") + endforeach() endif() endforeach() @@ -51,10 +65,12 @@ set(CMAke__extra) ################################################################################ ################################the pycv library################################ ################################################################################ -#TODO: removhe the "lib" prefix +#TODO: remove the "lib" prefix add_library(PythonCVInterface SHARED src/ActionWithPython.cpp src/PythonCVInterface.cpp src/PythonFunction.cpp) #public, so they trickle down to the python module target_compile_definitions(PythonCVInterface PUBLIC ${PLUMED_CPP_FLAGS}) +get_target_property(COMPILE_DEFINITIONS PythonCVInterface COMPILE_DEFINITIONS) +message(STATUS "COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS}") target_compile_options(PythonCVInterface PUBLIC ${PLUMED_CXX_FLAGS}) target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) target_link_libraries(PythonCVInterface PUBLIC plumedKernel ${PLUMED_DYNAMIC_LIBS}) diff --git a/plugins/pycv/prepareMakeForDevelop.sh b/plugins/pycv/prepareMakeForDevelop.sh deleted file mode 100755 index 375851c5a9..0000000000 --- a/plugins/pycv/prepareMakeForDevelop.sh +++ /dev/null @@ -1,27 +0,0 @@ -#! /usr/bin/env bash - -#formatted with shfmt https://github.com/mvdan/sh/releases -#checked with shellcheck -# the SC2154 warnings are variables present in the sourced file - -source compileConfiguration.sh - - -if [[ -z $PLUMED_KERNEL ]]; then - echo "$(basename $0) can work only if \"PLUMED_KERNEL\" is defined" - echo "either via module load or sourceme.sh, or manually exported" - exit 1 -fi - -plumed_include=$(${plumed_program_name} --no-mpi info --include-dir) -{ - ${plumed_program_name} --no-mpi config makefile_conf - echo "PLUMED_KERNEL=${PLUMED_KERNEL}" - if [[ ! $plumed_canPyCV = yes ]]; then - echo "pybind11_cflags=$pybind11_cflags" - echo "python_cf_embedded=$python_cf_embedded" - echo "python_ld_embedded=$python_ld_embedded" - fi - echo "ADDCPPFLAGS=-I${plumed_include}/plumed" - echo "ADDCLDFLAGS=${PYCV_EXTRA_LDFLAGS} ${conda_fixup}" -} > Makefile.conf diff --git a/plugins/pycv/pyproject.toml b/plugins/pycv/pyproject.toml index 28b3f196eb..45f0e95f6e 100644 --- a/plugins/pycv/pyproject.toml +++ b/plugins/pycv/pyproject.toml @@ -1,10 +1,15 @@ [build-system] -requires = ["scikit-build-core>=0.10", "pybind11"] +requires = ["scikit-build-core>=0.10", "pybind11>=2.10.3,<=2.11.1", "numpy"] build-backend = "scikit_build_core.build" [project] name = "pyCV" +dependencies = [ + "plumed", + "numpy", + "pybind11>=2.10.3,<=2.11.1" +] version = "0.0.1" description="PyCV support module for plumed" readme = "README.md" diff --git a/plugins/pycv/pythontests/.gitignore b/plugins/pycv/pythontests/.gitignore new file mode 100644 index 0000000000..e378414052 --- /dev/null +++ b/plugins/pycv/pythontests/.gitignore @@ -0,0 +1,4 @@ +bck* +*.out +logfile +*.log From 9112fa103a9d5e0746d69054fe85537009b2693f Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:49:37 +0200 Subject: [PATCH 08/33] reorganized the code to try to work --- plugins/pycv/CMakeLists.txt | 4 +- plugins/pycv/pyproject.toml | 6 +- plugins/pycv/pythontests/mypycv.py | 19 +++++ plugins/pycv/pythontests/test_run.py | 106 +++++++++++++++++++++++++++ plugins/pycv/pythontests/traj.xyz | 24 ++++++ plugins/pycv/src/pycv/__init__.py | 10 +++ 6 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 plugins/pycv/pythontests/mypycv.py create mode 100644 plugins/pycv/pythontests/test_run.py create mode 100644 plugins/pycv/pythontests/traj.xyz create mode 100644 plugins/pycv/src/pycv/__init__.py diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index 8e8fd5701e..ba2905f225 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -75,8 +75,10 @@ target_compile_options(PythonCVInterface PUBLIC ${PLUMED_CXX_FLAGS}) target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) target_link_libraries(PythonCVInterface PUBLIC plumedKernel ${PLUMED_DYNAMIC_LIBS}) target_include_directories(PythonCVInterface PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) +#this removes the "lib" prefix +set_target_properties(PythonCVInterface PROPERTIES PREFIX "") -install(TARGETS PythonCVInterface DESTINATION .) +install(TARGETS PythonCVInterface DESTINATION pycv) ################################################################################ ############################The pvCV companion module########################### diff --git a/plugins/pycv/pyproject.toml b/plugins/pycv/pyproject.toml index 45f0e95f6e..ac06ea8c2a 100644 --- a/plugins/pycv/pyproject.toml +++ b/plugins/pycv/pyproject.toml @@ -4,9 +4,8 @@ build-backend = "scikit_build_core.build" [project] -name = "pyCV" +name = "pycv" dependencies = [ - "plumed", "numpy", "pybind11>=2.10.3,<=2.11.1" ] @@ -32,6 +31,8 @@ classifiers = [ [project.optional-dependencies] test = ["pytest", "plumed"] +[project.scripts] +pycv = "pycv:main" [tool.scikit-build] wheel.expand-macos-universal-tags = true @@ -57,3 +58,4 @@ test-extras = ["test"] [tool.cibuildwheel.pyodide] build-frontend = {name = "build", args = ["--exports", "whole_archive"]} + diff --git a/plugins/pycv/pythontests/mypycv.py b/plugins/pycv/pythontests/mypycv.py new file mode 100644 index 0000000000..13b71e3a52 --- /dev/null +++ b/plugins/pycv/pythontests/mypycv.py @@ -0,0 +1,19 @@ +import plumedCommunications as PLMD +import numpy +from sys import stderr as log +# log = open("pydist.log", "w") + +print("Imported my pydist+.", file=log) + + +def plumedInitio(action: PLMD.PythonCVInterface): + # return {"Value": {"period": [None,0,0]}} + # return {"Value": {"period": None}} + return {"Value": {"period": ["0",0.3]}} +plumedInit={"Value": {"period": None},"NOPBC":False, + "ATOMS":"1,2"} + +def plumedCalculate(action: PLMD.PythonCVInterface): + ret = [action.nat] + print ("Hello from plumedCalculate") + return ret diff --git a/plugins/pycv/pythontests/test_run.py b/plugins/pycv/pythontests/test_run.py new file mode 100644 index 0000000000..113ca06cd1 --- /dev/null +++ b/plugins/pycv/pythontests/test_run.py @@ -0,0 +1,106 @@ +import unittest +import numpy as np +from plumed import Plumed + +import os +from contextlib import contextmanager + +@contextmanager +def cd(newdir): + prevdir = os.getcwd() + os.chdir(newdir) + try: + yield + finally: + os.chdir(prevdir) + +def read_xyz(filename): + xyz = open(filename) + n_atoms = int(xyz.readline()) + title = xyz.readline() + trajectory =[] + while True : + atom_type= np.zeros(n_atoms).astype(str) + coordinates = np.zeros([n_atoms,3]) + for i in range(0,n_atoms) : + line = xyz.readline() + atom,x,y,z = line.split() + atom_type[i]=atom + coordinates[i,:]=np.array([x,y,z],dtype=np.float64) + trajectory.append( coordinates ) + nextline = xyz.readline() + if( nextline=="" ) : break + c_atoms = int(nextline) + if( c_atoms!=n_atoms ) : break + title = xyz.readline() + xyz.close() + return trajectory + +def create_plumed_var( plmd, name, command ): + plmd.cmd("readInputLine", name + ": " + command ) + shape = np.zeros( 1, dtype=np.int_ ) + plmd.cmd("getDataRank " + name, shape ) + data = np.zeros((1)) + plmd.cmd("setMemoryForData " + name, data ) + return data + +class Test(unittest.TestCase): + def runtest(self): + from pycv import getLib + os.system('rm -f bck.*') + # Output to four decimal places only + np.set_printoptions(precision=4) + # Read trajectory + traj = read_xyz("traj.xyz") + num_frames = len(traj) + num_atoms = traj[0].shape[0] + + # Create arrays for stuff + box=np.diag(12.41642*np.ones(3,dtype=np.float64)) + virial=np.zeros((3,3),dtype=np.float64) + masses=np.ones(num_atoms,dtype=np.float64) + forces=np.random.rand(num_atoms,3) + charges=np.zeros(num_atoms,dtype=np.float64) + + # Create PLUMED object and read input + plmd = Plumed() + + # not really needed, used to check https://github.com/plumed/plumed2/issues/916 + plumed_version = np.zeros(1, dtype=np.intc) + plmd.cmd( "getApiVersion", plumed_version) + + plmd.cmd("setMDEngine","python") + plmd.cmd("setTimestep", 1.) + plmd.cmd("setKbT", 1.) + plmd.cmd("setNatoms",num_atoms) + plmd.cmd("setLogFile","test.log") + plmd.cmd("init") + # plmd.cmd("readInputLine","LOAD FILE=./libPythonCVInterface.so") + plmd.cmd("readInputLine",f"LOAD FILE={getLib()}") + cvPy = create_plumed_var( plmd, "cvPy", "PYCVINTERFACE IMPORT=mypycv") + plmd.cmd("readInputLine","PRINT FILE=colvar.out ARG=*") + # Open an output file + with open("logfile", "w+") as of: + + # Now analyze the trajectory + for step in range(0,num_frames) : + of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n" ) + plmd.cmd("setStep",step ) + plmd.cmd("setBox",box ) + plmd.cmd("setMasses", masses ) + plmd.cmd("setCharges", charges ) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces ) + plmd.cmd("setVirial", virial ) + plmd.cmd("calc") + + self.assertEqual(cvPy,2) + + + def test(self): + + self.runtest() + +if __name__ == "__main__": + unittest.main() + diff --git a/plugins/pycv/pythontests/traj.xyz b/plugins/pycv/pythontests/traj.xyz new file mode 100644 index 0000000000..c0e66cf2b2 --- /dev/null +++ b/plugins/pycv/pythontests/traj.xyz @@ -0,0 +1,24 @@ +4 +100 100 100 +X 5 0 0 +X 0 0 0 +X 0 5 0 +X 5 5 0 +4 +100 100 100 +X 5 0 0 +X 0 0 0 +X 0 5 0 +X 0 5 5 +4 +100 100 100 +X 5 0 0 +X 0 0 0 +X 0 5 0 +X -5 5 0 +4 +100 100 100 +X 5 0 0 +X 0 0 0 +X 0 5 0 +X 0 5 -5 diff --git a/plugins/pycv/src/pycv/__init__.py b/plugins/pycv/src/pycv/__init__.py new file mode 100644 index 0000000000..2fb1625192 --- /dev/null +++ b/plugins/pycv/src/pycv/__init__.py @@ -0,0 +1,10 @@ +import inspect + +def getLib(): + import pycv + path_of_this = inspect.getfile(pycv) + path_of_lib=path_of_this[:path_of_this.rfind("/")] + return path_of_lib+"/PythonCVInterface.so" +def main(): + print(getLib()) + return 0 \ No newline at end of file From 389e11a96daaef46fdec34d63c748615c2155767 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:06:51 +0200 Subject: [PATCH 09/33] bettwen naming --- plugins/pycv/pythontests/test_run.py | 6 +++--- plugins/pycv/src/pycv/__init__.py | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/pycv/pythontests/test_run.py b/plugins/pycv/pythontests/test_run.py index 113ca06cd1..91a68bcb20 100644 --- a/plugins/pycv/pythontests/test_run.py +++ b/plugins/pycv/pythontests/test_run.py @@ -46,7 +46,7 @@ def create_plumed_var( plmd, name, command ): class Test(unittest.TestCase): def runtest(self): - from pycv import getLib + from pycv import getPythonCVInterface os.system('rm -f bck.*') # Output to four decimal places only np.set_printoptions(precision=4) @@ -75,8 +75,8 @@ def runtest(self): plmd.cmd("setNatoms",num_atoms) plmd.cmd("setLogFile","test.log") plmd.cmd("init") - # plmd.cmd("readInputLine","LOAD FILE=./libPythonCVInterface.so") - plmd.cmd("readInputLine",f"LOAD FILE={getLib()}") + # plmd.cmd("readInputLine","LOAD FILE=./PythonCVInterface.so") + plmd.cmd("readInputLine",f"LOAD FILE={getPythonCVInterface()}") cvPy = create_plumed_var( plmd, "cvPy", "PYCVINTERFACE IMPORT=mypycv") plmd.cmd("readInputLine","PRINT FILE=colvar.out ARG=*") # Open an output file diff --git a/plugins/pycv/src/pycv/__init__.py b/plugins/pycv/src/pycv/__init__.py index 2fb1625192..91a0ad75d9 100644 --- a/plugins/pycv/src/pycv/__init__.py +++ b/plugins/pycv/src/pycv/__init__.py @@ -1,10 +1,15 @@ import inspect +# checked and formatted with ruff 0.6.9 -def getLib(): + +def getPythonCVInterface(): import pycv + path_of_this = inspect.getfile(pycv) - path_of_lib=path_of_this[:path_of_this.rfind("/")] - return path_of_lib+"/PythonCVInterface.so" + path_of_lib = path_of_this[: path_of_this.rfind("/")] + return path_of_lib + "/PythonCVInterface.so" + + def main(): - print(getLib()) - return 0 \ No newline at end of file + print(getPythonCVInterface()) + return 0 From a4875958ea8c16574880cccc32a405b72da26ef1 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:16:30 +0200 Subject: [PATCH 10/33] setting up a second run option, adding an helper --- plugins/pycv/src/pycv/__init__.py | 12 +++++++++++- plugins/pycv/src/pycv/__main__.py | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 plugins/pycv/src/pycv/__main__.py diff --git a/plugins/pycv/src/pycv/__init__.py b/plugins/pycv/src/pycv/__init__.py index 91a0ad75d9..8f2d79fec3 100644 --- a/plugins/pycv/src/pycv/__init__.py +++ b/plugins/pycv/src/pycv/__init__.py @@ -1,8 +1,8 @@ -import inspect # checked and formatted with ruff 0.6.9 def getPythonCVInterface(): + import inspect import pycv path_of_this = inspect.getfile(pycv) @@ -11,5 +11,15 @@ def getPythonCVInterface(): def main(): + from argparse import ArgumentParser + + parser = ArgumentParser( + prog="pyCV", + description="""shows the path for the pycv shared object. + + Just run this with no arguments to see the path. + """, + ) + _ = parser.parse_args() print(getPythonCVInterface()) return 0 diff --git a/plugins/pycv/src/pycv/__main__.py b/plugins/pycv/src/pycv/__main__.py new file mode 100644 index 0000000000..770c223002 --- /dev/null +++ b/plugins/pycv/src/pycv/__main__.py @@ -0,0 +1,6 @@ +if __name__ == "__main__": + import sys + + from . import main + + sys.exit(main()) From 4b81b97660f2e59e22a9c6b6ee072e3c285c7197 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Mon, 14 Oct 2024 15:08:44 +0200 Subject: [PATCH 11/33] removed the self-import gor getting the path of pycv --- plugins/pycv/src/pycv/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/pycv/src/pycv/__init__.py b/plugins/pycv/src/pycv/__init__.py index 8f2d79fec3..ee2bdd414a 100644 --- a/plugins/pycv/src/pycv/__init__.py +++ b/plugins/pycv/src/pycv/__init__.py @@ -2,10 +2,15 @@ def getPythonCVInterface(): - import inspect - import pycv + """returns the location of the pycv shared object""" + # older version + # import inspect + # import pycv - path_of_this = inspect.getfile(pycv) + # path_of_this = inspect.getfile(pycv) + import importlib.util + + path_of_this = importlib.util.find_spec("pycv").origin path_of_lib = path_of_this[: path_of_this.rfind("/")] return path_of_lib + "/PythonCVInterface.so" From 938228d882d90e944897639a6294d3c7b9626b17 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Mon, 14 Oct 2024 15:38:16 +0200 Subject: [PATCH 12/33] adding an example --- plugins/pycv/src/pycv/__init__.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/pycv/src/pycv/__init__.py b/plugins/pycv/src/pycv/__init__.py index ee2bdd414a..7cae10a7dd 100644 --- a/plugins/pycv/src/pycv/__init__.py +++ b/plugins/pycv/src/pycv/__init__.py @@ -25,6 +25,22 @@ def main(): Just run this with no arguments to see the path. """, ) - _ = parser.parse_args() + parser.add_argument( + "-p", + "--plumed", + help="print on screen an example plumed.dat", + action="store_true", + ) + args = parser.parse_args() + + if args.plumed: + print( + f"""LOAD FILE={getPythonCVInterface()} +cvPy:PYCVINTERFACE IMPORT=mypycv +fPy: PYFUNCTION IMPORT=mypycvfunc ARG=cvPy +PRINT FILE=colvar.out ARG=*""" + ) + return 0 + print(getPythonCVInterface()) return 0 From f2374044e7fa51f1bb734f87b9df644692786929 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:05:18 +0200 Subject: [PATCH 13/33] Better CMakefiles --- plugins/pycv/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index ba2905f225..a9d9c75d80 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -72,6 +72,7 @@ target_compile_definitions(PythonCVInterface PUBLIC ${PLUMED_CPP_FLAGS}) get_target_property(COMPILE_DEFINITIONS PythonCVInterface COMPILE_DEFINITIONS) message(STATUS "COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS}") target_compile_options(PythonCVInterface PUBLIC ${PLUMED_CXX_FLAGS}) +target_compile_options(PythonCVInterface PRIVATE -fvisibility=hidden) target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) target_link_libraries(PythonCVInterface PUBLIC plumedKernel ${PLUMED_DYNAMIC_LIBS}) target_include_directories(PythonCVInterface PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) @@ -86,8 +87,7 @@ install(TARGETS PythonCVInterface DESTINATION pycv) pybind11_add_module(plumedCommunications src/PlumedPythonEmbeddedModule.cpp) #python_add_library(plumedCommunications MODULE PlumedPythonEmbeddedModule.cpp WITH_SOABI) -# target_link_libraries(plumedCommunications PRIVATE pybind11::headers) -#target_compile_definitions(plumedCommunications PUBLIC ${PLUMED_CPP_FLAGS}) + target_link_libraries(plumedCommunications PRIVATE pybind11::headers) target_link_libraries(plumedCommunications PUBLIC plumedKernel ${PLUMED_DYNAMIC_LIBS}) target_link_libraries(plumedCommunications PUBLIC PythonCVInterface) target_include_directories(plumedCommunications PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) From c5062fcae8ce795117724aea0ae3e52740671688 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Wed, 16 Oct 2024 08:40:31 +0200 Subject: [PATCH 14/33] moving to a more "external" include fashion --- plugins/pycv/CMakeLists.txt | 4 ++-- plugins/pycv/src/ActionWithPython.cpp | 4 ++-- plugins/pycv/src/ActionWithPython.h | 2 +- plugins/pycv/src/PlumedPythonEmbeddedModule.cpp | 4 ++-- plugins/pycv/src/PythonCVInterface.cpp | 8 ++++---- plugins/pycv/src/PythonCVInterface.h | 2 +- plugins/pycv/src/PythonFunction.cpp | 4 ++-- plugins/pycv/src/PythonFunction.h | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index a9d9c75d80..ee84d1efe3 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -75,7 +75,7 @@ target_compile_options(PythonCVInterface PUBLIC ${PLUMED_CXX_FLAGS}) target_compile_options(PythonCVInterface PRIVATE -fvisibility=hidden) target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) target_link_libraries(PythonCVInterface PUBLIC plumedKernel ${PLUMED_DYNAMIC_LIBS}) -target_include_directories(PythonCVInterface PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) +target_include_directories(PythonCVInterface PUBLIC src ${PLUMED_INCLUDE_DIR}) #this removes the "lib" prefix set_target_properties(PythonCVInterface PROPERTIES PREFIX "") @@ -90,7 +90,7 @@ pybind11_add_module(plumedCommunications src/PlumedPythonEmbeddedModule.cpp) target_link_libraries(plumedCommunications PRIVATE pybind11::headers) target_link_libraries(plumedCommunications PUBLIC plumedKernel ${PLUMED_DYNAMIC_LIBS}) target_link_libraries(plumedCommunications PUBLIC PythonCVInterface) -target_include_directories(plumedCommunications PUBLIC src ${PLUMED_INCLUDE_DIR}/plumed) +target_include_directories(plumedCommunications PUBLIC src ${PLUMED_INCLUDE_DIR}) # The install directory is the output (wheel) directory install(TARGETS plumedCommunications DESTINATION .) diff --git a/plugins/pycv/src/ActionWithPython.cpp b/plugins/pycv/src/ActionWithPython.cpp index 6886dc1123..49bf3434f0 100644 --- a/plugins/pycv/src/ActionWithPython.cpp +++ b/plugins/pycv/src/ActionWithPython.cpp @@ -17,8 +17,8 @@ along with plumed. If not, see . #include "ActionWithPython.h" -#include "core/ActionWithValue.h" -#include "tools/DLLoader.h" +#include "plumed/core/ActionWithValue.h" +#include "plumed/tools/DLLoader.h" #include // everything needed for embedding #include diff --git a/plugins/pycv/src/ActionWithPython.h b/plugins/pycv/src/ActionWithPython.h index a941eb4bae..81ea0fccb1 100644 --- a/plugins/pycv/src/ActionWithPython.h +++ b/plugins/pycv/src/ActionWithPython.h @@ -20,7 +20,7 @@ along with plumed. If not, see . #include #include -#include "core/Action.h" +#include "plumed/core/Action.h" #include // everything needed for embedding diff --git a/plugins/pycv/src/PlumedPythonEmbeddedModule.cpp b/plugins/pycv/src/PlumedPythonEmbeddedModule.cpp index c0b2f5feb7..f991e49f75 100644 --- a/plugins/pycv/src/PlumedPythonEmbeddedModule.cpp +++ b/plugins/pycv/src/PlumedPythonEmbeddedModule.cpp @@ -21,8 +21,8 @@ along with plumed. If not, see . #include #include -#include "tools/Vector.h" -#include "tools/NeighborList.h" +#include "plumed/tools/Vector.h" +#include "plumed/tools/NeighborList.h" #include "PythonCVInterface.h" #include "PythonFunction.h" diff --git a/plugins/pycv/src/PythonCVInterface.cpp b/plugins/pycv/src/PythonCVInterface.cpp index 374c370ea1..08fb1fe9ef 100644 --- a/plugins/pycv/src/PythonCVInterface.cpp +++ b/plugins/pycv/src/PythonCVInterface.cpp @@ -16,10 +16,10 @@ along with plumed. If not, see . +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ #include "PythonCVInterface.h" -#include "core/ActionRegister.h" -#include "core/PlumedMain.h" -#include "tools/NeighborList.h" -#include "tools/Pbc.h" +#include "plumed/core/ActionRegister.h" +#include "plumed/core/PlumedMain.h" +#include "plumed/tools/NeighborList.h" +#include "plumed/tools/Pbc.h" #include // everything needed for embedding #include diff --git a/plugins/pycv/src/PythonCVInterface.h b/plugins/pycv/src/PythonCVInterface.h index b5971029c1..23bd60f69f 100644 --- a/plugins/pycv/src/PythonCVInterface.h +++ b/plugins/pycv/src/PythonCVInterface.h @@ -18,7 +18,7 @@ along with plumed. If not, see . #define __PLUMED_pycv_PythonCVInterface_h #include "ActionWithPython.h" -#include "colvar/Colvar.h" +#include "plumed/colvar/Colvar.h" namespace PLMD { diff --git a/plugins/pycv/src/PythonFunction.cpp b/plugins/pycv/src/PythonFunction.cpp index a0aa837f3f..23d007063e 100644 --- a/plugins/pycv/src/PythonFunction.cpp +++ b/plugins/pycv/src/PythonFunction.cpp @@ -16,8 +16,8 @@ along with plumed. If not, see . +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ #include "PythonFunction.h" -#include "core/ActionRegister.h" -#include "core/PlumedMain.h" // cite +#include "plumed/core/ActionRegister.h" +#include "plumed/core/PlumedMain.h" // cite #include // everything needed for embedding #include diff --git a/plugins/pycv/src/PythonFunction.h b/plugins/pycv/src/PythonFunction.h index 1f1059b46d..aa55aaf766 100644 --- a/plugins/pycv/src/PythonFunction.h +++ b/plugins/pycv/src/PythonFunction.h @@ -17,7 +17,7 @@ along with plumed. If not, see . #ifndef __PLUMED_pycv_PythonFunction_h #define __PLUMED_pycv_PythonFunction_h #include "ActionWithPython.h" -#include "function/Function.h" +#include "plumed/function/Function.h" #include namespace PLMD { From 32041bea60e113e87c9278eb93d10212d7c8c74b Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:35:00 +0200 Subject: [PATCH 15/33] Now pycv seems to work again --- plugins/pycv/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index ee84d1efe3..07509b0727 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -72,7 +72,10 @@ target_compile_definitions(PythonCVInterface PUBLIC ${PLUMED_CPP_FLAGS}) get_target_property(COMPILE_DEFINITIONS PythonCVInterface COMPILE_DEFINITIONS) message(STATUS "COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS}") target_compile_options(PythonCVInterface PUBLIC ${PLUMED_CXX_FLAGS}) -target_compile_options(PythonCVInterface PRIVATE -fvisibility=hidden) +# uncommenting this brings problems since some symbols here are needed by the python module +# even if it should be the correct setting +# https://gcc.gnu.org/wiki/Visibility could be a starting point +# target_compile_options(PythonCVInterface PRIVATE -fvisibility=hidden) target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) target_link_libraries(PythonCVInterface PUBLIC plumedKernel ${PLUMED_DYNAMIC_LIBS}) target_include_directories(PythonCVInterface PUBLIC src ${PLUMED_INCLUDE_DIR}) From b9d1e0a7519f0df23cf899bb88bc5d3910ad6a23 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:55:10 +0200 Subject: [PATCH 16/33] A more "canonical" CMake --- plugins/pycv/CMakeLists.txt | 96 +++++++++++++------------------------ 1 file changed, 33 insertions(+), 63 deletions(-) diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index 07509b0727..2fa30d623d 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -5,80 +5,53 @@ project( LANGUAGES CXX) set (CMAKE_CXX_STANDARD 17) +#Finding necessary packages find_package(Python REQUIRED COMPONENTS Interpreter Development) find_package(pybind11 CONFIG REQUIRED) -message(STATUS "pybind11 found: ${pybind11_VERSION}") +find_package(PkgConfig REQUIRED) +pkg_check_modules(plumed REQUIRED plumedInternals) -exec_program(plumed -ARGS info --include-dir -OUTPUT_VARIABLE PLUMED_INCLUDE_DIR -) +#Finding optionals things +if("-D__PLUMED_HAS_MPI=1" IN_LIST plumed_CFLAGS) + find_package(MPI REQUIRED) +endif() +if(MPI_CXX_FOUND) + list(APPEND extraLibs MPI::MPI_CXX) +endif() -exec_program(plumed -ARGS info --configuration -OUTPUT_VARIABLE PLUMED_CONFIG -) -set(PLUMED_CXX_FLAGS "") -set(PLUMED_CPP_FLAGS "") -set(PLUMED_DYNAMIC_LIBS "") +if("-fopenmp" IN_LIST plumed_STATIC_LDFLAGS_OTHER) + find_package(OpenMP REQUIRED) +endif() +if(OpenMP_CXX_FOUND ) + list(APPEND extraLibs OpenMP::OpenMP_CXX) +endif() -string(REPLACE "\n" ";" ProcessFile_LINES "${PLUMED_CONFIG}") -foreach(_line ${ProcessFile_LINES}) - # message(STATUS "Found PLUMED :${_line}") - if (${_line} MATCHES "CXXFLAGS=.*") - set(PLUMED_CXX_FLAGS ${_line}) - string(REGEX REPLACE "CXXFLAGS= *" "" PLUMED_CXX_FLAGS ${PLUMED_CXX_FLAGS}) - string(REPLACE " " ";" PLUMED_CXX_FLAGS ${PLUMED_CXX_FLAGS}) - # message(STATUS "Found PLUMED CXX_FLAGS: \"${PLUMED_CXX_FLAGS}\"") - message(STATUS "Found PLUMED CXX_FLAGS: ") - foreach (_flag ${PLUMED_CXX_FLAGS}) - message(STATUS " \"${_flag}\"") - endforeach() - endif() - if (${_line} MATCHES "CPPFLAGS=.*") - set(PLUMED_CPP_FLAGS ${_line}) - string(REGEX REPLACE "CPPFLAGS= *" "" PLUMED_CPP_FLAGS ${PLUMED_CPP_FLAGS}) - string(REPLACE "\\" "" PLUMED_CPP_FLAGS ${PLUMED_CPP_FLAGS}) - string(REPLACE "-D" ";" PLUMED_CPP_FLAGS ${PLUMED_CPP_FLAGS}) - # message(STATUS "Found PLUMED CPP_FLAGS: \"${PLUMED_CPP_FLAGS}\"") - message(STATUS "Found PLUMED CPP_FLAGS:") - foreach(_flag ${PLUMED_CPP_FLAGS}) - message(STATUS " \"${_flag}\"") - endforeach() - - endif() - if (${_line} MATCHES "DYNAMIC_LIBS=.*") - set(PLUMED_DYNAMIC_LIBS ${_line}) - string(REGEX REPLACE "DYNAMIC_LIBS= *" "" PLUMED_DYNAMIC_LIBS ${PLUMED_DYNAMIC_LIBS}) - string(REPLACE " " ";" PLUMED_DYNAMIC_LIBS ${PLUMED_DYNAMIC_LIBS}) - # message(STATUS "Found PLUMED DYNAMIC_LIBS: \"${PLUMED_DYNAMIC_LIBS}\"") - message(STATUS "Found PLUMED DYNAMIC_LIBS:") - foreach(_flag ${PLUMED_DYNAMIC_LIBS}) - message(STATUS " \"${_flag}\"") - endforeach() - endif() - -endforeach() +include(CheckCXXCompilerFlag) +check_cxx_compiler_flag(-fno-gnu-unique USE_NO_GNU_UNIQUE) +if(USE_NO_GNU_UNIQUE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-gnu-unique") +endif() + +# plumed_STATIC_LDFLAGS_OTHER:INTERNAL=-rdynamic;-Wl,-Bsymbolic;-fopenmp +#-rdynamic is automatically set by cmake, as -fPIC -message(STATUS "Plumed include dir: ${PLUMED_INCLUDE_DIR}") -set(CMAke__extra) ################################################################################ ################################the pycv library################################ ################################################################################ -#TODO: remove the "lib" prefix + add_library(PythonCVInterface SHARED src/ActionWithPython.cpp src/PythonCVInterface.cpp src/PythonFunction.cpp) #public, so they trickle down to the python module -target_compile_definitions(PythonCVInterface PUBLIC ${PLUMED_CPP_FLAGS}) -get_target_property(COMPILE_DEFINITIONS PythonCVInterface COMPILE_DEFINITIONS) -message(STATUS "COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS}") +target_compile_definitions(PythonCVInterface PUBLIC ${plumed_CFLAGS}) target_compile_options(PythonCVInterface PUBLIC ${PLUMED_CXX_FLAGS}) -# uncommenting this brings problems since some symbols here are needed by the python module -# even if it should be the correct setting +target_include_directories(PythonCVInterface PUBLIC src ${plumed_INCLUDEDIR}) +####################################################################### +# uncommenting this brings problems since some symbols here are needed +# by the python module even if it should be the correct setting... # https://gcc.gnu.org/wiki/Visibility could be a starting point +####################################################################### # target_compile_options(PythonCVInterface PRIVATE -fvisibility=hidden) target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) -target_link_libraries(PythonCVInterface PUBLIC plumedKernel ${PLUMED_DYNAMIC_LIBS}) -target_include_directories(PythonCVInterface PUBLIC src ${PLUMED_INCLUDE_DIR}) +target_link_libraries(PythonCVInterface PUBLIC plumedKernel ${extraLibs}) #this removes the "lib" prefix set_target_properties(PythonCVInterface PROPERTIES PREFIX "") @@ -89,11 +62,8 @@ install(TARGETS PythonCVInterface DESTINATION pycv) ################################################################################ pybind11_add_module(plumedCommunications src/PlumedPythonEmbeddedModule.cpp) -#python_add_library(plumedCommunications MODULE PlumedPythonEmbeddedModule.cpp WITH_SOABI) - target_link_libraries(plumedCommunications PRIVATE pybind11::headers) -target_link_libraries(plumedCommunications PUBLIC plumedKernel ${PLUMED_DYNAMIC_LIBS}) +target_link_libraries(plumedCommunications PRIVATE pybind11::headers) target_link_libraries(plumedCommunications PUBLIC PythonCVInterface) -target_include_directories(plumedCommunications PUBLIC src ${PLUMED_INCLUDE_DIR}) # The install directory is the output (wheel) directory install(TARGETS plumedCommunications DESTINATION .) From 9dc5e48e38fa352c2501c39fc1078c9cad697b5f Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:18:12 +0200 Subject: [PATCH 17/33] now it shoudl work with plumed from pkg-config or not installed (just needs the plumed executable in the path) --- plugins/pycv/CMakeLists.txt | 48 ++++++++++--------- plugins/pycv/FindPlumed.cmake | 87 +++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 21 deletions(-) create mode 100644 plugins/pycv/FindPlumed.cmake diff --git a/plugins/pycv/CMakeLists.txt b/plugins/pycv/CMakeLists.txt index 2fa30d623d..e3f6f69a2b 100644 --- a/plugins/pycv/CMakeLists.txt +++ b/plugins/pycv/CMakeLists.txt @@ -3,27 +3,32 @@ project( ${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES CXX) -set (CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 17) -#Finding necessary packages +message( + STATUS + "Everithing should work fine if you are in the same environment in which you have compiled plumed" +) +# FinPlumed is here: +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}") +# Finding necessary packages find_package(Python REQUIRED COMPONENTS Interpreter Development) find_package(pybind11 CONFIG REQUIRED) -find_package(PkgConfig REQUIRED) -pkg_check_modules(plumed REQUIRED plumedInternals) +find_package(Plumed REQUIRED) -#Finding optionals things -if("-D__PLUMED_HAS_MPI=1" IN_LIST plumed_CFLAGS) - find_package(MPI REQUIRED) +# Finding optionals things +if(Plumed_HAS_MPI) + find_package(MPI REQUIRED) endif() if(MPI_CXX_FOUND) - list(APPEND extraLibs MPI::MPI_CXX) + list(APPEND extraLibs MPI::MPI_CXX) endif() -if("-fopenmp" IN_LIST plumed_STATIC_LDFLAGS_OTHER) - find_package(OpenMP REQUIRED) +if(Plumed_HAS_OPENMP) + find_package(OpenMP REQUIRED) endif() -if(OpenMP_CXX_FOUND ) - list(APPEND extraLibs OpenMP::OpenMP_CXX) +if(OpenMP_CXX_FOUND) + list(APPEND extraLibs OpenMP::OpenMP_CXX) endif() include(CheckCXXCompilerFlag) @@ -33,18 +38,19 @@ if(USE_NO_GNU_UNIQUE) endif() # plumed_STATIC_LDFLAGS_OTHER:INTERNAL=-rdynamic;-Wl,-Bsymbolic;-fopenmp -#-rdynamic is automatically set by cmake, as -fPIC +# -rdynamic is automatically set by cmake, and also -fPIC ################################################################################ ################################the pycv library################################ ################################################################################ -add_library(PythonCVInterface SHARED src/ActionWithPython.cpp src/PythonCVInterface.cpp src/PythonFunction.cpp) -#public, so they trickle down to the python module -target_compile_definitions(PythonCVInterface PUBLIC ${plumed_CFLAGS}) -target_compile_options(PythonCVInterface PUBLIC ${PLUMED_CXX_FLAGS}) -target_include_directories(PythonCVInterface PUBLIC src ${plumed_INCLUDEDIR}) -####################################################################### +add_library( + PythonCVInterface SHARED src/ActionWithPython.cpp src/PythonCVInterface.cpp + src/PythonFunction.cpp) +# public, so they trickle down to the python module +target_compile_definitions(PythonCVInterface PUBLIC ${Plumed_CFLAGS}) +target_include_directories(PythonCVInterface PUBLIC src ${Plumed_INCLUDEDIR}) +# #################################################################### # uncommenting this brings problems since some symbols here are needed # by the python module even if it should be the correct setting... # https://gcc.gnu.org/wiki/Visibility could be a starting point @@ -52,13 +58,13 @@ target_include_directories(PythonCVInterface PUBLIC src ${plumed_INCLUDEDIR}) # target_compile_options(PythonCVInterface PRIVATE -fvisibility=hidden) target_link_libraries(PythonCVInterface PRIVATE pybind11::embed) target_link_libraries(PythonCVInterface PUBLIC plumedKernel ${extraLibs}) -#this removes the "lib" prefix +# this removes the "lib" prefix set_target_properties(PythonCVInterface PROPERTIES PREFIX "") install(TARGETS PythonCVInterface DESTINATION pycv) ################################################################################ -############################The pvCV companion module########################### +###########################The pvCV companion module############################ ################################################################################ pybind11_add_module(plumedCommunications src/PlumedPythonEmbeddedModule.cpp) diff --git a/plugins/pycv/FindPlumed.cmake b/plugins/pycv/FindPlumed.cmake new file mode 100644 index 0000000000..e2a816cbc4 --- /dev/null +++ b/plugins/pycv/FindPlumed.cmake @@ -0,0 +1,87 @@ +if(NOT Plumed_FOUND) + find_package(PkgConfig) + if(Plumed_FIND_QUIETLY) + function(message) + # THIS completely shuts down messages + endfunction() + pkg_check_modules(PLUMED QUIET plumedInternals) + else() + pkg_check_modules(PLUMED plumedInternals) + endif() + + if(Plumed_FOUND) + if("-D__PLUMED_HAS_MPI=1" IN_LIST Plumed_CFLAGS) + set(Plumed_HAS_MPI + 1 + CACHE INTERNAL "plumed has MPI") + endif() + if("-fopenmp" IN_LIST Plumed_STATIC_LDFLAGS_OTHER) + set(Plumed_HAS_OPENMP + 1 + CACHE INTERNAL "plumed has OpenMP") + endif() + else() + message(STATUS "plumed not found via pkgconfig, trying executable") + + execute_process( + COMMAND plumed info --include-dir + RESULT_VARIABLE PLUMED_EXECUTABLE + OUTPUT_QUIET ERROR_QUIET) + if(PLUMED_EXECUTABLE EQUAL 0) + set(Plumed_FOUND + 1 + CACHE INTERNAL "plumed found") + + message(STATUS "Configuring plumed from executable") + execute_process( + COMMAND plumed info --include-dir + OUTPUT_VARIABLE Plumed_INCLUDEDIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + set(Plumed_INCLUDEDIR + ${Plumed_INCLUDEDIR} + CACHE INTERNAL "plumed include dir") + execute_process( + COMMAND plumed info --configuration + OUTPUT_VARIABLE Plumed_CONFIG + OUTPUT_STRIP_TRAILING_WHITESPACE) + + set(Plumed_CPP_FLAGS "") + + string(REPLACE "\n" ";" ProcessFile_LINES "${Plumed_CONFIG}") + foreach(_line ${ProcessFile_LINES}) + if(${_line} MATCHES "CPPFLAGS=.*") + set(Plumed_CPP_FLAGS ${_line}) + string(REGEX REPLACE "CPPFLAGS= *" "" Plumed_CPP_FLAGS + ${Plumed_CPP_FLAGS}) + string(REPLACE "\\" "" Plumed_CPP_FLAGS ${Plumed_CPP_FLAGS}) + string(REPLACE "-D" ";" Plumed_CPP_FLAGS ${Plumed_CPP_FLAGS}) + # message(STATUS "Found PLUMED CPP_FLAGS: \"${Plumed_CPP_FLAGS}\"") + # message(STATUS "Found PLUMED CPP_FLAGS:") foreach(_flag + # ${Plumed_CPP_FLAGS}) message(STATUS " \"${_flag}\"") endforeach() + endif() + if(${_line} MATCHES ".*-fopenmp.*") + set(Plumed_HAS_MPI + 1 + CACHE INTERNAL "plumed has MPI") + endif() + endforeach() + set(Plumed_CFLAGS + ${Plumed_CPP_FLAGS} + CACHE INTERNAL "plumed Definitions flags") + + execute_process(COMMAND plumed config -q has mpi + RESULT_VARIABLE Plumed_WITH_MPI) + if(Plumed_WITH_MPI EQUAL 0) + set(Plumed_HAS_MPI + 1 + CACHE INTERNAL "plumed has MPI") + endif() + + else() + if(Plumed_FIND_REQUIRED) + message(FATAL_ERROR "plumed not found") + endif() + endif() + endif() +endif() From 8eb73c9daad2e77d31e15087429389aab0d5d9f4 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:08:50 +0200 Subject: [PATCH 18/33] Restored the Makefile --- plugins/pycv/Makefile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 plugins/pycv/Makefile diff --git a/plugins/pycv/Makefile b/plugins/pycv/Makefile new file mode 100644 index 0000000000..013840f7d5 --- /dev/null +++ b/plugins/pycv/Makefile @@ -0,0 +1,19 @@ +.PHONY: clean check check_standalone check_python all + +all: pycv_here + +pycv_here: src/*.cpp src/*.h src/pycv/*.py + @python3 -m pip install . + @which python3 > $@ + +clean: + @python3 -m pip uninstall pycv + +check_standalone: + $(MAKE) -C regtest testclean + $(MAKE) -C regtest checkfail + +check_python: + python3 -m pytest + +check: check_standalone check_python From 1c8737c97526b1717bb2b2ff8571f500ac652d9c Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:45:32 +0200 Subject: [PATCH 19/33] restoring the standalone tests --- .../regtest/pycvcomm/rt-MDinformations/config | 28 +++++++++++++++++++ .../pycvcomm/rt-MDinformations/plumed.dat | 2 +- .../regtest/pycvcomm/rt-PBC-getBox/config | 28 +++++++++++++++++++ .../regtest/pycvcomm/rt-PBC-getBox/plumed.dat | 2 +- .../regtest/pycvcomm/rt-PBC-getInvBox/config | 28 +++++++++++++++++++ .../pycvcomm/rt-PBC-getInvBox/plumed.dat | 2 +- plugins/pycv/regtest/pycvcomm/rt-PBCs/config | 28 +++++++++++++++++++ .../pycv/regtest/pycvcomm/rt-PBCs/plumed.dat | 2 +- .../pycvcomm/rt-absoluteIndexes/config | 28 +++++++++++++++++++ .../pycvcomm/rt-absoluteIndexes/plumed.dat | 2 +- .../regtest/pycvcomm/rt-autoFunctions/config | 28 +++++++++++++++++++ .../pycvcomm/rt-autoFunctions/plumed.dat | 2 +- plugins/pycv/regtest/pycvcomm/rt-doc/config | 28 +++++++++++++++++++ .../regtest/pycvcomm/rt-doc/config.reference | 28 +++++++++++++++++++ .../pycv/regtest/pycvcomm/rt-doc/plumed.dat | 2 +- .../regtest/pycvcomm/rt-getPosition/config | 28 +++++++++++++++++++ .../pycvcomm/rt-getPosition/plumed.dat | 2 +- .../regtest/pycvcomm/rt-getPositionNL/config | 28 +++++++++++++++++++ .../pycvcomm/rt-getPositionNL/plumed.dat | 2 +- .../pycvcomm/rt-getPositionNLPair/config | 28 +++++++++++++++++++ .../pycvcomm/rt-getPositionNLPair/plumed.dat | 2 +- .../regtest/pycvcomm/rt-getPositions/config | 28 +++++++++++++++++++ .../pycvcomm/rt-getPositions/plumed.dat | 2 +- .../pycv/regtest/pycvcomm/rt-makeWhole/config | 28 +++++++++++++++++++ .../regtest/pycvcomm/rt-makeWhole/plumed.dat | 2 +- .../pycvcomm/rt-massesAndCharges/config | 28 +++++++++++++++++++ .../pycvcomm/rt-massesAndCharges/plumed.dat | 2 +- .../pycvcomm/rt-massesAndChargesArray/config | 28 +++++++++++++++++++ .../rt-massesAndChargesArray/plumed.dat | 2 +- .../pycvcomm/rt-multipleComponents/config | 28 +++++++++++++++++++ .../pycvcomm/rt-multipleComponents/plumed.dat | 2 +- .../rt-multipleValuePeriodicity/config | 28 +++++++++++++++++++ .../rt-multipleValuePeriodicity/plumed.dat | 2 +- .../regtest/pycvcomm/rt-multiplecalls/config | 28 +++++++++++++++++++ .../pycvcomm/rt-multiplecalls/plumed.dat | 2 +- .../pycvcomm/rt-newFrameNewAtom/config | 28 +++++++++++++++++++ .../pycvcomm/rt-newFrameNewAtom/plumed.dat | 2 +- .../pycvcomm/rt-newFrameNewAtomSTR/config | 28 +++++++++++++++++++ .../pycvcomm/rt-newFrameNewAtomSTR/plumed.dat | 2 +- .../regtest/pycvcomm/rt-persistentData/config | 28 ++++++++++++++++++- .../pycvcomm/rt-persistentData/plumed.dat | 2 +- .../pycvcomm/rt-valuePeriodicity/config | 28 +++++++++++++++++++ .../pycvcomm/rt-valuePeriodicity/plumed.dat | 2 +- .../regtest/pycvfunc/rt-ArgsMethods/config | 28 +++++++++++++++++++ .../pycvfunc/rt-ArgsMethods/plumed.dat | 2 +- .../regtest/pycvfunc/rt-Components/config | 28 +++++++++++++++++++ .../regtest/pycvfunc/rt-Components/plumed.dat | 2 +- .../regtest/pycvfunc/rt-MDinformations/config | 28 +++++++++++++++++++ .../pycvfunc/rt-MDinformations/plumed.dat | 2 +- .../pycv/regtest/pycvfunc/rt-arguments/config | 28 +++++++++++++++++++ .../regtest/pycvfunc/rt-arguments/plumed.dat | 2 +- .../regtest/pycvfunc/rt-argumentsArray/config | 28 +++++++++++++++++++ .../pycvfunc/rt-argumentsArray/plumed.dat | 2 +- .../rt-argumentsWithComponents/config | 28 +++++++++++++++++++ .../rt-argumentsWithComponents/plumed.dat | 2 +- .../regtest/pycvfunc/rt-derivative/config | 28 +++++++++++++++++++ .../regtest/pycvfunc/rt-derivative/plumed.dat | 2 +- plugins/pycv/regtest/pycvfunc/rt-doc/config | 28 +++++++++++++++++++ .../regtest/pycvfunc/rt-doc/config.reference | 28 +++++++++++++++++++ .../pycv/regtest/pycvfunc/rt-doc/plumed.dat | 2 +- .../pycv/regtest/pycvfunc/rt-withPYCV/config | 28 +++++++++++++++++++ .../regtest/pycvfunc/rt-withPYCV/plumed.dat | 2 +- 62 files changed, 925 insertions(+), 31 deletions(-) diff --git a/plugins/pycv/regtest/pycvcomm/rt-MDinformations/config b/plugins/pycv/regtest/pycvcomm/rt-MDinformations/config index 7429ccc9fa..af185de1f2 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-MDinformations/config +++ b/plugins/pycv/regtest/pycvcomm/rt-MDinformations/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz --mc massCharges.dat" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-MDinformations/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-MDinformations/plumed.dat index b2aa6e0aa5..fc6d26d9b9 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-MDinformations/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-MDinformations/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE diff --git a/plugins/pycv/regtest/pycvcomm/rt-PBC-getBox/config b/plugins/pycv/regtest/pycvcomm/rt-PBC-getBox/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-PBC-getBox/config +++ b/plugins/pycv/regtest/pycvcomm/rt-PBC-getBox/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-PBC-getBox/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-PBC-getBox/plumed.dat index 99aca77cbe..8e0f71ac14 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-PBC-getBox/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-PBC-getBox/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE diff --git a/plugins/pycv/regtest/pycvcomm/rt-PBC-getInvBox/config b/plugins/pycv/regtest/pycvcomm/rt-PBC-getInvBox/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-PBC-getInvBox/config +++ b/plugins/pycv/regtest/pycvcomm/rt-PBC-getInvBox/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-PBC-getInvBox/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-PBC-getInvBox/plumed.dat index 58aa94faa7..ccfaae24fd 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-PBC-getInvBox/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-PBC-getInvBox/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE diff --git a/plugins/pycv/regtest/pycvcomm/rt-PBCs/config b/plugins/pycv/regtest/pycvcomm/rt-PBCs/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-PBCs/config +++ b/plugins/pycv/regtest/pycvcomm/rt-PBCs/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-PBCs/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-PBCs/plumed.dat index 4d73a47b57..d26fa5f694 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-PBCs/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-PBCs/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: PYCVINTERFACE ATOMS=1,4 IMPORT=pydistancePBCs CALCULATE=pydist diff --git a/plugins/pycv/regtest/pycvcomm/rt-absoluteIndexes/config b/plugins/pycv/regtest/pycvcomm/rt-absoluteIndexes/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-absoluteIndexes/config +++ b/plugins/pycv/regtest/pycvcomm/rt-absoluteIndexes/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-absoluteIndexes/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-absoluteIndexes/plumed.dat index b5ab5a470d..8cb195373b 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-absoluteIndexes/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-absoluteIndexes/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE diff --git a/plugins/pycv/regtest/pycvcomm/rt-autoFunctions/config b/plugins/pycv/regtest/pycvcomm/rt-autoFunctions/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-autoFunctions/config +++ b/plugins/pycv/regtest/pycvcomm/rt-autoFunctions/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-autoFunctions/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-autoFunctions/plumed.dat index a9cf9e0185..5a9cfb8f26 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-autoFunctions/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-autoFunctions/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE diff --git a/plugins/pycv/regtest/pycvcomm/rt-doc/config b/plugins/pycv/regtest/pycvcomm/rt-doc/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-doc/config +++ b/plugins/pycv/regtest/pycvcomm/rt-doc/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-doc/config.reference b/plugins/pycv/regtest/pycvcomm/rt-doc/config.reference index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-doc/config.reference +++ b/plugins/pycv/regtest/pycvcomm/rt-doc/config.reference @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-doc/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-doc/plumed.dat index 34b82a81c2..d3657abc0d 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-doc/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-doc/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvdist: PYCVINTERFACE IMPORT=pyhelp diff --git a/plugins/pycv/regtest/pycvcomm/rt-getPosition/config b/plugins/pycv/regtest/pycvcomm/rt-getPosition/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-getPosition/config +++ b/plugins/pycv/regtest/pycvcomm/rt-getPosition/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-getPosition/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-getPosition/plumed.dat index 4f10c542cc..aa7cc493f0 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-getPosition/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-getPosition/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: PYCVINTERFACE ATOMS=1,4 IMPORT=pydistancegetAtPos CALCULATE=pydist diff --git a/plugins/pycv/regtest/pycvcomm/rt-getPositionNL/config b/plugins/pycv/regtest/pycvcomm/rt-getPositionNL/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-getPositionNL/config +++ b/plugins/pycv/regtest/pycvcomm/rt-getPositionNL/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-getPositionNL/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-getPositionNL/plumed.dat index 75d37d16bc..1c7340e6d4 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-getPositionNL/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-getPositionNL/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: PYCVINTERFACE GROUPA=1,4 IMPORT=pydistancegetAtPos CALCULATE=pydist diff --git a/plugins/pycv/regtest/pycvcomm/rt-getPositionNLPair/config b/plugins/pycv/regtest/pycvcomm/rt-getPositionNLPair/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-getPositionNLPair/config +++ b/plugins/pycv/regtest/pycvcomm/rt-getPositionNLPair/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-getPositionNLPair/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-getPositionNLPair/plumed.dat index a8b77fa7ef..e35d02e559 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-getPositionNLPair/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-getPositionNLPair/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE diff --git a/plugins/pycv/regtest/pycvcomm/rt-getPositions/config b/plugins/pycv/regtest/pycvcomm/rt-getPositions/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-getPositions/config +++ b/plugins/pycv/regtest/pycvcomm/rt-getPositions/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-getPositions/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-getPositions/plumed.dat index 41acc74975..5995120f82 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-getPositions/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-getPositions/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: PYCVINTERFACE ATOMS=1,4 IMPORT=pydistancegetAt CALCULATE=pydist diff --git a/plugins/pycv/regtest/pycvcomm/rt-makeWhole/config b/plugins/pycv/regtest/pycvcomm/rt-makeWhole/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-makeWhole/config +++ b/plugins/pycv/regtest/pycvcomm/rt-makeWhole/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-makeWhole/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-makeWhole/plumed.dat index 7c72b82cb1..79bb423ec4 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-makeWhole/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-makeWhole/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE diff --git a/plugins/pycv/regtest/pycvcomm/rt-massesAndCharges/config b/plugins/pycv/regtest/pycvcomm/rt-massesAndCharges/config index 7429ccc9fa..af185de1f2 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-massesAndCharges/config +++ b/plugins/pycv/regtest/pycvcomm/rt-massesAndCharges/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz --mc massCharges.dat" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-massesAndCharges/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-massesAndCharges/plumed.dat index b5ab5a470d..8cb195373b 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-massesAndCharges/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-massesAndCharges/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE diff --git a/plugins/pycv/regtest/pycvcomm/rt-massesAndChargesArray/config b/plugins/pycv/regtest/pycvcomm/rt-massesAndChargesArray/config index 7429ccc9fa..af185de1f2 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-massesAndChargesArray/config +++ b/plugins/pycv/regtest/pycvcomm/rt-massesAndChargesArray/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz --mc massCharges.dat" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-massesAndChargesArray/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-massesAndChargesArray/plumed.dat index 2124644f0e..517ddbfa7d 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-massesAndChargesArray/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-massesAndChargesArray/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE diff --git a/plugins/pycv/regtest/pycvcomm/rt-multipleComponents/config b/plugins/pycv/regtest/pycvcomm/rt-multipleComponents/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-multipleComponents/config +++ b/plugins/pycv/regtest/pycvcomm/rt-multipleComponents/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-multipleComponents/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-multipleComponents/plumed.dat index 77e7340b95..a3a0ee55a3 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-multipleComponents/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-multipleComponents/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: PYCVINTERFACE ATOMS=1,2,4 IMPORT=pydistancegetAt CALCULATE=pydist NOPBC diff --git a/plugins/pycv/regtest/pycvcomm/rt-multipleValuePeriodicity/config b/plugins/pycv/regtest/pycvcomm/rt-multipleValuePeriodicity/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-multipleValuePeriodicity/config +++ b/plugins/pycv/regtest/pycvcomm/rt-multipleValuePeriodicity/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-multipleValuePeriodicity/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-multipleValuePeriodicity/plumed.dat index 5250932b26..5e41a1ab40 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-multipleValuePeriodicity/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-multipleValuePeriodicity/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE diff --git a/plugins/pycv/regtest/pycvcomm/rt-multiplecalls/config b/plugins/pycv/regtest/pycvcomm/rt-multiplecalls/config index 82e4472874..dca9b502ca 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-multiplecalls/config +++ b/plugins/pycv/regtest/pycvcomm/rt-multiplecalls/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz --dump-forces forces --dump-forces-fmt=%10.6f" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-multiplecalls/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-multiplecalls/plumed.dat index 527ea33178..1752024b03 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-multiplecalls/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-multiplecalls/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cv1: PYCVINTERFACE ATOMS=1,3 IMPORT=distcv CALCULATE=cv cv2: PYCVINTERFACE ATOMS=1,4 IMPORT=distcv CALCULATE=cv diff --git a/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtom/config b/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtom/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtom/config +++ b/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtom/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtom/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtom/plumed.dat index 4c7b6b9735..a31f126c5f 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtom/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtom/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cv1: PYCVINTERFACE ATOMS=@mdatoms IMPORT=pycvPerFrame CALCULATE=pydist PREPARE=changeAtom diff --git a/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtomSTR/config b/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtomSTR/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtomSTR/config +++ b/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtomSTR/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtomSTR/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtomSTR/plumed.dat index 4c7b6b9735..a31f126c5f 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtomSTR/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-newFrameNewAtomSTR/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cv1: PYCVINTERFACE ATOMS=@mdatoms IMPORT=pycvPerFrame CALCULATE=pydist PREPARE=changeAtom diff --git a/plugins/pycv/regtest/pycvcomm/rt-persistentData/config b/plugins/pycv/regtest/pycvcomm/rt-persistentData/config index 66a5c0dad7..a0ec704a92 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-persistentData/config +++ b/plugins/pycv/regtest/pycvcomm/rt-persistentData/config @@ -4,5 +4,31 @@ arg="--plumed plumed.dat --ixyz traj.xyz" #this will showcase that you can import a complex module!!! plumed_regtest_before(){ - cp -r ../pycvPersistentData . + cp -r ../pycvPersistentData . + + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 } diff --git a/plugins/pycv/regtest/pycvcomm/rt-persistentData/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-persistentData/plumed.dat index b5ebc5d1a4..dbbb42b33d 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-persistentData/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-persistentData/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cv1: PYCVINTERFACE ATOMS=@mdatoms IMPORT=pycvPersistentData CALCULATE=pydist INIT=pyinit diff --git a/plugins/pycv/regtest/pycvcomm/rt-valuePeriodicity/config b/plugins/pycv/regtest/pycvcomm/rt-valuePeriodicity/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-valuePeriodicity/config +++ b/plugins/pycv/regtest/pycvcomm/rt-valuePeriodicity/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvcomm/rt-valuePeriodicity/plumed.dat b/plugins/pycv/regtest/pycvcomm/rt-valuePeriodicity/plumed.dat index 52ea575ec2..c4ea179df8 100644 --- a/plugins/pycv/regtest/pycvcomm/rt-valuePeriodicity/plumed.dat +++ b/plugins/pycv/regtest/pycvcomm/rt-valuePeriodicity/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE diff --git a/plugins/pycv/regtest/pycvfunc/rt-ArgsMethods/config b/plugins/pycv/regtest/pycvfunc/rt-ArgsMethods/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-ArgsMethods/config +++ b/plugins/pycv/regtest/pycvfunc/rt-ArgsMethods/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvfunc/rt-ArgsMethods/plumed.dat b/plugins/pycv/regtest/pycvfunc/rt-ArgsMethods/plumed.dat index 658124827e..3a6dda360f 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-ArgsMethods/plumed.dat +++ b/plugins/pycv/regtest/pycvfunc/rt-ArgsMethods/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ d12c: DISTANCE ATOMS=1,2 COMPONENTS diff --git a/plugins/pycv/regtest/pycvfunc/rt-Components/config b/plugins/pycv/regtest/pycvfunc/rt-Components/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-Components/config +++ b/plugins/pycv/regtest/pycvfunc/rt-Components/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvfunc/rt-Components/plumed.dat b/plugins/pycv/regtest/pycvfunc/rt-Components/plumed.dat index bb48f0c8f4..9521aa747d 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-Components/plumed.dat +++ b/plugins/pycv/regtest/pycvfunc/rt-Components/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ dc: DISTANCE ATOMS=1,2 COMPONENTS diff --git a/plugins/pycv/regtest/pycvfunc/rt-MDinformations/config b/plugins/pycv/regtest/pycvfunc/rt-MDinformations/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-MDinformations/config +++ b/plugins/pycv/regtest/pycvfunc/rt-MDinformations/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvfunc/rt-MDinformations/plumed.dat b/plugins/pycv/regtest/pycvfunc/rt-MDinformations/plumed.dat index b75648d8e9..163660f533 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-MDinformations/plumed.dat +++ b/plugins/pycv/regtest/pycvfunc/rt-MDinformations/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ fPY: ... PYFUNCTION diff --git a/plugins/pycv/regtest/pycvfunc/rt-arguments/config b/plugins/pycv/regtest/pycvfunc/rt-arguments/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-arguments/config +++ b/plugins/pycv/regtest/pycvfunc/rt-arguments/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvfunc/rt-arguments/plumed.dat b/plugins/pycv/regtest/pycvfunc/rt-arguments/plumed.dat index ced0f2f8df..9bcea812e5 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-arguments/plumed.dat +++ b/plugins/pycv/regtest/pycvfunc/rt-arguments/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ d1: DISTANCE ATOMS=1,2 d2: DISTANCE ATOMS=1,3 diff --git a/plugins/pycv/regtest/pycvfunc/rt-argumentsArray/config b/plugins/pycv/regtest/pycvfunc/rt-argumentsArray/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-argumentsArray/config +++ b/plugins/pycv/regtest/pycvfunc/rt-argumentsArray/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvfunc/rt-argumentsArray/plumed.dat b/plugins/pycv/regtest/pycvfunc/rt-argumentsArray/plumed.dat index 84460382e5..e4fb18fbd6 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-argumentsArray/plumed.dat +++ b/plugins/pycv/regtest/pycvfunc/rt-argumentsArray/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ dc: DISTANCE ATOMS=1,2 COMPONENTS d: DISTANCE ATOMS=1,2 diff --git a/plugins/pycv/regtest/pycvfunc/rt-argumentsWithComponents/config b/plugins/pycv/regtest/pycvfunc/rt-argumentsWithComponents/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-argumentsWithComponents/config +++ b/plugins/pycv/regtest/pycvfunc/rt-argumentsWithComponents/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvfunc/rt-argumentsWithComponents/plumed.dat b/plugins/pycv/regtest/pycvfunc/rt-argumentsWithComponents/plumed.dat index 84460382e5..e4fb18fbd6 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-argumentsWithComponents/plumed.dat +++ b/plugins/pycv/regtest/pycvfunc/rt-argumentsWithComponents/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ dc: DISTANCE ATOMS=1,2 COMPONENTS d: DISTANCE ATOMS=1,2 diff --git a/plugins/pycv/regtest/pycvfunc/rt-derivative/config b/plugins/pycv/regtest/pycvfunc/rt-derivative/config index 7e13a932fd..a9b93b35ca 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-derivative/config +++ b/plugins/pycv/regtest/pycvfunc/rt-derivative/config @@ -9,3 +9,31 @@ plumed_regtest_after() { awk 'function abs(v) {return v < 0 ? -v : v} NR>1{print $1, $2, 0.0001 < abs($3-$4) } ' deriv_delta } + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvfunc/rt-derivative/plumed.dat b/plugins/pycv/regtest/pycvfunc/rt-derivative/plumed.dat index 519df8b70c..4a1d9d609b 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-derivative/plumed.dat +++ b/plugins/pycv/regtest/pycvfunc/rt-derivative/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ d1: DISTANCE ATOMS=1,2 d2: DISTANCE ATOMS=1,3 diff --git a/plugins/pycv/regtest/pycvfunc/rt-doc/config b/plugins/pycv/regtest/pycvfunc/rt-doc/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-doc/config +++ b/plugins/pycv/regtest/pycvfunc/rt-doc/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvfunc/rt-doc/config.reference b/plugins/pycv/regtest/pycvfunc/rt-doc/config.reference index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-doc/config.reference +++ b/plugins/pycv/regtest/pycvfunc/rt-doc/config.reference @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvfunc/rt-doc/plumed.dat b/plugins/pycv/regtest/pycvfunc/rt-doc/plumed.dat index f9618b43cf..05d656eacf 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-doc/plumed.dat +++ b/plugins/pycv/regtest/pycvfunc/rt-doc/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvdist: PYFUNCTION IMPORT=pyhelp diff --git a/plugins/pycv/regtest/pycvfunc/rt-withPYCV/config b/plugins/pycv/regtest/pycvfunc/rt-withPYCV/config index 010fed6f0a..bca39af1e7 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-withPYCV/config +++ b/plugins/pycv/regtest/pycvfunc/rt-withPYCV/config @@ -1,3 +1,31 @@ type=driver arg="--plumed plumed.dat --ixyz traj.xyz" + +plumed_regtest_before() { + if [[ -z $PLUMED_PYTHON_BIN ]]; then + PLUMED_PYTHON_BIN=python + fi + pycvpath=$($PLUMED_PYTHON_BIN -m pycv) + sed -i "s%@pycvpath@%${pycvpath}%g" plumed.dat +} + +plumed_custom_skip() { + if test -n "$PLUMED_PYTHON_SELECT"; then + export PLUMED_PYTHON_BIN="$PLUMED_PYTHON_SELECT" + if $PLUMED_PYTHON_BIN -c "import pycv"; then + return 1 + fi + + return 0 + fi + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import pycv" 2>/dev/null; then + if [ $python_bin != python ]; then + export PLUMED_PYTHON_BIN=$python_bin + fi + return 1 + fi + done + return 0 +} diff --git a/plugins/pycv/regtest/pycvfunc/rt-withPYCV/plumed.dat b/plugins/pycv/regtest/pycvfunc/rt-withPYCV/plumed.dat index a749a417cb..8d344a4078 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-withPYCV/plumed.dat +++ b/plugins/pycv/regtest/pycvfunc/rt-withPYCV/plumed.dat @@ -1,4 +1,4 @@ -LOAD FILE=../../../../PythonCVInterface.so +LOAD FILE=@pycvpath@ cvPY: ... PYCVINTERFACE From 62d8aba8c710111674590339186a1752c96abac6 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Thu, 17 Oct 2024 14:52:49 +0200 Subject: [PATCH 20/33] resahping the python test --- plugins/pycv/pythontests/test_run.py | 181 ++++++++++++++------------- 1 file changed, 94 insertions(+), 87 deletions(-) diff --git a/plugins/pycv/pythontests/test_run.py b/plugins/pycv/pythontests/test_run.py index 91a68bcb20..e5e7fc2d70 100644 --- a/plugins/pycv/pythontests/test_run.py +++ b/plugins/pycv/pythontests/test_run.py @@ -5,6 +5,9 @@ import os from contextlib import contextmanager +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + @contextmanager def cd(newdir): prevdir = os.getcwd() @@ -14,93 +17,97 @@ def cd(newdir): finally: os.chdir(prevdir) -def read_xyz(filename): - xyz = open(filename) - n_atoms = int(xyz.readline()) - title = xyz.readline() - trajectory =[] - while True : - atom_type= np.zeros(n_atoms).astype(str) - coordinates = np.zeros([n_atoms,3]) - for i in range(0,n_atoms) : - line = xyz.readline() - atom,x,y,z = line.split() - atom_type[i]=atom - coordinates[i,:]=np.array([x,y,z],dtype=np.float64) - trajectory.append( coordinates ) - nextline = xyz.readline() - if( nextline=="" ) : break - c_atoms = int(nextline) - if( c_atoms!=n_atoms ) : break - title = xyz.readline() - xyz.close() - return trajectory - -def create_plumed_var( plmd, name, command ): - plmd.cmd("readInputLine", name + ": " + command ) - shape = np.zeros( 1, dtype=np.int_ ) - plmd.cmd("getDataRank " + name, shape ) - data = np.zeros((1)) - plmd.cmd("setMemoryForData " + name, data ) - return data - -class Test(unittest.TestCase): - def runtest(self): - from pycv import getPythonCVInterface - os.system('rm -f bck.*') - # Output to four decimal places only - np.set_printoptions(precision=4) - # Read trajectory - traj = read_xyz("traj.xyz") - num_frames = len(traj) - num_atoms = traj[0].shape[0] - - # Create arrays for stuff - box=np.diag(12.41642*np.ones(3,dtype=np.float64)) - virial=np.zeros((3,3),dtype=np.float64) - masses=np.ones(num_atoms,dtype=np.float64) - forces=np.random.rand(num_atoms,3) - charges=np.zeros(num_atoms,dtype=np.float64) - - # Create PLUMED object and read input - plmd = Plumed() - - # not really needed, used to check https://github.com/plumed/plumed2/issues/916 - plumed_version = np.zeros(1, dtype=np.intc) - plmd.cmd( "getApiVersion", plumed_version) - - plmd.cmd("setMDEngine","python") - plmd.cmd("setTimestep", 1.) - plmd.cmd("setKbT", 1.) - plmd.cmd("setNatoms",num_atoms) - plmd.cmd("setLogFile","test.log") - plmd.cmd("init") - # plmd.cmd("readInputLine","LOAD FILE=./PythonCVInterface.so") - plmd.cmd("readInputLine",f"LOAD FILE={getPythonCVInterface()}") - cvPy = create_plumed_var( plmd, "cvPy", "PYCVINTERFACE IMPORT=mypycv") - plmd.cmd("readInputLine","PRINT FILE=colvar.out ARG=*") - # Open an output file - with open("logfile", "w+") as of: - - # Now analyze the trajectory - for step in range(0,num_frames) : - of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n" ) - plmd.cmd("setStep",step ) - plmd.cmd("setBox",box ) - plmd.cmd("setMasses", masses ) - plmd.cmd("setCharges", charges ) - plmd.cmd("setPositions", traj[step]) - plmd.cmd("setForces", forces ) - plmd.cmd("setVirial", virial ) - plmd.cmd("calc") - - self.assertEqual(cvPy,2) - - - def test(self): - - self.runtest() + +def read_xyz(filename: str): + xyz = open(filename) + n_atoms = int(xyz.readline()) + _ = xyz.readline() + trajectory = [] + while True: + atom_type = np.zeros(n_atoms).astype(str) + coordinates = np.zeros([n_atoms, 3]) + for i in range(0, n_atoms): + line = xyz.readline() + atom, x, y, z = line.split() + atom_type[i] = atom + coordinates[i, :] = np.array([x, y, z], dtype=np.float64) + trajectory.append(coordinates) + nextline = xyz.readline() + if nextline == "": + break + c_atoms = int(nextline) + if c_atoms != n_atoms: + break + _ = xyz.readline() + xyz.close() + return trajectory + + +def create_plumed_var(plmd: Plumed, name: str, command: str): + plmd.cmd("readInputLine", name + ": " + command) + shape = np.zeros(1, dtype=np.int_) + plmd.cmd("getDataRank " + name, shape) + data = np.zeros((1)) + plmd.cmd("setMemoryForData " + name, data) + return data + + +class TestPyCV(unittest.TestCase): + def setUpTraj(self): + self.traj = read_xyz("traj.xyz") + self.num_frames = len(self.traj) + self.num_atoms = self.traj[0].shape[0] + + # Create arrays for stuff + self.box = np.diag(12.41642 * np.ones(3, dtype=np.float64)) + self.virial = np.zeros((3, 3), dtype=np.float64) + self.masses = np.ones(self.num_atoms, dtype=np.float64) + self.forces = np.random.rand(self.num_atoms, 3) + self.charges = np.zeros(self.num_atoms, dtype=np.float64) + + def preparePlumed(self): + from pycv import getPythonCVInterface + + # Create PLUMED object and read input + plmd = Plumed() + + # not really needed, used to check https://github.com/plumed/plumed2/issues/916 + plumed_version = np.zeros(1, dtype=np.intc) + plmd.cmd("getApiVersion", plumed_version) + plmd.cmd("setMDEngine", "python") + plmd.cmd("setTimestep", 1.0) + plmd.cmd("setKbT", 1.0) + plmd.cmd("setNatoms", self.num_atoms) + plmd.cmd("setLogFile", "test.log") + plmd.cmd("init") + plmd.cmd("readInputLine", f"LOAD FILE={getPythonCVInterface()}") + return plmd + + def test_nat(self): + with cd(THIS_DIR): + self.setUpTraj() + plmd = self.preparePlumed() + cvPy = create_plumed_var(plmd, "cvPy", "PYCVINTERFACE IMPORT=mypycv") + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + # Open an output file + with open("logfile", "w+") as of: + # Now analyze the trajectory + for step in range(0, self.num_frames): + of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n") + plmd.cmd("setStep", step) + plmd.cmd("setBox", self.box) + plmd.cmd("setMasses", self.masses) + plmd.cmd("setCharges", self.charges) + plmd.cmd("setPositions", self.traj[step]) + plmd.cmd("setForces", self.forces) + plmd.cmd("setVirial", self.virial) + plmd.cmd("calc") + + self.assertEqual(cvPy, 2) + if __name__ == "__main__": + os.environ["PLUMED_MAXBACKUP"] = "0" + # Output to four decimal places only + np.set_printoptions(precision=4) unittest.main() - From 287ae990b9e07263933985fc40dcead639ec75f8 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:44:17 +0200 Subject: [PATCH 21/33] adding some extra tests --- .../{mypycv.py => atoms_number.py} | 2 +- plugins/pycv/pythontests/pydistancePBCs.py | 1 + .../pycv/pythontests/pydistancegetAtPos.py | 1 + plugins/pycv/pythontests/test_run.py | 56 ++++++++++++++++++- 4 files changed, 57 insertions(+), 3 deletions(-) rename plugins/pycv/pythontests/{mypycv.py => atoms_number.py} (97%) create mode 120000 plugins/pycv/pythontests/pydistancePBCs.py create mode 120000 plugins/pycv/pythontests/pydistancegetAtPos.py diff --git a/plugins/pycv/pythontests/mypycv.py b/plugins/pycv/pythontests/atoms_number.py similarity index 97% rename from plugins/pycv/pythontests/mypycv.py rename to plugins/pycv/pythontests/atoms_number.py index 13b71e3a52..0f3bca1aaf 100644 --- a/plugins/pycv/pythontests/mypycv.py +++ b/plugins/pycv/pythontests/atoms_number.py @@ -1,5 +1,5 @@ import plumedCommunications as PLMD -import numpy + from sys import stderr as log # log = open("pydist.log", "w") diff --git a/plugins/pycv/pythontests/pydistancePBCs.py b/plugins/pycv/pythontests/pydistancePBCs.py new file mode 120000 index 0000000000..7e45c7145a --- /dev/null +++ b/plugins/pycv/pythontests/pydistancePBCs.py @@ -0,0 +1 @@ +../regtest/pycvcomm/rt-PBCs/pydistancePBCs.py \ No newline at end of file diff --git a/plugins/pycv/pythontests/pydistancegetAtPos.py b/plugins/pycv/pythontests/pydistancegetAtPos.py new file mode 120000 index 0000000000..7d693ec5cd --- /dev/null +++ b/plugins/pycv/pythontests/pydistancegetAtPos.py @@ -0,0 +1 @@ +../regtest/pycvcomm/rt-getPosition/pydistancegetAtPos.py \ No newline at end of file diff --git a/plugins/pycv/pythontests/test_run.py b/plugins/pycv/pythontests/test_run.py index e5e7fc2d70..8fbb59e367 100644 --- a/plugins/pycv/pythontests/test_run.py +++ b/plugins/pycv/pythontests/test_run.py @@ -85,9 +85,10 @@ def preparePlumed(self): def test_nat(self): with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" self.setUpTraj() plmd = self.preparePlumed() - cvPy = create_plumed_var(plmd, "cvPy", "PYCVINTERFACE IMPORT=mypycv") + cvPy = create_plumed_var(plmd, "cvPy", "PYCVINTERFACE IMPORT=atoms_number") plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") # Open an output file with open("logfile", "w+") as of: @@ -105,9 +106,60 @@ def test_nat(self): self.assertEqual(cvPy, 2) + def test_atomPositions(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + self.setUpTraj() + plmd = self.preparePlumed() + + cvPy=create_plumed_var(plmd, "cvPy", "PYCVINTERFACE ATOMS=1,4 IMPORT=pydistancegetAtPos CALCULATE=pydist") + cvCPP=create_plumed_var(plmd, "cvCPP", "DISTANCE ATOMS=1,4 NOPBC") + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + # Open an output file + with open("logfile", "w+") as of: + # Now analyze the trajectory + for step in range(0, self.num_frames): + of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n") + plmd.cmd("setStep", step) + plmd.cmd("setBox", self.box) + plmd.cmd("setMasses", self.masses) + plmd.cmd("setCharges", self.charges) + plmd.cmd("setPositions", self.traj[step]) + plmd.cmd("setForces", self.forces) + plmd.cmd("setVirial", self.virial) + plmd.cmd("calc") + + np.testing.assert_almost_equal(cvPy, cvCPP,decimal=4) + + def test_atomPositionsPBC(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + self.setUpTraj() + plmd = self.preparePlumed() + + cvPy=create_plumed_var(plmd, "cvPy", "PYCVINTERFACE ATOMS=1,4 IMPORT=pydistancePBCs CALCULATE=pydist") + cvCPP=create_plumed_var(plmd, "cvCPP", "DISTANCE ATOMS=1,4") + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + # Open an output file + with open("logfile", "w+") as of: + # Now analyze the trajectory + for step in range(0, self.num_frames): + of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n") + plmd.cmd("setStep", step) + plmd.cmd("setBox", self.box) + plmd.cmd("setMasses", self.masses) + plmd.cmd("setCharges", self.charges) + plmd.cmd("setPositions", self.traj[step]) + plmd.cmd("setForces", self.forces) + plmd.cmd("setVirial", self.virial) + plmd.cmd("calc") + + np.testing.assert_almost_equal(cvPy, cvCPP,decimal=4) + if __name__ == "__main__": - os.environ["PLUMED_MAXBACKUP"] = "0" # Output to four decimal places only np.set_printoptions(precision=4) unittest.main() From 557887be3cd710a86f368dca99b796de446fce80 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:47:17 +0200 Subject: [PATCH 22/33] updating the WF --- .github/workflows/linuxWF.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/linuxWF.yml b/.github/workflows/linuxWF.yml index 21a1237ea2..8c96987838 100644 --- a/.github/workflows/linuxWF.yml +++ b/.github/workflows/linuxWF.yml @@ -198,8 +198,7 @@ jobs: if: contains( matrix.variant, '-pycv-' ) working-directory: ./plugins/pycv/ run: | - pip install --user -r requirements.txt source ../../sourceme.sh ln -s $(realpath ../../regtest/scripts) ./regtest/scripts - ./prepareMakeForDevelop.sh make check + From 6e405e9fa6227290026ec0b190680e812bd7378b Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:22:49 +0200 Subject: [PATCH 23/33] better makefile? --- plugins/pycv/Makefile | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/pycv/Makefile b/plugins/pycv/Makefile index 013840f7d5..0d23a37074 100644 --- a/plugins/pycv/Makefile +++ b/plugins/pycv/Makefile @@ -1,19 +1,24 @@ +#this makefiles assume that pip and pytest are installed .PHONY: clean check check_standalone check_python all all: pycv_here pycv_here: src/*.cpp src/*.h src/pycv/*.py - @python3 -m pip install . - @which python3 > $@ + @echo installing pycv + pip install . + touch $@ clean: - @python3 -m pip uninstall pycv + pip uninstall pycv + rm -fv pycv_here -check_standalone: +check_standalone: pycv_here $(MAKE) -C regtest testclean $(MAKE) -C regtest checkfail -check_python: - python3 -m pytest +#just in case pytest is still not installed we install it before the tests +check_python: pycv_here + pip install pytest + pytest check: check_standalone check_python From 840993e5cfa3654971ae3d8bc7b48ad9d52a17b9 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 18 Oct 2024 12:19:02 +0200 Subject: [PATCH 24/33] addressing a problem with master --- plugins/pycv/pythontests/pycvPerFrame.py | 1 + plugins/pycv/pythontests/pycvPerFrameSTR.py | 1 + plugins/pycv/pythontests/test_cv.py | 167 ++++++++++++++++++ plugins/pycv/pythontests/test_run.py | 165 ----------------- .../pycv/pythontests/trajnewFrameNewAtom.xyz | 24 +++ .../pycv/pythontests/utilities_for_test.py | 84 +++++++++ plugins/pycv/src/PythonCVInterface.cpp | 3 + 7 files changed, 280 insertions(+), 165 deletions(-) create mode 120000 plugins/pycv/pythontests/pycvPerFrame.py create mode 120000 plugins/pycv/pythontests/pycvPerFrameSTR.py create mode 100644 plugins/pycv/pythontests/test_cv.py delete mode 100644 plugins/pycv/pythontests/test_run.py create mode 100644 plugins/pycv/pythontests/trajnewFrameNewAtom.xyz create mode 100644 plugins/pycv/pythontests/utilities_for_test.py diff --git a/plugins/pycv/pythontests/pycvPerFrame.py b/plugins/pycv/pythontests/pycvPerFrame.py new file mode 120000 index 0000000000..72efc4907a --- /dev/null +++ b/plugins/pycv/pythontests/pycvPerFrame.py @@ -0,0 +1 @@ +../regtest/pycvcomm/rt-newFrameNewAtom/pycvPerFrame.py \ No newline at end of file diff --git a/plugins/pycv/pythontests/pycvPerFrameSTR.py b/plugins/pycv/pythontests/pycvPerFrameSTR.py new file mode 120000 index 0000000000..fe96d1970c --- /dev/null +++ b/plugins/pycv/pythontests/pycvPerFrameSTR.py @@ -0,0 +1 @@ +../regtest/pycvcomm/rt-newFrameNewAtomSTR/pycvPerFrame.py \ No newline at end of file diff --git a/plugins/pycv/pythontests/test_cv.py b/plugins/pycv/pythontests/test_cv.py new file mode 100644 index 0000000000..44f78224a5 --- /dev/null +++ b/plugins/pycv/pythontests/test_cv.py @@ -0,0 +1,167 @@ +import unittest +import numpy as np + +from utilities_for_test import * + +import os + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class TestPyCV(unittest.TestCase): + def test_nat(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, num_frames, num_atoms, box, virial, masses, forces, charges = ( + setUpTraj("traj.xyz") + ) + plmd = preparePlumed(num_atoms) + cvPy = create_plumed_var(plmd, "cvPy", "PYCVINTERFACE IMPORT=atoms_number") + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + # Open an output file + with open("logfile", "w+") as of: + # Now analyze the trajectory + for step in range(0, num_frames): + of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n") + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + + self.assertEqual(cvPy, 2) + + def test_atomPositions(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, num_frames, num_atoms, box, virial, masses, forces, charges = ( + setUpTraj("traj.xyz") + ) + plmd = preparePlumed(num_atoms) + + cvPy = create_plumed_var( + plmd, + "cvPy", + "PYCVINTERFACE ATOMS=1,4 IMPORT=pydistancegetAtPos CALCULATE=pydist", + ) + cvCPP = create_plumed_var(plmd, "cvCPP", "DISTANCE ATOMS=1,4 NOPBC") + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + # Open an output file + with open("logfile", "w+") as of: + # Now analyze the trajectory + for step in range(0, num_frames): + of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n") + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + + np.testing.assert_almost_equal(cvPy, cvCPP, decimal=4) + + def test_atomPositionsPBC(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, num_frames, num_atoms, box, virial, masses, forces, charges = ( + setUpTraj("traj.xyz") + ) + plmd = preparePlumed(num_atoms) + + cvPy = create_plumed_var( + plmd, + "cvPy", + "PYCVINTERFACE ATOMS=1,4 IMPORT=pydistancePBCs CALCULATE=pydist", + ) + cvCPP = create_plumed_var(plmd, "cvCPP", "DISTANCE ATOMS=1,4") + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + # Open an output file + with open("logfile", "w+") as of: + # Now analyze the trajectory + for step in range(0, num_frames): + of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n") + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + + np.testing.assert_almost_equal(cvPy, cvCPP, decimal=4) + + def test_newFrameNewAtomSTR(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, num_frames, num_atoms, box, virial, masses, forces, charges = ( + setUpTraj("trajnewFrameNewAtom.xyz") + ) + plmd = preparePlumed(num_atoms) + + cvPy = create_plumed_var( + plmd, + "cvPy", + "PYCVINTERFACE ATOMS=@mdatoms IMPORT=pycvPerFrameSTR CALCULATE=pydist PREPARE=changeAtom", + ) + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + # Open an output file + with open("logfile", "w+") as of: + # Now analyze the trajectory + for step in range(0, num_frames): + of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n") + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + + np.testing.assert_almost_equal(cvPy, step + 1.0, decimal=4) + + def test_newFrameNewAtom(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, num_frames, num_atoms, box, virial, masses, forces, charges = ( + setUpTraj("trajnewFrameNewAtom.xyz") + ) + plmd = preparePlumed(num_atoms) + + cvPy = create_plumed_var( + plmd, + "cvPy", + "PYCVINTERFACE ATOMS=@mdatoms IMPORT=pycvPerFrame CALCULATE=pydist PREPARE=changeAtom", + ) + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + # Open an output file + with open("logfile", "w+") as of: + # Now analyze the trajectory + for step in range(0, num_frames): + of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n") + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + + np.testing.assert_almost_equal(cvPy, step + 1.0, decimal=4) + + +if __name__ == "__main__": + # Output to four decimal places only + np.set_printoptions(precision=4) + unittest.main() diff --git a/plugins/pycv/pythontests/test_run.py b/plugins/pycv/pythontests/test_run.py deleted file mode 100644 index 8fbb59e367..0000000000 --- a/plugins/pycv/pythontests/test_run.py +++ /dev/null @@ -1,165 +0,0 @@ -import unittest -import numpy as np -from plumed import Plumed - -import os -from contextlib import contextmanager - -THIS_DIR = os.path.dirname(os.path.abspath(__file__)) - - -@contextmanager -def cd(newdir): - prevdir = os.getcwd() - os.chdir(newdir) - try: - yield - finally: - os.chdir(prevdir) - - -def read_xyz(filename: str): - xyz = open(filename) - n_atoms = int(xyz.readline()) - _ = xyz.readline() - trajectory = [] - while True: - atom_type = np.zeros(n_atoms).astype(str) - coordinates = np.zeros([n_atoms, 3]) - for i in range(0, n_atoms): - line = xyz.readline() - atom, x, y, z = line.split() - atom_type[i] = atom - coordinates[i, :] = np.array([x, y, z], dtype=np.float64) - trajectory.append(coordinates) - nextline = xyz.readline() - if nextline == "": - break - c_atoms = int(nextline) - if c_atoms != n_atoms: - break - _ = xyz.readline() - xyz.close() - return trajectory - - -def create_plumed_var(plmd: Plumed, name: str, command: str): - plmd.cmd("readInputLine", name + ": " + command) - shape = np.zeros(1, dtype=np.int_) - plmd.cmd("getDataRank " + name, shape) - data = np.zeros((1)) - plmd.cmd("setMemoryForData " + name, data) - return data - - -class TestPyCV(unittest.TestCase): - def setUpTraj(self): - self.traj = read_xyz("traj.xyz") - self.num_frames = len(self.traj) - self.num_atoms = self.traj[0].shape[0] - - # Create arrays for stuff - self.box = np.diag(12.41642 * np.ones(3, dtype=np.float64)) - self.virial = np.zeros((3, 3), dtype=np.float64) - self.masses = np.ones(self.num_atoms, dtype=np.float64) - self.forces = np.random.rand(self.num_atoms, 3) - self.charges = np.zeros(self.num_atoms, dtype=np.float64) - - def preparePlumed(self): - from pycv import getPythonCVInterface - - # Create PLUMED object and read input - plmd = Plumed() - - # not really needed, used to check https://github.com/plumed/plumed2/issues/916 - plumed_version = np.zeros(1, dtype=np.intc) - plmd.cmd("getApiVersion", plumed_version) - plmd.cmd("setMDEngine", "python") - plmd.cmd("setTimestep", 1.0) - plmd.cmd("setKbT", 1.0) - plmd.cmd("setNatoms", self.num_atoms) - plmd.cmd("setLogFile", "test.log") - plmd.cmd("init") - plmd.cmd("readInputLine", f"LOAD FILE={getPythonCVInterface()}") - return plmd - - def test_nat(self): - with cd(THIS_DIR): - os.environ["PLUMED_MAXBACKUP"] = "0" - self.setUpTraj() - plmd = self.preparePlumed() - cvPy = create_plumed_var(plmd, "cvPy", "PYCVINTERFACE IMPORT=atoms_number") - plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") - # Open an output file - with open("logfile", "w+") as of: - # Now analyze the trajectory - for step in range(0, self.num_frames): - of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n") - plmd.cmd("setStep", step) - plmd.cmd("setBox", self.box) - plmd.cmd("setMasses", self.masses) - plmd.cmd("setCharges", self.charges) - plmd.cmd("setPositions", self.traj[step]) - plmd.cmd("setForces", self.forces) - plmd.cmd("setVirial", self.virial) - plmd.cmd("calc") - - self.assertEqual(cvPy, 2) - - def test_atomPositions(self): - with cd(THIS_DIR): - os.environ["PLUMED_MAXBACKUP"] = "0" - self.setUpTraj() - plmd = self.preparePlumed() - - cvPy=create_plumed_var(plmd, "cvPy", "PYCVINTERFACE ATOMS=1,4 IMPORT=pydistancegetAtPos CALCULATE=pydist") - cvCPP=create_plumed_var(plmd, "cvCPP", "DISTANCE ATOMS=1,4 NOPBC") - - plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") - # Open an output file - with open("logfile", "w+") as of: - # Now analyze the trajectory - for step in range(0, self.num_frames): - of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n") - plmd.cmd("setStep", step) - plmd.cmd("setBox", self.box) - plmd.cmd("setMasses", self.masses) - plmd.cmd("setCharges", self.charges) - plmd.cmd("setPositions", self.traj[step]) - plmd.cmd("setForces", self.forces) - plmd.cmd("setVirial", self.virial) - plmd.cmd("calc") - - np.testing.assert_almost_equal(cvPy, cvCPP,decimal=4) - - def test_atomPositionsPBC(self): - with cd(THIS_DIR): - os.environ["PLUMED_MAXBACKUP"] = "0" - self.setUpTraj() - plmd = self.preparePlumed() - - cvPy=create_plumed_var(plmd, "cvPy", "PYCVINTERFACE ATOMS=1,4 IMPORT=pydistancePBCs CALCULATE=pydist") - cvCPP=create_plumed_var(plmd, "cvCPP", "DISTANCE ATOMS=1,4") - - plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") - # Open an output file - with open("logfile", "w+") as of: - # Now analyze the trajectory - for step in range(0, self.num_frames): - of.write("RUNNING ANALYSIS FOR STEP " + str(step) + "\n") - plmd.cmd("setStep", step) - plmd.cmd("setBox", self.box) - plmd.cmd("setMasses", self.masses) - plmd.cmd("setCharges", self.charges) - plmd.cmd("setPositions", self.traj[step]) - plmd.cmd("setForces", self.forces) - plmd.cmd("setVirial", self.virial) - plmd.cmd("calc") - - np.testing.assert_almost_equal(cvPy, cvCPP,decimal=4) - - -if __name__ == "__main__": - # Output to four decimal places only - np.set_printoptions(precision=4) - unittest.main() diff --git a/plugins/pycv/pythontests/trajnewFrameNewAtom.xyz b/plugins/pycv/pythontests/trajnewFrameNewAtom.xyz new file mode 100644 index 0000000000..ead294112f --- /dev/null +++ b/plugins/pycv/pythontests/trajnewFrameNewAtom.xyz @@ -0,0 +1,24 @@ +4 +100 100 100 +X 0 0 0 +X 0 0 1 +X 0 0 0 +X 0 0 0 +4 +100 100 100 +X 0 0 0 +X 0 0 0 +X 0 0 2 +X 0 0 0 +4 +100 100 100 +X 0 0 0 +X 0 0 0 +X 0 0 0 +X 0 0 3 +4 +100 100 100 +X 0 0 0 +X 0 0 4 +X 0 0 0 +X 0 0 0 diff --git a/plugins/pycv/pythontests/utilities_for_test.py b/plugins/pycv/pythontests/utilities_for_test.py new file mode 100644 index 0000000000..1c62b7ddab --- /dev/null +++ b/plugins/pycv/pythontests/utilities_for_test.py @@ -0,0 +1,84 @@ +from plumed import Plumed +from contextlib import contextmanager +import os +import numpy as np + +__all__ = ["read_xyz", "setUpTraj", "preparePlumed", "cd", "create_plumed_var"] + + +@contextmanager +def cd(newdir): + prevdir = os.getcwd() + os.chdir(newdir) + try: + yield + finally: + os.chdir(prevdir) + + +def read_xyz(filename: str): + xyz = open(filename) + n_atoms = int(xyz.readline()) + _ = xyz.readline() + trajectory = [] + while True: + atom_type = np.zeros(n_atoms).astype(str) + coordinates = np.zeros([n_atoms, 3]) + for i in range(0, n_atoms): + line = xyz.readline() + atom, x, y, z = line.split() + atom_type[i] = atom + coordinates[i, :] = np.array([x, y, z], dtype=np.float64) + trajectory.append(coordinates) + nextline = xyz.readline() + if nextline == "": + break + c_atoms = int(nextline) + if c_atoms != n_atoms: + break + _ = xyz.readline() + xyz.close() + return trajectory + + +def setUpTraj(trajfile: str): + traj = read_xyz(trajfile) + num_frames = len(traj) + num_atoms = traj[0].shape[0] + + # Create arrays for stuff + box = np.diag(12.41642 * np.ones(3, dtype=np.float64)) + virial = np.zeros((3, 3), dtype=np.float64) + masses = np.ones(num_atoms, dtype=np.float64) + forces = np.random.rand(num_atoms, 3) + charges = np.zeros(num_atoms, dtype=np.float64) + + return traj, num_frames, num_atoms, box, virial, masses, forces, charges + + +def preparePlumed(num_atoms: int): + from pycv import getPythonCVInterface + + # Create PLUMED object and read input + plmd = Plumed() + + # not really needed, used to check https://github.com/plumed/plumed2/issues/916 + plumed_version = np.zeros(1, dtype=np.intc) + plmd.cmd("getApiVersion", plumed_version) + plmd.cmd("setMDEngine", "python") + plmd.cmd("setTimestep", 1.0) + plmd.cmd("setKbT", 1.0) + plmd.cmd("setNatoms", num_atoms) + plmd.cmd("setLogFile", "test.log") + plmd.cmd("init") + plmd.cmd("readInputLine", f"LOAD FILE={getPythonCVInterface()}") + return plmd + + +def create_plumed_var(plmd: Plumed, name: str, command: str): + plmd.cmd("readInputLine", name + ": " + command) + shape = np.zeros(1, dtype=np.int_) + plmd.cmd("getDataRank " + name, shape) + data = np.zeros((1)) + plmd.cmd("setMemoryForData " + name, data) + return data diff --git a/plugins/pycv/src/PythonCVInterface.cpp b/plugins/pycv/src/PythonCVInterface.cpp index 08fb1fe9ef..bf725b7c17 100644 --- a/plugins/pycv/src/PythonCVInterface.cpp +++ b/plugins/pycv/src/PythonCVInterface.cpp @@ -422,6 +422,7 @@ PythonCVInterface::PythonCVInterface(const ActionOptions&ao) ://the catch only a PLUMED_COLVAR_INIT(ao), ActionWithPython(ao) { try { + py::gil_scoped_acquire gil; //Loading the python module std::string import; parse("IMPORT",import); @@ -612,6 +613,7 @@ void PythonCVInterface::prepare() { } } if (hasPrepare) { + py::gil_scoped_acquire gil; py::dict prepareDict = pyPrepare(this); if (prepareDict.contains("setAtomRequest")) { //should I use "interpretAtomList"? @@ -657,6 +659,7 @@ void PythonCVInterface::calculate() { nl->update(getPositions()); } } + py::gil_scoped_acquire gil; // Call the function py::object r = pyCalculate(this); if(getNumberOfComponents()>1) { // MULTIPLE NAMED COMPONENTS From a22dd66a283770f00741a793d6853c07d6063a63 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:03:20 +0200 Subject: [PATCH 25/33] Now pycv appears to load correcly --- plugins/pycv/pythontests/justInit.py | 10 ++ plugins/pycv/pythontests/justInitDict.py | 8 ++ plugins/pycv/pythontests/justPrepare.py | 13 +++ plugins/pycv/pythontests/justUpdate.py | 12 +++ plugins/pycv/pythontests/test_cv_calls.py | 122 ++++++++++++++++++++++ plugins/pycv/src/PythonCVInterface.cpp | 1 + 6 files changed, 166 insertions(+) create mode 100644 plugins/pycv/pythontests/justInit.py create mode 100644 plugins/pycv/pythontests/justInitDict.py create mode 100644 plugins/pycv/pythontests/justPrepare.py create mode 100644 plugins/pycv/pythontests/justUpdate.py create mode 100644 plugins/pycv/pythontests/test_cv_calls.py diff --git a/plugins/pycv/pythontests/justInit.py b/plugins/pycv/pythontests/justInit.py new file mode 100644 index 0000000000..b0df723d36 --- /dev/null +++ b/plugins/pycv/pythontests/justInit.py @@ -0,0 +1,10 @@ +import numpy as np +import plumedCommunications + + +def myInit(_: plumedCommunications.PythonCVInterface): + return{"Value": plumedCommunications.defaults.COMPONENT_NODEV,} + +def plumedCalculate(action: plumedCommunications.PythonCVInterface): + at: np.ndarray = action.getPositions() + return at[0][0]+at[0][1] diff --git a/plugins/pycv/pythontests/justInitDict.py b/plugins/pycv/pythontests/justInitDict.py new file mode 100644 index 0000000000..009b089f4f --- /dev/null +++ b/plugins/pycv/pythontests/justInitDict.py @@ -0,0 +1,8 @@ +import numpy as np +import plumedCommunications + +plumedInit={"Value": plumedCommunications.defaults.COMPONENT,} + +def plumedCalculate(action: plumedCommunications.PythonCVInterface): + at: np.ndarray = action.getPositions() + return at[0][0]+at[0][1] diff --git a/plugins/pycv/pythontests/justPrepare.py b/plugins/pycv/pythontests/justPrepare.py new file mode 100644 index 0000000000..1e1bb7301f --- /dev/null +++ b/plugins/pycv/pythontests/justPrepare.py @@ -0,0 +1,13 @@ +import numpy as np +import plumedCommunications + +plumedInit={"Value": plumedCommunications.defaults.COMPONENT,} + +def plumedPrepare(_: plumedCommunications.PythonCVInterface): + toret = {"setAtomRequest": f"1"} + return toret + + +def plumedCalculate(action: plumedCommunications.PythonCVInterface): + at: np.ndarray = action.getPositions() + return at[0][0]+at[0][1] diff --git a/plugins/pycv/pythontests/justUpdate.py b/plugins/pycv/pythontests/justUpdate.py new file mode 100644 index 0000000000..182049abf5 --- /dev/null +++ b/plugins/pycv/pythontests/justUpdate.py @@ -0,0 +1,12 @@ +import numpy as np +import plumedCommunications + +plumedInit={"Value": plumedCommunications.defaults.COMPONENT,} + +def myUpdate(_: plumedCommunications.PythonCVInterface): + print("myUpdate") + return {} + +def plumedCalculate(action: plumedCommunications.PythonCVInterface): + at: np.ndarray = action.getPositions() + return at[0][0]+at[0][1] diff --git a/plugins/pycv/pythontests/test_cv_calls.py b/plugins/pycv/pythontests/test_cv_calls.py new file mode 100644 index 0000000000..d32264cc1e --- /dev/null +++ b/plugins/pycv/pythontests/test_cv_calls.py @@ -0,0 +1,122 @@ +import unittest +import numpy as np + +from utilities_for_test import * + +import os + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class TestPyCV(unittest.TestCase): + def test_INIT(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, _, num_atoms, box, virial, masses, forces, charges = setUpTraj( + "traj.xyz" + ) + plmd = preparePlumed(num_atoms) + + cvPy = create_plumed_var( + plmd, "cvPy", "PYCVINTERFACE ATOMS=4 IMPORT=justInit INIT=myInit" + ) + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + + step = 0 + + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + np.testing.assert_almost_equal(cvPy, 10.0, decimal=4) + + def test_INITDICT(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, _, num_atoms, box, virial, masses, forces, charges = setUpTraj( + "traj.xyz" + ) + plmd = preparePlumed(num_atoms) + + cvPy = create_plumed_var( + plmd, "cvPy", "PYCVINTERFACE ATOMS=4 IMPORT=justInitDict" + ) + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + + step = 0 + + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + np.testing.assert_almost_equal(cvPy, 10.0, decimal=4) + + def test_UPDATE(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, _, num_atoms, box, virial, masses, forces, charges = setUpTraj( + "traj.xyz" + ) + plmd = preparePlumed(num_atoms) + + cvPy = create_plumed_var( + plmd, "cvPy", "PYCVINTERFACE ATOMS=4 IMPORT=justUpdate UPDATE=myUpdate" + ) + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + + step = 0 + + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + np.testing.assert_almost_equal(cvPy, 10.0, decimal=4) + + def test_PREPARE(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, _, num_atoms, box, virial, masses, forces, charges = setUpTraj( + "traj.xyz" + ) + plmd = preparePlumed(num_atoms) + #atoms=4 but the module choses 1 + cvPy = create_plumed_var( + plmd, "cvPy", "PYCVINTERFACE ATOMS=4 IMPORT=justPrepare PREPARE=plumedPrepare") + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + # Open an output file + + step = 0 + + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + + np.testing.assert_almost_equal(cvPy, 5.0, decimal=4) + + + + +if __name__ == "__main__": + # Output to four decimal places only + np.set_printoptions(precision=4) + unittest.main() diff --git a/plugins/pycv/src/PythonCVInterface.cpp b/plugins/pycv/src/PythonCVInterface.cpp index bf725b7c17..4632abf8c6 100644 --- a/plugins/pycv/src/PythonCVInterface.cpp +++ b/plugins/pycv/src/PythonCVInterface.cpp @@ -643,6 +643,7 @@ void PythonCVInterface::prepare() { void PythonCVInterface::update() { try { if(hasUpdate) { + py::gil_scoped_acquire gil; py::dict updateDict=pyUpdate(this); //See what to do here } From b3e9f22df0955fe22c7e010ce4bce7549df416a9 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:18:58 +0200 Subject: [PATCH 26/33] added an extra test --- plugins/pycv/pythontests/pycvPersistentData | 1 + plugins/pycv/pythontests/test_cv.py | 33 +++++++++++++++++++++ plugins/pycv/pythontests/test_cv_calls.py | 9 +++--- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 120000 plugins/pycv/pythontests/pycvPersistentData diff --git a/plugins/pycv/pythontests/pycvPersistentData b/plugins/pycv/pythontests/pycvPersistentData new file mode 120000 index 0000000000..e74d2380e4 --- /dev/null +++ b/plugins/pycv/pythontests/pycvPersistentData @@ -0,0 +1 @@ +../regtest/pycvcomm/rt-persistentData/pycvPersistentData \ No newline at end of file diff --git a/plugins/pycv/pythontests/test_cv.py b/plugins/pycv/pythontests/test_cv.py index 44f78224a5..7d0ddc1631 100644 --- a/plugins/pycv/pythontests/test_cv.py +++ b/plugins/pycv/pythontests/test_cv.py @@ -160,6 +160,39 @@ def test_newFrameNewAtom(self): np.testing.assert_almost_equal(cvPy, step + 1.0, decimal=4) + def test_loadAmodule_and_persistData(self): + """This test loads a module that is a directory and stores some data within plumed""" + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, num_frames, num_atoms, box, virial, masses, forces, charges = ( + setUpTraj("trajnewFrameNewAtom.xyz") + ) + plmd = preparePlumed(num_atoms) + + cvPy = create_plumed_var( + plmd, + "cvPy", + "PYCVINTERFACE ATOMS=@mdatoms IMPORT=pycvPersistentData CALCULATE=pydist INIT=pyinit", + ) + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + + # Now analyze the trajectory + for step in range(0, num_frames): + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + # this cv sums the number of the step till now: + # to future me: "//" is integer (floor) division + np.testing.assert_almost_equal( + cvPy, ((step) * (step + 1)) // 2, decimal=4 + ) + if __name__ == "__main__": # Output to four decimal places only diff --git a/plugins/pycv/pythontests/test_cv_calls.py b/plugins/pycv/pythontests/test_cv_calls.py index d32264cc1e..49ec3efd10 100644 --- a/plugins/pycv/pythontests/test_cv_calls.py +++ b/plugins/pycv/pythontests/test_cv_calls.py @@ -94,9 +94,12 @@ def test_PREPARE(self): "traj.xyz" ) plmd = preparePlumed(num_atoms) - #atoms=4 but the module choses 1 + # atoms=4 but the module choses 1 cvPy = create_plumed_var( - plmd, "cvPy", "PYCVINTERFACE ATOMS=4 IMPORT=justPrepare PREPARE=plumedPrepare") + plmd, + "cvPy", + "PYCVINTERFACE ATOMS=4 IMPORT=justPrepare PREPARE=plumedPrepare", + ) plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") # Open an output file @@ -114,8 +117,6 @@ def test_PREPARE(self): np.testing.assert_almost_equal(cvPy, 5.0, decimal=4) - - if __name__ == "__main__": # Output to four decimal places only np.set_printoptions(precision=4) From a699ba578494411f80ec96ef4adbf659c2595248 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:00:38 +0200 Subject: [PATCH 27/33] set up aslo a few basic tests for pyfunc --- plugins/pycv/Makefile | 2 +- plugins/pycv/astyle.sh | 3 +- plugins/pycv/pythontests/pyfuncINITdict.py | 1 + plugins/pycv/pythontests/pyfuncINITfunc.py | 1 + plugins/pycv/pythontests/test_cv_calls.py | 2 +- plugins/pycv/pythontests/test_fun_calls.py | 92 +++++++++++++++++++ .../pycvfunc/rt-derivative/unitTest.py | 2 +- plugins/pycv/src/PythonFunction.cpp | 2 + 8 files changed, 101 insertions(+), 4 deletions(-) create mode 120000 plugins/pycv/pythontests/pyfuncINITdict.py create mode 120000 plugins/pycv/pythontests/pyfuncINITfunc.py create mode 100644 plugins/pycv/pythontests/test_fun_calls.py diff --git a/plugins/pycv/Makefile b/plugins/pycv/Makefile index 0d23a37074..3f07f69ade 100644 --- a/plugins/pycv/Makefile +++ b/plugins/pycv/Makefile @@ -19,6 +19,6 @@ check_standalone: pycv_here #just in case pytest is still not installed we install it before the tests check_python: pycv_here pip install pytest - pytest + pytest -v check: check_standalone check_python diff --git a/plugins/pycv/astyle.sh b/plugins/pycv/astyle.sh index 51b0a7be36..86a2d3da7f 100755 --- a/plugins/pycv/astyle.sh +++ b/plugins/pycv/astyle.sh @@ -3,13 +3,14 @@ #formatted with shfmt https://github.com/mvdan/sh/releases #checked with shellcheck +cd src || exit 1 for file in *.c *.cpp *.h *.inc.in; do test -f "$file" || continue echo -n "astyle $file" - ../../astyle/astyle --options=../../.astyle.options <"$file" >"${file}.tmp" && { + ../../../astyle/astyle --options=../../../.astyle.options <"$file" >"${file}.tmp" && { if cmp -s "$file" "${file}.tmp"; then echo else diff --git a/plugins/pycv/pythontests/pyfuncINITdict.py b/plugins/pycv/pythontests/pyfuncINITdict.py new file mode 120000 index 0000000000..eb9f725611 --- /dev/null +++ b/plugins/pycv/pythontests/pyfuncINITdict.py @@ -0,0 +1 @@ +../regtest/pycvfunc/rt-argumentsArray/unitTest.py \ No newline at end of file diff --git a/plugins/pycv/pythontests/pyfuncINITfunc.py b/plugins/pycv/pythontests/pyfuncINITfunc.py new file mode 120000 index 0000000000..d6961d59ba --- /dev/null +++ b/plugins/pycv/pythontests/pyfuncINITfunc.py @@ -0,0 +1 @@ +../regtest/pycvfunc/rt-derivative/unitTest.py \ No newline at end of file diff --git a/plugins/pycv/pythontests/test_cv_calls.py b/plugins/pycv/pythontests/test_cv_calls.py index 49ec3efd10..4c6086cbf4 100644 --- a/plugins/pycv/pythontests/test_cv_calls.py +++ b/plugins/pycv/pythontests/test_cv_calls.py @@ -8,7 +8,7 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) -class TestPyCV(unittest.TestCase): +class TestPyCVCalls(unittest.TestCase): def test_INIT(self): with cd(THIS_DIR): os.environ["PLUMED_MAXBACKUP"] = "0" diff --git a/plugins/pycv/pythontests/test_fun_calls.py b/plugins/pycv/pythontests/test_fun_calls.py new file mode 100644 index 0000000000..3ba155d062 --- /dev/null +++ b/plugins/pycv/pythontests/test_fun_calls.py @@ -0,0 +1,92 @@ +import unittest +import numpy as np + +from utilities_for_test import * + +import os + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + +# CALCULATE is tested "by default" + + +class TestFunctionCalls(unittest.TestCase): + def test_INIT(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, num_frames, num_atoms, box, virial, masses, forces, charges = ( + setUpTraj("traj.xyz") + ) + plmd = preparePlumed(num_atoms) + d1 = create_plumed_var(plmd, "d1", "DISTANCE ATOMS=1,2") + d2 = create_plumed_var(plmd, "d2", "DISTANCE ATOMS=1,3") + + fPy = create_plumed_var( + plmd, + "fPY", + "PYFUNCTION IMPORT=pyfuncINITfunc INIT=initForF CALCULATE=function ARG=d1,d2", + ) + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + + for step in range(num_frames): + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + + np.testing.assert_almost_equal(fPy, d1 * d2, decimal=4) + + def test_INITDICT(self): + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, num_frames, num_atoms, box, virial, masses, forces, charges = ( + setUpTraj("traj.xyz") + ) + plmd = preparePlumed(num_atoms) + + plmd.cmd("readInputLine", "dc: DISTANCE ATOMS=1,2 COMPONENTS") + shape = np.zeros(1, dtype=np.int_) + plmd.cmd("getDataRank " + "dc.x", shape) + plmd.cmd("getDataRank " + "dc.y", shape) + plmd.cmd("getDataRank " + "dc.z", shape) + dcx = np.zeros((1)) + dcy = np.zeros((1)) + dcz = np.zeros((1)) + plmd.cmd("setMemoryForData dc.x", dcx) + plmd.cmd("setMemoryForData dc.y", dcy) + plmd.cmd("setMemoryForData dc.z", dcz) + + d = create_plumed_var(plmd, "d", "DISTANCE ATOMS=1,2") + + fPy = create_plumed_var( + plmd, + "fPY", + "PYFUNCTION IMPORT=pyfuncINITdict INIT=initForF CALCULATE=function ARG=dc.x,dc.y,dc.z,d", + ) + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + + for step in range(num_frames): + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + + np.testing.assert_almost_equal( + fPy, np.abs(np.sqrt(dcx**2 + dcy**2 + dcz**2) - d[0]), decimal=4 + ) + + +if __name__ == "__main__": + # Output to four decimal places only + np.set_printoptions(precision=4) + unittest.main() diff --git a/plugins/pycv/regtest/pycvfunc/rt-derivative/unitTest.py b/plugins/pycv/regtest/pycvfunc/rt-derivative/unitTest.py index a0c386bfe1..a1ffa9d34c 100644 --- a/plugins/pycv/regtest/pycvfunc/rt-derivative/unitTest.py +++ b/plugins/pycv/regtest/pycvfunc/rt-derivative/unitTest.py @@ -5,7 +5,7 @@ print("Imported my pydist+.", file=log) -initForF={"Value": PLMD.defaults.COMPONENT} +def initForF(_: PLMD.PythonFunction): return {"Value": PLMD.defaults.COMPONENT} def function(action: PLMD.PythonFunction): arg = [action.argument(0), diff --git a/plugins/pycv/src/PythonFunction.cpp b/plugins/pycv/src/PythonFunction.cpp index 23d007063e..633c04f3a8 100644 --- a/plugins/pycv/src/PythonFunction.cpp +++ b/plugins/pycv/src/PythonFunction.cpp @@ -120,6 +120,7 @@ PythonFunction::PythonFunction(const ActionOptions&ao): Function(ao), ActionWithPython(ao) { try { + py::gil_scoped_acquire gil; //Loading the python module std::string import; parse("IMPORT",import); @@ -205,6 +206,7 @@ PythonFunction::PythonFunction(const ActionOptions&ao): // calculator void PythonFunction::calculate() { try { + py::gil_scoped_acquire gil; // Call the function py::object r = pyCalculate(this); if(getNumberOfComponents()>1) { // MULTIPLE NAMED COMPONENTS From 42a8dfc387365139277fe6bb3efcda7cce1d66ae Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:39:44 +0200 Subject: [PATCH 28/33] updated the docker recipes with the new installation method of pycv --- docker/fedora39-pycv | 2 -- docker/rocky8-pycv | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/docker/fedora39-pycv b/docker/fedora39-pycv index 80b6ed15d7..30cf608be3 100644 --- a/docker/fedora39-pycv +++ b/docker/fedora39-pycv @@ -5,7 +5,5 @@ RUN source /etc/bashrc \ && cd plumed2 \ && source ./sourceme.sh \ && cd plugins/pycv \ - && pip3 install -r requirements.txt \ && ln -s $(realpath ../../regtest/scripts) ./regtest/scripts \ - && python_bin=python3 ./prepareMakeForDevelop.sh \ && make check diff --git a/docker/rocky8-pycv b/docker/rocky8-pycv index 7dedd42ce3..ffaf7036cc 100644 --- a/docker/rocky8-pycv +++ b/docker/rocky8-pycv @@ -1,11 +1,9 @@ FROM plumed:rocky8 -RUN source ./.bashrc \ +RUN source /etc/bashrc \ && module load mpi \ && cd plumed2 \ && source ./sourceme.sh \ && cd plugins/pycv \ - && pip3 install --user -r requirements.txt \ && ln -s $(realpath ../../regtest/scripts) ./regtest/scripts \ - && python_bin=python3 ./prepareMakeForDevelop.sh \ && make check From e7012f72354581bf06b1797c98e2b4a55b197c43 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:00:24 +0200 Subject: [PATCH 29/33] using pip3 in the makefile --- plugins/pycv/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/pycv/Makefile b/plugins/pycv/Makefile index 3f07f69ade..a385ba0355 100644 --- a/plugins/pycv/Makefile +++ b/plugins/pycv/Makefile @@ -5,11 +5,11 @@ all: pycv_here pycv_here: src/*.cpp src/*.h src/pycv/*.py @echo installing pycv - pip install . + pip3 install . touch $@ clean: - pip uninstall pycv + pip3 uninstall pycv rm -fv pycv_here check_standalone: pycv_here @@ -18,7 +18,7 @@ check_standalone: pycv_here #just in case pytest is still not installed we install it before the tests check_python: pycv_here - pip install pytest + pip3 install pytest pytest -v check: check_standalone check_python From 4ab187df3bb7b4c26fead8ab5380a86d354f4594 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:58:19 +0200 Subject: [PATCH 30/33] sourcing the correct bashrc in rocky8 --- docker/rocky8-pycv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/rocky8-pycv b/docker/rocky8-pycv index ffaf7036cc..b663cf2e81 100644 --- a/docker/rocky8-pycv +++ b/docker/rocky8-pycv @@ -1,6 +1,6 @@ FROM plumed:rocky8 -RUN source /etc/bashrc \ +RUN . ./.bashrc \ && module load mpi \ && cd plumed2 \ && source ./sourceme.sh \ From cd5bd130c8b2b9604ec39120261b2a88f5d4533c Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:25:38 +0200 Subject: [PATCH 31/33] checking if changing env will make the CI pass --- docker/fedora39-pycv | 10 ++++++++++ docker/rocky8-pycv | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/docker/fedora39-pycv b/docker/fedora39-pycv index 30cf608be3..dd6f95d0e9 100644 --- a/docker/fedora39-pycv +++ b/docker/fedora39-pycv @@ -2,6 +2,16 @@ FROM plumed:fedora39 RUN source /etc/bashrc \ && module load mpi \ + && export OMPI_MCA_btl_base_warn_component_unused=0 \ + && export OMPI_MCA_btl_base_verbose=0 \ + && export OMPI_MCA_plm=isolated \ + && export OMPI_MCA_btl_vader_single_copy_mechanism=none \ + && export OMPI_MCA_rmaps_base_oversubscribe=yes \ + && export PATH=$HOME/opt/bin:$PATH \ + && export CPATH=$HOME/opt/include:$CPATH \ + && export INCLUDE=$HOME/opt/include:$INCLUDE \ + && export LIBRARY_PATH=$HOME/opt/lib:$LIBRARY_PATH \ + && export LD_LIBRARY_PATH=$HOME/opt/lib:$LD_LIBRARY_PATH \ && cd plumed2 \ && source ./sourceme.sh \ && cd plugins/pycv \ diff --git a/docker/rocky8-pycv b/docker/rocky8-pycv index b663cf2e81..7c541d3b17 100644 --- a/docker/rocky8-pycv +++ b/docker/rocky8-pycv @@ -2,6 +2,16 @@ FROM plumed:rocky8 RUN . ./.bashrc \ && module load mpi \ + && export OMPI_MCA_btl_base_warn_component_unused=0 \ + && export OMPI_MCA_btl_base_verbose=0 \ + && export OMPI_MCA_plm=isolated \ + && export OMPI_MCA_btl_vader_single_copy_mechanism=none \ + && export OMPI_MCA_rmaps_base_oversubscribe=yes \ + && export PATH=$HOME/opt/bin:$PATH \ + && export CPATH=$HOME/opt/include:$CPATH \ + && export INCLUDE=$HOME/opt/include:$INCLUDE \ + && export LIBRARY_PATH=$HOME/opt/lib:$LIBRARY_PATH \ + && export LD_LIBRARY_PATH=$HOME/opt/lib:$LD_LIBRARY_PATH \ && cd plumed2 \ && source ./sourceme.sh \ && cd plugins/pycv \ From 34aeec9c778ae9e3e975de5a88077dd05c1551b2 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Mon, 21 Oct 2024 16:35:54 +0200 Subject: [PATCH 32/33] now findplumed uses plumed--no-mpi --- plugins/pycv/FindPlumed.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/pycv/FindPlumed.cmake b/plugins/pycv/FindPlumed.cmake index e2a816cbc4..160518c7cf 100644 --- a/plugins/pycv/FindPlumed.cmake +++ b/plugins/pycv/FindPlumed.cmake @@ -24,7 +24,7 @@ if(NOT Plumed_FOUND) message(STATUS "plumed not found via pkgconfig, trying executable") execute_process( - COMMAND plumed info --include-dir + COMMAND plumed --no-mpi info --include-dir RESULT_VARIABLE PLUMED_EXECUTABLE OUTPUT_QUIET ERROR_QUIET) if(PLUMED_EXECUTABLE EQUAL 0) @@ -34,7 +34,7 @@ if(NOT Plumed_FOUND) message(STATUS "Configuring plumed from executable") execute_process( - COMMAND plumed info --include-dir + COMMAND plumed --no-mpi info --include-dir OUTPUT_VARIABLE Plumed_INCLUDEDIR OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -42,7 +42,7 @@ if(NOT Plumed_FOUND) ${Plumed_INCLUDEDIR} CACHE INTERNAL "plumed include dir") execute_process( - COMMAND plumed info --configuration + COMMAND plumed --no-mpi info --configuration OUTPUT_VARIABLE Plumed_CONFIG OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -70,7 +70,7 @@ if(NOT Plumed_FOUND) ${Plumed_CPP_FLAGS} CACHE INTERNAL "plumed Definitions flags") - execute_process(COMMAND plumed config -q has mpi + execute_process(COMMAND plumed --no-mpi config -q has mpi RESULT_VARIABLE Plumed_WITH_MPI) if(Plumed_WITH_MPI EQUAL 0) set(Plumed_HAS_MPI From ea2e77fc12beb3f4f094efcbfcd59b2b0c6af0ef Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Tue, 22 Oct 2024 09:49:16 +0200 Subject: [PATCH 33/33] readding a donfiguration file --- docker/fedora39-pycv | 1 + docker/rocky8-pycv | 1 + plugins/pycv/Makefile | 16 ++++++++++------ plugins/pycv/configurePyCV.sh | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100755 plugins/pycv/configurePyCV.sh diff --git a/docker/fedora39-pycv b/docker/fedora39-pycv index dd6f95d0e9..e2a0fb36ba 100644 --- a/docker/fedora39-pycv +++ b/docker/fedora39-pycv @@ -15,5 +15,6 @@ RUN source /etc/bashrc \ && cd plumed2 \ && source ./sourceme.sh \ && cd plugins/pycv \ + && ./configurePyCV.sh \ && ln -s $(realpath ../../regtest/scripts) ./regtest/scripts \ && make check diff --git a/docker/rocky8-pycv b/docker/rocky8-pycv index 7c541d3b17..35b12ad5ea 100644 --- a/docker/rocky8-pycv +++ b/docker/rocky8-pycv @@ -15,5 +15,6 @@ RUN . ./.bashrc \ && cd plumed2 \ && source ./sourceme.sh \ && cd plugins/pycv \ + && ./configurePyCV.sh \ && ln -s $(realpath ../../regtest/scripts) ./regtest/scripts \ && make check diff --git a/plugins/pycv/Makefile b/plugins/pycv/Makefile index a385ba0355..d045ccf3e6 100644 --- a/plugins/pycv/Makefile +++ b/plugins/pycv/Makefile @@ -1,3 +1,7 @@ + +PYTHON=python +#optional, just in case you want to override python with ./configurePyCV.sh +-include Makefile.conf #this makefiles assume that pip and pytest are installed .PHONY: clean check check_standalone check_python all @@ -5,12 +9,12 @@ all: pycv_here pycv_here: src/*.cpp src/*.h src/pycv/*.py @echo installing pycv - pip3 install . - touch $@ + $(PYTHON) -m pip install . + @touch $@ clean: - pip3 uninstall pycv - rm -fv pycv_here + @$(PYTHON) -m pip uninstall pycv -y + @rm -fv pycv_here check_standalone: pycv_here $(MAKE) -C regtest testclean @@ -18,7 +22,7 @@ check_standalone: pycv_here #just in case pytest is still not installed we install it before the tests check_python: pycv_here - pip3 install pytest - pytest -v + @$(PYTHON) -m pip install pytest + @$(PYTHON) -m pytest -v check: check_standalone check_python diff --git a/plugins/pycv/configurePyCV.sh b/plugins/pycv/configurePyCV.sh new file mode 100755 index 0000000000..f97dcaae8b --- /dev/null +++ b/plugins/pycv/configurePyCV.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +#formatted with shfmtv3.36.0 (https://github.com/mvdan/sh/releases) + +#A simple script to configure PyCV if python does not work +PYTHON="" +if which plumed >/dev/null; then + echo "plumed found" + PYTHON=$(plumed --no-mpi info --configuration | grep 'python_bin=') + PYTHON=${PYTHON#python_bin=} +fi + +if [ -z "$PYTHON" ]; then + echo "python not found using plumed" + echo "serching for available python with plumed module installed" + + for python_bin in python python3 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7; do + if $python_bin -c "import plumed" 2>/dev/null; then + if [ $python_bin != python ]; then + PYTHON=$python_bin + fi + return 1 + fi + done + +fi + +if [ -z "$PYTHON" ]; then + echo "python not found" + exit 1 +fi + +cat <Makefile.conf +PYTHON=$(which "$PYTHON") +EOF