Skip to content

Crystal arrays out through the C interface (WP3 slice 1); legacy tests prefer this checkout's build - #59

Merged
tproffen merged 2 commits into
claude-python-appfrom
claude/inspiring-brahmagupta-ne81m7
Nov 24, 2026
Merged

tproffen merged 2 commits into
claude-python-appfrom
claude/inspiring-brahmagupta-ne81m7

Conversation

@tproffen

@tproffen tproffen commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Targets claude-python-app (not master).

This PR has two commits. The second was pushed while the first was still waiting for review.

1. Step 4 / WP3, first slice: crystal arrays out (a6de9b9)

New bind(C) functions; the C interface goes to version 2. They use the "ask, then fill" pattern:

Function Returns
dc_crystal_size number of atoms, number of atom types
dc_get_cell lattice, space group, unit cells, atoms per cell
dc_get_atoms positions as double[n][3] (the layout of cr_pos(3,n)), types, property flags, molecule numbers
dc_get_atom_types names, B, occupancy of types 0..ntypes

Python side:

  • Crystal.atoms() reads these instead of saving and parsing a .stru file, with the same positions:

    Atoms Arrays save + parse
    129,600 4 ms 0.4 s
    1,036,800 34 ms 3.7 s
  • read_structure() takes natoms, lattice and the space group from them, with no r[490..496] round trip.

  • New: Crystal.atom_types() (names, B, occupancy) and Crystal.space_group.

Tests:

  • test_capi: every new function, including a 2×3×1 supercell that checks the (n, 3) order, and wrong sizes returning -1.
  • test_wp3_structures: the arrays against DISCUS's own save output for the nine golden structures (names, positions, B, properties, molecules, types, occupancy, cell, space group).

Docs: api.md, the powder_demo example, the binding decision and the plan (WP3 progress).

2. Legacy tests: which discus_suite (fee9d06)

On the owner's machine, pytest picked up an older discus_suite working copy in /usr/local/bin, so 03.pdf, 04.sro3 and 08.nano_ellipsoid failed, and nothing in the output said which binary had run.

  • tools/run_legacy_tests.py and tests/python/test_legacy_macros.py now look in this order:
    1. --exe
    2. $DISCUS_SUITE
    3. build/suite/prog/discus_suite of this checkout
    4. PATH, last
  • The runner prints, and the pytest header shows, the binary, its build time and where it was found, with a warning when it comes from PATH.
  • tests/README.md: the search order, and setting DISCUS_SUITE in the virtual environment.

Tests (local)

  • pytest tests/python: 141 passed, 34 skipped, 2 xfailed.
  • The discus_suite lookup checked in four cases: DISCUS_SUITE set, only PATH, a build inside the checkout, none found.
  • Sphinx -W: OK.

CI runs every job, because the C interface (python/*.f90, *.h) changed.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yw8KkfPLawp8Po4f5Bc9v

…inary

run_legacy_tests.py and test_legacy_macros.py look for discus_suite in
this order: --exe, $DISCUS_SUITE, build/suite/prog/discus_suite of this
checkout, PATH. PATH comes last because an installed discus_suite (e.g. a
working copy in /usr/local/bin) may be older than the checkout: that made
03.pdf, 04.sro3 and 08.nano_ellipsoid fail on the owner's machine. The
runner prints, and the pytest header shows, the binary, its build time and
where it was found, with a warning when it comes from PATH.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yw8KkfPLawp8Po4f5Bc9v
New bind(C) functions (C interface version 2), "ask, then fill":
dc_crystal_size (atoms, atom types), dc_get_cell (lattice, space group,
unit cells, atoms per cell), dc_get_atoms (positions as double[n][3] =
cr_pos(3,n), types, property flags, molecule numbers) and
dc_get_atom_types (names, B, occupancy of types 0..ntypes).

Crystal.atoms() reads these instead of saving and parsing a .stru file:
about 100 times faster (1 036 800 atoms: 34 ms instead of 3.7 s), same
positions. read_structure() takes natoms, lattice and the space group from
them (no r[490..496] round trip). New: Crystal.atom_types() (names, B,
occupancy) and Crystal.space_group.

Tests: test_capi calls every new function (sizes, cell, a 2x3x1 supercell
that checks the (n, 3) order, wrong sizes give -1); test_wp3_structures
compares the arrays with DISCUS's own "save" output for the nine golden
structures (names, positions, B, properties, molecules, types, occupancy,
cell, space group). Docs: api.md, powder_demo example, binding decision,
plan (WP3 progress).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yw8KkfPLawp8Po4f5Bc9v
@tproffen tproffen changed the title Legacy tests: prefer this checkout's build over PATH, and say which discus_suite Crystal arrays out through the C interface (WP3 slice 1); legacy tests prefer this checkout's build Nov 24, 2026
@tproffen
tproffen merged commit 9011579 into claude-python-app Nov 24, 2026
6 checks passed
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