{"id":3160,"date":"2016-10-20T19:25:04","date_gmt":"2016-10-20T18:25:04","guid":{"rendered":"http:\/\/www.blopig.com\/blog\/?p=3160"},"modified":"2016-12-13T16:19:07","modified_gmt":"2016-12-13T16:19:07","slug":"viewing-3d-molecules-interactively-in-jupyter-ipython-notebooks","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2016\/10\/viewing-3d-molecules-interactively-in-jupyter-ipython-notebooks\/","title":{"rendered":"Viewing 3D molecules interactively in Jupyter iPython notebooks"},"content":{"rendered":"<p><a href=\"https:\/\/plus.google.com\/+GregLandrum\">Greg Landrum<\/a>, curator of the invaluable open source cheminformatics API, <a href=\"http:\/\/rdkit.org\/\">RDKit<\/a>, <a href=\"http:\/\/rdkit.blogspot.co.uk\/2016\/07\/using-ipywidgets-and-py3dmol-to-browse.html\">recently blogged<\/a> about viewing molecules in a 3D window within a Jupyter-hosted iPython notebook (as long as your browser supports WebGL, that is).<\/p>\n<p>The trick is to use <code>py3Dmol<\/code>. It&#8217;s easy to install:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-linenumbers=\"false\">pip install py3Dmol<\/pre>\n<p>This is built on the&nbsp;object-oriented, webGL based JavaScript library for online molecular visualization <a href=\"https:\/\/3dmol.csb.pitt.edu\/\"><code>3Dmol.js<\/code><\/a><code> (Rego &amp; Koes, 2015); here's a nice summary of the <\/code><a href=\"https:\/\/3dmol.csb.pitt.edu\/doc\/index.html\">capabilities<\/a><a href=\"https:\/\/3dmol.csb.pitt.edu\/doc\/index.html\"> of 3Dmol.js<\/a><code>. It's features include:<br \/>\n<\/code><\/p>\n<ul>\n<li>support for pdb, sdf, mol2, xyz, and cube formats<\/li>\n<li>parallelized molecular surface computation<\/li>\n<li>sphere, stick, line, cross, cartoon, and surface styles<\/li>\n<li>atom property based selection and styling<\/li>\n<li>labels<\/li>\n<li>clickable interactivity with molecular data<\/li>\n<li>geometric shapes including spheres and arrows<\/li>\n<\/ul>\n<p>I tried a simple example and it worked beautifully:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-linenumbers=\"false\">import py3Dmol\r\nview = py3Dmol.view(query='pdb:1hvr')\r\nview.setStyle({'cartoon':{'color':'spectrum'}})\r\nview<\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2016\/10\/py3Dmol_in_Jupyter_iPython.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-3161\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2016\/10\/py3Dmol_in_Jupyter_iPython.png?resize=300%2C283&#038;ssl=1\" alt=\"py3dmol_in_jupyter_ipython\" width=\"300\" height=\"283\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2016\/10\/py3Dmol_in_Jupyter_iPython.png?resize=300%2C283&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2016\/10\/py3Dmol_in_Jupyter_iPython.png?resize=768%2C725&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2016\/10\/py3Dmol_in_Jupyter_iPython.png?resize=1024%2C967&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2016\/10\/py3Dmol_in_Jupyter_iPython.png?resize=624%2C589&amp;ssl=1 624w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2016\/10\/py3Dmol_in_Jupyter_iPython.png?w=1434&amp;ssl=1 1434w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2016\/10\/py3Dmol_in_Jupyter_iPython.png?w=1250&amp;ssl=1 1250w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The 3Dmol.js website summarizes <a href=\"https:\/\/3dmol.csb.pitt.edu\/doc\/tutorial-url.html\">how to view molecules<\/a>, along with how to choose representations, how to embed it, and even how to develop with it.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>References<\/strong><\/span><\/p>\n<p>Nicholas Rego &amp; David Koes (2015). &#8220;3Dmol.js: molecular visualization with WebGL&#8221;.<br \/>\n<em>Bioinformatics,<\/em> <strong>31<\/strong> (8): 1322-1324. <a href=\"http:\/\/doi.org\/10.1093\/bioinformatics\/btu829\">doi:10.1093\/bioinformatics\/btu829<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Greg Landrum, curator of the invaluable open source cheminformatics API, RDKit, recently blogged about viewing molecules in a 3D window within a Jupyter-hosted iPython notebook (as long as your browser supports WebGL, that is). The trick is to use py3Dmol. It&#8217;s easy to install: pip install py3Dmol This is built on the&nbsp;object-oriented, webGL based JavaScript [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29,14,15],"tags":[157,153,156,154,133,158,152,129,155],"ppma_author":[488],"class_list":["post-3160","post","type-post","status-publish","format-standard","hentry","category-code","category-howto","category-technical","tag-3dmol-js","tag-ipython","tag-javascript","tag-jupyter","tag-molecular-graphics","tag-py3dmol","tag-python","tag-rdkit","tag-webgl"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":488,"user_id":35,"is_guest":0,"slug":"garrett","display_name":"Garrett","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/df625261419c37dd5c5937e37f17a732626acd6eea1e6fabd03d935c25b453bf?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/3160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=3160"}],"version-history":[{"count":3,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/3160\/revisions"}],"predecessor-version":[{"id":5004,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/3160\/revisions\/5004"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=3160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=3160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=3160"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=3160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}