Skip to content

feat(moyo-wasm): space-group data-access wrappers#331

Merged
lan496 merged 3 commits into
mainfrom
feat/wasm-data-wrappers
May 18, 2026
Merged

feat(moyo-wasm): space-group data-access wrappers#331
lan496 merged 3 commits into
mainfrom
feat/wasm-data-wrappers

Conversation

@lan496

@lan496 lan496 commented May 18, 2026

Copy link
Copy Markdown
Member

Summary

  • Add four #[wasm_bindgen] data-access functions to moyo-wasm so JS/TS callers can query crystallographic data without constructing a Cell. They wrap the corresponding moyo::data functions and mirror the moyopy API surface (SpaceGroupType, HallSymbolEntry, ArithmeticCrystalClass):
    • operations_from_number(number, setting, primitive) -> MoyoOperation[]
    • hall_symbol_entry(hall_number) -> MoyoHallSymbolEntry
    • space_group_type(number) -> MoyoSpaceGroupType (synthesized from HallSymbolEntry + ArithmeticCrystalClassEntry, matching PySpaceGroupType::new)
    • arithmetic_crystal_class(arithmetic_number) -> MoyoArithmeticCrystalClass
  • Add Tsify DTOs (MoyoSetting, MoyoCentering, MoyoHallSymbolEntry, MoyoArithmeticCrystalClass, MoyoSpaceGroupType). MoyoSetting is a tagged enum exposing all three Setting variants (Spglib, Standard, HallNumber(i32)) — the existing analyze_cell's string-based setting is left untouched and can be unified in a follow-up.
  • Errors map through the same JsValue::from_str(format!("moyo error: {:?}", err)) pattern used by analyze_cell, consolidated into a map_moyo_err helper.
  • Out of scope: layer-group and magnetic-space-group data wrappers (same pattern, follow-up PRs).

Test plan

  • cd moyo-wasm && npm run build — wasm-pack builds clean; generated pkg/moyo_wasm.d.ts contains the four new functions plus MoyoSetting/MoyoCentering/MoyoHallSymbolEntry/MoyoArithmeticCrystalClass/MoyoSpaceGroupType.
  • cd moyo-wasm && npx vitest run — 41/41 tests pass (14 new in tests/data.test.ts + 27 existing in tests/analyze_cell.test.ts).
  • New tests cover: operation counts for Ia-3d/Pm-3m/P1/C2/c, primitive vs conventional, Standard vs Spglib settings, error on invalid inputs; HallSymbolEntry(528) → Fd-3c origin choice 2; ArithmeticCrystalClass(45)3m1P/3m/hP; SpaceGroupType(221) and SpaceGroupType(167) reproducing the moyopy assertions.
  • just prek — all pre-commit hooks green (cargo fmt, mdformat, typos, etc.).

[Claude Code] Generated with Claude Code

Expose four lookup functions from moyo-wasm so JS/TS callers can query
crystallographic data without constructing a Cell:

- operations_from_number(number, setting, primitive) -> MoyoOperation[]
- hall_symbol_entry(hall_number) -> MoyoHallSymbolEntry
- space_group_type(number) -> MoyoSpaceGroupType
- arithmetic_crystal_class(arithmetic_number) -> MoyoArithmeticCrystalClass

Adds Tsify DTOs (MoyoSetting, MoyoCentering, MoyoHallSymbolEntry,
MoyoArithmeticCrystalClass, MoyoSpaceGroupType) that mirror the moyopy
API surface, plus a vitest suite covering all four functions.
Mirror the existing python and c groups so wasm-pack and vitest are
discoverable via `just --list`.
Reflects the new operations_from_number / hall_symbol_entry /
space_group_type / arithmetic_crystal_class wrappers.
@lan496
lan496 marked this pull request as ready for review May 18, 2026 12:08
@lan496
lan496 requested a review from janosh as a code owner May 18, 2026 12:08
@lan496
lan496 merged commit c6dc679 into main May 18, 2026
10 checks passed
@lan496
lan496 deleted the feat/wasm-data-wrappers branch May 18, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant