{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Importing Structures\n", "This tutorial demonstrates how to visualize 3D structures using the [py3Dmol](http://3dmol.csb.pitt.edu/index.html) Jupyter Notebook widget. Here we show how to download structures from the PDB as well as read local structure files.\n", "\n", "3Dmol.js: molecular visualization with WebGL, N. Rego, D. Koes, [Bioinformatics (2015) 31, 1322–1324](https://doi.org/10.1093/bioinformatics/btu829)\n", "\n", "Also, check out the [py3Dmol tutorial](http://nbviewer.jupyter.org/github/3dmol/3Dmol.js/blob/9050b97144e81f065df7eecc87ba9a16723ab14b/py3Dmol/examples.ipynb) for additional features." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import py3Dmol" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download a structure from the RCSB Protein Data Bank\n", "py3Dmol downloads PDB structures using the [compressed](http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0174846) binary [MMTF file format](https://doi.org/10.1371/journal.pcbi.1005575) from https://mmtf.rcsb.org. Prepend the 'pdb:\" prefix to the 4-letter PDB ID.\n", "\n", "Downloading PDB structures in MMTF format has the following advantages:\n", "* Very large structures are downloaded efficiently\n", "* Molecules contain bond order information\n", "* DSSP secondary structure has been recalculated for consistency" ] }, { "cell_type": "code", "execution_count": 2, "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": [ "viewer = py3Dmol.view(query='pdb:5MXB')\n", "\n", "# setting styles will be covered in the next tutorial\n", "viewer.setStyle({'cartoon': {'color': 'spectrum'}})\n", "viewer.setStyle({'hetflag': True}, {'stick':{'radius': 0.3, 'singleBond': False}})\n", "viewer.zoomTo()\n", "viewer.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Import a structure from a local file\n", "[List of supported file formats](http://3dmol.csb.pitt.edu/doc/types.html#FileFormats)\n", "\n", "A disadvantage of reading local PDB files is the absence of bond order information. Compare the small molecules below with the downloaded version above." ] }, { "cell_type": "code", "execution_count": 3, "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": [ "structure = open('5mxb.pdb','r').read()\n", "viewer = py3Dmol.view()\n", "viewer.addModel(structure,'pdb')\n", "\n", "viewer.setStyle({'cartoon': {'color': 'spectrum'}})\n", "viewer.setStyle({'hetflag': True}, {'stick':{'radius': 0.3, 'singleBond': False}})\n", "viewer.zoomTo()\n", "viewer.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.7" } }, "nbformat": 4, "nbformat_minor": 2 }