Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nequip support fixes #223 #304

Merged
merged 8 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Tools for machine learnt interatomic potentials
- matgl = 1.1.3 (optional)
- sevenn = 0.10.3 (optional)
- alignn = 2024.5.27 (optional)
- nequip = 0.6.1 (optional)

All required and optional dependencies can be found in [pyproject.toml](pyproject.toml).

Expand Down Expand Up @@ -92,6 +93,7 @@ Current and planned features include:
- CHGNet
- ALIGNN (experimental)
- SevenNet (experimental)
- NequIP (experimental)
- [x] Single point calculations
- [x] Geometry optimisation
- [x] Molecular Dynamics
Expand Down
2 changes: 2 additions & 0 deletions docs/source/getting_started/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Dependencies
- matgl = 1.1.3 (optional)
- sevenn = 0.10.3 (optional)
- alignn = 2024.5.27 (optional)
- nequip = 0.6.1 (optional)

All required and optional dependencies can be found in `pyproject.toml <https://github.com/stfc/janus-core/blob/main/pyproject.toml>`_.

Expand Down Expand Up @@ -56,5 +57,6 @@ Currently supported extras are:
- ``chgnet``: `CHGNet <https://github.com/CederGroupHub/chgnet/>`_
- ``m3gnet``: `M3GNet <https://github.com/materialsvirtuallab/matgl/>`_
- ``sevenn``: `SevenNet <https://github.com/MDIL-SNU/SevenNet/>`_
- ``nequip``: `NequIP <https://github.com/mir-group/nequip>`_

``extras`` are also listed in `pyproject.toml <https://github.com/stfc/janus-core/blob/main/pyproject.toml>`_ under ``[project.optional-dependencies]``.
2 changes: 1 addition & 1 deletion janus_core/helpers/janus_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class CorrelationKwargs(TypedDict, total=True):

# Janus specific
Architectures = Literal[
"mace", "mace_mp", "mace_off", "m3gnet", "chgnet", "alignn", "sevennet"
"mace", "mace_mp", "mace_off", "m3gnet", "chgnet", "alignn", "sevennet", "nequip"
]
Devices = Literal["cpu", "cuda", "mps", "xpu"]
Ensembles = Literal["nph", "npt", "nve", "nvt", "nvt-nh", "nvt-csvr", "npt-mtk"]
Expand Down
16 changes: 16 additions & 0 deletions janus_core/helpers/mlip_calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ def choose_calculator(
kwargs.setdefault("sevennet_config", None)
calculator = SevenNetCalculator(model=model_path, device=device, **kwargs)

elif arch == "nequip":
from nequip import __version__
from nequip.ase import NequIPCalculator

# No default `model_path`
if model_path is None:
raise ValueError(
alinelena marked this conversation as resolved.
Show resolved Hide resolved
f"Please specify `model_path`, as there is no default model for {arch}"
)

model_path = str(model_path)

calculator = NequIPCalculator.from_deployed_model(
model_path=model_path, device=device, **kwargs
)

else:
raise ValueError(
f"Unrecognized {arch=}. Suported architectures "
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ m3gnet = [
sevennet = [
"sevenn == 0.10.3",
]
nequip = [
"nequip == 0.6.1",
]
all = [
"janus-core[alignn]",
"janus-core[chgnet]",
"janus-core[m3gnet]",
"janus-core[sevennet]",
"janus-core[nequip]",
]

[project.scripts]
Expand Down
17 changes: 17 additions & 0 deletions tests/data/toluene.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
15
Toluene
C 1.2264 0.0427 0.0670
C 1.0031 -1.3293 0.0600
C -0.2945 -1.8256 -0.0060
C -1.3704 -0.9461 -0.0646
C -1.1511 0.4266 -0.0578
C 0.1497 0.9292 0.0066
C 0.3871 2.3956 -0.0022
H 2.2495 0.4310 0.1211
H 1.8510 -2.0202 0.1071
H -0.4688 -2.9062 -0.0109
H -2.3926 -1.3347 -0.1157
H -2.0006 1.1172 -0.1021
H 0.5024 2.7582 -1.0330
H 1.2994 2.6647 0.5466
H -0.4475 2.9470 0.4506
Binary file added tests/models/toluene.pth
Binary file not shown.
17 changes: 17 additions & 0 deletions tests/test_mlip_calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

ALIGNN_PATH = MODEL_PATH / "v5.27.2024"

NEQUIP_PATH = MODEL_PATH / "toluene.pth"


@pytest.mark.parametrize(
"arch, device, kwargs",
Expand All @@ -52,6 +54,8 @@
("chgnet", "cpu", {"model": "0.2.0"}),
("chgnet", "cpu", {"model_path": CHGNET_PATH}),
("chgnet", "cpu", {"model": CHGNET_MODEL}),
("nequip", "cpu", {"model_path": NEQUIP_PATH}),
("nequip", "cpu", {"model": NEQUIP_PATH}),
],
)
def test_mlips(arch, device, kwargs):
Expand All @@ -75,6 +79,7 @@ def test_invalid_arch():
("mace_mp", "/invalid/path"),
("m3gnet", "/invalid/path"),
("chgnet", "/invalid/path"),
("nequip", "/invalid/path"),
],
)
def test_invalid_model_path(arch, model_path):
Expand Down Expand Up @@ -119,6 +124,8 @@ def test_invalid_device(arch):
("sevennet", "cpu", {"model_path": SEVENNET_PATH}),
("sevennet", "cpu", {}),
("sevennet", "cpu", {"model": "sevennet-0"}),
("nequip", "cpu", {"model_path": NEQUIP_PATH}),
("nequip", "cpu", {"model": NEQUIP_PATH}),
],
)
def test_extra_mlips(arch, device, kwargs):
Expand Down Expand Up @@ -159,6 +166,16 @@ def test_extra_mlips(arch, device, kwargs):
"model_path": SEVENNET_PATH,
"model": SEVENNET_PATH,
},
{
"arch": "nequip",
"model_path": NEQUIP_PATH,
"model": NEQUIP_PATH,
},
{
"arch": "nequip",
"model_path": NEQUIP_PATH,
"path": NEQUIP_PATH,
},
],
)
def test_extra_mlips_invalid(kwargs):
Expand Down
23 changes: 17 additions & 6 deletions tests/test_single_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
MACE_PATH = MODEL_PATH / "mace_mp_small.model"
SEVENNET_PATH = MODEL_PATH / "sevennet_0.pth"
ALIGNN_PATH = MODEL_PATH / "v5.27.2024"
NEQUIP_PATH = MODEL_PATH / "toluene.pth"

