How chaidiscovery/chai-lab works
Purpose and entry points
Chai-1 is a GPU/CUDA Python inference package for multimodal molecular structure prediction: proteins, small molecules, nucleic acids, glycans, covalent complexes, templates, MSAs, and experimental restraints. Primary APIs are chai_lab.chai1.run_inference and advanced context-based folding through run_folding_on_context in chai_lab/chai1.py. CLI packaging/commands are rooted in chai_lab/main.py; example invocation is in examples/predict_structure.py.
Input parsing and validation
FASTA and auxiliary inputs are parsed into typed molecular entities and constraints before inference. The parser handles protein/nucleic-acid sequences, ligand SMILES, glycans, structure data, MSA formats, templates, and restraint specifications. Key boundaries: user files become normalized internal entity/context representations.
Paths: chai_lab/data/parsing/fasta.py, chai_lab/data/parsing/input_validation.py, chai_lab/data/parsing/restraints.py.
Structural context assembly
AllAtomFeatureContext is the central inference payload, combining tokenized all-atom structure, optional embeddings, MSAs, template information, and restraint/covalent-bond data. inference_dataset builds model-ready examples from parsed inputs; atom tokenization establishes a shared representation across molecular modalities.
Paths: chai_lab/data/dataset/all_atom_feature_context.py, chai_lab/data/dataset/inference_dataset.py, chai_lab/data/dataset/structure/all_atom_residue_tokenizer.py.
Enrichment sources: MSA, templates, embeddings
Optional enrichments are separate from core sequence input. MSAs can be supplied as aligned parquet or obtained through a ColabFold/MMseqs2 server, then preprocessed into MSA context. Templates are selected from m8 hits and loaded from local CIFs or downloaded RCSB structures. ESM embedding support is represented as an embedding context.
Paths: chai_lab/data/dataset/msas/colabfold.py, chai_lab/data/dataset/templates/load.py, chai_lab/data/dataset/embeddings/esm.py.
Feature generation and batching
The feature factory converts assembled contexts into model tensors via specialized generators for residue/atom identity, relative positions, bonds, MSA/template features, docking, and distance/pocket restraints. Collation batches examples while preserving the model’s structured atom/token/pair inputs.
Paths: chai_lab/data/features/feature_factory.py, chai_lab/data/features/generators/, chai_lab/data/collate/collate.py.
Model execution and sampling
Inference orchestration in chai1.py downloads/locates weights, applies model and diffusion schedule utilities, generates multiple predicted structures, and writes output artifacts. The runtime requires Linux, Python 3.10+, CUDA, and bfloat16-capable GPUs; weight storage can be redirected with CHAI_DOWNLOADS_DIR.
Paths: chai_lab/chai1.py, chai_lab/model/diffusion_schedules.py, chai_lab/model/utils.py.
Output, ranking, and external boundaries
Predicted structures are serialized as PDB/CIF-compatible outputs and ranked using confidence and geometry signals including pLDDT, pTM, frames, and clash detection. External-service boundaries are ColabFold/MMseqs2 for automatic MSAs and RCSB for template CIF retrieval; local template overrides use CHAI_TEMPLATE_CIF_FOLDER.
Paths: chai_lab/ranking/rank.py, chai_lab/ranking/clashes.py, chai_lab/data/io/rcsb.py.
Main entry points: all_atom_feature_context.py AllAtomFeatureContext · chai1.py Inference orchestration · input_validation.py Input validation · inference_dataset.py Inference dataset
Components 23
Entry points
- Inference APIs · run_inference and run_folding_on_context.
chai_lab/chai1.py - CLI commands
chai_lab/main.py - Prediction example
examples/predict_structure.py
Input and enrichment
- FASTA parser · Parses molecular sequence inputs into typed entities.
chai_lab/data/parsing/fasta.py - Input validation · Normalizes supported molecular and auxiliary inputs.
chai_lab/data/parsing/input_validation.py - Restraint parser
chai_lab/data/parsing/restraints.py - MSA acquisition · Uses supplied alignments or ColabFold/MMseqs2.
chai_lab/data/dataset/msas/colabfold.py - Template loader · Loads local CIFs or retrieved template structures.
chai_lab/data/dataset/templates/load.py - ESM embeddings
chai_lab/data/dataset/embeddings/esm.py - ColabFold/MMseqs2 · Automatic MSA service boundary.
- RCSB · Template CIF retrieval boundary.
chai_lab/data/io/rcsb.py
Context and features
- All-atom tokenizer · Shared token representation across molecular modalities.
chai_lab/data/dataset/structure/all_atom_residue_tokenizer.py - Inference dataset · Builds model-ready examples from parsed inputs.
chai_lab/data/dataset/inference_dataset.py - AllAtomFeatureContext · Central context for structure, MSA, templates, embeddings, and constraints.
chai_lab/data/dataset/all_atom_feature_context.py - Feature factory · Generates atom, token, pair, MSA, template, and restraint features.
chai_lab/data/features/feature_factory.py - Feature generators
- Structured collation · Batches structured atom, token, and pair inputs.
chai_lab/data/collate/collate.py
Inference runtime
- Inference orchestration · Locates weights, executes sampling, and writes artifacts.
chai_lab/chai1.py - Diffusion schedules
chai_lab/model/diffusion_schedules.py - Model utilities
chai_lab/model/utils.py
Outputs
- Confidence ranking · Ranks predictions using confidence and geometry signals.
chai_lab/ranking/rank.py - Clash detection
chai_lab/ranking/clashes.py - Structure artifacts · Serialized predicted structures and ranked results.
Connections 22
- CLI commands → Inference APIs: invokes
- Prediction example → Inference APIs: uses
- Inference APIs → FASTA parser: parses inputs
- FASTA parser → Input validation: typed entities
- Restraint parser → Input validation: constraints
- ColabFold/MMseqs2 → MSA acquisition: alignments
- RCSB → Template loader: template CIFs
- Input validation → Inference dataset: normalized inputs
- All-atom tokenizer → Inference dataset: atom tokens
- MSA acquisition → AllAtomFeatureContext: MSA context
- Template loader → AllAtomFeatureContext: template context
- ESM embeddings → AllAtomFeatureContext: embedding context
- Inference dataset → AllAtomFeatureContext: assembled example
- AllAtomFeatureContext → Feature factory: feature inputs
- Feature generators → Feature factory: specialized features
- Feature factory → Structured collation: model tensors
- Structured collation → Inference orchestration: batched inputs
- Diffusion schedules → Inference orchestration: sampling schedule
- Model utilities → Inference orchestration: model support
- Inference orchestration → Confidence ranking: predicted structures
- Clash detection → Confidence ranking: geometry signal
- Confidence ranking → Structure artifacts: ranked PDB/CIF