{ "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", "< [Accessing PyRosetta Documentation](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/02.03-Accessing-PyRosetta-Documentation.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [Protein Geometry](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/02.05-Protein-Geometry.ipynb) >

\"Open" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting spatial features from a Pose\n", "Keywords: conformation(), bond_length(), AtomID, atom_index()" ] }, { "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 directory with 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": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import Image\n", "Image('./Media/dihedral-final.png',width='500')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`Pose` objects make it easy to access angles, distances, and torsions for analysis. Lets take a look at how to get backbone torsions first." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "ed5e9945c167263301f8965fc7a5acec", "grade": true, "grade_id": "cell-515a9a625374ff39", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "#resid = \"get the pose residue number for chain A:res 28 using the pdb2pose function\"\n", "YOUR-CODE-HERE" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"phi:\", pose.phi(resid))\n", "print(\"psi:\", pose.psi(resid))\n", "print(\"chi1:\", pose.chi(1, resid))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Say we want to find the length of the $N$-$C_\\alpha$ and $C_\\alpha$-$C$ bonds for residue A:28 from the PDB file. We can use a couple approaches. The first involves using the bond length in the `Conformation` class, which stores some info on protein geometry. Take a look at some of the methods in the `Conformation` class using tab completion." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "conformation = pose.conformation()\n", "# do some tab completion here to explore the Conformation class methods\n", "#conformation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Look at the documentation for the method `conformation.bond_length` below. Remember using the `?`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "bc0497d4812b2dfbd5a0d430b596dc52", "grade": true, "grade_id": "cell-24f6696e51608ed9", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To use the bond_length method in the `Conformation` class, it looks like we'll need to make `AtomID` objects. We can do this using an atom index and residue ID as follows:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Double Check: does resid contain the Pose numbering or PDB numbering?\n", "res_28 = pose.residue(resid)\n", "N28 = AtomID(res_28.atom_index(\"N\"), resid)\n", "CA28 = AtomID(res_28.atom_index(\"CA\"), resid)\n", "C28 = AtomID(res_28.atom_index(\"C\"), resid)\n", "\n", "# try printing out an AtomID object!" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "78f71f2bf4ff57e36242c4782cf9579e", "grade": true, "grade_id": "cell-173ad95e5970743d", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As usual, if you did not know how to construct an `AtomID`, you could check the documentation using `?AtomID`.\n", "\n", "Now we can compute the bond lengths:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(pose.conformation().bond_length(N28, CA28))\n", "print(pose.conformation().bond_length(CA28, C28))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively, we can compute bond lengths ourselves starting from the xyz coordinates of the atoms. \n", "\n", "The method `xyz` of `Residue` returns a `Vector` class. The `Vector` class has various useful builtin methods including computing dot products, cross products, and norms. Through operator overloading in the `Vector` class, you can just subtract and add vector objects and they will manipulate the corresponding vectors appropriately." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "N_xyz = res_28.xyz(\"N\")\n", "CA_xyz = res_28.xyz(\"CA\")\n", "C_xyz = res_28.xyz(\"C\")\n", "N_CA_vector = CA_xyz - N_xyz\n", "CA_C_vector = CA_xyz - C_xyz\n", "print(N_CA_vector.norm())\n", "print(CA_C_vector.norm())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Thankfully, the two approaches for computing distances check out!\n", "\n", "**Note**: Not all bond lengths, angles, and torsions will be accessible using the `Conformation` object. That is because the `Conformation` object stores only the subset it needs to generate xyz locations for the atoms in the pose. The most stable way to get this information is to compute it using the xyz Cartesian coordinate vectors as a starting point." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "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", "http://www.pyrosetta.org/pymol_mover-tutorial" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Accessing PyRosetta Documentation](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/02.03-Accessing-PyRosetta-Documentation.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [Protein Geometry](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/02.05-Protein-Geometry.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": false } }, "nbformat": 4, "nbformat_minor": 2 }