Interactive Visualisation with Plotly

Graphein provides several visualisation utilities for interacting with protein structure graphs.

Visualisation API Reference

Open In Colab

[1]:
# Install Graphein if necessary
# !pip install graphein
[14]:
import logging
logging.getLogger('graphein').setLevel(logging.INFO)
logging.getLogger('matplotlib').setLevel(logging.INFO)

Creating graphs

First, we’ll create two graphs to work with based on PDB: 3EIY: a simple_graph (\(C\alpha\) backbone with peptide bonds) and a complex_graph (\(C\alpha\) backbone with peptide bonds, hydrogen bonds and ionic interactions).

[4]:
INFO:graphein.protein.edges.distance:Found 75 hbond interactions.
INFO:graphein.protein.edges.distance:Found 7 hbond interactions.
INFO:graphein.protein.edges.distance:Found 1308 ionic interactions.

Distance Matrix and Contact Map

Distance matrices are a representation of protein structure. They take the form of an \(N \times N\) matrix, where \(N\) is, typically, the length of the sequence. The entries of the matrix correspond to the euclidean distance (in Å) between the residues. Distance matrices are also computable for atom-level graphs, though these are of course much larger.

Distance matrices and contact maps can be visualised with `plot_distance_matrix() <https://graphein.ai/modules/graphein.protein.html#graphein.protein.visualisation.plot_distance_matrix>`__

One can construct a contact map by thresholding the distance matrix to some arbirary distance (10 Å in our example).

[6]:
contact_map = (simple_graph.graph["dist_mat"] > 10).astype(int) # Threshold distance matrix
plot_distance_matrix(g=simple_graph, dist_mat=contact_map) # Plot contact map

Distance Landscape

We can also visualise the distance matrix as a landscape in 3D using `plot_distance_landscape() <https://graphein.ai/modules/graphein.protein.html#graphein.protein.visualisation.plot_distance_landscape>`__. In this plot, the distance is represented by both the colour and the height of the peaks.

Plot 3D Structure

Graphein provides two main ways of visualising protein graph structures. These are based on plotly (interactive) and matplotlib (static).

Interactive

Interactive visualisation can be performed by using `plotly_protein_structure_graph() <https://graphein.ai/modules/graphein.protein.html#graphein.protein.visualisation.plotly_protein_structure_graph>`__

Parameters

G: nx.Graph,
plot_title: Optional[str] = None,
figsize: Tuple[int, int] = (620, 650),
node_alpha: float = 0.7,
node_size_min: float = 20.0,
node_size_multiplier: float = 20.0,
label_node_ids: bool = True,
node_colour_map=plt.cm.plasma,
edge_color_map=plt.cm.plasma,
colour_nodes_by: str = "degree",
colour_edges_by: str = "type",
edge_alpha: float = 0.5,

Plots

[8]:
from graphein.protein.visualisation import plotly_protein_structure_graph

plotly_protein_structure_graph(
    G=simple_graph,
    plot_title="Simple Protein Structure (Backbone only)",
    colour_nodes_by="residue_number",
    colour_edges_by="kind",
    node_size_min=1
    )
[9]:
from graphein.protein.visualisation import plotly_protein_structure_graph

plotly_protein_structure_graph(
    G=complex_graph,
    plot_title="Residue level graph with Hydrogen bonds, ionic interactions and peptide bonds",
    colour_nodes_by="residue_number",
    colour_edges_by="kind",
    node_size_min=20,
    node_size_multiplier=1
    )

Atom-level Plots

We can also plot atomic graphs of protein structures in exactly the same way.

[10]:
from graphein.protein.edges.atomic import add_atomic_edges
config = ProteinGraphConfig(granularity='atom', edge_construction_functions=[add_atomic_edges])
g = construct_graph(config, pdb_code="3eiy")

# Create atomic graph
plotly_protein_structure_graph(
    g,
    plot_title="Atom level graph",
    colour_nodes_by="atom_type",
    colour_edges_by="kind",
    node_size_min=10,
    node_size_multiplier=1
    )