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

Fixes #143, return_surface and return_midpoint #146

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Authors (chronological)
* Paul Smith
* Raquel Lopez-Rios
* David Goh
* Rubén Chaves
19 changes: 12 additions & 7 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/p-j-smith/lipyphilic>`_
2. Install and activate Rust::

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

3. Fork `lipyphilic <https://github.com/p-j-smith/lipyphilic>`_
(look for the "Fork" button).

3. Clone your fork locally::
4. Clone your fork locally::

git clone [email protected]: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 <https://tox.readthedocs.io/en/latest/install.html>`_ one command::
7. When you're done making changes run all the checks and docs builder with `tox <https://tox.readthedocs.io/en/latest/install.html>`_ 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
-----------------------
Expand Down
7 changes: 4 additions & 3 deletions src/lipyphilic/analysis/memb_thickness.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down Expand Up @@ -276,15 +277,15 @@ 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]
)

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.
Expand Down
13 changes: 12 additions & 1 deletion src/lipyphilic/analysis/z_positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
----
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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
Expand Down