{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "py3Dmol\n", "=======\n", "\n", "A simple [IPython/Jupyter](http://jupyter.org/) widget to\n", "embed an interactive [3Dmol.js](http://3dmol.csb.pitt.edu) viewer in a notebook.\n", "\n", "The widget is completely static, which means the viewer doesn't need a running\n", "IPython kernel to be useful and web pages and presentations generated from\n", "the notebook will work as expected. However, this also means there is only\n", "one-way communication between the notebook and the viewer.\n", "\n", "Installation\n", "------------\n", "\n", "From PyPI:\n", "\n", " pip install py3Dmol\n", " \n", "API\n", "---\n", "\n", "The returned view object has the exact same API as [3Dmol.GLViewer](http://3dmol.csb.pitt.edu/doc/$3Dmol.GLViewer.html)\n", "with the exception that functions return None.\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import py3Dmol" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = py3Dmol.view(query='pdb:1ycr')\n", "p.setStyle({'cartoon': {'color':'spectrum'}})\n", "p.show()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "xyz = '''4\n", "* (null), Energy -1000.0000000\n", "N 0.000005 0.019779 -0.000003 -0.157114 0.000052 -0.012746\n", "H 0.931955 -0.364989 0.000003 1.507100 -0.601158 -0.004108\n", "H -0.465975 -0.364992 0.807088 0.283368 0.257996 -0.583024\n", "H -0.465979 -0.364991 -0.807088 0.392764 0.342436 0.764260\n", "'''" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xyzview = py3Dmol.view(width=400,height=400)\n", "xyzview.addModel(xyz,'xyz',{'vibrate': {'frames':10,'amplitude':1}})\n", "xyzview.setStyle({'stick':{}})\n", "xyzview.setBackgroundColor('0xeeeeee')\n", "xyzview.animate({'loop': 'backAndForth'})\n", "xyzview.zoomTo()\n", "xyzview.show()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "view = py3Dmol.view(query='pdb:1dc9')\n", "view.setViewStyle({'style':'outline','color':'black','width':0.1})\n", "view.setStyle({'cartoon':{'arrows':True, 'tubes':True, 'style':'oval', 'color':'white'}})\n", "view" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "view = py3Dmol.view(query='pdb:1ycr')\n", "chA = {'chain':'A'}\n", "chB = {'chain':'B'}\n", "view.setStyle(chA,{'cartoon': {'color':'spectrum'}})\n", "view.addSurface(py3Dmol.VDW,{'opacity':0.7,'color':'white'}, chA)\n", "view.setStyle(chB,{'stick':{}})\n", "view.show()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "view = py3Dmol.view(query='pdb:5ire',options={'doAssembly':True})\n", "view.setStyle({'cartoon':{'color':'spectrum'}})\n", "view" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" }, "widgets": { "state": {}, "version": "1.1.1" } }, "nbformat": 4, "nbformat_minor": 0 }