{
"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": [
"
"
]
},
{
"cell_type": "markdown",
"source": [
"\n"
],
"metadata": {
"id": "MbEK2RpZcVCU"
}
},
{
"cell_type": "markdown",
"source": [
"This notebook runs the CombFold assembly algorithm, with optional crosslinks between subunits. 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: 7ZKQ](https://www.rcsb.org/structure/7ZKQ)), 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",
"3. crosslinks.txt - a txt file that can be provided optionally defininig crosslinks between 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: 7ZKQ](https://www.rcsb.org/structure/7ZKQ). This complex have a total of 5 chains, each represents a single subuit.\n",
"\n",
"#@markdown - subunits.json - Defines five subunits (named: 2,A,C,T,b)\n",
"\n",
"#@markdown - pdb files - Structure models predicted by AlphaFold-Multimer of different pairings of the subunits. Each pair have multiple models, as many different pairwise interactions can be considered during assembly\n",
"\n",
"#@markdown - crosslinks.txt - Defines crosslinks, each line represents a single crosslink. the format of each line is
\\ \\ \\ \\ \\ \\ \\\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\", \"crosslinks.txt\", \"pdbs/AFM_2_A_rank_001.pdb\", \"pdbs/AFM_2_A_rank_002.pdb\", \"pdbs/AFM_2_C_rank_001.pdb\", \"pdbs/AFM_2_C_rank_002.pdb\", \"pdbs/AFM_2_T_rank_001.pdb\", \"pdbs/AFM_2_T_rank_002.pdb\", \"pdbs/AFM_2_b_rank_001.pdb\", \"pdbs/AFM_2_b_rank_002.pdb\", \"pdbs/AFM_A_C_rank_001.pdb\", \"pdbs/AFM_A_C_rank_002.pdb\", \"pdbs/AFM_A_T_rank_001.pdb\", \"pdbs/AFM_A_T_rank_002.pdb\", \"pdbs/AFM_A_b_rank_001.pdb\", \"pdbs/AFM_A_b_rank_002.pdb\", \"pdbs/AFM_C_T_rank_001.pdb\", \"pdbs/AFM_C_T_rank_002.pdb\", \"pdbs/AFM_C_b_rank_001.pdb\", \"pdbs/AFM_C_b_rank_002.pdb\", \"pdbs/AFM_T_b_rank_001.pdb\", \"pdbs/AFM_T_b_rank_002.pdb\"]\n",
"example_path = \"/content/CombFold-master/example/example_xlinks\"\n",
"\n",
"subunits_path = os.path.join(example_path, \"subunits.json\")\n",
"crosslinks_path = os.path.join(example_path, \"crosslinks.txt\")\n",
"\n",
"if element_to_view == 'subunits.json':\n",
" print(open(subunits_path, \"r\").read())\n",
"elif element_to_view == 'crosslinks.txt':\n",
" print(open(crosslinks_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",
"#@markdown If you wish to include crosslinks - tick the enable_crosslinks box and include a crosslinks.txt\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/example_xlinks' #@param {type:\"string\"}\n",
"max_results_number = \"5\" #@param [1, 5, 10, 20]\n",
"enable_crosslinks = True #@param {type:\"boolean\"}\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 (enable_crosslinks and 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",
"output_filenames.sort()\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": []
},
{
"cell_type": "code",
"source": [
"#@title Download results\n",
"from google.colab import files\n",
"\n",
"results_zip_path = \"/content/tmp_assembled/results.zip\"\n",
"os.system(f\"zip -r {results_zip_path} {assembled_folder}\")\n",
"files.download(results_zip_path)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 17
},
"cellView": "form",
"id": "ZRNIIGP9FOsa",
"outputId": "ed721f78-a9d4-4719-f608-583ac202ffae"
},
"execution_count": 16,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
""
],
"application/javascript": [
"\n",
" async function download(id, filename, size) {\n",
" if (!google.colab.kernel.accessAllowed) {\n",
" return;\n",
" }\n",
" const div = document.createElement('div');\n",
" const label = document.createElement('label');\n",
" label.textContent = `Downloading \"${filename}\": `;\n",
" div.appendChild(label);\n",
" const progress = document.createElement('progress');\n",
" progress.max = size;\n",
" div.appendChild(progress);\n",
" document.body.appendChild(div);\n",
"\n",
" const buffers = [];\n",
" let downloaded = 0;\n",
"\n",
" const channel = await google.colab.kernel.comms.open(id);\n",
" // Send a message to notify the kernel that we're ready.\n",
" channel.send({})\n",
"\n",
" for await (const message of channel.messages) {\n",
" // Send a message to notify the kernel that we're ready.\n",
" channel.send({})\n",
" if (message.buffers) {\n",
" for (const buffer of message.buffers) {\n",
" buffers.push(buffer);\n",
" downloaded += buffer.byteLength;\n",
" progress.value = downloaded;\n",
" }\n",
" }\n",
" }\n",
" const blob = new Blob(buffers, {type: 'application/binary'});\n",
" const a = document.createElement('a');\n",
" a.href = window.URL.createObjectURL(blob);\n",
" a.download = filename;\n",
" div.appendChild(a);\n",
" a.click();\n",
" div.remove();\n",
" }\n",
" "
]
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
""
],
"application/javascript": [
"download(\"download_20623bbe-19a7-462a-9778-96d4ed3cd0a5\", \"results.zip\", 1491275)"
]
},
"metadata": {}
}
]
}
]
}