From fa4d65295a4a2dadc7954f272a19101704280d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 8 May 2024 19:55:21 +0200 Subject: [PATCH] Allow custom Python executables --- Makefile | 40 ++++++++++--------- samples/Beyer2024/create_paper_data.py | 12 +++--- testsuite/cph_ideal_tests.py | 3 +- testsuite/gcmc_tests.py | 13 +++--- testsuite/globular_protein_tests.py | 7 ++-- testsuite/grxmc_ideal_tests.py | 5 ++- testsuite/peptide_tests.py | 7 ++-- .../weak_polyelectrolyte_dialysis_test.py | 3 +- 8 files changed, 50 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 122dfd8..2ed0794 100644 --- a/Makefile +++ b/Makefile @@ -3,36 +3,38 @@ .PHONY: visual .PHONY: clean +PYTHON = python3 + docs: mkdir -p ./documentation - pdoc ./pyMBE.py -o ./documentation --docformat google + PDOC_ALLOW_EXEC=0 ${PYTHON} -m pdoc ./pyMBE.py -o ./documentation --docformat google tests: - python3 testsuite/lj_tests.py - python3 testsuite/set_particle_acidity_test.py - python3 testsuite/bond_tests.py - python3 testsuite/generate_perpendicular_vectors_test.py - python3 testsuite/create_molecule_position_test.py - python3 testsuite/seed_test.py - python3 testsuite/read-write-df_test.py - python3 testsuite/parameter_test.py - python3 testsuite/henderson_hasselbalch_tests.py - python3 testsuite/cph_ideal_tests.py - python3 testsuite/grxmc_ideal_tests.py - python3 testsuite/peptide_tests.py - python3 testsuite/gcmc_tests.py - python3 testsuite/weak_polyelectrolyte_dialysis_test.py - python3 testsuite/globular_protein_tests.py + ${PYTHON} testsuite/lj_tests.py + ${PYTHON} testsuite/set_particle_acidity_test.py + ${PYTHON} testsuite/bond_tests.py + ${PYTHON} testsuite/generate_perpendicular_vectors_test.py + ${PYTHON} testsuite/create_molecule_position_test.py + ${PYTHON} testsuite/seed_test.py + ${PYTHON} testsuite/read-write-df_test.py + ${PYTHON} testsuite/parameter_test.py + ${PYTHON} testsuite/henderson_hasselbalch_tests.py + ${PYTHON} testsuite/cph_ideal_tests.py + ${PYTHON} testsuite/grxmc_ideal_tests.py + ${PYTHON} testsuite/peptide_tests.py + ${PYTHON} testsuite/gcmc_tests.py + ${PYTHON} testsuite/weak_polyelectrolyte_dialysis_test.py + ${PYTHON} testsuite/globular_protein_tests.py sample: - python3 samples/peptide.py + ${PYTHON} samples/peptide.py visual: - python3 visualization/vmd-traj.py + ${PYTHON} visualization/vmd-traj.py vmd -e visualization.tcl tutorial: jupyter-lab tutorials/pyMBE_tutorial.ipynb pylint: - pylint pyMBE.py lib/ testsuite/ samples/ maintainer/ visualization/ + ${PYTHON} -m pylint pyMBE.py lib/ testsuite/ samples/ maintainer/ visualization/ diff --git a/samples/Beyer2024/create_paper_data.py b/samples/Beyer2024/create_paper_data.py index 9b543e0..d686179 100644 --- a/samples/Beyer2024/create_paper_data.py +++ b/samples/Beyer2024/create_paper_data.py @@ -1,7 +1,8 @@ # Import pyMBE and other libraries import pyMBE from lib import analysis -import os +import os +import sys import numpy as np import argparse import subprocess @@ -51,7 +52,7 @@ raise RuntimeError() pH_range = np.linspace(2, 12, num=21) for pH in pH_range: - run_command=["python3", script_path, "--sequence", sequence, "--pH", str(pH), "--mode", mode] + run_command=[sys.executable, script_path, "--sequence", sequence, "--pH", str(pH), "--mode", mode] print(subprocess.list2cmdline(run_command)) subprocess.check_output(run_command) @@ -64,13 +65,14 @@ script_path=pmb.get_resource("samples/Beyer2024/globular_protein.py") pH_range = np.linspace(2, 7, num=11) + run_command_common=[sys.executable, script_path, "--pdb", protein_pdb, "--path_to_cg", path_to_cg, "--mode", mode, "--no_verbose"] if fig_label == "8a": protein_pdb = "1f6s" path_to_cg = f"parameters/globular_proteins/{protein_pdb}.vtf" for pH in pH_range: - run_command=["python3", script_path, "--pdb", protein_pdb, "--pH", str(pH), "--path_to_cg", path_to_cg, "--mode", mode, "--no_verbose", "--metal_ion_name", "Ca", "--metal_ion_charge", str(2)] + run_command=run_command_common + ["--pH", str(pH), "--metal_ion_name", "Ca", "--metal_ion_charge", str(2)] print(subprocess.list2cmdline(run_command)) subprocess.check_output(run_command) @@ -78,7 +80,7 @@ protein_pdb = "1beb" path_to_cg = f"parameters/globular_proteins/{protein_pdb}.vtf" for pH in pH_range: - run_command=["python3", script_path, "--pdb", protein_pdb, "--pH", str(pH), "--path_to_cg", path_to_cg, "--mode", mode, "--no_verbose"] + run_command=run_command_common + ["--pH", str(pH)] print(subprocess.list2cmdline(run_command)) subprocess.check_output(run_command) else: @@ -91,7 +93,7 @@ pH_range = np.linspace(1, 13, num=13) c_salt_res = 0.01 * pmb.units.mol/pmb.units.L for pH in pH_range: - run_command=["python3", script_path, "--c_salt_res", str(0.01), "--c_mon_sys", str(0.435), "--pH_res", str(pH), "--pKa_value", str(4.0), "--mode", mode] + run_command=[sys.executable, script_path, "--c_salt_res", str(0.01), "--c_mon_sys", str(0.435), "--pH_res", str(pH), "--pKa_value", str(4.0), "--mode", mode] print(subprocess.list2cmdline(run_command)) subprocess.check_output(run_command) diff --git a/testsuite/cph_ideal_tests.py b/testsuite/cph_ideal_tests.py index f07126c..5e3d888 100644 --- a/testsuite/cph_ideal_tests.py +++ b/testsuite/cph_ideal_tests.py @@ -1,5 +1,6 @@ # Import pyMBE and other libraries import pyMBE +import sys import subprocess import numpy as np import pandas as pd @@ -13,7 +14,7 @@ print("*** Constant pH (cpH) implementation tests ***\n") print("*** Test that our implementation of the cpH method reproduces the Henderson Hasselbalch equation for an ideal polyampholyte ***\n") -run_command = ["python3", script_path, "--test"] +run_command = [sys.executable, script_path, "--test"] subprocess.check_output(run_command) data = pd.read_csv(data_path) diff --git a/testsuite/gcmc_tests.py b/testsuite/gcmc_tests.py index 3ba28f9..1878780 100644 --- a/testsuite/gcmc_tests.py +++ b/testsuite/gcmc_tests.py @@ -1,13 +1,14 @@ # Import pyMBE and other libraries -import pyMBE -from lib import analysis +import sys import tempfile import subprocess +import pyMBE +from lib import analysis import numpy as np # Template of the test -def gcmc_test(mode, script_path): +def gcmc_test(script_path, mode): if mode == "ideal": print("*** Running test for GCMC of salt solution (ideal). ***") elif mode == "interacting": @@ -15,7 +16,7 @@ def gcmc_test(mode, script_path): with tempfile.TemporaryDirectory() as time_series_path: for c_salt_res in salt_concentrations: print(f"c_salt_res = {c_salt_res}") - run_command=["python3", script_path, "--c_salt_res", str(c_salt_res), "--output", time_series_path, "--mode", mode, "--no_verbose"] + run_command=[sys.executable, script_path, "--c_salt_res", str(c_salt_res), "--output", time_series_path, "--mode", mode, "--no_verbose"] print(subprocess.list2cmdline(run_command)) subprocess.check_output(run_command) # Analyze all time series @@ -37,7 +38,7 @@ def gcmc_test(mode, script_path): atol=0.0 # absolute tolerance # Ideal test -gcmc_test("ideal", script_path) +gcmc_test(script_path, "ideal") # Interacting test -gcmc_test("interacting", script_path) +gcmc_test(script_path, "interacting") diff --git a/testsuite/globular_protein_tests.py b/testsuite/globular_protein_tests.py index 08e04a3..b953c62 100644 --- a/testsuite/globular_protein_tests.py +++ b/testsuite/globular_protein_tests.py @@ -1,6 +1,7 @@ # Import pyMBE and other libraries import pyMBE from lib import analysis +import sys import tempfile import subprocess import numpy as np @@ -22,13 +23,13 @@ def run_protein_test(script_path, test_pH_values, protein_pdb, rtol, atol,mode=" print(f"Running tests for {protein_pdb}") with tempfile.TemporaryDirectory() as time_series_path: - for pH in test_pH_values: print(f"pH = {pH}") - run_command=["python3", script_path, "--pdb", protein_pdb, "--pH", str(pH), "--path_to_cg", f"parameters/globular_proteins/{protein_pdb}.vtf"] + run_command=[sys.executable, script_path, "--pdb", protein_pdb, "--pH", str(pH), + "--path_to_cg", f"parameters/globular_proteins/{protein_pdb}.vtf", + "--mode", "test", "--no_verbose", "--output", time_series_path] if protein_pdb == '1f6s': run_command+=["--metal_ion_name","Ca", "--metal_ion_charge", "2"] - run_command+=["--mode", "test", "--no_verbose", "--output", time_series_path] print(subprocess.list2cmdline(run_command)) subprocess.check_output(run_command) # Analyze all time series diff --git a/testsuite/grxmc_ideal_tests.py b/testsuite/grxmc_ideal_tests.py index 67400ba..8265d8b 100644 --- a/testsuite/grxmc_ideal_tests.py +++ b/testsuite/grxmc_ideal_tests.py @@ -1,5 +1,6 @@ # Import pyMBE and other libraries import pyMBE +import sys import subprocess import numpy as np import pandas as pd @@ -12,7 +13,7 @@ print("*** Grand reaction (G-RxMC) implementation tests ***\n") print("*** Test that our implementation of the original G-RxMC method reproduces the Henderson-Hasselbalch equation corrected with the Donnan potential (HH+Don) for an ideal mixture of peptides ***") -run_command = ["python3", script_path, "--mode", "standard", "--test"] +run_command = [sys.executable, script_path, "--mode", "standard", "--test"] subprocess.check_output(run_command) data = pd.read_csv(data_path) @@ -26,7 +27,7 @@ print("*** Test that our implementation of the G-RxMC method with unified ion types reproduces HH+Don for an ideal mixture of peptides ***") -run_command = ["python3", script_path, "--mode", "unified", "--test"] +run_command = [sys.executable, script_path, "--mode", "unified", "--test"] subprocess.check_output(run_command) data = pd.read_csv(data_path) diff --git a/testsuite/peptide_tests.py b/testsuite/peptide_tests.py index 0cd90cf..261499e 100644 --- a/testsuite/peptide_tests.py +++ b/testsuite/peptide_tests.py @@ -1,8 +1,9 @@ # Import pyMBE and other libraries -import pyMBE -from lib import analysis +import sys import tempfile import subprocess +import pyMBE +from lib import analysis import numpy as np import pandas as pd @@ -24,7 +25,7 @@ def run_peptide_test(script_path,test_pH_values,sequence,rtol,atol,mode="test"): with tempfile.TemporaryDirectory() as time_series_path: for pH in test_pH_values: print(f"pH = {pH}") - run_command=["python3", script_path, "--sequence", sequence, "--pH", str(pH), "--mode", "test", "--no_verbose", "--output", time_series_path] + run_command=[sys.executable, script_path, "--sequence", sequence, "--pH", str(pH), "--mode", "test", "--no_verbose", "--output", time_series_path] print(subprocess.list2cmdline(run_command)) subprocess.check_output(run_command) # Analyze all time series diff --git a/testsuite/weak_polyelectrolyte_dialysis_test.py b/testsuite/weak_polyelectrolyte_dialysis_test.py index e8e95b8..c770cc3 100644 --- a/testsuite/weak_polyelectrolyte_dialysis_test.py +++ b/testsuite/weak_polyelectrolyte_dialysis_test.py @@ -1,6 +1,7 @@ # Import pyMBE and other libraries import pyMBE from lib import analysis +import sys import tempfile import subprocess import numpy as np @@ -21,7 +22,7 @@ with tempfile.TemporaryDirectory() as time_series_path: for pH in test_pH_values: print(f"pH = {pH}") - run_command=["python3", script_path, "--c_salt_res", str(c_salt_res), "--c_mon_sys", str(c_mon_sys), "--pKa_value", str(pKa_value), "--pH_res", str(pH), "--mode", "test", "--output", time_series_path, "--no_verbose"] + run_command=[sys.executable, script_path, "--c_salt_res", str(c_salt_res), "--c_mon_sys", str(c_mon_sys), "--pKa_value", str(pKa_value), "--pH_res", str(pH), "--mode", "test", "--output", time_series_path, "--no_verbose"] print(subprocess.list2cmdline(run_command)) subprocess.check_output(run_command) # Analyze all time series