{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "py3Dmol - in place updates\n", "=======\n", "\n", "Per @dr_greg_landrum's request, support updating an already existing viewer in-place.\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 7, "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 py3Dmol\n", "\n", "benz='''\n", " RDKit 3D\n", "\n", " 6 6 0 0 0 0 0 0 0 0999 V2000\n", " -0.9517 0.7811 -0.6622 C 0 0 0 0 0 0 0 0 0 0 0 0\n", " 0.2847 1.3329 -0.3121 C 0 0 0 0 0 0 0 0 0 0 0 0\n", " 1.2365 0.5518 0.3512 C 0 0 0 0 0 0 0 0 0 0 0 0\n", " 0.9517 -0.7811 0.6644 C 0 0 0 0 0 0 0 0 0 0 0 0\n", " -0.2847 -1.3329 0.3144 C 0 0 0 0 0 0 0 0 0 0 0 0\n", " -1.2365 -0.5518 -0.3489 C 0 0 0 0 0 0 0 0 0 0 0 0\n", " 1 2 2 0\n", " 2 3 1 0\n", " 3 4 2 0\n", " 4 5 1 0\n", " 5 6 2 0\n", " 6 1 1 0\n", "M END\n", "$$$$'''\n", "view = py3Dmol.view()\n", "view.addModel(benz,'sdf')\n", "view.setStyle({'stick':{}})\n", "view.zoomTo()\n", "view.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "view.setStyle({'stick':{'color':'blue'}})\n", "view.update()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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", "'''\n", "view.addModel(xyz,'xyz',{'vibrate': {'frames':10,'amplitude':1}})\n", "view.setStyle({'model':1},{'stick':{}})\n", "view.setBackgroundColor('0xeeeeee')\n", "view.animate({'loop': 'backAndForth'})\n", "view.zoomTo()\n", "view.update()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "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.8.10" } }, "nbformat": 4, "nbformat_minor": 1 }