Skip to content

Commit

Permalink
Merge branch 'materialsvirtuallab:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kenko911 authored Nov 17, 2023
2 parents 233cb4d + c3e5642 commit 4587b9b
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

release:
if: github.event.name == 'release'
if: github.event_name == 'release'
needs: test
runs-on: ubuntu-latest
permissions:
Expand Down
21 changes: 6 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,32 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.284
rev: v0.1.5
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.0
rev: v1.7.0
hooks:
- id: mypy

- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
stages: [commit, commit-msg]
exclude_types: [html]
additional_dependencies: [tomli] # needed to read pyproject.toml below py3.11
args: [--check-filenames]

- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.15.0
Expand All @@ -45,12 +42,6 @@ repos:
args: [--no-pycodestyle]
- id: double-quote-cython-strings

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
hooks:
- id: nbqa-ruff
args: [--fix]

- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
hooks:
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Testing](https://github.com/materialsvirtuallab/matgl/actions/workflows/testing.yml/badge.svg)](https://github.com/materialsvirtuallab/matgl/actions/workflows/testing.yml)
[![Downloads](https://static.pepy.tech/badge/matgl)](https://pepy.tech/project/matgl)
[![codecov](https://codecov.io/gh/materialsvirtuallab/matgl/branch/main/graph/badge.svg?token=3V3O79GODQ)](https://codecov.io/gh/materialsvirtuallab/matgl)
[![PyPI](https://img.shields.io/pypi/v/matgl?logo=pypi&logoColor=white)](https://pypi.org/project/matgl?logo=pypi&logoColor=white)

# Materials Graph Library <img src="https://github.com/materialsvirtuallab/matgl/blob/main/assets/MatGL.png?raw=true" alt="matgl" width="30%" style="float: right">

Expand Down Expand Up @@ -50,7 +51,6 @@ in future.
<p>Figure: Schematic of M3GNet/MEGNet</p>
</div>


### MEGNet

[MatErials Graph Network (MEGNet)][megnet] is an implementation of DeepMind's [graph networks][graphnetwork] for
Expand Down Expand Up @@ -178,24 +178,24 @@ information. If you are using any of the pretrained models, please cite the rele

> **MEGNet**
>
> Chen, C.; Ye, W.; Zuo, Y.; Zheng, C.; Ong, S. P. _Graph Networks as a Universal Machine Learning Framework for
> Molecules and Crystals._ Chem. Mater. 2019, 31 (9), 3564–3572. DOI: [10.1021/acs.chemmater.9b01294][megnet].
> Chen, C.; Ye, W.; Zuo, Y.; Zheng, C.; Ong, S. P. *Graph Networks as a Universal Machine Learning Framework for
> Molecules and Crystals.* Chem. Mater. 2019, 31 (9), 3564–3572. DOI: [10.1021/acs.chemmater.9b01294][megnet].

> **Multi-fidelity MEGNet**
>
> Chen, C.; Zuo, Y.; Ye, W.; Li, X.; Ong, S. P. _Learning Properties of Ordered and Disordered Materials from
> Multi-Fidelity Data._ Nature Computational Science, 2021, 1, 46–53. DOI: [10.1038/s43588-020-00002-x][mfimegnet].
> Chen, C.; Zuo, Y.; Ye, W.; Li, X.; Ong, S. P. *Learning Properties of Ordered and Disordered Materials from
> Multi-Fidelity Data.* Nature Computational Science, 2021, 1, 46–53. DOI: [10.1038/s43588-020-00002-x][mfimegnet].

> **M3GNet**
>
> Chen, C., Ong, S.P. _A universal graph deep learning interatomic potential for the periodic table._ Nature
> Chen, C., Ong, S.P. *A universal graph deep learning interatomic potential for the periodic table.* Nature
> Computational Science, 2023, 2, 718–728. DOI: [10.1038/s43588-022-00349-3][m3gnet].

## FAQs

1. **The `M3GNet-MP-2021.2.8-PES` differs from the original TensorFlow (TF) implementation!**

_Answer:_ `M3GNet-MP-2021.2.8-PES` is a refitted model with some data improvements and minor architectural changes.
*Answer:* `M3GNet-MP-2021.2.8-PES` is a refitted model with some data improvements and minor architectural changes.
Porting over the weights from the TF version to DGL/PyTorch is non-trivial. We have performed reasonable benchmarking
to ensure that the new implementation reproduces the broad error characteristics of the original TF implementation
(see [examples][jupyternb]). However, it is not expected to reproduce the TF version exactly. This refitted model
Expand All @@ -204,22 +204,22 @@ information. If you are using any of the pretrained models, please cite the rele

2. **I am getting errors with `matgl.load_model()`!**
_Answer:_ The most likely reason is that you have a cached older version of the model. We often refactor models to
*Answer:* The most likely reason is that you have a cached older version of the model. We often refactor models to
ensure the best implementation. This can usually be solved by updating your `matgl` to the latest version
and clearing your cache using the following command `mgl clear`. On the next run, the latest model will be
downloaded. With effect from v0.5.2, we have implemented a model versioning scheme that will detect code vs model
version conflicts and alert the user of such problems.
3. **What pre-trained models should I be using?**
_Answer:_ There is no one definitive answer. In general, the newer the architecture and dataset, the more likely
*Answer:* There is no one definitive answer. In general, the newer the architecture and dataset, the more likely
the model performs better. However, it should also be noted that a model operating on a more diverse dataset may
compromise on performance on a specific system. The best way is to look at the READMEs included with each model
and do some tests on the systems you are interested in.
4. **How do I contribute to matgl?**
_Answer:_ For code contributions, please fork and submit pull requests. You should read the
*Answer:* For code contributions, please fork and submit pull requests. You should read the
[developer guide](developer.md) to understand the general design guidelines. We welcome pre-trained model
contributions as well, which should also be submitted via PRs. Please follow the folder structure of the
pretrained models. In particular, we expect all models to come with a `README.md` and notebook
Expand All @@ -229,7 +229,7 @@ information. If you are using any of the pretrained models, please cite the rele
5. **None of your models do what I need. Where can I get help?**
_Answer:_ Please contact [Prof Ong][ongemail] with a brief description of your needs. For simple problems, we are
*Answer:* Please contact [Prof Ong][ongemail] with a brief description of your needs. For simple problems, we are
glad to advise and point you in the right direction. For more complicated problems, we are always open to
academic collaborations or projects. We also offer [consulting services][mqm] for companies with unique needs,
including but not limited to custom data generation, model development and materials design.
Expand Down
143 changes: 99 additions & 44 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,93 +6,148 @@ nav_order: 3

# Change Log

## v0.8.6

* set pbc_offsift and pos as float64 by @lbluque in https://github.com/materialsvirtuallab/matgl/pull/153
* Bump pytorch-lightning from 2.0.7 to 2.0.8 by @dependabot in https://github.com/materialsvirtuallab/matgl/pull/155
* add cpu() to avoid crash when using ase with GPU by @kenko911 in https://github.com/materialsvirtuallab/matgl/pull/156
* Added the united test for hessian in test_ase.py to improve the coverage score by @kenko911 in https://github.com/materialsvirtuallab/matgl/pull/157
* AtomRef Updates by @lbluque in https://github.com/materialsvirtuallab/matgl/pull/158
* Bump pymatgen from 2023.8.10 to 2023.9.2 by @dependabot in https://github.com/materialsvirtuallab/matgl/pull/160
* Remove torch.unique for finding the maximum three body index and little cleanup in united tests by @kenko911 in https://github.com/materialsvirtuallab/matgl/pull/161
* Bump pymatgen from 2023.9.2 to 2023.9.10 by @dependabot in https://github.com/materialsvirtuallab/matgl/pull/162
* Add united test for trainer.test and description in the example by @kenko911 in https://github.com/materialsvirtuallab/matgl/pull/165
* Bump pytorch-lightning from 2.0.8 to 2.0.9 by @dependabot in https://github.com/materialsvirtuallab/matgl/pull/167
* Sequence instead of list for inputs by @lbluque in https://github.com/materialsvirtuallab/matgl/pull/169
* Avoiding crashes for PES training without stresses and update pretrained models by @kenko911 in https://github.com/materialsvirtuallab/matgl/pull/168
* Bump pymatgen from 2023.9.10 to 2023.9.25 by @dependabot in https://github.com/materialsvirtuallab/matgl/pull/173
* Allow to choose distribution in xavier_init by @lbluque in https://github.com/materialsvirtuallab/matgl/pull/174
* An example for the simple training of M3GNet formation energy model is added by @kenko911 in https://github.com/materialsvirtuallab/matgl/pull/176
* Directed line graph by @lbluque in https://github.com/materialsvirtuallab/matgl/pull/178
* Bump pymatgen from 2023.9.25 to 2023.10.4 by @dependabot in https://github.com/materialsvirtuallab/matgl/pull/180
* Bump torch from 2.0.1 to 2.1.0 by @dependabot in https://github.com/materialsvirtuallab/matgl/pull/181
* Bump pymatgen from 2023.10.4 to 2023.10.11 by @dependabot in https://github.com/materialsvirtuallab/matgl/pull/183
* add testing to m3gnet potential training example by @lbluque in https://github.com/materialsvirtuallab/matgl/pull/179
* Update Training a MEGNet Formation Energy Model with PyTorch Lightnin… by @1152041831 in https://github.com/materialsvirtuallab/matgl/pull/185
* Bump pymatgen from 2023.10.11 to 2023.11.12 by @dependabot in https://github.com/materialsvirtuallab/matgl/pull/187
* dEdLat contribution for stress calculations is added and Universal Potentials are updated by @kenko911 in https://github.com/materialsvirtuallab/matgl/pull/189
* Bump torch from 2.1.0 to 2.1.1 by @dependabot in https://github.com/materialsvirtuallab/matgl/pull/190

## New Contributors

* @1152041831 made their first contribution in https://github.com/materialsvirtuallab/matgl/pull/185

**Full Changelog**: https://github.com/materialsvirtuallab/matgl/compare/v0.8.5...v0.8.6

## 0.8.3
- Extend the functionality of ASE-interface for molecular systems and include more different ensembles. (@kenko911)
- Improve the dgl graph construction and fix the if statements for stress and atomwise training. (@kenko911)
- Refactored MEGNetDataset and M3GNetDataset classes with optimizations.

* Extend the functionality of ASE-interface for molecular systems and include more different ensembles. (@kenko911)
* Improve the dgl graph construction and fix the if statements for stress and atomwise training. (@kenko911)
* Refactored MEGNetDataset and M3GNetDataset classes with optimizations.

## 0.8.5
- Bug fix for np.meshgrid. (@kenko911)

* Bug fix for np.meshgrid. (@kenko911)

## 0.8.2
- Add site-wise predictions for Potential. (@lbluque)
- Enable CLI tool to be used for multi-fidelity models. (@kenko911)
- Minor fix for model version for DIRECT model.

* Add site-wise predictions for Potential. (@lbluque)
* Enable CLI tool to be used for multi-fidelity models. (@kenko911)
* Minor fix for model version for DIRECT model.

## 0.8.1
- Fixed bug with loading of models trained with GPUs.
- Updated default model for relaxations to be the `M3GNet-MP-2021.2.8-DIRECT-PES model`.

* Fixed bug with loading of models trained with GPUs.
* Updated default model for relaxations to be the `M3GNet-MP-2021.2.8-DIRECT-PES model`.

## 0.8.0
- Fix a bug with use of set2set in M3Gnet implementation that affected intensive models such as the formation energy

* Fix a bug with use of set2set in M3Gnet implementation that affected intensive models such as the formation energy
model. M3GNet model version is updated to 2 to invalidate previous models. Note that PES models are unaffected.
(@kenko911)

## 0.7.1
- Minor optimizations for memory and isolated atom training (@kenko911)

* Minor optimizations for memory and isolated atom training (@kenko911)

## 0.7.0
- MatGL now supports structures with isolated atoms. (@JiQi535)
- Fourier expansion layer and generalize cutoff polynomial. (@lbluque)
- Radial bessel (zeroth order bessel). (@lbluque)

* MatGL now supports structures with isolated atoms. (@JiQi535)
* Fourier expansion layer and generalize cutoff polynomial. (@lbluque)
* Radial bessel (zeroth order bessel). (@lbluque)

## 0.6.2
- Simple CLI tool `mgl` added.

* Simple CLI tool `mgl` added.

## 0.6.1
- Bug fix for training loss_fn.

* Bug fix for training loss_fn.

## 0.6.0
- Refactoring of training utilities. Added example for training an M3GNet potential.

* Refactoring of training utilities. Added example for training an M3GNet potential.

## 0.5.6
- Minor internal refactoring of basis expansions into `_basis.py`. (@lbluque)

* Minor internal refactoring of basis expansions into `_basis.py`. (@lbluque)

## 0.5.5
- Critical bug fix for code regression affecting pre-loaded models.

* Critical bug fix for code regression affecting pre-loaded models.

## 0.5.4
- M3GNet Formation energy model added, with example notebook.
- M3GNet.predict_structure method added.
- Massively improved documentation at http://matgl.ai.

* M3GNet Formation energy model added, with example notebook.
* M3GNet.predict_structure method added.
* Massively improved documentation at http://matgl.ai.

## 0.5.3
- Minor doc and code usability improvements.

* Minor doc and code usability improvements.

## 0.5.2
- Minor improvements to model versioning scheme.
- Added `matgl.get_available_pretrained_models()` to help with model discovery.
- Misc doc and error message improvements.

* Minor improvements to model versioning scheme.
* Added `matgl.get_available_pretrained_models()` to help with model discovery.
* Misc doc and error message improvements.

## 0.5.1
- Model versioning scheme implemented.
- Added convenience method to clear cache.

* Model versioning scheme implemented.
* Added convenience method to clear cache.

## 0.5.0
- Model serialization has been completely rewritten to make it easier to use models out of the box.
- Convenience method `matgl.load_model` is now the default way to load models.
- Added a TransformedTargetModel.
- Enable serialization of Potential.
- IMPORTANT: Pre-trained models have been reserialized. These models can only be used with v0.5.0+!

* Model serialization has been completely rewritten to make it easier to use models out of the box.
* Convenience method `matgl.load_model` is now the default way to load models.
* Added a TransformedTargetModel.
* Enable serialization of Potential.
* IMPORTANT: Pre-trained models have been reserialized. These models can only be used with v0.5.0+!

## 0.4.0
- Pre-trained M3GNet universal potential
- Pytorch lightning training utility.

* Pre-trained M3GNet universal potential
* Pytorch lightning training utility.

## v0.3.0
- Major refactoring of MEGNet and M3GNet models and organization of internal implementations. Only key API are exposed

* Major refactoring of MEGNet and M3GNet models and organization of internal implementations. Only key API are exposed
via matgl.models or matgl.layers to hide internal implementations (which may change).
- Pre-trained models ported over to new implementation.
- Model download now implemented.
* Pre-trained models ported over to new implementation.
* Model download now implemented.

## v0.2.1
- Fixes for pre-trained model download.
- Speed up M3GNet 3-body computations.

* Fixes for pre-trained model download.
* Speed up M3GNet 3-body computations.

## v0.2.0
- Pre-trained MEGNet models for formation energies and band gaps are now available.
- MEGNet model implemented with `predict_structure` convenience method.
- Example notebook demonstrating pre-trained model usage is available.

* Pre-trained MEGNet models for formation energies and band gaps are now available.
* MEGNet model implemented with `predict_structure` convenience method.
* Example notebook demonstrating pre-trained model usage is available.

## v0.1.0
- Initial working version with m3gnet and megnet.

* Initial working version with m3gnet and megnet.
14 changes: 8 additions & 6 deletions matgl/ext/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Relaxer:

def __init__(
self,
potential: Potential | None = None,
potential: Potential,
state_attr: torch.Tensor | None = None,
optimizer: Optimizer | str = "FIRE",
relax_cell: bool = True,
Expand All @@ -209,7 +209,9 @@ def __init__(
"""
self.optimizer: Optimizer = OPTIMIZERS[optimizer.lower()].value if isinstance(optimizer, str) else optimizer
self.calculator = M3GNetCalculator(
potential=potential, state_attr=state_attr, stress_weight=stress_weight # type: ignore
potential=potential,
state_attr=state_attr,
stress_weight=stress_weight, # type: ignore
)
self.relax_cell = relax_cell
self.potential = potential
Expand Down Expand Up @@ -295,7 +297,7 @@ def __len__(self):
return len(self.energies)

def as_pandas(self) -> pd.DataFrame:
"""Returns: DataFrame of energies, forces, streeses, cells and atom_positions."""
"""Returns: DataFrame of energies, forces, stresses, cells and atom_positions."""
return pd.DataFrame(
{
"energies": self.energies,
Expand Down Expand Up @@ -368,18 +370,18 @@ def __init__(
taut (float): time constant for Berendsen temperature coupling
taup (float): time constant for pressure coupling
friction (float): friction coefficient for nvt_langevin, typically set to 1e-4 to 1e-2
andersen_prob (float): random collision probility for nvt_andersen, typically set to 1e-4 to 1e-1
andersen_prob (float): random collision probability for nvt_andersen, typically set to 1e-4 to 1e-1
ttime (float): Characteristic timescale of the thermostat, in ASE internal units
pfactor (float): A constant in the barostat differential equation.
external_stress (float): The external stress in eV/A^3.
Either 3x3 tensor,6-vector or a scalar representing pressure
Either 3x3 tensor,6-vector or a scalar representing pressure
compressibility_au (float): compressibility of the material in A^3/eV
trajectory (str or Trajectory): Attach trajectory object
logfile (str): open this file for recording MD outputs
loginterval (int): write to log file every interval steps
append_trajectory (bool): Whether to append to prev trajectory.
mask (np.array): either a tuple of 3 numbers (0 or 1) or a symmetric 3x3 array indicating,
which strain values may change for NPT simulations.
which strain values may change for NPT simulations.
"""
if isinstance(atoms, (Structure, Molecule)):
atoms = AseAtomsAdaptor().get_atoms(atoms)
Expand Down
Loading

0 comments on commit 4587b9b

Please sign in to comment.