Skip to content

Commit 682277d

Browse files
Define machine learning / MatPES schemas (#1222)
* Add schemas for ML training and specifically for the MP co-led MatPES project * Make matcalc optional
1 parent d55444f commit 682277d

File tree

15 files changed

+434
-99
lines changed

15 files changed

+434
-99
lines changed

emmet-builders/emmet/builders/materials/ml.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,26 @@
33

44
from maggma.builders.map_builder import MapBuilder
55
from maggma.core import Store
6-
from matcalc import PESCalculator
6+
7+
try:
8+
from matcalc import PESCalculator
9+
10+
matcalc_installed = True
11+
except ImportError:
12+
matcalc_installed = False
13+
714
from pymatgen.core import Structure
815

916
from emmet.core.ml import MLDoc
1017
from emmet.core.utils import jsanitize
1118

1219
if TYPE_CHECKING:
13-
from ase.calculators.calculator import Calculator
20+
try:
21+
from ase.calculators.calculator import Calculator
22+
23+
ase_installed = True
24+
except ImportError:
25+
ase_installed = False
1426

1527

1628
class MLBuilder(MapBuilder):
@@ -40,6 +52,10 @@ def __init__(
4052
MLDocs. Will be saved in each document so use sparingly. Defaults to None.
4153
Set to {} to disable default provenance model, version, matcalc_version.
4254
"""
55+
56+
if not matcalc_installed or not ase_installed:
57+
raise ImportError("Please `pip install matcalc` to use the MLBuilder.")
58+
4359
self.materials = materials
4460
self.ml_potential = ml_potential
4561
self.kwargs = kwargs

emmet-core/emmet/core/math.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,19 @@
2323

2424
ListMatrix3D = List[ListVector3D]
2525
ListMatrix3D.__doc__ = "Real space Matrix as list" # type: ignore
26+
27+
VOIGT_INDICES = [(0, 0), (1, 1), (2, 2), (1, 2), (0, 2), (0, 1)]
28+
29+
30+
def matrix_3x3_to_voigt(matrix: Matrix3D) -> list[float]:
31+
"""Convert a 3x3 symmetric matrix to its Voigt vector representation.
32+
33+
Parameters
34+
-----------
35+
matrix : Matrix3D
36+
37+
Returns
38+
-----------
39+
list of float
40+
"""
41+
return [matrix[idx[0]][idx[1]] for idx in VOIGT_INDICES]

0 commit comments

Comments
 (0)