ENH: per-atom site energies and virials in the Manybody calculator - #323
Open
jameskermode wants to merge 1 commit into
Open
ENH: per-atom site energies and virials in the Manybody calculator#323jameskermode wants to merge 1 commit into
jameskermode wants to merge 1 commit into
Conversation
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.
jameskermode
marked this pull request as ready for review
July 1, 2026 13:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Expose per-atom decompositions from the (public)
Manybodycalculator(
matscipy/calculators/manybody/calculator.py) as the standard ASE per-atomproperties:
energies— site energies,e_n = 0.5 * sum_{p: i_p = n} F_pstresses— per-atom virialr (x) faccumulated on the home atom with thesame
0.5factor (Voigtn x 6)Both are purely additive:
energy,stressandforcesare untouched, and byconstruction
sum(energies) == energyandsum(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-atomenergies 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) == energyto ~1e-13 andsum(per-atom stress) == global stressto~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
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.
calculator.pyManybody. The separatenewmb.Manybodycould mirror this if desired (left out here to keep the change focused).
set_sublattices; parametrisingeval_shift's relaxationfmax) arebehaviour-sensitive (they touch values pinned by existing tests) and are tracked
separately rather than bundled here.
🤖 Generated with Claude Code