fix(corrections): swap defect/bulk site potentials in get_efnv_correction#226
Merged
Conversation
…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.
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.
Closes #219.
Summary
get_efnv_correctionwas extracting site potentials from the wrong structures:For antisites (
defect.num_sites == bulk.num_sites) the swap was silent but inverted the sign of the alignment term. For vacancies/interstitials it raisedIndexErrordownstream inpydefect.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.test_kumagai_vacancy: synthesizes a vacancy by removing a site from the bundled q=0 structure sodefect.num_sites != bulk.num_sites. Without the fix this reproduces the originalIndexError; with the fix it returns cleanly.