A minimal crystal structure viewer for the web.
npm install bravais threeimport { buildScene, createViewer, expandStructure, readCif } from "bravais";
const scene = buildScene(expandStructure(await readCif(cifText)));
createViewer(document.getElementById("viewer")).setLayers([{ scene }]);- three.js: rendering, as a peer dependency.
- moyo: space-group operations, bundled as WebAssembly.
- VESTA: the bond cutoffs, the element colours, used here in Pretty Lattice's softened version, and the occupancy pies.
- pymatgen: the copy of VESTA's cutoff table this package ships.
- OKLab: Björn Ottosson's public-domain colour formulas. They supply no colours: they measure how alike two colours look, and move an element's colour only when it would clash with one already on screen.
Thanks to Feitong Song's Pretty Lattice, which this viewer follows in its lighting and materials, depth fading, trackball feel, axes gizmo, legend swatch, standard view and softened element colours.
The code was written by Claude Code, under the author's direction and review.
MIT. Notices for the bundled third-party material are in THIRD_PARTY_NOTICES.md.