Repository navigation
Crystal in from Python arrays (WP3 slice 2) and the ASE bridge - #60
Merged
Merged
Conversation
…E bridge dc_set_crystal (C interface version 3) replaces DISCUS's crystal from arrays: lattice, space group (recorded, not applied), unit cells and atoms per cell, atom types (names, B, occupancy) and atoms (positions as double[n][3], types, property flags). It follows the steps of "read stru": rese_cr, allocation, header, atoms as struc_read_atoms sets them (surface, magnetic and value zero, as_* list), cell counts as do_readstru_disk, then setup_lattice, get_symmetry_matrices, prep_anis, stack reset. Errors call errlist, so dc_last_error has the message (e.g. an unknown space group). Python: * dc.make_crystal(lattice, names, positions, space_group=, b_iso=, occupancy=, cells=, types=): B and occupancy as one value, per name or per atom; as in DISCUS a type is name + B + occupancy (+ an optional label, e.g. the site: .cell files give each site its own type). A Crystal made this way is sent again when DISCUS holds another structure meanwhile. * dc.from_ase(atoms) and Crystal.to_ase() (ASE cell = the whole crystal, DISCUS names kept in atoms.arrays["discus_names"]). * Crystal.path may be None (made from arrays); Crystal.label; the short Crystal repr (it sat in StructureView by mistake) now includes the space group. * ASE is a default dependency: inclusive default install (owner, Nov 2026); the plan (WP1) records the options for a lean install. Tests (tests/python/test_wp3_crystal_in.py, test_capi): the round trip file -> arrays -> make_crystal -> arrays is identical for the nine golden structures; powder, Fourier plane and PDF equal those of the structure read from its file (Ni, CuO); reload after another structure; type grouping; bad input; unknown space group; ASE bulk, to_ase and back (same Debye pattern), and ASE's CIF reader gives the same anatase cell as DISCUS's. Example crystals_from_python.py (NumPy crystal, O vacancies in anatase, Au nanoparticle from ASE and its PDF); api.md, install docs, binding decision and plan updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Yw8KkfPLawp8Po4f5Bc9v
…terim and fallback The owner's intent: pip install . installs everything, an extra such as .[no-jupyter] leaves a part out. Standard extras only add; PEP 771 default extras would do this but is not in a pip release yet (Nov 2026). Interim: plain dependencies and a documented lean install; fallback at the first release: diffuse-core + diffuse. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Yw8KkfPLawp8Po4f5Bc9v
What a Crystal holds (lattice, space group, atoms(), atom_types(), cartesian(), lattice_vectors(), view()); a random Cu3Au alloy built with NumPy and make_crystal, powder pattern against pure Cu; atom types (name + B + occupancy); to_ase() with ASE's neighbour list (Ti-O bonds of anatase) and file writers (into a temporary folder); from_ase() from a CIF read by ASE and from gold clusters (icosahedron vs octahedron, Debye patterns); the round trip. Committed without outputs; runs as a script in the notebook test (view cells tagged jupyter-only) and in a Jupyter kernel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Yw8KkfPLawp8Po4f5Bc9v
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.
Targets
claude-python-app(notmaster).What
The second slice of step 4 / WP3: a crystal goes from Python into DISCUS without a file, plus the ASE bridge.
C interface (version 3):
dc_set_crystalreplaces DISCUS's crystal from arrays:double[n][3], types, property flagsIt follows the steps of
read struinstructur.f90:rese_crand allocationstruc_read_atomssets themdo_readstru_disksets themsetup_lattice,get_symmetry_matrices,prep_anisand the stack resetOn an error it calls
errlist, sodc_last_errorcarries the message, for example an unknown space group.Python
dc.make_crystal(lattice, names, positions, space_group=, b_iso=, occupancy=, cells=, types=)typeslabel keeps further splits, such as the per-site types a.cellfile gives.dc.from_ase(atoms)andCrystal.to_ase(). The ASE cell is the whole crystal; DISCUS names are kept inatoms.arrays["discus_names"].Crystal.pathmay beNone; newCrystal.label.Crystal's short repr was defined insideStructureViewby mistake. It is now onCrystal, with the space group.Packaging: ASE is a default dependency. The owner wants an inclusive default install, with extras such as
.[no-jupyter]to leave parts out. Plan WP1 records how to get there:diffuse-coreplusdiffuseThe decision is deferred to the first release; Jupyter stays an extra until then.
Tests
New file
tests/python/test_wp3_crystal_in.py:make_crystal→ arrays: identical for the nine golden structures.to_ase()and back gives the same Debye pattern; ASE's CIF reader gives the same anatase cell as DISCUS, an independent check of the space-group expansion.test_capialso callsdc_set_crystal, including a bad type and a bad space group.Local results:
tests/python: 168 passed, 34 skipped, 2 xfailed-W: OKDocs and examples
crystals_from_python.py(gallery): a NumPy-built crystal, oxygen vacancies in anatase, and a gold nanoparticle built with ASE with its PDF.crystals_and_ase.ipynb, committed without outputs:Crystalholds, andview()to_ase()with ASE's neighbour list (Ti–O bonds in anatase) and its file writersfrom_ase()from a CIF read by ASE, and from gold icosahedron and octahedron clusters (Debye patterns)api.md, the install docs, the examples README, the binding decision and the plan (WP1 install note, WP3 progress).🤖 Generated with Claude Code
https://claude.ai/code/session_018Yw8KkfPLawp8Po4f5Bc9v