{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Interactive 3D molecular renderings\n", "===================================\n", "\n", "Interactive 3D molecular renderings are useful to visualize per-nucleotide and\n", "inter-nucleotide data on 3D models of RNA. Per-nucleotide data may be used to\n", "color nucleotides, and inter-nucleotide data may be drawn as cylinders that\n", "connect nucleotides through space.\n", "\n", "These plots are interactive. Here are the controls:\n", "* scroll up/down to zoom in/out\n", "* click and drag to rotate\n", "* 3rd mouse button and drag to pan" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import rnavigate as rnav\n", "from rnavigate.examples import rnasep_1, rnasep_2\n", "\n", "plot = rnav.plot_mol(\n", " samples=[rnasep_1, rnasep_2],\n", " structure=\"pdb\",\n", " profile=\"shapemap\",\n", " colors=\"profile\",\n", ")\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on function plot_mol in module rnavigate.plotting_functions:\n", "\n", "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)\n", " Generates a multipanel interactive 3D molecular rendering of a PDB\n", " structure. Nucleotides may be colored by per-nucleotide data or custom\n", " color lists. Inter-nucleotide data may be displayed as cylinders connecting\n", " atoms or residues. Each plot may display a unique sample and/or filtering\n", " scheme.\n", " \n", " Parameters\n", " ----------\n", " samples : list of rnavigate Samples\n", " samples used to retrieve data\n", " structure : data keyword string or data object\n", " 3D structure to view as interactive molecule\n", " All data are mapped to this sequence before plotting\n", " profile : data keyword string or data object, defaults to None\n", " Profile used to color nucleotides if colors=\"profile\"\n", " interactions : one of the formats below, defaults to None\n", " format 1 (data or data keyword)\n", " Interactions to plot on molecule, no filtering performed\n", " format 2 (dictionary)\n", " e.g. {\"interactions\": format 1}\n", " additional filtering options can be added to the dictionary\n", " format 3 (list of format 2 dictionaries)\n", " This format allows multiple filtering schemes to be applied,\n", " each will be plotted on a seperate axis\n", " labels : list of strings, defaults to sample.sample for each sample\n", " list containing Labels to be used in plot titles\n", " style : \"cartoon\", \"cross\", \"line\", \"sphere\" or \"stick\", defaults to \"cartoon\"\n", " sets the py3Dmol style for drawing the molecule\n", " hide_cylinders : bool, defaults to False\n", " whether to hide nucleotide cylinders (only shows backbone ribbon)\n", " colors : string or list of colors, defaults to \"grey\"\n", " \"sequence\": color by nucleotide identity\n", " \"position\": color by position in sequence\n", " \"annotations\": color by sequence annotations from `annotations`\n", " \"profile\": color by per-nucleotide data from `profile`\n", " \"structure\": color by base-pairing status\n", " matplotlib color: all positions plotted in this color\n", " array of colors: a different color for each position\n", " must be the same length as structure\n", " atom : string or dictionary, defaults to \"O2'\"\n", " which atoms to draw interactions between\n", " for DMS reactive atoms (N1 for A and G, N3 for U and C) use \"DMS\"\n", " use a dictionary to specify a different atom for each nucleotide\n", " e.g. \"DMS\" == {\"A\": \"N1\", \"G\": \"N1\", \"U\": \"N3\", \"C\": \"N3\"}\n", " rotation : dictionary, defaults to {\"x\": 0, \"y\": 0, \"z\": 0}\n", " axis-degrees pairs for setting the starting orientation of the\n", " molecule, only the axes to be rotated are needed\n", " e.g. {\"x\": 180} flips the molecule on the x-axis\n", " orientation : list of 9 floats, defaults to None\n", " set the precise starting orientation\n", " see get_orientation for more details\n", " get_orientation : bool, defaults to False\n", " allows getting the orientation for use with orientation argument\n", " all other arguments will be ignored and a larger, single panel view\n", " window is displayed with no title\n", " 1. adjust the molecule to the desired orientation\n", " 2. click on the molecule to display the orientation vector\n", " 3. copy this orientation vector (manually)\n", " 4. provide this list of values to the orientation argument\n", " title : bool, defaults to True\n", " whether to display the title\n", " colorbars : bool, defaults to True\n", " Whether to plot color scales for all plot elements\n", " width : integer, defaults to 400\n", " width of view window in pixels\n", " height : integer, defaults to 400\n", " height of view window in pixels\n", " rows : integer, defaults to None (set automatically)\n", " the number of rows in the view window\n", " cols : integer, defaults to None (set automatically)\n", " the number of columns in the view window\n", " background_alpha : float, defaults to 1 (completely opaque)\n", " the opacity of the view window, must be between 0 and 1\n", " show : bool, defaults to True\n", " whether to display the viewer object\n", " \n", " Returns\n", " -------\n", " rnavigate.plots.Mol:\n", " object containing py3dmol viewer with additional plotting and file saving\n", " methods\n", "\n" ] } ], "source": [ "help(rnav.plot_mol)\n" ] } ], "metadata": { "kernelspec": { "display_name": "RNAvigate", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.2" } }, "nbformat": 4, "nbformat_minor": 2 }