{ "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", "< [Packing and Relax](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/06.02-Packing-design-and-regional-relax.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [Protein Design 2](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/06.04-Protein-Design-2.ipynb) >

\"Open" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Protein Design with a Resfile and FastRelax\n", "\n", "Keywords: FastDesign, FastRelax, ResfileCommandOperation, Resfile, ResidueSelector, MoveMapFactory, TaskFactory, TaskOperation, NoRepackDisulfides, IncludeCurrent, ReadResfile, conf2pdb_chain(), pose_from_rcsb(), create_score_function(), CA_rmsd()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview\n", "\n", "In this Workshop, we will learn the classic way to design proteins, but in the same breath introduce the concept of design using a flexible backbone protocol. \n", "\n", "This protocol, is essentially design during FastRelax. A separate class, FastDesign, has a bit more options for design, but essentially, they are the same. \n", "\n", "Many modern designs have used this FastDesign/RelaxedDesign protocol - including many Science papers from the Baker lab and the RosettaAntibodyDesign (RAbD) protocol that we will cover in another tutorial. \n", "\n", "Before this workshop, you should read about the resfile syntax here: https://www.rosettacommons.org/docs/latest/rosetta_basics/file_types/resfiles" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Warning*: This notebook uses `pyrosetta.distributed.viewer` code, which runs in `jupyter notebook` and might not run if you're using `jupyterlab`." ] }, { "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": "markdown", "metadata": {}, "source": [ "**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": [ "import logging\n", "logging.basicConfig(level=logging.INFO)\n", "import pyrosetta\n", "import pyrosetta.toolbox\n", "\n", "from IPython.core.display import display, HTML\n", "display(HTML(\"\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Initialize PyRosetta" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pyrosetta.init(\"-ignore_unrecognized_res 1 -ex1 -ex2aro -detect_disulf 0\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " For this tutorial, let's use the well-studied native protein crambin from PDB ID 1AB1 (http://www.rcsb.org/structure/1AB1).\n", " \n", " Setup the input pose and scorefunction:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "start_pose = pyrosetta.toolbox.rcsb.pose_from_rcsb(\"1AB1\", ATOM=True, CRYS=False)\n", "pose = start_pose.clone()\n", "scorefxn = pyrosetta.create_score_function(\"ref2015_cart.wts\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Make of list of which residues are cysteine:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cys_res = []\n", "for i, aa in enumerate(start_pose.sequence(), start=1):\n", " if aa == \"C\":\n", " cys_res.append(i)\n", "print(cys_res)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Inspect `start_pose` using the `PyMolMover` or `dump_pdb()`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Design strategy:\n", "\n", "Design away the cysteine residues (i.e. disulfide bonds) using a resfile, allowing all side-chains to re-pack and all backbone and side-chain torsions to minimize using the `FastRelax` mover.\n", "\n", " Read more about resfile file structure at https://www.rosettacommons.org/docs/latest/rosetta_basics/file_types/resfiles" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To write a resfile, we need to know which chain to mutate.\n", "\n", "We can see that the pose consists of only chain \"A\" by printing the `pose.pdb_info()` object:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(pose.pdb_info())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " More programmatically, we could find which chains are in the `pose` using `pyrosetta.rosetta.core.pose.conf2pdb_chain(pose)` which returns a `pyrosetta.rosetta.std.map_unsigned_long_char` object which is iterable." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(pyrosetta.rosetta.core.pose.conf2pdb_chain(pose))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for k, v in pyrosetta.rosetta.core.pose.conf2pdb_chain(pose).items():\n", " print(v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " So we could write a resfile to disc indicating design specifications to mutate only the cysteine residues in chain \"A\". Use the syntax described below, and save your resfile in this directory as `resfile`.\n", " \n", " https://www.rosettacommons.org/docs/latest/rosetta_basics/file_types/resfiles" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "b3420e2f23aa7ab23f126fa827874ccd", "grade": true, "grade_id": "cell-4dfc4f43e2031e10", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that we don't necessarily need a resfile to use resfile commands. We can now do this in an intuitive way through code and `ResidueSelectors` using the `ResfileCommandOperation`. The main docs for the XML interface are available below, however the code-level interface is extremely similar. Use the ? to get more info on this. The operation is located in `pyrosetta.rosetta.core.pack.task.operation` as we saw this location in the previous tutorial.\n", "\n", "https://www.rosettacommons.org/docs/latest/scripting_documentation/RosettaScripts/TaskOperations/taskoperations_pages/ResfileCommandOperation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Now we can setup the TaskOperations for the `FastRelax` mover. These tell `FastRelax` which residues to design or repack during the packer steps in `FastRelax`. You should be familiar with this from the previous tutorial\n", " \n", "We use the `IncludeCurrent` to include the current rotamer of from the crystal structure during packing." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# The task factory accepts all the task operations\n", "tf = pyrosetta.rosetta.core.pack.task.TaskFactory()\n", "\n", "# These are pretty standard\n", "tf.push_back(pyrosetta.rosetta.core.pack.task.operation.InitializeFromCommandline())\n", "tf.push_back(pyrosetta.rosetta.core.pack.task.operation.IncludeCurrent())\n", "tf.push_back(pyrosetta.rosetta.core.pack.task.operation.NoRepackDisulfides())\n", "\n", "# Include the resfile\n", "tf.push_back(pyrosetta.rosetta.core.pack.task.operation.ReadResfile(resfile))\n", "\n", "# Convert the task factory into a PackerTask to take a look at it\n", "packer_task = tf.create_task_and_apply_taskoperations(pose)\n", "# View the PackerTask\n", "print(packer_task)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " The PackerTask looks as intended! \n", "\n", " Now we can set up a `MoveMap` or a `MoveMapFactory` to specify which torsions are free to minimize during the minimization steps of the `FastDesign` mover" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Set up a MoveMapFactory\n", "mmf = pyrosetta.rosetta.core.select.movemap.MoveMapFactory()\n", "mmf.all_bb(setting=True)\n", "mmf.all_bondangles(setting=True)\n", "mmf.all_bondlengths(setting=True)\n", "mmf.all_chi(setting=True)\n", "mmf.all_jumps(setting=True)\n", "mmf.set_cartesian(setting=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Set up a MoveMap\n", "# mm = pyrosetta.rosetta.core.kinematics.MoveMap()\n", "# mm.set_bb(True)\n", "# mm.set_chi(True)\n", "# mm.set_jump(True)\n", "\n", "# If needed, you could turn off bb and chi torsions for individual residues like this:\n", "\n", "# vector1 of true/false for each residue in the pose\n", "# subset_to_minimize = do_something_set.apply(pose)\n", "\n", "# for i in range(1, pose.size() + 1):\n", "# if (not subset_to_minimize[i]):\n", "# mm.set_bb(i, False)\n", "# mm.set_chi(i, False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Because some Movers only take as input a `MoveMap`, for backwards-compatibility one could generate a `MoveMap` from a `MoveMapFactory` using the `MoveMapFactory` function `create_movemap_from_pose(pose)`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Now let's double-check some more `pose` information to verify that we are ready for `FastRelax`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "display_pose = pyrosetta.rosetta.protocols.fold_from_loops.movers.DisplayPoseLabelsMover()\n", "display_pose.tasks(tf)\n", "display_pose.movemap_factory(mmf)\n", "display_pose.apply(pose)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Setting up `FastRelax` prints the default `relaxscript`, showing the `ramp_repack_min` settings with the following assignments:\n", ">ramp_repack_min [scale:fa_rep] [min_tolerance] [coord_cst_weight]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fr = pyrosetta.rosetta.protocols.relax.FastRelax(scorefxn_in=scorefxn, standard_repeats=1)\n", "fr.cartesian(True)\n", "fr.set_task_factory(tf)\n", "fr.set_movemap_factory(mmf)\n", "fr.min_type(\"lbfgs_armijo_nonmonotone\") # For non-Cartesian scorefunctions, use \"dfpmin_armijo_nonmonotone\"\n", "\n", "#Note that this min_type is automatically set when you set the cartesian option. \n", "# But it is good to be aware of this - as not all protocols will do this for you.\n", "\n", "#fr.set_movemap(mm) # Could have optionally specified a MoveMap instead of MoveMapFactory\n", "#fr.minimize_bond_angles(True) # If not using MoveMapFactory, could specify bond angle minimization here\n", "#fr.minimize_bond_lengths(True) # If not using MoveMapFactory, could specify bond length minimization here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For recommendations on setting `fr.min_type()` for the scorefunction being used, see: https://www.rosettacommons.org/docs/latest/rosetta_basics/structural_concepts/minimization-overview#recommendations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Run Fast(Design)! Note: this takes ~1min 31s" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "cc00b01d2d83fede06166de26580bf5f", "grade": true, "grade_id": "cell-5bcc2bfb4357035d", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Analysis\n", "\n", "Inspect the resulting design!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " By how many Angstroms RMSD did the backbone Cα atoms move?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pyrosetta.rosetta.core.scoring.CA_rmsd(start_pose, pose)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What is the delta `total_score` from `start_pose` to `pose`? Why is it large?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "delta_total_score = scorefxn(pose) - scorefxn(start_pose)\n", "print(delta_total_score)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " What is the per-residue energy difference for each mutated position between `start_pose` and `pose`?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "31f989d422ba63bc448bf44710ae3328", "grade": true, "grade_id": "cell-32cfb702cb53c564", "locked": false, "points": 0, "schema_version": 3, "solution": true } }, "outputs": [], "source": [ "YOUR-CODE-HERE" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Packing and Relax](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/06.02-Packing-design-and-regional-relax.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [Protein Design 2](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/06.04-Protein-Design-2.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 }