Skip to content

WP3: anisotropic ADPs and molecules through the C interface; next steps (asymmetric unit, option E pilot) - #61

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

tproffen merged 1 commit into
claude-python-appfrom
claude/inspiring-brahmagupta-ne81m7

Conversation

@tproffen

Copy link
Copy Markdown
Owner

Targets claude-python-app (not master).

What

Displacement parameters and molecules, out and in (C interface version 4)

Function Gives or takes
dc_get_type_anis tensors per type, as given
dc_adp_count, dc_get_adps, dc_get_atom_adps the distinct tensors after symmetry, with principal axes, and the tensor of each atom
dc_set_crystal now also takes per-type tensors
dc_molecule_size, dc_get_molecules, dc_set_molecules molecules: type, character, atoms; the molecule flag and number per atom

prep_anis only sets up the first 5 × (atoms per cell) atoms. dc_set_crystal therefore gives every later atom the tensor of its type; nothing is rotated on this path, so all atoms of a type share one tensor. If a type first appears beyond that range, it lets prep_anis look at all atoms.

Python

  • Crystal.adps(): U11, U22, U33, U23, U13, U12 per atom, CIF convention, symmetry-rotated.
  • Crystal.molecules(): molecule types and the atom indices of each molecule.
  • make_crystal:
    • u_aniso= per name or per atom;
    • molecules= and molecule_types=;
    • a type is now name + B + occupancy + tensor.
  • to_ase() stores the tensors in atoms.arrays["discus_u_aniso"], and from_ase() uses them.

DISCUS bug found, kept as a strict xfail test: save writes one atom type per distinct tensor, but read stru assigns atoms by name, B and occupancy. So the symmetry-rotated tensors are lost: 236 of 384 atoms in an anatase 4×4×2 crystal get the wrong tensor.

Next steps, written up: new migration/WP3_Next_Steps.md.

  1. An asymmetric unit plus space group from Python (crystal_from_sites):
    • what it gives beyond make_crystal;
    • what DISCUS's read cell does, so what a dc_set_cell has to repeat;
    • open points: origin choices and settings, special-position tolerance, mixed sites, molecules, an asymmetric-unit object, spglib;
    • tests and effort.
  2. The option E pilot in detail:
    • the kernel: the Debye histogram behind dc.powder;
    • versions: Fortran, C++ behind a C function, NumPy, Numba, later GPU;
    • correctness, including the Fortran's sine table;
    • the benchmark matrix: sizes, grids, 1 and all cores, scaling, repeats with medians, peak memory, the recorded environment;
    • fairness rules, an effort record, decision criteria and a 1.5-week plan.

It is linked from CLAUDE.md, the plan, the binding decision and the docs.

Tests

New file tests/python/test_wp3_adp_molecules.py:

  • I4₁/amd: the four-fold axis swaps U11 and U22 of O, while Ti keeps U11 = U22, for every atom of a 4×4×2 supercell.
  • The principal values are kept, B = 8π²·U_eq, and isotropic atoms carry the tensor of their B.
  • Round trip file → adps() → make_crystal → adps() is identical and gives the same Fourier map; an isotropic crystal gives a different one.
  • Per-name tensors, hexagonal P6, and a type first seen late.
  • Molecules: out, round trip (flags and molecule number per atom), reload after another structure, bad input.
  • The ASE round trip keeps the tensors.

test_capi calls all the new functions.

The notebook crystals_and_ase.ipynb gains a section on displacement parameters (h0l maps: isotropic, against O vibrating along c) and one on molecules. It ran in a Jupyter kernel and as a script.

Local results:

  • pytest tests/python: 187 passed, 34 skipped, 3 xfailed
  • Sphinx -W: OK

Generated by Claude Code

…next-steps write-up

C interface version 4:
* dc_get_type_anis (per type, as given), dc_adp_count / dc_get_adps
  (distinct tensors after symmetry, principal axes) / dc_get_atom_adps
  (tensor per atom); dc_set_crystal takes per-type tensors (has_anis, anis).
  prep_anis sets the first 5*ncatoms atoms only; dc_set_crystal gives the
  others the tensor of their type (nothing is rotated there) and lets
  prep_anis look at all atoms if a type first appears beyond that range.
* dc_molecule_size / dc_get_molecules / dc_set_molecules (type, character,
  length, atoms; molecule flag and number per atom).

Python: Crystal.adps() (per atom U11..U12, CIF convention), Crystal.molecules()
(types, atom indices); make_crystal(u_aniso=per name or per atom,
molecules=, molecule_types=); a type is name + B + occupancy + U. to_ase()
keeps the tensors in atoms.arrays["discus_u_aniso"], from_ase() uses them.

Tests (test_wp3_adp_molecules.py, test_capi): the four-fold axis of
I41/amd swaps U11/U22 of O while Ti keeps U11 = U22, for every atom of a
4x4x2 supercell; principal values kept; B = 8 pi^2 U_eq; isotropic atoms
carry the tensor of B; round trip file -> adps() -> make_crystal ->
adps() identical and the same Fourier map (an isotropic crystal differs);
per-name tensors; hexagonal P6; a type first seen late; molecules out,
round trip (flags and numbers per atom), reload; bad input; ASE round trip
keeps tensors. Found a DISCUS bug, kept as strict xfail: save writes one
type per distinct tensor but read stru assigns atoms by name, B and
occupancy, so rotated tensors are lost (236 of 384 atoms).

Docs: notebook crystals_and_ase.ipynb gains ADPs (h0l maps, isotropic vs O
vibrating along c) and molecules; api.md. New migration/WP3_Next_Steps.md:
status, an asymmetric unit + space group from Python (what DISCUS's read
cell does and what a dc_set_cell must repeat, open points, tests, effort)
and the option E pilot in detail (Debye histogram kernel; Fortran, C++,
NumPy, Numba, later GPU; correctness incl. the Fortran's sine table;
benchmark matrix, repeats, memory, recorded environment, fairness rules,
effort record, decision criteria, 1.5-week plan). Linked from CLAUDE.md,
the plan, the binding decision and the docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yw8KkfPLawp8Po4f5Bc9v
@tproffen
tproffen merged commit c8968a8 into claude-python-app Nov 24, 2026
11 checks passed
@tproffen
tproffen deleted the claude/inspiring-brahmagupta-ne81m7 branch November 24, 2026 18:59
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