# apple/ml-simplefold architecture

> Architecture diagram of the GitHub repository apple/ml-simplefold, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/apple/ml-simplefold
- Repository: https://github.com/apple/ml-simplefold

## Overview

#### 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: [`src/simplefold/inference.py`](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/inference.py) (Inference Orchestrator), [`src/simplefold/process_mmcif.py`](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/process_mmcif.py) (Structure Conversion), [`src/simplefold/boltz_data_pipeline/write/mmcif.py`](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/boltz_data_pipeline/write/mmcif.py) (PDB/mmCIF Writers), [`src/simplefold/model/flow.py`](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/model/flow.py) (Flow Formulation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Prediction"]
  node_cli["Prediction CLI<br/>[cli.py]"]
  node_inference["Inference Orchestrator<br/>prediction lifecycle<br/>[inference.py]"]
  node_wrapper{{"Model Wrapper<br/>backend boundary<br/>[wrapper.py]"}}
end

subgraph group_pipeline["Protein Data Pipeline"]
  node_fasta_parse["FASTA Parser<br/>sequence parser<br/>[fasta.py]"]
  node_schema["Structure Schema<br/>data schema<br/>[schema.py]"]
  node_filter_crop["Filtering and Crops<br/>structure selection"]
  node_featurizer["Featurizer<br/>protein features<br/>[featurizer.py]"]
  node_tokenizer["Protein Tokenizer<br/>tokenization<br/>[boltz_protein.py]"]
  node_structure_writers["PDB/mmCIF Writers<br/>structure serialization<br/>[mmcif.py]"]
end

subgraph group_model["Flow-Matching Model"]
  node_simplefold["SimpleFold Core<br/>model facade<br/>[simplefold.py]"]
  node_flow["Flow Formulation<br/>flow matching<br/>[flow.py]"]
  node_torch_model["PyTorch Model Stack<br/>training runtime<br/>[architecture.py]"]
  node_mlx_model["MLX Model Stack<br/>inference runtime<br/>[architecture.py]"]
end

subgraph group_training["Training"]
  node_data_prep["Structure Conversion<br/>dataset preparation<br/>[process_mmcif.py]"]
  node_redis_ccd[("Redis CCD Database<br/>external dependency")]
  node_datamodule["Training DataModule<br/>dataset batching"]
  node_train["Training Launchers<br/>Hydra training<br/>[train.py]"]
  node_hydra_configs["Hydra Config Composition<br/>experiment configuration<br/>[train.yaml]"]
end

subgraph group_evaluation["Evaluation"]
  node_folding_eval["Folding Benchmark<br/>mmCIF evaluator<br/>[analyze_folding.py]"]
  node_two_state_eval["Two-State Evaluation<br/>PDB evaluator"]
end

node_cli -->|"delegates prediction"| node_inference
node_inference -->|"reads sequences"| node_fasta_parse
node_fasta_parse -->|"builds inputs"| node_schema
node_schema -->|"structures representation"| node_featurizer
node_featurizer -->|"creates model tokens"| node_tokenizer
node_inference -->|"selects backend"| node_wrapper
node_wrapper -->|"executes model"| node_simplefold
node_simplefold -->|"uses generative objective"| node_flow
node_flow -->|"PyTorch path"| node_torch_model
node_flow -->|"MLX path"| node_mlx_model
node_tokenizer -->|"model-ready inputs"| node_simplefold
node_inference -->|"writes predictions"| node_structure_writers
node_data_prep -.->|"looks up components"| node_redis_ccd
node_data_prep -->|"filters structures"| node_filter_crop
node_filter_crop -->|"selected crops"| node_featurizer
node_data_prep -->|"prepared training data"| node_datamodule
node_datamodule -->|"batches examples"| node_train
node_hydra_configs -->|"configures runs"| node_train
node_train -->|"optimizes"| node_torch_model
node_structure_writers -->|"predicted mmCIF"| node_folding_eval
node_structure_writers -->|"predicted PDB"| node_two_state_eval

