Lipid z positions — lipyphilic.lib.z_positions


Paul Smith




GNU Public License v2

This module provides methods for calculating the distance in \(z\) of lipids to the bilayer center.

The class lipyphilic.lib.z_position.ZPositions assigns the membrane midpoint to be at \(z = 0\) Lipids in the upper leaflet will have positive \(z\) values and those in the lower leaflet will have negative \(z\) values.


  • universe : an MDAnalysis Universe object

  • lipid_sel : atom selection for all lipids in the bilayer

  • height_sel : atom selection for the molecules for which the \(z\) position will be calculated

  • n_bins : split the membrane into n_bins * n_bins patches, and calculate local membrane midpoints for each patch


  • z_position : height in \(z\) of each selected molecule in the bilayer

The \(z\) positions data are returned in a numpy.ndarray, where each row corresponds to an individual molecule and each column corresponds to an individual frame.

Example usage of ZPositions

An MDAnalysis Universe must first be created before using ZPositions:

import MDAnalysis as mda
from lipyphilic.lib.z_positions import ZPositions

u = mda.Universe(tpr, trajectory)

If we have used the MARTINI forcefield to study a phospholipid/cholesterol mixture, we can calculate the height of cholesterol in the bilayer as follows:

z_positions = ZPositions(
  lipid_sel="name GL1 GL2 ROH",
  height_sel="name ROH"

lipid_sel is an atom selection that covers all lipids in the bilayer. This is used for calculating the membrane midpoint. height_sel selects which atoms to use for caclulating the height of each each molecule.


In the above example we are calculating the height of cholesterol in the bilayer, although the height of any molecule - even those not in the bilayer, such as peptides - can be calculated instead.

We then select which frames of the trajectory to analyse (None will use every frame) and choose to display a progress bar (verbose=True):

The results are then available in the z_positions.z_positions attribute as a numpy.ndarray. The array has the shape (n_residues, n_frames). Each row corresponds to an individual molecule and each column to an individual frame. The height is signed (not absolute) — positive and negative values correspond to the molecule being in the upper of lower leaflet respecitvely.

\(z\) positions based on local membrane midpoints

The first example computes a global membrane midpoint based on all the atoms of the lipids in the membrane. \(z\) positions are then calculated as the distance to this midpoint. This is okay for planar bilayers, but can lead to inaccurate results in membranes with undulations. If your bilayer has undulations, ZPositions can account for this by creating a grid in \(xy\) of your membrane, calculating the local membrane midpoint in each patch, then find the distance of each molecule to its local midpoint. This is done through use of n_bins:

z_positions = ZPositions(
  lipid_sel="name GL1 GL2 ROH",
  height_sel="name ROH"

In this example, the membrane will be split into a 10 x 10 grid and a lipid \(z\) positions calculated based on the distance to the midpoint of the patch the molecule is in.


Using n_bins can account for small undulations. However, if you have large unulations in your bilayer the calculated height will be inaccurate.

The class and its methods

class lipyphilic.lib.z_positions.ZPositions(universe, lipid_sel, height_sel, n_bins=1)[source]

Calculate the \(z\) position of molecules in a bilayer.

Set up parameters for calculating \(z\) positions.

  • universe (Universe) – MDAnalysis Universe object

  • lipid_sel (str) – Selection string for the lipids in a membrane. Atoms in this selection are used for calculating membrane midpoints.

  • height_sel (str) – Selection string for molecules for which the height in \(z\) will be calculated. Any residues not in this selection will not have their \(z\) positions calculated.

  • n_bins (int, optional) – Number of bins in x and y to use to create a grid of membrane patches. Local membrane midpoints are computed for each patch, and lipid \(z\) positions calculated based on the distance to their local membrane midpoint. The default is 1, which is equivalent to computing a single global midpoint.


height_sel must be a subset of lipid_sel