arrayff 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arrayff/__init__.py +29 -0
- arrayff/electrostatics/__init__.py +20 -0
- arrayff/electrostatics/calculator.py +18 -0
- arrayff/electrostatics/placeholders.py +23 -0
- arrayff/electrostatics/qeq.py +498 -0
- arrayff/neighbors/__init__.py +9 -0
- arrayff/neighbors/_list.py +649 -0
- arrayff/neighbors/_table.py +388 -0
- arrayff/potentials/__init__.py +76 -0
- arrayff/potentials/_torch.py +44 -0
- arrayff/potentials/base.py +720 -0
- arrayff/potentials/calculator.py +146 -0
- arrayff/potentials/composite.py +142 -0
- arrayff/potentials/eam/__init__.py +1 -0
- arrayff/potentials/eam/_torch.py +31 -0
- arrayff/potentials/eam/calculator.py +20 -0
- arrayff/potentials/eam/eam.py +233 -0
- arrayff/potentials/eam/io/__init__.py +8 -0
- arrayff/potentials/eam/io/eam.py +115 -0
- arrayff/potentials/emt/__init__.py +1 -0
- arrayff/potentials/emt/_torch.py +38 -0
- arrayff/potentials/emt/calculator.py +18 -0
- arrayff/potentials/emt/emt.py +353 -0
- arrayff/potentials/pairwise/__init__.py +21 -0
- arrayff/potentials/pairwise/_pairs.py +36 -0
- arrayff/potentials/pairwise/_torch.py +181 -0
- arrayff/potentials/pairwise/base.py +346 -0
- arrayff/potentials/pairwise/calculator.py +43 -0
- arrayff/potentials/pairwise/forms.py +147 -0
- arrayff/potentials/pairwise/lj.py +134 -0
- arrayff/potentials/pairwise/lj93.py +85 -0
- arrayff/potentials/pairwise/lj_kim.py +138 -0
- arrayff/potentials/pairwise/morse.py +100 -0
- arrayff/potentials/pairwise/params.py +50 -0
- arrayff/potentials/placeholders.py +37 -0
- arrayff/potentials/registry.py +49 -0
- arrayff/py.typed +0 -0
- arrayff/utils/__init__.py +50 -0
- arrayff/utils/ad.py +272 -0
- arrayff/utils/ase.py +68 -0
- arrayff/utils/backend.py +101 -0
- arrayff/utils/dispatch.py +118 -0
- arrayff/utils/exceptions.py +19 -0
- arrayff/utils/interp.py +77 -0
- arrayff/utils/jit.py +51 -0
- arrayff/utils/optional.py +38 -0
- arrayff-0.0.1.dist-info/METADATA +142 -0
- arrayff-0.0.1.dist-info/RECORD +50 -0
- arrayff-0.0.1.dist-info/WHEEL +4 -0
- arrayff-0.0.1.dist-info/licenses/src/LICENSE +674 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Lennard-Jones 9-3 surface potential."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
from arrayff.potentials.pairwise.base import PairwisePotential
|
|
10
|
+
from arrayff.potentials.pairwise.forms import GeneralizedLJ
|
|
11
|
+
from arrayff.potentials.pairwise.params import PairParameters
|
|
12
|
+
from arrayff.potentials.registry import register_potential
|
|
13
|
+
from arrayff.utils.dispatch import to_backend
|
|
14
|
+
|
|
15
|
+
__all__ = ["LennardJones93"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _per_element(
|
|
19
|
+
value: float | dict[int, float], elements: np.ndarray
|
|
20
|
+
) -> np.ndarray:
|
|
21
|
+
if isinstance(value, dict):
|
|
22
|
+
missing = [int(z) for z in elements if int(z) not in value]
|
|
23
|
+
if missing:
|
|
24
|
+
raise KeyError(f"Missing LJ93 parameters for Z={missing}")
|
|
25
|
+
return np.array([float(value[int(z)]) for z in elements])
|
|
26
|
+
return np.full(len(elements), float(value))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@register_potential("lj93")
|
|
30
|
+
class LennardJones93(PairwisePotential):
|
|
31
|
+
"""9-3 Lennard-Jones potential, usually used for gas-surface pairs."""
|
|
32
|
+
|
|
33
|
+
name = "lj93"
|
|
34
|
+
form = GeneralizedLJ(9, 3)
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
r0: float | dict[int, float],
|
|
39
|
+
depth: float | dict[int, float],
|
|
40
|
+
cutoff: float = 10.0,
|
|
41
|
+
*,
|
|
42
|
+
shift: bool = False,
|
|
43
|
+
smooth: bool = False,
|
|
44
|
+
layout: str = "edges",
|
|
45
|
+
backend: str = "numpy",
|
|
46
|
+
dtype: Any = None,
|
|
47
|
+
max_neighbors: int | None = None,
|
|
48
|
+
builder: str = "sklearn",
|
|
49
|
+
skin: float = 0.0,
|
|
50
|
+
jit: bool = False,
|
|
51
|
+
method: str = "analytic",
|
|
52
|
+
) -> None:
|
|
53
|
+
super().__init__(
|
|
54
|
+
cutoff,
|
|
55
|
+
shift=shift,
|
|
56
|
+
smooth=smooth,
|
|
57
|
+
layout=layout,
|
|
58
|
+
backend=backend,
|
|
59
|
+
dtype=dtype,
|
|
60
|
+
max_neighbors=max_neighbors,
|
|
61
|
+
builder=builder,
|
|
62
|
+
skin=skin,
|
|
63
|
+
jit=jit,
|
|
64
|
+
method=method,
|
|
65
|
+
)
|
|
66
|
+
self.r0 = r0
|
|
67
|
+
self.depth = depth
|
|
68
|
+
self.mixing = {"r0": "arithmetic", "depth": "geometric"}
|
|
69
|
+
|
|
70
|
+
def element_parameters(self, elements: np.ndarray) -> PairParameters:
|
|
71
|
+
r0 = _per_element(self.r0, elements)
|
|
72
|
+
depth = _per_element(self.depth, elements)
|
|
73
|
+
if np.any(r0 <= 0.0):
|
|
74
|
+
raise ValueError("r0 must be positive")
|
|
75
|
+
if np.any(depth < 0.0):
|
|
76
|
+
raise ValueError("depth must be non-negative")
|
|
77
|
+
return PairParameters(
|
|
78
|
+
elements=np.asarray(elements, dtype=np.int64),
|
|
79
|
+
values={
|
|
80
|
+
"r0": to_backend(r0, self.backend),
|
|
81
|
+
"depth": to_backend(depth, self.backend),
|
|
82
|
+
},
|
|
83
|
+
mixing=self.mixing,
|
|
84
|
+
cutoff=None,
|
|
85
|
+
)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Lennard-Jones parameters from the OpenKIM universal shifted model.
|
|
2
|
+
|
|
3
|
+
Model: LennardJones612_UniversalShifted__MO_959249795837_003
|
|
4
|
+
https://openkim.org (LGPL-2.1-or-later).
|
|
5
|
+
|
|
6
|
+
sigma from covalent radii, epsilon from bond dissociation energies and
|
|
7
|
+
cutoff = 4 * sigma; each pair is shifted to zero at its cutoff.
|
|
8
|
+
Values are (cutoff [Angstrom], epsilon [eV], sigma [Angstrom]).
|
|
9
|
+
|
|
10
|
+
https://github.com/openkim/kim-api/blob/master/examples/portable-models/LennardJones612_UniversalShifted__MO_959249795837_003/LennardJones612_UniversalShifted.params
|
|
11
|
+
KIM-KEY: LennardJones612_UniversalShifted__MO_959249795837_003
|
|
12
|
+
LJ_ElliottAkerson_2015_Universal__MO_959249795837_003
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
__all__ = ["KIM_LJ_PARAMETERS"]
|
|
18
|
+
|
|
19
|
+
KIM_LJ_PARAMETERS: dict[int, tuple[float, float, float]] = {
|
|
20
|
+
1: (2.20943, 4.47789, 0.552357), # H
|
|
21
|
+
2: (1.99561, 0.0009421, 0.498903), # He
|
|
22
|
+
3: (9.1228, 1.04969, 2.2807), # Li
|
|
23
|
+
4: (6.8421, 0.572942, 1.71053), # Be
|
|
24
|
+
5: (6.05811, 2.96703, 1.51453), # B
|
|
25
|
+
6: (5.41666, 6.36953, 1.35417), # C
|
|
26
|
+
7: (5.0603, 9.75379, 1.26508), # N
|
|
27
|
+
8: (4.70395, 5.12647, 1.17599), # O
|
|
28
|
+
9: (4.0625, 1.60592, 1.01562), # F
|
|
29
|
+
10: (4.13377, 0.0036471, 1.03344), # Ne
|
|
30
|
+
11: (11.8311, 0.736745, 2.95778), # Na
|
|
31
|
+
12: (10.0493, 0.0785788, 2.51233), # Mg
|
|
32
|
+
13: (8.6239, 2.70067, 2.15597), # Al
|
|
33
|
+
14: (7.91118, 3.17431, 1.9778), # Si
|
|
34
|
+
15: (7.62609, 5.0305, 1.90652), # P
|
|
35
|
+
16: (7.48355, 4.36927, 1.87089), # S
|
|
36
|
+
17: (7.26973, 4.48328, 1.81743), # Cl
|
|
37
|
+
18: (7.55482, 0.0123529, 1.88871), # Ar
|
|
38
|
+
19: (14.4682, 0.551799, 3.61705), # K
|
|
39
|
+
20: (12.5439, 0.132679, 3.13596), # Ca
|
|
40
|
+
21: (12.1162, 1.6508, 3.02906), # Sc
|
|
41
|
+
22: (11.4035, 1.18027, 2.85088), # Ti
|
|
42
|
+
23: (10.9046, 2.75249, 2.72615), # V
|
|
43
|
+
24: (9.90679, 1.53679, 2.4767), # Cr
|
|
44
|
+
25: (9.90679, 0.599888, 2.4767), # Mn
|
|
45
|
+
26: (9.40789, 1.18442, 2.35197), # Fe
|
|
46
|
+
27: (8.98026, 1.27769, 2.24506), # Co
|
|
47
|
+
28: (8.83772, 2.07572, 2.20943), # Ni
|
|
48
|
+
29: (9.40789, 2.04463, 2.35197), # Cu
|
|
49
|
+
30: (8.69517, 0.191546, 2.17379), # Zn
|
|
50
|
+
31: (8.69517, 1.0642, 2.17379), # Ga
|
|
51
|
+
32: (8.55263, 2.70171, 2.13816), # Ge
|
|
52
|
+
33: (8.48136, 3.9599, 2.12034), # As
|
|
53
|
+
34: (8.55263, 3.38677, 2.13816), # Se
|
|
54
|
+
35: (8.55263, 1.97063, 2.13816), # Br
|
|
55
|
+
36: (8.26754, 0.0173276, 2.06689), # Kr
|
|
56
|
+
37: (15.6798, 0.468265, 3.91995), # Rb
|
|
57
|
+
38: (13.898, 0.133923, 3.47451), # Sr
|
|
58
|
+
39: (13.5417, 2.75975, 3.38542), # Y
|
|
59
|
+
40: (12.4726, 3.05201, 3.11815), # Zr
|
|
60
|
+
41: (11.6886, 5.2782, 2.92215), # Nb
|
|
61
|
+
42: (10.9759, 4.47499, 2.74397), # Mo
|
|
62
|
+
43: (10.477, 3.38159, 2.61924), # Tc
|
|
63
|
+
44: (10.4057, 1.96172, 2.60142), # Ru
|
|
64
|
+
45: (10.1206, 2.40582, 2.53015), # Rh
|
|
65
|
+
46: (9.90679, 1.37097, 2.4767), # Pd
|
|
66
|
+
47: (10.3344, 1.64976, 2.58361), # Ag
|
|
67
|
+
48: (10.2632, 0.0377447, 2.56579), # Cd
|
|
68
|
+
49: (10.1206, 0.811314, 2.53015), # In
|
|
69
|
+
50: (9.90679, 1.90057, 2.4767), # Sn
|
|
70
|
+
51: (9.90679, 3.08828, 2.4767), # Sb
|
|
71
|
+
52: (9.83552, 2.63123, 2.45888), # Te
|
|
72
|
+
53: (9.90679, 1.53938, 2.4767), # I
|
|
73
|
+
54: (9.97807, 0.023888, 2.49452), # Xe
|
|
74
|
+
55: (17.3903, 0.416642, 4.34759), # Cs
|
|
75
|
+
56: (15.3235, 1.9, 3.83086), # Ba
|
|
76
|
+
57: (14.7533, 2.49961, 3.68832), # La
|
|
77
|
+
58: (14.5395, 2.57008, 3.63487), # Ce
|
|
78
|
+
59: (14.4682, 1.29946, 3.61705), # Pr
|
|
79
|
+
60: (14.3257, 0.819605, 3.58141), # Nd
|
|
80
|
+
61: (14.1831, 3.24134, 3.54578), # Pm
|
|
81
|
+
62: (14.1118, 0.521122, 3.52796), # Sm
|
|
82
|
+
63: (14.1118, 0.429918, 3.52796), # Eu
|
|
83
|
+
64: (13.9693, 2.09956, 3.49232), # Gd
|
|
84
|
+
65: (13.8267, 1.39999, 3.45669), # Tb
|
|
85
|
+
66: (13.6842, 0.690055, 3.42105), # Dy
|
|
86
|
+
67: (13.6842, 0.690055, 3.42105), # Ho
|
|
87
|
+
68: (13.4704, 0.738766, 3.3676), # Er
|
|
88
|
+
69: (13.5417, 0.521122, 3.38542), # Tm
|
|
89
|
+
70: (13.3278, 0.130399, 3.33196), # Yb
|
|
90
|
+
71: (13.3278, 1.43315, 3.33196), # Lu
|
|
91
|
+
72: (12.4726, 3.36086, 3.11815), # Hf
|
|
92
|
+
73: (12.1162, 4.00343, 3.02906), # Ta
|
|
93
|
+
74: (11.546, 6.86389, 2.88651), # W
|
|
94
|
+
75: (10.7621, 4.43871, 2.69051), # Re
|
|
95
|
+
76: (10.2632, 4.26253, 2.56579), # Os
|
|
96
|
+
77: (10.0493, 3.70287, 2.51233), # Ir
|
|
97
|
+
78: (9.69298, 3.1401, 2.42324), # Pt
|
|
98
|
+
79: (9.69298, 2.3058, 2.42324), # Au
|
|
99
|
+
80: (9.40789, 0.045414, 2.35197), # Hg
|
|
100
|
+
81: (10.3344, 0.577087, 2.58361), # Tl
|
|
101
|
+
82: (10.4057, 0.858988, 2.60142), # Pb
|
|
102
|
+
83: (10.5482, 2.07987, 2.63706), # Bi
|
|
103
|
+
84: (9.97807, 1.89953, 2.49452), # Po
|
|
104
|
+
85: (10.6908, 1.385442, 2.6727), # At
|
|
105
|
+
86: (10.6908, 0.0214992, 2.6727), # Rn
|
|
106
|
+
87: (18.5307, 0.3749778, 4.63267), # Fr
|
|
107
|
+
88: (15.7511, 1.71, 3.93777), # Ra
|
|
108
|
+
89: (15.3235, 2.249649, 3.83086), # Ac
|
|
109
|
+
90: (14.682, 2.313072, 3.6705), # Th
|
|
110
|
+
91: (14.2544, 1.169514, 3.56359), # Pa
|
|
111
|
+
92: (13.9693, 0.7376445, 3.49232), # U
|
|
112
|
+
93: (13.5417, 2.917206, 3.38542), # Np
|
|
113
|
+
94: (13.3278, 0.4690098, 3.33196), # Pu
|
|
114
|
+
95: (12.8289, 0.3869262, 3.20724), # Am
|
|
115
|
+
96: (12.045, 1.889604, 3.01124), # Cm
|
|
116
|
+
97: (11.9737, 1.259991, 2.99342), # Bk
|
|
117
|
+
98: (11.9737, 0.6210495, 2.99342), # Cf
|
|
118
|
+
99: (11.7599, 0.6210495, 2.93997), # Es
|
|
119
|
+
100: (11.9024, 0.6648894, 2.9756), # Fm
|
|
120
|
+
101: (12.33, 0.4690098, 3.08251), # Md
|
|
121
|
+
102: (12.5439, 0.1173591, 3.13596), # No
|
|
122
|
+
103: (11.4748, 1.289835, 2.86869), # Lr
|
|
123
|
+
104: (11.1897, 3.024774, 2.79742), # Rf
|
|
124
|
+
105: (10.6195, 3.603087, 2.65488), # Db
|
|
125
|
+
106: (10.1919, 6.177501, 2.54797), # Sg
|
|
126
|
+
107: (10.0493, 3.994839, 2.51233), # Bh
|
|
127
|
+
108: (9.55043, 3.836277, 2.38761), # Hs
|
|
128
|
+
109: (9.19407, 3.332583, 2.29852), # Mt
|
|
129
|
+
110: (9.1228, 2.82609, 2.2807), # Ds
|
|
130
|
+
111: (8.6239, 2.07522, 2.15597), # Rg
|
|
131
|
+
112: (8.69517, 0.0408726, 2.17379), # Cn
|
|
132
|
+
113: (9.69298, 0.5193783, 2.42324), # Nh
|
|
133
|
+
114: (10.1919, 0.7730892, 2.54797), # Fl
|
|
134
|
+
115: (11.546, 1.871883, 2.88651), # Mc
|
|
135
|
+
116: (12.4726, 1.709577, 3.11815), # Lv
|
|
136
|
+
117: (11.7599, 1.2468978, 2.93997), # Ts
|
|
137
|
+
118: (11.1897, 0.0193493, 2.79742), # Og
|
|
138
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""Morse potential built on the generic pairwise layer."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
from arrayff.potentials.pairwise.base import PairwisePotential
|
|
10
|
+
from arrayff.potentials.pairwise.forms import Morse as MorseForm
|
|
11
|
+
from arrayff.potentials.pairwise.params import PairParameters
|
|
12
|
+
from arrayff.potentials.registry import register_potential
|
|
13
|
+
from arrayff.utils.dispatch import to_backend
|
|
14
|
+
|
|
15
|
+
__all__ = ["Morse"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _per_element(
|
|
19
|
+
value: float | dict[int, float], elements: np.ndarray
|
|
20
|
+
) -> np.ndarray:
|
|
21
|
+
if isinstance(value, dict):
|
|
22
|
+
missing = [int(z) for z in elements if int(z) not in value]
|
|
23
|
+
if missing:
|
|
24
|
+
raise KeyError(f"Missing Morse parameters for Z={missing}")
|
|
25
|
+
return np.array([float(value[int(z)]) for z in elements])
|
|
26
|
+
return np.full(len(elements), float(value))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@register_potential("morse")
|
|
30
|
+
class Morse(PairwisePotential):
|
|
31
|
+
"""Morse potential ``depth * (exp(-2a(r-r0)) - 2 exp(-a(r-r0)))``."""
|
|
32
|
+
|
|
33
|
+
name = "morse"
|
|
34
|
+
form = MorseForm()
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
r0: float | dict[int, float],
|
|
39
|
+
depth: float | dict[int, float],
|
|
40
|
+
a: float | dict[int, float] = 1.5,
|
|
41
|
+
cutoff: float = 10.0,
|
|
42
|
+
*,
|
|
43
|
+
shift: bool = True,
|
|
44
|
+
smooth: bool = False,
|
|
45
|
+
layout: str = "edges",
|
|
46
|
+
backend: str = "numpy",
|
|
47
|
+
dtype: Any = None,
|
|
48
|
+
max_neighbors: int | None = None,
|
|
49
|
+
builder: str = "sklearn",
|
|
50
|
+
skin: float = 0.0,
|
|
51
|
+
jit: bool = False,
|
|
52
|
+
method: str = "analytic",
|
|
53
|
+
) -> None:
|
|
54
|
+
super().__init__(
|
|
55
|
+
cutoff,
|
|
56
|
+
shift=shift,
|
|
57
|
+
smooth=smooth,
|
|
58
|
+
layout=layout,
|
|
59
|
+
backend=backend,
|
|
60
|
+
dtype=dtype,
|
|
61
|
+
max_neighbors=max_neighbors,
|
|
62
|
+
builder=builder,
|
|
63
|
+
skin=skin,
|
|
64
|
+
jit=jit,
|
|
65
|
+
method=method,
|
|
66
|
+
)
|
|
67
|
+
self.r0 = r0
|
|
68
|
+
self.depth = depth
|
|
69
|
+
self.a = a
|
|
70
|
+
self.mixing = {
|
|
71
|
+
"r0": "arithmetic",
|
|
72
|
+
"depth": "geometric",
|
|
73
|
+
"a": "arithmetic",
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
def element_parameters(self, elements: np.ndarray) -> PairParameters:
|
|
77
|
+
values = {
|
|
78
|
+
"r0": _per_element(self.r0, elements),
|
|
79
|
+
"depth": _per_element(self.depth, elements),
|
|
80
|
+
"a": _per_element(self.a, elements),
|
|
81
|
+
}
|
|
82
|
+
if np.any(values["r0"] <= 0.0):
|
|
83
|
+
raise ValueError("r0 must be positive")
|
|
84
|
+
if np.any(values["depth"] < 0.0):
|
|
85
|
+
raise ValueError("depth must be non-negative")
|
|
86
|
+
if np.any(values["a"] <= 0.0):
|
|
87
|
+
raise ValueError("a must be positive")
|
|
88
|
+
return PairParameters(
|
|
89
|
+
elements=np.asarray(elements, dtype=np.int64),
|
|
90
|
+
values={
|
|
91
|
+
name: to_backend(value, self.backend)
|
|
92
|
+
for name, value in values.items()
|
|
93
|
+
},
|
|
94
|
+
mixing={
|
|
95
|
+
"r0": "arithmetic",
|
|
96
|
+
"depth": "geometric",
|
|
97
|
+
"a": "arithmetic",
|
|
98
|
+
},
|
|
99
|
+
cutoff=None,
|
|
100
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Per-element parameters for pairwise potentials."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import dataclasses as dc
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
from arrayff.utils.dispatch import to_backend
|
|
11
|
+
|
|
12
|
+
__all__ = ["PairParameters"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dc.dataclass(frozen=True)
|
|
16
|
+
class PairParameters:
|
|
17
|
+
"""Element ordered parameters plus mixing rules.
|
|
18
|
+
|
|
19
|
+
Attributes
|
|
20
|
+
----------
|
|
21
|
+
elements:
|
|
22
|
+
Sorted unique atomic numbers, ``(S,)``.
|
|
23
|
+
values:
|
|
24
|
+
``{name: (S,) array}`` with the per element parameters.
|
|
25
|
+
mixing:
|
|
26
|
+
``{name: rule}`` overriding the form's defaults.
|
|
27
|
+
cutoff:
|
|
28
|
+
Optional ``(S,)`` per element cutoff radius, mixed pairwise just like
|
|
29
|
+
the other parameters (this is what the OpenKIM universal model wants).
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
elements: np.ndarray
|
|
33
|
+
values: dict[str, Any]
|
|
34
|
+
mixing: dict[str, str]
|
|
35
|
+
cutoff: Any | None = None
|
|
36
|
+
|
|
37
|
+
def to_backend(self, backend: str) -> PairParameters:
|
|
38
|
+
if backend == "numpy":
|
|
39
|
+
return self
|
|
40
|
+
return PairParameters(
|
|
41
|
+
elements=self.elements,
|
|
42
|
+
values={
|
|
43
|
+
name: to_backend(value, backend)
|
|
44
|
+
for name, value in self.values.items()
|
|
45
|
+
},
|
|
46
|
+
mixing=self.mixing,
|
|
47
|
+
cutoff=None
|
|
48
|
+
if self.cutoff is None
|
|
49
|
+
else to_backend(self.cutoff, backend),
|
|
50
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Declared but not yet implemented potentials.
|
|
2
|
+
|
|
3
|
+
They are registered with ``implemented=False`` so the public API advertises the
|
|
4
|
+
roadmap honestly: ``get_potential("meam")`` raises ``NotImplementedError`` and
|
|
5
|
+
constructing the class directly raises a ``ScopeError``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from arrayff.potentials.registry import register_potential
|
|
11
|
+
from arrayff.utils.exceptions import ScopeError
|
|
12
|
+
|
|
13
|
+
__all__ = ["MEAM", "UF3"]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class _Placeholder:
|
|
17
|
+
name = "placeholder"
|
|
18
|
+
|
|
19
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
20
|
+
raise ScopeError(
|
|
21
|
+
f"{type(self).__name__} is declared in the API but not implemented "
|
|
22
|
+
"yet; see docs/architecture.md for the roadmap."
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@register_potential("meam", implemented=False)
|
|
27
|
+
class MEAM(_Placeholder):
|
|
28
|
+
"""Second nearest neighbour MEAM (planned)."""
|
|
29
|
+
|
|
30
|
+
name = "meam"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@register_potential("uf3", implemented=False)
|
|
34
|
+
class UF3(_Placeholder):
|
|
35
|
+
"""UF3 spline force field (planned)."""
|
|
36
|
+
|
|
37
|
+
name = "uf3"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Potential registration.
|
|
2
|
+
|
|
3
|
+
The registry drives the public ``arrayff.get_potential`` helper and records
|
|
4
|
+
which potentials are implemented, so placeholder modules can be shipped
|
|
5
|
+
without pretending to work.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Callable
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
__all__ = ["available_potentials", "get_potential", "register_potential"]
|
|
14
|
+
|
|
15
|
+
_REGISTRY: dict[str, tuple[Callable[..., Any], bool]] = {}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def register_potential(
|
|
19
|
+
name: str, *, implemented: bool = True
|
|
20
|
+
) -> Callable[[Callable[..., Any]], Callable[..., Any]]:
|
|
21
|
+
"""Register a potential class under ``name``."""
|
|
22
|
+
|
|
23
|
+
def decorator(cls: Callable[..., Any]) -> Callable[..., Any]:
|
|
24
|
+
if name in _REGISTRY:
|
|
25
|
+
raise KeyError(f"Potential {name!r} is already registered")
|
|
26
|
+
_REGISTRY[name] = (cls, implemented)
|
|
27
|
+
return cls
|
|
28
|
+
|
|
29
|
+
return decorator
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_potential(name: str, **kwargs: Any) -> Any:
|
|
33
|
+
"""Instantiate the potential registered under ``name``."""
|
|
34
|
+
try:
|
|
35
|
+
cls, implemented = _REGISTRY[name]
|
|
36
|
+
except KeyError:
|
|
37
|
+
raise KeyError(
|
|
38
|
+
f"Unknown potential {name!r}; available: {sorted(_REGISTRY)}"
|
|
39
|
+
) from None
|
|
40
|
+
if not implemented:
|
|
41
|
+
raise NotImplementedError(
|
|
42
|
+
f"Potential {name!r} is declared but not implemented yet."
|
|
43
|
+
)
|
|
44
|
+
return cls(**kwargs)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def available_potentials() -> dict[str, bool]:
|
|
48
|
+
"""Return ``{name: implemented}`` for every known potential."""
|
|
49
|
+
return {name: flag for name, (_, flag) in sorted(_REGISTRY.items())}
|
arrayff/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Low level utilities shared by the rest of :mod:`arrayff`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from arrayff.utils.backend import (
|
|
6
|
+
ARRAY_BACKENDS,
|
|
7
|
+
available_backends,
|
|
8
|
+
default_dtype,
|
|
9
|
+
infer_backend,
|
|
10
|
+
resolve_ad_backend,
|
|
11
|
+
)
|
|
12
|
+
from arrayff.utils.dispatch import (
|
|
13
|
+
do,
|
|
14
|
+
dtype_of,
|
|
15
|
+
register_autograd_alias,
|
|
16
|
+
require_same_backend,
|
|
17
|
+
to_backend,
|
|
18
|
+
to_numpy,
|
|
19
|
+
)
|
|
20
|
+
from arrayff.utils.exceptions import (
|
|
21
|
+
ArrayFFError,
|
|
22
|
+
MissingBackendError,
|
|
23
|
+
ScopeError,
|
|
24
|
+
ShapeError,
|
|
25
|
+
)
|
|
26
|
+
from arrayff.utils.jit import enable_x64, jit, x64_enabled
|
|
27
|
+
from arrayff.utils.optional import is_available, require
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"ARRAY_BACKENDS",
|
|
31
|
+
"ArrayFFError",
|
|
32
|
+
"MissingBackendError",
|
|
33
|
+
"ScopeError",
|
|
34
|
+
"ShapeError",
|
|
35
|
+
"available_backends",
|
|
36
|
+
"default_dtype",
|
|
37
|
+
"do",
|
|
38
|
+
"dtype_of",
|
|
39
|
+
"enable_x64",
|
|
40
|
+
"infer_backend",
|
|
41
|
+
"is_available",
|
|
42
|
+
"jit",
|
|
43
|
+
"require",
|
|
44
|
+
"register_autograd_alias",
|
|
45
|
+
"require_same_backend",
|
|
46
|
+
"resolve_ad_backend",
|
|
47
|
+
"to_backend",
|
|
48
|
+
"to_numpy",
|
|
49
|
+
"x64_enabled",
|
|
50
|
+
]
|