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.
Files changed (50) hide show
  1. arrayff/__init__.py +29 -0
  2. arrayff/electrostatics/__init__.py +20 -0
  3. arrayff/electrostatics/calculator.py +18 -0
  4. arrayff/electrostatics/placeholders.py +23 -0
  5. arrayff/electrostatics/qeq.py +498 -0
  6. arrayff/neighbors/__init__.py +9 -0
  7. arrayff/neighbors/_list.py +649 -0
  8. arrayff/neighbors/_table.py +388 -0
  9. arrayff/potentials/__init__.py +76 -0
  10. arrayff/potentials/_torch.py +44 -0
  11. arrayff/potentials/base.py +720 -0
  12. arrayff/potentials/calculator.py +146 -0
  13. arrayff/potentials/composite.py +142 -0
  14. arrayff/potentials/eam/__init__.py +1 -0
  15. arrayff/potentials/eam/_torch.py +31 -0
  16. arrayff/potentials/eam/calculator.py +20 -0
  17. arrayff/potentials/eam/eam.py +233 -0
  18. arrayff/potentials/eam/io/__init__.py +8 -0
  19. arrayff/potentials/eam/io/eam.py +115 -0
  20. arrayff/potentials/emt/__init__.py +1 -0
  21. arrayff/potentials/emt/_torch.py +38 -0
  22. arrayff/potentials/emt/calculator.py +18 -0
  23. arrayff/potentials/emt/emt.py +353 -0
  24. arrayff/potentials/pairwise/__init__.py +21 -0
  25. arrayff/potentials/pairwise/_pairs.py +36 -0
  26. arrayff/potentials/pairwise/_torch.py +181 -0
  27. arrayff/potentials/pairwise/base.py +346 -0
  28. arrayff/potentials/pairwise/calculator.py +43 -0
  29. arrayff/potentials/pairwise/forms.py +147 -0
  30. arrayff/potentials/pairwise/lj.py +134 -0
  31. arrayff/potentials/pairwise/lj93.py +85 -0
  32. arrayff/potentials/pairwise/lj_kim.py +138 -0
  33. arrayff/potentials/pairwise/morse.py +100 -0
  34. arrayff/potentials/pairwise/params.py +50 -0
  35. arrayff/potentials/placeholders.py +37 -0
  36. arrayff/potentials/registry.py +49 -0
  37. arrayff/py.typed +0 -0
  38. arrayff/utils/__init__.py +50 -0
  39. arrayff/utils/ad.py +272 -0
  40. arrayff/utils/ase.py +68 -0
  41. arrayff/utils/backend.py +101 -0
  42. arrayff/utils/dispatch.py +118 -0
  43. arrayff/utils/exceptions.py +19 -0
  44. arrayff/utils/interp.py +77 -0
  45. arrayff/utils/jit.py +51 -0
  46. arrayff/utils/optional.py +38 -0
  47. arrayff-0.0.1.dist-info/METADATA +142 -0
  48. arrayff-0.0.1.dist-info/RECORD +50 -0
  49. arrayff-0.0.1.dist-info/WHEEL +4 -0
  50. arrayff-0.0.1.dist-info/licenses/src/LICENSE +674 -0
