{ "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", "< [Introduction to Folding](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/04.00-Introduction-to-Folding.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [Low-Res Scoring and Fragments](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/04.02-Low-Res-Scoring-and-Fragments.ipynb) >

\"Open" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Basic Folding Algorithm\n", "Keywords: pose_from_sequence(), random move, scoring move, Metropolis, assign(), Pose()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install pyrosettacolabsetup\n", "import pyrosettacolabsetup; pyrosettacolabsetup.install_pyrosetta()\n", "import pyrosetta; pyrosetta.init()\n", "from pyrosetta import *\n", "from pyrosetta.teaching import *\n", "init()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Building the Pose" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this workshop, you will be folding a 10 residue protein by building a simple de novo folding algorithm. Start by initializing PyRosetta as usual." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a simple poly-alanine `pose` with 10 residues for testing your folding algorithm. Store the pose in a variable called \"polyA.\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "c84545e6bf563e3782311230dcdb8997", "grade": true, "grade_id": "cell-e4c1f7f4858d8ee4", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE\n", "\n", "polyA.pdb_info().name(\"polyA\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Question:__\n", "Check the backbone dihedrals of a few residues (except the first and last) using the `.phi()` and `.psi()` methods in `Pose`. What are the values of $\\phi$ and $\\psi$ dihedrals? You should see ideal bond lengths and angles, but the dihedrals may not be as realistic." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "81b6d822e9f4f75816fba3feb28a270c", "grade": true, "grade_id": "cell-8ff53305ceab1573", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "OPTIONAL:\n", "We may want to visualize folding as it happens. Before starting with the folding protocol, instantiate a PyMOL mover and use a UNIQUE port number between 10,000 and 65,536. We will retain history in order to view the entire folding process by utilizing the `.keep_history()` method. Make sure it says `PyMOL <---> PyRosetta link started!` on its command line." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmm = PyMOLMover()\n", "pmm.keep_history(True)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the PyMOL mover to view the `polyA` `Pose`. You should see a long thread-like structure in PyMOL." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmm.apply(polyA)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Building A Basic *de Novo* Folding Algorithm\n", "\n", "Now, write a program that implements a Monte Carlo algorithm to optimize the protein conformation. You can do this here in the notebook, or you may use a code editor to write a `.py` file and execute in a Python or iPython shell. \n", "\n", "Our main program will include 100 iterations of making a random trial move, scoring the protein, and accepting/rejecting the move. Therefore, we can break this algorithm down into three smaller subroutines: **random, score, and decision.**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 1: Random Move\n", "\n", "For the **random** trial move, write a subroutine to choose one residue at random using `random.randint()` and then randomly perturb either the φ or ψ angles by a random number chosen from a Gaussian distribution. Use the Python built-in function `random.gauss()` from the `random` library with a mean of the current angle and a standard deviation of 25°. After changing the torsion angle, use `pmm.apply(polyA)` to update the structure in PyMOL." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "69416bf7479bcac7a4eab043f69510b9", "grade": true, "grade_id": "cell-745a45e62c624566", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "import math\n", "import random\n", "\n", "def randTrial(your_pose):\n", "YOUR-CODE-HERE\n", " return your_pose" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 2: Scoring Move\n", "\n", "For the **scoring** step, we need to create a scoring function and make a subroutine that simply returns the numerical energy score of the pose." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "44440b37bea4030dde9a1c89639096f5", "grade": true, "grade_id": "cell-bd1a937d32ede4e2", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "sfxn = get_fa_scorefxn()\n", "\n", "def score(your_pose):\n", " YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 3: Accepting/Rejecting Move\n", "For the **decision** step, we need to make a subroutine that either accepts or rejects the new conformatuon based on the Metropolis criterion. The Metropolis criterion has a probability of accepting a move as $P = \\exp( -\\Delta G / kT )$. When $ΔE ≥ 0$, the Metropolis criterion probability of accepting the move is $P = \\exp( -\\Delta G / kT )$. When $ΔE < 0$, the Metropolis criterion probability of accepting the move is $P = 1$. Use $kT = 1$ Rosetta Energy Unit (REU)." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "b66aa02a9e3ac3309efdb8e9cc1d046f", "grade": true, "grade_id": "cell-9f9766e421aae110", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "def decision(before_pose, after_pose):\n", " YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 4: Execution\n", "Now we can put these three subroutines together in our main program! Write a loop in the main program so that it performs 100 iterations of: making a random trial move, scoring the protein, and accepting/rejecting the move. \n", "\n", "After each iteration of the search, output the current pose energy and the lowest energy ever observed. **The final output of this program should be the lowest energy conformation that is achieved at *any* point during the simulation.** Be sure to use `low_pose.assign(pose)` rather than `low_pose = pose`, since the latter will only copy a pointer to the original pose." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "7cfdecf2e85ef954de3da0790f96fdf8", "grade": true, "grade_id": "cell-2556d0daef881f24", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "def basic_folding(your_pose):\n", " \"\"\"Your basic folding algorithm that completes 100 Monte-Carlo iterations on a given pose\"\"\"\n", " \n", " lowest_pose = Pose() # Create an empty pose for tracking the lowest energy pose.\n", " \n", " YOUR-CODE-HERE\n", " return lowest_pose" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, output the last pose and the lowest-scoring pose observed and view them in PyMOL. Plot the energy and lowest-energy observed vs. cycle number. What are the energies of the initial, last, and lowest-scoring pose? Is your program working? Has it converged to a good solution?\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "basic_folding(polyA)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here's an example of the PyMOL view:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import Image\n", "Image('./Media/folding.gif',width='300')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 1: Comparing to Alpha Helices\n", "Using the program you wrote for Workshop #2, force the $A_{10}$ sequence into an ideal α-helix.\n", "\n", "**Questions:** Does this helical structure have a lower score than that produced by your folding algorithm above? What does this mean about your sampling or discrimination?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 2: Optimizing Algorithm \n", "Since your program is a stochastic search algorithm, it may not produce an ideal structure consistently, so try running the simulation multiple times or with a different number of cycles (if necessary). Using a kT of 1, your program may need to make up to 500,000 iterations." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Introduction to Folding](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/04.00-Introduction-to-Folding.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [Low-Res Scoring and Fragments](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/04.02-Low-Res-Scoring-and-Fragments.ipynb) >

\"Open" ] } ], "metadata": { "anaconda-cloud": {}, "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": "calc(100% - 180px)", "left": "10px", "top": "150px", "width": "254.188px" }, "toc_section_display": true, "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 1 }