click node_cli "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/cli.py"
click node_inference "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/inference.py"
click node_wrapper "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/wrapper.py"
click node_fasta_parse "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/boltz_data_pipeline/parse/fasta.py"
click node_schema "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/boltz_data_pipeline/parse/schema.py"
click node_featurizer "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/boltz_data_pipeline/feature/featurizer.py"
click node_tokenizer "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/boltz_data_pipeline/tokenize/boltz_protein.py"
click node_structure_writers "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/boltz_data_pipeline/write/mmcif.py"
click node_simplefold "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/model/simplefold.py"
click node_flow "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/model/flow.py"
click node_torch_model "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/model/torch/architecture.py"
click node_mlx_model "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/model/mlx/architecture.py"
click node_data_prep "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/process_mmcif.py"
click node_datamodule "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/datasets/train_datamodule.py"
click node_train "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/train.py"
click node_hydra_configs "https://github.com/apple/ml-simplefold/blob/main/configs/experiment/train.yaml"
click node_folding_eval "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/evaluation/analyze_folding.py"
click node_two_state_eval "https://github.com/apple/ml-simplefold/blob/main/src/simplefold/evaluation/analyze_two_state.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_inference,node_wrapper toneBlue
class node_fasta_parse,node_schema,node_filter_crop,node_featurizer,node_tokenizer,node_structure_writers toneAmber
class node_simplefold,node_flow,node_torch_model,node_mlx_model toneMint
class node_data_prep,node_redis_ccd,node_datamodule,node_train,node_hydra_configs toneRose
class node_folding_eval,node_two_state_eval toneIndigo
```

## Components

### Prediction

- [Prediction CLI](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/cli.py): CLI · Accepts FASTA inputs, model scale, backend, and conformer options. · `src/simplefold/cli.py`
- [Inference Orchestrator](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/inference.py): prediction lifecycle · Runs sequence prediction and artifact generation. · `src/simplefold/inference.py`
- [Model Wrapper](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/wrapper.py): backend boundary · Connects inference orchestration to the selected runtime model. · `src/simplefold/wrapper.py`

### Protein Data Pipeline

- [FASTA Parser](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/boltz_data_pipeline/parse/fasta.py): sequence parser · `src/simplefold/boltz_data_pipeline/parse/fasta.py`
- [Structure Schema](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/boltz_data_pipeline/parse/schema.py): data schema · `src/simplefold/boltz_data_pipeline/parse/schema.py`
- **Filtering and Crops**: structure selection
- [Featurizer](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/boltz_data_pipeline/feature/featurizer.py): protein features · `src/simplefold/boltz_data_pipeline/feature/featurizer.py`
- [Protein Tokenizer](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/boltz_data_pipeline/tokenize/boltz_protein.py): tokenization · `src/simplefold/boltz_data_pipeline/tokenize/boltz_protein.py`
- [PDB/mmCIF Writers](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/boltz_data_pipeline/write/mmcif.py): structure serialization · `src/simplefold/boltz_data_pipeline/write/mmcif.py`

### Flow-Matching Model

- [SimpleFold Core](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/model/simplefold.py): model facade · Shared model layer across runtime implementations. · `src/simplefold/model/simplefold.py`
- [Flow Formulation](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/model/flow.py): flow matching · Defines the generative control path. · `src/simplefold/model/flow.py`
- [PyTorch Model Stack](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/model/torch/architecture.py): training runtime · Architecture, sampler, and confidence head for PyTorch. · `src/simplefold/model/torch/architecture.py`
- [MLX Model Stack](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/model/mlx/architecture.py): inference runtime · Architecture, sampler, confidence head, and ESM integration for MLX. · `src/simplefold/model/mlx/architecture.py`

### Training

- [Structure Conversion](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/process_mmcif.py): dataset preparation · Processes raw mmCIF structures into training representations. · `src/simplefold/process_mmcif.py`
- **Redis CCD Database**: external dependency · Local chemical-component database required during mmCIF processing.
- [Training DataModule](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/datasets/train_datamodule.py): dataset batching · `src/simplefold/datasets/train_datamodule.py`
- [Training Launchers](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/train.py): Hydra training · Standard and FSDP training entry points. · `src/simplefold/train.py`
- [Hydra Config Composition](https://github.com/apple/ml-simplefold/blob/main/configs/experiment/train.yaml): experiment configuration · Composes experiment, model, trainer, data, and runtime settings. · `configs/experiment/train.yaml`

### Evaluation

- [Folding Benchmark](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/evaluation/analyze_folding.py): mmCIF evaluator · Compares predictions with targets through OpenStructure Docker. · `src/simplefold/evaluation/analyze_folding.py`
- [Two-State Evaluation](https://github.com/apple/ml-simplefold/blob/main/src/simplefold/evaluation/analyze_two_state.py): PDB evaluator · Assesses Apo/CoDNaS ensembles using an external TM-score binary. · `src/simplefold/evaluation/analyze_two_state.py`

## Connections

- 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
