Repository navigation
fix(unfold): refuse an atom with no translated image, and take the nearest image - #93
Merged
Merged
Conversation
…t image wins Red on main: a vacancy and a transformation_matrix that does not make the cell return weights with no error, and a 1.6 Angstrom dimer's bonding band gets weight 0 instead of 1.
… are supercells The 2x2x2 fixture held atoms at the origin and the body centre only, so six of its eight translations had no image and the tests pinned the silent fallback to basis 0. It now holds the eight sites of the supercell.
Two atoms landing on one image leave another atom with no preimage, so the translation map is not one to one.
…arest image Unfolder._make_translate_maps left index 0 for an atom with no image under a primitive-cell translation, and let the last atom within tol_radius win. A vacancy, an interstitial or a transformation_matrix that does not make the supercell gave weights with no error, and a short bond inside the tolerance mapped an atom onto its neighbour. translation_images now picks the nearest same-label site within the tolerance and raises a ValueError naming the atom and the translation when the map is not one to one. Both unfolders call it.
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.
film.mp4
Why
Band unfolding pairs each atom with its image under every primitive-cell translation. When no atom matched, the map kept index 0. When two atoms matched, the last one won. A vacancy, an interstitial, or a
transformation_matrixthat does not make the supercell gave unfolding weights with no error. This was item "Unfolding silently falls back to basis 0" in #57.What changed
translation_imagesinpyprocar/utils/unfolder.pybuilds the map. It picks the nearest same-label site withintol_radius. It raises aValueErrorthat names the atom and the translation when the map is not one to one.Unfolder(behindebs.unfoldandpyprocar.unfold) and the legacyprocarunfold.Unfolderboth call it.Scope
Blast Radius
Every
pyprocar.unfoldandebs.unfoldcall goes through the new map. For a valid supercell the map is the same, so the weights are the same. A call that used to return wrong weights now raises.Verification
Wrong matrix on the MgB2 fixture (
data/examples/bands/unfolding/supercell,diag(4, 2, 1)instead ofdiag(2, 2, 2)). On main the weights differ from the correct ones by up to 0.74, with no error. On the PR it raises, naming atom 0 (Mg) and the translation (0.25, 0, 0). Headdfd4777f.Correct matrix on the same fixture. The
diag(2, 2, 2)weights are bitwise identical on main and the PR (max difference 0.0, 150 x 80 weights).Independent reference.
$H run ref-unfold data/examples/bands/unfolding .../ref_unfold.pymatchesebs.unfoldto 8.9e-16. Its analytic check passes at 1.1e-16.Red, then green.
python .github/scripts/red_green.py origin/mainpasses. The vacancy, wrong-matrix and interstitial cases did not raise on main. The 1.6 Angstrom dimer's bonding band got weight 0.0 on main, and gets 1.0 (the Popescu-Zunger value) here.CI commands. The non-data suite passes (3580 tests). The 95 data-marked unfolding tests pass. ruff check and format gates pass. The ty baseline gate shows no new diagnostic from this change, and 4 stale entries are pruned in their own commit.
Not verified
unresolved-importdiagnostics intests/scripts/. main shows the same 3 in this worktree, so CI is the final check.Created with Claude Opus 5.5 in T3 Code.