Skip to content

Add smooth analytic ZBL correction - #44

Open
Pragalbhv wants to merge 1 commit into
BingqingCheng:mainfrom
Pragalbhv:zbl-correction
Open

Add smooth analytic ZBL correction#44
Pragalbhv wants to merge 1 commit into
BingqingCheng:mainfrom
Pragalbhv:zbl-correction

Conversation

@Pragalbhv

Copy link
Copy Markdown

Summary

Adds ZBLCorrection, a fixed (non-trainable), differentiable short-range Ziegler–Biersack–Littmark repulsive correction as a CACE output_module.
Prevents unphysical atomic collapse at very short range without perturbing normal-bond-length behavior.

Design

  • Reproduces the ZBL formula and numerical constants from hiphive's ZBLCalculator (https://gitlab.com/materials-modeling/hiphive), ported to PyTorch on CACE's directed-edge graph (edge_index/shifts) so it is differentiable through CACE's existing Forces/stress pipeline via autograd — no separate calculator-side implementation needed.
  • Smoothly switched to exactly zero above a configurable switch_off using the existing cace.modules.cutoff.SwitchFunction, so it only affects the short-range repulsive wall and leaves the learned + electrostatic energy untouched at normal interatomic distances.
  • Correctly accounts for CACE's directed (doubled) edge list (0.5 per-edge weighting), batched multi-structure graphs (scatter_sum over data["batch"]), and periodic images (including self-loop edges through nonzero periodic shifts).
  • No trainable parameters; drops into an existing output_modules list ahead of FeatureAdd/Forces with no changes to either.

Usage

zbl = cace.modules.ZBLCorrection(switch_on=..., switch_off=..., output_key="zbl_energy")
e_add = cace.modules.FeatureAdd(
    feature_keys=[..., "zbl_energy"], output_key="CACE_energy"
)
output_modules = [..., zbl, e_add, forces]

Tests

tests/test_zbl.py (9 tests, all passing):

  • Analytic pair energy vs. hiphive's closed-form value, with directed-edge (i→j/j→i) double-counting accounted for.
  • Switch-to-zero above switch_off.
  • Force gradient vs. finite-difference/autograd of the energy.
  • Finite energy/gradient at near-zero distance in float32 and float64.
  • Correct ordering through FeatureAddForces.
  • Constructor validation (switch_off vs. cutoff).
  • Periodic self-loop pairs (atom interacting with its own periodic image) treated as ordinary weighted pairs.
  • Batching: per-structure energies match independent evaluation.

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