Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure the pyMBE virtual environment #12

Merged
merged 7 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +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}"
sed -i "s/\${ESPResSo_build_path}\///" Makefile
source pymbe/bin/activate
make testsuite
export PYTHONPATH="${OLD_PYTHONPATH}"
deactivate
shell: bash
21 changes: 8 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,27 @@
.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

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
Expand Down
118 changes: 94 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -35,54 +37,122 @@ 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 virtual 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. Following the NEP29 guidelines, we recommend the users of pyMBE to use Python3.10+ when using our module.

```py
from pyMBE import pyMBE
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
```

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
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:

```py
import espressomd
```sh
python3 -m venv pymbe
source pymbe/bin/activate
python3 maintainer/configure_venv.py --espresso_path=/home/user/espresso/build # adapt path
python3 -m pip install -r requirements.txt
deactivate
```

and your simulations should be runned using ESPResSo
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 absolute path were ESPResSo was installed.

The pyMBE virtual enviroment can be deactivated at any moment:
```sh
${ESPResSo_build_path}/pypresso your_simulation_script.py
deactivate
```

### Run the tutorial of pyMBE
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:

```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
```

You can run the interactive tutorial of pyMBE with the command
To use pyMBE in JupyterLab, register the virtual environment in a new kernel:

```sh
${ESPResSo_build_path}/ipypresso notebook pyMBE_tutorial.ipynb
source pymbe/bin/activate
python3 -m pip install ipykernel "jupyterlab>=4.0.8" "PyOpenGL>=3.1.5"
python3 -m ipykernel install --user --name=pyMBE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I tried to encapsulate the pyMBE kernel into the virtual environment itself, but Jupyter only seems to detect the ones installed in the user's $HOME folder:

(pymbe) $ python3 -m ipykernel install --sys-prefix --name=pyMBE
Installed kernelspec pyMBE in /work/jgrad/pyMBE/pymbe/share/jupyter/kernels/pymbe
(pymbe) $ which jupyter
/work/jgrad/pyMBE/pymbe/bin/jupyter
(pymbe) $ jupyter kernelspec list
Available kernels:
  pymbe      /home/jgrad/.local/share/jupyter/kernels/pymbe
  python3    /home/jgrad/.local/share/jupyter/kernels/python3

I couldn't find a way to detect the local folders. I tried to generate a default Jupyter config file in the virtual environment, thinking I could adapt something a path in there, but Jupyter ended up writing the default config file in my $HOME folder directly... So be careful if you want to tinker with Jupyter settings in the virtual environment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jngrad I followed the instructions and it was pretty clear to me how to set up and use the new virtual environment of pyMBE. I fixed all paths in the scripts and removed the previous logic to import pyMBE.

I have to say that this new pyMBE environment is very cool and I think that it could be very helpful to make our lives easier to use both espresso and pyMBE. It is, however, not clear to me how to setup pyMBE when using it in a cluster when you do not now the path in which espresso was built. I tried to import the espresso module built-in in the cluster we use at NTNU and then following the instructions but I failed:

[pablb@idun-login1 pyMBE_jn]$ module load ESPResSo/4.2.1-foss-2022a
[pablb@idun-login1 pyMBE_jn]$ python3 -m venv pymbe
[pablb@idun-login1 pyMBE_jn]$ source pymbe/bin/activate
(pymbe) [pablb@idun-login1 pyMBE_jn]$ python3 -m pip install -r requirements.txt
Collecting numpy>=1.23
  Downloading numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 82.3 MB/s eta 0:00:00
Collecting pandas>=1.5.3
  Downloading pandas-2.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.0/13.0 MB 65.9 MB/s eta 0:00:00
Requirement already satisfied: pint>=0.20.01 in /cluster/apps/eb/software/Pint/0.22-GCCcore-11.3.0/lib/python3.10/site-packages (from -r requirements.txt (line 3)) (0.22)
Collecting pint-pandas==0.5
  Downloading Pint_Pandas-0.5-py3-none-any.whl (25 kB)
