From 2a9af7a30cfeab3bc61fe5f4997b5989e229e2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 1 Mar 2024 17:35:12 +0100 Subject: [PATCH 1/7] Set up pyMBE virtual environment --- .github/workflows/testsuite.yml | 1 - Makefile | 20 +++++++-------- README.md | 43 ++++++++++++++++++++++----------- maintainer/configure_venv.py | 22 +++++++++++++++++ 4 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 maintainer/configure_venv.py diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index 5cd8138..316ef71 100644 --- a/.github/workflows/testsuite.yml +++ b/.github/workflows/testsuite.yml @@ -26,7 +26,6 @@ jobs: module load ESPResSo/4.2.1-foss-2023a export OLD_PYTHONPATH="${PYTHONPATH}" export PYTHONPATH="$(realpath .)${PYTHONPATH:+:$PYTHONPATH}" - sed -i "s/\${ESPResSo_build_path}\///" Makefile make testsuite export PYTHONPATH="${OLD_PYTHONPATH}" shell: bash diff --git a/Makefile b/Makefile index 308b15c..4975dc3 100644 --- a/Makefile +++ b/Makefile @@ -6,32 +6,30 @@ .PHONY: testsuite .PHONY: docs -ESPResSo_build_path=~/software/espresso_v4.2/build/ - docs: pdoc ./pyMBE.py -o ./docs --docformat google testsuite: - ${ESPResSo_build_path}/pypresso testsuite/LYS_ASP_peptide.py + python3 testsuite/LYS_ASP_peptide.py sample: - ${ESPResSo_build_path}/pypresso sample_scripts/peptide_simulation_example.py + python3 sample_scripts/peptide_simulation_example.py visual: python3 handy_scripts/vmd-traj.py vmd -e visualization.tcl tutorial: - ${ESPResSo_build_path}/ipypresso notebook sugar_tutorial.ipynb + jupyter lab sugar_tutorial.ipynb tests_peptide: - ${ESPResSo_build_path}/pypresso tests/LYS_ASP_peptide.py - ${ESPResSo_build_path}/pypresso tests/GLU_HIS_peptide.py - ${ESPResSo_build_path}/pypresso tests/histatin5_peptide.py - + python3 tests/LYS_ASP_peptide.py + python3 tests/GLU_HIS_peptide.py + python3 tests/histatin5_peptide.py + tests_globular_protein: - python3 tests/run_test_protein.py --pdb_code 1beb --run_command "${ESPResSo_build_path}/pypresso sample_scripts/globular_protein.py --pdb 1beb --path_to_cg reference_parameters/coarse_grained_structures/1beb.vtf" - python3 tests/run_test_protein.py --pdb_code 1f6s --run_command "${ESPResSo_build_path}/pypresso sample_scripts/globular_protein.py --pdb 1f6s --metal_ion_name Ca --metal_ion_charge 2 --path_to_cg reference_parameters/coarse_grained_structures/1f6s.vtf" + python3 tests/run_test_protein.py --pdb_code 1beb --run_command "python3 sample_scripts/globular_protein.py --pdb 1beb --path_to_cg reference_parameters/coarse_grained_structures/1beb.vtf" + python3 tests/run_test_protein.py --pdb_code 1f6s --run_command "python3 sample_scripts/globular_protein.py --pdb 1f6s --metal_ion_name Ca --metal_ion_charge 2 --path_to_cg reference_parameters/coarse_grained_structures/1f6s.vtf" tests: make tests_peptide diff --git a/README.md b/README.md index 50f86f2..05d24a1 100644 --- a/README.md +++ b/README.md @@ -35,30 +35,45 @@ A deprecated version of pyMBE compatible with ESPResSo v4.1.4 (under the histori ## Usage -### Use pyMBE in your simulation scripts +### Set up the pyMBE environment -To use pyMBE in your simulations, first clone this repository into your source folder +To use pyMBE in your simulations, first clone this repository locally: ```sh -git clone git@gitlab.com:blancoapa/pyMBE.git +git clone git@github.com:pm-blanco/pyMBE.git ``` -then you can load pyMBE into your script with the command +Please, be aware that pyMBE is intended to be a supporting tool to setup simulations with ESPResSo. +Thus, for most of its functionalities ESPResSo must also be available. -```py -from pyMBE import pyMBE +Create a virtual environment to install Python dependencies and configure +the path to the ESPResSo build folder: + +```sh +python3 -m venv pymbe +source pymbe/bin/activate +python3 maintainer/configure_venv.py /home/user/Documents/espresso/build # adapt this +python3 -m pip install -r requirements.txt +deactivate ``` -Please, be aware that pyMBE is intended to be a supporting tool to setup simulations with ESPResSo. Thus, for most of its functionalities ESPResSo must be also loaded to your script +Now you can use pyMBE and ESPResSo by activating the virtual environment: -```py -import espressomd +```sh +$ source pymbe/bin/activate +(pymbe) $ python3 -c "import espressomd.version; print(espressomd.version.friendly())" +4.2 +(pymbe) $ python3 -c "import pyMBE; print(pyMBE.__file__)" +/home/user/Documents/pyMBE/pyMBE.py +$ deactivate ``` -and your simulations should be runned using ESPResSo +### Use pyMBE in your simulation scripts ```sh -${ESPResSo_build_path}/pypresso your_simulation_script.py +source pymbe/bin/activate +python3 sample_scripts/peptide.py +deactivate ``` ### Run the tutorial of pyMBE @@ -75,14 +90,14 @@ or alternatively you can run the command make tutorial ``` -provided that you have modified the `$ESPResSo_build_path` variable in `Makefile` to match the path where you have built ESPResSo. - ### Run the testsuite To make sure your code is valid, please run the testsuite before submitting your contribution: ```sh -PYTHONPATH=$(realpath .) make testsuite +source pymbe/bin/activate +make testsuite +deactivate ``` When contributing new features, consider adding a unit test in the `testsuite/` diff --git a/maintainer/configure_venv.py b/maintainer/configure_venv.py new file mode 100644 index 0000000..1d3554b --- /dev/null +++ b/maintainer/configure_venv.py @@ -0,0 +1,22 @@ +import os +import argparse +import sysconfig + + +def make_pth(name, path): + if not os.path.isdir(path): + raise ValueError(f"Folder '{path}' doesn't exist") + site_packages = sysconfig.get_path("platlib") + with open(os.path.join(site_packages, f"{name}.pth"), "w") as f: + f.write(os.path.realpath(path)) + + +parser = argparse.ArgumentParser(description="Configure pyBME and ESPResSo module paths") +parser.add_argument("espresso_build_path", type=str, help="Path to the ESPResSo build folder") +args = parser.parse_args() + +if not os.environ.get("VIRTUAL_ENV"): + raise RuntimeError("This script should be run in a virtual environment") + +make_pth("pymbe", os.path.dirname(os.path.dirname(__file__))) +make_pth("espresso", os.path.join(args.espresso_build_path, "src", "python")) From c594a4242158002094bcad4c82736122a4898329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 1 Mar 2024 17:37:36 +0100 Subject: [PATCH 2/7] Set up pyMBE Jupyter kernel --- Makefile | 3 --- README.md | 32 ++++++++++++++++++++++++------- tutorials/pyMBE_tutorial.ipynb | 12 +----------- tutorials/solution_tutorial.ipynb | 10 ---------- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 4975dc3..a33ea06 100644 --- a/Makefile +++ b/Makefile @@ -19,9 +19,6 @@ visual: python3 handy_scripts/vmd-traj.py vmd -e visualization.tcl -tutorial: - jupyter lab sugar_tutorial.ipynb - tests_peptide: python3 tests/LYS_ASP_peptide.py python3 tests/GLU_HIS_peptide.py diff --git a/README.md b/README.md index 05d24a1..5309d8a 100644 --- a/README.md +++ b/README.md @@ -68,28 +68,46 @@ $ source pymbe/bin/activate $ deactivate ``` -### Use pyMBE in your simulation scripts +To use pyMBE in JupyterLab, register the virtual environment in a new kernel: ```sh source pymbe/bin/activate -python3 sample_scripts/peptide.py +python3 -m pip install ipykernel "jupyterlab>=4.0.8" "PyOpenGL>=3.1.5" +python3 -m ipykernel install --user --name=pyMBE deactivate ``` -### Run the tutorial of pyMBE +Please be aware the pyMBE kernel will be registered outside the environment, +typically in your home folder. You can later inspect the list of registered +kernels and delete unwanted ones with the following commands: + +```sh +jupyter kernelspec list +jupyter kernelspec uninstall pymbe +``` + +The JupyterLab main menu will now show a new Python kernel called "pyMBE" +that uses the virtual environment. -You can run the interactive tutorial of pyMBE with the command +### Use pyMBE in your simulation scripts ```sh -${ESPResSo_build_path}/ipypresso notebook pyMBE_tutorial.ipynb +source pymbe/bin/activate +python3 sample_scripts/peptide.py +deactivate ``` -or alternatively you can run the command +### Run the tutorial of pyMBE + +You can run the interactive tutorial of pyMBE with the command: ```sh -make tutorial +jupyter lab tutorials/pyMBE_tutorial.ipynb ``` +Be sure to use the pyMBE kernel instead of the default Python3 kernel. +The currently active kernel is usually displayed in the top right corner of the notebook. + ### Run the testsuite To make sure your code is valid, please run the testsuite before submitting your contribution: diff --git a/tutorials/pyMBE_tutorial.ipynb b/tutorials/pyMBE_tutorial.ipynb index b4e3523..7e7c33f 100644 --- a/tutorials/pyMBE_tutorial.ipynb +++ b/tutorials/pyMBE_tutorial.ipynb @@ -46,16 +46,6 @@ "metadata": {}, "outputs": [], "source": [ - "import sys\n", - "import os\n", - "import inspect\n", - "\n", - "# Find path to pyMBE\n", - "current_dir= os.path.dirname(os.path.abspath(\"\"))\n", - "path_end_index=current_dir.find(\"pyMBE\")\n", - "pyMBE_path=current_dir[0:path_end_index]+\"pyMBE\"\n", - "sys.path.insert(0, pyMBE_path)\n", - "\n", "# Import pyMBE and ESPResSo\n", "import pyMBE\n", "import espressomd\n", @@ -1151,7 +1141,7 @@ "metadata": {}, "outputs": [], "source": [ - "pmb.load_interaction_parameters (filename = pyMBE_path+'/reference_parameters/interaction_parameters/Lunkad2021.txt')\n", + "pmb.load_interaction_parameters (filename = pmb.get_resource('reference_parameters/interaction_parameters/Lunkad2021.txt'))\n", "pmb.add_bonds_to_espresso (espresso_system = espresso_system)" ] }, diff --git a/tutorials/solution_tutorial.ipynb b/tutorials/solution_tutorial.ipynb index db3ff76..2b60955 100644 --- a/tutorials/solution_tutorial.ipynb +++ b/tutorials/solution_tutorial.ipynb @@ -32,16 +32,6 @@ "metadata": {}, "outputs": [], "source": [ - "import sys\n", - "import os\n", - "import inspect\n", - "\n", - "# Find path to pyMBE\n", - "current_dir= os.path.dirname(os.path.abspath(\"\"))\n", - "path_end_index=current_dir.find(\"pyMBE\")\n", - "pyMBE_path=current_dir[0:path_end_index]+\"pyMBE\"\n", - "sys.path.insert(0, pyMBE_path)\n", - "\n", "# Import pyMBE and ESPResSo\n", "import pyMBE\n", "import espressomd\n", From 9dae0b525910dd00b0eb3938a6ef653735b9b482 Mon Sep 17 00:00:00 2001 From: blancoapa Date: Sat, 2 Mar 2024 11:44:44 +0100 Subject: [PATCH 3/7] Add clarifying note to README, fix paths and imports in all scripts --- README.md | 4 ++++ sample_scripts/branched_polyampholyte.py | 7 ------- sample_scripts/globular_protein.py | 17 +++++------------ sample_scripts/peptide.py | 15 +++++---------- sample_scripts/peptide_mixture_grxmc_ideal.py | 12 ++++-------- .../peptide_mixture_grxmc_unified_ideal.py | 12 ++++-------- tests/GLU_HIS_peptide.py | 16 ++++++---------- tests/LYS_ASP_peptide.py | 18 +++++++----------- tests/histatin5_peptide.py | 14 +++++--------- tests/run_test_protein.py | 14 +++++--------- tests/simulation_script_grxmc.py | 6 ++---- 11 files changed, 47 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index 5309d8a..f318879 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ python3 -m pip install -r requirements.txt deactivate ``` +We highlight that the path `/home/user/Documents/espresso/build` is just an example of a possible absolute path to the ESPResSo build folder. The user should change this path to match the local path were ESPResSo was installed. + Now you can use pyMBE and ESPResSo by activating the virtual environment: ```sh @@ -102,7 +104,9 @@ deactivate You can run the interactive tutorial of pyMBE with the command: ```sh +source pymbe/bin/activate jupyter lab tutorials/pyMBE_tutorial.ipynb +deactivate ``` Be sure to use the pyMBE kernel instead of the default Python3 kernel. diff --git a/sample_scripts/branched_polyampholyte.py b/sample_scripts/branched_polyampholyte.py index 5fdef5a..f75d6a3 100644 --- a/sample_scripts/branched_polyampholyte.py +++ b/sample_scripts/branched_polyampholyte.py @@ -11,13 +11,6 @@ from espressomd import interactions -# Find path to pyMBE -current_dir= os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) -path_end_index=current_dir.find("pyMBE") -pyMBE_path=current_dir[0:path_end_index]+"pyMBE" -sys.path.insert(0, pyMBE_path) - - # Create an instance of pyMBE library import pyMBE pmb = pyMBE.pymbe_library() diff --git a/sample_scripts/globular_protein.py b/sample_scripts/globular_protein.py index 5a65444..57168b8 100644 --- a/sample_scripts/globular_protein.py +++ b/sample_scripts/globular_protein.py @@ -9,12 +9,6 @@ from espressomd.io.writer import vtf from espressomd import electrostatics -# Find path to pyMBE -current_dir= os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) -path_end_index=current_dir.find("pyMBE") -pyMBE_path=current_dir[0:path_end_index]+"pyMBE" -sys.path.insert(0, pyMBE_path) - # Create an instance of pyMBE library import pyMBE pmb = pyMBE.pymbe_library() @@ -74,11 +68,9 @@ espresso_system = espressomd.System(box_l=[Box_L.to('reduced_length').magnitude] * 3) espresso_system.virtual_sites = espressomd.virtual_sites.VirtualSitesRelative() -#Directory of the protein model -protein_filename = pyMBE_path+"/"+args.path_to_cg - #Reads the VTF file of the protein model -topology_dict = pmb.read_protein_vtf_in_df (filename=protein_filename) +path_to_cg=pmb.get_resource(args.path_to_cg) +topology_dict = pmb.read_protein_vtf_in_df (filename=path_to_cg) #Defines the protein in the pmb.df pmb.define_protein (name=protein_name, topology_dict=topology_dict, model = '2beadAA') @@ -116,8 +108,9 @@ pmb.define_particle(name = cation_name, q = 1, diameter=0.2*pmb.units.nm, epsilon=epsilon) pmb.define_particle(name = anion_name, q =-1, diameter=0.2*pmb.units.nm, epsilon=epsilon) -# Here we upload the pka set from the reference_parameters folder -pmb.load_pka_set (filename=pyMBE_path+'/reference_parameters/pka_sets/Nozaki1967.txt') +# Here we upload the pka set from the reference_parameters folder +path_to_pka=pmb.get_resource('reference_parameters/pka_sets/Nozaki1967.txt') +pmb.load_pka_set (filename=path_to_pka) #We create the protein in espresso pmb.create_protein(name=protein_name, diff --git a/sample_scripts/peptide.py b/sample_scripts/peptide.py index fffa633..8bf7434 100644 --- a/sample_scripts/peptide.py +++ b/sample_scripts/peptide.py @@ -11,14 +11,6 @@ from espressomd import interactions from espressomd import electrostatics - -# Find path to pyMBE -current_dir= os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) -path_end_index=current_dir.find("pyMBE") -pyMBE_path=current_dir[0:path_end_index]+"pyMBE" -sys.path.insert(0, pyMBE_path) - - # Create an instance of pyMBE library import pyMBE pmb = pyMBE.pymbe_library() @@ -53,8 +45,11 @@ N_peptide_chains = 4 # Load peptide parametrization from Lunkad, R. et al. Molecular Systems Design & Engineering (2021), 6(2), 122-131. -pmb.load_interaction_parameters (filename=pyMBE_path+'/reference_parameters/interaction_parameters/Lunkad2021.txt') -pmb.load_pka_set (filename=pyMBE_path+'/reference_parameters/pka_sets/Hass2015.txt') + +path_to_interactions=pmb.get_resource("reference_parameters/interaction_parameters/Lunkad2021.txt") +path_to_pka=pmb.get_resource("reference_parameters/pka_sets/Hass2015.txt") +pmb.load_interaction_parameters (filename=path_to_interactions) +pmb.load_pka_set (path_to_pka) # Use a generic parametrization for the aminoacids not parametrized diff --git a/sample_scripts/peptide_mixture_grxmc_ideal.py b/sample_scripts/peptide_mixture_grxmc_ideal.py index 2a1538a..4a6ce4c 100644 --- a/sample_scripts/peptide_mixture_grxmc_ideal.py +++ b/sample_scripts/peptide_mixture_grxmc_ideal.py @@ -11,12 +11,6 @@ from espressomd import interactions from espressomd import electrostatics -# Find path to pyMBE -current_dir= os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) -path_end_index=current_dir.find("pyMBE") -pyMBE_path=current_dir[0:path_end_index]+"pyMBE" -sys.path.insert(0, pyMBE_path) - # Create an instance of pyMBE library import pyMBE pmb = pyMBE.pymbe_library() @@ -52,8 +46,10 @@ N_peptide2_chains = 10 # Load peptide parametrization from Lunkad, R. et al. Molecular Systems Design & Engineering (2021), 6(2), 122-131. -pmb.load_interaction_parameters (filename=pyMBE_path+'/reference_parameters/interaction_parameters/Lunkad2021.txt') -pmb.load_pka_set (filename=pyMBE_path+'/reference_parameters/pka_sets/Hass2015.txt') +path_to_interactions=pmb.get_resource("reference_parameters/interaction_parameters/Lunkad2021.txt") +path_to_pka=pmb.get_resource("reference_parameters/pka_sets/Hass2015.txt") +pmb.load_interaction_parameters (filename=path_to_interactions) +pmb.load_pka_set (path_to_pka) # Use a generic parametrization for the aminoacids not parametrized not_parametrized_neutral_aminoacids = ['A','N','Q','G','I','L','M','F','P','O','S','U','T','W','V','J'] diff --git a/sample_scripts/peptide_mixture_grxmc_unified_ideal.py b/sample_scripts/peptide_mixture_grxmc_unified_ideal.py index 8d30a2e..570ce0c 100644 --- a/sample_scripts/peptide_mixture_grxmc_unified_ideal.py +++ b/sample_scripts/peptide_mixture_grxmc_unified_ideal.py @@ -11,12 +11,6 @@ from espressomd import interactions from espressomd import electrostatics -# Find path to pyMBE -current_dir= os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) -path_end_index=current_dir.find("pyMBE") -pyMBE_path=current_dir[0:path_end_index]+"pyMBE" -sys.path.insert(0, pyMBE_path) - # Create an instance of pyMBE library import pyMBE pmb = pyMBE.pymbe_library() @@ -53,8 +47,10 @@ # Load peptide parametrization from Lunkad, R. et al. Molecular Systems Design & Engineering (2021), 6(2), 122-131. -pmb.load_interaction_parameters (filename=pyMBE_path+'/reference_parameters/interaction_parameters/Lunkad2021.txt') -pmb.load_pka_set (filename=pyMBE_path+'/reference_parameters/pka_sets/Hass2015.txt') +path_to_interactions=pmb.get_resource("reference_parameters/interaction_parameters/Lunkad2021.txt") +path_to_pka=pmb.get_resource("reference_parameters/pka_sets/Hass2015.txt") +pmb.load_interaction_parameters (filename=path_to_interactions) +pmb.load_pka_set (path_to_pka) # Use a generic parametrization for the aminoacids not parametrized diff --git a/tests/GLU_HIS_peptide.py b/tests/GLU_HIS_peptide.py index c0fa960..5641ff3 100644 --- a/tests/GLU_HIS_peptide.py +++ b/tests/GLU_HIS_peptide.py @@ -25,12 +25,6 @@ from espressomd.io.writer import vtf from espressomd import electrostatics -# Find path to pyMBE -current_dir= os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) -path_end_index=current_dir.find("pyMBE") -pyMBE_path=current_dir[0:path_end_index]+"pyMBE" -sys.path.insert(0, pyMBE_path) - # Create an instance of pyMBE library import pyMBE pmb = pyMBE.pymbe_library() @@ -75,8 +69,10 @@ pmb.define_particle( name=anion_name, q=-1, diameter=0.35*pmb.units.nm, epsilon=1*pmb.units('reduced_energy')) # Load peptide parametrization from Lunkad, R. et al. Molecular Systems Design & Engineering (2021), 6(2), 122-131. -pmb.load_interaction_parameters (filename=pyMBE_path+'/reference_parameters/interaction_parameters/Lunkad2021.txt') -pmb.load_pka_set (filename=pyMBE_path+'/reference_parameters/pka_sets/CRC1991.txt') +path_to_interactions=pmb.get_resource("reference_parameters/interaction_parameters/Lunkad2021.txt") +path_to_pka=pmb.get_resource("reference_parameters/pka_sets/CRC1991.txt") +pmb.load_interaction_parameters (filename=path_to_interactions) +pmb.load_pka_set (path_to_pka) # Create a molecule entry on the pyMBE dataframe pmb.define_peptide (name=sequence, sequence=sequence, model=model) @@ -208,9 +204,9 @@ pH_list=pH_range) # Load the reference data +path_to_ref=pmb.get_resource("reference_data") +reference_data = pd.read_csv(f"{path_to_ref}/Glu-HisMSDE.csv") -reference_file_Path = pyMBE_path+"/reference_data/Glu-HisMSDE.csv" -reference_data = pd.read_csv(reference_file_Path) Z_ref = N_aminoacids*-1*reference_data['aaa']+N_aminoacids*reference_data['aab'] Rg_ref = reference_data['arg']*0.37 diff --git a/tests/LYS_ASP_peptide.py b/tests/LYS_ASP_peptide.py index a65352b..791febd 100644 --- a/tests/LYS_ASP_peptide.py +++ b/tests/LYS_ASP_peptide.py @@ -25,12 +25,6 @@ from espressomd.io.writer import vtf from espressomd import electrostatics -# Find path to pyMBE -current_dir= os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) -path_end_index=current_dir.find("pyMBE") -pyMBE_path=current_dir[0:path_end_index]+"pyMBE" -sys.path.insert(0, pyMBE_path) - # Create an instance of pyMBE library import pyMBE pmb = pyMBE.pymbe_library() @@ -76,9 +70,10 @@ pmb.define_particle( name=anion_name, q=-1, diameter=0.35*pmb.units.nm, epsilon=1*pmb.units('reduced_energy')) # Load peptide parametrization from Lunkad, R. et al. Molecular Systems Design & Engineering (2021), 6(2), 122-131. - -pmb.load_interaction_parameters (filename=pyMBE_path+'/reference_parameters/interaction_parameters/Lunkad2021.txt') -pmb.load_pka_set (filename=pyMBE_path+'/reference_parameters/pka_sets/CRC1991.txt') +path_to_interactions=pmb.get_resource("reference_parameters/interaction_parameters/Lunkad2021.txt") +path_to_pka=pmb.get_resource("reference_parameters/pka_sets/CRC1991.txt") +pmb.load_interaction_parameters (filename=path_to_interactions) +pmb.load_pka_set (path_to_pka) # Define the peptide on the pyMBE dataframe pmb.define_peptide( name=sequence, sequence=sequence, model=model) @@ -213,8 +208,9 @@ pH_list=pH_range) # Load the reference data -reference_file_Path = pyMBE_path+"/reference_data/Lys-AspMSDE.csv" -reference_data = pd.read_csv(reference_file_Path) +path_to_ref=pmb.get_resource("reference_data") +reference_data = pd.read_csv(f"{path_to_ref}/Lys-AspMSDE.csv") + Z_ref = N_aminoacids*-1*reference_data['aaa']+N_aminoacids*reference_data['aab'] Rg_ref = reference_data['arg']*0.37 diff --git a/tests/histatin5_peptide.py b/tests/histatin5_peptide.py index 619bd7c..338285e 100644 --- a/tests/histatin5_peptide.py +++ b/tests/histatin5_peptide.py @@ -25,12 +25,6 @@ from espressomd.io.writer import vtf from espressomd import electrostatics -# Find path to pyMBE -current_dir= os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) -path_end_index=current_dir.find("pyMBE") -pyMBE_path=current_dir[0:path_end_index]+"pyMBE" -sys.path.insert(0, pyMBE_path) - # Load some functions from the handy_scripts library for convinience from handy_scripts.handy_functions import setup_electrostatic_interactions from handy_scripts.handy_functions import minimize_espresso_system_energy @@ -81,7 +75,9 @@ N_aminoacids = len (pmb.protein_sequence_parser(sequence=sequence)) # Load pKa set -pmb.load_pka_set (filename=pyMBE_path+'/reference_parameters/pka_sets/Nozaki1967.txt') +path_to_pka=pmb.get_resource("reference_parameters/pka_sets/Nozaki1967.txt") +pmb.load_pka_set (path_to_pka) + already_defined_AA=[] for aminoacid_key in pmb.protein_sequence_parser(sequence=sequence): @@ -234,8 +230,8 @@ pH_list=pH_range) # Load the reference data -reference_file_Path = pyMBE_path+"/reference_data/histatin5_SoftMatter.txt" -reference_data = np.loadtxt(reference_file_Path, delimiter=",") +path_to_ref=pmb.get_resource("reference_data") +reference_data = np.loadtxt(f"{path_to_ref}/histatin5_SoftMatter.txt", delimiter=",") Z_ref=reference_data[:,1] Z_err_ref=reference_data[:,2] diff --git a/tests/run_test_protein.py b/tests/run_test_protein.py index 0293753..49cf27f 100644 --- a/tests/run_test_protein.py +++ b/tests/run_test_protein.py @@ -12,12 +12,6 @@ import sys import inspect -# Find path to pyMBE -current_dir= os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) -path_end_index=current_dir.find("pyMBE") -pyMBE_path=current_dir[0:path_end_index]+"pyMBE" -sys.path.insert(0, pyMBE_path) - # Create an instance of pyMBE library import pyMBE pmb = pyMBE.pymbe_library() @@ -98,8 +92,10 @@ numerical_comparison['error %'] = abs(( (numerical_comparison['espresso']) - (numerical_comparison['ref_torres'])) / (numerical_comparison['ref_torres'])) *100 -#Save `numerical_comparison` to a csv file -numerical_comparison.to_csv(f'{pyMBE_path}/tests/observables_results/{pdb}-numerical_comparison.csv',index = True) +#Save `numerical_comparison` to a csv file + +path_to_tests=pmb.get_resource("tests") +numerical_comparison.to_csv(f'{path_to_tests}/{pdb}-numerical_comparison.csv',index = True) #Plot results @@ -177,7 +173,7 @@ ax1.legend(frameon =False) plt.legend(prop={'size': 35}) -pdf_name = f'{pyMBE_path}/tests/observables_results/{pdb}-analyzed_observables.pdf' +pdf_name = f'{path_to_tests}/observables_results/{pdb}-analyzed_observables.pdf' plt.savefig(pdf_name) plt.show() diff --git a/tests/simulation_script_grxmc.py b/tests/simulation_script_grxmc.py index 55ff926..d8c6959 100644 --- a/tests/simulation_script_grxmc.py +++ b/tests/simulation_script_grxmc.py @@ -16,9 +16,6 @@ import pickle # Load pyMBE -currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) -parentdir = os.path.dirname(currentdir) -sys.path.insert(0, parentdir) import pyMBE pmb = pyMBE.pymbe_library() @@ -106,7 +103,8 @@ print("Created molecules") # Set up the reactions -ionic_strength, excess_chemical_potential_monovalent_pairs_in_bulk_data, bjerrums, excess_chemical_potential_monovalent_pairs_in_bulk_data_error =np.loadtxt("../../../../../../../reference_data/excess_chemical_potential.dat", unpack=True) +path_to_ex_pot=pmb.get_resource("reference_data") +ionic_strength, excess_chemical_potential_monovalent_pairs_in_bulk_data, bjerrums, excess_chemical_potential_monovalent_pairs_in_bulk_data_error =np.loadtxt(f"{path_to_ex_pot}/excess_chemical_potential.dat", unpack=True) excess_chemical_potential_monovalent_pair_interpolated = interpolate.interp1d(ionic_strength, excess_chemical_potential_monovalent_pairs_in_bulk_data) activity_coefficient_monovalent_pair = lambda x: np.exp(excess_chemical_potential_monovalent_pair_interpolated(x.to('1/(reduced_length**3 * N_A)').magnitude)) print("Setting up reactions...") From df5c64bea235b519d6deb315d1077008c121bec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 4 Mar 2024 13:46:11 +0100 Subject: [PATCH 4/7] Set up virtual environment for cluster users --- .github/workflows/testsuite.yml | 11 +++++++---- README.md | 22 ++++++++++++++++++++-- maintainer/configure_venv.py | 11 +++++++++-- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index 316ef71..0eef7f8 100644 --- a/.github/workflows/testsuite.yml +++ b/.github/workflows/testsuite.yml @@ -20,12 +20,15 @@ jobs: - name: Install dependencies run: | module load ESPResSo/4.2.1-foss-2023a - python3 -m pip install --user -r requirements.txt + python3 -m venv --system-site-packages pymbe + source pymbe/bin/activate + python3 maintainer/configure_venv.py + python3 -m pip install -r requirements.txt + deactivate - name: Run testsuite run: | module load ESPResSo/4.2.1-foss-2023a - export OLD_PYTHONPATH="${PYTHONPATH}" - export PYTHONPATH="$(realpath .)${PYTHONPATH:+:$PYTHONPATH}" + source pymbe/bin/activate make testsuite - export PYTHONPATH="${OLD_PYTHONPATH}" + deactivate shell: bash diff --git a/README.md b/README.md index f318879..ace1fe3 100644 --- a/README.md +++ b/README.md @@ -52,12 +52,30 @@ the path to the ESPResSo build folder: ```sh python3 -m venv pymbe source pymbe/bin/activate -python3 maintainer/configure_venv.py /home/user/Documents/espresso/build # adapt this +python3 maintainer/configure_venv.py --espresso_path=~/espresso/build # adapt path python3 -m pip install -r requirements.txt deactivate ``` -We highlight that the path `/home/user/Documents/espresso/build` is just an example of a possible absolute path to the ESPResSo build folder. The user should change this path to match the local path were ESPResSo was installed. +We highlight that the path `~/espresso/build` is just an example of a possible +path to the ESPResSo build folder. The user should change this path to match +the local path were ESPResSo was installed. + +Cluster users who rely on module files to load dependencies should opt for the +following alternative: + +```sh +module load ESPResSo/4.2.1-foss-2022a # adapt module name +python3 -m venv --system-site-packages pymbe +source pymbe/bin/activate +python3 maintainer/configure_venv.py +python3 -m pip install -r requirements.txt +deactivate +module purge +``` + +We highlight that the module files need to be loaded before every activation +of the virtual environment. Now you can use pyMBE and ESPResSo by activating the virtual environment: diff --git a/maintainer/configure_venv.py b/maintainer/configure_venv.py index 1d3554b..f73990a 100644 --- a/maintainer/configure_venv.py +++ b/maintainer/configure_venv.py @@ -1,6 +1,11 @@ import os import argparse import sysconfig +try: + import espressomd + espressomd_found = True +except ModuleNotFoundError: + espressomd_found = False def make_pth(name, path): @@ -12,11 +17,13 @@ def make_pth(name, path): parser = argparse.ArgumentParser(description="Configure pyBME and ESPResSo module paths") -parser.add_argument("espresso_build_path", type=str, help="Path to the ESPResSo build folder") +parser.add_argument("--espresso_path", type=str, required=not espressomd_found, + help="Path to the ESPResSo build folder") args = parser.parse_args() if not os.environ.get("VIRTUAL_ENV"): raise RuntimeError("This script should be run in a virtual environment") +if not espressomd_found: + make_pth("espresso", os.path.join(args.espresso_path, "src", "python")) make_pth("pymbe", os.path.dirname(os.path.dirname(__file__))) -make_pth("espresso", os.path.join(args.espresso_build_path, "src", "python")) From 92411a03047631e5b47bf6400b0803627795b6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 6 Mar 2024 22:19:17 +0100 Subject: [PATCH 5/7] Bugfix --- maintainer/configure_venv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maintainer/configure_venv.py b/maintainer/configure_venv.py index f73990a..fbd3c74 100644 --- a/maintainer/configure_venv.py +++ b/maintainer/configure_venv.py @@ -26,4 +26,4 @@ def make_pth(name, path): if not espressomd_found: make_pth("espresso", os.path.join(args.espresso_path, "src", "python")) -make_pth("pymbe", os.path.dirname(os.path.dirname(__file__))) +make_pth("pymbe", os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) From 02f77950d4833c9c5ea8a03257eba65b4dd3181c Mon Sep 17 00:00:00 2001 From: blancoapa Date: Thu, 7 Mar 2024 14:58:23 +0100 Subject: [PATCH 6/7] Improve README with more details about venv, the path to espresso. Soften dependency on pint-pandas to 0.3 --- README.md | 29 +++++++++++++++++++++-------- requirements.txt | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ace1fe3..6f28d9b 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ A deprecated version of pyMBE compatible with ESPResSo v4.1.4 (under the histori ## Usage -### Set up the pyMBE environment +### Set up the pyMBE virtual environment To use pyMBE in your simulations, first clone this repository locally: @@ -44,22 +44,35 @@ git clone git@github.com:pm-blanco/pyMBE.git ``` Please, be aware that pyMBE is intended to be a supporting tool to setup simulations with ESPResSo. -Thus, for most of its functionalities ESPResSo must also be available. +Thus, for most of its functionalities ESPResSo must also be available. Following the NEP29 guidelines, we recommend the users of pyMBE to use Python3.10+ when using our module. -Create a virtual environment to install Python dependencies and configure -the path to the ESPResSo build folder: +The pyMBE module uses its own Python virtual enviroment to avoid incompatibility issues when loading its requierements from other libraries. +The Python module (`venv`)[https://docs.python.org/3/library/venv.html#module-venv] from the Python Standard Library (starting with Python 3.3) is needed to set up pyMBE. +If `venv` is not in the Python distribution of the user, the user will need to first install 'venv' before setting up pyMBE. +For Ubuntu users, this can be done as follows: + +```sh +sudo apt install python3-venv +``` + +To set up pyMBE, the users need to install its virtual environment, install its Python dependencies and configure the path to the ESPResSo build folder as follows: ```sh python3 -m venv pymbe source pymbe/bin/activate -python3 maintainer/configure_venv.py --espresso_path=~/espresso/build # adapt path +python3 maintainer/configure_venv.py --espresso_path=/home/user/espresso/build # adapt path python3 -m pip install -r requirements.txt deactivate ``` -We highlight that the path `~/espresso/build` is just an example of a possible +We highlight that the path `/home/user/espresso/build` is just an example of a possible path to the ESPResSo build folder. The user should change this path to match -the local path were ESPResSo was installed. +the local absolute path were ESPResSo was installed. + +The pyMBE virtual enviroment can be deactivated at any moment: +```sh +deactivate +``` Cluster users who rely on module files to load dependencies should opt for the following alternative: @@ -123,7 +136,7 @@ You can run the interactive tutorial of pyMBE with the command: ```sh source pymbe/bin/activate -jupyter lab tutorials/pyMBE_tutorial.ipynb +jupyter-lab tutorials/pyMBE_tutorial.ipynb deactivate ``` diff --git a/requirements.txt b/requirements.txt index 03666d4..bbe9eb0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ numpy>=1.23 pandas>=1.5.3 pint>=0.20.01 -pint-pandas==0.5 +pint-pandas>=0.3 biopandas==0.5.1.dev0 scipy matplotlib From 5895abc199b4f1599f332b11a621620ea4139659 Mon Sep 17 00:00:00 2001 From: blancoapa Date: Thu, 7 Mar 2024 15:33:58 +0100 Subject: [PATCH 7/7] fix dependencies version number, add new folders to README --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6f28d9b..395b0bd 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@ pyMBE provides tools to facilitate building up molecules with complex architectu ## Dependencies -- [ESPResSo](https://espressomd.org/wordpress/) v4.2.1 -- [Pint](https://pint.readthedocs.io/en/stable/) v0.20.01 -- [Pandas](https://pandas.pydata.org/) v1.5.3 -- [Pint-Pandas](https://pypi.org/project/Pint-Pandas/) v0.5 -- [Numpy](https://numpy.org/) -- [SciPy](https://scipy.org/) +- [ESPResSo](https://espressomd.org/wordpress/) =4.2.1 +- [Pint](https://pint.readthedocs.io/en/stable/) >=0.20.01 +- [Pandas](https://pandas.pydata.org/) >=1.5.3 +- [Pint-Pandas](https://pypi.org/project/Pint-Pandas/) >=0.3 +- [Numpy](https://numpy.org/) >=1.23 +- [SciPy](https://scipy.org/) - [pdoc](https://pdoc.dev/) (for building the docs) ## Branches @@ -22,10 +22,12 @@ A deprecated version of pyMBE compatible with ESPResSo v4.1.4 (under the histori - `figs/`: folder with various images used in the tutorials of pyMBE. - `handy_scripts/`: folder with various handy scripts and libraries. - `logo/`: folder with the logo of pyMBE. +- `mantainer/`: folder with various scripts used by the mantainers. - `reference_data/`: folder with various reference data set used to validate pyMBE. - `reference_parameters/`: folder with various sets of parameters from previous works. - `sample_scripts/`: folder with various sample scripts showcasing how to use pyMBE to setup different systems. - `tests/`: folder with several test scripts to check that new developments do not break pyMBE. +- `testsuite/`: folder with several test scripts and data for continous integration of the library. - `tutorials/`: folder with the available tutorials on pyMBE. - `visualization/`: folder with helper scripts to aid the visualization of vtf trajectories from constant pH and Grand reaction simulations with [VMD](https://www.ks.uiuc.edu/Research/vmd/). - `AUTHORS.md`: list of authors and contributors of pyMBE.