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

Updated installation #14

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d6c0222
Vanilla editable build of Trimem 0.2.1 used as starting point for the…
watermair Jul 5, 2023
32cb08a
Trimem-Sbeady Project 1. commit:
watermair Jul 7, 2023
0c8cb1a
Version 0.1 of the Trimem_sbeady code introducing the reset of simula…
watermair Jul 12, 2023
0563874
Adding the TriSim Class and start of development on alternative Energ…
watermair Jul 14, 2023
0ba50fe
add clion paths to gitignore
lasergyro Jul 14, 2023
929a8fa
Merge branch 'main' of github-lasergyro:Saric-Group/trimem_sbeady
lasergyro Jul 14, 2023
c66a6e2
some cpp
lasergyro Jul 14, 2023
fe50d10
First working TriSim-object oriented version. EnergyEvaluators got de…
watermair Jul 24, 2023
8618591
Version used for Validation Data
watermair Jul 25, 2023
5523880
Isolating Helfrich Energy and Gradient from Surface Repulsion by intr…
watermair Aug 2, 2023
e5da6c2
Connecting TriMem and LAMMPS via the LAMMPS modify external and treat…
watermair Aug 14, 2023
ab65cf3
Lammpspowered Version of Trimem including meshtopology via bonds and …
watermair Aug 24, 2023
b210253
Including Non-Reciprocal Interactions
watermair Sep 6, 2023
f058fa4
Documented Version. Started adding h5 output
watermair Sep 18, 2023
8dc51ca
adding install-guides
watermair Sep 26, 2023
4bfde5c
Installation ready version
watermair Sep 26, 2023
2a92ac8
Added custom mode and fixed problem with multiple interactions
watermair Sep 29, 2023
28ab6d5
fix trilmp.py in set_repulsion
maitane-muba Oct 9, 2023
f3cd34e
updated 'fix langevin' with user-input parameters
maitane-muba Oct 10, 2023
a49f019
Merge pull request #1 from Saric-Group/Fix-Langevin-hardcoded-parameters
maitane-muba Oct 10, 2023
0707a34
remove CM drift in fix langevin
maitane-muba Oct 10, 2023
10f81d3
Merge pull request #2 from Saric-Group/fix-langevin-update
maitane-muba Oct 10, 2023
56ad0ff
refactor to correct zero beads situation. compile and run on osx-arm6…
lasergyro Oct 10, 2023
8efa707
Merge branch 'main' of github-lasergyro:Saric-Group/trimem_sbeady
lasergyro Oct 10, 2023
e1fa93c
2024
lasergyro Aug 29, 2024
bc9d3bf
Merge branch 'bio-phys:main' into install_tmp
maitane-muba Aug 30, 2024
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
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
**/.DS_store
.vscode/
**/*.so
**/*.dylib
build
cmake-build-*/
.idea/
**/*.so
**/*.so.*
_skbuild
dist
public
src/trimem/_version.py
*.egg-info
**/*.egg-info
.eggs
*.so
__pycache__
*.swp
venv
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "OpenMesh"]
path = OpenMesh
url = https://gitlab.vci.rwth-aachen.de:9000/OpenMesh/OpenMesh.git
[submodule "lammps"]
path = lammps
url = [email protected]:lammps/lammps.git
120 changes: 111 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,128 @@
# Trimem
# TriLmp

**Trimem** is a python package for the Monte Carlo simulation of lipid
membranes according to the Helfrich theory [^Helfrich1973].
**TriLmp** is a modified version of the **Trimem** python package for the Monte Carlo simulation of lipid
membranes according to the Helfrich theory [^Helfrich1973]. It allows for the direct use for MD simulations
in connection with LAMMPS via the python interface of the latter. Hereby the calculation of the surface repulsion
is dealt with by LAMMPS instead of Trimem.

[^Helfrich1973]: Helfrich, W. (1973) Elastic properties of lipid bilayers:
Theory and possible experiments. Zeitschrift für Naturforschung C,
28(11), 693-703

## Installation

Trimem can be installed using pip:
We suggest installing TriLmp in a conda environment and then install trimem/trilmp as a editable install.
This allows you to alter trilmp functionality by directly tinkering with the src/trimem/trilmp.py file.
As trilmp is reliant on a lot of LAMMPS command-string which are not all parametrized via the TriLmp object,
an editable install should be a bit more flexible.


### Conda Environment

To set up a conda environment including some prerequisites use:

```bash
conda create -n Trienv
conda install -n Trienv scikit-build libgcc pybind11
conda activate Trienv
```
Make sure the evironment is activated throughout the rest of the setup!

### Trimem/Trilmp
TriLmp can be installed using pip:
Note that this folder will be the actual location of the modules with an editable install.
I.e. if you change something in the python code here, effects will be immediate.
In case you want to change something on the c++ side: run "python3 setup.py build" to compile and copy
the libaries to the src/trimem folder as described below.

```bash
git clone --recurse-submodules https://github.com/Saric-Group/trimem_sbeady.git

cd trimem_sbeady
git submodule update
pip install -e .
```

In case they are not build during install one can compile the shared libraries
using
```bash
python3 setup.py build
```

Finally some shared libraries have to be copied manually from the _skbuild folder.
The names depends on system and python verison!
-> all the .so files should be placed in the src/trimem folder

```bash
cp _skbuild/linux-x86_64-3.11/cmake-build/core.cpython-311-x86_64-linux-gnu.so src/trimem/.
cp _skbuild/linux-x86_64-3.11/cmake-build/libtrimem.so src/trimem/.
cp _skbuild/linux-x86_64-3.11/cmake-build/Build/lib/* src/trimem/.
```

### LAMMPS
LAMMPs has to be installed using python shared libraries and some packages (can be extended).
If you already have lammps you might just have to reinstall it. In any case you will have to
perform the python install using your Trienv environment.

To get lammps from git ( go back to the directory where you want to have your install folder)

```bash
git clone -b stable https://github.com/lammps/lammps.git lammps
```
!!!! IMPORTANT !!!!
Before proceeding further you have to place some files in the lammps/src folder to enable the nonreciprocal and nonreciprocal/omp pair_styles.
In the folder nonrec in the trimem_sbeady repositry you find pair_nonreciprocal.cpp/.h and pair_nonreciprocal_omp.cpp/.h .
The two files pair_nonreciprocal have to be placed in the lammps/src folder and the two pair_nonreciprocal_omp files in the lammps/src/OPENMP folder.
Now we can start installing the LAMMPS. First go to the lammps directory and create the build folder.
```bash
cd lammps
mkdir build
cd build
```

Next we have to determine the python executable path. You can do that from the python console
using
```bash
python3
import sys
print(sys.executable)
```
which should print something like

```bash
/nfs/scistore15/saricgrp/Your_folder/.conda/envs/Trienv/bin/python3
```
and will be referred to as "python_path" in the next bash command. Not that this enables PyLammps this specific conda environment only!

Now we can set up the makefiles and build LAMMPS w
REMARK: -D PKG_ASPHERE=yes is not stricly necessary in what comes next, but instead you can add whatever package you have in mind for your simulations.

```bash
cmake -D BUILD_OMP=yes -D BUILD_SHARED_LIBS=yes -D PYTHON_EXECUTABLE="python_path" -D PKG_MOLECULE=yes -D PKG_PYTHON=yes -D PKG_OPENMP=yes -D PKG_EXTRA-PAIR=yes -D PKG_ASPHERE=yes ../cmake
cmake --build .
```

Finally to make LAMMPS accessible for python, i.e. making and copying the shared libaries.

```bash
git clone --recurse-submodules https://github.com/bio-phys/trimem.git
pip install trimem/
make install-python
```

We suggest the installation using the `--user` flag to `pip`. Alternatively,
we recommend to consider the usage of virtual environments to isolate the
installation of trimem, see, e.g., [here](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment).











### Dependencies


(Rest is CopyPaste from Trimem)
Trimem builds upon the generic mesh data structure
[OpenMesh](https://www.graphics.rwth-aachen.de/software/openmesh/), which
is included as a submodule that is pulled in upon `git clone` via the
Expand All @@ -39,6 +140,7 @@ automatically installed:
* scipy
* h5py
* meshio
* psutil

Documentation and tests further require:

Expand Down
Empty file added __init__.py
Empty file.
10 changes: 10 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
rm -rdf trimem.egg-info
rm -rdf cmake-build-debug
rm -rdf _skbuild/
rm -rdf src/trimem.egg-info
rm -rdf src/trimem/*.so
rm -rdf src/trimem/*.dylib
rm -rdf src/trimem/testd
rm -rdf src/trimem/__pycache__/
rm -rdf src/debug/testd
4 changes: 4 additions & 0 deletions copy_libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
cp _skbuild/*/cmake-build/Build/lib/* src/trimem/
cp _skbuild/*/cmake-build/*.so src/trimem/
cp _skbuild/*/cmake-build/*.dylib src/trimem/
27 changes: 27 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: trilmp
channels:
- conda-forge
dependencies:
- python==3.11
- scikit-build
- cmake
- pybind11
- pip

- numpy
- scipy
- h5py
- meshio
- trimesh
- psutil
- pytest
# - lammps #by default has no openmp package activated, so we build it.
# lammps reqs

- cmake
- make
- compilers
- mpich #mpi
- llvm-openmp


155 changes: 155 additions & 0 deletions examples/custom_interactions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@

import faulthandler
faulthandler.enable()


import trimesh
from trimem.core import TriMesh
import numpy as np
import pickle

from trimem.mc.trilmp import TriLmp, load_checkpoint



"""
In this example we want to highlight the option to define arbitrary bead-membrane and
bead-bead interactions using the setting for bead_int='custom' .
The membrane-membrane surface repulsion, necessary to avoid self-intersecting membranes
is implemented as a pair_style table/omp, created using the parameters used to initilize the TriLmp class.
To stay consistent with these one has to add additional interactions using hybrid or hybrid/overlay pairstyle.
A minimal example can be found in the definition of the set_repulsion() method of TriLmp:

pair_style hybrid lj/cut/omp 0.1 table/omp linear 2000
pair_coeff 1 1 table/omp trimem_srp.table trimem_srp
pair_modify pair table/omp special lj/coul 0.0 0.0 0.0
pair_coeff 2 2 lj/cut/omp 0.0 0.0
pair_coeff 1 2 lj/cut/omp 0.0 0.0

Which introduces additional to the surface repulsion via table/omp a lj/cut/omp pair style between beads and membranes.

As illustrative example for several fucionalities of TriLmp we want to simulate the following (unphysical) scenario:
Two beads of different size placed inside a spherical membrane of volume and area V and A. The reference values for the
Voulume is set 0.2*V_init leading to a apprupt shrinking of the membrane while overall area is more or less conserved.
To make the dynamics not to aprupt we set the coefficient for the volume control kappa_v=1e4 (in contrast to 1e6 being the stiff default).
The bead interacts with the membrane with a combination of a lj for the core and a longer-ranged repulsive harmonic potential.
The two beads repell each other with combination of lj and harmonic as well but relatively strong

To use the right size of the membrane beads we use the default size given bi 0.75*l with l being the average
distance in the initial configuration"""

# to get the avg distance we use a method from the Trimem shared libray
import trimesh
import trimem.core as m
from trimem.core import TriMesh
from trimem.mc.mesh import Mesh
import trimesh.creation

mesh = trimesh.creation.icosphere(5)
mesh.vertices=mesh.vertices*2
a, l = m.avg_tri_props(Mesh(points=mesh.vertices, cells=mesh.faces).trimesh)

sigma12=0.5*(1.0+0.75*l) # assuming a bead 1 of diameter 1
sigma13=0.5*(1.5+0.75*l) # assuming a bead 2 of diameter 1.5
sigma23=0.5*(1.5+1.0)

"""
By using the parameter bead_int='custom' the bead_int_params will be used as a command string.
Note that the parameter additonal_command could also be used to overwrite previous commands in the LAMMPS initialisation.
So to set the interactions we have to create a string block like the following
"""

custom_interactions=f"""
pair_style hybrid/overlay lj/cut/omp 1.0 harmonic/cut/omp table/omp linear 2000
pair_coeff 1 1 table/omp trimem_srp.table trimem_srp
pair_modify pair table/omp special lj/coul 0.0 0.0 0.0
pair_coeff 2 2 lj/cut/omp 0.0 0.0
pair_coeff 3 3 lj/cut/omp 0.0 0.0
pair_coeff 1 2 lj/cut/omp 1.5 {sigma12} {2.2*sigma12}
pair_coeff 1 3 lj/cut/omp 1.5 {sigma13} {2.2*sigma13}
pair_coeff 2 3 lj/cut/omp 1.0 {sigma23} {2.2*sigma23}
pair_coeff 1 2 harmonic/cut/omp 10 {2.2*sigma12}
pair_coeff 1 3 harmonic/cut/omp 10 {2.2*sigma13}

pair_coeff 1 1 harmonic/cut/omp 0.0 0.0
pair_coeff 2 2 harmonic/cut/omp 0.0 0.0
pair_coeff 3 3 harmonic/cut/omp 0.0 0.0

pair_coeff 2 3 harmonic/cut/omp 500.0 {4*sigma23}

"""


"""
Now we only have to initialize the TriLmp Class accordingly and use the .run() method
"""




trilmp=TriLmp(mesh_points=mesh.vertices, # input mesh
mesh_faces=mesh.faces,
initialize=True, # use mesh to initialize mesh reference
output_prefix='custom_trilmp', # prefix for output filenames
checkpoint_every=1000, # interval of checkpoints (alternating pickles)
thin=1, # write out
num_steps=5000, # number of steps in simulation (overwritten if trilmp.run(N=new_number)
info=0, # output hmc/flip info every ith step
performance_increment=10, # output performace stats to prefix_performance.dat file
energy_increment=1000, # output energies to energies.dat file
initial_temperature=1.0, # initial temperature -> for HMC
output_format='lammps_txt_folder', # choose different formats for 'lammps_txt', 'lammps_txt_folder' or 'h5_custom'
## <- this setting creates dict /lmp_trj

n_types=2,
bead_pos=np.asarray([[-1.49,0,0],[+1.23,0,0]]), # place bead inside membrane
bead_vel=None, # no intial velocity for beads
bead_sizes=(1.0,1.5), # diameter of bead
bead_int='custom', # use custom setting to overwrite existing settings
bead_int_params=custom_interactions,
bead_types=(2,3), # <- bead type for single particle (membrane -> type 1, beads type 2,3,....)
bead_masses=(1.0,1.0),
kappa_v=1e4, # make volume constraint less stiff
volume_frac=0.2, # set referrence value for membrane volume to 0.2*V0
kappa_c=0.0, # turn of constraint on mean curvature
box=(-5,5,-5,5,-5,5), # set box manually



thermal_velocities=False, # no reset of vel at start of MD traj
pure_MD=True, # no metropolis rsetting of positions
langevin_thermostat=True, # use langevin thermostat -> BD sim
langevin_damp=0.01, # damping
langevin_seed=1, # seed for BD
additional_command=None # here you could also add the custom_interactions
# but this parameter is intedend for manipulating/overwriting other lammps params
)

# create specific checkpoint to be used as e.g. as common starting point for different simulations
trilmp.make_checkpoint(force_name='test.cpt')

# load a checkpoint with a specific name -> otherwise load last checkpoint associated with output_prefix (see function definition in trilmp.py)
trilmp=load_checkpoint('test.cpt',alt='explicit')

trilmp.run()





















1 change: 1 addition & 0 deletions examples/example_2024/launch.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python source here "from pathlib import Path; exec(Path('launch.py').read_text())"
Loading