# microsoft/mattergen architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/mattergen
- Repository: https://github.com/microsoft/mattergen

## Overview

MatterGen generates inorganic crystal structures, either unconditionally or guided by one or more property constraints; its README also documents relaxing and evaluating generated structures. The main runtime path runs from a generation request through model setup and predictor-corrector diffusion sampling to crystal structures and trajectory outputs. Training and fine-tuning are a separate capability, while evaluation compares structures against reference data and computes structure and energy metrics. The graph reflects sampled source and explicit README statements; unsampled modules are represented only where the tree or README supports their role.

Main entry points: [`mattergen/diffusion/sampling/pc_sampler.py`](https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/sampling/pc_sampler.py) (PC sampler), [`mattergen/evaluation/evaluate.py`](https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/evaluate.py) (Evaluation orchestration), [`mattergen/generator.py`](https://github.com/microsoft/mattergen/blob/main/mattergen/generator.py) (Generator orchestration), [`mattergen/diffusion/lightning_module.py`](https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/lightning_module.py) (Training module)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Product entry points"]
  node_generation["Generation interface<br/>[generate.py]"]
  node_generator["Generator orchestration<br/>[generator.py]"]
  node_structures["Generated structures"]
end

subgraph group_model["Crystal representation and model"]
  node_crystal["Crystal graph data<br/>[chemgraph.py]"]
  node_properties["Property embeddings"]
  node_denoiser["Denoising network<br/>[denoiser.py]"]
  node_gemnet["GemNet backbone<br/>[gemnet.py]"]
end

subgraph group_diffusion["Diffusion runtime"]
  node_sampler["PC sampler<br/>[pc_sampler.py]"]
  node_diffmodule["Diffusion module"]
  node_corruption["Corruption processes<br/>[corruption.py]"]
  node_sde["SDE schedules<br/>[sde_lib.py]"]
  node_batch["Batched states<br/>[batched_data.py]"]
end

subgraph group_training["Data and training"]
  node_traincmd["Training interface<br/>[finetune.py]"]
  node_datamodule["Material data pipeline<br/>[datamodule.py]"]
  node_dataset["Structure dataset<br/>[dataset.py]"]
  node_lightning["Training module"]
  node_fieldloss["Field denoising loss<br/>[field_loss.py]"]
end

subgraph group_evaluation["Evaluation and references"]
  node_evaluatecmd["Evaluation interface<br/>[evaluate.py]"]
  node_evaluate["Evaluation orchestration<br/>[evaluate.py]"]
  node_refdata[("Reference dataset")]
  node_relax["Structure relaxation<br/>[relaxation.py]"]
  node_metrics["Structure metrics<br/>[structure.py]"]
  node_matcher["Structure matching"]
  node_energy["Energy metrics<br/>[energy.py]"]
end

node_user(("Materials researcher"))

node_user -->|"requests samples"| node_generation
node_generation -->|"runs generation"| node_generator
node_generator -->|"samples with"| node_sampler
node_generator -->|"builds crystal data"| node_crystal
node_generator -->|"sets conditions"| node_properties
node_sampler -->|"queries scores"| node_diffmodule
node_sampler -->|"builds predictors"| node_corruption
node_diffmodule -.->|"predicts scores"| node_denoiser
node_denoiser -->|"uses backbone"| node_gemnet
node_sampler -->|"updates batched states"| node_batch
node_corruption -->|"uses SDEs"| node_sde
node_sampler -->|"returns samples"| node_structures
node_user -.->|"trains or fine-tunes"| node_traincmd
node_datamodule -.->|"loads structures"| node_dataset
node_traincmd -.->|"configures training"| node_lightning
node_lightning -->|"wraps diffusion"| node_diffmodule
node_lightning -.->|"computes training loss"| node_fieldloss
node_user -->|"evaluates structures"| node_evaluatecmd
node_evaluatecmd -->|"runs evaluation"| node_evaluate
node_evaluate -->|"loads reference data"| node_refdata
node_evaluate -->|"relaxes structures"| node_relax
node_evaluate -->|"computes metrics"| node_metrics
node_metrics -->|"compares against"| node_refdata
node_metrics -->|"matches structures"| node_matcher
node_evaluate -.->|"computes energy metrics"| node_energy

click node_generation "https://github.com/microsoft/mattergen/blob/main/mattergen/scripts/generate.py"
click node_generator "https://github.com/microsoft/mattergen/blob/main/mattergen/generator.py"
click node_crystal "https://github.com/microsoft/mattergen/blob/main/mattergen/common/data/chemgraph.py"
click node_properties "https://github.com/microsoft/mattergen/blob/main/mattergen/property_embeddings.py"
click node_denoiser "https://github.com/microsoft/mattergen/blob/main/mattergen/denoiser.py"
click node_gemnet "https://github.com/microsoft/mattergen/blob/main/mattergen/common/gemnet/gemnet.py"
click node_sampler "https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/sampling/pc_sampler.py"
click node_diffmodule "https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/diffusion_module.py"
click node_corruption "https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/corruption/corruption.py"
click node_sde "https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/corruption/sde_lib.py"
click node_batch "https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/data/batched_data.py"
click node_traincmd "https://github.com/microsoft/mattergen/blob/main/mattergen/scripts/finetune.py"
click node_datamodule "https://github.com/microsoft/mattergen/blob/main/mattergen/common/data/datamodule.py"
click node_dataset "https://github.com/microsoft/mattergen/blob/main/mattergen/common/data/dataset.py"
click node_lightning "https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/lightning_module.py"
click node_fieldloss "https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/training/field_loss.py"
click node_evaluatecmd "https://github.com/microsoft/mattergen/blob/main/mattergen/scripts/evaluate.py"
click node_evaluate "https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/evaluate.py"
click node_refdata "https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/reference/reference_dataset.py"
click node_relax "https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/utils/relaxation.py"
click node_metrics "https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/metrics/structure.py"
click node_matcher "https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/utils/structure_matcher.py"
click node_energy "https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/metrics/energy.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_generation,node_generator,node_structures toneBlue
class node_crystal,node_properties,node_denoiser,node_gemnet toneAmber
class node_sampler,node_diffmodule,node_corruption,node_sde,node_batch toneMint
class node_traincmd,node_datamodule,node_dataset,node_lightning,node_fieldloss toneRose
class node_evaluatecmd,node_evaluate,node_refdata,node_relax,node_metrics,node_matcher,node_energy,node_user toneIndigo
```

## Components

### Product entry points

- [Generation interface](https://github.com/microsoft/mattergen/blob/main/mattergen/scripts/generate.py): `mattergen/scripts/generate.py`
- [Generator orchestration](https://github.com/microsoft/mattergen/blob/main/mattergen/generator.py): `mattergen/generator.py`
- **Generated structures**

### Crystal representation and model

- [Crystal graph data](https://github.com/microsoft/mattergen/blob/main/mattergen/common/data/chemgraph.py): `mattergen/common/data/chemgraph.py`
- [Property embeddings](https://github.com/microsoft/mattergen/blob/main/mattergen/property_embeddings.py): `mattergen/property_embeddings.py`
- [Denoising network](https://github.com/microsoft/mattergen/blob/main/mattergen/denoiser.py): `mattergen/denoiser.py`
- [GemNet backbone](https://github.com/microsoft/mattergen/blob/main/mattergen/common/gemnet/gemnet.py): `mattergen/common/gemnet/gemnet.py`

### Diffusion runtime

- [PC sampler](https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/sampling/pc_sampler.py): `mattergen/diffusion/sampling/pc_sampler.py`
- [Diffusion module](https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/diffusion_module.py): `mattergen/diffusion/diffusion_module.py`
- [Corruption processes](https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/corruption/corruption.py): `mattergen/diffusion/corruption/corruption.py`
- [SDE schedules](https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/corruption/sde_lib.py): `mattergen/diffusion/corruption/sde_lib.py`
- [Batched states](https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/data/batched_data.py): `mattergen/diffusion/data/batched_data.py`

### Data and training

- [Training interface](https://github.com/microsoft/mattergen/blob/main/mattergen/scripts/finetune.py): `mattergen/scripts/finetune.py`
- [Material data pipeline](https://github.com/microsoft/mattergen/blob/main/mattergen/common/data/datamodule.py): `mattergen/common/data/datamodule.py`
- [Structure dataset](https://github.com/microsoft/mattergen/blob/main/mattergen/common/data/dataset.py): `mattergen/common/data/dataset.py`
- [Training module](https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/lightning_module.py): `mattergen/diffusion/lightning_module.py`
- [Field denoising loss](https://github.com/microsoft/mattergen/blob/main/mattergen/diffusion/training/field_loss.py): `mattergen/diffusion/training/field_loss.py`

### Evaluation and references

- [Evaluation interface](https://github.com/microsoft/mattergen/blob/main/mattergen/scripts/evaluate.py): `mattergen/scripts/evaluate.py`
- [Evaluation orchestration](https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/evaluate.py): `mattergen/evaluation/evaluate.py`
- [Reference dataset](https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/reference/reference_dataset.py): `mattergen/evaluation/reference/reference_dataset.py`
- [Structure relaxation](https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/utils/relaxation.py): `mattergen/evaluation/utils/relaxation.py`
- [Structure metrics](https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/metrics/structure.py): `mattergen/evaluation/metrics/structure.py`
- [Structure matching](https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/utils/structure_matcher.py): `mattergen/evaluation/utils/structure_matcher.py`
- [Energy metrics](https://github.com/microsoft/mattergen/blob/main/mattergen/evaluation/metrics/energy.py): `mattergen/evaluation/metrics/energy.py`

### Other components

- **Materials researcher**

## Connections

- Materials researcher → Generation interface: requests samples
- Generation interface → Generator orchestration: runs generation
- Generator orchestration → PC sampler: samples with (evidence: `mattergen/generator.py`)
- Generator orchestration → Crystal graph data: builds crystal data (evidence: `mattergen/generator.py`)
- Generator orchestration → Property embeddings: sets conditions (evidence: `mattergen/generator.py`)
- PC sampler → Diffusion module: queries scores (evidence: `mattergen/diffusion/sampling/pc_sampler.py`)
- PC sampler → Corruption processes: builds predictors (evidence: `mattergen/diffusion/sampling/pc_sampler.py`)
- Diffusion module → Denoising network: predicts scores
- Denoising network → GemNet backbone: uses backbone (evidence: `mattergen/denoiser.py`)
- PC sampler → Batched states: updates batched states (evidence: `mattergen/diffusion/sampling/pc_sampler.py`)
- Corruption processes → SDE schedules: uses SDEs (evidence: `mattergen/diffusion/corruption/corruption.py`)
- PC sampler → Generated structures: returns samples
- Materials researcher → Training interface: trains or fine-tunes
- Material data pipeline → Structure dataset: loads structures
- Training interface → Training module: configures training
- Training module → Diffusion module: wraps diffusion (evidence: `mattergen/diffusion/lightning_module.py`)
- Training module → Field denoising loss: computes training loss
- Materials researcher → Evaluation interface: evaluates structures
- Evaluation interface → Evaluation orchestration: runs evaluation
- Evaluation orchestration → Reference dataset: loads reference data (evidence: `mattergen/evaluation/evaluate.py`)
- Evaluation orchestration → Structure relaxation: relaxes structures (evidence: `mattergen/evaluation/evaluate.py`)
- Evaluation orchestration → Structure metrics: computes metrics (evidence: `mattergen/evaluation/evaluate.py`)
- Structure metrics → Reference dataset: compares against (evidence: `mattergen/evaluation/metrics/structure.py`)
- Structure metrics → Structure matching: matches structures (evidence: `mattergen/evaluation/metrics/structure.py`)
- Evaluation orchestration → Energy metrics: computes energy metrics
