# adimanethia/crystaldiff architecture

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

- Interactive diagram: https://gitdiagram.com/adimanethia/crystaldiff
- Repository: https://github.com/adimanethia/crystaldiff

## Overview

CrystalDiff is a PyTorch crystal-generation application: it acquires perovskite structures, trains an equivariant denoiser, generates candidate coordinates, and presents or analyzes results. The main interactive path runs from user-selected chemistry through the Streamlit app and model to rendered structures and bond-length checks. The graph also preserves dataset preparation, command-line generation, and scientific RDF analysis. Evidence is limited to the README and sampled excerpts; no property-conditioning stage is shown in the sampled model, despite the README describing that capability.

Main entry points: [`src/model.py`](https://github.com/adimanethia/crystaldiff/blob/main/src/model.py) (Diffusion model), [`app.py`](https://github.com/adimanethia/crystaldiff/blob/main/app.py) (Streamlit designer), [`generate.py`](https://github.com/adimanethia/crystaldiff/blob/main/generate.py) (CLI generation), [`train.py`](https://github.com/adimanethia/crystaldiff/blob/main/train.py) (Model training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_fetch["Dataset acquisition<br/>[data_loader.py]"]
  node_dataset[("Perovskite dataset")]
end

subgraph group_learning["Equivariant model"]
  node_training["Model training<br/>[train.py]"]
  node_model["Diffusion model<br/>[model.py]"]
  node_egnn["EGNN layer<br/>[layers.py]"]
end

subgraph group_generation["Generation"]
  node_web_app["Streamlit designer<br/>[app.py]"]
  node_cli_generation["CLI generation<br/>[generate.py]"]
  node_coordinates["Generated coordinates"]
end

subgraph group_inspection["Result inspection"]
  node_web_render["Interactive 3D view<br/>[app.py]"]
  node_bond_metrics["Bond-length check<br/>[app.py]"]
  node_rdf["RDF analysis<br/>[analysis.py]"]
  node_xyz_validation["XYZ validation<br/>[validate.py]"]
  node_plotting["Crystal plotting<br/>[visualize.py]"]
  node_analysis["Analysis script<br/>[analysis.py]"]
end

node_user(("Materials researcher"))
node_materials_project(("Materials Project"))

node_user -->|"selects chemistry"| node_web_app
node_web_app -->|"runs denoising"| node_model
node_model -->|"applies layers"| node_egnn
node_web_app -->|"renders structure"| node_web_render
node_web_app -->|"checks bonds"| node_bond_metrics
node_materials_project -->|"provides structures"| node_fetch
node_fetch -->|"saves tensors"| node_dataset
node_training -->|"loads samples"| node_dataset
node_training -->|"trains model"| node_model
node_user -.->|"runs generation"| node_cli_generation
node_cli_generation -->|"runs denoising"| node_model
node_cli_generation -->|"writes XYZ"| node_coordinates
node_analysis -->|"generates structure"| node_model
node_analysis -->|"computes RDF"| node_rdf
node_coordinates -->|"reads XYZ"| node_xyz_validation
node_coordinates -->|"reads XYZ"| node_plotting

click node_fetch "https://github.com/adimanethia/crystaldiff/blob/main/src/data_loader.py"
click node_dataset "https://github.com/adimanethia/crystaldiff/blob/main/data/perovskite_dataset.pt"
click node_training "https://github.com/adimanethia/crystaldiff/blob/main/train.py"
click node_model "https://github.com/adimanethia/crystaldiff/blob/main/src/model.py"
click node_egnn "https://github.com/adimanethia/crystaldiff/blob/main/src/layers.py"
click node_web_app "https://github.com/adimanethia/crystaldiff/blob/main/app.py"
click node_cli_generation "https://github.com/adimanethia/crystaldiff/blob/main/generate.py"
click node_web_render "https://github.com/adimanethia/crystaldiff/blob/main/app.py"
click node_bond_metrics "https://github.com/adimanethia/crystaldiff/blob/main/app.py"
click node_rdf "https://github.com/adimanethia/crystaldiff/blob/main/analysis.py"
click node_xyz_validation "https://github.com/adimanethia/crystaldiff/blob/main/validate.py"
click node_plotting "https://github.com/adimanethia/crystaldiff/blob/main/visualize.py"
click node_analysis "https://github.com/adimanethia/crystaldiff/blob/main/analysis.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_fetch,node_dataset toneBlue
class node_training,node_model,node_egnn toneAmber
class node_web_app,node_cli_generation,node_coordinates toneMint
class node_web_render,node_bond_metrics,node_rdf,node_xyz_validation,node_plotting,node_analysis toneRose
class node_user,node_materials_project toneIndigo
```

## Components

### Data preparation

- [Dataset acquisition](https://github.com/adimanethia/crystaldiff/blob/main/src/data_loader.py): `src/data_loader.py`
- [Perovskite dataset](https://github.com/adimanethia/crystaldiff/blob/main/data/perovskite_dataset.pt): `data/perovskite_dataset.pt`

### Equivariant model

- [Model training](https://github.com/adimanethia/crystaldiff/blob/main/train.py): `train.py`
- [Diffusion model](https://github.com/adimanethia/crystaldiff/blob/main/src/model.py): `src/model.py`
- [EGNN layer](https://github.com/adimanethia/crystaldiff/blob/main/src/layers.py): `src/layers.py`

### Generation

- [Streamlit designer](https://github.com/adimanethia/crystaldiff/blob/main/app.py): `app.py`
- [CLI generation](https://github.com/adimanethia/crystaldiff/blob/main/generate.py): `generate.py`
- **Generated coordinates**

### Result inspection

- [Interactive 3D view](https://github.com/adimanethia/crystaldiff/blob/main/app.py): `app.py`
- [Bond-length check](https://github.com/adimanethia/crystaldiff/blob/main/app.py): `app.py`
- [RDF analysis](https://github.com/adimanethia/crystaldiff/blob/main/analysis.py): `analysis.py`
- [XYZ validation](https://github.com/adimanethia/crystaldiff/blob/main/validate.py): `validate.py`
- [Crystal plotting](https://github.com/adimanethia/crystaldiff/blob/main/visualize.py): `visualize.py`
- [Analysis script](https://github.com/adimanethia/crystaldiff/blob/main/analysis.py): `analysis.py`

### Other components

- **Materials researcher**
- **Materials Project**

## Connections

- Materials researcher → Streamlit designer: selects chemistry (evidence: `app.py`)
- Streamlit designer → Diffusion model: runs denoising (evidence: `app.py`)
- Diffusion model → EGNN layer: applies layers (evidence: `src/model.py`)
- Streamlit designer → Interactive 3D view: renders structure (evidence: `app.py`)
- Streamlit designer → Bond-length check: checks bonds (evidence: `app.py`)
- Materials Project → Dataset acquisition: provides structures (evidence: `src/data_loader.py`)
- Dataset acquisition → Perovskite dataset: saves tensors (evidence: `src/data_loader.py`)
- Model training → Perovskite dataset: loads samples (evidence: `train.py`)
- Model training → Diffusion model: trains model (evidence: `train.py`)
- Materials researcher → CLI generation: runs generation
- CLI generation → Diffusion model: runs denoising (evidence: `generate.py`)
- CLI generation → Generated coordinates: writes XYZ (evidence: `generate.py`)
- Analysis script → Diffusion model: generates structure (evidence: `analysis.py`)
- Analysis script → RDF analysis: computes RDF (evidence: `analysis.py`)
- Generated coordinates → XYZ validation: reads XYZ (evidence: `validate.py`)
- Generated coordinates → Crystal plotting: reads XYZ (evidence: `visualize.py`)
