{ "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.notebooks);\n", "content is available [on Github](https://github.com/RosettaCommons/PyRosetta.notebooks.git).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [PyRosettaCluster Tutorial 1B. Reproduce simple protocol](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/16.07-PyRosettaCluster-Reproduce-simple-protocol.ipynb) | [Contents](toc.ipynb) | [Index](index.ipynb) | [PyRosettaCluster Tutorial 3. Multiple decoys](http://nbviewer.jupyter.org/github/RosettaCommons/PyRosetta.notebooks/blob/master/notebooks/16.09-PyRosettaCluster-Multiple-decoys.ipynb) >
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PyRosettaCluster Tutorial 2. Multiple protocols\n",
"\n",
"PyRosettaCluster Tutorial 2 is an example of using multiple user-provided PyRosetta protocols with `PyRosettaCluster`. Unlike Rosetta's `MultiplePoseMover` which executes multiple protocols serially, `PyRosettaCluster` executes multiple protocols in parallel (provided the cluster has more than one distributed worker). The user defines the order in which the protocols execute. Each `Pose` or `PackedPose` object returned from the first user-provided PyRosetta protocol is automatically passed to the second user-providd PyRosetta protocol, and so on. That is, `protocol1` returns a `Pose` object, which is then used as input for `protocol2`; `protocol2` returns a new `Pose` object, which is then used as input for `protocol3`, and so on. `Pose` objects returned by the final protocol are written to disk (unless the user specifies `PyRosettaCluster(..., save_all=True, ...)` in which case all intermediate decoys are also written to disk. Each decoy contains all of the relevant information needed to reproduce it."
]
},
{
"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 uses parallelization and is **not** meant to be executed within a Google Colab environment."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Note:* This Jupyter notebook requires the PyRosetta distributed layer which is obtained by building PyRosetta with the `--serialization` flag or installing PyRosetta from the RosettaCommons conda channel \n",
"\n",
"**Please see Chapter 16.00 for setup instructions**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Note:* This Jupyter notebook is intended to be run within **Jupyter Lab**, but may still be run as a standalone Jupyter notebook."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. Import packages"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import bz2\n",
"import glob\n",
"import json\n",
"import logging\n",
"import os\n",
"import pyrosetta\n",
"import pyrosetta.distributed.io as io\n",
"import pyrosetta.distributed.viewer as viewer\n",
"\n",
"from pyrosetta.distributed.cluster import PyRosettaCluster\n",
"\n",
"logging.basicConfig(level=logging.INFO)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. Initialize a compute cluster using `dask`:\n",
"\n",
"See Tutorial 1A to review:\n",
"1. Click the \"Dask\" tab in Jupyter Lab (arrow, left)\n",
"2. Click the \"+ NEW\" button to launch a new compute cluster (arrow, lower)\n",
"3. Once the cluster has started, click the brackets to \"inject client code\" for the cluster into your notebook\n",
"\n",
"Inject client code here, then run the cell:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if not os.getenv(\"DEBUG\"):\n",
" from dask.distributed import Client\n",
"\n",
" client = Client(\"tcp://127.0.0.1:40329\")\n",
"else:\n",
" client = None\n",
"client"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. Define the user-provided PyRosetta protocols:\n",
"\n",
"User-provided PyRosetta protocols may return `Pose` or `PackedPose` objects to be passed on to the next protocol. Protocols that don't return `Pose` or `PackedPose` objects are allowed, for example returning a `NoneType` object. In such cases, the subsequent protocol receives an empty `PackedPose` object."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def protocol1(packed_pose_in, **kwargs):\n",
" \"\"\"\n",
" Repacks the input `PackedPose` object, which can be (a) input to the function\n",
" automatically via the 'packed_pose_in' argument or (b) accessed through the 's' \n",
" `kwargs` keyword argument, depending on the order in which the protocol is \n",
" specified in the PyRosettaCluster.distributed() method.\n",
" \n",
" Args:\n",
" packed_pose_in: A `PackedPose` object to be repacked. Optional.\n",
" **kwargs: PyRosettaCluster keyword arguments.\n",
"\n",
" Returns:\n",
" A `PackedPose` object.\n",
" \"\"\"\n",
" import pyrosetta\n",
" import pyrosetta.distributed.io as io\n",
" import pyrosetta.distributed.tasks.rosetta_scripts as rosetta_scripts\n",
" \n",
" logging.info(\n",
" \"Now executing protocol number '{0}' called '{1}'.\".format(\n",
" kwargs[\"PyRosettaCluster_protocol_number\"],\n",
" kwargs[\"PyRosettaCluster_protocol_name\"]\n",
" )\n",
" )\n",
" \n",
" if packed_pose_in == None:\n",
" logging.info(\"Generating `packed_pose_in` from `kwargs['s']`.\")\n",
" packed_pose_in = io.pose_from_file(kwargs[\"s\"])\n",
" else:\n",
" logging.info(\"Using `packed_pose_in` from `args`.\")\n",
" \n",
" xml = \"\"\"\n",
"
" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:PyRosetta.notebooks]", "language": "python", "name": "pyrosetta.notebooks" }, "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" } }, "nbformat": 4, "nbformat_minor": 4 }