From 366c6f06d2e4c981e6ba4afbdb93da641d540ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Chaves?= Date: Mon, 9 Dec 2024 13:13:33 +0100 Subject: [PATCH 1/5] Add Rust to dev setup --- AUTHORS.rst | 1 + CONTRIBUTING.rst | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index cea33ad..127d9e3 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -10,3 +10,4 @@ Authors (chronological) * Paul Smith * Raquel Lopez-Rios * David Goh +* Rubén Chaves diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 9f500d6..624d76e 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -42,35 +42,40 @@ To set up `lipyphilic` for local development: conda create -n lipyphilic-dev -c conda-forge python=3.10 pip conda activate lipyphilic-dev -2. Fork `lipyphilic `_ +2. Install and activate Rust:: + + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + source $HOME/.cargo/env + +3. Fork `lipyphilic `_ (look for the "Fork" button). -3. Clone your fork locally:: +4. Clone your fork locally:: git clone git@github.com:YOURGITHUBNAME/lipyphilic.git -4. Install an editible version of `lipyphilic` along with its development dependencies: +5. Install an editible version of `lipyphilic` along with its development dependencies: cd lipyphilic python -m pip install -e ".[dev]" -4. Create a branch for local development:: +6. Create a branch for local development:: git checkout -b name-of-your-bugfix-or-feature Now you can make your changes locally. -5. When you're done making changes run all the checks and docs builder with `tox `_ one command:: +7. When you're done making changes run all the checks and docs builder with `tox `_ one command:: tox -6. Commit your changes and push your branch to GitHub:: +8. Commit your changes and push your branch to GitHub:: git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature -7. Submit a pull request through the GitHub website. +9. Submit a pull request through the GitHub website. Pull Request Guidelines ----------------------- From bfdda89195d66a0c37af4da6155a8be434388f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Chaves?= Date: Mon, 9 Dec 2024 13:13:55 +0100 Subject: [PATCH 2/5] Add doc #143 --- src/lipyphilic/analysis/memb_thickness.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lipyphilic/analysis/memb_thickness.py b/src/lipyphilic/analysis/memb_thickness.py index ac9834d..83ab30b 100644 --- a/src/lipyphilic/analysis/memb_thickness.py +++ b/src/lipyphilic/analysis/memb_thickness.py @@ -169,7 +169,8 @@ def __init__(self, universe, lipid_sel, leaflets, n_bins=1, interpolate=False, r of higher-resolution grids. The default is False. return_surface : bool, optional If True, the height of the bilayer at grid point at each frame is returned as - numpy ndarray. The default is False. + numpy ndarray. The 2D grid will be stored in self.memb_thickness_grid. The + default is False. Tip --- From 6da77c181fda4f2c5151f8ef4c080530a83f9e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Chaves?= Date: Mon, 9 Dec 2024 16:43:32 +0100 Subject: [PATCH 3/5] Fix error with return_surface=True and n_bins=1 --- src/lipyphilic/analysis/memb_thickness.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lipyphilic/analysis/memb_thickness.py b/src/lipyphilic/analysis/memb_thickness.py index 83ab30b..7979f37 100644 --- a/src/lipyphilic/analysis/memb_thickness.py +++ b/src/lipyphilic/analysis/memb_thickness.py @@ -285,7 +285,7 @@ def _single_frame(self): self.results.memb_thickness[self._frame_index] = thickness if self._return_surface: - self.memb_thickness_grid[self._frame_index] = upper_surface - lower_surface + self.memb_thickness_grid[self._frame_index] = upper_surface - lower_surface if self.n_bins > 1 else thickness def _interpolate(self, surface): """Interpolate the leaflet intrinsic surface. From cd52b8229127b84aa324bb3b67035895e2fd5ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Chaves?= Date: Mon, 9 Dec 2024 16:45:04 +0100 Subject: [PATCH 4/5] mean of the values that are not nan instead of colapsing to nan --- src/lipyphilic/analysis/memb_thickness.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lipyphilic/analysis/memb_thickness.py b/src/lipyphilic/analysis/memb_thickness.py index 7979f37..18e685f 100644 --- a/src/lipyphilic/analysis/memb_thickness.py +++ b/src/lipyphilic/analysis/memb_thickness.py @@ -277,7 +277,7 @@ def _single_frame(self): lower_surface = self._interpolate(lower_surface) thickness = ( - np.mean(upper_surface - lower_surface) + np.nanmean(upper_surface - lower_surface) if self.n_bins > 1 else (upper_surface - lower_surface)[0, 0] ) From 2882db5c6708ccb5a8bb3e0ed89af867c421dfdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Chaves?= Date: Mon, 9 Dec 2024 16:47:02 +0100 Subject: [PATCH 5/5] Add return_midpoint --- src/lipyphilic/analysis/z_positions.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lipyphilic/analysis/z_positions.py b/src/lipyphilic/analysis/z_positions.py index 3481f25..53f80db 100644 --- a/src/lipyphilic/analysis/z_positions.py +++ b/src/lipyphilic/analysis/z_positions.py @@ -136,7 +136,7 @@ class ZPositions(AnalysisBase): """Calculate the :math:`z` position of molecules in a bilayer.""" - def __init__(self, universe, lipid_sel, height_sel, n_bins=1): + def __init__(self, universe, lipid_sel, height_sel, n_bins=1, return_midpoint=False): """Set up parameters for calculating :math:`z` positions. Parameters @@ -155,6 +155,9 @@ def __init__(self, universe, lipid_sel, height_sel, n_bins=1): positions calculated based on the distance to their local membrane midpoint. The default is `1`, which is equivalent to computing a single global midpoint. + return_midpoint : bool, optional + If True, the height of the midpoint at grid point at each frame is returned as + numpy ndarray. The 2D grid will be stored in self.memb_midpoint. The default is False. Note ---- @@ -185,6 +188,7 @@ def __init__(self, universe, lipid_sel, height_sel, n_bins=1): self.n_bins = n_bins self.results.z_positions = None + self._return_midpoint = return_midpoint @property def z_positions(self): @@ -197,6 +201,11 @@ def _prepare(self): fill_value=np.NaN, ) + if self._return_midpoint: + self.memb_midpoint = np.full( + (self.n_frames, self.n_bins, self.n_bins), + fill_value=np.NaN) + def _single_frame(self): # Atoms must be wrapped before creating a lateral grid of the membrane self.membrane.wrap(inplace=True) @@ -221,6 +230,8 @@ def _single_frame(self): bins=(x_bins, y_bins), expand_binnumbers=True, ) + if self._return_midpoint: + self.memb_midpoint[self._frame_index] = memb_midpoint_xy.statistic if self.n_bins > 1 else memb_midpoint_xy.statistic[0, 0] # The height in z of each lipid is calculated as the mean heigh # of its selected atoms