Phase 12 — Native, object-oriented bindings
Goal: make Python and JavaScript feel native: objects in, objects out, arrays without copies where possible, full type information, no re-parsing. Phase 12 is additive in 1.x; the text/dict functions it supersedes are deprecated (Task 11.4.2) and removed in 2.0 (Task 17.1).
Release gate: v1.5.0.
Task 12.1 — Python object API
- [ ] 12.1.1 Every operation accepts
StructureDescription: every function that takes CIF text also accepts aStructure, and every structure-producing function returns aStructure(withto_dict()for the old shape). Methods mirror the free functions:s.supercell(2, 2, 2).slab((1, 1, 1), layers=2, vacuum=10).write("s.cif"). - [ ] 12.1.2 Typed result classes Description: replace
dict/Anyresults with frozen classes (SymmetryDataset,PxrdPattern,OptimizeResult,PorosityReport, …) generated from the serde types, withto_dict(),__repr__and rich_repr_html_for notebooks. - [ ] 12.1.3
mypy --strictwithoutAnyDescription: the.pyistubs contain noAnyin public signatures; a test greps for it. - [ ] 12.1.4 Context managers and progress Description: long operations accept
progress=callbacks and honourKeyboardInterruptthrough the cancellation token;tqdmintegration when installed.
Task 12.2 — NumPy
- [ ] 12.2.1 Arrays out Description:
positions,frac_positions,cell,numbers,forces,stress, PXRDtwo_theta/intensity, grids and meshes asnumpy.ndarray(copy-free where layout allows). Featurenumpyon by default for wheels. - [ ] 12.2.2 Arrays in Description:
Structure.from_arrays(cell, numbers, frac=… | cart=…),set_positions(array); shape and dtype validated withInputError. - [ ] 12.2.3 Batch APIs Description:
xtalforge.batch.read(paths),batch.detect_symmetry,batch.pxrdreleasing the GIL and running in parallel, returning lists in input order (rule 6).
Task 12.3 — JavaScript/TypeScript object API
- [ ] 12.3.1 Structure handle Description: a
Structureclass owning the parsed Rust value (Structure.fromText(text, hint)), with methods for every operation, so a structure is parsed once; explicitfree()plusFinalizationRegistry. - [ ] 12.3.2 Typed results Description: generate TypeScript interfaces from the serde types (
tsifyor a schema-driven generator); no exported function returnsany. A test fails onanyinxtalforge_wasm.d.ts. - [ ] 12.3.3 Typed arrays Description: positions, scene buffers, patterns and meshes as
Float64Array/Float32Array/Uint32Arrayviews for zero-copy rendering. - [ ] 12.3.4 Web worker and Node entry points Description: an optional worker wrapper (
xtalforge-wasm/worker) that runs heavy operations off the main thread with progress and cancellation; a Node entry with file helpers. - [ ] 12.3.5 Optional threads Description: a second WASM build with
wasm-bindgen-rayonfor browsers with cross-origin isolation; same results as the single-threaded build.
Task 12.4 — Surfaces and docs
- [ ] 12.4.1 Parity matrix, API pages, tutorials and the playground move to the object API; benchmarks show the parse-once gain.