{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "*This notebook contains material from [PyRosetta](https://RosettaCommons.github.io/PyRosetta.notebooks);\n", "content is available [on Github](https://github.com/RosettaCommons/PyRosetta.notebooks.git).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Protein Geometry](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/02.05-Protein-Geometry.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [Visualization with the `PyMOLMover`, PyRosetta ColabPyMOL integration](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/02.07-Visualization-and-PyMOL-Mover.PyRosetta-ColabPyMOL-integration.ipynb) >

\"Open" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualization with the `PyMOLMover`\n", "Keywords: PyMOLMover, send_hbonds()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**If you are using Google Colab:** Currently, we do not have a way to connect to the local machine's PyMOL, but you can always dump any pose into a pdb file and open that on your own computer. Please see 02.07-Visualization-and-PyMOL-Mover.PyRosetta-ColabPyMOL-integration.ipynb notebook for experimantal workaround that works only on small proteins.\n", "```\n", "pose.dump_pdb(\"output_file.pdb\")\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install pyrosettacolabsetup\n", "import pyrosettacolabsetup; pyrosettacolabsetup.install_pyrosetta()\n", "import pyrosetta; pyrosetta.init()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pyrosetta import *\n", "init()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**From previous section:**\n", "Make sure you are in the right directory for accessing the `.pdb` files:\n", "\n", "`cd google_drive/MyDrive/student-notebooks/`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pose = pose_from_pdb(\"inputs/5tj3.pdb\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To check that the necessary PyRosetta commands are run by PyMOL, open up PyMOL on Polander and check for a message like `PyMOL <--> PyRosetta link started!` in the dialog box. PyMOL is now listening for updates from PyRosetta on port 127.0.0.1 by default." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note:** this may not work if many people are trying to do this at the same time, so you may need to specify a different port number by (1) typing `pmm = PyMOLMover('127.0.0.1', some number between 10000 and 65536)` in PyRosetta, (2) `run PyMOL-RosettaServer.py` in PyMOL command line, and (3) `start_rosetta_server('127.0.0.1', that number you used in step 1)` in PyMOL command line." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**If you are using your own computer (not Polander):** either use the PyMOL command line to run the PyMOL-RosettaServer.py file or drag and drop the PyMOL-RosettaServer.py file onto the PyMOL window to start the PyMOL-PyRosetta link." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `PyMOLMover` class will let us send information from PyRosetta to PyMOL for quick visualization. We are creating an instance of PyMOLMover called `pmm`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pyrosetta import PyMOLMover" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(Skip this if you already initialized pmm.)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmm = PyMOLMover() #go here for additional help: https://www.pyrosetta.org/documentation/pymol_mover-tutorial" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To view the pose, you can use the apply method on your pose." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "clone_pose = Pose()\n", "clone_pose.assign(pose)\n", "pmm.apply(clone_pose)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The PyMOLMover has useful helper functions. For example, you can visualize all the hydrogen bonds in your protein with the following:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmm.send_hbonds(clone_pose)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Just deselect the hydrogen bonds in PyMOL if you want to hide them temporarily.\n", "\n", "What other send methods does the PyMOLMover have?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The method `keep_history`, if set to True, allows you to load in structures with the same name into states of the same object in PyMOL. This is the starting point for creating a PyMOL movie of your structure, and allows you to loop through structures in different geometries efficiently (try clicking the arrows that are shown below in the red box)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmm.keep_history(True) \n", "pmm.apply(clone_pose)\n", "clone_pose.set_phi(5, -90)\n", "pmm.apply(clone_pose)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is what it should look like (assuming you are able to establish the PyMOL <--> PyRosetta link):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.core.interactiveshell import InteractiveShell\n", "InteractiveShell.ast_node_interactivity = \"all\"\n", "from IPython import display" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "gifPath = Path(\"./Media/PyMOL-tutorial.gif\")\n", "# Display GIF in Jupyter, CoLab, IPython\n", "with open(gifPath,'rb') as f:\n", " display.Image(data=f.read(), format='png',width='800')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 7: Visualizing changes in backbone angles" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use a `for` loop to change some backbone torsions (phi and psi) of `test_pose`. Be sure to `keep_history` and send to PyMOL. Try printing the $\\phi$ and $\\psi$ before and after you set it to make sure it is working as you expect." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "test_pose = Pose()\n", "test_pose.assign(pose)\n", "\n", "# use a for loop here\n", "# set some phi and psi values\n", "# send the structure to PyMOL" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Additional Exercises ##" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following exercises are meant to get you more comfortable with `Pose` methods and python coding. Many will require looping through the residues in a pose. As you find residues that answer these questions, view them in the PyMOL structure to check your work.\n", "\n", "**PyMOL Instructios:** View the original protein (5tj3) in PyMOL, view as cartoon, view Zn2+ atoms as spheres, and color the substrate mimic residue TPO distinctly (in PyMOL, try `select resn TPO`)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Create the Ramachandran plot for the protein and compare with the [Ramachandran plot](http://kinemage.biochem.duke.edu/teaching/anatax/html/anatax.1b.html)\n", "from [Richardson's Anatomy and Taxonomy of Protein Structure](http://kinemage.biochem.duke.edu/teaching/anatax/).\n", "\n", "Don't forget to label your axes!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib\n", "# this inline command gets plots to appear within the notebook\n", "# %matplotlib inline (Uncomment this)\n", "import matplotlib.pyplot as plt\n", "\n", "# example of how to make a scatter plot from a list\n", "# uncomment to see how it works and pops up in the notebook\n", "#x_coords = list(range(10))\n", "#y_coords = list(range(10))\n", "#plt.scatter(x_coords, y_coords)\n", "#plt.xlabel(\"X axis\")\n", "#plt.ylabel(\"Y axis\")\n", "\n", "# A Ramachandran plot is psi vs phi. Collect these values from the pose and plot them" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Analyzing Amino Acid Patterns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Find all the polar amino acids in the protein. Using PyMOL, figure out where they are they located in the protein. Are there any patterns here?\n", "\n", "Hint, don't type in a residue number one-by-one. Try `select resn XXX` and replace XXX with polar residue names in PyMOL" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Active Site Residues" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Find all residues that coordinate with the Zn2+ atoms around TPO (have any side-chain atoms within < 2.3 Angstroms). These residues may have a role in catalysis.\n", "\n", "Consider how you could loop through every atom index in a residue" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Get all residue types within 8 Angstroms of the active site. Are there any patterns in terms of residue types here?\n", "\n", "Perhaps residues with backbone atoms within 8-9 Angstroms to the Zn atoms are within the active site" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Answers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 6" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# three alanines\n", "tripeptide = pose_from_sequence(\"AAA\")\n", "\n", "orig_phi = tripeptide.phi(2)\n", "orig_psi = tripeptide.psi(2)\n", "print(\"original phi:\", orig_phi)\n", "print(\"original psi:\", orig_psi)\n", "\n", "# print the xyz coordinates of the CB atom of residue 2 here BEFORE setting\n", "print(\"xyz coordinates:\", tripeptide.residue(2).xyz(\"CB\"))\n", "\n", "# set the phi and psi here\n", "tripeptide.set_phi(2, -60)\n", "tripeptide.set_psi(2, -43)\n", "\n", "print(\"new phi:\", tripeptide.phi(2))\n", "print(\"new psi:\", tripeptide.psi(2))\n", "\n", "# print the xyz coordinates of the CB atom of residue 2 here AFTER setting\n", "print(\"xyz coordinates:\", tripeptide.residue(2).xyz(\"CB\"))\n", "# did changing the phi and psi angle change the xyz coordinates of the CB atom of alanine 2?\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## References\n", "This notebook includes some concepts and exercises from:\n", "\n", "\"Workshop #2: PyRosetta\" in the PyRosetta workbook: https://graylab.jhu.edu/pyrosetta/downloads/documentation/pyrosetta4_online_format/PyRosetta4_Workshop2_PyRosetta.pdf\n", "\n", "\"Workshop #4.1: PyMOL_Mover\" in the PyRosetta workbook: \n", "https://www.pyrosetta.org/documentation/pymol_mover-tutorial" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Protein Geometry](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/02.05-Protein-Geometry.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [Visualization with the `PyMOLMover`, PyRosetta ColabPyMOL integration](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/02.07-Visualization-and-PyMOL-Mover.PyRosetta-ColabPyMOL-integration.ipynb) >

\"Open" ] } ], "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.6.0" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 2 }