File size: 83,256 Bytes
8efb4bd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | {
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/dina-lab3D/CombFold/blob/master/CombFold.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"\n"
],
"metadata": {
"id": "MbEK2RpZcVCU"
}
},
{
"cell_type": "markdown",
"source": [
"This notebook runs the CombFold assembly algorithm. The algorithm assembles large protein complexes, by combining PDB files of possible subcomplexes. \"Possible subcomplexes\" are structure models of different combinations of subunits from the target complex.\n",
"\n",
"By default, the notebook runs on an example ([PDB: 6YBQ](https://www.rcsb.org/structure/6YBQ)), but by uploading your own PDB files to Google Drive (and creating a subunits.json) you can assemble your complex by changing the path in the \"Run\" cell, as instructed in the cell.\n",
"\n",
"\n",
"**The inputs** are\n",
"1. subunits.json - a json describing all the subunits (sequences) in the complex.\n",
"2. pdbs folder - a folder with AlphaFold-Multimer models (PDB files) of different combinations of these subunits.\n",
"\n",
"**The output** consists of several .PDB files which are models of the assembled complex structure.\n",
"more information is available on https://github.com/dina-lab3D/CombFold.\n"
],
"metadata": {
"id": "ZbAj512vF4eK"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "yPmEy4fH4CT8",
"cellView": "form"
},
"outputs": [],
"source": [
"#@title Install CombFold (~2 min)\n",
"\n",
"!pip -q install biopython\n",
"!pip -q install py3Dmol\n",
"!echo Installed python dependencies\n",
"\n",
"!wget -qnc -O CombFold-master.zip wget https://github.com/dina-lab3D/CombFold/archive/refs/heads/master.zip\n",
"!unzip -q CombFold-master.zip\n",
"!echo Downloaded CombFold, Installing\n",
"!cd CombFold-master/CombinatorialAssembler && make --silent\n",
"!echo CombFold Installed!\n",
"\n",
"import py3Dmol\n",
"import os\n",
"\n",
"def view_pdb_color_by_chain(pdb_path: str):\n",
" pdb_content = open(pdb_path, \"r\").read()\n",
" view = py3Dmol.view(width=400, height=300)\n",
" view.addModelsAsFrames(pdb_content)\n",
"\n",
" # Get the list of chains in the protein\n",
" chains = {i[21] for i in pdb_content.split(\"\\n\") if len(i) > 21}\n",
"\n",
" # Assign a color to each chain\n",
" colors = [\"red\", \"blue\", \"green\", \"orange\", \"purple\", \"yellow\", \"pink\", \"brown\", \"black\", \"gray\", \"cyan\", \"magenta\", \"olive\", \"maroon\", \"navy\", \"teal\", \"gold\", \"silver\", \"crimson\"]\n",
" colors = 10 * colors\n",
"\n",
" # Set the style for each chain\n",
" for i, chain in enumerate(chains):\n",
" view.setStyle({'chain': chain}, {'cartoon': {'color': colors[i]}})\n",
"\n",
" view.zoomTo()\n",
" view.show()\n"
]
},
{
"cell_type": "code",
"source": [
"#@title View example elements {run: \"auto\"}\n",
"\n",
"#@markdown Here we demonstrate the input used to create a model of [PDB: 6YBQ](https://www.rcsb.org/structure/6YBQ). This complex have a total of 12 chains, composed of 2 subunits (unique chains in this case) with 6 copies each.\n",
"\n",
"#@markdown - subunits.json - Defines two subunits (A0 and G0) with 6 copies each (implemented by defining 6 chain_names)\n",
"\n",
"#@markdown - pdb files - Structure models predicted by AlphaFold-Multimer of different subsets of 2 or 3 subunits from the complex. Each combination have multiple models, as many different pairwise interactions can be considered during assembly\n",
"\n",
"#@markdown You can view elements in the input by choosing them and running the cell.\n",
"\n",
"element_to_view = 'subunits.json' #@param [\"subunits.json\", 'pdbs/AFM_A0_A0_unrelaxed_rank_1_model_1.pdb', 'pdbs/AFM_A0_A0_unrelaxed_rank_2_model_4.pdb', 'pdbs/AFM_A0_G0_unrelaxed_rank_1_model_2.pdb', 'pdbs/AFM_A0_G0_unrelaxed_rank_2_model_3.pdb', 'pdbs/AFM_G0_G0_unrelaxed_rank_2_model_5.pdb', 'pdbs/AFM_G0_G0_unrelaxed_rank_1_model_4.pdb', 'pdbs/AFM_A0_A0_A0_unrelaxed_rank_1_model_3.pdb', 'pdbs/AFM_A0_A0_A0_unrelaxed_rank_2_model_1.pdb','pdbs/AFM_A0_A0_G0_unrelaxed_rank_2_model_3.pdb', 'pdbs/AFM_A0_A0_G0_unrelaxed_rank_1_model_1.pdb']\n",
"example_path = \"/content/CombFold-master/example/\"\n",
"\n",
"subunits_path = os.path.join(example_path, \"subunits.json\")\n",
"\n",
"if element_to_view == 'subunits.json':\n",
" print(open(subunits_path, \"r\").read())\n",
"else:\n",
" view_pdb_color_by_chain(os.path.join(example_path, element_to_view))\n"
],
"metadata": {
"id": "vAk-cPl4p2Jg",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title Run (~2 min on example)\n",
"import os\n",
"#@markdown The folder path on drive should have\n",
"#@markdown (1) a file named \"subunits.json\" with a description of the subunits\n",
"#@markdown and (2) a folder in it named \"pdbs\" containing all pdbs created by AFM.\n",
"\n",
"#@markdown The results will be saved to a new folder named \"assembled\", under the path_on_drive .\n",
"\n",
"#@markdown The path should start with /content/drive/MyDrive/ and can be copied by selecting it from the files sidebar with Right-Click->Copy Path.\n",
"path_on_drive = '/content/CombFold-master/example/' #@param {type:\"string\"}\n",
"max_results_number = \"5\" #@param [1, 5, 10, 20]\n",
"create_cif_instead_of_pdb = False #@param {type:\"boolean\"}\n",
"\n",
"subunits_path = os.path.join(path_on_drive, \"subunits.json\")\n",
"crosslinks_path = os.path.join(path_on_drive, \"crosslinks.txt\")\n",
"pdbs_folder = os.path.join(path_on_drive, \"pdbs\")\n",
"assembled_folder = os.path.join(path_on_drive, \"assembled\")\n",
"tmp_assembled_folder = \"/content/tmp_assembled\"\n",
"\n",
"if not os.path.exists(crosslinks_path):\n",
" crosslinks_path = None\n",
"\n",
"if os.path.exists(assembled_folder):\n",
" answer = input(f\"{assembled_folder} already exists, Should delete? (y/n)\")\n",
" if answer in (\"y\", \"Y\"):\n",
" print(\"Deleteing\")\n",
" shutil.rmtree(assembled_folder)\n",
" else:\n",
" print(\"Stopping\")\n",
" exit()\n",
"\n",
"if os.path.exists(tmp_assembled_folder):\n",
" shutil.rmtree(tmp_assembled_folder)\n",
"\n",
"import subprocess\n",
"import sys\n",
"import shutil\n",
"sys.path.append(\"/content/CombFold-master/scripts/\")\n",
"import run_on_pdbs\n",
"run_on_pdbs.run_on_pdbs_folder(subunits_path, pdbs_folder, tmp_assembled_folder,\n",
" crosslinks_path=crosslinks_path,\n",
" output_cif=create_cif_instead_of_pdb,\n",
" max_results_number=int(max_results_number))\n",
"\n",
"shutil.copytree(os.path.join(tmp_assembled_folder, \"assembled_results\"),\n",
" assembled_folder)\n",
"\n",
"print(\"Results saved to\", assembled_folder)"
],
"metadata": {
"id": "OgnoSp2WNMPr",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title Display Assemled 3D structure models {run: \"auto\"}\n",
"model_num = \"0\" #@param [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
"model_num = int(model_num)\n",
"\n",
"output_filenames = [i for i in os.listdir(assembled_folder) if i.endswith(\".pdb\") or i.endswith(\".cif\")]\n",
"assert model_num < len(output_filenames), f\"Only have {len(output_filenames)} models\"\n",
"output_path = os.path.join(assembled_folder, output_filenames[model_num])\n",
"\n",
"view_pdb_color_by_chain(output_path)\n"
],
"metadata": {
"id": "WwqShmF0_YCY",
"cellView": "form"
},
"execution_count": null,
"outputs": []
}
]
}
|