{ "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", "< [Rosetta Energy Score Functions](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/03.00-Rosetta-Energy-Score-Functions.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [Practice: Analyzing energy between residues](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/03.02-Analyzing-energy-between-residues.ipynb) >

\"Open" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "c89eb5f9776b6d5cabbdd15abea6ad0b", "grade": false, "grade_id": "cell-eeaeae18e9d996eb", "locked": true, "schema_version": 3, "solution": false } }, "source": [ "# Score Function Basics\n", "Keywords: score function, ScoreFunction(), get_score_function(), set_weight(), show(), etable_atom_pair_energies(), Atom objects, get_hbonds(), nhbonds(), residue_hbonds()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install pyrosettacolabsetup\n", "import pyrosettacolabsetup; pyrosettacolabsetup.install_pyrosetta()\n", "import pyrosetta; pyrosetta.init()\n", "import pyrosetta\n", "pyrosetta.init()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Make sure you are in the directory with the pdb files:**\n", "\n", "`cd google_drive/MyDrive/student-notebooks/`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this module, we will explore the PyRosetta score function interface. You will learn to inspect energies of a biomolecule at the whole protein, per-residue, and per-atom level. Finally, you will gain practice applying the energies to answering biological questions involving proteins. For these exercises, we will use the protein Ras (PDB 6q21). Either make sure you have the PDB file \"6Q21_A.pdb\" in your current directory, or if you have an Internet connection, load the pdb into a pose called `ras` with the pyrosetta.pose_from_pdb method. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "21081d5873d275d36a3d87644277ebfc", "grade": true, "grade_id": "cell-be26a363af7b009c", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "fa643c83272b1075ade2fc98f989dec1", "grade": false, "grade_id": "cell-ed57c5745ba69a27", "locked": true, "schema_version": 3, "solution": false } }, "source": [ "To score a protein, you will begin by defining a score function using the `get_score_function(is_fullatom: bool)` method in the `pyrosetta.teaching` namespace. Specifying `True` will return the default `ref2015` all-atom energy function, while `False` will specify the default centroid score function.\n", "\n", "Create a PyRosetta score function using:\n", "```\n", "sfxn = get_score_function(True)\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "828771ae15f4125f2f229e90536276e7", "grade": true, "grade_id": "cell-a8401defb7b4a814", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "from pyrosetta.teaching import *\n", "\n", "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "8e921b1ceb89e2bb7a17dd05b958b751", "grade": false, "grade_id": "cell-67b6769efaa385af", "locked": true, "schema_version": 3, "solution": false } }, "source": [ "You can see the terms, weights, and energy method options by printing the score function:\n", "\n", "```\n", "print(sfxn)\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "5d7bf9a8c23e18ccad31f042ce89458f", "grade": true, "grade_id": "cell-d9875a1b051c6971", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "a8b9f964f0f6175fb9d6e18be295f256", "grade": false, "grade_id": "cell-5714b7bc994c3fe3", "locked": true, "schema_version": 3, "solution": false } }, "source": [ "## Practice: List the terms in the energy function and their relative weights\n", "\n", "**Hint:** look at the top line that starts with 'weights'" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "eff359ad3ee25e034961c1f31fcddfd0", "grade": true, "grade_id": "cell-22ba33466d6eb287", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "## Your Response Here\n", "\n", "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Custom energy functions" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "6715f2735e589ad8a4c346d3661fcd4a", "grade": false, "grade_id": "cell-9c06a7c877210a94", "locked": true, "schema_version": 3, "solution": false } }, "source": [ "You can also create a custom energy function that includes select terms. Typically, creating a whole new score function is unneccesary because the current one works well in most cases. However, tweaking the current enrgy function by reassigning weights and adding certain energy terms can be useful.\n", "\n", "Here, we will make an example energy function with only the van der Waals attractive and repulsive terms, both with weights of 1. We need to use the `set_weight()`. Make a new `ScoreFunction` and set the weights accordingly. This is how we set the full-atom attractive (`fa_atr`) and the full-atom repulsive (`fa_rep`) terms.\n", "\n", "```\n", "sfxn2 = ScoreFunction()\n", "sfxn2.set_weight(fa_atr, 1.0)\n", "sfxn2.set_weight(fa_rep, 1.0)\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "653ca46e10728c164c946e37cc51be49", "grade": true, "grade_id": "cell-c4c5c8d7de03487d", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "975c15f8bca2e6102dda4d88beb62085", "grade": false, "grade_id": "cell-951446e04ce45937", "locked": true, "schema_version": 3, "solution": false } }, "source": [ "Lets compare the score of `ras` using the full-atom `ScoreFunction` versus the `ScoreFunction` we made above using only the attractive and repulsive terms.\n", "\n", "First, print the total energy of `ras` using `print(sfxn(ras))`\n", "Then, print the attractive and repulsive energy only of `ras` using `print(sfxn2(ras))`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "c9f538e5d8339f33206453436fa6d15d", "grade": true, "grade_id": "cell-7013e0c60ab37e65", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "# print total energy of ras\n", "YOUR-CODE-HERE\n", "\n", "# print the attractive and repulsive energy of ras\n", "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Energy Breakdown" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "93b04a3da53f917be441c7f1dc7b1bc0", "grade": false, "grade_id": "cell-952b996905b5bfc0", "locked": true, "schema_version": 3, "solution": false } }, "source": [ "Using the full-atom `ScoreFunction` `sfxn`, break the energy of `ras` down into its individual pieces with the `sfxn.show(ras)` method. Which are the three most dominant contributions, and what are their values? Is this what you would have expected? Why? Note which terms are positive and negative" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "6c8b0fe414dcc2ed932b4b92957f86a6", "grade": true, "grade_id": "cell-1985d733350b2c83", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "# use the sfxn.show() method\n", "YOUR-CODE-HERE" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [], "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "e5f67c4a806a5ac514dbc014dc1f720a", "grade": false, "grade_id": "cell-4ad3a4c661b9a763", "locked": true, "schema_version": 3, "solution": false } }, "outputs": [], "source": [ "# Your response here: what are the three most dominant contributions?" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "4dd005ae5ba2ab4da7ed844e659a32c1", "grade": false, "grade_id": "cell-dfa8632eb3d02079", "locked": true, "schema_version": 3, "solution": false } }, "source": [ "Unweighted, individual component energies of each residue in a structure are stored in the `Pose` object and can be accessed by the `energies()` method. For example, to break down the energy into each residue's contribution, we use: \n", "```\n", "print(ras.energies().show())\n", "```\n", "Where `` is the residue number.\n", "\n", "What are the total van der Waals, solvation, and hydrogen-bonding contributions of residue 24?\n", "\n", "Note: The _backbone_ hydrogen-bonding terms for each residue are not available from the `Energies` object. You can get them by using EnergyMethodOptions. See http://www.pyrosetta.org/documentation#TOC-Hydrogen-Bonds-and-Hydrogen-Bond-Scoring." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "012f9b0befd31f1254cb84b2add21ba8", "grade": true, "grade_id": "cell-cd5175f1ed3fd0ad", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "5d6e21483aecadac4cdb91f9b8685f13", "grade": false, "grade_id": "cell-910b1116d1d0becf", "locked": true, "schema_version": 3, "solution": false } }, "outputs": [], "source": [ "# your response here" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "f71d7469a99f6552564f4d1805ba1bc8", "grade": false, "grade_id": "cell-4832aeb37f36c0c6", "locked": true, "schema_version": 3, "solution": false } }, "source": [ "The van der Waals, solvation, and electrostatic terms are atom-atom pairwise energies calculated from a pre-tabulated lookup table, dependent upon the distance between the two atoms and their types. You can access this lookup table, called the `etable` directly to check these energy calculations on an atom-by-atom basis. Use the `etable_atom_pair_energies` function which returns a triplet of energies for attractive, repulsive and solvation scores.\n", "\n", "(Note that the `etable_atom_pair_energies()` function requires `Atom` objects, not the `AtomID` objects we saw in Workshop #2. For more info, look at the [documentation](https://graylab.jhu.edu/PyRosetta.documentation/pyrosetta.toolbox.atom_pair_energy.html?highlight=etable_atom_pair_energies#pyrosetta.toolbox.atom_pair_energy.etable_atom_pair_energies).)\n", "\n", "**Practice:** What are the attractive, repulsive, solvation, and electrostatic components between the nitrogen of residue 24 and the oxygen of residue 20? \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "ed20886fb4fde1e8104970d0e2a4dea4", "grade": true, "grade_id": "cell-7ce1bc99f2fd0b00", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Rosetta Energy Score Functions](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/03.00-Rosetta-Energy-Score-Functions.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [Practice: Analyzing energy between residues](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/03.02-Analyzing-energy-between-residues.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": { "height": "503.333px", "left": "207px", "top": "151.722px", "width": "254.167px" }, "toc_section_display": true, "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 2 }