Skip to content

Commit

Permalink
Docs: Add comprehensive project documentation site
Browse files Browse the repository at this point in the history
Sets up Sphinx documentation with Read the Docs theme, including:
- Installation guides for each backbone model
- Detailed configuration and usage examples
- Model backbone documentation
- Contributing guidelines

Adds GitHub Actions workflow to automatically build and deploy docs
  • Loading branch information
nimashoghi committed Nov 27, 2024
1 parent ae98bf2 commit 44172eb
Show file tree
Hide file tree
Showing 18 changed files with 649 additions and 77 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Deploy Documentation

on:
push:
branches:
- main # or your default branch
paths:
- 'docs/**'
- '.github/workflows/docs.yml'

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r docs/requirements.txt
pip install .
- name: Build documentation
run: |
cd docs
make html
# Create .nojekyll file to allow files and folders starting with an underscore
touch _build/html/.nojekyll
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: docs/_build/html

deploy:
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,5 @@ md_results/
results_backup/
ZnMn2O4_*/
examples/matbench/data/
bfg.jar
bfg.jar
.dir2textignore
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# MatterTune: A Unified Platform for Atomistic Foundation Model Fine-Tuning

[![Documentation Status](https://github.com/Fung-Lab/MatterTune/actions/workflows/docs.yml/badge.svg)](https://nimashoghi.github.io/mattertune/)

MatterTune is a flexible and powerful machine learning library designed specifically for fine-tuning state-of-the-art chemistry models. It provides intuitive interfaces for computational chemists to fine-tune pre-trained models on their specific use cases.

## Table of Contents
Expand Down Expand Up @@ -181,7 +183,7 @@ Note: MatterTune requires PyTorch >= 2.0 and additional backbone-specific depend
For development installation:
```bash
git clone https://github.com/nimashoghi/mattertune.git
git clone https://github.com/Fung-Lab/MatterTune.git
cd mattertune
pip install -e .
``` -->
Expand Down
19 changes: 19 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Empty file removed docs/backbones/eqV2.md
Empty file.
30 changes: 30 additions & 0 deletions docs/backbones/eqv2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# EquiformerV2 Backbone

The EquiformerV2 backbone implements the EquiformerV2 model architecture in MatterTune. This is a state-of-the-art equivariant transformer model for molecular and materials property prediction.

```{note}
This documentation is currently under development. Please check back later for complete documentation of the EquiformerV2 backbone.
```

## Key Features

- Equivariant transformer architecture
- Support for both molecular and periodic systems
- State-of-the-art performance on various property prediction tasks

## Basic Usage

```python
from mattertune import MatterTuner
from mattertune.configs import EquiformerV2BackboneConfig

config = {
"model": {
"name": "eqv2",
"ckpt_path": "path/to/pretrained.pt",
# Additional configuration options will be documented soon
}
}

tuner = MatterTuner(config)
```
48 changes: 1 addition & 47 deletions docs/backbones/JMP.md → docs/backbones/jmp.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,53 +69,7 @@ config = {
"aint": 1000
}
}
},
# ... rest of config
}
}
tuner = MatterTuner(config)
```

## Property Prediction

The JMP backbone supports predicting:

1. System-level properties:
- Total energy
- Stress tensor
- Other graph-level scalar properties

2. Atom-level properties:
- Per-atom forces

Both conservative and non-conservative forces/stresses can be predicted.

## Implementation Details

The backbone is implemented in the `JMPBackboneModule` class which:

- Loads pre-trained weights from checkpoints
- Constructs atomic graphs using the configured settings
- Handles normalization of inputs/outputs
- Manages training and inference

The implementation includes:

- Graph construction
- Property prediction heads
- Normalization utilities
- ASE calculator interface

## Requirements

The JMP backbone requires:
- JMP library
- PyTorch Geometric
- PyTorch

These dependencies will be checked and validated when using the backbone.

## References

- JMP Paper/Documentation
- Source code in `mattertune/backbones/jmp/`
16 changes: 0 additions & 16 deletions docs/backbones/M3GNet.md → docs/backbones/m3gnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,7 @@ The backbone is implemented in `M3GNetBackboneModule` which:
4. Manages normalization of inputs/outputs

Key features:

- Energy-conserving force prediction
- Three-body interactions for improved accuracy
- Efficient graph construction
- Support for periodic boundary conditions

## Requirements

The M3GNet backbone requires:
- matgl
- dgl (Deep Graph Library)
- torch

These dependencies are automatically checked when using the backbone.

## References

- [M3GNet Paper](https://www.nature.com/articles/s43588-022-00349-3)
- [MatGL Documentation](https://materialsvirtuallab.github.io/matgl/)
- Source code in `src/mattertune/backbones/m3gnet/`
30 changes: 18 additions & 12 deletions docs/backbones/ORB.md → docs/backbones/orb.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The ORB backbone allows using pre-trained ORB models as a backbone in MatterTune. ORB is a library that provides pre-trained graph neural networks for predicting material properties.

## ORB Backbone Configuration
## Configuration

To use an ORB backbone, specify the following configuration in your MatterTune config:

Expand All @@ -19,10 +19,12 @@ class ORBBackboneConfig(FinetuneModuleBaseConfig):
"""The system configuration, controlling how to featurize a system of atoms."""
```

