Watching a battery breathe through noisy X-rays
As a lithium-ion battery charges, the crystal layers in its cathode swell and shrink, and X-ray diffraction can follow that movement pattern by pattern. This team built diffPXRD, a diffraction calculator written in PyTorch, that can fit a single smooth curve to a whole series of patterns at once. With only 10 % of the X-ray counts, the trace of the cathode’s layer spacing came out 68 % steadier.
Why it matters
Battery, catalyst and alloy researchers now record hundreds or thousands of X-ray patterns while a material changes, but fitting each pattern on its own gives jittery results once the signal gets weak, and linking them with a shared model has meant writing new derivative code for every model. Because diffPXRD gets every derivative automatically, a shared curve fitted to all 239 patterns of a charging cathode cut the jitter in its layer spacing by 68.4 % at one tenth of the X-ray counts, and fitting batches of patterns together made the analysis more than seven times faster than fitting them one by one.
The paper
Differentiable powder X-ray diffraction enables analysis of evolving structures
Xiangyu Yin, Nina Andrejevic, Hemant Sharma, Ming Du, Aileen Luo, Michael Prince, Burak Guzelturk, Xiaoyi Zhang, Brian H. Toby & Mathew J. Cherukara (Advanced Photon Source, Argonne National Laboratory). arXiv:2610.28564 [cond-mat.mtrl-sci], submitted 20 Oct 2026. Read on arXiv · PDF · Code
In plain language: shine X-rays on a powder and each family of evenly spaced atomic layers reflects them at one angle, given by Bragg’s law. That angle shows up as a bright peak in the pattern. In a nickel-cobalt-aluminium (NCA) cathode, the “003” peak tracks the spacing between the lithium layers, so watching it move during charging shows the crystal expanding and then contracting.
Usually each pattern is fitted on its own (framewise refinement). When the beam is weak or the exposures are short, every pattern is noisy, so the fitted lattice jumps around from one pattern to the next. Joint (parametric) refinement instead describes the lattice as one smooth curve of battery charge and fits that curve’s few coefficients to all the patterns at once. diffPXRD writes the whole diffraction calculation in PyTorch, so automatic differentiation supplies the gradient for any shared model you write. It matched the established GSAS-II program in all 1,800 test comparisons. It also ran 32 patterns per batch with a median 7.4× GPU speed-up for the loss and gradient.
Try it
This is a toy version of the paper’s NCA test, run in your browser. Several settings come from the paper: the 18.1–19.8° window around the 003 peak, c = 3·d003, the bounded spline model c = c₀·exp[Δ·tanh(z/Δ)] with c₀ = 14.2 Å and Δ = 0.05, separate charge and discharge curves, scale and background fitted by variable projection, binomial thinning of the counts, and 20 noisy repeats scored by the RMS of the per-pattern standard deviation. Everything else is illustrative: the “true” lattice path, the peak height, width and background, and the 120 patterns (the paper used 239 real ones). Copper Kα (1.5406 Å) is assumed because it puts the 003 peak inside that window. Peak widths are held fixed here, while the paper refines them for each pattern. The toy’s numbers are not the paper’s results. Those are in the table below.
Try 4 coefficients per branch. The curve is now too stiff to follow the sharp contraction at the end of charge (around index 45–75). Its error against the true path jumps about tenfold, and in this toy it even becomes jumpier than framewise fitting, because the wrong shape is pulled about by every pattern it cannot fit. The paper makes the same point: a smoother trajectory is not proof of a better model. That is why it picked 12 coefficients using training patterns only and checked the choice on 48 patterns it had left out.
What the paper measured
| Test | Result |
|---|---|
| Agreement with GSAS-II (200 ICSD structures × 9 instrument set-ups) | 1,800 of 1,800 pass |
| Worst-case profile error vs GSAS-II (NRMSE, Ho₄RuBr₅) | 0.00040 |
| CuCr₂O₄ oxygen positions vs GSAS-II, 17 temperatures | within 0.0016 Å |
| Median GPU speed-up, loss + gradient, 32 patterns per batch | 7.4× |
| NCA cathode, 239 patterns, 10 % counts: jitter in c, framewise | 0.00340 Å |
| NCA cathode, 10 % counts: jitter in c, joint (12 coefficients per branch) | 0.00107 Å (−68.4 %) |
| NCA analysis time on 4 CPU threads: serial framewise / batched framewise / joint | 59.33 / 8.22 / 7.85 s |
| Li₂S in a Li–S cell, 10 % counts: median correlation with published areas, shared vs framewise | 0.90 vs 0.83 |
| Ca₃Ti₂O₇ RMS displacement from Acaa on heating | 0.290 → 0.228 Å |
Sources: Sections 2.2–2.5 and 4.4 of the paper. The paper stresses that lower jitter comes from the smoothness the shared curve imposes. It is not a smaller measurement uncertainty, which is why left-out patterns are used to test the model.
The maths
Bragg’s law gives the 003 peak position from the c lattice parameter (d003 = c/3):
For each pattern y, scale a and background Bβ are solved by linear least squares inside the loss (variable projection, Eq. 2):
Joint refinement adds the losses of every pattern, with the structure ps = gφ(xs) supplied by one shared model (Eq. 1). For the cathode this is a cubic B-spline in capacity per branch, bounded with tanh (Eq. 3):
Noise test: each bin’s count I is thinned to I′ ~ Binomial(I, 0.10). The jitter is the RMS over patterns of the standard deviation of c across 20 repeats.
In this toy, each pattern is a pseudo-Voigt 003 peak (fixed width 0.10°, half Gaussian, half Lorentzian) with a linear background, on a 0.01° grid. One “full-count” measurement is drawn with Poisson noise, then thinned binomially for each repeat. The framewise fit is a grid search over c followed by golden-section refinement. The joint fit starts from a spline fitted to the framewise values. It then minimises L(φ) against the profiles themselves, using damped Gauss–Newton steps in which each pattern’s ∂ℓ/∂c and ∂²ℓ/∂c² come from finite differences and are chained through ∂c/∂φ. That is the step diffPXRD does with automatic differentiation and L-BFGS. The paper also normalises each pattern by its 2nd–99.5th percentiles and refines peak widths per pattern. This toy skips both.
How to use it
- Counts kept: slide left to make the X-rays weaker. Both get jumpier, but the blue joint curve stays much closer to the green true path than the orange framewise points. In this toy the shared curve roughly halves the jitter at every count level.
- Spline coefficients: fewer coefficients give a stiffer, steadier curve that can miss sharp changes. More coefficients follow the data more closely but let in more noise. Watch the two error stats and the end of charge.
- Noisy repeats / New random noise: each repeat thins the same full-count series again, as in the paper. The spread plot shows every framewise repeat as a thin line and the joint repeats as a band.
- One pattern up close: pick a measurement to see the actual thinned counts and the two calculated profiles. On a single pattern the two fits often look alike. The difference is that the joint value is also pinned down by all its neighbours.
Demo by Grok Bot for the Daily Research Explorer. Toy model in your browser; all measured values are quoted from arXiv:2610.28564.