Archive of AI

Source Snapshot / 2025-01-16-microsoft-mattergen-nature-2

microsoft/mattergen

Linked event: 2025-01-16 · Microsoft AI for Science Publishes and Open-Sources Diffusion-Based Inorganic Crystal Generation Model MatterGen in Nature

Publisher
GitHub
Archived
2026-11-23
Capture Method
Direct page capture
HTTP / SHA-256
200 / 66ba5573a1c3f547
Original URL
Open source ↗
Wayback Backup
Not archived
This page preserves a plain-text static snapshot against link rot. When citing figures, tables, or full legal terms, verify against the original URL and Wayback Machine archive.

[来源关键摘录] Official open-source implementation of MatterGen under the MIT license.

[正文前段节选] Skip to content

Navigation Menu

Appearance settings

You signed in with another tab or window. Reload to refresh your session.

You signed out in another tab or window. Reload to refresh your session.

You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

Repository navigation

NotificationsYou must be signed in to change notification settings

Fork363 (363)

Star1.9k (1.9k)You must be signed in to star a repository

Official implementation of MatterGen -- a generative model for inorganic materials design across the periodic table that can be fine-tuned to steer the generation towards a wide range of property constraints.

www.nature.com/articles/s41586-025-08628-5

generative-aimaterials-designmaterials-science

Code of conduct

Contributing

Security policy

Custom properties

Report repository

BranchesTags

Open more actions menu

Latest commit

Folders and files

Last commit message

Last commit date

data-release

CODE_OF_CONDUCT.md

CONTRIBUTING.md

MODEL_CARD.md

pyproject.toml

View all files

Repository files navigation

MatterGen is a generative model for inorganic materials design across the periodic table that can be fine-tuned to steer the generation towards a wide range of property constraints.

Table of Contents

Installation

Get started with a pre-trained model

Generating materials

Train MatterGen yourself

Data release

Responsible AI Transparency Documentation

Get in touch

The easiest way to install prerequisites is via uv, a fast Python package and project manager.

The MatterGen environment can be installed via the following command (assumes you are running Linux and have a CUDA GPU):

pip install uv

uv venv .venv --python 3.10

source .venv/bin/activate

uv pip install -e .

Alternatively, install the released package from PyPI with the matching pre-built PyTorch Geometric CUDA wheels:

uv pip install mattergen --find-links https://data.pyg.org/whl/torch-2.2.0+cu121.html

Note that our datasets and model checkpoints are provided inside this repo via Git Large File Storage (LFS).

To find out whether LFS is installed on your machine, run

git lfs --version

If this prints some version like git-lfs/3.0.2 (GitHub; linux amd64; go 1.18.1), you can skip the following step.

Install Git LFS

If Git LFS was not installed before you cloned this repo, you can install it via:

sudo apt install git-lfs

git lfs install

Apple Silicon

Running MatterGen on Apple Silicon is experimental. Use at your own risk.

Further, you need to run export PYTORCH_ENABLE_MPS_FALLBACK=1 before any training or generation run.

We provide checkpoints of an unconditional base version of MatterGen as well as fine-tuned models for these properties:

mattergen_base: unconditional base model trained on Alex-MP-20

mp_20_base: unconditional base model trained on MP-20

chemical_system: fine-tuned model conditioned on chemical system

space_group: fine-tuned model conditioned on space group

dft_mag_density: fine-tuned model conditioned on magnetic density from DFT

dft_band_gap: fine-tuned model conditioned on band gap from DFT

ml_bulk_modulus: fine-tuned model conditioned on bulk modulus from ML predictor

dft_mag_density_hhi_score: fine-tuned model jointly conditioned on magnetic density from DFT and HHI score

chemical_system_energy_above_hull: fine-tuned model jointly conditioned on chemical system and energy above hull from DFT

The checkpoints are located at checkpoints/<model_name> and are also available on Hugging Face. By default, they are downloaded from Huggingface when requested. You can also manually download them from Git LFS via