The key configuration options are:
### Key Parameters

- `pretrained_model`: The name of the pre-trained ORB model to load. Must be one of the models available in the `orb_models` package.
- `system`: Configures how to convert an `ase.Atoms` object into the graph representation expected by ORB. The `radius` specifies the cutoff distance for including neighbors in the graph, and `max_num_neighbors` limits the maximum number of neighbors per node.
- `system`: Configures how to convert an `ase.Atoms` object into the graph representation expected by ORB:
- `radius`: Specifies the cutoff distance for including neighbors in the graph
- `max_num_neighbors`: Limits the maximum number of neighbors per node

## Supported Properties

Expand All @@ -33,20 +35,24 @@ The ORB backbone supports predicting the following properties:
- Stress (`StressesPropertyConfig` with `conservative=False`)
- Generic graph properties (`GraphPropertyConfig`)

```{note}
Conservative forces and stresses are currently not supported.
```

## Implementation Details

The key components of the ORB backbone implementation in `backbones/orb/model.py` are:
The key components of the ORB backbone implementation are:

- `ORBBackboneModule`: The main module that loads the pre-trained ORB model and defines the forward pass.
- `create_model`: Loads the pre-trained ORB model specified by `pretrained_model` and initializes the output heads.
- `model_forward`: Runs the backbone model and output heads to predict the properties.
- `atoms_to_data`: Converts an `ase.Atoms` object to the graph representation expected by ORB using the configured `system` settings.
### ORBBackboneModule
The main module that loads the pre-trained ORB model and defines the forward pass:
- `create_model`: Loads the pre-trained ORB model and initializes output heads
- `model_forward`: Runs the backbone model and output heads to predict properties
- `atoms_to_data`: Converts `ase.Atoms` objects to ORB graph representation

- Output head creation (`_create_output_head`): Based on the property configuration, the appropriate ORB output head is initialized:
- `EnergyHead` for `EnergyPropertyConfig`
- `NodeHead` for `ForcesPropertyConfig`
- `GraphHead` for `StressesPropertyConfig` and `GraphPropertyConfig`
### Output Heads
Based on the property configuration, appropriate ORB output heads are initialized:
- `EnergyHead` for `EnergyPropertyConfig`
- `NodeHead` for `ForcesPropertyConfig`
- `GraphHead` for `StressesPropertyConfig` and `GraphPropertyConfig`

The ORB backbone leverages the `orb_models` and `nanoflann` packages to load pre-trained models and efficiently construct graph representations suitable for the ORB architecture.
45 changes: 45 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import annotations

import os
import sys

sys.path.insert(0, os.path.abspath(".."))

project = "MatterTune"
copyright = "2023, MatterTune Team"
author = "MatterTune Team"

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
"sphinx.ext.githubpages",
"myst_parser",
]

# MyST Markdown settings
myst_enable_extensions = [
"colon_fence",
"deflist",
"dollarmath",
"fieldlist",
"html_admonition",
"html_image",
"replacements",
"smartquotes",
"tasklist",
]

# Theme settings
html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
html_logo = None
html_favicon = None

# General settings
source_suffix = {
".rst": "restructuredtext",
".md": "markdown",
}
master_doc = "index"
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
41 changes: 41 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Contributing to MatterTune

We welcome contributions to MatterTune! Whether you're fixing bugs, adding new features, improving documentation, or reporting issues, your help is appreciated.

## How to Contribute

1. Fork the repository
2. Create a new branch for your feature
3. Make your changes
4. Submit a pull request

For detailed contribution guidelines, please see our [Contributing Guidelines](https://github.com/Fung-Lab/MatterTune/blob/main/CONTRIBUTING.md) in the repository.

## Development Setup

1. Fork and clone the repository
2. Create a virtual environment
3. Install development dependencies
4. Run tests to ensure everything is working

## Code Style

We follow standard Python code style guidelines:
- Use Black for code formatting
- Follow PEP 8 guidelines
- Write descriptive docstrings
- Add type hints where appropriate

## Testing

Please ensure all tests pass before submitting a pull request:
```bash
pytest tests/
```

## Documentation

When contributing new features, please:
1. Add docstrings to new functions and classes
2. Update relevant documentation files
3. Add examples where appropriate
Loading

0 comments on commit 44172eb

Please sign in to comment.