Skip to content

ENH: per-atom site energies and virials in the Manybody calculator - #323

Open
jameskermode wants to merge 1 commit into
masterfrom
fix/manybody-per-atom-decomposition
Open

ENH: per-atom site energies and virials in the Manybody calculator#323
jameskermode wants to merge 1 commit into
masterfrom
fix/manybody-per-atom-decomposition

Conversation

@jameskermode

Copy link
Copy Markdown
Member

What

Expose per-atom decompositions from the (public) Manybody calculator
(matscipy/calculators/manybody/calculator.py) as the standard ASE per-atom
properties:

  • energies — site energies, e_n = 0.5 * sum_{p: i_p = n} F_p
  • stresses — per-atom virial r (x) f accumulated on the home atom with the
    same 0.5 factor (Voigt n x 6)

Both are purely additive: energy, stress and forces are untouched, and by
construction sum(energies) == energy and sum(per-atom virial) == global virial.

Why

The many-body calculators previously exposed only global energy/stress, so anything
needing a per-atom hook had no access to it — in particular
matscipy.fracture_mechanics.energy_release.J_integral (which takes per-atom
energies and per-atom virials), per-site energy checks, and atomic-strain work. This
came up while building a from-scratch Sinclair flexible-BC fracture reference oracle
(same campaign as #320, #321, #322).

Validation

sum(energies) == energy to ~1e-13 and sum(per-atom stress) == global stress to
~1e-17 for Stillinger–Weber (SW-Si) and Tersoff/Erhart–Albe (3C-SiC), including
sheared cells (all six virial components exercised). Test added in
tests/manybody/test_per_atom_decomposition.py.

Notes / caveats

  • Marked draft: developed in an environment without the built extension / pytest,
    so the change was validated by reproducing the decomposition against the installed
    release (sums to machine precision) rather than by running the suite locally —
    please let CI confirm.
  • Targets the exported calculator.py Manybody. The separate newmb.Manybody
    could mirror this if desired (left out here to keep the change focused).
  • Two further robustness items from the same campaign (opt-in graph-based
    set_sublattices; parametrising eval_shift's relaxation fmax) are
    behaviour-sensitive (they touch values pinned by existing tests) and are tracked
    separately rather than bundled here.

🤖 Generated with Claude Code

Expose per-atom decompositions from Manybody.calculate as the ASE per-atom
properties `energies` (site energies, 0.5*sum_{p:i_p=n} F_p) and `stresses`
(per-atom virial r(x)f accumulated on the home atom, same 0.5 factor). Both are
additive — existing `energy`/`stress`/`forces` are unchanged — and sum exactly to
the global energy and global virial by construction.

These are needed for e.g. the J-integral (energy_release.J_integral), per-site
energy checks, and atomic-strain work, which previously had no per-atom hook on
the many-body calculators. Validated: sum(energies)=energy to 1e-13 and
sum(per-atom stress)=global stress to ~1e-17 for Stillinger-Weber and
Tersoff/Erhart-Albe (SW-Si and 3C-SiC), including sheared cells.

Adds tests/manybody/test_per_atom_decomposition.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant