How apple/ml-simplefold works
Purpose and Entry Points
SimpleFold is a flow-matching protein-structure predictor built from general-purpose transformer layers. It supports inference on FASTA sequences, model training/fine-tuning, structure-data preparation, and benchmark evaluation. Primary entry points are src/simplefold/cli.py and src/simplefold/inference.py for prediction; src/simplefold/train.py and src/simplefold/train_fsdp.py for training; and src/simplefold/process_mmcif.py / src/simplefold/process_structure.py for dataset conversion.
Inference Orchestration
The CLI accepts FASTA files/directories, selects a model scale and Torch or MLX backend, generates one or more conformers through iterative flow sampling, and writes predicted structures and optional pLDDT confidence. src/simplefold/cli.py delegates prediction lifecycle work to src/simplefold/inference.py; src/simplefold/wrapper.py likely provides the backend/model-facing integration boundary. Input sequence parsing and output serialization are separated from model execution.
Protein Input and Structure Pipeline
The embedded Boltz-derived pipeline converts heterogeneous biological formats into model-ready protein representations. Parsing, filtering, crop selection, featurization, padding/symmetry processing, and protein tokenization are organized beneath src/simplefold/boltz_data_pipeline/. Architecturally central stages are:
• Parsing/schema: src/simplefold/boltz_data_pipeline/parse/fasta.py, src/simplefold/boltz_data_pipeline/parse/schema.py
• Structure filtering and crops: src/simplefold/boltz_data_pipeline/filter/, src/simplefold/boltz_data_pipeline/crop/boltz.py
• Features/tokens: src/simplefold/boltz_data_pipeline/feature/featurizer.py, src/simplefold/boltz_data_pipeline/tokenize/boltz_protein.py
• PDB/mmCIF outputs: src/simplefold/boltz_data_pipeline/write/mmcif.py, src/simplefold/boltz_data_pipeline/write/pdb.py
Folding Model and Generative Sampling
src/simplefold/model/simplefold.py is the common model layer; src/simplefold/model/flow.py defines the flow-matching formulation/control path. Architecture, transformer blocks, positional embeddings, confidence prediction, and sampler implementations are duplicated per runtime:
• PyTorch: src/simplefold/model/torch/architecture.py, src/simplefold/model/torch/sampler.py, src/simplefold/model/torch/confidence_module.py
• MLX: src/simplefold/model/mlx/architecture.py, src/simplefold/model/mlx/sampler.py, src/simplefold/model/mlx/confidence_module.py
This isolates backend tensor/runtime concerns while retaining equivalent model-family configuration.
Training and Distributed Execution
Hydra composes experiment, data, model, trainer, callbacks, logger, and path configuration. Standard and FSDP launches are implemented in src/simplefold/train.py and src/simplefold/train_fsdp.py; dataset loading/batching is owned by src/simplefold/datasets/train_datamodule.py. Core composition points are configs/experiment/train.yaml, configs/model/default.yaml, and configs/trainer/fsdp.yaml. Model scales from 100M through 3B are declared under configs/model/architecture/.
Data Preparation and External Dependencies
Raw mmCIF structures are processed and tokenized before training through src/simplefold/process_mmcif.py and src/simplefold/process_structure.py. The mmCIF processing boundary depends on a locally running Redis CCD database. Training data may combine PDB experimental structures with AFDB SwissProt and AFESM-derived structures. PyTorch is the principal training runtime; MLX is an optional Apple-silicon inference runtime, with ESM-related MLX modules under src/simplefold/model/mlx/esm_network.py.
Evaluation
Folding benchmark evaluation compares generated mmCIF structures against targets using an OpenStructure Docker environment via src/simplefold/evaluation/analyze_folding.py. Ensemble/two-state assessment for Apo and CoDNaS consumes predicted PDB files and an externally compiled TM-score binary through src/simplefold/evaluation/analyze_two_state.py. These evaluators are downstream consumers of inference artifacts, not part of the training or generation path.
Main entry points: inference.py Inference Orchestrator · process_mmcif.py Structure Conversion · mmcif.py PDB/mmCIF Writers · flow.py Flow Formulation
Components 20
Prediction
- Prediction CLI · Accepts FASTA inputs, model scale, backend, and conformer options.
src/simplefold/cli.py - Inference Orchestrator · Runs sequence prediction and artifact generation.
src/simplefold/inference.py - Model Wrapper · Connects inference orchestration to the selected runtime model.
src/simplefold/wrapper.py
Protein Data Pipeline
- FASTA Parser
src/simplefold/boltz_data_pipeline/parse/fasta.py - Structure Schema
src/simplefold/boltz_data_pipeline/parse/schema.py - Filtering and Crops
- Featurizer
src/simplefold/boltz_data_pipeline/feature/featurizer.py - Protein Tokenizer
src/simplefold/boltz_data_pipeline/tokenize/boltz_protein.py - PDB/mmCIF Writers
src/simplefold/boltz_data_pipeline/write/mmcif.py
Flow-Matching Model
- SimpleFold Core · Shared model layer across runtime implementations.
src/simplefold/model/simplefold.py - Flow Formulation · Defines the generative control path.
src/simplefold/model/flow.py - PyTorch Model Stack · Architecture, sampler, and confidence head for PyTorch.
src/simplefold/model/torch/architecture.py - MLX Model Stack · Architecture, sampler, confidence head, and ESM integration for MLX.
src/simplefold/model/mlx/architecture.py
Training
- Structure Conversion · Processes raw mmCIF structures into training representations.
src/simplefold/process_mmcif.py - Redis CCD Database · Local chemical-component database required during mmCIF processing.
- Training DataModule
src/simplefold/datasets/train_datamodule.py - Training Launchers · Standard and FSDP training entry points.
src/simplefold/train.py - Hydra Config Composition · Composes experiment, model, trainer, data, and runtime settings.
configs/experiment/train.yaml
Evaluation
- Folding Benchmark · Compares predictions with targets through OpenStructure Docker.
src/simplefold/evaluation/analyze_folding.py - Two-State Evaluation · Assesses Apo/CoDNaS ensembles using an external TM-score binary.
src/simplefold/evaluation/analyze_two_state.py
Connections 21
- Prediction CLI → Inference Orchestrator: delegates prediction
- Inference Orchestrator → FASTA Parser: reads sequences
- FASTA Parser → Structure Schema: builds inputs
- Structure Schema → Featurizer: structures representation
- Featurizer → Protein Tokenizer: creates model tokens
- Inference Orchestrator → Model Wrapper: selects backend
- Model Wrapper → SimpleFold Core: executes model
- SimpleFold Core → Flow Formulation: uses generative objective
- Flow Formulation → PyTorch Model Stack: PyTorch path
- Flow Formulation → MLX Model Stack: MLX path
- Protein Tokenizer → SimpleFold Core: model-ready inputs
- Inference Orchestrator → PDB/mmCIF Writers: writes predictions
- Structure Conversion → Redis CCD Database: looks up components
- Structure Conversion → Filtering and Crops: filters structures
- Filtering and Crops → Featurizer: selected crops
- Structure Conversion → Training DataModule: prepared training data
- Training DataModule → Training Launchers: batches examples
- Hydra Config Composition → Training Launchers: configures runs
- Training Launchers → PyTorch Model Stack: optimizes
- PDB/mmCIF Writers → Folding Benchmark: predicted mmCIF
- PDB/mmCIF Writers → Two-State Evaluation: predicted PDB