Interactive 3D molecular renderings

Interactive 3D molecular renderings are useful to visualize per-nucleotide and inter-nucleotide data on 3D models of RNA. Per-nucleotide data may be used to color nucleotides, and inter-nucleotide data may be drawn as cylinders that connect nucleotides through space.

These plots are interactive. Here are the controls:

  • scroll up/down to zoom in/out

  • click and drag to rotate

  • 3rd mouse button and drag to pan

[1]:
import rnavigate as rnav
from rnavigate.examples import rnasep_1, rnasep_2

plot = rnav.plot_mol(
    samples=[rnasep_1, rnasep_2],
    structure="pdb",
    profile="shapemap",
    colors="profile",
)

3Dmol.js failed to load for some reason. Please check your browser console for error messages.

[2]:
help(rnav.plot_mol)

Help on function plot_mol in module rnavigate.plotting_functions:

plot_mol(samples, structure, profile=None, interactions=None, labels=None, style='cartoon', hide_cylinders=False, colors='grey', atom="O2'", rotation=None, orientation=None, get_orientation=False, title=True, colorbars=True, width=400, height=400, rows=None, cols=None, background_alpha=1, show=True)
    Generates a multipanel interactive 3D molecular rendering of a PDB
    structure. Nucleotides may be colored by per-nucleotide data or custom
    color lists. Inter-nucleotide data may be displayed as cylinders connecting
    atoms or residues. Each plot may display a unique sample and/or filtering
    scheme.

    Parameters
    ----------
    samples : list of rnavigate Samples
        samples used to retrieve data
    structure : data keyword string or data object
        3D structure to view as interactive molecule
        All data are mapped to this sequence before plotting
    profile : data keyword string or data object, defaults to None
        Profile used to color nucleotides if colors="profile"
    interactions : one of the formats below, defaults to None
        format 1 (data or data keyword)
            Interactions to plot on molecule, no filtering performed
        format 2 (dictionary)
            e.g. {"interactions": format 1}
            additional filtering options can be added to the dictionary
        format 3 (list of format 2 dictionaries)
            This format allows multiple filtering schemes to be applied,
            each will be plotted on a seperate axis
    labels : list of strings, defaults to sample.sample for each sample
        list containing Labels to be used in plot titles
    style : "cartoon", "cross", "line", "sphere" or "stick", defaults to "cartoon"
        sets the py3Dmol style for drawing the molecule
    hide_cylinders : bool, defaults to False
        whether to hide nucleotide cylinders (only shows backbone ribbon)
    colors : string or list of colors, defaults to "grey"
        "sequence": color by nucleotide identity
        "position": color by position in sequence
        "annotations": color by sequence annotations from `annotations`
        "profile": color by per-nucleotide data from `profile`
        "structure": color by base-pairing status
        matplotlib color: all positions plotted in this color
        array of colors: one per position, must match structure length
    atom : string or dictionary, defaults to "O2'"
        which atoms to draw interactions between
        for DMS reactive atoms (N1 for A and G, N3 for U and C) use "DMS"
        use a dictionary to specify a different atom for each nucleotide
        e.g. "DMS" == {"A": "N1", "G": "N1", "U": "N3", "C": "N3"}.
    rotation : dictionary, defaults to {"x": 0, "y": 0, "z": 0}
        axis-degrees pairs for setting the starting orientation of the
        molecule, only the axes to be rotated are needed
        e.g. {"x": 180} flips the molecule on the x-axis
    orientation : list of 9 floats, defaults to None
        set the precise starting orientation
        see get_orientation for more details
    get_orientation : bool, defaults to False
        allows getting the orientation for use with orientation argument
        all other arguments will be ignored and a larger, single panel view
        window is displayed with no title
        1. adjust the molecule to the desired orientation
        2. click on the molecule to display the orientation vector
        3. copy this orientation vector (manually)
        4. provide this list of values to the orientation argument
    title : bool, defaults to True
        whether to display the title
    colorbars : bool, defaults to True
        Whether to plot color scales for all plot elements
    width : integer, defaults to 400
        width of view window in pixels
    height : integer, defaults to 400
        height of view window in pixels
    rows : integer, defaults to None (set automatically)
        the number of rows in the view window
    cols : integer, defaults to None (set automatically)
        the number of columns in the view window
    background_alpha : float, defaults to 1 (completely opaque)
        the opacity of the view window, must be between 0 and 1
    show : bool, defaults to True
        whether to display the viewer object

    Returns
    -------
    rnavigate.plots.Mol:
        object containing py3dmol viewer with additional plotting and file saving
        methods