Secondary-structure topology diagrams

Secondary-structure topology diagrams#

Portein runs DSSP to assign each residue to a secondary-structure element (SSE), then draws each element with a parameterized glyph:

  • helices as either waves or cylinders (toggle via portein.HelixConfig’s as_cylinder)

  • β-strands as arrows

  • turns as arcs joined by circles

Adapted from this gist.

import tempfile
from pathlib import Path

import matplotlib.pyplot as plt

import portein

output_dir = Path(tempfile.mkdtemp())

Default topology#

protein_config = portein.ProteinConfig(
    pdb_file="../_data/7lc2.pdb",
    rotate=True,
    width=1000,
    output_prefix=str(output_dir / "secondary_structure"),
)
pss = portein.SecondaryStructure(
    protein_config=protein_config,
    helix_config=portein.HelixConfig(),
    sheet_config=portein.SheetConfig(),
    turn_config=portein.TurnConfig(),
    dpi=100,
)
pss.run();
/home/runner/work/portein/portein/portein/rotate.py:23: NumbaPerformanceWarning: np.dot() is faster on contiguous arrays, called on (Array(float64, 1, 'A', False, aligned=True), Array(float64, 1, 'A', False, aligned=True))
  m = find_best_projection(coords)
/home/runner/work/portein/portein/portein/rotate.py:23: NumbaPerformanceWarning: np.dot() is faster on contiguous arrays, called on (Array(float64, 2, 'C', False, aligned=True), Array(float64, 1, 'A', False, aligned=True))
  m = find_best_projection(coords)
/home/runner/work/portein/portein/portein/rotate.py:28: NumbaPerformanceWarning: np.dot() is faster on contiguous arrays, called on (Array(float64, 2, 'A', False, aligned=True), Array(float64, 2, 'F', False, aligned=True))
  matrix = rotate_to_maximize_bb_height(coords[:, :2]) @ matrix
../_images/8f53f8802e240de1060a3dfa5d446e53eb4cfb54b8dfd1ef7f468571fb9e02bd.png

Highlight specific residues#

SecondaryStructure.run() returns a Matplotlib Axes — overlay any matplotlib primitive on top.

ax = pss.run()
ax.set_title("Portrait of PDB ID: 7lc2", fontsize=20)
highlight_residues = [30, 35, 25, 10, 11, 12, 13, 14, 15]
ax.scatter(
    pss.coords[highlight_residues, 0],
    pss.coords[highlight_residues, 1],
    color="red",
    s=100,
    edgecolor="black",
    linewidth=2,
);
../_images/c23b7b5e008efeb58fdfd5cba5bea34b57e0b4e12e19e87fe4386279fc10b060.png

Linear diagram#

Pass linear=True for a single-row strip — useful as a header band on top of a sequence alignment or a per-residue plot.

fig, ax = plt.subplots(1, figsize=(50, 1))
pss.run(ax=ax, linear=True);
../_images/5d6f49b335f7f413ce6c10689b57fc249749de409b2cd494869ac4a68ec6e4ea.png

From the command line#

portein secondary 7lc2

-h, -s, -t accept YAML config files for helix, sheet, and turn parameters. See configs/ in the repo for examples.