Skip to content

Crystal.save() and Crystal.export(), tested by reading back; crystal-method list in the plan - #62

Open
tproffen wants to merge 1 commit into
claude-python-appfrom
claude/inspiring-brahmagupta-ne81m7
Open

tproffen wants to merge 1 commit into
claude-python-appfrom
claude/inspiring-brahmagupta-ne81m7

Conversation

@tproffen

Copy link
Copy Markdown
Owner

Targets claude-python-app (not master).

What

Crystal.save(path) writes DISCUS's own format through the save menu (reset, outfile, write all):

  • .stru (text), or
  • .h5/.hdf5 (format nexus, binary, compact for large crystals).

read_structure now also reads .h5/.hdf5.

Crystal.export(path, format=..., ...) writes files for other programs through DISCUS export; the format comes from the suffix or from format=:

Format Options
CIF space_group: "P1" or "original"
SHELX .ins cycles, force, origin, wavelength
RMCProfile .rmc6f version: 6 or 7
VASP / POSCAR –
Scatty site: "average" or "indiv"

Both methods load the crystal first if DISCUS holds another one, refuse file names DISCUS cannot take (commas, quotes), and check that the file was written.

Tests: each reads back what was written

New file tests/python/test_crystal_save_export.py:

  • save to .stru and .h5: a crystal with molecules (cmm2), a monoclinic one (CuO), an anisotropic tensor (P6), and a crystal made in Python. Atoms, types, B, occupancy, tensors, property flags, molecules, cell, space group and cell counts are identical, and the Fourier map is the same.
  • CIF: read by gemmi (P1, the whole crystal as one cell, U_iso = B/8π²) and by DISCUS.
  • RMCProfile: read back through DISCUS's import; the same sites after a whole-cell shift.
  • VASP and Scatty: the files are parsed; for Scatty, site + cell gives back every position.
  • SHELX: the file is written. The full round trip is the known bug already in test_wp3_structures.
  • Bad arguments.

DISCUS bugs found, kept as strict xfail tests:

  1. read stru sets the displacement tensors of the first 5 × (atoms per cell) atoms only; every later atom keeps tensor 1.
    • A saved anisotropic supercell reads back wrong: 21 of 48 atoms, and a Fourier map changes by up to 3 %.
    • Isotropic crystals only report it wrong in adps(); their calculations use B and are unaffected (checked).
    • make_crystal already works around this.
  2. export cif with spcgr:original lists the whole unit cell together with the space-group operations, so readers (DISCUS and gemmi alike) generate 80 atoms for anatase instead of 12. The docstring warns to use "P1" until this is fixed.

Plan

migration/WP3_Next_Steps.md:

  • A table of the DISCUS bugs found in crystal I/O, with their tests.
  • New section 3: the DISCUS routines that should become Crystal methods.
    • Writing; questions about the crystal; changing the crystal.
    • What stays outside the class.
    • Design questions, starting with: return a new crystal rather than change it in place.
    • A first batch: save and export (done here); composition, asymmetric_unit, cut, replace, remove, thermal_displacements; then the chem analysis.
  • The updated order of next steps.

Docs

  • api.md: save, export.
  • Notebook crystals_and_ase.ipynb: a "Saving and exporting" section; it ran in a Jupyter kernel.

Local results:

  • pytest tests/python: 212 passed, 34 skipped, 5 xfailed
  • Sphinx -W: OK

Generated by Claude Code

…method list in the plan

Crystal.save(path): DISCUS's own format through the save menu (reset,
outfile, write all): .stru, or .h5/.hdf5 (format nexus); read_structure
now also reads .h5/.hdf5. Crystal.export(path, format=, ...): DISCUS
export as CIF (space_group "P1" or "original"), SHELX (cycles, force,
origin, wavelength), RMCProfile (version 6/7), VASP/POSCAR, Scatty (site
average/indiv); the format from the suffix or format=. Both load the
crystal first if DISCUS holds another one, refuse names DISCUS cannot
take, and check that the file was written.

Tests (tests/python/test_crystal_save_export.py), each reading back what
was written:
* save .stru and .h5 for molecules (cmm2), a monoclinic crystal (CuO)
  and an anisotropic tensor (P6), and a crystal made in Python: atoms,
  types, B, occupancy, tensors, property flags, molecules, cell, space
  group, cell counts identical; the same Fourier map.
* export CIF read by gemmi (P1, the whole crystal as one cell, U_iso =
  B/8 pi^2) and by DISCUS; RMCProfile through DISCUS's import (same sites
  after a whole-cell shift); VASP and Scatty parsed (Scatty: site + cell
  gives every position); SHELX writes a file; bad arguments.

DISCUS bugs found, kept as strict xfail tests:
* read stru sets the tensors of the first 5 x (atoms per cell) atoms only;
  a saved anisotropic supercell reads back with wrong tensors (a Fourier
  map changes by up to 3 %); isotropic crystals only report it wrong.
* export cif with spcgr:original lists the whole unit cell with the
  space-group operations; readers (DISCUS and gemmi) generate 80 atoms
  for anatase instead of 12.

migration/WP3_Next_Steps.md: the DISCUS bugs found in crystal I/O, and a
new section 3 with the DISCUS routines that should become Crystal methods
(writing, questions, changes; what stays outside the class; design
questions; first batch), and the updated order of next steps. Notebook
crystals_and_ase.ipynb: saving and exporting. api.md: save, export.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yw8KkfPLawp8Po4f5Bc9v

This branch has not been deployed

No deployments
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.

2 participants