diff --git a/notebooks/AlphaFold2/AlphaFold2.ipynb b/notebooks/AlphaFold2/AlphaFold2.ipynb new file mode 100644 index 0000000..4552012 --- /dev/null +++ b/notebooks/AlphaFold2/AlphaFold2.ipynb @@ -0,0 +1,1101 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "G4yBrceuFbf3" + }, + "source": [ + "\n", + "\n", + "## ColabFold v1.5.5: AlphaFold2 using MMseqs2\n", + "\n", + "Easy to use protein structure and complex prediction using [AlphaFold2](https://www.nature.com/articles/s41586-021-03819-2) and [Alphafold2-multimer](https://www.biorxiv.org/content/10.1101/2021.10.04.463034v1). Sequence alignments/templates are generated through [MMseqs2](mmseqs.com) and [HHsearch](https://github.com/soedinglab/hh-suite). For more details, see bottom of the notebook, checkout the [ColabFold GitHub](https://github.com/sokrypton/ColabFold) and [Nature Protocols](https://www.nature.com/articles/s41596-024-01060-5).\n", + "\n", + "Old versions: [v1.4](https://colab.research.google.com/github/sokrypton/ColabFold/blob/v1.4.0/AlphaFold2.ipynb), [v1.5.1](https://colab.research.google.com/github/sokrypton/ColabFold/blob/v1.5.1/AlphaFold2.ipynb), [v1.5.2](https://colab.research.google.com/github/sokrypton/ColabFold/blob/v1.5.2/AlphaFold2.ipynb), [v1.5.3-patch](https://colab.research.google.com/github/sokrypton/ColabFold/blob/56c72044c7d51a311ca99b953a71e552fdc042e1/AlphaFold2.ipynb)\n", + "\n", + "[Mirdita M, Schütze K, Moriwaki Y, Heo L, Ovchinnikov S, Steinegger M. ColabFold: Making protein folding accessible to all.\n", + "*Nature Methods*, 2022](https://www.nature.com/articles/s41592-022-01488-1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "x1qqCtdgKOGy" + }, + "outputs": [], + "source": [ + "# @markdown Run this cell to check this notebook's version.\n", + "\n", + "current_version = \"0.0.1\"\n", + "notebook_name = \"AlphaFold2\" # Replace with the actual notebook name\n", + "\n", + "# First of all check if ipywidgets is installed, if not through an informative error\n", + "try:\n", + " import ipywidgets as widgets\n", + "except ImportError:\n", + " raise ImportError(\"ipywidgets is not installed. Please install it using 'pip install ipywidgets' or 'conda install -c conda-forge ipywidgets'.\")\n", + "\n", + "from IPython.display import display\n", + "\n", + "try:\n", + " from google.colab import output\n", + " output.enable_custom_widget_manager()\n", + "\n", + " try:\n", + " import yaml\n", + " except ImportError:\n", + " raise ImportError(\"pyyaml is not installed. Please install it using 'pip install pyyaml' or 'conda install -c conda-forge pyyaml'.\")\n", + "\n", + " import requests\n", + " import base64\n", + "\n", + " # Create widgets\n", + " github_repo = widgets.Text(\n", + " value=\"\",\n", + " description=\"*GitHub Repository URL:\",\n", + " placeholder=\"e.g https://github.com/username/repository\",\n", + " layout=widgets.Layout(width=\"70%\"),\n", + " style={'description_width': '150px'},\n", + " )\n", + "\n", + " github_token = widgets.Password(\n", + " value=\"\",\n", + " description=\"*Personal Access Token:\",\n", + " placeholder=\"[Disabled] e.g. ghp_XXXXXXXXXXXXXXXXXXXX\",\n", + " disabled=True,\n", + " layout=widgets.Layout(width=\"70%\"),\n", + " style={'description_width': '150px'},\n", + " )\n", + "\n", + " test_button = widgets.Button(\n", + " description=\"Test Connection\",\n", + " button_style='success',\n", + " )\n", + "\n", + " output_area = widgets.HTML()\n", + "\n", + " # By default the repository is considered public\n", + " if \"repository_is_private\" not in globals():\n", + " repository_is_private = False\n", + " elif repository_is_private:\n", + " github_token.disabled = False\n", + " github_token.placeholder = \"e.g. ghp_XXXXXXXXXXXXXXXXXXXX\"\n", + "\n", + " def on_test_button_clicked(b):\n", + " global repository_is_private\n", + "\n", + " # Check that the GitHub repository URL is provided\n", + " if not github_repo.value:\n", + " output_area.value = \"⚠️ Please provide a GitHub repository URL.\"\n", + " return\n", + "\n", + " # Get the owner and repo name from the URL\n", + " repo_url = github_repo.value.rstrip('/')\n", + " github_owner, github_repo_name = repo_url.split('/')[-2:]\n", + "\n", + " # Online version checking file path\n", + " version_file_path = \"notebooks/notebook_latest_versions.yaml\"\n", + " version_url = f\"https://api.github.com/repos/{github_owner}/{github_repo_name}/contents/{version_file_path}\"\n", + "\n", + " # Do an initial request to check if the repository is public\n", + " if not repository_is_private:\n", + " version_response = requests.get(version_url)\n", + " if version_response.status_code == 404:\n", + " repository_is_private = True\n", + " github_token.disabled = False\n", + " github_token.placeholder = \"e.g. ghp_XXXXXXXXXXXXXXXXXXXX\"\n", + " output_area.value = f\"⚠️ We have detected that the repository might be private. Please provide a Personal Access Token and click 'Test Connection' again.\"\n", + " return\n", + " else:\n", + " headers = {\"Accept\": \"application/vnd.github.v3+json\"}\n", + " if not github_token.value:\n", + " output_area.value = \"⚠️ Personal Access Token is required for private repositories.\"\n", + " return\n", + " headers[\"Authorization\"] = f\"token {github_token.value}\"\n", + "\n", + " version_response = requests.get(version_url, headers=headers)\n", + "\n", + " # Check the response status\n", + " if version_response.status_code == 200:\n", + " content = version_response.json()['content']\n", + " decoded_content = base64.b64decode(content).decode('utf-8')\n", + " config = yaml.safe_load(decoded_content)\n", + " # notebook_latest_versions.yaml groups the notebooks by folder: {\"\": {\"\": \"\"}}\n", + " latest_version = next((str(group[notebook_name]) for group in (config or {}).values()\n", + " if isinstance(group, dict) and notebook_name in group), \"\")\n", + "\n", + " output_area.value = (f\"Notebook version: `{current_version}`
\"\n", + " f\"Latest version available: `{latest_version}`
\")\n", + "\n", + " if latest_version == \"\":\n", + " output_area.value += \"⚠️ This notebook is not listed in the version file.
\"\n", + " elif current_version == latest_version:\n", + " output_area.value += \"✅ This notebook is up-to-date.
\"\n", + " else:\n", + " output_area.value += f\"⚠️ A new version of this notebook is available.\"\n", + " else:\n", + " output_area.value += \"⚠️ Could not retrieve the version file.
\"\n", + "\n", + " test_button.on_click(on_test_button_clicked)\n", + " # Widget layout\n", + " widget_box = widgets.VBox([github_repo, github_token, test_button, output_area])\n", + " display(widget_box)\n", + "except ImportError:\n", + " display(widgets.HTML('To check the notebook version, please go to the Welcome notebook.'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "kOblAo-xetgx" + }, + "outputs": [], + "source": [ + "#@title Input protein sequence(s)\n", + "import sys\n", + "try:\n", + " from google.colab import files\n", + "except ImportError:\n", + " files = None\n", + "\n", + "# Follow the CellTracksColab pattern: install only in Google Colab.\n", + "IN_COLAB = \"google.colab\" in sys.modules\n", + "if IN_COLAB:\n", + " !pip install -q ezinput==0.0.12\n", + "else:\n", + " print(\"Local execution: using EZInput from the application environment.\")\n", + "\n", + "import os\n", + "import re\n", + "import hashlib\n", + "\n", + "from ezinput import EZInput\n", + "from IPython.display import display, Markdown, clear_output\n", + "\n", + "from sys import version_info\n", + "python_version = f\"{version_info.major}.{version_info.minor}\"\n", + "\n", + "def add_hash(x,y):\n", + " return x+\"_\"+hashlib.sha1(y.encode()).hexdigest()[:5]\n", + "\n", + "# check if directory with jobname exists\n", + "def check(folder):\n", + " if os.path.exists(folder):\n", + " return False\n", + " else:\n", + " return True\n", + "\n", + "input_protein_gui = EZInput(title=\"AlphaFold2_advanced_input\")\n", + "\n", + "input_protein_gui.add_text(tag=\"query_sequence\",\n", + "\t\t\tdescription=\"Input protein sequence(s):\",\n", + "\t\t\tplaceholder=\"PIAQIHILEGRSDEQKETLIREVSEAISRSLDAPLTSVRVIITEMAKGHFGIGGELASK\",\n", + "\t\t\tremember_value=True)\n", + "input_protein_gui.add_HTML(tag=\"temp_output\",\n", + "\t\t\tvalue=\" - Use : to specify inter-protein chainbreaks for modeling complexes (supports homo- and hetro-oligomers). For example PI...SK:PI...SK for a homodimer\")\n", + "input_protein_gui.add_text(tag=\"jobname\",\n", + "\t\t\tdescription=\"Job name:\",\n", + "\t\t\tplaceholder=\"test\",\n", + "\t\t\tremember_value=True)\n", + "# number of models to use\n", + "input_protein_gui.add_dropdown(tag=\"num_relax\",\n", + "\t\t\t\tdescription=\"Number of models to relax using Amber:\",\n", + "\t\t\t\toptions=[0, 1, 5],\n", + "\t\t\t\tvalue=0,\n", + "\t\t\t\tremember_value=True)\n", + "\n", + "input_protein_gui.add_HTML(tag=\"temp_output_2\",\n", + "\t\t\t\tvalue=\" - specify how many of the top ranked structures to relax using amber\")\n", + "input_protein_gui.add_dropdown(tag=\"template_mode\",\n", + "\t\t\t\tdescription=\"Template mode:\",\n", + "\t\t\t\toptions=[\"none\", \"pdb100\",\"custom\"],\n", + "\t\t\t\tvalue=\"none\",\n", + "\t\t\t\tremember_value=True)\n", + "input_protein_gui.add_text(tag=\"local_template_path\",\n", + "\t\t\tdescription=\"Custom template file or folder (local only):\",\n", + "\t\t\tplaceholder=\"Path to .pdb/.cif file(s); on Colab you are asked to upload instead\",\n", + "\t\t\tremember_value=True)\n", + "input_protein_gui.add_HTML(tag=\"temp_output_3\",\n", + "\t\t\t\tvalue=\"- none = no template information is used. pdb100 = detect templates in pdb100 (see [notes](#pdb100)). custom - upload and search own templates (PDB or mmCIF format, see [notes](#custom_templates))\")\n", + "\n", + "use_amber, query_sequence, jobname, num_relax, template_mode = None, None, None, None, None\n", + "use_templates, custom_template_path, queries_path = None, None, None\n", + "def run_cell(_):\n", + "\tglobal use_amber, query_sequence, jobname, num_relax, template_mode, use_templates, custom_template_path, queries_path\n", + "\n", + "\tquery_sequence = input_protein_gui[\"query_sequence\"].value\n", + "\tjobname = input_protein_gui[\"jobname\"].value\n", + "\tnum_relax = input_protein_gui[\"num_relax\"].value\n", + "\ttemplate_mode = input_protein_gui[\"template_mode\"].value\n", + "\n", + "\twith input_protein_gui[\"output\"]:\n", + "\t\tclear_output()\n", + "\n", + "\t\tuse_amber = num_relax > 0\n", + "\n", + "\t\t# remove whitespaces\n", + "\t\tquery_sequence = \"\".join(query_sequence.split())\n", + "\n", + "\t\tbasejobname = \"\".join(jobname.split())\n", + "\t\tbasejobname = re.sub(r'\\W+', '', basejobname)\n", + "\t\tjobname = add_hash(basejobname, query_sequence)\n", + "\n", + "\t\tif not check(jobname):\n", + "\t\t\tn = 0\n", + "\t\t\twhile not check(f\"{jobname}_{n}\"): n += 1\n", + "\t\t\tjobname = f\"{jobname}_{n}\"\n", + "\n", + "\t\t# make directory to save results\n", + "\t\tos.makedirs(jobname, exist_ok=True)\n", + "\n", + "\t\t# save queries\n", + "\t\tqueries_path = os.path.join(jobname, f\"{jobname}.csv\")\n", + "\t\twith open(queries_path, \"w\") as text_file:\n", + "\t\t\ttext_file.write(f\"id,sequence\\n{jobname},{query_sequence}\")\n", + "\n", + "\t\tif template_mode == \"pdb100\":\n", + "\t\t\tuse_templates = True\n", + "\t\t\tcustom_template_path = None\n", + "\t\telif template_mode == \"custom\":\n", + "\t\t\tcustom_template_path = os.path.join(jobname,f\"template\")\n", + "\t\t\tos.makedirs(custom_template_path, exist_ok=True)\n", + "\t\t\tuse_templates = True\n", + "\t\t\tif IN_COLAB:\n", + "\t\t\t\tuploaded = files.upload()\n", + "\t\t\t\tfor fn in uploaded.keys():\n", + "\t\t\t\t\tos.rename(fn,os.path.join(custom_template_path,fn))\n", + "\t\t\telse:\n", + "\t\t\t\timport shutil\n", + "\t\t\t\tlocal_path = input_protein_gui[\"local_template_path\"].value.strip().strip('\"')\n", + "\t\t\t\tif os.path.isdir(local_path):\n", + "\t\t\t\t\ttemplate_files = [os.path.join(local_path, fn) for fn in os.listdir(local_path) if fn.lower().endswith((\".pdb\", \".cif\"))]\n", + "\t\t\t\telif os.path.isfile(local_path):\n", + "\t\t\t\t\ttemplate_files = [local_path]\n", + "\t\t\t\telse:\n", + "\t\t\t\t\ttemplate_files = []\n", + "\t\t\t\tif not template_files:\n", + "\t\t\t\t\traise FileNotFoundError(\"Template mode 'custom': set 'Custom template file or folder' to a .pdb/.cif file or a folder containing them.\")\n", + "\t\t\t\tfor fn in template_files:\n", + "\t\t\t\t\tshutil.copy(fn, os.path.join(custom_template_path, os.path.basename(fn)))\n", + "\t\telse:\n", + "\t\t\tcustom_template_path = None\n", + "\t\t\tuse_templates = False\n", + "\n", + "\t\tprint(\"jobname\",jobname)\n", + "\t\tprint(\"sequence\",query_sequence)\n", + "\t\tprint(\"length\",len(query_sequence.replace(\":\",\"\")))\n", + "\n", + "input_protein_gui.add_callback(\"run_cell\", func=run_cell, values=input_protein_gui.elements, description=\"Submit\")\n", + "input_protein_gui.add_output(tag=\"output\")\n", + "\n", + "# Display the GUI\n", + "input_protein_gui.show()\n", + "\n", + "# Save settings\n", + "input_protein_gui._save_settings()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "qxobkcfQ8LjB" + }, + "outputs": [], + "source": [ + "#@title Install dependencies\n", + "# %%time\n", + "import os\n", + "if use_amber is None:\n", + " raise RuntimeError(\"Click 'Submit' in the 'Input protein sequence(s)' cell first, then run this cell again.\")\n", + "USE_AMBER = use_amber\n", + "USE_TEMPLATES = use_templates\n", + "PYTHON_VERSION = python_version\n", + "\n", + "# Preserve the original setup commands for Google Colab only.\n", + "if IN_COLAB:\n", + " if not os.path.isfile(\"COLABFOLD_READY\"):\n", + " print(\"installing colabfold...\")\n", + " os.system(\"pip install -q --no-warn-conflicts 'colabfold[alphafold-minus-jax] @ git+https://github.com/sokrypton/ColabFold'\")\n", + " if os.environ.get('TPU_NAME', False) != False:\n", + " os.system(\"pip uninstall -y jax jaxlib\")\n", + " os.system(\"pip install --no-warn-conflicts --upgrade dm-haiku==0.0.10 'jax[cuda12_pip]'==0.3.25 -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html\")\n", + " os.system(\"ln -s /usr/local/lib/python3.*/dist-packages/colabfold colabfold\")\n", + " os.system(\"ln -s /usr/local/lib/python3.*/dist-packages/alphafold alphafold\")\n", + " # hack to fix TF crash\n", + " os.system(\"rm -f /usr/local/lib/python3.*/dist-packages/tensorflow/core/kernels/libtfkernel_sobol_op.so\")\n", + " os.system(\"touch COLABFOLD_READY\")\n", + "\n", + " if USE_AMBER or USE_TEMPLATES:\n", + " if not os.path.isfile(\"CONDA_READY\"):\n", + " print(\"installing conda...\")\n", + " os.system(\"wget -qnc https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh\")\n", + " os.system(\"bash Miniforge3-Linux-x86_64.sh -bfp /usr/local\")\n", + " os.system(\"mamba config --set auto_update_conda false\")\n", + " os.system(\"touch CONDA_READY\")\n", + "\n", + " if USE_TEMPLATES and not os.path.isfile(\"HH_READY\") and USE_AMBER and not os.path.isfile(\"AMBER_READY\"):\n", + " print(\"installing hhsuite and amber...\")\n", + " os.system(f\"mamba install -y -c conda-forge -c bioconda kalign2=2.04 hhsuite=3.3.0 openmm=8.2.0 python='{PYTHON_VERSION}' pdbfixer\")\n", + " os.system(\"touch HH_READY\")\n", + " os.system(\"touch AMBER_READY\")\n", + " else:\n", + " if USE_TEMPLATES and not os.path.isfile(\"HH_READY\"):\n", + " print(\"installing hhsuite...\")\n", + " os.system(f\"mamba install -y -c conda-forge -c bioconda kalign2=2.04 hhsuite=3.3.0 python='{PYTHON_VERSION}'\")\n", + " os.system(\"touch HH_READY\")\n", + " if USE_AMBER and not os.path.isfile(\"AMBER_READY\"):\n", + " print(\"installing amber...\")\n", + " os.system(f\"mamba install -y -c conda-forge openmm=8.2.0 python='{PYTHON_VERSION}' pdbfixer\")\n", + " os.system(\"touch AMBER_READY\")\n", + "else:\n", + " print(\"Local execution: skipping all package installations and Colab setup.\")\n", + " print(\"Dependencies must be provided by the application environment.\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "C2_sh2uAonJH" + }, + "outputs": [], + "source": [ + "\n", + "#@title MSA options (custom MSA upload, single sequence, pairing mode)\n", + "\n", + "msa_gui = EZInput(title=\"AlphaFold2_msa_options\")\n", + "\n", + "msa_gui.add_HTML(tag=\"temp_output_0\",\n", + "\t\t\t\tvalue=\"

MSA options (custom MSA upload, single sequence, pairing mode)

\")\n", + "msa_gui.add_dropdown(\"msa_mode\",\n", + "\t\t\t\tdescription=\"MSA mode:\",\n", + "\t\t\t\toptions=[\"mmseqs2_uniref_env\", \"mmseqs2_uniref\",\"single_sequence\",\"custom\"],\n", + "\t\t\t\tvalue=\"mmseqs2_uniref_env\",\n", + "\t\t\t\tremember_value=True)\n", + "msa_gui.add_dropdown(\"pair_mode\",\n", + "\t\t\t\tdescription=\"Pairing mode:\",\n", + "\t\t\t\toptions=[\"unpaired_paired\",\"paired\",\"unpaired\"],\n", + "\t\t\t\tvalue=\"unpaired_paired\",\n", + "\t\t\t\tremember_value=True)\n", + "\n", + "msa_gui.add_text(tag=\"local_a3m_path\",\n", + "\t\t\t\tdescription=\"Custom MSA .a3m file (local only):\",\n", + "\t\t\t\tplaceholder=\"Path to .a3m; on Colab you are asked to upload instead\",\n", + "\t\t\t\tremember_value=True)\n", + "msa_gui.add_HTML(tag=\"temp_output_1\",\n", + "\t\t\t\tvalue=\"- unpaired_paired = pair sequences from same species + unpaired MSA, unpaired = separate MSA for each chain, paired - only use paired sequences.\")\n", + "\n", + "msa_mode, pair_mode, query_sequence, a3m_file = None, None, None, None\n", + "\n", + "def run_cell_msa(_):\n", + "\tglobal msa_mode, pair_mode, queries_path, a3m_file, query_sequence\n", + "\tmsa_mode = msa_gui[\"msa_mode\"].value\n", + "\tpair_mode = msa_gui[\"pair_mode\"].value\n", + "\n", + "\twith msa_gui[\"output\"]:\n", + "\t\tclear_output()\n", + "\t\t# decide which a3m to use\n", + "\t\tif \"mmseqs2\" in msa_mode:\n", + "\t\t\ta3m_file = os.path.join(jobname,f\"{jobname}.a3m\")\n", + "\n", + "\t\telif msa_mode == \"custom\":\n", + "\t\t\ta3m_file = os.path.join(jobname,f\"{jobname}.custom.a3m\")\n", + "\t\t\tif not os.path.isfile(a3m_file):\n", + "\t\t\t\tif IN_COLAB:\n", + "\t\t\t\t\tcustom_msa_dict = files.upload()\n", + "\t\t\t\t\tcustom_msa = list(custom_msa_dict.keys())[0]\n", + "\t\t\t\telse:\n", + "\t\t\t\t\timport shutil\n", + "\t\t\t\t\tlocal_a3m = msa_gui[\"local_a3m_path\"].value.strip().strip('\"')\n", + "\t\t\t\t\tif not os.path.isfile(local_a3m):\n", + "\t\t\t\t\t\traise FileNotFoundError(\"MSA mode 'custom': set 'Custom MSA .a3m file' to an existing .a3m file.\")\n", + "\t\t\t\t\tcustom_msa = os.path.basename(local_a3m)\n", + "\t\t\t\t\tshutil.copy(local_a3m, custom_msa)\n", + "\t\t\t\theader = 0\n", + "\t\t\t\timport fileinput\n", + "\t\t\t\tfor line in fileinput.FileInput(custom_msa,inplace=1):\n", + "\t\t\t\t\tif line.startswith(\">\"):\n", + "\t\t\t\t\t\theader = header + 1\n", + "\t\t\t\t\tif not line.rstrip():\n", + "\t\t\t\t\t\tcontinue\n", + "\t\t\t\t\tif line.startswith(\">\") == False and header == 1:\n", + "\t\t\t\t\t\tquery_sequence = line.rstrip()\n", + "\t\t\t\t\tprint(line, end='')\n", + "\n", + "\t\t\t\tos.rename(custom_msa, a3m_file)\n", + "\t\t\t\tqueries_path=a3m_file\n", + "\t\t\t\tprint(f\"moving {custom_msa} to {a3m_file}\")\n", + "\n", + "\t\telse:\n", + "\t\t\ta3m_file = os.path.join(jobname,f\"{jobname}.single_sequence.a3m\")\n", + "\t\t\twith open(a3m_file, \"w\") as text_file:\n", + "\t\t\t\ttext_file.write(\">1\\n%s\" % query_sequence)\n", + "\n", + "\t\tprint(\"MSA mode:\",msa_mode)\n", + "\t\tprint(\"Pairing mode:\",pair_mode)\n", + "\t\tprint(\"Using MSA file:\",a3m_file)\n", + "\n", + "msa_gui.add_callback(\"run_cell_msa\", func=run_cell_msa, values=msa_gui.elements, description=\"Submit\")\n", + "msa_gui.add_output(tag=\"output\")\n", + "\n", + "# Display the GUI\n", + "msa_gui.show()\n", + "\n", + "# Save settings\n", + "msa_gui._save_settings()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "ADDuaolKmjGW" + }, + "outputs": [], + "source": [ + "#@title Advanced settings\n", + "\n", + "advanced_settings_gui = EZInput(title=\"AlphaFold2_advanced_settings\")\n", + "\n", + "advanced_settings_gui.add_HTML(tag=\"temp_output_adv\",\n", + "\t\t\t\tvalue=\"

Advanced settings

\")\n", + "advanced_settings_gui.add_dropdown(tag=\"model_type\",\n", + "\t\t\t\tdescription=\"Model type:\",\n", + "\t\t\t\toptions=[\"auto\", \"alphafold2_ptm\", \"alphafold2_multimer_v1\", \"alphafold2_multimer_v2\", \"alphafold2_multimer_v3\", \"deepfold_v1\", \"alphafold2\"],\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_HTML(tag=\"temp_output_adv_1\",\n", + "\t\t\t\tvalue=\"- if auto selected, will use alphafold2_ptm for monomer prediction and alphafold2_multimer_v3 for complex prediction.
Any of the mode_types can be used (regardless if input is monomer or complex).\")\n", + "\n", + "advanced_settings_gui.add_dropdown(tag=\"num_recycles\",\n", + "\t\t\t\tdescription=\"Number of recycles:\",\n", + "\t\t\t\toptions=[\"auto\", \"0\", \"1\", \"3\", \"6\", \"12\", \"24\", \"48\"],\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_HTML(tag=\"temp_output_adv_2\",\n", + "\t\t\t\tvalue= \"- if auto selected, will use num_recycles=20 if model_type=alphafold2_multimer_v3, else num_recycles=3 .\")\n", + "advanced_settings_gui.add_dropdown(tag=\"recycle_early_stop_tolerance\",\n", + "\t\t\t\tdescription=\"Recycle early stop tolerance:\",\n", + "\t\t\t\toptions=[\"auto\", \"0.0\", \"0.5\", \"1.0\"],\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_HTML(tag=\"temp_output_adv_3\",\n", + "\t\t\t\tvalue=\"- if auto selected, will use tol=0.5 if model_type=alphafold2_multimer_v3 else tol=0.0.\")\n", + "advanced_settings_gui.add_text(tag=\"relax_max_iterations\",\n", + "\t\t\t\tdescription=\"Relax max iterations (0=unlimited):\",\n", + "\t\t\t\tplaceholder=\"200\",\n", + "\t\t\t\tvalue=\"200\",\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_HTML(tag=\"temp_output_adv_4\",\n", + "\t\t\t\tvalue=\"- max amber relax iterations, 0 = unlimited (AlphaFold2 default, can take very long)\")\n", + "advanced_settings_gui.add_dropdown(tag=\"pairing_strategy\",\n", + "\t\t\t\tdescription=\"Pairing strategy:\",\n", + "\t\t\t\toptions=[\"greedy\", \"complete\"],\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_HTML(tag=\"temp_output_adv_5\",\n", + "\t\t\t\tvalue=\"- greedy = pair any taxonomically matching subsets, complete = all sequences have to match in one line.\")\n", + "advanced_settings_gui.add_checkbox(tag=\"calc_extra_ptm\",\n", + "\t\t\t\tdescription=\"Calculate extra PTM scores\",\n", + "\t\t\t\tvalue=False,\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_HTML(tag=\"temp_output_adv_6\",\n", + "\t\t\t\tvalue=\"- return pairwise chain iptm/actifptm

Sample settings

- enable dropouts and increase number of seeds to sample predictions from uncertainty of the model.
- decrease max_msa to increase uncertainity\")\n", + "advanced_settings_gui.add_dropdown(tag=\"max_msa\",\n", + "\t\t\t\tdescription=\"Max MSA:\",\n", + "\t\t\t\toptions=[\"auto\", \"512:1024\", \"256:512\", \"64:128\", \"32:64\", \"16:32\"],\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_dropdown(tag=\"num_seeds\",\n", + "\t\t\t\tdescription=\"Number of seeds:\",\n", + "\t\t\t\toptions=[1,2,4,8,16],\n", + "\t\t\t\tvalue=1,\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_check(tag=\"use_dropout\",\n", + "\t\t\t\tdescription=\"Use dropout for sampling\",\n", + "\t\t\t\tvalue=False,\n", + "\t\t\t\tremember_value=True)\n", + "\n", + "\n", + "advanced_settings_gui.add_HTML(tag=\"temp_output_adv_7\",\n", + "\t\t\t\tvalue=\"

Save settings

\")\n", + "advanced_settings_gui.add_check(tag=\"save_all\",\n", + "\t\t\t\tdescription=\"Save all outputs\",\n", + "\t\t\t\tvalue=False,\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_check(tag=\"save_recycles\",\n", + "\t\t\t\tdescription=\"Save recycles\",\n", + "\t\t\t\tvalue=False,\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_check(tag=\"save_to_google_drive\",\n", + "\t\t\t\tdescription=\"Save results to Google Drive\",\n", + "\t\t\t\tvalue=False,\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_HTML(tag=\"temp_output_adv_8\",\n", + "\t\t\t\tvalue=\"- if the save_to_google_drive option was selected, the result zip will be uploaded to your Google Drive\")\n", + "advanced_settings_gui.add_int_text(tag=\"dpi\",\n", + "\t\t\t\tdescription=\"DPI for images:\",\n", + "\t\t\t\tplaceholder=\"200\",\n", + "\t\t\t\tvalue=\"200\",\n", + "\t\t\t\tremember_value=True)\n", + "advanced_settings_gui.add_HTML(tag=\"temp_output_adv_9\",\n", + "\t\t\t\tvalue=\"- set dpi for image resolution\")\n", + "\n", + "model_type = None\n", + "num_recycles = None\n", + "recycle_early_stop_tolerance = None\n", + "relax_max_iterations = None\n", + "pairing_strategy = None\n", + "calc_extra_ptm = None\n", + "max_msa = None\n", + "num_seeds = None\n", + "use_dropout = None\n", + "save_all = None\n", + "save_recycles = None\n", + "save_to_google_drive = None\n", + "dpi = None\n", + "\n", + "def run_cell(_):\n", + "\tglobal model_type, num_recycles, recycle_early_stop_tolerance\n", + "\tglobal relax_max_iterations, pairing_strategy, calc_extra_ptm\n", + "\tglobal max_msa, num_seeds, use_dropout\n", + "\tglobal save_all, save_recycles, save_to_google_drive, dpi\n", + "\n", + "\twith advanced_settings_gui['output']:\n", + "\t\tclear_output()\n", + "\t\tmodel_type = advanced_settings_gui[\"model_type\"].value\n", + "\t\tnum_recycles = advanced_settings_gui[\"num_recycles\"].value\n", + "\t\trecycle_early_stop_tolerance = advanced_settings_gui[\"recycle_early_stop_tolerance\"].value\n", + "\t\trelax_max_iterations = int(advanced_settings_gui[\"relax_max_iterations\"].value)\n", + "\t\tpairing_strategy = advanced_settings_gui[\"pairing_strategy\"].value\n", + "\t\tcalc_extra_ptm = advanced_settings_gui[\"calc_extra_ptm\"].value\n", + "\t\tmax_msa = advanced_settings_gui[\"max_msa\"].value\n", + "\t\tnum_seeds = advanced_settings_gui[\"num_seeds\"].value\n", + "\t\tuse_dropout = advanced_settings_gui[\"use_dropout\"].value\n", + "\t\tsave_all = advanced_settings_gui[\"save_all\"].value\n", + "\t\tsave_recycles = advanced_settings_gui[\"save_recycles\"].value\n", + "\t\tsave_to_google_drive = advanced_settings_gui[\"save_to_google_drive\"].value\n", + "\t\tdpi = int(advanced_settings_gui[\"dpi\"].value)\n", + "\n", + "\t\tnum_recycles = None if num_recycles == \"auto\" else int(num_recycles)\n", + "\t\trecycle_early_stop_tolerance = None if recycle_early_stop_tolerance == \"auto\" else float(recycle_early_stop_tolerance)\n", + "\t\tif max_msa == \"auto\": max_msa = None\n", + "\n", + "\t\tif save_to_google_drive and not IN_COLAB:\n", + "\t\t\tprint(\"Saving to Google Drive is only available on Google Colab; results stay in the job folder.\")\n", + "\t\t\tsave_to_google_drive = False\n", + "\t\tif save_to_google_drive:\n", + "\t\t\tfrom pydrive2.drive import GoogleDrive\n", + "\t\t\tfrom pydrive2.auth import GoogleAuth\n", + "\t\t\tfrom google.colab import auth\n", + "\t\t\tfrom oauth2client.client import GoogleCredentials\n", + "\t\t\tauth.authenticate_user()\n", + "\t\t\tgauth = GoogleAuth()\n", + "\t\t\tgauth.credentials = GoogleCredentials.get_application_default()\n", + "\t\t\tdrive = GoogleDrive(gauth)\n", + "\t\t\tprint(\"You are logged into Google Drive and are good to go!\")\n", + "\n", + "\t\tprint(\"model_type\",model_type)\n", + "\t\tprint(\"num_recycles\",num_recycles)\n", + "\t\tprint(\"recycle_early_stop_tolerance\",recycle_early_stop_tolerance)\n", + "\t\tprint(\"relax_max_iterations\",relax_max_iterations)\n", + "\t\tprint(\"pairing_strategy\",pairing_strategy)\n", + "\t\tprint(\"calc_extra_ptm\",calc_extra_ptm)\n", + "\t\tprint(\"max_msa\",max_msa)\n", + "\t\tprint(\"num_seeds\",num_seeds)\n", + "\t\tprint(\"use_dropout\",use_dropout)\n", + "\t\tprint(\"save_all\",save_all)\n", + "\t\tprint(\"save_recycles\",save_recycles)\n", + "\t\tprint(\"save_to_google_drive\",save_to_google_drive)\n", + "\t\tprint(\"dpi\",dpi)\n", + "\n", + "advanced_settings_gui.add_callback(\"run_cell_adv\", func=run_cell, values=advanced_settings_gui.elements, description=\"Submit\")\n", + "advanced_settings_gui.add_output(tag=\"output\")\n", + "\n", + "# Display the GUI\n", + "advanced_settings_gui.show()\n", + "# Save settings\n", + "advanced_settings_gui._save_settings()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "mbaIO9pWjaN0" + }, + "outputs": [], + "source": [ + "#@title Run Prediction\n", + "\n", + "import sys\n", + "import warnings\n", + "warnings.simplefilter(action='ignore', category=FutureWarning)\n", + "from Bio import BiopythonDeprecationWarning\n", + "warnings.simplefilter(action='ignore', category=BiopythonDeprecationWarning)\n", + "from pathlib import Path\n", + "from colabfold.download import download_alphafold_params, default_data_dir\n", + "from colabfold.utils import setup_logging\n", + "from colabfold.batch import get_queries, run, set_model_type\n", + "from colabfold.plot import plot_msa_v2\n", + "\n", + "from colabfold.colabfold import plot_protein\n", + "from pathlib import Path\n", + "import matplotlib.pyplot as plt\n", + "\n", + "import os\n", + "import shutil\n", + "import numpy as np\n", + "import matplotlib\n", + "import matplotlib.cm\n", + "\n", + "# ColabFold's plot_protein() still calls matplotlib.cm.get_cmap, which Matplotlib 3.9 removed\n", + "if not hasattr(matplotlib.cm, \"get_cmap\"):\n", + " matplotlib.cm.get_cmap = matplotlib.colormaps.get_cmap\n", + "\n", + "def input_features_callback(input_features):\n", + " if display_images:\n", + " plot_msa_v2(input_features)\n", + " plt.show()\n", + " plt.close()\n", + "\n", + "def prediction_callback(protein_obj, length,\n", + " prediction_result, input_features, mode):\n", + " model_name, relaxed = mode\n", + " if not relaxed:\n", + " if display_images:\n", + " fig = plot_protein(protein_obj, Ls=length, dpi=150)\n", + " plt.show()\n", + " plt.close()\n", + "\n", + "prediction_gui = EZInput(title=\"AlphaFold2_run_settings\")\n", + "\n", + "prediction_gui.add_HTML(tag=\"temp_output_run\",\n", + "\t\t\t\tvalue=\"

Run Prediction

\")\n", + "\n", + "prediction_gui.add_check(tag=\"display_images\",\n", + "\t\t\t\tdescription=\"Display images during prediction\",\n", + "\t\t\t\tvalue=True,\n", + "\t\t\t\tremember_value=True)\n", + "\n", + "results, queries, is_complex = None, None, None\n", + "\n", + "def run_cell(_):\n", + "\tglobal display_images, model_type, num_recycles, recycle_early_stop_tolerance\n", + "\tglobal relax_max_iterations, pairing_strategy, calc_extra_ptm\n", + "\tglobal max_msa, num_seeds, use_dropout\n", + "\tglobal save_all, save_recycles, dpi, results, queries, is_complex\n", + "\n", + "\twith prediction_gui['output']:\n", + "\t\tclear_output()\n", + "\t\tdisplay_images = prediction_gui[\"display_images\"].value\n", + "\t\tprint(\"Display images during prediction:\",display_images)\n", + "\n", + "\t\ttry:\n", + "\t\t\tK80_chk = os.popen('nvidia-smi | grep \"Tesla K80\" | wc -l').read()\n", + "\t\texcept:\n", + "\t\t\tK80_chk = \"0\"\n", + "\t\t\tpass\n", + "\t\tif \"1\" in K80_chk:\n", + "\t\t\tprint(\"WARNING: found GPU Tesla K80: limited to total length < 1000\")\n", + "\t\t\tif \"TF_FORCE_UNIFIED_MEMORY\" in os.environ:\n", + "\t\t\t\tdel os.environ[\"TF_FORCE_UNIFIED_MEMORY\"]\n", + "\t\t\tif \"XLA_PYTHON_CLIENT_MEM_FRACTION\" in os.environ:\n", + "\t\t\t\tdel os.environ[\"XLA_PYTHON_CLIENT_MEM_FRACTION\"]\n", + "\n", + "\t\t# Colab-only path workaround for the original Amber installation\n", + "\t\tif IN_COLAB and use_amber and f\"/usr/local/lib/python{python_version}/site-packages/\" not in sys.path:\n", + "\t\t\tsys.path.insert(0, f\"/usr/local/lib/python{python_version}/site-packages/\")\n", + "\n", + "\n", + "\t\tresult_dir = jobname\n", + "\t\tlog_filename = os.path.join(jobname,\"log.txt\")\n", + "\t\tsetup_logging(Path(log_filename))\n", + "\n", + "\t\tqueries, is_complex = get_queries(queries_path)\n", + "\t\tmodel_type = set_model_type(is_complex, model_type)\n", + "\n", + "\t\tif \"multimer\" in model_type and max_msa is not None:\n", + "\t\t\tuse_cluster_profile = False\n", + "\t\telse:\n", + "\t\t\tuse_cluster_profile = True\n", + "\n", + "\t\tdownload_alphafold_params(model_type, Path(\".\"))\n", + "\t\tresults = run(\n", + "\t\t\tqueries=queries,\n", + "\t\t\tresult_dir=result_dir,\n", + "\t\t\tuse_templates=use_templates,\n", + "\t\t\tcustom_template_path=custom_template_path,\n", + "\t\t\tnum_relax=num_relax,\n", + "\t\t\tmsa_mode=msa_mode,\n", + "\t\t\tmodel_type=model_type,\n", + "\t\t\tnum_models=5,\n", + "\t\t\tnum_recycles=num_recycles,\n", + "\t\t\trelax_max_iterations=relax_max_iterations,\n", + "\t\t\trecycle_early_stop_tolerance=recycle_early_stop_tolerance,\n", + "\t\t\tnum_seeds=num_seeds,\n", + "\t\t\tuse_dropout=use_dropout,\n", + "\t\t\tmodel_order=[1,2,3,4,5],\n", + "\t\t\tis_complex=is_complex,\n", + "\t\t\tdata_dir=Path(\".\"),\n", + "\t\t\tkeep_existing_results=False,\n", + "\t\t\trank_by=\"auto\",\n", + "\t\t\tpair_mode=pair_mode,\n", + "\t\t\tpairing_strategy=pairing_strategy,\n", + "\t\t\tstop_at_score=float(100),\n", + "\t\t\tprediction_callback=prediction_callback,\n", + "\t\t\tdpi=dpi,\n", + "\t\t\tzip_results=False,\n", + "\t\t\tsave_all=save_all,\n", + "\t\t\tmax_msa=max_msa,\n", + "\t\t\tuse_cluster_profile=use_cluster_profile,\n", + "\t\t\tinput_features_callback=input_features_callback,\n", + "\t\t\tsave_recycles=save_recycles,\n", + "\t\t\tuser_agent=\"colabfold/google-colab-main\",\n", + "\t\t\tcalc_extra_ptm=calc_extra_ptm,\n", + "\t\t)\n", + "\t\tshutil.make_archive(f\"{jobname}.result\", \"zip\", root_dir=\".\", base_dir=jobname)\n", + "\n", + "prediction_gui.add_callback(\"run_cell_run\", func=run_cell, values=prediction_gui.elements, description=\"Submit\")\n", + "prediction_gui.add_output(tag=\"output\")\n", + "\n", + "# Display the prediction_gui\n", + "prediction_gui.show()\n", + "# Save settings\n", + "prediction_gui._save_settings()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "KK7X9T44pWb7" + }, + "outputs": [], + "source": [ + "#@title Display 3D structure {run: \"auto\"}\n", + "import py3Dmol\n", + "import glob\n", + "import matplotlib.pyplot as plt\n", + "from colabfold.colabfold import plot_plddt_legend\n", + "from colabfold.colabfold import pymol_color_list, alphabet_list\n", + "\n", + "display_3d_gui = EZInput(\"AlphaFold2_display_3D_settings\")\n", + "\n", + "display_3d_gui.add_dropdown(tag=\"rank_num\",\n", + "\t\t\t\tdescription=\"Select model rank to display:\",\n", + "\t\t\t\toptions=[\"1\", \"2\", \"3\", \"4\", \"5\"],\n", + "\t\t\t\tvalue=\"1\",\n", + "\t\t\t\tremember_value=True)\n", + "display_3d_gui.add_dropdown(tag=\"color\",\n", + "\t\t\t\tdescription=\"Color scheme:\",\n", + "\t\t\t\toptions=[\"chain\", \"lDDT\", \"rainbow\"],\n", + "\t\t\t\tvalue=\"lDDT\",\n", + "\t\t\t\tremember_value=True)\n", + "display_3d_gui.add_check(tag=\"show_sidechains\",\n", + "\t\t\t\tdescription=\"Show sidechains\",\n", + "\t\t\t\tvalue=False,\n", + "\t\t\t\tremember_value=True)\n", + "display_3d_gui.add_check(tag=\"show_mainchains\",\n", + "\t\t\t\tdescription=\"Show mainchains\",\n", + "\t\t\t\tvalue=False,\n", + "\t\t\t\tremember_value=True)\n", + "\n", + "jobname_prefix = None\n", + "\n", + "def run_cell(_):\n", + "\tglobal rank_num, color, show_sidechains, show_mainchains, jobname_prefix\n", + "\n", + "\twith display_3d_gui['output']:\n", + "\t\tclear_output()\n", + "\t\trank_num = int(display_3d_gui[\"rank_num\"].value)\n", + "\t\tcolor = display_3d_gui[\"color\"].value\n", + "\t\tshow_sidechains = display_3d_gui[\"show_sidechains\"].value\n", + "\t\tshow_mainchains = display_3d_gui[\"show_mainchains\"].value\n", + "\n", + "\t\tprint(\"Displaying model rank:\",rank_num)\n", + "\t\tprint(\"Color scheme:\",color)\n", + "\t\tprint(\"Show sidechains:\",show_sidechains)\n", + "\t\tprint(\"Show mainchains:\",show_mainchains)\n", + "\n", + "\t\ttag = results[\"rank\"][0][rank_num - 1]\n", + "\t\tjobname_prefix = \".custom\" if msa_mode == \"custom\" else \"\"\n", + "\t\tpdb_filename = f\"{jobname}/{jobname}{jobname_prefix}_unrelaxed_{tag}.pdb\"\n", + "\t\tpdb_file = glob.glob(pdb_filename)\n", + "\n", + "\t\tdef show_pdb(rank_num=1, show_sidechains=False, show_mainchains=False, color=\"lDDT\"):\n", + "\t\t\tmodel_name = f\"rank_{rank_num}\"\n", + "\t\t\tview = py3Dmol.view(js='https://3dmol.org/build/3Dmol.js',)\n", + "\t\t\tview.addModel(open(pdb_file[0],'r').read(),'pdb')\n", + "\n", + "\t\t\tif color == \"lDDT\":\n", + "\t\t\t\tview.setStyle({'cartoon': {'colorscheme': {'prop':'b','gradient': 'roygb','min':50,'max':90}}})\n", + "\t\t\telif color == \"rainbow\":\n", + "\t\t\t\tview.setStyle({'cartoon': {'color':'spectrum'}})\n", + "\t\t\telif color == \"chain\":\n", + "\t\t\t\tchains = len(queries[0][1]) + 1 if is_complex else 1\n", + "\t\t\t\tfor n,chain,color in zip(range(chains),alphabet_list,pymol_color_list):\n", + "\t\t\t\t\tview.setStyle({'chain':chain},{'cartoon': {'color':color}})\n", + "\n", + "\t\t\tif show_sidechains:\n", + "\t\t\t\tBB = ['C','O','N']\n", + "\t\t\t\tview.addStyle({'and':[{'resn':[\"GLY\",\"PRO\"],'invert':True},{'atom':BB,'invert':True}]},\n", + "\t\t\t\t\t\t\t\t\t{'stick':{'colorscheme':f\"WhiteCarbon\",'radius':0.3}})\n", + "\t\t\t\tview.addStyle({'and':[{'resn':\"GLY\"},{'atom':'CA'}]},\n", + "\t\t\t\t\t\t\t\t\t{'sphere':{'colorscheme':f\"WhiteCarbon\",'radius':0.3}})\n", + "\t\t\t\tview.addStyle({'and':[{'resn':\"PRO\"},{'atom':['C','O'],'invert':True}]},\n", + "\t\t\t\t\t\t\t\t\t{'stick':{'colorscheme':f\"WhiteCarbon\",'radius':0.3}})\n", + "\t\t\tif show_mainchains:\n", + "\t\t\t\tBB = ['C','O','N','CA']\n", + "\t\t\t\tview.addStyle({'atom':BB},{'stick':{'colorscheme':f\"WhiteCarbon\",'radius':0.3}})\n", + "\n", + "\t\t\tview.zoomTo()\n", + "\t\t\treturn view\n", + "\n", + "\t\tshow_pdb(rank_num, show_sidechains, show_mainchains, color).show()\n", + "\t\tif color == \"lDDT\":\n", + "\t\t\tplot_plddt_legend().show()\n", + "\n", + "display_3d_gui.add_callback(\"run_cell_run\", func=run_cell, values=display_3d_gui.elements, description=\"Submit\")\n", + "display_3d_gui.add_output(tag=\"output\")\n", + "\n", + "# Display the display_3d_gui\n", + "display_3d_gui.show()\n", + "# Save settings\n", + "display_3d_gui._save_settings()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "11l8k--10q0C" + }, + "outputs": [], + "source": [ + "#@title Plots {run: \"auto\"}\n", + "from IPython.display import display, HTML\n", + "import base64\n", + "from html import escape\n", + "\n", + "# see: https://stackoverflow.com/a/53688522\n", + "def image_to_data_url(filename):\n", + " ext = filename.split('.')[-1]\n", + " prefix = f'data:image/{ext};base64,'\n", + " with open(filename, 'rb') as f:\n", + " img = f.read()\n", + " return prefix + base64.b64encode(img).decode('utf-8')\n", + "\n", + "jobname_prefix = \".custom\" if msa_mode == \"custom\" else \"\"\n", + "pae = \"\"\n", + "pae_file = os.path.join(jobname,f\"{jobname}{jobname_prefix}_pae.png\")\n", + "if os.path.isfile(pae_file):\n", + " pae = image_to_data_url(pae_file)\n", + "cov = image_to_data_url(os.path.join(jobname,f\"{jobname}{jobname_prefix}_coverage.png\"))\n", + "plddt = image_to_data_url(os.path.join(jobname,f\"{jobname}{jobname_prefix}_plddt.png\"))\n", + "display(HTML(f\"\"\"\n", + "\n", + "
\n", + "

Plots for {escape(jobname)}

\n", + " { '' if pae == '' else '' }\n", + " \n", + " \n", + "
\n", + "\"\"\"))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "R_AH6JSXaeb2" + }, + "outputs": [], + "source": [ + "#@title Package and download results\n", + "#@markdown If you are having issues downloading the result archive, try disabling your adblocker and run this cell again. If that fails click on the little folder icon to the left, navigate to file: `jobname.result.zip`, right-click and select \\\"Download\\\" (see [screenshot](https://pbs.twimg.com/media/E6wRW2lWUAEOuoe?format=jpg&name=small)).\n", + "\n", + "if msa_mode == \"custom\":\n", + " print(\"Don't forget to cite your custom MSA generation method.\")\n", + "\n", + "if IN_COLAB:\n", + " files.download(f\"{jobname}.result.zip\")\n", + "else:\n", + " print(f\"Results saved to: {os.path.abspath(jobname + '.result.zip')}\")\n", + "\n", + "if IN_COLAB and save_to_google_drive == True and drive:\n", + " uploaded = drive.CreateFile({'title': f\"{jobname}.result.zip\"})\n", + " uploaded.SetContentFile(f\"{jobname}.result.zip\")\n", + " uploaded.Upload()\n", + " print(f\"Uploaded {jobname}.result.zip to Google Drive with ID {uploaded.get('id')}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "UGUBLzB3C6WN", + "pycharm": { + "name": "#%% md\n" + } + }, + "source": [ + "# Instructions \n", + "For detailed instructions, tips and tricks, see recently published paper at [Nature Protocols](https://www.nature.com/articles/s41596-024-01060-5)\n", + "\n", + "**Runtime-specific setup**\n", + "- **Google Colab:** the original EZInput and dependency installation commands run as before.\n", + "- **Local JupyterLab / LabConstrictor:** installation and Colab system modifications are skipped. Install dependencies through the application environment before running this notebook. Custom templates use HH-suite and Kalign: they are installed with ColabFold on Linux and Apple Silicon Macs; on Windows and Intel Macs install them separately. Custom templates and MSAs are given as local file paths instead of uploads, and saving to Google Drive is only available on Colab.\n", + "- Model weights and sequence-alignment data may still be downloaded during prediction in either environment.\n", + "\n", + "**Quick start**\n", + "1. Paste your protein sequence(s) in the input field.\n", + "2. Run the cells in order. In each cell with a form, choose the settings and click **Submit** before running the next cell. (\"Run all\" does not click Submit.)\n", + "3. After the prediction finishes, run the 3D structure, plots and download cells.\n", + "\n", + "**Result zip file contents**\n", + "\n", + "1. PDB formatted structures sorted by avg. pLDDT and complexes are sorted by pTMscore. (unrelaxed and relaxed if `use_amber` is enabled).\n", + "2. Plots of the model quality.\n", + "3. Plots of the MSA coverage.\n", + "4. Parameter log file.\n", + "5. A3M formatted input MSA.\n", + "6. A `predicted_aligned_error_v1.json` using [AlphaFold-DB's format](https://alphafold.ebi.ac.uk/faq#faq-7) and a `scores.json` for each model which contains an array (list of lists) for PAE, a list with the average pLDDT and the pTMscore.\n", + "7. BibTeX file with citations for all used tools and databases.\n", + "\n", + "At the end of the job a download modal box will pop up with a `jobname.result.zip` file. Additionally, if the `save_to_google_drive` option was selected, the `jobname.result.zip` will be uploaded to your Google Drive.\n", + "\n", + "**MSA generation for complexes**\n", + "\n", + "For the complex prediction we use unpaired and paired MSAs. Unpaired MSA is generated the same way as for the protein structures prediction by searching the UniRef100 and environmental sequences three iterations each.\n", + "\n", + "The paired MSA is generated by searching the UniRef100 database and pairing the best hits sharing the same NCBI taxonomic identifier (=species or sub-species). We only pair sequences if all of the query sequences are present for the respective taxonomic identifier.\n", + "\n", + "**Using a custom MSA as input**\n", + "\n", + "To predict the structure with a custom MSA (A3M formatted): (1) Change the `msa_mode`: to \"custom\", (2) Wait for an upload box to appear at the end of the \"MSA options ...\" box. Upload your A3M. The first fasta entry of the A3M must be the query sequence without gaps.\n", + "\n", + "It is also possilbe to provide custom MSAs for complex predictions. Read more about the format [here](https://github.com/sokrypton/ColabFold/issues/76).\n", + "\n", + "As an alternative for MSA generation the [HHblits Toolkit server](https://toolkit.tuebingen.mpg.de/tools/hhblits) can be used. After submitting your query, click \"Query Template MSA\" -> \"Download Full A3M\". Download the A3M file and upload it in this notebook.\n", + "\n", + "**PDB100** \n", + "\n", + "As of 23/06/08, we have transitioned from using the PDB70 to a 100% clustered PDB, the PDB100. The construction methodology of PDB100 differs from that of PDB70.\n", + "\n", + "The PDB70 was constructed by running each PDB70 representative sequence through [HHblits](https://github.com/soedinglab/hh-suite) against the [Uniclust30](https://uniclust.mmseqs.com/). On the other hand, the PDB100 is built by searching each PDB100 representative structure with [Foldseek](https://github.com/steineggerlab/foldseek) against the [AlphaFold Database](https://alphafold.ebi.ac.uk).\n", + "\n", + "To maintain compatibility with older Notebook versions and local installations, the generated files and API responses will continue to be named \"PDB70\", even though we're now using the PDB100.\n", + "\n", + "**Using custom templates** \n", + "\n", + "To predict the structure with a custom template (PDB or mmCIF formatted): (1) change the `template_mode` to \"custom\" in the execute cell and (2) wait for an upload box to appear at the end of the \"Input Protein\" box. Select and upload your templates (multiple choices are possible).\n", + "\n", + "* Templates must follow the four letter PDB naming with lower case letters.\n", + "\n", + "* Templates in mmCIF format must contain `_entity_poly_seq`. An error is thrown if this field is not present. The field `_pdbx_audit_revision_history.revision_date` is automatically generated if it is not present.\n", + "\n", + "* Templates in PDB format are automatically converted to the mmCIF format. `_entity_poly_seq` and `_pdbx_audit_revision_history.revision_date` are automatically generated.\n", + "\n", + "If you encounter problems, please report them to this [issue](https://github.com/sokrypton/ColabFold/issues/177).\n", + "\n", + "**Comparison to the full AlphaFold2 and AlphaFold2 Colab**\n", + "\n", + "This notebook replaces the homology detection and MSA pairing of AlphaFold2 with MMseqs2. For a comparison against the [AlphaFold2 Colab](https://colab.research.google.com/github/deepmind/alphafold/blob/main/notebooks/AlphaFold.ipynb) and the full [AlphaFold2](https://github.com/deepmind/alphafold) system read our [paper](https://www.nature.com/articles/s41592-022-01488-1).\n", + "\n", + "**Troubleshooting**\n", + "* Check that the runtime type is set to GPU at \"Runtime\" -> \"Change runtime type\".\n", + "* Try to restart the session \"Runtime\" -> \"Factory reset runtime\".\n", + "* Check your input sequence.\n", + "\n", + "**Known issues**\n", + "* Google Colab assigns different types of GPUs with varying amount of memory. Some might not have enough memory to predict the structure for a long sequence.\n", + "* Your browser can block the pop-up for downloading the result file. You can choose the `save_to_google_drive` option to upload to Google Drive instead or manually download the result file: Click on the little folder icon to the left, navigate to file: `jobname.result.zip`, right-click and select \\\"Download\\\" (see [screenshot](https://pbs.twimg.com/media/E6wRW2lWUAEOuoe?format=jpg&name=small)).\n", + "\n", + "**Limitations**\n", + "* Computing resources: Our MMseqs2 API can handle ~20-50k requests per day.\n", + "* MSAs: MMseqs2 is very precise and sensitive but might find less hits compared to HHblits/HMMer searched against BFD or MGnify.\n", + "* We recommend to additionally use the full [AlphaFold2 pipeline](https://github.com/deepmind/alphafold).\n", + "\n", + "**Description of the plots**\n", + "* **Number of sequences per position** - We want to see at least 30 sequences per position, for best performance, ideally 100 sequences.\n", + "* **Predicted lDDT per position** - model confidence (out of 100) at each position. The higher the better.\n", + "* **Predicted Alignment Error** - For homooligomers, this could be a useful metric to assess how confident the model is about the interface. The lower the better.\n", + "\n", + "**Bugs**\n", + "- If you encounter any bugs, please report the issue to https://github.com/sokrypton/ColabFold/issues\n", + "\n", + "**License**\n", + "\n", + "The source code of ColabFold is licensed under [MIT](https://raw.githubusercontent.com/sokrypton/ColabFold/main/LICENSE). Additionally, this notebook uses the AlphaFold2 source code and its parameters licensed under [Apache 2.0](https://raw.githubusercontent.com/deepmind/alphafold/main/LICENSE) and [CC BY 4.0](https://creativecommons.org/licenses/by-sa/4.0/) respectively. Read more about the AlphaFold license [here](https://github.com/deepmind/alphafold).\n", + "\n", + "**Acknowledgments**\n", + "- We thank the AlphaFold team for developing an excellent model and open sourcing the software.\n", + "\n", + "- [KOBIC](https://kobic.re.kr) and [Söding Lab](https://www.mpinat.mpg.de/soeding) for providing the computational resources for the MMseqs2 MSA server.\n", + "\n", + "- Richard Evans for helping to benchmark the ColabFold's Alphafold-multimer support.\n", + "\n", + "- [David Koes](https://github.com/dkoes) for his awesome [py3Dmol](https://3dmol.csb.pitt.edu/) plugin, without whom these notebooks would be quite boring!\n", + "\n", + "- Do-Yoon Kim for creating the ColabFold logo.\n", + "\n", + "- A colab by Sergey Ovchinnikov ([@sokrypton](https://twitter.com/sokrypton)), Milot Mirdita ([@milot_mirdita](https://twitter.com/milot_mirdita)) and Martin Steinegger ([@thesteinegger](https://twitter.com/thesteinegger)).\n" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "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.11.14" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/notebooks/AlphaFold2/requirements.yaml b/notebooks/AlphaFold2/requirements.yaml new file mode 100644 index 0000000..cf61bf8 --- /dev/null +++ b/notebooks/AlphaFold2/requirements.yaml @@ -0,0 +1,25 @@ +# LabConstrictor requirements schema; this is not a Conda environment.yml. +# Resolve dependencies together in a clean environment, then lock the result. +# The Git requirement needs Git installed on the build machine. +dependencies: +- ipywidgets==8.1.7 +- PyYAML==6.0.3 +- requests==2.32.4 +- ezinput==0.0.18 +- PyDrive2==1.21.1 +- oauth2client==4.1.3 +- matplotlib==3.10.0 +- numpy==2.4.6 +- jsonschema==4.26.0 +- truststore==0.10.5 +- certifi==2026.10.23 +- tornado==6.6 +- packaging==26.3 +- setuptools==80.10.2 +- nbformat==5.11.1 +- colabfold[alphafold,openmm]==1.6.3 +description: 'AlphaFold2 structure prediction with ColabFold, EZInput widgets, 3D visualization, optional Amber relaxation and Google Drive export (Colab).' +linux_dependencies: [] +macos_dependencies: [] +python_version: 3.13.18 +windows_dependencies: []