git lfs pull -I checkpoints/<model_name> --exclude=""

The checkpoints provided were re-trained using this repository, i.e., are not identical to the ones used in the paper. Hence, results may slightly deviate from those in the publication.

Unconditional generation

To sample from the pre-trained base model, run the following command.

export MODEL_NAME=mattergen_base

export RESULTS_PATH=results/ # Samples will be written to this directory

# generate batch_size * num_batches samples

mattergen-generate $RESULTS_PATH --pretrained-name=$MODEL_NAME --batch_size=16 --num_batches 1

Pass --seed=42 to reset the Python, NumPy, and PyTorch random generators before sampling.

Exact reproducibility is only expected with the same software and hardware configuration because

some CUDA operations are nondeterministic.

This script will write the following files into $RESULTS_PATH:

generated_crystals_cif.zip: a ZIP file containing a single .cif file per generated structure.

generated_crystals.extxyz, a single file containing the individual generated structures as frames.

If --record-trajectories == True (default): generated_trajectories.zip: a ZIP file containing a .extxyz file per generated structure, which contains the full denoising trajectory for each individual structure.

For best efficiency, increase the batch size to the largest your GPU can sustain without running out of memory.

To sample from a model you've trained yourself, replace --pretrained-name=$MODEL_NAME with --model_path=$MODEL_PATH, filling in your model's location for $MODEL_PATH.

Property-conditioned generation

With a fine-tuned model, you can generate materials conditioned on a target property.

For example, to sample from the model trained on magnetic density, you can run the following command.

export MODEL_NAME=dft_mag_density

export RESULTS_PATH="results/$MODEL_NAME/" # Samples will be written to this directory, e.g., `results/dft_mag_density`

# Generate conditional samples with a target magnetic density of 0.15

mattergen-generate $RESULTS_PATH --pretrained-name=$MODEL_NAME --batch_size=16 --properties_to_condition_on="{'dft_mag_density': 0.15}" --diffusion_guidance_factor=2.0

The argument --diffusion-guidance-factor corresponds to the $\gamma$ parameter in classifier-free diffusion guidance. Setting it to zero corresponds to unconditional generation, and increasing it further tends to produce samples which adhere more to the input property values, though at the expense of diversity and realism of samples.

Multiple property-conditioned generation

You can also generate materials conditioned on more than one property. For instance, you can use the pre-trained model located at checkpoints/chemical_system_energy_above_hull to generate conditioned on chemical system and energy above the hull, or the model at checkpoints/dft_mag_density_hhi_score for joint conditioning on HHI score and magnetic density.

Adapt the following command to your specific needs:

export MODEL_NAME=chemical_system_energy_above_hull

mattergen-generate $RESULTS_PATH --pretrained-name=$MODEL_NAME --batch_size=16 --properties_to_condition_on="{'energy_above_hull': 0.05, 'chemical_system': 'Li-O'}" --diffusion_guidance_factor=2.0

Once you have generated a list of structures contained in $RESULTS_PATH (either using MatterGen or another method), you can relax the structures using the default MatterSim machine learning force field (see repository) and compute novelty, uniqueness, stability (using energy estimated by MatterSim), and other metrics via the following command:

mattergen-evaluate --structures_path=$RESULTS_PATH --relax=True --structure_matcher='disordered' --save_as="$RESULTS_PATH/metrics.json"

The default MP2020 reference dataset is downloaded from Hugging Face on first use and reused from the local cache.

If you want to use the reference dataset while applying the TRI2024 correction scheme (recommended), instead run the following:

mattergen-evaluate --structures_path=$RESULTS_PATH --relax=True --structure_matcher='disordered' --save_as="$RESULTS_PATH/metrics.json" --energy_correction_scheme="TRI2024"

This script will write metrics.json containing the metric results to $RESULTS_PATH and will print it to your console.

[...内容已截断,完整版请查看原文或 Wayback 快照]