Skip to main content
Ctrl+K
Biotite - Home
  • Tutorial
  • Installation
  • API Reference
  • Examples
  • Extensions
  • Contributor guide
  • Logo
  • GitHub
  • PyPI
  • News
  • Tutorial
  • Installation
  • API Reference
  • Examples
  • Extensions
  • Contributor guide
  • Logo
  • GitHub
  • PyPI
  • News

Section Navigation

  • Sequence examples
    • Homology and alignment
      • Pairwise sequence alignment of protein sequences
      • Customized visualization of a multiple sequence alignment
      • Finding homologous regions in two genomes
      • Finding homologs of a gene in a genome
      • Phylogenetic tree of a protein family
      • Hydropathy and conservation of ion channels
      • Dendrogram of a protein family
      • Homology search and multiple sequence alignment
      • Conservation of binding site
      • Fetching and aligning a protein from different species
      • Display sequence similarity in a heat map
      • Plot epitope mapping data onto protein sequence alignments
      • Mutual information as measure for coevolution of residues
      • Polymorphisms in a gene
    • Sequence read quality control and mapping
      • Quantifying gene expression from RNA-seq data
      • Comparative genome assembly
      • Quality control of sequencing data
      • Quality of sequence reads
    • Sequence profiles
      • Sequence logo of sequences with equal length
      • Identification of a binding site by sequence conservation
    • Features and annotations
      • Feature map of a synthetic operon
      • Plasmid map of a vector
      • Visualization of a custom plasmid
      • Visualization of a region in proximity to a feature
      • Domains of bacterial sigma factors
    • Miscellaneous
      • Dendrogram of a substitution matrix
      • Calculation of codon usage
      • Biotite color schemes
      • Biotite color schemes for protein sequences
      • Statistics of local alignments and the E-value
      • Identification of potential open reading frames
  • Structure examples
    • Protein backbone and secondary structure
      • Assembly of a straight peptide from sequence
      • Ramachandran plot of dynein motor domain
      • Determination of amino acid enantiomers
      • Arrangement of beta-sheets
      • Three ways to get the secondary structure of a protein
    • Nucleic acid base pairs and secondary structure
      • Plotting the base pairs of a tRNA-like-structure
      • Leontis-Westhof Nomenclature
      • Comparison of a tRNA-like-structure with a tRNA
      • Visualization of Watson-Crick base pairs
    • Small molecules
      • Enumeration of alkane isomers
      • Molecular visualization of a small molecule using Matplotlib
      • Partial charge distribution
    • Proximity and contacts
      • Construction of an adjacency matrix
      • Contact sites of protein-DNA interaction
      • Detection of disulfide bonds
      • Hydrogen bonds between protein domains
      • Identification of lipid bilayer leaflets
    • Molecular dynamics and docking
      • Docking a ligand to a receptor
      • Basic analysis of a MD simulation
      • BinaryCIF as trajectory format
      • LDDT for predicted structure evaluation
      • Visualization of normal modes from an elastic network model
      • Creation of an amino acid rotamer library
      • Analysis of solvation shells
      • Secondary structure during an MD simulation
      • Cavity solvation in different states of an ion channel
    • Structural alphabets
      • Multiple Structural alignment of orthologous proteins
      • Searching for structural homologs in a protein structure database
    • Miscellaneous
      • Biological assembly of a structure
      • Calculation of protein diameter
      • Identifying unresolved regions in protein structures
      • Visualization of glycosylated amino acids
      • Superimposition of homologous protein structures
      • Annual releases of PDB structures
  • Examples
  • Proximity and contacts
  • Identificati...

Note

Go to the end to download the full example code.

Identification of lipid bilayer leaflets#

This script implements the LeafletFinder algorithm [1] used by MDAnalysis. The algorithm detects which lipid molecules belong to the same membrane leaflet, i.e. the same side of a lipid bilayer, irrespective of the shape of the bilayer.

At first the algorithm creates an adjacency matrix of all lipid head groups, where the cutoff distance is smaller than the minimum distance between a head group of one leaflet to a head group of another leaflet. A graph is created from the matrix. Each leaflet is a connected subgraph.

[1]

N. {Michaud-Agrawal}, E. J. Denning, T. B. Woolf, O. Beckstein, “MDAnalysis: A toolkit for the analysis of molecular dynamics simulations,” Journal of Computational Chemistry, vol. 32, pp. 2319–2327, 2011. doi: 10.1002/jcc.21787

