arrayff 0.1.0__tar.gz → 0.2.0__tar.gz

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 (140) hide show
  1. arrayff-0.2.0/PKG-INFO +695 -0
  2. arrayff-0.2.0/README.md +651 -0
  3. {arrayff-0.1.0 → arrayff-0.2.0}/pyproject.toml +30 -1
  4. {arrayff-0.1.0 → arrayff-0.2.0}/pyproject.toml.orig +31 -1
  5. arrayff-0.2.0/src/arrayff/__init__.py +62 -0
  6. arrayff-0.2.0/src/arrayff/_compat.py +73 -0
  7. arrayff-0.2.0/src/arrayff/cli/__init__.py +172 -0
  8. arrayff-0.2.0/src/arrayff/cli/config.py +141 -0
  9. arrayff-0.2.0/src/arrayff/cli/training.py +582 -0
  10. {arrayff-0.1.0/src/arrayff/utils → arrayff-0.2.0/src/arrayff/core}/__init__.py +5 -5
  11. {arrayff-0.1.0/src/arrayff/utils → arrayff-0.2.0/src/arrayff/core}/ad.py +8 -9
  12. arrayff-0.1.0/src/arrayff/utils/ase.py → arrayff-0.2.0/src/arrayff/core/atoms.py +1 -1
  13. {arrayff-0.1.0/src/arrayff/utils → arrayff-0.2.0/src/arrayff/core}/backend.py +2 -2
  14. arrayff-0.2.0/src/arrayff/core/bspline.py +173 -0
  15. {arrayff-0.1.0/src/arrayff/utils → arrayff-0.2.0/src/arrayff/core}/dispatch.py +215 -11
  16. {arrayff-0.1.0/src/arrayff/utils → arrayff-0.2.0/src/arrayff/core}/interp.py +10 -6
  17. {arrayff-0.1.0/src/arrayff/utils → arrayff-0.2.0/src/arrayff/core}/jit.py +10 -8
  18. {arrayff-0.1.0/src/arrayff/utils → arrayff-0.2.0/src/arrayff/core}/optional.py +1 -1
  19. {arrayff-0.1.0/src/arrayff/utils → arrayff-0.2.0/src/arrayff/core}/stress.py +3 -5
  20. arrayff-0.2.0/src/arrayff/core/switching.py +70 -0
  21. arrayff-0.2.0/src/arrayff/core/system.py +177 -0
  22. arrayff-0.2.0/src/arrayff/core/tree.py +179 -0
  23. arrayff-0.2.0/src/arrayff/engine/__init__.py +7 -0
  24. arrayff-0.2.0/src/arrayff/engine/evaluator.py +624 -0
  25. arrayff-0.2.0/src/arrayff/interfaces/ase.py +210 -0
  26. arrayff-0.2.0/src/arrayff/interfaces/torch.py +429 -0
  27. arrayff-0.2.0/src/arrayff/io/__init__.py +0 -0
  28. arrayff-0.1.0/src/arrayff/potentials/eam/io/eam.py → arrayff-0.2.0/src/arrayff/io/eam_setfl.py +1 -1
  29. arrayff-0.2.0/src/arrayff/io/export.py +306 -0
  30. arrayff-0.2.0/src/arrayff/io/meam_library.py +234 -0
  31. arrayff-0.2.0/src/arrayff/io/reaxff_ffield.py +333 -0
  32. arrayff-0.2.0/src/arrayff/io/uf3.py +268 -0
  33. arrayff-0.2.0/src/arrayff/mc/__init__.py +44 -0
  34. arrayff-0.2.0/src/arrayff/mc/force_bias.py +193 -0
  35. arrayff-0.2.0/src/arrayff/mc/local.py +357 -0
  36. arrayff-0.2.0/src/arrayff/mc/moves.py +231 -0
  37. arrayff-0.2.0/src/arrayff/mc/observables.py +75 -0
  38. arrayff-0.2.0/src/arrayff/mc/samplers.py +466 -0
  39. arrayff-0.2.0/src/arrayff/models/__init__.py +92 -0
  40. {arrayff-0.1.0/src/arrayff/potentials → arrayff-0.2.0/src/arrayff/models}/_torch.py +21 -13
  41. arrayff-0.2.0/src/arrayff/models/base.py +479 -0
  42. arrayff-0.2.0/src/arrayff/models/composite.py +273 -0
  43. {arrayff-0.1.0/src/arrayff/potentials → arrayff-0.2.0/src/arrayff/models}/eam/_torch.py +11 -3
  44. arrayff-0.2.0/src/arrayff/models/eam/calculator.py +7 -0
  45. arrayff-0.2.0/src/arrayff/models/eam/eam.py +180 -0
  46. arrayff-0.2.0/src/arrayff/models/electrostatics/__init__.py +80 -0
  47. arrayff-0.2.0/src/arrayff/models/electrostatics/_torch.py +603 -0
  48. arrayff-0.2.0/src/arrayff/models/electrostatics/calculator.py +7 -0
  49. arrayff-0.2.0/src/arrayff/models/electrostatics/charges/__init__.py +9 -0
  50. arrayff-0.2.0/src/arrayff/models/electrostatics/charges/base.py +66 -0
  51. arrayff-0.2.0/src/arrayff/models/electrostatics/charges/eem.py +37 -0
  52. arrayff-0.2.0/src/arrayff/models/electrostatics/charges/qeq.py +33 -0
  53. arrayff-0.2.0/src/arrayff/models/electrostatics/eem.py +85 -0
  54. arrayff-0.2.0/src/arrayff/models/electrostatics/ewald.py +14 -0
  55. arrayff-0.2.0/src/arrayff/models/electrostatics/kernels.py +276 -0
  56. arrayff-0.2.0/src/arrayff/models/electrostatics/model.py +408 -0
  57. arrayff-0.2.0/src/arrayff/models/electrostatics/placeholders.py +5 -0
  58. arrayff-0.2.0/src/arrayff/models/electrostatics/pqeq.py +1314 -0
  59. arrayff-0.2.0/src/arrayff/models/electrostatics/qeq.py +103 -0
  60. arrayff-0.2.0/src/arrayff/models/electrostatics/solvers/__init__.py +25 -0
  61. arrayff-0.2.0/src/arrayff/models/electrostatics/solvers/base.py +115 -0
  62. arrayff-0.2.0/src/arrayff/models/electrostatics/solvers/direct.py +37 -0
  63. arrayff-0.2.0/src/arrayff/models/electrostatics/solvers/ewald.py +208 -0
  64. arrayff-0.2.0/src/arrayff/models/emt/_torch.py +129 -0
  65. arrayff-0.2.0/src/arrayff/models/emt/calculator.py +7 -0
  66. arrayff-0.2.0/src/arrayff/models/emt/emt.py +371 -0
  67. arrayff-0.2.0/src/arrayff/models/meam/__init__.py +13 -0
  68. arrayff-0.2.0/src/arrayff/models/meam/_torch.py +197 -0
  69. arrayff-0.2.0/src/arrayff/models/meam/meam.py +841 -0
  70. arrayff-0.2.0/src/arrayff/models/pairwise/__init__.py +21 -0
  71. {arrayff-0.1.0/src/arrayff/potentials → arrayff-0.2.0/src/arrayff/models}/pairwise/_torch.py +73 -52
  72. arrayff-0.2.0/src/arrayff/models/pairwise/base.py +155 -0
  73. arrayff-0.2.0/src/arrayff/models/pairwise/calculator.py +7 -0
  74. {arrayff-0.1.0/src/arrayff/potentials → arrayff-0.2.0/src/arrayff/models}/pairwise/forms.py +2 -2
  75. {arrayff-0.1.0/src/arrayff/potentials → arrayff-0.2.0/src/arrayff/models}/pairwise/lj.py +5 -7
  76. {arrayff-0.1.0/src/arrayff/potentials → arrayff-0.2.0/src/arrayff/models}/pairwise/lj93.py +4 -6
  77. {arrayff-0.1.0/src/arrayff/potentials → arrayff-0.2.0/src/arrayff/models}/pairwise/morse.py +4 -6
  78. {arrayff-0.1.0/src/arrayff/potentials → arrayff-0.2.0/src/arrayff/models}/pairwise/params.py +5 -4
  79. arrayff-0.2.0/src/arrayff/models/placeholders.py +3 -0
  80. arrayff-0.2.0/src/arrayff/models/reaxff/__init__.py +20 -0
  81. arrayff-0.2.0/src/arrayff/models/reaxff/_torch.py +502 -0
  82. arrayff-0.2.0/src/arrayff/models/reaxff/bond_order.py +411 -0
  83. arrayff-0.2.0/src/arrayff/models/reaxff/model.py +598 -0
  84. arrayff-0.2.0/src/arrayff/models/reaxff/params.py +253 -0
  85. arrayff-0.2.0/src/arrayff/models/reaxff/terms/__init__.py +26 -0
  86. arrayff-0.2.0/src/arrayff/models/reaxff/terms/angles.py +343 -0
  87. arrayff-0.2.0/src/arrayff/models/reaxff/terms/atoms.py +127 -0
  88. arrayff-0.2.0/src/arrayff/models/reaxff/terms/bonds.py +74 -0
  89. arrayff-0.2.0/src/arrayff/models/reaxff/terms/hbonds.py +71 -0
  90. arrayff-0.2.0/src/arrayff/models/reaxff/terms/nonbonded.py +203 -0
  91. arrayff-0.2.0/src/arrayff/models/reaxff/terms/torsions.py +271 -0
  92. arrayff-0.2.0/src/arrayff/models/reaxff/topology.py +157 -0
  93. arrayff-0.2.0/src/arrayff/models/registry.py +281 -0
  94. arrayff-0.2.0/src/arrayff/models/uf/__init__.py +26 -0
  95. arrayff-0.2.0/src/arrayff/models/uf/_terms.py +155 -0
  96. arrayff-0.2.0/src/arrayff/models/uf/_torch.py +104 -0
  97. arrayff-0.2.0/src/arrayff/models/uf/fit.py +400 -0
  98. arrayff-0.2.0/src/arrayff/models/uf/uf3.py +333 -0
  99. {arrayff-0.1.0 → arrayff-0.2.0}/src/arrayff/neighbors/_list.py +1 -1
  100. arrayff-0.2.0/src/arrayff/neighbors/_manybody.py +265 -0
  101. {arrayff-0.1.0 → arrayff-0.2.0}/src/arrayff/neighbors/_table.py +27 -3
  102. arrayff-0.2.0/src/arrayff/neighbors/cache.py +217 -0
  103. arrayff-0.2.0/src/arrayff/neighbors/container.py +165 -0
  104. arrayff-0.2.0/src/arrayff/neighbors/pairs.py +135 -0
  105. {arrayff-0.1.0 → arrayff-0.2.0}/src/arrayff/optimize/__init__.py +9 -1
  106. {arrayff-0.1.0 → arrayff-0.2.0}/src/arrayff/optimize/_dimer.py +12 -7
  107. {arrayff-0.1.0 → arrayff-0.2.0}/src/arrayff/optimize/_helper.py +44 -10
  108. {arrayff-0.1.0 → arrayff-0.2.0}/src/arrayff/optimize/_neb.py +23 -11
  109. arrayff-0.2.0/src/arrayff/py.typed +0 -0
  110. arrayff-0.1.0/PKG-INFO +0 -229
  111. arrayff-0.1.0/README.md +0 -191
  112. arrayff-0.1.0/src/arrayff/__init__.py +0 -34
  113. arrayff-0.1.0/src/arrayff/electrostatics/__init__.py +0 -20
  114. arrayff-0.1.0/src/arrayff/electrostatics/calculator.py +0 -18
  115. arrayff-0.1.0/src/arrayff/electrostatics/ewald.py +0 -78
  116. arrayff-0.1.0/src/arrayff/electrostatics/placeholders.py +0 -23
  117. arrayff-0.1.0/src/arrayff/electrostatics/qeq.py +0 -579
  118. arrayff-0.1.0/src/arrayff/potentials/__init__.py +0 -78
  119. arrayff-0.1.0/src/arrayff/potentials/base.py +0 -729
  120. arrayff-0.1.0/src/arrayff/potentials/calculator.py +0 -146
  121. arrayff-0.1.0/src/arrayff/potentials/composite.py +0 -155
  122. arrayff-0.1.0/src/arrayff/potentials/eam/calculator.py +0 -20
  123. arrayff-0.1.0/src/arrayff/potentials/eam/eam.py +0 -206
  124. arrayff-0.1.0/src/arrayff/potentials/eam/io/__init__.py +0 -8
  125. arrayff-0.1.0/src/arrayff/potentials/emt/_torch.py +0 -40
  126. arrayff-0.1.0/src/arrayff/potentials/emt/calculator.py +0 -18
  127. arrayff-0.1.0/src/arrayff/potentials/emt/emt.py +0 -329
  128. arrayff-0.1.0/src/arrayff/potentials/pairwise/__init__.py +0 -21
  129. arrayff-0.1.0/src/arrayff/potentials/pairwise/_pairs.py +0 -43
  130. arrayff-0.1.0/src/arrayff/potentials/pairwise/base.py +0 -322
  131. arrayff-0.1.0/src/arrayff/potentials/pairwise/calculator.py +0 -43
  132. arrayff-0.1.0/src/arrayff/potentials/placeholders.py +0 -37
  133. arrayff-0.1.0/src/arrayff/potentials/registry.py +0 -49
  134. {arrayff-0.1.0 → arrayff-0.2.0}/src/LICENSE +0 -0
  135. {arrayff-0.1.0/src/arrayff/utils → arrayff-0.2.0/src/arrayff/core}/exceptions.py +0 -0
  136. /arrayff-0.1.0/src/arrayff/py.typed → /arrayff-0.2.0/src/arrayff/interfaces/__init__.py +0 -0
  137. {arrayff-0.1.0/src/arrayff/potentials → arrayff-0.2.0/src/arrayff/models}/eam/__init__.py +0 -0
  138. {arrayff-0.1.0/src/arrayff/potentials → arrayff-0.2.0/src/arrayff/models}/emt/__init__.py +0 -0
  139. {arrayff-0.1.0/src/arrayff/potentials → arrayff-0.2.0/src/arrayff/models}/pairwise/lj_kim.py +0 -0
  140. {arrayff-0.1.0 → arrayff-0.2.0}/src/arrayff/neighbors/__init__.py +0 -0
