# materialyzeai/m3gnet architecture

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

- Interactive diagram: https://gitdiagram.com/materialyzeai/m3gnet
- Repository: https://github.com/materialyzeai/m3gnet

## Overview

M3GNet is a TensorFlow materials graph neural network for property prediction and interatomic potentials. Users provide structures or material graphs; conversion creates atom, bond, and three-body features, which the model processes to predict properties or energy. Potential workflows derive forces and stresses for simulation and relaxation, while trainers support property and potential fitting. The graph highlights the documented relaxation and prediction capabilities alongside training. Edges are limited to relationships visible in excerpts, SOURCE INDEX references, or README; some internal calls and relaxation details are unsampled.

Main entry points: [`m3gnet/models/_m3gnet.py`](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/models/_m3gnet.py) (M3GNet model), [`m3gnet/layers/_gn.py`](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_gn.py) (Graph featurizer), [`m3gnet/graph/_types.py`](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/graph/_types.py) (Material graph), [`m3gnet/models/_base.py`](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/models/_base.py) (Model interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_graphs["Graph representation"]
  node_converter["Structure conversion<br/>[_converters.py]"]
  node_graphdata["Material graph<br/>[_types.py]"]
  node_geometry["Geometry features<br/>[_compute.py]"]
  node_batch["Graph batching<br/>[_batch.py]"]
end

subgraph group_network["Neural network"]
  node_features["Graph featurizer<br/>[_gn.py]"]
  node_embedding["Atom and state embedding<br/>[_atom.py]"]
  node_basis["Radial and angular bases<br/>[_three_body.py]"]
  node_interactions["Bond interactions<br/>[_bond.py]"]
  node_messagepassing["Graph updates<br/>[_gn.py]"]
  node_readout["Property readout<br/>[_readout.py]"]
  node_corelayers["Core layer operations<br/>[_core.py]"]
  node_config["Numeric precision<br/>[config.py]"]
  node_utilities["Math and tensor utilities<br/>[_math.py]"]
end

subgraph group_inference["Prediction and dynamics"]
  node_model["M3GNet model<br/>[_m3gnet.py]"]
  node_base["Model interface<br/>[_base.py]"]
  node_potential["Energy force stress<br/>[_dynamics.py]"]
  node_relax["Structure relaxation<br/>[_dynamics.py]"]
end

subgraph group_training["Model training"]
  node_propertytrainer["Property trainer<br/>[_property.py]"]
  node_potentialtrainer["Potential trainer<br/>[_potential.py]"]
end

node_user(("Materials user"))
node_structures["Structures"]

node_user -->|"provides"| node_structures
node_structures -->|"converts"| node_converter
node_converter -->|"creates"| node_graphdata
node_converter -->|"computes geometry"| node_geometry
node_graphdata -->|"assembles"| node_batch
node_graphdata -->|"feeds"| node_features
node_features -->|"embeds fields"| node_embedding
node_features -.->|"builds bases"| node_basis
node_features -.->|"sets interactions"| node_interactions
node_model -->|"configures"| node_converter
node_model -->|"featurizes"| node_features
node_model -.->|"applies blocks"| node_interactions
node_model -.->|"produces outputs"| node_readout
node_interactions -->|"updates graph"| node_messagepassing
node_messagepassing -->|"uses operations"| node_corelayers
node_base -->|"invokes"| node_model
node_base -->|"assembles batches"| node_graphdata
node_base -->|"computes derivatives"| node_potential
node_potential -->|"evaluates energy"| node_model
node_user -.->|"requests prediction"| node_base
node_potential -.->|"supplies potential"| node_relax
node_user -->|"requests relaxation"| node_relax
node_user -.->|"provides targets"| node_propertytrainer
node_propertytrainer -->|"trains"| node_model
node_propertytrainer -->|"converts structures"| node_graphdata
node_user -.->|"provides targets"| node_potentialtrainer
node_potentialtrainer -->|"trains"| node_model
node_potentialtrainer -->|"uses graphs"| node_graphdata
node_config -->|"sets dtypes"| node_geometry
node_utilities -.->|"supports operations"| node_features

click node_converter "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/graph/_converters.py"
click node_graphdata "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/graph/_types.py"
click node_geometry "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/graph/_compute.py"
click node_batch "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/graph/_batch.py"
click node_features "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_gn.py"
click node_embedding "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_atom.py"
click node_basis "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_three_body.py"
click node_interactions "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_bond.py"
click node_messagepassing "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_gn.py"
click node_readout "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_readout.py"
click node_corelayers "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_core.py"
click node_model "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/models/_m3gnet.py"
click node_base "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/models/_base.py"
click node_potential "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/models/_dynamics.py"
click node_relax "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/models/_dynamics.py"
click node_propertytrainer "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/trainers/_property.py"
click node_potentialtrainer "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/trainers/_potential.py"
click node_config "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/config.py"
click node_utilities "https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/utils/_math.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_converter,node_graphdata,node_geometry,node_batch,node_user toneBlue
class node_features,node_embedding,node_basis,node_interactions,node_messagepassing,node_readout,node_corelayers,node_config,node_utilities toneAmber
class node_model,node_base,node_potential,node_relax toneMint
class node_propertytrainer,node_potentialtrainer toneRose
class node_structures toneIndigo
```

## Components

### Graph representation

- [Structure conversion](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/graph/_converters.py): `m3gnet/graph/_converters.py`
- [Material graph](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/graph/_types.py): `m3gnet/graph/_types.py`
- [Geometry features](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/graph/_compute.py): `m3gnet/graph/_compute.py`
- [Graph batching](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/graph/_batch.py): `m3gnet/graph/_batch.py`

### Neural network

- [Graph featurizer](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_gn.py): `m3gnet/layers/_gn.py`
- [Atom and state embedding](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_atom.py): `m3gnet/layers/_atom.py`
- [Radial and angular bases](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_three_body.py): `m3gnet/layers/_three_body.py`
- [Bond interactions](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_bond.py): `m3gnet/layers/_bond.py`
- [Graph updates](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_gn.py): `m3gnet/layers/_gn.py`
- [Property readout](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_readout.py): `m3gnet/layers/_readout.py`
- [Core layer operations](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/layers/_core.py): `m3gnet/layers/_core.py`
- [Numeric precision](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/config.py): `m3gnet/config.py`
- [Math and tensor utilities](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/utils/_math.py): `m3gnet/utils/_math.py`

### Prediction and dynamics

- [M3GNet model](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/models/_m3gnet.py): `m3gnet/models/_m3gnet.py`
- [Model interface](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/models/_base.py): `m3gnet/models/_base.py`
- [Energy force stress](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/models/_dynamics.py): `m3gnet/models/_dynamics.py`
- [Structure relaxation](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/models/_dynamics.py): `m3gnet/models/_dynamics.py`

### Model training

- [Property trainer](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/trainers/_property.py): `m3gnet/trainers/_property.py`
- [Potential trainer](https://github.com/materialyzeai/m3gnet/blob/main/m3gnet/trainers/_potential.py): `m3gnet/trainers/_potential.py`

### Other components

- **Materials user**
- **Structures**

## Connections

- Materials user → Structures: provides
- Structures → Structure conversion: converts (evidence: `m3gnet/graph/_converters.py`)
- Structure conversion → Material graph: creates (evidence: `m3gnet/graph/_converters.py`)
- Structure conversion → Geometry features: computes geometry (evidence: `m3gnet/graph/_converters.py`)
- Material graph → Graph batching: assembles (evidence: `m3gnet/graph/_batch.py`)
- Material graph → Graph featurizer: feeds
- Graph featurizer → Atom and state embedding: embeds fields (evidence: `m3gnet/layers/_gn.py`)
- Graph featurizer → Radial and angular bases: builds bases
- Graph featurizer → Bond interactions: sets interactions (evidence: `m3gnet/layers/_gn.py`)
- M3GNet model → Structure conversion: configures (evidence: `m3gnet/models/_m3gnet.py`)
- M3GNet model → Graph featurizer: featurizes (evidence: `m3gnet/models/_m3gnet.py`)
- M3GNet model → Bond interactions: applies blocks
- M3GNet model → Property readout: produces outputs
- Bond interactions → Graph updates: updates graph (evidence: `m3gnet/layers/_gn.py`)
- Graph updates → Core layer operations: uses operations (evidence: `m3gnet/layers/_gn.py`)
- Model interface → M3GNet model: invokes (evidence: `m3gnet/models/_base.py`)
- Model interface → Material graph: assembles batches (evidence: `m3gnet/models/_base.py`)
- Model interface → Energy force stress: computes derivatives (evidence: `m3gnet/models/_base.py`)
- Energy force stress → M3GNet model: evaluates energy (evidence: `m3gnet/models/_dynamics.py`)
- Materials user → Model interface: requests prediction
- Energy force stress → Structure relaxation: supplies potential (evidence: `m3gnet/models/_dynamics.py`)
- Materials user → Structure relaxation: requests relaxation
- Materials user → Property trainer: provides targets
- Property trainer → M3GNet model: trains (evidence: `m3gnet/trainers/_property.py`)
- Property trainer → Material graph: converts structures (evidence: `m3gnet/trainers/_property.py`)
- Materials user → Potential trainer: provides targets
- Potential trainer → M3GNet model: trains (evidence: `m3gnet/trainers/_potential.py`)
- Potential trainer → Material graph: uses graphs (evidence: `m3gnet/trainers/_potential.py`)
- Numeric precision → Geometry features: sets dtypes (evidence: `m3gnet/graph/_compute.py`)
- Math and tensor utilities → Graph featurizer: supports operations
