ColabFold

repository·main·Indexed 25 days ago

https://github.com/sokrypton/colabfold

A pipeline for protein structure and complex prediction using AlphaFold2 and AlphaFold 3. It replaces traditional homology detection with MMseqs2 for faster sequence alignments and provides a local API server implementation for hosting MSA services. Supports various MSA and pairing modes, template configurations, and integration with OpenFold3. Includes tools for setting up local API servers on Linux/macOS, managing systemd services, and optimizing database performance with vmtouch.

Tokens
29.8K
Snippets
51
Records
152
Agent score
83%

What's inside colabfold

  1. Set up a systemd service for the ColabFold API server

    main

    To ensure the server automatically restarts on failure and can be managed via systemctl and journalctl, follow these steps:

    1. Run ./setup-and-start-local.sh once to generate the necessary folder structure and binaries.
    2. Edit the provided systemd-example-mmseqs-server.service file, ensuring all paths point to your local installation.
    3. Execute the restart script to enable and start the service: ./restart-systemd.sh
    ./setup-and-start-local.sh
    # ... edit systemd-example-mmseqs-server.service ...
    ./restart-systemd.sh
  2. Force search databases to stay resident in system memory using `vmtouch`

    main

    To achieve response times of a few seconds, the search databases must be held fully within system memory. For the default databases (UniRef30 + ColabFoldDB), this typically requires 768GB-1024GB of RAM.

    After installing vmtouch, navigate to the databases directory and run the following command to prevent the database index files from being evicted from the system cache:

    cd databases
    sudo vmtouch -f -w -t -l -d -m 1000G *.idx
  3. Run the `setup-and-start-local.sh` script to set up the ColabFold API server

    main

    The setup-and-start-local.sh script automates the setup of a local ColabFold API server on Linux (or macOS for testing). It performs the following tasks:

    • Verifies required software (curl, aria2c, rsync, aws).
    • Downloads platform-specific MMseqs2 and mmseqs-server binaries.
    • Downloads databases (UniRef30 and ColabFoldDB).
    • Downloads and compiles the API server binary.
    • Starts the API server.

    Important Configuration Steps before running:

    1. Enable GPU (Linux only): Uncomment the export GPU=1 line inside the script. This adds --paths.colabfold.gpu.gpu 1 --paths.colabfold.gpu.server 1 to the server startup.
    2. Select PDB Mirror: At the top of the script, uncomment exactly one pair of PDB rsync mirrors (RCSB, PDBe, or PDBj). The script will exit if no mirror is selected.

    Quick Test Mode: To start the server with templates disabled and a tiny database for rapid testing, set the DEBUG_MINI_DB=1 environment variable.

  4. Configure the ColabFold API server via `config.json`

    main

    You can customize the API server behavior by editing config.json. Key configuration options include:

    • server.address: Change the bind address and port. (Note: It is recommended to use nginx as a reverse proxy for gzip and SSL support).
    • local.workers: Set the number of local job workers.
    • paths.colabfold.gpu: An optional block to pin specific device IDs per database when running in multi-GPU mode.
    • server.ratelimit: An optional setting to enable rate limiting (an example is provided in the config file).
  5. Install ColabFold and AlphaFold2 Dependencies

    main

    The following bash script installs the necessary Python packages, clones the ColabFold script, sets up the AlphaFold repository, and downloads the model parameters.

    Note: The script includes a patch to remove END and ENDMDL from PDB lines in alphafold/common/protein.py to prevent Biopython compatibility errors.

    # Example of the dependency installation logic used in the notebook
    pip -q install biopython dm-haiku ml-collections py3Dmol
    
    wget -qnc https://raw.githubusercontent.com/sokrypton/ColabFold/main/beta/colabfold.py
    
    if [ ! -d "alphafold/" ]; then
      git clone https://github.com/deepmind/alphafold.git --quiet
      mv alphafold alphafold_
      mv alphafold_/alphafold .
      sed -i "s/pdb_lines.append('END')//" /content/alphafold/common/protein.py
      sed -i "s/pdb_lines.append('ENDMDL')//" /content/alphafold/common/protein.py
    fi
    
    if [ ! -d "params/" ]; then
      wget -qnc https://storage.googleapis.com/alphafold/alphafold_params_2021-07-14.tar
      mkdir params
      tar -xf alphafold_params_2021-07-14.tar -C params/
      rm alphafold_params_2021-07-14.tar
    fi
  6. Use AlphaFold2 for Protein Complex Prediction

    main

    This notebook (now retired in favor of the AlphaFold2 advanced notebook) is designed for predicting structures of protein complexes.

    Key Usage Guidelines:

    • Monomers/Homo-oligomers: Use the standard AlphaFold2 notebook.
    • Prokaryotic Complexes: For complexes found in operons, it is recommended to use the pair_msa option.
    • Sequence Input: Use 'U' to indicate an 'UNKNOWN' residue. Note that 'U' residues will not be modeled, but a linker of at least 32 residues is required for the logic to function correctly.
    • Hardware Limits: For a typical Google Colab GPU (16G) session, the maximum total sequence length is 1400 residues.
  7. Install OmegaFold and dependencies

    main

    To use the experimental OmegaFold hacks, you must install the OmegaFold repository, its requirements, py3Dmol, aria2, hhsuite, and the colabfold.py script. This setup also involves downloading the model checkpoint release1.pt to ~/.cache/omegafold_ckpt/model.pt.

    Note: This setup is designed for a Colab-like environment where apt-get and pip are available.

    import os,sys,re
    from IPython.utils import io
    if "SETUP_DONE" not in dir():
      import torch
      device = "cuda" if torch.cuda.is_available() else "cpu"
      with io.capture_output() as captured:
        if not os.path.isdir("OmegaFold"):
          %shell git clone --quiet https://github.com/sokrypton/OmegaFold.git
          %shell cd OmegaFold; pip -q install -r requirements.txt
          %shell pip -q install py3Dmol
          %shell apt-get install aria2 -qq > /dev/null
          %shell aria2c -q -x 16 https://helixon.s3.amazonaws.com/release1.pt
          %shell mkdir -p ~/.cache/omegafold_ckpt
          %shell mv release1.pt ~/.cache/omegafold_ckpt/model.pt
          %shell wget -qnc https://github.com/soedinglab/hh-suite/releases/download/v3.3.0/hhsuite-3.3.0-SSE2-Linux.tar.gz
          %shell tar xfz hhsuite-3.3.0-SSE2-Linux.tar.gz
          %shell wget -qnc https://raw.githubusercontent.com/sokrypton/ColabFold/main/colabfold/colabfold.py
      os.environ['PATH'] += ":/content/bin:/content/scripts"
      SETUP_DONE = True
  8. Install ESMFold, OpenFold, and dependencies

    main

    To use the advanced ESMFold notebook, you must install the required libraries and download the model parameters. This process installs esmfold, openfold, and several dependencies like omegaconf, pytorch_lightning, and biopython. It also downloads the esmfold.model file using aria2c.

    Note on Colab Limitations: On a Tesla T4 GPU (standard free Colab), the maximum total sequence length is approximately 900 residues.

    import os, time
    import torch
    if not os.path.isfile("esmfold.model"):
      os.system("apt-get install aria2 -qq")
      os.system("aria2c -q -x 16 https://colabfold.steineggerlab.workers.dev/esm/esmfold.model &")
    
      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...")
      os.system(f"pip install -q git+https://github.com/sokrypton/openfold.git")
    
    print("installing esmfold...")
      os.system(f"pip install -q git+https://github.com/sokrypton/esm.git@beta")
    
      if not os.path.isfile("esmfold.model"):
        os.system("aria2c -q -x 16 https://files.ipd.uw.edu/pub/esmfold/esmfold.model")
      else:
        while os.path.isfile("esmfold.model.aria2"):
          time.sleep(5)
    
    if "model" not in dir():
      model_path = "esmfold.model"
      model = torch.load(model_path, weights_only=False)
      model.cuda().requires_grad_(False)
  9. Refine structures with Amber-Relax

    main

    After prediction, you can optionally refine the side-chain bond geometry using Amber-Relax. Note that this can approximately double the runtime and typically only affects side-chain geometry rather than the backbone.

    Options for num_relax:

    • None: No relaxation.
    • Top1: Relax only the highest-ranked structure.
    • Top5: Relax the top 5 ranked structures.
    • All: Relax all generated models.