arrayff-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,695 @@
1
+ Metadata-Version: 2.4
2
+ Name: arrayff
3
+ Version: 0.2.0
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 :: 3 - Alpha
11
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
12
+ Classifier: Intended Audience :: Science/Research
13
+ Requires-Dist: numpy
14
+ Requires-Dist: ase>=3.23
15
+ Requires-Dist: scipy>=1.6
16
+ Requires-Dist: autograd>=1.6 ; extra == 'autograd'
17
+ Requires-Dist: autoray>=0.6 ; extra == 'autoray'
18
+ Requires-Dist: vesin ; extra == 'builders'
19
+ Requires-Dist: matscipy ; extra == 'builders'
20
+ Requires-Dist: pymatgen ; extra == 'builders'
21
+ Requires-Dist: scikit-learn>=1.5 ; extra == 'builders'
22
+ Requires-Dist: jax>=0.5 ; extra == 'jax'
23
+ Requires-Dist: autoray>=0.6 ; extra == 'jax'
24
+ Requires-Dist: autograd>=1.6 ; extra == 'reaxff'
25
+ Requires-Dist: autoray>=0.6 ; extra == 'reaxff'
26
+ Requires-Dist: scikit-learn>=1.5 ; extra == 'sklearn'
27
+ Requires-Dist: torch>=2.3 ; extra == 'torch'
28
+ Requires-Dist: autoray>=0.6 ; extra == 'torch'
29
+ Requires-Dist: autograd>=1.6 ; extra == 'uf3'
30
+ Requires-Dist: autoray>=0.6 ; extra == 'uf3'
31
+ Requires-Python: >=3.12
32
+ Project-URL: Homepage, https://github.com/LiuGaoyong/ArrayFF
33
+ Project-URL: Repository, https://github.com/LiuGaoyong/ArrayFF
34
+ Project-URL: Issues, https://github.com/LiuGaoyong/ArrayFF/issues/
35
+ Provides-Extra: autograd
36
+ Provides-Extra: autoray
37
+ Provides-Extra: builders
38
+ Provides-Extra: jax
39
+ Provides-Extra: reaxff
40
+ Provides-Extra: sklearn
41
+ Provides-Extra: torch
42
+ Provides-Extra: uf3
43
+ Description-Content-Type: text/markdown
44
+
45
+ # ArrayFF
46
+
47
+ ![Conda Version](https://img.shields.io/conda/vn/conda-forge/arrayff.svg)
48
+ ![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/arrayff.svg)
49
+ ![Pypi version](https://img.shields.io/pypi/v/arrayff)
50
+ ![PyPI Downloads](https://static.pepy.tech/badge/arrayff)
51
+
52
+ The Force Field Library Based on Multiple Array Backends like NumPy, PyTorch
53
+ and JAX.
54
+
55
+ Kernels are written once against a small dispatch layer, so the backend is
56
+ chosen by the arrays you pass in: NumPy (and autograd) run on a built-in
57
+ dispatcher, PyTorch and JAX go through
58
+ [`autoray`](https://github.com/jcmgray/autoray). Structural I/O uses
59
+ `ase.Atoms` throughout.
60
+
61
+ The only required array backend is NumPy. Automatic differentiation of NumPy
62
+ arrays uses [`autograd`](https://github.com/HIPS/autograd); autograd, autoray,
63
+ PyTorch and JAX are optional extras.
64
+
65
+ ## Install
66
+
67
+ ```bash
68
+ uv pip install -e .
69
+ uv pip install -e ".[autograd]" # NumPy autodiff (method="autodiff")
70
+ uv pip install -e ".[torch]" # PyTorch backend + nn wrappers (with autoray)
71
+ uv pip install -e ".[jax]" # JAX backend (with autoray)
72
+ uv pip install -e ".[sklearn]" # scikit-learn neighbour builder
73
+ uv pip install -e ".[builders]" # sklearn / vesin / matscipy / pymatgen neighbours
74
+ uv pip install -e ".[uf3]" # NumPy autodiff for UF3
75
+ uv pip install -e ".[reaxff]" # NumPy autodiff for ReaxFF (optional)
76
+ ```
77
+
78
+ The hard dependencies are NumPy, SciPy (>= 1.6) and ASE. Without autograd
79
+ every NumPy feature works except `method="autodiff"`. Torch/JAX arrays and
80
+ `jit=True`
81
+ on those backends need autoray (pulled in by the `torch`/`jax` extras). A
82
+ missing optional dependency raises `MissingBackendError` with the install
83
+ command.
84
+
85
+ ## Quick start
86
+
87
+ ```python
88
+ from ase.build import bulk
89
+ from arrayff import ArrayFFCalculator, build_potential
90
+
91
+ atoms = bulk("Cu", "fcc", a=3.6, cubic=True).repeat((2, 2, 2))
92
+
93
+ calc = build_potential("emt") # numpy backend; "auto" uses analytic forces
94
+ energy, forces = calc.energy_and_forces(atoms)
95
+ energies = calc.energies(atoms) # per atom; they sum to `energy`
96
+
97
+ atoms.calc = ArrayFFCalculator("emt") # same model, ASE calculator
98
+ energy = atoms.get_potential_energy()
99
+ per_atom = atoms.calc.get_property("energies", atoms)
100
+ ```
101
+
102
+ `build_potential` and `ArrayFFCalculator` take a name or a sum of names
103
+ (`lj`, `lj93`, `morse`, `emt`, `eam`, `meam`, `uf2`, `uf3`, `reaxff`, `qeq`,
104
+ `eem`, `pqeq`). Options shared by every component (`backend`, `dtype`,
105
+ `device`, `jit`, `method`, `builder`, `skin`, `max_neighbors`) are passed
106
+ directly; options of one component go in a dict named after it:
107
+
108
+ ```python
109
+ atoms.calc = ArrayFFCalculator(
110
+ "lj+qeq",
111
+ lj={"sigma": 3.405, "epsilon": 0.01032, "cutoff": 8.0},
112
+ qeq={"chi": {8: 8.5, 1: 4.5}, "J": {8: 10.0, 1: 12.0}},
113
+ backend="torch",
114
+ )
115
+ ```
116
+
117
+ Several structures can be evaluated in one call.
118
+ `EMT().evaluate_batch([atoms_a, atoms_b], properties=("energy", "forces", "stress"))` returns `energy` with shape `(B,)`, `forces` with shape `(N, 3)`
119
+ and `stress` with shape `(B, 3, 3)`; only `energy` is returned by default.
120
+
121
+ Backends are selected at construction:
122
+
123
+ ```python
124
+ from arrayff.models import EMT
125
+
126
+ calc = EMT(backend="torch") # or "jax"
127
+ calc = EMT(backend="jax", jit=True)
128
+ calc = EMT(backend="torch", dtype=torch.float32, device="cuda")
129
+ ```
130
+
131
+ Each potential exposes analytic and autodiff forces/stress:
132
+
133
+ ```python
134
+ from arrayff.models import LennardJones
135
+
136
+ calc = LennardJones(cutoff=8.0, sigma=3.405, epsilon=0.01032)
137
+ calc.energy_and_forces(atoms) # method="auto": analytic when the model has it
138
+ calc.energy_and_forces(atoms, method="autodiff")
139
+ calc.stress(atoms, method="analytic")
140
+ ```
141
+
142
+ `LennardJones()` without arguments uses the OpenKIM universal shifted
143
+ parameters (118 elements, cutoff `4*sigma` per pair, Lorentz-Berthelot
144
+ mixing: arithmetic `r0`/cutoff and geometric `epsilon`). The neighbour
145
+ table only reaches the largest cutoff of the elements actually present.
146
+
147
+ `jit=True` compiles the array-level kernel with `autoray.autojit` (JAX and
148
+ PyTorch only; NumPy runs eagerly). See
149
+ [Backend and derivative support](#backend-and-derivative-support).
150
+
151
+ ### Neighbour tables
152
+
153
+ Tables are built with `scipy.spatial.KDTree` (`builder="scipy"`, default).
154
+ `sklearn` (scikit-learn `NearestNeighbors`, optional extra), `vesin`,
155
+ `matscipy`, `pymatgen` and `ase_kdtree` are alternatives. They are built
156
+ with `cutoff + skin` and reused until an atom has moved more than `skin / 2`,
157
+ measured with the minimum-image convention: wrapping atoms back into the cell
158
+ does not trigger a rebuild, the cached image shifts are corrected in place.
159
+ The default `skin=0.5` Angstrom suits MD, relaxations and Monte Carlo;
160
+ `skin=0.0` rebuilds whenever the positions change.
161
+
162
+ In an additive composite the short-ranged components share one table built
163
+ at the largest cutoff; each component sees the pairs inside its own cutoff.
164
+ Charge models and ReaxFF keep their own tables.
165
+
166
+ ## Models
167
+
168
+ ### Short-ranged potentials
169
+
170
+ - **Lennard-Jones, LJ 9-3, Morse**: generic pairwise layer, optional energy
171
+ shift and smooth switch.
172
+ - **EMT**: matches `ase.calculators.emt` (including `asap_cutoff`).
173
+ - **EAM**: setfl tables with the not-a-knot cubic spline of
174
+ `ase.calculators.eam` (continuous forces).
175
+ - **MEAM**: LAMMPS `library.meam` plus an optional `.meam` parameter file.
176
+ Partial densities `rho^(0..3)`, `G(Gamma)` (`ibar` 0/1/3/4/-5), `augt1`,
177
+ the pair potential of the fcc/bcc reference crystal and elliptical
178
+ many-body screening (`Cmin`/`Cmax`). Forces and stress are closed form
179
+ (chain rule through `rho_l`, the pair potential and the screening
180
+ triplets) and agree with `method="autodiff"` to 1e-14. On a 256-atom Cu
181
+ cell energy+forces cost 1.4-1.5x the energy alone (2.3x with autodiff).
182
+ ```python
183
+ from arrayff.models import MEAM
184
+
185
+ meam = MEAM("library.meam", "Cu.meam", elements=("Cu",))
186
+ ```
187
+ - **UF2 / UF3**: uniform-knot cubic B-splines, LAMMPS `.uf3` files and a
188
+ JSON form; two-body (`UF2`) or two- plus three-body (`UF3`) terms.
189
+ - **ReaxFF**: LAMMPS `ffield`; bond orders with corrections, bond,
190
+ lone-pair, over/under-coordination, valence-angle, penalty, coalition,
191
+ torsion, conjugation, hydrogen-bond, van der Waals and Coulomb terms.
192
+ Charges from the built-in QEq/EEM solve (`charges="qeq"` / `"eem"`) or
193
+ from an external charge model (`charges="none"`, e.g. `"reaxff+qeq"`).
194
+ Forces and stress are closed form (every term's derivative by the bond
195
+ orders, `Delta` and the geometry, carried back through the bond order
196
+ corrections as in LAMMPS), at fixed charges; they agree with
197
+ `method="autodiff"` to 1e-12 and with LAMMPS to 1e-9. On ethanol energy+
198
+ forces take 1.8 ms on NumPy (2.0x the energy alone; autodiff 7 ms).
199
+
200
+ All of them provide per-atom energies except ReaxFF.
201
+
202
+ ### Charge models
203
+
204
+ ```python
205
+ from arrayff.models.electrostatics import EEM, PQEq, QEq
206
+
207
+ qeq = QEq(chi={8: 8.5, 1: 4.5}, J={8: 10.0, 1: 12.0}, shielding=1.0)
208
+ charges = qeq.charges(atoms) # sum == total charge
209
+
210
+ # additive composite: energy/forces/stress add, charges come from QEq
211
+ composite = LennardJones(cutoff=8.0, sigma=3.405, epsilon=0.01032) + qeq
212
+ energy, forces = composite.energy_and_forces(atoms)
213
+ ```
214
+
215
+ A charge model is assembled from a charge model (`QEqCharges`,
216
+ `EEMCharges`), a Coulomb kernel and a solver:
217
+
218
+ - **QEq** (Rappe-Goddard, `chi q + 1/2 J q^2`) and **EEM** (Mortier,
219
+ `chi q + eta q^2`).
220
+ - Kernels: `"shielded"` (default, `1/sqrt(r^2 + lambda^2)`), `"gaussian"`
221
+ (`erf(r/lambda)/r`), `"point"`, `ReaxFFShieldedKernel` (with the ReaxFF
222
+ taper) and `PairGaussianKernel` (per-element Gaussian widths).
223
+ - Solvers: direct sums for clusters and tapered kernels, Ewald sums for fully
224
+ periodic cells (`ewald_accuracy`, `ewald_cutoff`). With Gaussian kernels
225
+ the Ewald sum is exact to `ewald_accuracy`; the shielded kernel's `r^-3`
226
+ remainder is truncated at `shielded_cutoff`, which is approximate (an
227
+ `AccuracyWarning` is emitted), so prefer `kernel="gaussian"` for periodic
228
+ systems. Mixed boundary conditions are not supported.
229
+ - Charge solve: `solver_method="dense"` (default) factorises the bordered
230
+ system; `"cg"` runs two Jacobi-preconditioned conjugate-gradient solves
231
+ warm-started from the previous geometry. Monte Carlo switches charge
232
+ models to `"cg"`.
233
+ - `charge_response="frozen"` (Hellmann-Feynman, default) or `"relaxed"`
234
+ (differentiate through the charge solve); both give the same forces.
235
+
236
+ **PQEq** (Naserifar et al. 2017; Kwon et al. 2018) adds a Gaussian shell
237
+ of charge `-Z` bound to each core by `1/2 K_s |r_s - r_c|^2`. Charges and
238
+ shell displacements are minimised together (charge solve, then a damped
239
+ per-atom Newton step on the shells with a line search); forces use the
240
+ envelope theorem at that minimum, and periodic cells go through the same
241
+ Ewald solver as the core-shell energy. The stress is the closed-form virial
242
+ at the relaxed charges and shells (real-space and reciprocal Ewald parts,
243
+ own core-shell pair, spring). A uniform external `field` is supported for
244
+ clusters. The 2N-site pair table keeps a Verlet skin (`site_skin`, default
245
+ 0.5 A), so one relaxation builds it once; pairs beyond the cutoff are
246
+ dropped, so the energy does not depend on the skin.
247
+
248
+ ```python
249
+ pqeq = PQEq(chi={1: 4.5, 8: 8.5}, J={1: 12.0, 8: 10.0},
250
+ radius={1: 0.35, 8: 0.30}, spring={1: 300.0, 8: 400.0},
251
+ charge={1: 1.0, 8: 6.0})
252
+ result = pqeq.evaluate(atoms, properties=("energy", "forces", "charges",
253
+ "shell_displacements"))
254
+ ```
255
+
256
+ The built-in table `PQEQ_PARAMETERS` (H, C, N, O, Cu) is used when
257
+ parameters are omitted; its values have not been checked entry by entry
258
+ against the published tables, so pass explicit parameters for production
259
+ work.
260
+
261
+ PQEq runs on NumPy, PyTorch and JAX (`backend=`). The charge and shell
262
+ relaxation always runs in NumPy (L-BFGS on the shells, preconditioned by
263
+ the per-atom spring and self-curvature, charges solved exactly at each
264
+ step); the energy is then rebuilt on the backend
265
+ with the charges and shells held fixed, so `method="autodiff"` forces and
266
+ stress are exact (envelope theorem) and agree with the analytic ones to
267
+ 1e-9 on clusters and periodic cells. One relaxation sets up the Ewald
268
+ lattice and the core-core block of the Coulomb matrix once and updates
269
+ only the shell columns at each line-search point; the set-up is kept
270
+ while the cell and the parameters are unchanged. On a 16-atom periodic
271
+ cell the relaxation takes about 17 ms and energy, forces and stress
272
+ together about 22-28 ms on NumPy (see Performance).
273
+
274
+ ## Monte Carlo
275
+
276
+ `arrayff.mc` samplers are `ase.optimize.optimize.Dynamics` objects: one
277
+ `step()` is one move, and `run`, `irun`, `attach(fn, interval)`,
278
+ `trajectory=` and `logfile=` work as in `ase.md`. `run()` returns an
279
+ `MCRunResult` with the sampled energies, volumes, atom counts and acceptance
280
+ ratios.
281
+
282
+ ```python
283
+ from arrayff.mc import NPT, NVE, NVT, ForceBiasMove, GrandCanonical, TimeStampedMove
284
+
285
+ mc = NVT(atoms, "emt", temperature=300.0, max_step=0.05, rng=0,
286
+ trajectory="mc.traj")
287
+ result = mc.run(5000, n_equil=1000)
288
+ result.mean_energy, result.acceptance
289
+
290
+ NPT(atoms, "emt", 300.0, pressure=0.0) # displacement + volume moves
291
+ NVE(atoms, "emt", demon_energy=0.1) # Creutz demon
292
+ GrandCanonical(atoms, "emt", 300.0, chemical_potential=-3.0, elements=[29])
293
+
294
+ # force-bias MC (uniform acceptance or Metropolis) and time-stamped MC
295
+ NVT(atoms, "emt", 300.0, moves=[ForceBiasMove(0.05)])
296
+ tf = NVT(atoms, "emt", 300.0, moves=[TimeStampedMove(0.05)]).run(1000)
297
+ tf.time # simulated time of each sample
298
+ ```
299
+
300
+ - Moves: `DisplacementMove`, `SwapMove`, `VolumeMove`, `InsertDeleteMove`,
301
+ `ForceBiasMove` and `TimeStampedMove`; several moves are picked by
302
+ `weight`.
303
+ - `ForceBiasMove(delta, lambda_=0.5)` draws every Cartesian component from
304
+ `exp(gamma xi)` with `gamma = lambda beta F delta` (Neyts and Bogaerts
305
+ 2013). Uniform acceptance satisfies detailed balance only for small
306
+ `delta`; `acceptance="metropolis"` adds the forward/reverse proposal ratio.
307
+ Each step costs one energy+forces evaluation; the forces of an accepted
308
+ trial are reused for the next proposal.
309
+ - `TimeStampedMove(delta)` (tfMC, Mees et al. 2012) scales the step by
310
+ `(m_min / m)^(1/4)` and accumulates the mean timestep
311
+ `delta / 3 * sqrt(pi m_min / (2 kT))`.
312
+ - For one-atom displacements and swaps on potentials with per-atom energies,
313
+ `LocalEnergy` recomputes only the atoms whose energy changes, on the cached
314
+ neighbour table. It falls back to a full evaluation when the neighbourhood
315
+ covers more than half of the system.
316
+ - Observers see the current state through `atoms.calc`: the energy always,
317
+ the forces only when they are known (force-bias moves).
318
+
319
+ ## Training (optional)
320
+
321
+ `TorchModel` turns any spec into one `nn.Module`. Components with a
322
+ trainable torch module (`LJTorch`, `QEqTorch`, `UF3Torch`, `ReaxFFTorch`,
323
+ ...) are trained; the others (and those listed in `frozen=`) run as plain
324
+ potentials on the torch backend.
325
+
326
+ ```python
327
+ from arrayff import TorchModel
328
+
329
+ model = TorchModel(
330
+ "lj+qeq",
331
+ species=[8, 1],
332
+ qeq={"chi": {8: 8.5, 1: 4.5}, "J": {8: 10.0, 1: 12.0}},
333
+ )
334
+ out = model([atoms_a, atoms_b]) # energy (B,), forces (N, 3)
335
+ loss = ((out["energy"] - e_ref) ** 2).sum() + ((out["forces"] - f_ref) ** 2).sum()
336
+ loss.backward()
337
+
338
+ atoms.calc = model.to_calculator() # trained parameters back into ASE
339
+ ```
340
+
341
+ Forces are summed per component: components with closed-form forces add
342
+ them directly (they stay differentiable in the parameters, so force matching
343
+ trains them); components without them are differentiated with
344
+ respect to one positions leaf shared by the batch, together with one strain
345
+ leaf per structure when stress is requested, in a single backward pass.
346
+ All modules follow `module.to(device, dtype)`.
347
+
348
+ Notes on the trainable modules:
349
+
350
+ - `PQEqTorch` trains `chi`, `J`, `K_s` and the Gaussian `radius`. The
351
+ energy gradient with respect to them is exact (envelope theorem). With
352
+ `implicit=True` (default) the forces and stress are also differentiable
353
+ through the relaxed charges and shells: the sensitivity
354
+ `d(q, u)/d(theta)` is solved from the bordered Hessian system (total
355
+ charge fixed), which matches central differences that re-relax at every
356
+ step. `implicit_solver="auto"` (default) builds the dense `4N x 4N`
357
+ Hessian while `4N <= implicit_dense_max_size` (default 128, the measured
358
+ crossover on CPU float64) and above that solves with MINRES on
359
+ Hessian-vector products, one column per parameter (the projected Hessian
360
+ is indefinite, so CG does not apply); `"dense"` or `"minres"` forces one
361
+ of them. With `implicit=False` the force gradients with
362
+ respect to these parameters are zero (forces do not depend on them at
363
+ fixed `q`, `u`); `arrayff train` warns in that case when the force
364
+ weight is positive.
365
+ - `MEAMTorch(library, meam, elements, trainable=...)` trains, per element,
366
+ `alpha`, `beta` (4), `t1..t3`, `esub`, `asub`, `re` and `rozero`, and the
367
+ screening bounds `Cmin`/`Cmax`; `ibar`, `Z` and the reference lattice stay
368
+ fixed. The reference density is recomputed from the parameters. Energy
369
+ and force gradients with respect to them match finite differences.
370
+ `as_parameters()` returns the library elements and the parameter file.
371
+ - `ReaxFFTorch(ffield, species, trainable=...)` trains the entries of the
372
+ `ffield` file itself (sections `general`, `atom`, `bond`, `offdiag`,
373
+ `angle`, `torsion`, `hbond`); the expanded tables are rebuilt from them
374
+ in torch on every call, including the taper radii `swa`/`swb` and the
375
+ bond-order cutoff. Bond radii and the neighbour cutoff follow the current
376
+ parameters: the cached bond topology and neighbour table are rebuilt when
377
+ a radius moves past the reach they were built with (`skin`). Gradients
378
+ with respect to `swa`/`swb` include the charge response only with
379
+ `charge_response="relaxed"`. `as_parameters()` returns a
380
+ `ReaxFFParameters`.
381
+ - `EMTTorch(species, parameters=None)` trains the seven EMT parameters per
382
+ element (`E0`, `s0`, `V0`, `eta2`, `kappa`, `lambda`, `n0`; log
383
+ parametrised, `E0 < 0`); the cutoff stays at the initial table.
384
+ `as_parameters()` and `as_potential()` return the trained table and an
385
+ `EMT(parameters=...)`.
386
+ - `TorchModel(..., compile=True)` (or a dict of `torch.compile` options)
387
+ compiles the `analytic` and `total_energy` kernels with `torch.compile`
388
+ (`dynamic=True`). It falls back to eager with one `TorchCompileWarning`
389
+ when compilation fails. The first call of each kernel runs eagerly and
390
+ the second compiles it: 4 s for LJ, 20-50 s for MEAM and ReaxFF on CPU.
391
+ Each kernel then traces as one graph without graph breaks (checked for
392
+ LJ and EMT in `src/tests/test_compile.py`; measured also for EAM, MEAM
393
+ and ReaxFF). Measured on CPU (float64): forward
394
+ 2.5-3.2x and a training step 2.2-2.8x faster than eager for LJ (108
395
+ atoms), ReaxFF (9 and 243 atoms) and MEAM (256 atoms); with those
396
+ compile times it pays off after roughly 1300 (MEAM) to 5000 (LJ) calls.
397
+ Changing the number of atoms does not recompile, except that ReaxFF
398
+ recompiles once when a structure first has hydrogen bonds. GPUs were
399
+ not measured.
400
+
401
+ `arrayff.io.export.export(model, path)` writes the parameters of a trained
402
+ module or `TorchModel`. `path` is a file, a directory (existing, ending in
403
+ `/` or without a suffix; one `<component><suffix>` file per trainable
404
+ component, `.ffield` for ReaxFF, `.library` for MEAM, `.uf3` for UF2/UF3,
405
+ `.json` otherwise) or a `{component: file}` dict. A single file needs
406
+ exactly one trainable component. It returns the written paths;
407
+ `export_targets(model, path)` checks the plan without writing. The format
408
+ follows the suffix:
409
+
410
+ | Suffix | Content |
411
+ | --- | --- |
412
+ | `.ffield` / `.reax` | ReaxFF force field |
413
+ | `.meam` / `.library` | MEAM library, plus `<stem>.params.meam` |
414
+ | `.uf3` | UF2/UF3 LAMMPS table |
415
+ | `.json` | UF2/UF3 coefficients, or per element LJ, Morse, LJ 9-3, QEq (`chi`, `J`), EEM (`chi`, `eta`), PQEq (`chi`, `J`, `K_s`, `radius`, `Z`) and EMT parameters (read back with `EMT(**read_emt_json(path))`) |
416
+
417
+ Every format is read back in the tests and reproduces the trained energy;
418
+ the exported MEAM files are also run through LAMMPS `pair_style meam`.
419
+
420
+ ### Training CLI
421
+
422
+ `arrayff train` fits a `TorchModel` to reference structures read with
423
+ `ase.io.read` (energies, forces and stresses from `atoms.info`,
424
+ `atoms.arrays` or an attached single-point calculator, as ASE writes
425
+ extxyz). It needs the `torch` extra.
426
+
427
+ ```bash
428
+ arrayff train config.toml --set train.epochs=200 --set train.lr=1e-3
429
+ arrayff train --spec lj --data train.extxyz --epochs 50
430
+ arrayff eval run/best.pt --data test.extxyz
431
+ arrayff export run/best.pt --out trained.json
432
+ arrayff export run/best.pt --out lj=lj.json --out qeq=qeq.json
433
+ arrayff train --spec emt --data train.extxyz --export run/params/
434
+ ```
435
+
436
+ ```toml
437
+ [model]
438
+ spec = "reaxff"
439
+ species = [1, 8]
440
+ [model.reaxff] # options of the component
441
+ ffield = "ffield.reax.cho"
442
+ charges = "none"
443
+ trainable = ["atom", "bond"]
444
+
445
+ [data]
446
+ train = "train.extxyz"
447
+ valid = "valid.extxyz" # or valid_fraction = 0.1
448
+ energy_key = "energy"
449
+ forces_key = "forces"
450
+
451
+ [loss]
452
+ energy = 1.0 # on the energy per atom
453
+ forces = 10.0
454
+ stress = 0.0
455
+
456
+ [train]
457
+ optimizer = "adam" # adam | lbfgs
458
+ lr = 3e-5
459
+ epochs = 100
460
+ batch_size = 8
461
+ patience = 20 # early stop after this many epochs
462
+ seed = 0
463
+ device = "cpu"
464
+
465
+ [output]
466
+ dir = "run/"
467
+ export = "trained.ffield" # written from best.pt, inside dir
468
+ # export = {reaxff = "a.ffield", qeq = "b.json"} # several components
469
+ ```
470
+
471
+ With two trainable components and a single export file, `arrayff train`
472
+ stops before the first epoch.
473
+
474
+ - Precedence: defaults, the TOML file, the flags (`--spec`, `--data`,
475
+ `--epochs`, `--lr`, ...), then `--set section.key=value`, which takes
476
+ TOML values (`--set model.species=[1,8]`). No config file is needed.
477
+ - The loss is the weighted mean squared error of the per-atom energy, the
478
+ force components and the stress components. Every epoch prints and
479
+ appends to `log.csv` the MAE and RMSE of each quantity on the validation
480
+ set (or, without one, on the training set).
481
+ - `best.pt` (lowest validation loss) and `last.pt` hold the config, the
482
+ `state_dict`, the optimizer state, the shuffle state and the
483
+ early-stopping counters; `--resume run/last.pt` continues, and a resumed
484
+ run reproduces the uninterrupted one (tested with several batches per
485
+ epoch).
486
+ - Neighbour tables (and the ReaxFF topology) of the training and
487
+ validation structures are built once and reused while their geometry is
488
+ unchanged (`TorchModel.cache_structures`).
489
+ - `eval` prints the metrics (`--json` also writes them); `export` writes a
490
+ checkpoint in any of the formats above.
491
+
492
+ Checked in `src/tests/test_cli.py` with LJ (Adam, resume, export),
493
+ Morse (L-BFGS, config file, eval, export) and, under `-m slow`, a ReaxFF
494
+ water fit exported to `ffield`.
495
+
496
+ UF2/UF3 coefficients can also be fitted in closed form:
497
+
498
+ ```python
499
+ from arrayff.models.uf import UF3
500
+ from arrayff.models.uf.fit import ridge_fit, template
501
+
502
+ start = UF3(template(["Nb"], 0.001, 8.0, 24, r_cut_3b=4.0, n_intervals_3b=8))
503
+ model = ridge_fit(start, structures, energies, forces, stresses, alpha=1e-8)
504
+ ```
505
+
506
+ ## Status
507
+
508
+ | Model | Validated against | Notes |
509
+ |---|---|---|
510
+ | Lennard-Jones (OpenKIM universal shifted or explicit), LJ 9-3, Morse | closed form, autodiff | per-atom energies |
511
+ | EMT | `ase.calculators.emt` | per-atom energies |
512
+ | EAM | `ase.calculators.eam` | per-atom energies |
513
+ | MEAM | LAMMPS `pair_style meam` (Cu, Ni; ideal, displaced and rattled cells up to 256 atoms: energy, forces, per-atom energies) | fcc/bcc reference structures only; the second-nearest-neighbour (`nn2`) formulation and other reference lattices are not implemented |
514
+ | UF2 / UF3 | LAMMPS `pair_style uf3` (Nb, NbMo; orthorhombic and triclinic cells: energy, forces, stress) | ridge fitting |
515
+ | ReaxFF | LAMMPS `pair_style reaxff` + `fix qeq/reaxff`, term by term (C/H/O) | no per-atom energies |
516
+ | QEq / EEM | closed-form solve, finite differences, Madelung energy | dense or CG solve |
517
+ | PQEq | finite differences; Gaussian-QEq limit for `K_s -> inf`; induced dipole `alpha E` | built-in parameter table not checked against the papers |
518
+ | Monte Carlo | equipartition, ideal-gas `<V>` and `<N>`, NVE energy conservation, LAMMPS `fix tfmc` (Cu EAM) | |
519
+ | Additive composites (`"lj+qeq"`, `"reaxff+qeq"`, ...) | sum of components | |
520
+
521
+ ## Backend and derivative support
522
+
523
+ Every model runs on the three backends unless noted, and provides energy,
524
+ forces and (for fully periodic cells) stress. Each combination below was
525
+ checked against the NumPy result.
526
+
527
+ | Model | NumPy | PyTorch | JAX | Analytic forces/stress | Autodiff forces/stress | Trainable torch module |
528
+ |---|---|---|---|---|---|---|
529
+ | `LennardJones` (KIM or explicit sigma/epsilon) | yes | yes | yes | yes | yes | `LJTorch` |
530
+ | `LJ93` | yes | yes | yes | yes | yes | `LJ93Torch` |
531
+ | `Morse` | yes | yes | yes | yes | yes | `MorseTorch` |
532
+ | `EMT` | yes | yes | yes | yes | yes | `EMTTorch` |
533
+ | `EAM` | yes | yes | yes | yes | yes | `EAMTorch` |
534
+ | `MEAM` | yes | yes | yes | yes | yes | `MEAMTorch` |
535
+ | `QEq` / `EEM` (cluster / periodic) | yes | yes | yes | yes, envelope theorem | yes, frozen or relaxed charges | `QEqTorch` / `EEMTorch` |
536
+ | `PQEq` | yes | yes | yes | yes, envelope theorem | yes, fixed relaxed charges and shells | `PQEqTorch` |
537
+ | `UF2` / `UF3` | yes | yes | yes | yes | yes | `UF2Torch` / `UF3Torch` |
538
+ | `ReaxFF` | yes | yes | yes | yes, frozen or relaxed charges | yes | `ReaxFFTorch` |
539
+ | `CompositePotential` | yes | yes | yes | sum of components | sum of components | - |
540
+
541
+ - `method="auto"` (default) uses closed-form derivatives when the model
542
+ provides them, and automatic differentiation otherwise. `method="analytic"`
543
+ is the closed-form path and raises `ScopeError` when the model has none.
544
+ For QEq, the analytic forces and stress equal the relaxed-charge result to
545
+ solver accuracy, because the charge-response term vanishes at the minimum.
546
+ ReaxFF is different: its charges minimise the EEM energy with
547
+ `ke = 14.4` while the ReaxFF Coulomb and polarisation energies use
548
+ `332.06371 kcal/mol` and `23.02` (as in LAMMPS), so the response term
549
+ does not vanish (about 5e-3 eV/A on ethanol). `charge_response="frozen"`
550
+ (default) drops it, like LAMMPS `fix qeq/reaxff`;
551
+ `charge_response="relaxed"` adds it through one adjoint solve, and the
552
+ forces and stress then match finite differences of the energy.
553
+ - `method="autodiff"` uses autograd for NumPy (optional extra
554
+ `arrayff[autograd]`), `torch.func` for PyTorch and `jax.grad` for JAX.
555
+ Stress is the derivative with respect to a homogeneous strain; when
556
+ forces and stress are both requested one reverse pass over positions and
557
+ strain gives both (also under `jit`).
558
+ - `method="finite-difference"` is a diagnostic: forces stay analytic and only
559
+ the stress is obtained by central differences.
560
+ - `float32` and accelerators (`dtype=`, `device=`) are supported on PyTorch;
561
+ CPU and Apple MPS are tested.
562
+
563
+ `jit=True` compiles the following paths; everything else runs eagerly and
564
+ gives the same numbers:
565
+
566
+ | Backend | Analytic | Autodiff energy+forces | Autodiff stress |
567
+ |---|---|---|---|
568
+ | NumPy | eager (`jit` is ignored silently) | eager | eager |
569
+ | PyTorch | compiled (`torch.jit.trace`) | compiled energy kernel, then `torch.autograd` | compiled with forces (one pass), eager alone |
570
+ | JAX | compiled (`jax.jit`) | compiled `value_and_grad` | compiled with forces (one pass), eager alone |
571
+
572
+ For QEq, `jit` applies to the analytic path only.
573
+
574
+ Compiled kernels are keyed on the array shapes. For pair-type models
575
+ (`pads_pairs = True`: LJ, Morse, LJ 9-3, EAM, EMT, UF2/UF3 without
576
+ three-body terms) the pair table handed to a compiled kernel is padded to
577
+ a bucketed length with masked entries, so a Verlet rebuild usually reuses
578
+ the compiled kernel. `src/tests/test_jit_shapes.py` checks this for LJ
579
+ (32 atoms, 25 rattled steps on JAX); in 200 MD steps of 108-atom LJ and
580
+ EAM on JAX one compiled kernel was kept instead of one per rebuild. MEAM, ReaxFF and three-body UF3 still
581
+ recompile when the number of pairs or triplets changes.
582
+
583
+ ## Performance
584
+
585
+ Timings measured once, not checked by the tests (float64, warm caches,
586
+ Apple M-series CPU, best of 7 to 15). The machine was heavily loaded while
587
+ they were taken, so expect 10-30 % scatter:
588
+
589
+ | System | Path | Time |
590
+ |---|---|---|
591
+ | ReaxFF ethanol, 9 atoms, NumPy | energy + forces, analytic | 1.3 ms (1.8x energy) |
592
+ | ReaxFF ethanol, 243 atoms, NumPy | energy + forces, analytic | 17 ms (1.3x energy) |
593
+ | ReaxFF ethanol, 9 atoms, PyTorch | energy + forces, analytic | 2.9 ms |
594
+ | ReaxFF ethanol, 243 atoms, PyTorch | energy + forces, analytic | 20 ms |
595
+ | ReaxFF ethanol, 243 atoms, NumPy | energy + forces, `method="autodiff"` | 33 ms |
596
+ | ReaxFF ethanol, 9 atoms, PyTorch `jit=True` | energy + forces + stress, autodiff | 2.6 ms |
597
+ | MEAM Cu, 256 atoms, NumPy | energy + forces, analytic | 26 ms |
598
+ | MEAM Cu, 256 atoms, PyTorch | energy + forces, analytic | 16 ms |
599
+ | PQEq 16-atom periodic cell, NumPy | relaxation alone | 17 ms |
600
+ | PQEq 16-atom periodic cell, NumPy | energy + forces + stress | 22-28 ms |
601
+
602
+ Where the time goes:
603
+
604
+ - `do` calls with plain NumPy arrays skip autoray and go to a cached NumPy
605
+ function. Under autograd, the backward of an integer gather uses
606
+ `bincount` instead of `np.add.at` (registered once per process).
607
+ - ReaxFF on NumPy evaluates the torsion derivatives only on the dihedrals
608
+ that pass the bond-order cut (about 12 % of them in ethanol); the other
609
+ backends keep the dense, shape-stable path.
610
+ - MEAM drops, when the neighbour table is built, the triplets whose
611
+ screening factor cannot differ from 1 or whose bond is beyond `rc` for
612
+ any displacement within the Verlet skin (256-atom Cu: 220k to 98k
613
+ triplets). Building the table costs about 10 ms more, which pays back
614
+ within one evaluation from 8 to 256 atoms. The triplets are built only
615
+ when a full evaluation needs them: local Monte Carlo moves read the
616
+ pairs and build the triplets of the moved cluster alone, without the
617
+ skin margin. While `MEAMTorch` trains `Cmin`/`Cmax` only the `rc` test
618
+ applies.
619
+ - PQEq keeps the 2N-site pair table and the shell rows of one relaxation
620
+ while the neighbour table is unchanged.
621
+
622
+ Local Monte Carlo on a 2048-atom cell (one step, NumPy): MEAM 4.0 ms
623
+ (9.7 ms before the cluster changes), EAM 10.4 ms (13.4 ms), EMT 5.4 ms
624
+ (6.0 ms). Below about 500 atoms the moved cluster covers more than half
625
+ of the cell and a step evaluates the whole cell instead.
626
+
627
+ For molecular dynamics, prefer the PyTorch backend with `jit=True`, or
628
+ JAX with `jit=True` for pair-type models.
629
+
630
+ ## Limitations
631
+
632
+ - **ReaxFF**: the triple-bond switch (an integer), masses, hydrogen-bond
633
+ types and which interactions exist stay as in the initial force field
634
+ during training. Each term computes its energy and its closed-form
635
+ derivative side by side; `test_analytic_terms_match_autodiff` catches a
636
+ change made to only one of them.
637
+ - **MEAM**: `ibar=3` and `ibar=-5` are checked against autodiff only, not
638
+ LAMMPS.
639
+ - **PQEq**: `relax(tol=1e-12)` is limited by float64; on some structures the
640
+ shell gradient stalls between 1e-12 and 5e-12. Some clusters in an
641
+ external field do not converge with the default parameters. The dense
642
+ versus MINRES threshold of the implicit sensitivity depends on the
643
+ hardware.
644
+ - **JAX without `jit`**: every operation is dispatched and compiled on its
645
+ own, which made LJ, ReaxFF and MEAM 3-30x slower than NumPy in our
646
+ measurements. Use `jit=True` with `backend="jax"`.
647
+ - **EMT**: the cutoff is set by the largest `s0` of the table, so a custom
648
+ table with fewer elements has a smaller cutoff than ASE's full table.
649
+ - `TorchModel(compile=True)`: the compile time (tens of seconds) only
650
+ pays off over long runs; frames that hit Dynamo's recompile limit would
651
+ fall back to eager silently, without `TorchCompileWarning`. GPUs were
652
+ not measured.
653
+
654
+ ## Tests and benchmarks
655
+
656
+ ```bash
657
+ pytest -q # everything
658
+ pytest -q -m "not slow" # skip JAX compilation and LAMMPS runs
659
+ pytest -q -m slow
660
+ pytest -s src/tests-benchmark/bench_potentials.py
661
+ pytest -s src/tests-benchmark/bench_derivatives.py
662
+ ```
663
+
664
+ The `slow` marker (set in `src/tests/conftest.py`) covers every `[jax]`
665
+ parametrisation and the tests that call `lmp_serial`. CI runs the fast set on
666
+ Python 3.12 and 3.13, the slow set separately, a minimal job with only the
667
+ hard dependencies, `ruff` and `pyright`.
668
+
669
+ Reference data:
670
+
671
+ - UF3 and ReaxFF compare against `reference.npz` files in
672
+ `src/tests/data/uf3/` and `src/tests/data/reaxff/`, produced by the
673
+ `generate_lammps.py` scripts next to them. Running the tests needs neither
674
+ LAMMPS nor the `uf3` package.
675
+ - The MEAM and tfMC tests call `lmp_serial` directly and skip when it, or the
676
+ LAMMPS potential files under `/opt/homebrew/share/lammps/potentials`, are
677
+ missing. `src/tests/data/meam/generate_lammps.py` can write a reference
678
+ archive.
679
+
680
+ ## Layout
681
+
682
+ | Package | Contents |
683
+ |---|---|
684
+ | `arrayff.core` | dispatch, autodiff, jit, `System` (one structure or a batch), B-splines, switching functions |
685
+ | `arrayff.neighbors` | neighbour lists, triplets/quadruplets, Verlet cache |
686
+ | `arrayff.models` | potentials, charge models, registry, composites |
687
+ | `arrayff.engine` | derivative method, compilation, stress |
688
+ | `arrayff.io` | file formats (EAM setfl, MEAM library and parameter file, UF3 `.uf3`/JSON, ReaxFF `ffield`; readers and writers) and `export` |
689
+ | `arrayff.interfaces` | `ArrayFFCalculator` (ASE), `TorchModel` (PyTorch) |
690
+ | `arrayff.cli` | the `arrayff train` / `eval` / `export` command line |
691
+ | `arrayff.mc` | Monte Carlo samplers, moves, local energy updates |
692
+ | `arrayff.optimize` | ASE optimization, NEB and dimer helpers |
693
+
694
+ `arrayff.potentials`, `arrayff.electrostatics` and `arrayff.utils` still
695
+ import, and warn that they moved.