Collecting biopandas==0.5.1.dev0
  Downloading biopandas-0.5.1.dev0-py3-none-any.whl (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 11.7 MB/s eta 0:00:00
Requirement already satisfied: scipy in /cluster/apps/eb/software/SciPy-bundle/2022.05-foss-2022a/lib/python3.10/site-packages (from -r requirements.txt (line 6)) (1.8.1)
Collecting matplotlib
  Downloading matplotlib-3.8.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.6/11.6 MB 80.5 MB/s eta 0:00:00
Collecting tqdm
  Downloading tqdm-4.66.2-py3-none-any.whl (78 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.3/78.3 KB 9.4 MB/s eta 0:00:00
Requirement already satisfied: setuptools in ./pymbe/lib/python3.10/site-packages (from biopandas==0.5.1.dev0->-r requirements.txt (line 5)) (58.1.0)
Collecting looseversion==1.1.2
  Downloading looseversion-1.1.2-py3-none-any.whl (8.1 kB)
Collecting mmtf-python==1.1.3
  Downloading mmtf_python-1.1.3-py2.py3-none-any.whl (25 kB)
Collecting msgpack>=1.0.0
  Downloading msgpack-1.0.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (385 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 385.1/385.1 KB 39.1 MB/s eta 0:00:00
Collecting python-dateutil>=2.8.2
  Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 229.9/229.9 KB 25.5 MB/s eta 0:00:00
Collecting pytz>=2020.1
  Downloading pytz-2024.1-py2.py3-none-any.whl (505 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 505.5/505.5 KB 35.1 MB/s eta 0:00:00
Collecting tzdata>=2022.7
  Downloading tzdata-2024.1-py2.py3-none-any.whl (345 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 345.4/345.4 KB 25.2 MB/s eta 0:00:00
Collecting typing-extensions
  Downloading typing_extensions-4.10.0-py3-none-any.whl (33 kB)
Collecting numpy>=1.23
  Downloading numpy-1.24.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.3/17.3 MB 90.7 MB/s eta 0:00:00
Collecting pyparsing>=2.3.1
  Downloading pyparsing-3.1.1-py3-none-any.whl (103 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 103.1/103.1 KB 12.1 MB/s eta 0:00:00
Collecting kiwisolver>=1.3.1
  Downloading kiwisolver-1.4.5-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 81.6 MB/s eta 0:00:00
Collecting packaging>=20.0
  Downloading packaging-23.2-py3-none-any.whl (53 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 53.0/53.0 KB 5.7 MB/s eta 0:00:00
Collecting fonttools>=4.22.0
  Downloading fonttools-4.49.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.6/4.6 MB 95.1 MB/s eta 0:00:00
Collecting pillow>=8
  Downloading pillow-10.2.0-cp310-cp310-manylinux_2_28_x86_64.whl (4.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.5/4.5 MB 76.1 MB/s eta 0:00:00
Collecting cycler>=0.10
  Downloading cycler-0.12.1-py3-none-any.whl (8.3 kB)
Collecting contourpy>=1.0.1
  Downloading contourpy-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (310 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 310.7/310.7 KB 32.2 MB/s eta 0:00:00
Collecting six>=1.5
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: pytz, tzdata, typing-extensions, tqdm, six, pyparsing, pillow, packaging, numpy, msgpack, looseversion, kiwisolver, fonttools, cycler, python-dateutil, mmtf-python, contourpy, pandas, matplotlib, pint-pandas, biopandas
  Attempting uninstall: numpy
    Found existing installation: numpy 1.22.3
    Not uninstalling numpy at /cluster/apps/eb/software/SciPy-bundle/2022.05-foss-2022a/lib/python3.10/site-packages, outside environment /cluster/home/pablb/pymBE_jn/pymbe
    Can't uninstall 'numpy'. No files were found to uninstall.
  Attempting uninstall: pandas
    Found existing installation: pandas 1.4.2
    Not uninstalling pandas at /cluster/apps/eb/software/SciPy-bundle/2022.05-foss-2022a/lib/python3.10/site-packages, outside environment /cluster/home/pablb/pymBE_jn/pymbe
    Can't uninstall 'pandas'. No files were found to uninstall.
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
nbconvert 6.5.3 requires jinja2>=3.0, which is not installed.
nbconvert 6.5.3 requires MarkupSafe>=2.0, which is not installed.
nbconvert 6.5.3 requires pygments>=2.4.1, which is not installed.
jupyter-packaging 0.12.0 requires tomlkit, which is not installed.
jupyter-packaging 0.12.0 requires wheel, which is not installed.
ipykernel 6.13.0 requires psutil, which is not installed.
bleach 5.0.1 requires webencodings, which is not installed.
argon2-cffi 20.1.0 requires cffi>=1.0.0, which is not installed.
jupyter-packaging 0.12.0 requires setuptools>=60.2.0, but you have setuptools 58.1.0 which is incompatible.
Successfully installed biopandas-0.5.1.dev0 contourpy-1.2.0 cycler-0.12.1 fonttools-4.49.0 kiwisolver-1.4.5 looseversion-1.1.2 matplotlib-3.8.3 mmtf-python-1.1.3 msgpack-1.0.8 numpy-1.24.4 packaging-23.2 pandas-2.2.1 pillow-10.2.0 pint-pandas-0.5 pyparsing-3.1.1 python-dateutil-2.9.0.post0 pytz-2024.1 six-1.16.0 tqdm-4.66.2 typing-extensions-4.10.0 tzdata-2024.1
WARNING: You are using pip version 22.0.4; however, version 24.0 is available.
You should consider upgrading via the '/cluster/home/pablb/pymBE_jn/pymbe/bin/python3 -m pip install --upgrade pip' command.

(pymbe) [pablb@idun-login1 pyMBE_jn]$ pypresso testsuite/LYS_ASP_peptide.py
Traceback (most recent call last):
  File "/cluster/home/pablb/pyMBE_jn/testsuite/LYS_ASP_peptide.py", line 7, in <module>
    from tqdm import tqdm
ModuleNotFoundError: No module named 'tqdm'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pinedaps could you please check this new feature (see #12)? clone the forked pyMBE repository of @jngrad in here, follow the new instructions to set up and use pyMBE in the README file and let us now if they are clear to you

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am too used to building ESPResSo myself on clusters 😀

The configure_venv.py now detects if ESPResSo is already available as a module, so that cluster users can module load ESPResSo. I had to adapt the argparse syntax, because positional arguments cannot be made optional. The configure_venv.py script is now tested in CI as well.

There is also a venv option to only install the subset of Python packages that are not already loaded with ESPResSo; this should avoid the broken Python dependency tree you observed on the cluster. This is now documented in the readme file too.

Copy link
Contributor

@pinedaps pinedaps Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pm-blanco @jngrad, I was following the new instructions and I got this error while running

python3 maintainer/configure_venv.py --espresso_path=~/espresso/build " ...
(pymbe) student@student-Swift3:~/pyMBE$ python3 maintainer/configure_venv.py --espresso_path=/home/student/espresso-4.2.1/espresso/build
Traceback (most recent call last):
  File "maintainer/configure_venv.py", line 29, in <module>
    make_pth("pymbe", os.path.dirname(os.path.dirname(__file__)))
  File "maintainer/configure_venv.py", line 13, in make_pth
    raise ValueError(f"Folder '{path}' doesn't exist")
ValueError: Folder '' doesn't exist

In order to check that the provided path was right, I did 'ls' to the folder and it normally showed the content.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please check if the issue persists after replacing __file__ by os.path.abspath(__file__) at line 29?

Copy link
Contributor

@pinedaps pinedaps Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it and it worked. Now, It complained when installing the requirements because it could not find a version that satisfies the requirement pint-pandas==0.5. While looking for an explanation, we realized that my python's version is 3.8 while Pablo's version is 3.10 (it runs without problems). Could it be that the previous error is related to this fact as well? If so then should be worthy to specify which is the minimum required version of python.

Requirement already satisfied: numpy>=1.23 in ./pymbe/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (1.24.4)
Requirement already satisfied: pandas>=1.5.3 in ./pymbe/lib/python3.8/site-packages (from -r requirements.txt (line 2)) (2.0.3)
Requirement already satisfied: pint>=0.20.01 in ./pymbe/lib/python3.8/site-packages (from -r requirements.txt (line 3)) (0.21.1)
ERROR: Could not find a version that satisfies the requirement pint-pandas==0.5 (from -r requirements.txt (line 4)) (from versions: 0.1, 0.2, 0.3)
ERROR: No matching distribution found for pint-pandas==0.5 (from -r requirements.txt (line 4))

Copy link
Member Author

@jngrad jngrad Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pint-pandas is not packaged for Python 3.8. It is probably related to NEP 29 - Recommend Python and Numpy version support as a community policy standard. Major Python packages like matplotlib, jupyter and scipy had already adopted NEP 29 in 2020 (around the time when pint-pandas got its first release). ESPResSo eventually adopted NEP 29 in 2022 because maintaining support for older Python versions was not worth the trouble. According to the NEP 29 drop schedule, Python 3.8 is no longer officially supprted by the NumPy ecosystem since early 2023, and they'll drop support for Python 3.9 next month.

deactivate
```

or alternatively you can run the command
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.

### Use pyMBE in your simulation scripts

```sh
source pymbe/bin/activate
python3 sample_scripts/peptide.py
deactivate
```

### Run the tutorial of pyMBE

You can run the interactive tutorial of pyMBE with the command:

```sh
make tutorial
source pymbe/bin/activate
jupyter-lab tutorials/pyMBE_tutorial.ipynb
deactivate
```

provided that you have modified the `$ESPResSo_build_path` variable in `Makefile` to match the path where you have built ESPResSo.
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:

```sh
PYTHONPATH=$(realpath .) make testsuite
source pymbe/bin/activate
make testsuite
deactivate
```

When contributing new features, consider adding a unit test in the `testsuite/`
Expand Down
29 changes: 29 additions & 0 deletions maintainer/configure_venv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import argparse
import sysconfig
try:
import espressomd
espressomd_found = True
except ModuleNotFoundError:
espressomd_found = False


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_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(os.path.abspath(__file__))))
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 0 additions & 7 deletions sample_scripts/branched_polyampholyte.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 5 additions & 12 deletions sample_scripts/globular_protein.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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,
Expand Down
15 changes: 5 additions & 10 deletions sample_scripts/peptide.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down
12 changes: 4 additions & 8 deletions sample_scripts/peptide_mixture_grxmc_ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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']
Expand Down
Loading