Skip to content
Open
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: 1 addition & 1 deletion .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.13"
- "3.12"
- "3.11"
- "3.10"
os:
- ubuntu-latest

Expand Down
77 changes: 77 additions & 0 deletions mlipx/aserpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""ASE RPC calculator metadata provider.

This module provides calculator metadata for the aserpc plugin system.
Uses importlib.util.find_spec() for lightweight package detection without
triggering expensive imports (like torch).

Register via entry point in pyproject.toml:
[project.entry-points."aserpc.calculators"]
mlipx = "mlipx.aserpc:get_calculators"
"""

import importlib.util


def _create_orb_calculator(name: str = "orb_v2", device: str = "auto"):
"""Wrapper for ORB models that need pretrained loading."""
from orb_models.forcefield import pretrained
from orb_models.forcefield.calculator import ORBCalculator

method = getattr(pretrained, name)
if device == "auto":
import torch

device = "cuda" if torch.cuda.is_available() else "cpu"
orbff = method(device=device)
return ORBCalculator(orbff, device=device)


def get_calculators() -> dict[str, dict]:
"""Return metadata for available calculators.

Each entry is: {"factory": "module:class", "kwargs": {...}}
or {"factory_fn": callable, "kwargs": {...}} for custom initialization.

Uses importlib.util.find_spec() to check availability without importing.
"""
calcs = {}

# MACE models
if importlib.util.find_spec("mace") is not None:
calcs["mace-mpa-0"] = {
"factory": "mace.calculators:mace_mp",
}

# SevenNet models
if importlib.util.find_spec("sevenn") is not None:
calcs["7net-0"] = {
"factory": "sevenn.sevennet_calculator:SevenNetCalculator",
"kwargs": {"model": "7net-0"},
}
calcs["7net-mf-ompa-mpa"] = {
"factory": "sevenn.sevennet_calculator:SevenNetCalculator",
"kwargs": {"model": "7net-mf-ompa", "modal": "mpa"},
}

# ORB models (custom init)
if importlib.util.find_spec("orb_models") is not None:
calcs["orb-v2"] = {
"factory_fn": _create_orb_calculator,
"kwargs": {"name": "orb_v2"},
}
calcs["orb-v3"] = {
"factory_fn": _create_orb_calculator,
"kwargs": {"name": "orb_v3_conservative_inf_omat"},
}

# CHGNet
if importlib.util.find_spec("chgnet") is not None:
calcs["chgnet"] = {"factory": "chgnet.model:CHGNetCalculator"}

# MatterSim
if importlib.util.find_spec("mattersim") is not None:
calcs["mattersim"] = {
"factory": "mattersim.forcefield:MatterSimCalculator",
}

return calcs
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [

readme = "README.md"
license = "MIT"
requires-python = ">=3.10"
requires-python = ">=3.11"
keywords=["data-version-control", "machine-learning", "reproducibility", "collaboration", "machine-learned interatomic potential", "mlip", "mlff"]

dependencies = [
Expand All @@ -26,6 +26,7 @@ dependencies = [
"dvc-s3>=3.2.0",
"mpcontribs-client>=5.10.2",
"pydantic>=2.10.6",
"aserpc>=0.1.1",
]

[dependency-groups]
Expand Down Expand Up @@ -137,3 +138,6 @@ select = ["I", "F", "E", "C", "W"]

[project.entry-points.'zntrack.nodes']
mlipx = 'mlipx.entrypoints:nodes'

[project.entry-points.'aserpc.calculators']
mlipx = 'mlipx.aserpc:get_calculators'
Loading
Loading