leaflet
/home/runner/miniconda3/envs/test/lib/python3.12/site-packages/biotite/interface/pymol/convert.py:107: LossyConversionWarning: The following bond types could not be mapped to PyMOL: ANY
  warnings.warn(

# Code source: Patrick Kunzmann
# License: BSD 3 clause

import warnings
from tempfile import NamedTemporaryFile
import networkx as nx
import numpy as np
import biotite.interface.pymol as pymol_interface
import biotite.structure as struc
import biotite.structure.io as strucio

# The bilayer structure file can be downloaded from
# http://www.charmm-gui.org/archive/pure_bilayer/dppc.tar.gz
PDB_FILE_PATH = "../../../download/dppc_n128.pdb"


def find_leaflets(structure, head_atom_mask, cutoff_distance=15.0, periodic=False):
    """
    Identify which lipids molecules belong to the same lipid bilayer
    leaflet.

    Parameters
    ----------
    structure : AtomArray, shape=(n,)
        The structure containing the membrane.
        May also include other molecules, e.g. water or an embedded
        protein.
    head_atom_mask : ndarray, dtype=bool, shape=(n,)
        A boolean mask that selects atoms from `structure` that
        represent lipid head groups.
    cutoff_distance : float, optional
        When the distance of two head groups is larger than this value,
        they are not (directly) connected in the same leaflet.
    periodic : bool, optional,
        If true, periodic boundary conditions are considered.
        This requires that `structure` has an associated `box`.

    Returns
    -------
    leaflets : ndarray, dtype=bool, shape=(m,n)
        Multiple boolean masks, one for each identified leaflet.
        Each masks indicates which atoms of the input `structure`
        are in the leaflet.
    """

    cell_list = struc.CellList(
        structure,
        cell_size=cutoff_distance,
        selection=head_atom_mask,
        periodic=periodic,
    )
    adjacency_matrix = cell_list.create_adjacency_matrix(cutoff_distance)
    graph = nx.Graph(adjacency_matrix)

    head_leaflets = [
        sorted(c)
        for c in nx.connected_components(graph)
        # A leaflet cannot consist of a single lipid
        # This also removes all entries
        # for atoms not in 'head_atom_mask'
        if len(c) > 1
    ]

    # 'leaflets' contains indices to head atoms
    # Broadcast each head atom index to all atoms in its corresponding
    # residue
    leaflet_masks = np.empty((len(head_leaflets), structure.array_length()), dtype=bool)
    for i, head_leaflet in enumerate(head_leaflets):
        leaflet_masks[i] = struc.get_residue_masks(structure, head_leaflet).any(axis=0)
    return leaflet_masks


# Suppress warning that elements were guessed,
# as this PDB file omits the 'chemical element' column
with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    structure = strucio.load_structure(PDB_FILE_PATH)
# We cannot go over periodic boundaries in this case,
# because the input PDB does not define a box -> periodic=False
# However, as we have a planer lipid bilayer,
# periodicity should not matter
leaflets = find_leaflets(
    structure,
    head_atom_mask=(structure.res_name == "DPP") & (structure.atom_name == "P"),
)
# Bilayer -> Expect two leaflets
assert len(leaflets) == 2
# Mark leaflets using different chain IDs
for chain_id, leaflet_mask in zip(("A", "B"), leaflets):
    structure.chain_id[leaflet_mask] = chain_id

# Save marked lipids to structure file
temp = NamedTemporaryFile(suffix=".pdb")
strucio.save_structure(temp.name, structure)
temp.close()


# Visualization with PyMOL
pymol_interface.cmd.set("sphere_scale", 1.5)
# Remove hydrogen and water
structure = structure[(structure.element != "H") & (structure.res_name != "TIP")]
structure.bonds = struc.connect_via_distances(structure)
pymol_obj = pymol_interface.PyMOLObject.from_structure(structure)
# Configure lipid tails
pymol_obj.color("biotite_lightgreen", structure.chain_id == "A")
pymol_obj.color("biotite_brightorange", structure.chain_id == "B")
pymol_obj.show("sticks", np.isin(structure.chain_id, ("A", "B")))
# Configure lipid heads
pymol_obj.color(
    "biotite_darkgreen", (structure.chain_id == "A") & (structure.atom_name == "P")
)
pymol_obj.color(
    "biotite_dimorange", (structure.chain_id == "B") & (structure.atom_name == "P")
)
pymol_obj.show(
    "spheres", np.isin(structure.chain_id, ("A", "B")) & (structure.atom_name == "P")
)
# Adjust camera
pymol_obj.orient()
pymol_interface.cmd.turn("x", 90)
pymol_obj.zoom(buffer=-10)
# Display
pymol_interface.show((1500, 1000))

Download Jupyter notebook: leaflet.ipynb

Download Python source code: leaflet.py

Download zipped: leaflet.zip

Gallery generated by Sphinx-Gallery

Edit on GitHub
Show Source

© Copyright The Biotite contributors.

Created using Sphinx 8.2.3.

Built with the PyData Sphinx Theme 0.15.4.