OpenFold Documentation

repository·main·Indexed 25 days ago

https://github.com/aqlaboratory/openfold

OpenFold is a trainable PyTorch reproduction of DeepMind's AlphaFold 2, designed for model inference, training, and research into protein structure prediction. It supports Monomer, Multimer, and Single Sequence (Soloseq) inference modes. The documentation covers installation, the use of the OpenProteinSet database structure, converting v1 checkpoints to v2 weights, and troubleshooting CUDA and GLIBCXX errors.

Tokens
15.9K
Snippets
38
Records
73
Agent score
85%

What's inside OpenFold

  1. Overview of OpenFold Inference Modes

    main

    OpenFold supports three distinct modes of inference prediction:

    • Monomer: Standard single-chain prediction.
    • Multimer: Prediction for protein complexes.
    • Single Sequence (Soloseq): Prediction based on a single sequence without MSA.

    This documentation provides specific guides for each mode (e.g., Multimer_Inference.md and Single_Sequence_Inference.md).

  2. Understand OpenFold licensing and pretrained parameters

    main

    OpenFold's source code is licensed under the Apache Licence, Version 2.0.

    DeepMind's pretrained parameters are licensed under CC BY 4.0. A copy of this license is downloaded to openfold/resources/params by the installation script. (Note: This replaced the more restrictive CC BY-NC 4.0 license as of January 2022).

  3. Understand the OpenFold DB file structure

    main

    OpenFold uses a condensed filesystem structure to minimize I/O overhead during training. Instead of a directory per protein chain, it uses consolidated database files and index files.

    A typical OpenProteinSet directory structure looks like this:

    - OpenProteinSet 
      ├── duplicate_pdb_chains.txt
      └── pdb
    	  ├── mmcif_cache.json 
    	  ├── mmcifs 
    	  │   ├── 3lrm.cif
    	  │   └── 6kwc.cif
    	  └── alignment_db
    	      ├── alignment_db_0.db 
    	      ├── alignment_db_1.db 
    	      │   ...
    	      └── alignment_db.index 
  4. Run Multimer Inference

    main

    To run inference on a complex or multiple complexes using DeepMind's pretrained parameters, use the run_pretrained_openfold.py script. This pipeline uses HMMSearch with the PDB SeqRes database instead of HHSearch and PDB70 used in monomer mode.

    Required Databases/Tools:

    • UniProt, PDB SeqRes, UniRef30 (upgraded), MGnify (upgraded), BFD.
    • Binaries: jackhmmer, hhblits, hmmsearch, hmmbuild, kalign.

    Upgrade Note: If upgrading an existing installation, you must re-download AlphaFold-Multimer v3 weights, UniProt, PDB SeqRes, and the upgraded MGnify/UniRef30 databases.

    python3 run_pretrained_openfold.py \
        fasta_dir \
        data/pdb_mmcif/mmcif_files/ \
        --uniref90_database_path data/uniref90/uniref90.fasta \
        --mgnify_database_path data/mgnify/mgy_clusters_2022_05.fa \
        --pdb_seqres_database_path data/pdb_seqres/pdb_seqres.txt \
        --uniref30_database_path data/uniref30/UniRef30_2021_03 \
        --uniprot_database_path data/uniprot/uniprot.fasta \
        --bfd_database_path data/bfd/bfd_metaclust_clu_complete_id30_c90_final_seq.sorted_opt \
        --jackhmmer_binary_path lib/conda/envs/openfold_venv/bin/jackhmmer \
        --hhblits_binary_path lib/conda/envs/openfold_venv/bin/hhblits \
        --hmmsearch_binary_path lib/conda/envs/openfold_venv/bin/hmmsearch \
        --hmmbuild_binary_path lib/conda/envs/openfold_venv/bin/hmmbuild \
        --kalign_binary_path lib/conda/envs/openfold_venv/bin/kalign \
        --config_preset "model_1_multimer_v3" \
        --model_device "cuda:0" \
        --output_dir ./ 
  5. Create sharded alignment databases (optional)

    main

    For systems with I/O bottlenecks, you can use alignment_db files instead of standard alignment directories. This increases training performance. It is recommended to create 10 shards for better filesystem health. The script runs optimally if the number of CPUs is $\ge$ the number of shards.

    python $OF_DIR/scripts/alignment_db_scripts/create_alignment_db_sharded.py \
        alignment_data/alignments \
        alignment_data/alignment_dbs \
        alignment_db \
        --n_shards 10 \
        --duplicate_chains_file pdb_data/duplicate_pdb_chains.txt
  6. Convert OpenFold v1 checkpoints to v2 weights

    main

    If you have checkpoints trained with OpenFold v1 or older and want to resume training on OpenFold v2, you must convert them because certain model layers were renamed (e.g., module.model.template_angle_embedder.* is now module.model.template_embedder.template_single_embedder.*).

    Use the scripts/convert_v1_to_v2_weights.py script to perform the conversion.

    python scripts/convert_v1_to_v2_weights.py checkpoints/6-209.ckpt checkpoints/6-209.ckpt.converted
  7. Consolidate alignment directories into a database

    main

    To improve I/O performance in bottlenecked environments, you can consolidate alignment directories into a single database and index using scripts/alignment_db_scripts/:

    1. Run create_alignment_db.py to compile an alignment directory into database and index files.
    2. Run unify_alignment_db_indices.py to unify the indices into a super.index.
    3. Pass the resulting index to the training script using flags containing the phrase alignment_index. In this case, alignment_dir flags should point to the directory containing the compiled databases.
  8. Run SoloSeq inference using precomputed embeddings

    main

    Run MSA-free sequence-to-structure prediction using precomputed ESM-1b embeddings. If you wish to use templates, ensure *.hhr files are in the embeddings_output_dir and provide the PDB MMCIF dataset path.

    Note: The SoloSeq model is limited to a sequence length of 1022 residues; sequences longer than this will be truncated.

    python run_pretrained_openfold.py \
        fasta_dir \
        data/pdb_mmcif/mmcif_files/ \
        --use_precomputed_alignments embeddings_output_dir \
        --output_dir ./ \
        --model_device "cuda:0" \
        --config_preset "seq_model_esm1b_ptm" \
        --openfold_checkpoint_path openfold/resources/openfold_soloseq_params/seq_model_esm1b_ptm.pt
  9. Run SoloSeq (Single Sequence) Inference

    main

    SoloSeq is a language model-based structure prediction using ESM-1b embeddings. It is limited to sequences of up to 1022 residues (longer sequences will be truncated).

    Mode 1: Using Precomputed Embeddings (Faster)

    1. Precompute embeddings in bulk using scripts/precompute_embeddings.py: python scripts/precompute_embeddings.py fasta_dir/ embeddings_output_dir/
    2. Run inference using the --use_precomputed_alignments flag pointing to your embeddings directory.

    Mode 2: Generating Embeddings During Inference Skip the --use_precomputed_alignments argument. If you provide database paths and tools, HHSearch will also be used to find templates.

    Setup:

    1. Download SoloSeq weights: bash scripts/download_openfold_soloseq_params.sh openfold/resources
    2. Use config_preset "seq_model_esm1b_ptm" and provide the --openfold_checkpoint_path to the SoloSeq .pt file.
    # Example: Inference with precomputed embeddings
    python run_pretrained_openfold.py \
        fasta_dir \
        data/pdb_mmcif/mmcif_files/ \
        --use_precomputed_alignments embeddings_output_dir \
        --output_dir ./ \
        --model_device "cuda:0" \
        --config_preset "seq_model_esm1b_ptm" \
        --openfold_checkpoint_path openfold/resources/openfold_soloseq_params/seq_model_esm1b_ptm.pt
  10. Download Alignment Databases

    main

    Depending on your preferred MSA generation pipeline, use one of the following methods to download protein databases:

    1. DeepMind Pipeline (HMMR & HHblits): Use scripts/download_alphafold_dbs.sh.
    2. ColabFold Pipeline (MMseqs2): Use scripts/download_mmseqs_dbs.sh to download .tar files, then scripts/prep_mmseqs_dbs.sh to unpack and prepare them.

    Note: For the MMseqs2 pipeline, run the preparation script on the machine intended for MSA generation so it can correctly estimate database index splitting based on available memory.

    If using precomputed MSAs (e.g., from RODA), ensure the alignment_dir contains one directory per chain with corresponding .sto, .a3m, and .hhr files.

    # For DeepMind pipeline
    bash scripts/download_alphafold_dbs.sh data/
    
    # For ColabFold/MMseqs2 pipeline
    bash scripts/download_mmseqs_dbs.sh data/
    bash scripts/prep_mmseqs_dbs.sh data/