### Run the setup script Source: https://github.com/sokrypton/colabfold/blob/main/MsaServer/README.md This command executes the setup script to download dependencies, databases, and start the API server. ```bash ./setup-and-start-local.sh ``` -------------------------------- ### Setup Databases for On-the-fly Searches Source: https://github.com/sokrypton/colabfold/wiki/Home Command to download and set up databases for MMseqs2 when running on-the-fly searches, ensuring no large precomputed index is generated. ```bash MMSEQS_NO_INDEX=1 ./setup_databases.sh /path/to/db_folder ``` -------------------------------- ### Setup RoseTTAFold2 Source: https://github.com/sokrypton/colabfold/blob/main/RoseTTAFold2.ipynb This code block installs RoseTTAFold2, downloads necessary parameters, and sets up the environment for running predictions. It includes installing dependencies like dgl and e3nn, cloning the RoseTTAFold2 repository, and downloading pre-trained model weights. ```python %%time #@title setup **RoseTTAFold2** (~1m) params = "RF2_apr23" # @param ["RF2_apr23","RF2_jan24"] import os, time, sys os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:512" if params == "RF2_jan24" and not os.path.isfile(f"{params}.tgz"): # send param download into background os.system("(apt-get install aria2; aria2c -q -x 16 https://files.ipd.uw.edu/dimaio/RF2_jan24.tgz) &") if params == "RF2_apr23" and not os.path.isfile(f"{params}.tgz"): # send param download into background os.system("(apt-get install aria2; aria2c -q -x 16 https://files.ipd.uw.edu/dimaio/RF2_apr23.tgz) &") if not os.path.isdir("RoseTTAFold2"): print("install RoseTTAFold2") os.system("git clone https://github.com/uw-ipd/RoseTTAFold2.git") os.system("pip install py3Dmol") # 17Mar2024: adding --no-dependencies to avoid installing nvidia-cuda-* dependencies # 25Aug2025: updating dgi install to work with latest pytorch os.system("pip install --no-dependencies dgl -f https://data.dgl.ai/wheels/torch-2.4/cu124/repo.html") os.system("pip install --no-dependencies e3nn==0.5.5 opt_einsum_fx") os.system("cd RoseTTAFold2/SE3Transformer; pip install .") os.system("wget https://raw.githubusercontent.com/sokrypton/ColabFold/main/colabfold/colabfold.py -O colabfold_utils.py") #os.system("pip install dgl -f https://data.dgl.ai/wheels/cu121/repo.html") #os.system("cd RoseTTAFold2/SE3Transformer; pip -q install --no-cache-dir -r requirements.txt; pip -q install .") #os.system("wget https://raw.githubusercontent.com/sokrypton/ColabFold/beta/colabfold/mmseqs/api.py") # install hhsuite print("install hhsuite") os.makedirs("hhsuite", exist_ok=True) os.system(f"curl -fsSL https://github.com/soedinglab/hh-suite/releases/download/v3.3.0/hhsuite-3.3.0-SSE2-Linux.tar.gz | tar xz -C hhsuite/") if not os.path.isfile(f"{params}.pt"): time.sleep(5) if os.path.isfile(f"{params}.tgz.aria2"): print("downloading RoseTTAFold2 params") while os.path.isfile(f"{params}.tgz.aria2"): time.sleep(5) if not os.path.isfile(f"{params}.pt"): os.system(f"tar -zxvf {params}.tgz") if params == "RF2_apr23": os.system(f"mv weights/{params}.pt .") if not "IMPORTED" in dir(): if 'RoseTTAFold2/network' not in sys.path: os.environ["DGLBACKEND"] = "pytorch" sys.path.append('RoseTTAFold2/network') if "hhsuite" not in os.environ['PATH']: os.environ['PATH'] += ":hhsuite/bin:hhsuite/scripts" import matplotlib.pyplot as plt from google.colab import files import numpy as np from parsers import parse_a3m #from api import run_mmseqs2 from colabfold_utils import run_mmseqs2 import py3Dmol import torch from string import ascii_uppercase, ascii_lowercase import hashlib, re, os import random def get_hash(x): return hashlib.sha1(x.encode()).hexdigest() alphabet_list = list(ascii_uppercase+ascii_lowercase) from collections import OrderedDict, Counter IMPORTED = True if not "pred" in dir() or params_sele != params: from predict import Predictor print("compile RoseTTAFold2") if (torch.cuda.is_available()): pred = Predictor(f"{params}.pt", torch.device("cuda:0")) else: print ("WARNING: using CPU") pred = Predictor(f"{params}.pt", torch.device("cpu")) params_sele = params def get_unique_sequences(seq_list): unique_seqs = list(OrderedDict.fromkeys(seq_list)) return unique_seqs def run_mmseqs2_wrapper(*args, **kwargs): kwargs['user_agent'] = "colabfold/rosettafold2" return run_mmseqs2(*args, **kwargs) def get_msa(seq, jobname, cov=50, id=90, max_msa=2048, mode="unpaired_paired"): assert mode in ["unpaired","paired","unpaired_paired"] seqs = [seq] if isinstance(seq,str) else seq # collapse homooligomeric sequences counts = Counter(seqs) u_seqs = list(counts.keys()) u_nums = list(counts.values()) # expand homooligomeric sequences first_seq = "/".join(sum([[x]*n for x,n in zip(u_seqs,u_nums)],[])) msa = [first_seq] path = os.path.join(jobname,"msa") os.makedirs(path, exist_ok=True) if mode in ["paired","unpaired_paired"] and len(u_seqs) > 1: print("getting paired MSA") out_paired = run_mmseqs2_wrapper(u_seqs, f"{path}/", use_pairing=True) headers, sequences = [],[] for a3m_lines in out_paired: n = -1 for line in a3m_lines.split("\n"): if len(line) > 0: if line.startswith(">"): n += 1 if len(headers) < (n + 1): headers.append([]) sequences.append([]) ``` -------------------------------- ### Colab Development Setup - Install ColabFold Source: https://github.com/sokrypton/colabfold/blob/main/Contributing.md Bash script for setting up ColabFold development directly within a Google Colab environment, including installing the latest pip, cloning the repository, and linking it. ```bash %%bash pip install -U pip git clone https://github.com/sokrypton/Colabfold _colabfold pip install _colabfold # Unholy Hack: Use the files from our cloned git repository instead of installed copy site_packages=$(python -c 'import site; print(site.getsitepackages()[0])') rm -r ${site_packages}/colabfold ln -s $(pwd)/_colabfold/colabfold ${site_packages}/colabfold ``` -------------------------------- ### Starting with an existing clustering Source: https://github.com/sokrypton/colabfold/wiki/Creating-expandable-search-databases This section provides a step-by-step guide to creating an expandable search database when you already have an existing clustering. It includes commands for creating a database, converting a TSV mapping to a database, aligning sequences, generating profiles, creating a consensus, and finally creating an exprofile database. ```bash mmseqs createdb "INPUT.fasta" seqdb # take a look at the seqdb.lookup # you need to create a TSV mapping with numeric values (first column) of your sequence accessions (second column) for your clustering # e.g. you have a .lookup with # 0 Q9HGP0 0 # 1 Q9HGP1 1 # ... # You need to create a TSV: # 0 0 # 0 1 # 0 2 # 3 4 # ... # This means cluster 0 (Q9HGP0) contains sequences 0 (Q9HGP0), 1 (Q9HGP1), 2, cluster 3 contains sequence 4, ... mmseqs tsv2db NEW_TSV clu --output-dbtype 6 # disable E-value threshold with -e inf, accept everything that was clustered mmseqs align seqdb seqdb clu aln -a -e inf mmseqs result2profile seqdb seqdb aln prof mmseqs profile2consensus prof cons DBNAME=GIVE_THIS_A_GOOOD_NAME mmseqs prefixid cons ${DBNAME}.tsv --tsv --threads 1 mmseqs prefixid seqdb ${DBNAME}_seq.tsv --tsv --threads 1 mmseqs prefixid seqdb_h ${DBNAME}_h.tsv --tsv --threads 1 mmseqs prefixid aln ${DBNAME}_aln.tsv --tsv --threads 1 DBDIR=YOUR_FINAL_DB_DIR mkdir -p ${DBDIR} mmseqs tsv2exprofiledb ${DBNAME} ${DBDIR}/${DBNAME} ``` -------------------------------- ### Start GPU server(s) Source: https://github.com/sokrypton/colabfold/blob/main/README.md Commands to start MMseqs2 GPU servers, which hold databases in GPU memory for reduced latency. ```bash mmseqs gpuserver /path/to/db_folder/colabfold_envdb_202108_db --max-seqs 10000 --db-load-mode 0 --prefilter-mode 1 & PID1=$! mmseqs gpuserver /path/to/db_folder/uniref30_2302_db --max-seqs 10000 --db-load-mode 0 --prefilter-mode 1 & PID2=$! ``` -------------------------------- ### Setup Conda Environment Source: https://github.com/sokrypton/colabfold/blob/main/batch/AlphaFold2_batch.ipynb This script sets up the Conda environment, installing necessary packages like kalign2, hhsuite, and openmm if specified by environment variables. ```shell # setup conda if [ ${USE_AMBER} == "True" ] || [ ${USE_TEMPLATES} == "True" ]; then if [ ! -f CONDA_READY ]; then wget -qnc https://github.com/conda-forge/miniforge/releases/download/25.3.1-0/Miniforge3-25.3.1-0-Linux-x86_64.sh bash Miniforge3-25.3.1-0-Linux-x86_64.sh -bfp /usr/local 2>&1 1>/dev/null rm Miniforge3-25.3.1-0-Linux-x86_64.sh conda config --set auto_update_conda false touch CONDA_READY fi fi # setup template search if [ ${USE_TEMPLATES} == "True" ] && [ ! -f HH_READY ]; then conda install -y -q -c conda-forge -c bioconda kalign2=2.04 hhsuite=3.3.0 python="${PYTHON_VERSION}" 2>&1 1>/dev/null touch HH_READY fi # setup openmm for amber refinement if [ ${USE_AMBER} == "True" ] && [ ! -f AMBER_READY ]; then conda install -y -q -c conda-forge openmm=8.2.0 python="${PYTHON_VERSION}" pdbfixer 2>&1 1>/dev/null touch AMBER_READY fi ``` -------------------------------- ### Install Poetry and Project Dependencies Source: https://github.com/sokrypton/colabfold/blob/main/Contributing.md Steps to install poetry, clone the ColabFold repository, and install its dependencies, including the AlphaFold extras. ```shell curl -sSL https://install.python-poetry.org | python3 - poetry config virtualenvs.in-project true git clone https://github.com/sokrypton/ColabFold cd ColabFold poetry install -E alphafold ``` -------------------------------- ### Install AlphaFold Fork Source: https://github.com/sokrypton/colabfold/blob/main/Contributing.md Instructions to clone and install the AlphaFold fork if modifications are intended. ```shell git clone https://github.com/steineggerlab/alphafold pip install -e alphafold ``` -------------------------------- ### GPU database setup command Source: https://github.com/sokrypton/colabfold/blob/main/README.md Command to set up GPU databases for ColabFold using MMseqs2-GPU. ```bash GPU=1 ./setup_databases.sh /path/to/db_folder ``` -------------------------------- ### Install JAX with CUDA Support Source: https://github.com/sokrypton/colabfold/blob/main/Contributing.md Command to install the JAX library with CUDA support, which needs to be repeated after dependency updates. ```shell pip install -q "jax[cuda]>=0.3.8,<0.4" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html ``` -------------------------------- ### Starting from scratch Source: https://github.com/sokrypton/colabfold/wiki/Creating-expandable-search-databases This section outlines the process of creating an expandable search database from scratch. It includes steps for creating a database, clustering sequences with specified minimum sequence identity and coverage, aligning, generating profiles, creating a consensus, and finally creating an exprofile database. It also emphasizes the importance of parameter choice for clustering. ```bash mmseqs createdb "INPUT.fasta" seqdb # parameter choice is very important here, generally you want to cluster to a low sequence identity however keep a high coverage. # Without a high coverage, we might lose a domain in the representative sequence and then not be able to find the domain in any of the members anymore, since we always first need to match the cluster representative mmseqs cluster seqdb clu tmp --min-seq-id 0.3 -c 0.8 # disable E-value threshold with -e inf, accept everything that was clustered mmseqs align seqdb seqdb clu aln -a -e inf mmseqs result2profile seqdb seqdb aln prof mmseqs profile2consensus prof cons DBNAME=GIVE_THIS_A_GOOOD_NAME mmseqs prefixid cons ${DBNAME}.tsv --tsv --threads 1 mmseqs prefixid seqdb ${DBNAME}_seq.tsv --tsv --threads 1 mmseqs prefixid seqdb_h ${DBNAME}_h.tsv --tsv --threads 1 mmseqs prefixid aln ${DBNAME}_aln.tsv --tsv --threads 1 DBDIR=YOUR_FINAL_DB_DIR mkdir -p ${DBDIR} mmseqs tsv2exprofiledb ${DBNAME} ${DBDIR}/${DBNAME} ``` -------------------------------- ### Install dependencies Source: https://github.com/sokrypton/colabfold/blob/main/batch/AlphaFold2_batch.ipynb Installs necessary dependencies for ColabFold and downloads AlphaFold parameters. ```bash set -e USE_AMBER=$1 USE_TEMPLATES=$2 PYTHON_VERSION=$3 if [ ! -f COLABFOLD_READY ]; then # install dependencies # We have to use "--no-warn-conflicts" because colab already has a lot preinstalled with requirements different to ours pip install -q --no-warn-conflicts "colabfold[alphafold-minus-jax] @ git+https://github.com/sokrypton/ColabFold" if [ -n "${TPU_NAME}" ]; then pip install -q --no-warn-conflicts -U dm-haiku==0.0.10 jax==0.3.25 fi ln -s /usr/local/lib/python3.*/dist-packages/colabfold colabfold ln -s /usr/local/lib/python3.*/dist-packages/alphafold alphafold # hack to fix TF crash rm -f /usr/local/lib/python3.*/dist-packages/tensorflow/core/kernels/libtfkernel_sobol_op.so /usr/local/lib/python3.*/dist-packages/tensorflow/lite/python/*/*.so touch COLABFOLD_READY fi # Download params (~1min) python -m colabfold.download ``` -------------------------------- ### Install ESMFold, OpenFold, and Download Parameters Source: https://github.com/sokrypton/colabfold/blob/main/ESMFold.ipynb This code block installs necessary libraries, OpenFold, and ESMFold, and downloads the model parameters. It includes checks to avoid re-installation and waits for downloads to complete. ```python %%time #@title install #@markdown install ESMFold, OpenFold and download Params (~2min 30s) version = "1" # @param ["0", "1"] model_name = "esmfold_v0.model" if version == "0" else "esmfold.model" import os, time if not os.path.isfile(model_name): # download esmfold params os.system("apt-get install aria2 -qq") os.system(f"aria2c -q -x 16 https://colabfold.steineggerlab.workers.dev/esm/{model_name} &") if not os.path.isfile("finished_install"): # install libs print("installing libs...") os.system("pip install -q omegaconf pytorch_lightning biopython ml_collections einops py3Dmol modelcif") os.system("pip install -q git+https://github.com/NVIDIA/dllogger.git") print("installing openfold...") # install openfold os.system(f"pip install -q git+https://github.com/sokrypton/openfold.git") print("installing esmfold...") # install esmfold os.system(f"pip install -q git+https://github.com/sokrypton/esm.git") os.system("touch finished_install") # wait for Params to finish downloading... while not os.path.isfile(model_name): time.sleep(5) if os.path.isfile(f"{model_name}.aria2"): print("downloading params...") while os.path.isfile(f"{model_name}.aria2"): time.sleep(5) ``` -------------------------------- ### Install dependencies Source: https://github.com/sokrypton/colabfold/blob/main/Boltz1.ipynb This code block installs necessary dependencies for ColabFold and Boltz, including ColabFold itself, and optionally configures JAX for TPUs. It also downloads pre-trained weights for Boltz. ```python #@title Install dependencies %%time import os if not os.path.isfile("COLABFOLD_READY"): print("installing colabfold...") os.system("pip install -q --no-warn-conflicts 'colabfold[alphafold-minus-jax] @ git+https://github.com/sokrypton/ColabFold'") if os.environ.get('TPU_NAME', False) != False: os.system("pip uninstall -y jax jaxlib") 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") os.system("ln -s /usr/local/lib/python3.*/dist-packages/colabfold colabfold") os.system("ln -s /usr/local/lib/python3.*/dist-packages/alphafold alphafold") # hack to fix TF crash os.system("rm -f /usr/local/lib/python3.*/dist-packages/tensorflow/core/kernels/libtfkernel_sobol_op.so /usr/local/lib/python3.*/dist-packages/tensorflow/lite/python/*/*.so") os.system("touch COLABFOLD_READY") if not os.path.isfile("BOLZ_READY"): os.system("apt-get install -y aria2") os.system("pip install -q --no-warn-conflicts boltz") os.system("mkdir weights") os.system("aria2c -d weights -x8 -s8 https://colabfold.steineggerlab.workers.dev/boltz1.ckpt") os.system("aria2c -d weights -x8 -s8 https://colabfold.steineggerlab.workers.dev/ccd.pkl") os.system("touch BOLZ_READY") ``` -------------------------------- ### Display structure widget setup Source: https://github.com/sokrypton/colabfold/blob/main/BioEmu.ipynb Sets up interactive widgets for selecting clusters and samples to display protein structures. ```python #@title Display structure import os import ipywidgets as widgets import py3Dmol from IPython.display import display, clear_output # Create interactive widgets for cluster and sample selection. cluster_slider = widgets.IntSlider( value=0, min=0, max=n_clusters - 1, step=1, description='Cluster No:', continuous_update=False ) sample_slider = widgets.IntSlider( value=0, min=0, max=0, # will update based on the selected cluster step=1, description='Sample Idx:', continuous_update=False ) display(cluster_slider, sample_slider) ``` -------------------------------- ### Install dependencies Source: https://github.com/sokrypton/colabfold/blob/main/BioEmu.ipynb Installs necessary dependencies including Miniconda, BioEmu, and Foldseek. ```python #@title Install dependencies import os import sys _is_bioemu_setup_file = '/content/.BIOEMU_SETUP' conda_prefix = '/usr/local/' miniconda_link = 'https://repo.anaconda.com/miniconda/Miniconda3-py312_25.5.1-1-Linux-x86_64.sh' miniconda_basename = os.path.basename(miniconda_link) os.makedirs(conda_prefix, exist_ok=True) if not os.path.exists(_is_bioemu_setup_file): os.system(f'wget {miniconda_link}') os.system(f'chmod +x {miniconda_basename}') os.system(f'./{miniconda_basename} -b -f -p {conda_prefix}') os.system(f'conda install -q -y --prefix {conda_prefix} python=3.12') os.system('uv pip install --prerelease if-necessary-or-explicit bioemu') os.system('conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main') os.system('conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r') os.system('conda install -c conda-forge openmm cuda-version=11 --yes') sys.path.append(os.path.join(conda_prefix, 'lib/python3.12/site-packages/')) os.environ['CONDA_PREFIX'] = conda_prefix os.environ['CONDA_PREFIX_1'] = os.path.join(conda_prefix, 'envs/myenv') os.environ['CONDA_DEFAULT_ENV'] = 'base' os.system(f"touch {_is_bioemu_setup_file}") os.system('wget https://mmseqs.com/foldseek/foldseek-linux-avx2.tar.gz; tar xvzf foldseek-linux-avx2.tar.gz') os.system('/usr/bin/python3 -m pip install uv') os.unlink(miniconda_basename) ``` -------------------------------- ### MSA Generation and Job Setup Source: https://github.com/sokrypton/colabfold/blob/main/RoseTTAFold2.ipynb This code snippet handles sequence processing, MSA generation based on different methods, and job naming. ```python max_extra_msa = max_msa * 8 sequence = re.sub("[^A-Z:]", "", sequence.replace("/",":").upper()) sequence = re.sub(":+",":",sequence) sequence = re.sub("^[:]+","",sequence) sequence = re.sub("[:]+" ,"",sequence) if sym in ["X","C"]: copies = order elif sym in ["D"]: copies = order * 2 else: copies = {"T":12,"O":24,"I":60}[sym] order = "" symm = sym + str(order) sequences = sequence.replace(":","/").split("/") if collapse_identical: u_sequences = get_unique_sequences(sequences) else: u_sequences = sequences sequences = sum([u_sequences] * copies,[]) lengths = [len(s) for s in sequences] # TODO #subcrop = 1000 if sum(lengths) > 1400 else -1 subcrop = -1 topk = 1536 sequence = "/".join(sequences) jobname = jobname+"_"+symm+"_"+get_hash(sequence)[:5] print(f"jobname: {jobname}") print(f"lengths: {lengths}") os.makedirs(jobname, exist_ok=True) if msa_method == "mmseqs2": get_msa(u_sequences, jobname, mode=pair_mode, max_msa=max_extra_msa) elif msa_method == "single_sequence": u_sequence = "/".join(u_sequences) with open(f"{jobname}/msa.a3m","w") as a3m: a3m.write(f">{jobname}\n{u_sequence}\n") elif msa_method == "custom_a3m": print("upload custom a3m") msa_dict = files.upload() lines = msa_dict[list(msa_dict.keys())[0]].decode().splitlines() a3m_lines = [] for line in lines: line = line.replace("\x00","") if len(line) > 0 and not line.startswith('#'): a3m_lines.append(line) with open(f"{jobname}/msa.a3m","w") as a3m: a3m.write("\n".join(a3m_lines)) best_plddt = None best_seed = None for seed in range(random_seed,random_seed+num_models): torch.manual_seed(seed) random.seed(seed) np.random.seed(seed) npz = f"{jobname}/rf2_seed{seed}_00.npz" pred.predict(inputs=[f"{jobname}/msa.a3m"], out_prefix=f"{jobname}/rf2_seed{seed}", symm=symm, ffdb=None, #TODO (templates), n_recycles=num_recycles, msa_mask=0.15 if use_mlm else 0.0, msa_concat_mode=msa_concat_mode, nseqs=max_msa, nseqs_full=max_extra_msa, subcrop=subcrop, topk=topk, is_training=use_dropout) plddt = np.load(npz)["lddt"].mean() if best_plddt is None or plddt > best_plddt: best_plddt = plddt best_seed = seed ``` -------------------------------- ### Install and import libraries Source: https://github.com/sokrypton/colabfold/blob/main/RoseTTAFold.ipynb This code block installs necessary libraries, downloads RoseTTAFold model weights and SCWRL4, and applies a patch to the Refine_module.py file. It also sets up the Python path for RoseTTAFold modules. ```python #@title ##Install and import libraries #@markdown This step can take up to ~2 mins import os import sys from IPython.utils import io from google.colab import files import torch torch_v = torch.__version__ if not os.path.isdir("RoseTTAFold"): with io.capture_output() as captured: # extra functionality %shell wget -qnc https://raw.githubusercontent.com/sokrypton/ColabFold/main/beta/colabfold.py # download model %shell git clone https://github.com/RosettaCommons/RoseTTAFold.git %shell wget -qnc https://raw.githubusercontent.com/sokrypton/ColabFold/main/beta/RoseTTAFold__network__Refine_module.patch %shell patch -u RoseTTAFold/network/Refine_module.py -i RoseTTAFold__network__Refine_module.patch # download model params %shell wget -qnc https://files.ipd.uw.edu/pub/RoseTTAFold/weights.tar.gz %shell tar -xf weights.tar.gz %shell rm weights.tar.gz # download scwrl4 (for adding sidechains) # http://dunbrack.fccc.edu/SCWRL3.php # Thanks Roland Dunbrack! %shell wget -qnc https://files.ipd.uw.edu/krypton/TrRosetta/scwrl4.zip %shell unzip -qqo scwrl4.zip # install libraries %shell pip install -q dgl-cu113 -f https://data.dgl.ai/wheels/repo.html %shell pip install -q torch-scatter -f https://pytorch-geometric.com/whl/torch-{torch_v}.html %shell pip install -q torch-sparse -f https://pytorch-geometric.com/whl/torch-{torch_v}.html %shell pip install -q torch-geometric %shell pip install -q py3Dmol with io.capture_output() as captured: sys.path.append('/content/RoseTTAFold/network') import predict_e2e from parsers import parse_a3m import colabfold as cf import py3Dmol import subprocess import numpy as np import matplotlib.pyplot as plt def get_bfactor(pdb_filename): bfac = [] for line in open(pdb_filename,"r"): if line[:4] == "ATOM": bfac.append(float(line[60:66])) return np.array(bfac) def set_bfactor(pdb_filename, bfac): I = open(pdb_filename,"r").readlines() O = open(pdb_filename,"w") for line in I: if line[0:6] == "ATOM ": seq_id = int(line[22:26].strip()) - 1 O.write(f"{line[:60]}{bfac[seq_id]:6.2f}{line[66:]}") O.close() def do_scwrl(inputs, outputs, exe="./scwrl4/Scwrl4"): subprocess.run([exe," -i",inputs," -o",outputs," -h"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) bfact = get_bfactor(inputs) set_bfactor(outputs, bfact) return bfact ``` -------------------------------- ### Run Prediction Setup Source: https://github.com/sokrypton/colabfold/blob/main/AlphaFold2.ipynb This code block sets up the environment for running the prediction, including importing necessary libraries, setting up logging, and handling potential GPU warnings (e.g., for Tesla K80). ```python #@title Run Prediction display_images = True #@param {type:"boolean"} import sys import warnings warnings.simplefilter(action='ignore', category=FutureWarning) from Bio import BiopythonDeprecationWarning warnings.simplefilter(action='ignore', category=BiopythonDeprecationWarning) from pathlib import Path from colabfold.download import download_alphafold_params, default_data_dir from colabfold.utils import setup_logging from colabfold.batch import get_queries, run, set_model_type from colabfold.plot import plot_msa_v2 import os import numpy as np try: K80_chk = os.popen('nvidia-smi | grep "Tesla K80" | wc -l').read() except: K80_chk = "0" pass if "1" in K80_chk: print("WARNING: found GPU Tesla K80: limited to total length < 1000") if "TF_FORCE_UNIFIED_MEMORY" in os.environ: del os.environ["TF_FORCE_UNIFIED_MEMORY"] if "XLA_PYTHON_CLIENT_MEM_FRACTION" in os.environ: del os.environ["XLA_PYTHON_CLIENT_MEM_FRACTION"] from colabfold.colabfold import plot_protein from pathlib import Path import matplotlib.pyplot as plt ``` -------------------------------- ### ColabFold Installation with Conda and Pip Source: https://github.com/sokrypton/colabfold/blob/main/README.md Instructions for installing ColabFold using Conda and Pip, including options for CUDA GPU support, CPU-only, and colabfold_search only. ```shell conda create -n colabfold -c conda-forge -c bioconda python=3.13 kalign2=2.04 hhsuite=3.3.0 mmseqs2=18.8cc5c conda activate colabfold # With CUDA GPU support pip install colabfold[alphafold,openmm] jax[cuda] openmm[cuda12] extra-colabfold # CPU only pip install colabfold[alphafold,openmm] extra-colabfold # For colabfold_search only (no structure prediction) pip install colabfold ``` -------------------------------- ### FASTA format for non-protein molecules Source: https://github.com/sokrypton/colabfold/blob/main/README.md Example FASTA entries demonstrating how to include non-protein molecules like DNA, RNA, and ligands, with options for multiple copies. ```fasta >Complex1|Prot1:Prot2:Lig FIRSTPROTEIN:SECONDPROTEIN:ccd|ATP|2 >Complex2|Prot1:Prot2:Lig FIRSTPROTEIN:SECONDPROTEIN:ccd|ATP:ccd|ATP ``` -------------------------------- ### Run colabfold_search for On-the-fly MSA Generation Source: https://github.com/sokrypton/colabfold/wiki/Home Command to execute colabfold_search for on-the-fly MSA generation, ignoring any precomputed index and specifying the database folder and output folder. ```bash MMSEQS_IGNORE_INDEX=1 colabfold_search queries.fa /path/to/db_folder output_folder ``` -------------------------------- ### AlphaFold2 Prediction and Setup Source: https://github.com/sokrypton/colabfold/blob/main/AlphaFold2.ipynb This code block sets up the environment, defines callbacks for input features and predictions, configures logging, retrieves queries, determines model type, downloads parameters, and runs the AlphaFold2 prediction process. It also includes a command to zip the results. ```python if use_amber and f"/usr/local/lib/python{python_version}/site-packages/" not in sys.path: sys.path.insert(0, f"/usr/local/lib/python{python_version}/site-packages/") def input_features_callback(input_features): if display_images: plot_msa_v2(input_features) plt.show() plt.close() def prediction_callback(protein_obj, length, prediction_result, input_features, mode): model_name, relaxed = mode if not relaxed: if display_images: fig = plot_protein(protein_obj, Ls=length, dpi=150) plt.show() plt.close() result_dir = jobname log_filename = os.path.join(jobname,"log.txt") setup_logging(Path(log_filename)) queries, is_complex = get_queries(queries_path) model_type = set_model_type(is_complex, model_type) if "multimer" in model_type and max_msa is not None: use_cluster_profile = False else: use_cluster_profile = True download_alphafold_params(model_type, Path(".")) results = run( queries=queries, result_dir=result_dir, use_templates=use_templates, custom_template_path=custom_template_path, num_relax=num_relax, msa_mode=msa_mode, model_type=model_type, num_models=5, num_recycles=num_recycles, relax_max_iterations=relax_max_iterations, recycle_early_stop_tolerance=recycle_early_stop_tolerance, num_seeds=num_seeds, use_dropout=use_dropout, model_order=[1,2,3,4,5], is_complex=is_complex, data_dir=Path("."), keep_existing_results=False, rank_by="auto", pair_mode=pair_mode, pairing_strategy=pairing_strategy, stop_at_score=float(100), prediction_callback=prediction_callback, dpi=dpi, zip_results=False, save_all=save_all, max_msa=max_msa, use_cluster_profile=use_cluster_profile, input_features_callback=input_features_callback, save_recycles=save_recycles, user_agent="colabfold/google-colab-main", calc_extra_ptm=calc_extra_ptm, ) results_zip = f"{jobname}.result.zip" os.system(f"zip -r {results_zip} {jobname}") ``` -------------------------------- ### Colab Development Setup - Patch AlphaFold Source: https://github.com/sokrypton/colabfold/blob/main/Contributing.md Bash script for setting up AlphaFold development within a Google Colab environment, including uninstalling existing versions, cloning the fork, and installing it in editable mode. ```bash %%bash pip uninstall -y alphafold git clone https://github.com/sokrypton/alphafold _alphafold pip install -e ./_alphafold ``` -------------------------------- ### Write samples and run `foldseek` Source: https://github.com/sokrypton/colabfold/blob/main/BioEmu.ipynb Selects samples, writes them as PDB files, and prepares for Foldseek clustering. Includes parameters for sample selection and clustering thresholds. ```python #@title Write samples and run `foldseek` #@markdown - `n_write_samples`: Number of samples to randomly select for clustering. Set to `-1` to select all available samples #@markdown - `tmscore_threshold`: TM-score threshold used for foldseek clustering #@markdown - `coverage_threshold`: Coverage threshold used for foldseek clustering #@markdown - `seq_id`: Sequence identity threshold used for foldseek clustering n_write_samples = -1 #@param {type:"integer"} tmscore_threshold = 0.6 #@param {type: "number"} coverage_threshold = 0.7 #@param {type: "number"} seq_id = 0.95 #@param {type: "number"} import numpy as np import mdtraj _py3dmol_installed_file = '/content/.py3dmol' if not os.path.exists(_py3dmol_installed_file): os.system('uv pip install py3Dmol') os.system(f"touch {_py3dmol_installed_file}") import py3Dmol pdb_sample_dir = os.path.join('/content', 'pdb_samples') os.makedirs(pdb_sample_dir, exist_ok=True) def write_some_samples(topology_file: str, trajectory_file: str, output_dir:str, n_samples: int) -> None: traj = mdtraj.load(trajectory_file, top=topology_file) assert traj.n_frames >= n_samples if n_samples == -1: sample_indices = np.arange(traj.n_frames) else: sample_indices = np.random.choice(np.arange(traj.n_frames), size=n_samples, replace=False) for idx in sample_indices: traj[idx].save_pdb(os.path.join(output_dir, f'sample_{idx}.pdb')) topology_file = os.path.join(output_dir, "topology.pdb") trajectory_file = os.path.join(output_dir, "samples.xtc") write_some_samples(topology_file=topology_file, trajectory_file=trajectory_file, output_dir=pdb_sample_dir, n_samples=n_write_samples) ``` -------------------------------- ### Install Dependencies Source: https://github.com/sokrypton/colabfold/blob/main/AlphaFold2.ipynb Installs necessary ColabFold and other dependencies. ```python #@title Install dependencies %%time import os USE_AMBER = use_amber USE_TEMPLATES = use_templates PYTHON_VERSION = python_version if not os.path.isfile("COLABFOLD_READY"): print("installing colabfold...") os.system("pip install -q --no-warn-conflicts 'colabfold[alphafold-minus-jax] @ git+https://github.com/sokrypton/ColabFold'") if os.environ.get('TPU_NAME', False) != False: os.system("pip uninstall -y jax jaxlib") 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") os.system("ln -s /usr/local/lib/python3.*/dist-packages/colabfold colabfold") os.system("ln -s /usr/local/lib/python3.*/dist-packages/alphafold alphafold") # hack to fix TF crash os.system("rm -f /usr/local/lib/python3.*/dist-packages/tensorflow/core/kernels/libtfkernel_sobol_op.so /usr/local/lib/python3.*/dist-packages/tensorflow/lite/python/*/*.so") os.system("touch COLABFOLD_READY") if USE_AMBER or USE_TEMPLATES: if not os.path.isfile("CONDA_READY"): print("installing conda...") os.system("wget -qnc https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh") os.system("bash Miniforge3-Linux-x86_64.sh -bfp /usr/local") os.system("mamba config --set auto_update_conda false") os.system("touch CONDA_READY") if USE_TEMPLATES and not os.path.isfile("HH_READY") and USE_AMBER and not os.path.isfile("AMBER_READY"): print("installing hhsuite and amber...") 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") os.system("touch HH_READY") os.system("touch AMBER_READY") else: if USE_TEMPLATES and not os.path.isfile("HH_READY"): print("installing hhsuite...") os.system(f"mamba install -y -c conda-forge -c bioconda kalign2=2.04 hhsuite=3.3.0 python='{PYTHON_VERSION}'") os.system("touch HH_READY") if USE_AMBER and not os.path.isfile("AMBER_READY"): print("installing amber...") os.system(f"mamba install -y -c conda-forge openmm=8.2.0 python='{PYTHON_VERSION}' pdbfixer") os.system("touch AMBER_READY") ``` -------------------------------- ### Create Settings File Source: https://github.com/sokrypton/colabfold/blob/main/RoseTTAFold2.ipynb Python code to create a settings file for RoseTTAFold2, specifying various parameters. ```python settings_path = f"{jobname}/settings.txt" with open(settings_path, "w") as text_file: text_file.write(f"method=RoseTTAFold2\n") text_file.write(f"params={params}\n") text_file.write(f"sequence={sequence}\n") text_file.write(f"sym={sym}\n") text_file.write(f"order={order}\n") text_file.write(f"msa_concat_mode={msa_concat_mode}\n") text_file.write(f"collapse_identical={collapse_identical}") text_file.write(f"random_seed={random_seed}\n") text_file.write(f"msa_method={msa_method}\n") text_file.write(f"num_recycles={num_recycles}\n") text_file.write(f"use_mlm={use_mlm}\n") text_file.write(f"use_dropout={use_dropout}\n") text_file.write(f"num_models={num_models}\n") ``` -------------------------------- ### Input protein sequence, then hit `Runtime` -> `Run all` Source: https://github.com/sokrypton/colabfold/blob/main/batch/AlphaFold2_batch.ipynb Configures input and output directories, and advanced settings for the protein structure prediction. ```python #@param {type: "string"} input_dir = '/content/drive/MyDrive/input_fasta' #@param {type:"string"} result_dir = '/content/drive/MyDrive/result' #@param {type:"string"} # number of models to use #@markdown --- #@markdown ### Advanced settings msa_mode = "MMseqs2 (UniRef+Environmental)" #@param ["MMseqs2 (UniRef+Environmental)", "MMseqs2 (UniRef only)","single_sequence","custom"] num_models = 5 #@param [1,2,3,4,5] {type:"raw"} num_recycles = 3 #@param [1,3,6,12,24,48] {type:"raw"} stop_at_score = 100 #@param {type:"string"} #@markdown - early stop computing models once score > threshold (avg. plddt for "structures" and ptmscore for "complexes") use_custom_msa = False num_relax = 0 #@param [0, 1, 5] {type:"raw"} use_amber = num_relax > 0 relax_max_iterations = 200 #@param [0,200,2000] {type:"raw"} use_templates = False #@param {type:"boolean"} do_not_overwrite_results = True #@param {type:"boolean"} zip_results = False #@param {type:"boolean"} ``` -------------------------------- ### Predict Structures with colabfold_batch Source: https://github.com/sokrypton/colabfold/wiki/Home Command to predict protein structures using the generated MSAs from the output folder. ```bash colabfold_batch output_folder output_predictions_folder ``` -------------------------------- ### Keep search databases in system memory Source: https://github.com/sokrypton/colabfold/blob/main/MsaServer/README.md Command to ensure search databases remain in system memory using vmtouch, crucial for fast response times. ```bash cd databases sudo vmtouch -f -w -t -l -d -m 1000G *.idx ``` -------------------------------- ### Run colabfold_search for Single-query MSA Generation Source: https://github.com/sokrypton/colabfold/wiki/Home Command to execute colabfold_search for single-query MSA generation, using prefilter-mode 1 for a different prefiltering strategy. ```bash MMSEQS_IGNORE_INDEX=1 colabfold_search queries.fa /path/to/db_folder output_folder --prefilter-mode 1 ``` -------------------------------- ### Generating MSAs with colabfold_batch Source: https://github.com/sokrypton/colabfold/blob/main/README.md Demonstrates how to use `colabfold_batch` to generate MSAs and predict structures, with an option to split MSA querying and prediction into separate steps. ```shell # Query the MSA server and predict the structure on local GPU in one go: colabfold_batch input_sequences.fasta out_dir # Split querying MSA server and GPU predictions into two steps colabfold_batch input_sequences.fasta out_dir --msa-only colabfold_batch input_sequences.fasta out_dir ```