{"id":265,"date":"2020-05-18T02:05:07","date_gmt":"2020-05-18T02:05:07","guid":{"rendered":"https:\/\/leedavies.dev\/?p=265"},"modified":"2020-05-18T02:05:07","modified_gmt":"2020-05-18T02:05:07","slug":"protein-visualization-in-vscode","status":"publish","type":"post","link":"https:\/\/leedavies.dev\/index.php\/2020\/05\/18\/protein-visualization-in-vscode\/","title":{"rendered":"Protein Visualization in VSCode"},"content":{"rendered":"\n<p>VSCode Python add-in now supports ipywidgets in Jupyter Notebooks so you can view a protein or molecule visualization directly within the VSCode environment.<\/p>\n\n\n\n<p>First, we need to load the nglview library into the Jupyter Notebook environment. To do this, I am going to use anaconda.<\/p>\n\n\n\n<p>Quick note, the first time I tried to install the packages, I got several errors; however, after updating to the latest stable versions of anaconda and node, everything ran a lot smoother.<\/p>\n\n\n\n<p>I am using the following versions of anaconda and node:<\/p>\n\n\n\n<p>anaconda 4.8.3<br>node v12.16.2<\/p>\n\n\n\n<p>Open the Anaconda command line and type the following command to install the nglview packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>conda install nglview<\/code><\/pre>\n\n\n\n<p>Once the nglview packages have downloaded and installed, install the mdanalysis stable release using the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>conda config --add channels conda-forge\nconda install mdanalysis<\/code><\/pre>\n\n\n\n<p>I also installed the mdanalysis tests using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>conda install MDAnalysisTests<\/code><\/pre>\n\n\n\n<p>Finally, install the ipywidgets using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>conda install ipywidgets<\/code><\/pre>\n\n\n\n<p>Once the ipywidgets have installed, we start the Jupyter Notebook environment, open an existing or new notebook, and run the following command to visualize the protein.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import MDAnalysis as mda\nimport nglview as nv\nfrom nglview.datafiles import PDB, XTC\nu = mda.Universe(PDB, XTC)\nprotein = u.select_atoms('protein')\nw = nv.show_mdanalysis(protein)\nw<\/code><\/pre>\n\n\n\n<p>Run the code to display the protein in VSCode.<\/p>\n\n\n\n<p>Now that we have verified that everything is up and running in the Jupyter environment, we can connect VSCode to the same Jupyter environment and run the visualization (see the previous post on <a href=\"https:\/\/leedavies.dev\/index.php\/2020\/05\/09\/connecting-vscode-to-a-jupyter-notebook\/\">connecting VSCode to a Jupyter Notebook<\/a>).<\/p>\n\n\n\n<p>Once the Jupyter connection is made, and a notebook opened, we can rerun the protein visualization from within VSCode.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"720\" src=\"https:\/\/leedavies.dev\/wp-content\/uploads\/2020\/05\/MDAnalysisGif.gif\" alt=\"\" class=\"wp-image-266\"\/><figcaption>Protein displayed in VSCode<\/figcaption><\/figure><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>VSCode Python add-in now supports ipywidgets in Jupyter Notebooks so you can view a protein or molecule visualization directly within the VSCode environment. First, we need to load the nglview library into the Jupyter Notebook environment. To do this, I am going to use anaconda. Quick note, the first time I tried to install the packages, I got several errors; however, after updating to the latest stable versions of anaconda and node, everything ran a lot smoother. I am using&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/leedavies.dev\/index.php\/2020\/05\/18\/protein-visualization-in-vscode\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":267,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,4,29],"tags":[31,28,26,30],"class_list":["post-265","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-technology","category-vscode","tag-ipywidgets","tag-jupyter","tag-python","tag-vscode"],"_links":{"self":[{"href":"https:\/\/leedavies.dev\/index.php\/wp-json\/wp\/v2\/posts\/265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leedavies.dev\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leedavies.dev\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leedavies.dev\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/leedavies.dev\/index.php\/wp-json\/wp\/v2\/comments?post=265"}],"version-history":[{"count":3,"href":"https:\/\/leedavies.dev\/index.php\/wp-json\/wp\/v2\/posts\/265\/revisions"}],"predecessor-version":[{"id":270,"href":"https:\/\/leedavies.dev\/index.php\/wp-json\/wp\/v2\/posts\/265\/revisions\/270"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/leedavies.dev\/index.php\/wp-json\/wp\/v2\/media\/267"}],"wp:attachment":[{"href":"https:\/\/leedavies.dev\/index.php\/wp-json\/wp\/v2\/media?parent=265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leedavies.dev\/index.php\/wp-json\/wp\/v2\/categories?post=265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leedavies.dev\/index.php\/wp-json\/wp\/v2\/tags?post=265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}