test_data = [
(DATA_PATH / "benzene.xyz", -76.0605725422795, "energy", "energy", {}, None),
Expand Down Expand Up @@ -279,20 +280,30 @@ def test_mlips(arch, device, expected_energy):
"alignn",
"cpu",
-11.148092269897461,
"NaCl.cif",
{"model_path": ALIGNN_PATH / "best_model.pt"},
),
("sevennet", "cpu", -27.061979293823242, {"model_path": SEVENNET_PATH}),
("sevennet", "cpu", -27.061979293823242, {}),
("sevennet", "cpu", -27.061979293823242, {"model_path": "SevenNet-0_11July2024"}),
("sevennet", "cpu", -27.061979293823242, "NaCl.cif", {"model_path": SEVENNET_PATH}),
("sevennet", "cpu", -27.061979293823242, "NaCl.cif", {}),
(
"sevennet",
"cpu",
-27.061979293823242,
"NaCl.cif",
{"model_path": "SevenNet-0_11July2024"},
),
("nequip", "cpu", -169815.1282456301, "toluene.xyz", {"model_path": NEQUIP_PATH}),
ElliottKasoar marked this conversation as resolved.
Show resolved Hide resolved
]


@pytest.mark.extra_mlips
@pytest.mark.parametrize("arch, device, expected_energy, kwargs", test_extra_mlips_data)
def test_extra_mlips_alignn(arch, device, expected_energy, kwargs):
@pytest.mark.parametrize(
"arch, device, expected_energy, struct, kwargs", test_extra_mlips_data
)
def test_extra_mlips_alignn(arch, device, expected_energy, struct, kwargs):
"""Test single point energy using extra mlips calculators."""
single_point = SinglePoint(
struct_path=DATA_PATH / "NaCl.cif",
struct_path=DATA_PATH / struct,
arch=arch,
device=device,
properties="energy",
Expand Down