arrayff/utils/jit.py ADDED
@@ -0,0 +1,51 @@
1
+ """Compilation helpers.
2
+
3
+ Automatic compilation is opt-in and always applied to *array level*
4
+ functions: :class:`ase.Atoms` never enters a compiled function because its
5
+ contents are Python objects that JAX cannot trace.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any
11
+ from collections.abc import Callable
12
+
13
+ import autoray as ar
14
+
15
+
16
+ def jit(
17
+ fn: Callable[..., Any] | None = None,
18
+ *,
19
+ backend: str | None = None,
20
+ compiler_opts: dict[str, Any] | None = None,
21
+ ) -> Callable[..., Any]:
22
+ """Compile ``fn`` with the backend compiler.
23
+
24
+ ``backend="jax"`` uses ``jax.jit``; torch uses ``torch.jit.trace`` via
25
+ autoray. Functions written with :func:`arrayff.utils.dispatch.do` can be
26
+ traced; functions that also call backend AD transforms cannot (except
27
+ JAX).
28
+
29
+ Only functions written with :func:`arrayff.utils.dispatch.do` are traced,
30
+ so kernels must not call backend specific functions directly.
31
+ """
32
+ return ar.autojit(fn, backend=backend, compiler_opts=compiler_opts)
33
+
34
+
35
+ def autojit(fn: Callable[..., Any], backend: str) -> Callable[..., Any]:
36
+ """Alias used by :class:`arrayff.potentials.base.Potential`."""
37
+ return ar.autojit(fn, backend=backend)
38
+
39
+
40
+ def enable_x64() -> None:
41
+ """Enable 64 bit floats in JAX (off by default)."""
42
+ import jax
43
+
44
+ jax.config.update("jax_enable_x64", True)
45
+
46
+
47
+ def x64_enabled() -> bool:
48
+ """Return whether JAX currently uses 64 bit floats."""
49
+ import jax
50
+
51
+ return bool(jax.config.read("jax_enable_x64"))
@@ -0,0 +1,38 @@
1
+ """Helpers for optional dependencies.
2
+
3
+ Optional libraries (``torch``, ``jax``, alternative neighbour builders, ...)
4
+ must never be imported at module import time. Use :func:`require` inside the
5
+ function that actually needs them so that ``import arrayff`` works with only
6
+ the hard dependencies installed.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import importlib
12
+ import importlib.util
13
+ from types import ModuleType
14
+
15
+ from arrayff.utils.exceptions import MissingBackendError
16
+
17
+ __all__ = ["is_available", "require"]
18
+
19
+
20
+ def is_available(module: str) -> bool:
21
+ """Return whether ``module`` is importable without importing it."""
22
+ try:
23
+ return importlib.util.find_spec(module) is not None
24
+ except (ImportError, ValueError): # broken parent package
25
+ return False
26
+
27
+
28
+ def require(module: str, *, extra: str | None = None) -> ModuleType:
29
+ """Import and return ``module`` or raise :class:`MissingBackendError`."""
30
+ try:
31
+ return importlib.import_module(module)
32
+ except ImportError as exc:
33
+ hint = (
34
+ f"; install it with `pip install arrayff[{extra}]`" if extra else ""
35
+ )
36
+ raise MissingBackendError(
37
+ f"The optional dependency {module!r} is required{hint}"
38
+ ) from exc
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.4
2
+ Name: arrayff
3
+ Version: 0.0.1
4
+ Summary: The Force Field Library Based on Multiple Array Backends like NumPy, PyTorch and JAX.
5
+ Keywords: chemistry,Force Field
6
+ Author: LiuGaoyong
7
+ Author-email: LiuGaoyong <liugaoyong_88@163.com>
8
+ License-Expression: GPL-3.0-or-later
9
+ License-File: src/LICENSE
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
12
+ Classifier: Intended Audience :: Science/Research
13
+ Requires-Dist: numpy>=2,<3
14
+ Requires-Dist: ase>=3.23
15
+ Requires-Dist: autoray>=0.6
16
+ Requires-Dist: autograd>=1.6
17
+ Requires-Dist: scipy>=1.10,<2
18
+ Requires-Dist: scikit-learn>=1.5
19
+ Requires-Dist: vesin ; extra == 'builders'
20
+ Requires-Dist: matscipy ; extra == 'builders'
21
+ Requires-Dist: pymatgen ; extra == 'builders'
22
+ Requires-Dist: jax>=0.5 ; extra == 'jax'
23
+ Requires-Dist: torch>=2.3 ; extra == 'torch'
24
+ Requires-Python: >=3.12
25
+ Project-URL: Homepage, https://github.com/LiuGaoyong/ArrayFF
26
+ Project-URL: Repository, https://github.com/LiuGaoyong/ArrayFF
27
+ Project-URL: Issues, https://github.com/LiuGaoyong/ArrayFF/issues/
28
+ Provides-Extra: builders
29
+ Provides-Extra: jax
30
+ Provides-Extra: torch
31
+ Description-Content-Type: text/markdown
32
+
33
+ # ArrayFF
34
+
35
+ The Force Field Library Based on Multiple Array Backends like NumPy, PyTorch
36
+ and JAX.
37
+
38
+ Kernels are written once with [`autoray`](https://github.com/jcmgray/autoray),
39
+ so the backend is chosen by the arrays you pass in. Structural I/O uses
40
+ `ase.Atoms` throughout.
41
+
42
+ The only required array backends are NumPy and
43
+ [`autograd`](https://github.com/HIPS/autograd) (for NumPy autodiff); PyTorch and
44
+ JAX are optional extras.
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ uv pip install -e .
50
+ uv pip install -e ".[torch]" # optional PyTorch backend + nn wrappers
51
+ uv pip install -e ".[jax]" # optional JAX backend
52
+ uv pip install -e ".[builders]" # vesin / matscipy / pymatgen neighbours
53
+ ```
54
+
55
+ ## Quick start
56
+
57
+ ```python
58
+ from ase.build import bulk
59
+ from arrayff.potentials import EMT, EMTCalculator
60
+
61
+ atoms = bulk("Cu", "fcc", a=3.6, cubic=True).repeat((2, 2, 2))
62
+
63
+ calc = EMT() # numpy backend + autograd for forces
64
+ energy, forces = calc.energy_and_forces(atoms, method="analytic")
65
+
66
+ atoms.calc = EMTCalculator() # ASE calculator interface
67
+ energy = atoms.get_potential_energy()
68
+ ```
69
+
70
+ Backends are selected at construction:
71
+
72
+ ```python
73
+ calc = EMT(backend="torch") # or "jax"
74
+ calc = EMT(backend="jax", jit=True)
75
+ ```
76
+
77
+ `LennardJones()` without arguments uses the OpenKIM universal shifted
78
+ parameters (118 elements, cutoff `4*sigma` per pair, Lorentz-Berthelot
79
+ mixing: arithmetic `r0`/cutoff and geometric `epsilon`).
80
+
81
+ Each potential exposes analytic and autodiff forces/stress:
82
+
83
+ ```python
84
+ from arrayff.potentials import LennardJones
85
+
86
+ calc = LennardJones(cutoff=8.0, sigma=3.405, epsilon=0.01032)
87
+ calc.energy_and_forces(atoms, method="analytic")
88
+ calc.energy_and_forces(atoms, method="autodiff")
89
+ calc.stress(atoms, method="analytic")
90
+ ```
91
+
92
+ `jit=True` compiles the array-level kernel with `autoray.autojit` (JAX and
93
+ PyTorch are the useful backends; NumPy's compiler is best-effort).
94
+
95
+ ## Charge equilibration and composite potentials
96
+
97
+ ```python
98
+ from arrayff.electrostatics import QEq
99
+
100
+ qeq = QEq(chi={8: 8.5, 1: 4.5}, J={8: 10.0, 1: 12.0}, shielding=1.0)
101
+ charges = qeq.charges(atoms) # sum == total charge
102
+
103
+ # additive composite: energy/forces/stress add, charges come from QEq
104
+ composite = LennardJones(cutoff=8.0, sigma=3.405, epsilon=0.01032) + qeq
105
+ energy, forces = composite.energy_and_forces(atoms)
106
+ ```
107
+
108
+ QEq supports `charge_response="frozen"` (Hellmann-Feynman, default) and
109
+ `"relaxed"` (differentiate through the charge solve).
110
+
111
+ ## Training (optional)
112
+
113
+ ```python
114
+ from arrayff.potentials import LJTorch
115
+
116
+ model = LJTorch(species=[18]) # epsilon/sigma trainable
117
+ loss = (model(atoms) - target_energy) ** 2
118
+ loss.backward()
119
+ ```
120
+
121
+ ## Tests and benchmarks
122
+
123
+ ```bash
124
+ pytest -q
125
+ pytest -s src/tests-benchmark/bench_potentials.py
126
+ pytest -s src/tests-benchmark/bench_derivatives.py
127
+ ```
128
+
129
+ The benchmark tables compare analytic vs autodiff forces/stress and
130
+ `jit=False/True` across backends.
131
+
132
+ ## Status
133
+
134
+ | Potential | State |
135
+ |---|---|
136
+ | Lennard-Jones (OpenKIM universal shifted) | implemented |
137
+ | Lennard-Jones 9-3, Morse | implemented |
138
+ | EMT (matches `ase.calculators.emt`, including `asap_cutoff`) | implemented |
139
+ | EAM (setfl tables, matches `ase.calculators.eam`) | implemented |
140
+ | QEq (shielded Coulomb, extended matrix, frozen/relaxed response) | implemented |
141
+ | Additive composites (`LJ + QEq`, ...) | implemented |
142
+ | MEAM, UF3, EEM, PQEq | declared placeholders |
@@ -0,0 +1,50 @@
1
+ arrayff/__init__.py,sha256=3cf4VUV2iK5yXtQJeiBpncWzjvguVYLQnBW4AdS6L6w,650
2
+ arrayff/electrostatics/__init__.py,sha256=6AyuRjHzjm0595BMUP7SS0idell_qz7hd1vXMyMxtsY,613
3
+ arrayff/electrostatics/calculator.py,sha256=WefC7hJKfGu1v0rkKQfm8nRuoj-pUeyZeT12IIzhytE,552
4
+ arrayff/electrostatics/placeholders.py,sha256=qYxP3RwoaXm1aQFwQ04T1VeFLAd0BcytDDhwr_MReQc,580
5
+ arrayff/electrostatics/qeq.py,sha256=Y4QBe-q7pPhpp7vyarNP-qSPhIkzd6JQKrx-QchcwYo,17646
6
+ arrayff/neighbors/__init__.py,sha256=s4J1QJvBud9JzmzTbuAfjsCRUUAnttuWVKFSn24biWw,216
7
+ arrayff/neighbors/_list.py,sha256=FtLU2YUMD3WBAsr2ABPHspQg02YyfwZ1CSYWz0GGnmQ,22577
8
+ arrayff/neighbors/_table.py,sha256=ht8nzeFHY1JPyYhemz8Y9oKiW8oKPLOSKQHuD4ZI-3c,13324
9
+ arrayff/potentials/__init__.py,sha256=edx4VUFZsl1IgE2Kx0blvOToubwxevloNUaTKlgZY-M,2362
10
+ arrayff/potentials/_torch.py,sha256=XmEad34GrGhLgLDNps-mGlf8nlt-PtHo4LyR1xvSM9w,1467
11
+ arrayff/potentials/base.py,sha256=cFPB56VI8NDLs27E4_NguGQw-WTfKBLS8AQhrS47Tg4,24444
12
+ arrayff/potentials/calculator.py,sha256=unzJqWkir39BGy8HH2H_xpdLMoNEm-rtk6a6CTdSdTw,5086
13
+ arrayff/potentials/composite.py,sha256=6Hs04KWG1v8nm5NuHHViGc6SUzlNtF4LKzRQMpQSgE0,4848
14
+ arrayff/potentials/eam/__init__.py,sha256=PfNh4w1dU5MHCWg2bx3crqvzzONZDMffL86nTMu3Cj4,21
15
+ arrayff/potentials/eam/_torch.py,sha256=AWVtZwKAUsuOFxI0olIUi6So68xMR9rfTm2mY6D3JeQ,727
16
+ arrayff/potentials/eam/calculator.py,sha256=7GntcTvexyGQe_Cn_CVhUcbzHSuaVtFUrnJud5WHvAg,591
17
+ arrayff/potentials/eam/eam.py,sha256=9JXvufD_ppKCDNwmHV5KXc77P9S9YQe54JMCX-Mj0ds,7630
18
+ arrayff/potentials/eam/io/__init__.py,sha256=vLRtce_UkJRYv_CMwFWXp1A3UwvSPs-vh-yC_LuSs3A,250
19
+ arrayff/potentials/eam/io/eam.py,sha256=GCbUFvAsamsrCk1fASsWmWy-zsljGe8Vc_mlXbqt2-8,3423
20
+ arrayff/potentials/emt/__init__.py,sha256=1OsxVxkgpWaemrcBp72cDuYEzGBQDemJ6phyfw_SDGY,21
21
+ arrayff/potentials/emt/_torch.py,sha256=J08LmxaOfkZ2FVonPxw9EbtdiIlO1Ib8TlWbevhSIfs,967
22
+ arrayff/potentials/emt/calculator.py,sha256=zGJfg8VLsStjMNpppINwmAsIrqQDYKBGph6ryNlBlPk,550
23
+ arrayff/potentials/emt/emt.py,sha256=mnjnJIgHG_5bAOQ_yi_CA-muSsPA70-qNyDwPJQz1QA,11924
24
+ arrayff/potentials/pairwise/__init__.py,sha256=A5QqcIk-ThDUwYaZWjlX_lDAzg5qI6ol01NsjwVHJ-Q,676
25
+ arrayff/potentials/pairwise/_pairs.py,sha256=2RetqhvvfcS_Ki9d9SdxMO-0lwBWOM7tcX-34mAnybw,1222
26
+ arrayff/potentials/pairwise/_torch.py,sha256=PbB7VXf1DckLHT-gjq3FVZVZ0QzlstQmnicsWoRutWE,5844
27
+ arrayff/potentials/pairwise/base.py,sha256=porHmvyRsWpquEXRAazFCQ4HozIvv5pzHqnfKWxr2WA,11468
28
+ arrayff/potentials/pairwise/calculator.py,sha256=AjcckSrflOjPZ3z4af819jy_dD9wqmYgLBerc0F76yQ,1471
29
+ arrayff/potentials/pairwise/forms.py,sha256=dMI9qn_AlFtHLPvEOhLYCwtmJg4j7DylRgKqSPp0hrY,4330
30
+ arrayff/potentials/pairwise/lj.py,sha256=ia9JQGYvBSgd_8bSFUutInJ6lrr-Xb4AQtPCT_3EE_k,4870
31
+ arrayff/potentials/pairwise/lj93.py,sha256=QTfG_x0XKSIIBYsJq2J8DdWggfj8lUQMgUML82N2UCg,2611
32
+ arrayff/potentials/pairwise/lj_kim.py,sha256=eTbIl_D5SRYZV5PF15Nwac2qjI6TQMIEOBu7qNFaplE,5912
33
+ arrayff/potentials/pairwise/morse.py,sha256=ha2tNWiC_K6oTr_BKHMrzbUUrWkPl_pSQTu03FeHA9U,3042
34
+ arrayff/potentials/pairwise/params.py,sha256=slVqliDkOAKxOYYp2p9aAlE9QanyLXdg8w77RCdjjVM,1338
35
+ arrayff/potentials/placeholders.py,sha256=6qqSmImMQkRVHIv_7wtr7SDI1mSA8k0q0KU9k_5oKyc,995
36
+ arrayff/potentials/registry.py,sha256=-RPoLyJnMY7XyMyosgqIILWlXxkvTUkBnz9q6q6v9_w,1537
37
+ arrayff/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
+ arrayff/utils/__init__.py,sha256=sE4cT4UIOUJScFRvwSFBaazYsjgpVf5G9YZpbWAzFc8,1039
39
+ arrayff/utils/ad.py,sha256=Ac760TKxZ6nIDj3pZtoZrAmp14PzxLGGM14BBv0-dQA,8443
40
+ arrayff/utils/ase.py,sha256=ahwZiFjrysLZY60jXiwPBMyaJJpBClEej8oD2_nyj0Q,2292
41
+ arrayff/utils/backend.py,sha256=BH_WqcEtCb1sOtxvhygmp_wP7orZT5gbEaJpxRRewpk,3079
42
+ arrayff/utils/dispatch.py,sha256=0FjMjpgoxTzAsPZXYK7qL2DI2YsXY96hbT5AZbmK6pM,3807
43
+ arrayff/utils/exceptions.py,sha256=A5MXSNaOxdrjkehnbtNmzhpuExEr1BLV0Q4Cs19nkck,509
44
+ arrayff/utils/interp.py,sha256=QK0rL9KqOoNMpYPD1pX_YxY6zUY-BKAOooCpjIPGRuQ,2350
45
+ arrayff/utils/jit.py,sha256=fdUoo8KzwLipVL8Yai--4cWb48IVRkm76w9msyggbR8,1507
46
+ arrayff/utils/optional.py,sha256=AFrlM3WkI8tnk8dWvJaLYjg9E-XkuxtyoAAbW8zRfD8,1242
47
+ arrayff-0.0.1.dist-info/licenses/src/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
48
+ arrayff-0.0.1.dist-info/WHEEL,sha256=3NO1oYsF7mANFUWVdyEQLM-zmecczWWEmmF5rEbXrWk,80
49
+ arrayff-0.0.1.dist-info/METADATA,sha256=zyciyQeJABvJ9gas_LrNzyiKuLK5B6avZ-zACCQd8jA,4567
50
+ arrayff-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.13.6
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any