Fix transposed Lattice when writing non-symmetric cells - #49
Merged
Merged
Conversation
Frame.cell holds the cell vectors as columns, which is what both readers return for both Lattice syntaxes (old-style 9 numbers listed a1 a2 a3, and the nested 3x3 form as the matrix itself; test_new_non_symm_Lattice pins the latter). Both writers transposed it once more before serialising, so a read -> write -> read round trip transposed every non-symmetric cell: - C writer: pass frame.cell (its old-style output is column-major). - Python writer: write Lattice old-style (a1 a2 a3, full precision), like the C writer and ASE; ASE's own reader rejects the nested form. - ase-extxyz: _atoms_to_frame stores atoms.cell.T (ASE rows -> columns), and ExtXYZTrajectoryWriter no longer transposes (the two errors cancelled for the C trajectory writer only). Every existing round-trip test used a diagonal or otherwise symmetric cell. tests/test_cell_convention.py and the new ase-extxyz tests use a triclinic cell across both readers (cleri and first-char dispatch C parsers, Python) and both writers, and check the written file with ASE's independent reader. Frame's docstring now states the convention. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…irs with) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Frame.cellstores the lattice vectors as columns (cell[:, i]isa_i). Both readers already return that, for bothLatticesyntaxes:Lattice="a1 a2 a3": the nine numbers list a1, a2, a3 in turn;Lattice=[[...], [...], [...]]: the matrix as written, whichtest_new_non_symm_Latticepins.Both writers transposed the cell once more before writing. So a read → write → read round trip transposed every non-symmetric cell. Every existing round-trip test used a diagonal or symmetric cell, where a transpose doesn't show.
Fix (Python only; the C code is unchanged):
_write_frame_cextxyz): passframe.cell. Its old-style output is column-major._write_frame_pure_python): writeLatticein the old 9-number form (a1 a2 a3,reprprecision), as the C writer and ASE do. ASE's own extxyz reader rejects the nested form this writer used to produce._atoms_to_framestoresatoms.cell.T, converting ASE's row vectors to columns.ExtXYZTrajectoryWriterno longer transposes. Until now these two errors cancelled each other, but only for the C trajectory writer.Framedocstring: now states the convention. The old text called ASE's convention "column-vector".Tests:
tests/test_cell_convention.py: a triclinic cell through all three parsers (C with cleri, C first-char dispatch, Python), in bothLatticesyntaxes, through both writers, plus the full write/read round-trip matrix.python/ase-extxyz/tests/test_io.py:extxyzreader, an independent parser.test_io,test_ase_cases,test_kv_parsing_keyand the old-style-array tests: 28 passed. The full kv-parsing suite is slow.One mismatch for the maintainer to settle: the README spec section says a 3x3
Latticehas "rows are cell vectors". That contradictstest_new_non_symm_Latticeand the readers. This PR follows the readers and the test, and leaves the README unchanged.Found via ace-jax, whose extxyz round trip transposed triclinic cells (ACEsuit/ace-jax#36).
🤖 Generated with Claude Code