Skip to content

fix(corrections): swap defect/bulk site potentials in get_efnv_correction#226

Merged
jmmshn merged 1 commit into
mainfrom
fix/kumagai-swap-gh219
Jun 12, 2026
Merged

fix(corrections): swap defect/bulk site potentials in get_efnv_correction#226
jmmshn merged 1 commit into
mainfrom
fix/kumagai-swap-gh219

Conversation

@jmmshn

@jmmshn jmmshn commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Closes #219.

Summary

get_efnv_correction was extracting site potentials from the wrong structures:

defect_potentials = [site.properties["potential"] for site in defect_structure]  # was: bulk_structure
bulk_potentials   = [site.properties["potential"] for site in bulk_structure]    # was: defect_structure

For antisites (defect.num_sites == bulk.num_sites) the swap was silent but inverted the sign of the alignment term. For vacancies/interstitials it raised IndexError downstream in pydefect.make_efnv_correction. Reported in #219.

Tests

  • test_kumagai: invariant assertions (isfinite, < 0) + a snapshot value (-0.4898778 eV) for regression detection. The pre-fix code asserted > 0, which was implicitly locking in the buggy behavior.
  • New test_kumagai_vacancy: synthesizes a vacancy by removing a site from the bundled q=0 structure so defect.num_sites != bulk.num_sites. Without the fix this reproduces the original IndexError; with the fix it returns cleanly.

…tion (GH#219)

Lines 96-97 of kumagai.py had defect_potentials and bulk_potentials
sourced from the wrong structures. For antisite defects (defect.num_sites
== bulk.num_sites) the swap was silent but produced incorrect alignment;
for vacancies and interstitials it raised IndexError downstream in
pydefect's make_efnv_correction.

- Restore correct ordering: potentials are read from the structure they
  describe.
- The pre-existing test_kumagai assertion (q=+1 correction > 0) was
  effectively locking in the buggy behavior — the correct value with
  proper ordering is approximately -0.49 eV. Updated to assert the new
  reference value.
- Add test_kumagai_vacancy regression test that synthesizes a vacancy
  (different num_sites between defect and bulk) and exercises the bug
  directly. Without the fix this raises the same IndexError reported
  in GH#219.

Reported by user in GH issue #219; the issue body identifies the swap
and the verified-against-legacy KumagaiCorrection value.
@jmmshn jmmshn merged commit dd867f7 into main Jun 12, 2026
3 of 7 checks passed
@jmmshn jmmshn deleted the fix/kumagai-swap-gh219 branch June 12, 2026 16:02
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.

[Bug]: inverted site potentials in EFNV corrections

1 participant