{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Before you turn this problem in, make sure everything runs as expected. First, **restart the kernel** (in the menubar, select Kernel$\\rightarrow$Restart) and then **run all cells** (in the menubar, select Cell$\\rightarrow$Run All).\n", "\n", "Make sure you fill in any place that says `YOUR CODE HERE` or \"YOUR ANSWER HERE\", as well as your name and collaborators below:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "NAME = \"\"\n", "COLLABORATORS = \"\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "*This notebook contains material from [PyRosetta](https://RosettaCommons.github.io/PyRosetta);\n", "content is available [on Github](https://github.com/RosettaCommons/PyRosetta.notebooks.git).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Ligand Refinement in PyRosetta (a.k.a. High-Resolution Local Docking) Using the `ligand.wts` Scorefunction](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/07.03-Ligand-Docking-PyRosetta.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [`GALigandDock` Protocol with `pyrosetta.distributed` Using the `beta_cart.wts` Scorefunction](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/07.05-Ligand-Docking-pyrosetta.distributed.ipynb) >

\"Open" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Global Ligand Docking using `XMLObjects` Using the `ref2015.wts` Scorefunction" ] }, { "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": "markdown", "metadata": {}, "source": [ "*Note:* This Jupyter notebook requires the PyRosetta distributed layer. Please make sure to activate the `PyRosetta.notebooks` conda environment before running this notebook. The kernel is set to use this environment. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import logging\n", "logging.basicConfig(level=logging.INFO)\n", "import matplotlib\n", "%matplotlib inline\n", "import os\n", "import pandas as pd\n", "import pyrosetta\n", "import pyrosetta.distributed.viewer as viewer\n", "import seaborn\n", "seaborn.set()\n", "import sys\n", "\n", "# Notebook setup\n", "import sys\n", "if 'google.colab' in sys.modules:\n", " print(\"This Jupyter notebook uses parallelization and is therefore not set up for the Google Colab environment.\")\n", " sys.exit(0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we change the scorefunction to `ref2015.wts`, the weights of which were optimized on ligands with AM1-BCC partial charges generated with Amber's `antechamber`. Therefore, the Rosetta `.params` file should ideally also have AM1-BCC partial charges generated with `antechamber`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ligand_params = \"inputs/TPA.am1-bcc.fa.params\"\n", "flags = f\"\"\"\n", "-ignore_unrecognized_res 1\n", "-extra_res_fa {ligand_params}\n", "\"\"\"\n", "pyrosetta.distributed.init(flags)\n", "pose = pyrosetta.io.pose_from_file(filename=\"inputs/test_lig.pdb\")\n", "scorefxn = pyrosetta.create_score_function(\"ref2015\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ligand docking using `XmlObjects`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "xml = pyrosetta.rosetta.protocols.rosetta_scripts.XmlObjects.create_from_string(\"\"\"\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\"\"\").get_mover(\"ParsedProtocol\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Produce 5 global ligand docking trajectories using `PyJobDistributor`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "if not os.getenv(\"DEBUG\"):\n", " working_dir = os.getcwd()\n", " output_dir = \"outputs\"\n", " if not os.path.exists(output_dir):\n", " os.mkdir(output_dir)\n", " os.chdir(output_dir)\n", "\n", " jd = pyrosetta.toolbox.py_jobdistributor.PyJobDistributor(pdb_name=\"test_lig_XMLObjects\",\n", " nstruct=5,\n", " scorefxn=scorefxn)\n", " jd.native_pose = pose\n", " df = pd.DataFrame()\n", " while not jd.job_complete:\n", " test_pose = pose.clone()\n", " xml.apply(test_pose)\n", " test_df = pd.DataFrame.from_records(dict(test_pose.scores), index=[jd.current_name])\n", " df = df.append(test_df)\n", " jd.output_decoy(test_pose)\n", " os.chdir(working_dir)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that we have sampled some global ligand docking trajectories, let's plot the ligand binding energy landscape:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "matplotlib.rcParams['figure.figsize'] = [12.0, 8.0]\n", "seaborn.scatterplot(x=\"rmsd_chX\", y=\"interfE\", data=df)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can check which `.pdb` file has the lowest `interfE` score:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df.sort_values(by=\"interfE\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's take a look at the pose with the lowest `interfE` value that was generated:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lowest_energy_pdb_filename = os.path.join(\"expected_outputs\", df.sort_values(by=\"interfE\").head(1).index[0])\n", "test_pose = pyrosetta.io.pose_from_file(filename=lowest_energy_pdb_filename)\n", "\n", "chE = pyrosetta.rosetta.core.select.residue_selector.ChainSelector(\"E\")\n", "\n", "view = viewer.init(test_pose)\n", "view.add(viewer.setStyle())\n", "view.add(viewer.setStyle(command=({\"hetflag\": True}, {\"stick\": {\"colorscheme\": \"brownCarbon\", \"radius\": 0.2}})))\n", "view.add(viewer.setSurface(residue_selector=chE, opacity=0.7, color='white'))\n", "view.add(viewer.setHydrogenBonds())\n", "view()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*Exercise:*\n", "\n", "Re-run the above example with more sampling. *Pretend* that you have done enough sampling (i.e. ~2,000-10,000 global ligand docking trajectories depending on the surface area of the protein) and that the decoy with the lowest `interfE` score is the \"native\" ligand binding mode. Re-plot the ligand binding energy landscape fixing that decoy to `rmsd_chX`=0.0\n", "\n", "*Hint:* You have all of the decoys saved as `.pdb` files, so you need to re-score them using the command line flag `-in:file:native` specifying the `.pdb` file with the lowest `interfE` score, that way all `rmsd_chX` values correspond to the RMSD from that decoy, not the binding mode we started with above. Use the following cell to get started! The code below does not save the new scores to a scorefile, but if you would like to, make use of the `pyrosetta.toolbox.py_jobdistributor.output_scorefile()` function." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "*Restart Jupyter Notebook kernel to properly re-initialize PyRosetta*\n", "***" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import glob\n", "import logging\n", "logging.basicConfig(level=logging.INFO)\n", "import matplotlib\n", "%matplotlib inline\n", "import os\n", "import pandas as pd\n", "import pyrosetta\n", "import pyrosetta.distributed.viewer as viewer\n", "import seaborn\n", "seaborn.set()\n", "import sys\n", "\n", "# Notebook setup\n", "if 'google.colab' in sys.modules:\n", " !pip install pyrosettacolabsetup\n", " import pyrosettacolabsetup\n", " pyrosettacolabsetup.setup()\n", " print (\"Notebook is set for PyRosetta use in Colab. Have fun!\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "if not os.getenv(\"DEBUG\"):\n", " pdb_filenames = glob.glob(\"expected_outputs/test_lig_XMLObjects*.pdb\")\n", " ligand_params = \"inputs/TPA.am1-bcc.fa.params\"\n", " native_pdb_filename = \"expected_outputs/test_lig_XMLObjects_1.pdb\"\n", "\n", " flags = f\"\"\"\n", " -extra_res_fa {ligand_params} \n", " -in:file:native {native_pdb_filename}\n", " -ignore_unrecognized_res 1 \n", " -mute all\n", " \"\"\"\n", " pyrosetta.distributed.init(flags)\n", " scorefxn = pyrosetta.create_score_function(\"ref2015\")\n", "\n", " xml = pyrosetta.rosetta.protocols.rosetta_scripts.XmlObjects.create_from_string(\"\"\"\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \"\"\").get_mover(\"ParsedProtocol\")\n", "\n", " df = pd.DataFrame()\n", " for pdb_filename in pdb_filenames:\n", " test_pose = pyrosetta.io.pose_from_file(filename=pdb_filename)\n", " xml.apply(test_pose)\n", " test_df = pd.DataFrame.from_records(dict(test_pose.scores), index=[pdb_filename.split(\"/\")[-1]])\n", " df = df.append(test_df)\n", "\n", " matplotlib.rcParams['figure.figsize'] = [12.0, 8.0]\n", " seaborn.scatterplot(x=\"rmsd_chX\", y=\"interfE\", data=df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Ligand Refinement in PyRosetta (a.k.a. High-Resolution Local Docking) Using the `ligand.wts` Scorefunction](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/07.03-Ligand-Docking-PyRosetta.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [`GALigandDock` Protocol with `pyrosetta.distributed` Using the `beta_cart.wts` Scorefunction](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/07.05-Ligand-Docking-pyrosetta.distributed.ipynb) >

\"Open" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:PyRosetta.notebooks] *", "language": "python", "name": "conda-env-PyRosetta.notebooks-py" }, "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.7.6" }, "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 }