bravais 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import type { SymmetryOperation } from "../structure/types.js";
2
2
  /**
3
- * Parse one Jones-faithful operator such as `-x+1/2, y, -z+1/2` or
4
- * `2/3+x,1/3+y,1/3+z` into a rotation matrix and translation.
3
+ * Parse a symmetry operation as CIF files write it, such as
4
+ * `-x+1/2, y, -z+1/2`, into a rotation matrix and translation.
5
5
  */
6
6
  export declare function parseSymmetryOperator(text: string): SymmetryOperation;
@@ -18,12 +18,12 @@ export type { BuildSceneOptions, SceneAtom, StructureScene, } from "./scene/buil
18
18
  export type { Bond } from "./structure/bonds.js";
19
19
  export type { Lattice, LatticeParameters, Mat3, Site, SpaceGroupInfo, Species, Structure, SymmetryOperation, Vec3, } from "./structure/types.js";
20
20
  /**
21
- * Read the first structure in a CIF. Symmetry comes from the file's operator
22
- * loop, checked to fit its atoms, or from moyo by the file's space-group
23
- * symbol or number, in the setting its atoms or its cell select; a file
24
- * naming neither is taken as listing every atom (P1). Throws
25
- * `CifSyntaxError` for text that is not CIF, `CifStructureError` for a
26
- * CIF without a usable structure, and `SpaceGroupLookupError` for a space
27
- * group the symmetry table does not know.
21
+ * Read the first structure in a CIF file. Its symmetry comes from the
22
+ * file's list of symmetry operations or, without one, from its space-group
23
+ * symbol or number; a file with neither is read as listing every atom.
24
+ *
25
+ * Throws `CifSyntaxError` for text that is not valid CIF,
26
+ * `CifStructureError` for a file without a usable structure, and
27
+ * `SpaceGroupLookupError` for an unknown space group.
28
28
  */
29
29
  export declare function readCif(text: string): Promise<Structure>;
@@ -2,14 +2,17 @@ import { OrthographicCamera, Quaternion, Scene, type WebGLRenderer } from "three
2
2
  import type { Mat3 } from "../structure/types.js";
3
3
  /** The a, b, c axes of the cell drawn in a corner, following the camera. */
4
4
  export declare class AxesGizmo {
5
- private readonly fontFamily;
6
5
  readonly scene: Scene<import("three").Object3DEventMap>;
7
6
  readonly camera: OrthographicCamera;
8
7
  private readonly axes;
8
+ /** The a, b and c arrows, built once and turned to each new cell. */
9
+ private readonly arrows;
9
10
  private readonly headlight;
10
11
  private readonly inverse;
12
+ private readonly direction;
11
13
  /** `fontFamily` is the interface font the axis letters are drawn in. */
12
14
  constructor(fontFamily: string);
15
+ /** Point the arrows along the cell's a, b and c axes. */
13
16
  setCell(cell: Mat3): void;
14
17
  /** Draw into the bottom-left `size` pixels of a renderer whose main pass is done. */
15
18
  render(renderer: WebGLRenderer, cameraQuaternion: Quaternion, size: number): void;
@@ -1,4 +1,4 @@
1
- import { DataTexture, LineBasicMaterial, MeshStandardMaterial, type Material } from "three";
1
+ import { DataTexture, LineBasicMaterial, MeshStandardMaterial } from "three";
2
2
  export declare const METALNESS = 0.1;
3
3
  export declare const ROUGHNESS = 0.6;
4
4
  export declare const AMBIENT_LIGHT_INTENSITY = 0.8;
@@ -40,4 +40,3 @@ export declare const GIZMO_AXIS_STENCIL = 1;
40
40
  * axis letters can tell what they are drawn over.
41
41
  */
42
42
  export declare function createGizmoMaterial(color: string, stencilRef: number): MeshStandardMaterial;
43
- export declare function disposeMaterial(material: Material | Material[]): void;
@@ -1,12 +1,11 @@
1
- /** Assign session colours to `elements` before drawing them, most common first. */
1
+ /** Give these elements their colours now, the more common ones first, so colours do not depend on drawing order. */
2
2
  export declare function ensureElementColors(elements: readonly string[]): void;
3
- /** The session colour of an element, assigned now if it is new. */
3
+ /** The colour of an element as a hex string such as `#e15949`, given on first use. */
4
4
  export declare function elementColor(element: string): string;
5
- /** Elements seen in this session with their colours, in order of first appearance. */
5
+ /** Every element given a colour so far, with its colour, in the order given. */
6
6
  export declare function elementColorAssignments(): [string, string][];
7
7
  /**
8
- * Forget the session's colours, for when every structure is cleared. The
9
- * palette is shared by every viewer and thumbnail renderer in the page,
10
- * which pick up new colours at their next draw.
8
+ * Forget every colour given so far, for example when all structures are
9
+ * closed. Viewers and thumbnails pick up new colours at their next draw.
11
10
  */
12
11
  export declare function resetElementColors(): void;
@@ -6,12 +6,13 @@ export interface ThumbnailRenderer {
6
6
  * Models are cached by `key` and rebuilt when the layers array changes.
7
7
  */
8
8
  render(key: string, layers: SceneLayer[], view: ViewState | null, canvas: HTMLCanvasElement): void;
9
- /** Drop the cached model of `key`. */
9
+ /** Forget the cached model of `key`. */
10
10
  release(key: string): void;
11
+ /** Free the shared WebGL context and every cached model. */
11
12
  dispose(): void;
12
13
  }
13
14
  /**
14
- * One shared WebGL context that paints small previews into ordinary 2D
15
- * canvases, so a list of structures does not open a context per card.
15
+ * Draw small previews into ordinary canvases from one shared WebGL context,
16
+ * so a list of structures does not need a context for each.
16
17
  */
17
18
  export declare function createThumbnailRenderer(): ThumbnailRenderer;
@@ -1,7 +1,7 @@
1
1
  import type { Vec3 } from "../structure/types.js";
2
2
  /**
3
- * A camera pose an app can store, restore and carry between a viewer and a
4
- * thumbnail: the same state reads the same at any canvas size.
3
+ * A view an app can save and restore, or pass between a viewer and a
4
+ * thumbnail. It looks the same at any canvas size.
5
5
  */
6
6
  export interface ViewState {
7
7
  /** Orientation of the camera as [x, y, z, w], three.js order. */
@@ -8,32 +8,30 @@ export interface ViewerOptions {
8
8
  }
9
9
  export interface Viewer {
10
10
  /**
11
- * Replace what is drawn with scenes from `buildScene`, usually of expanded
12
- * structures. The view resets to the standard orientation unless `view`
13
- * is given.
11
+ * Draw these scenes from `buildScene`, replacing what was shown. The view
12
+ * resets to the standard orientation unless `view` is given.
14
13
  */
15
14
  setLayers(layers: SceneLayer[], view?: ViewState | null): void;
16
15
  /** Remove everything drawn. */
17
16
  clear(): void;
18
- /** The current pose, or null while nothing is loaded. */
17
+ /** The current view, or null while nothing is shown. */
19
18
  getView(): ViewState | null;
20
- /** Restore a pose from `getView`, of this or another viewer. */
19
+ /** Restore a view from `getView`, of this or another viewer. */
21
20
  setView(view: ViewState): void;
22
21
  /** Back to the standard orientation, fitted to the viewport. */
23
22
  resetView(): void;
24
- /** Refit to the element's size; call after layout changes the viewer's box. */
23
+ /** Fit the canvas to the container again; the viewer does this itself when the container resizes. */
25
24
  resize(): void;
26
25
  /** Draw a frame now. */
27
26
  render(): void;
28
- /** Called after the user moves the camera. Returns the unsubscribe function. */
27
+ /** Call `listener` when the user rotates or zooms. Returns a function that removes it. */
29
28
  onInteraction(listener: () => void): () => void;
30
- /** Take the viewer out of its container and release its WebGL resources. */
29
+ /** Remove the viewer from its container and free its WebGL resources. */
31
30
  dispose(): void;
32
31
  }
33
32
  /**
34
- * Mount a crystal viewer in `container`. The viewer fills the container and
35
- * follows its size, so the container needs a height of its own. The call
36
- * gives the container the class `bravais-viewer` and adds, once per
37
- * document, a `<style id="bravais-styles">` for the overlays.
33
+ * Create a viewer inside `container`. It fills the container and follows
34
+ * its size, so give the container a height. Adds the class `bravais-viewer`
35
+ * to the container and one small stylesheet to the page.
38
36
  */
39
37
  export declare function createViewer(container: HTMLElement, options?: ViewerOptions): Viewer;
@@ -23,26 +23,24 @@ export interface StructureScene {
23
23
  /** Elements present, in order of first appearance, deuterium as hydrogen. */
24
24
  elements: string[];
25
25
  }
26
- /** One structure drawn in a viewer; several overlay, each with its own opacity. */
26
+ /** One structure to draw. A viewer can overlay several, each with its own opacity. */
27
27
  export interface SceneLayer {
28
28
  scene: StructureScene;
29
29
  /**
30
- * 1 draws the layer solid; a lower value draws it translucent over the
31
- * others; 0 draws nothing, yet the layer still frames the view, so a viewer
32
- * switching between two states of a structure can keep one centre and
33
- * scale. Default 1.
30
+ * From 0 to 1; default 1. Below 1 the layer is drawn see-through over the
31
+ * others. At 0 it is not drawn but still counts when fitting the view, so
32
+ * switching between two versions of a structure keeps the same framing.
34
33
  */
35
34
  opacity?: number;
36
35
  }
37
36
  export interface BuildSceneOptions {
38
- /** Draw image atoms: boundary sites repeated on the opposite faces, edges and corners. Default true. */
37
+ /** Repeat atoms on the cell's faces, edges and corners on the opposite side too. Default true. */
39
38
  imageAtoms?: boolean;
40
39
  }
41
40
  /** Every chemical element on any site, in order of first appearance. */
42
41
  export declare function structureElements(structure: Structure): string[];
43
42
  /**
44
- * Atoms, bonds and cell of a structure as the renderer draws them. The sites
45
- * are drawn as listed and `operations` are not applied: pass
46
- * `expandStructure(structure)` to draw the full cell.
43
+ * Prepare a structure for drawing: its atoms, bonds and cell. Sites are
44
+ * drawn as listed; pass `expandStructure(structure)` to draw the whole cell.
47
45
  */
48
46
  export declare function buildScene(structure: Structure, options?: BuildSceneOptions): StructureScene;
@@ -1,6 +1,7 @@
1
1
  import { type Structure } from "./types.js";
2
2
  /**
3
- * Apply every operation to every site and keep the distinct positions: the
4
- * full cell as an explicit list of sites (P1).
3
+ * Fill the unit cell: apply every symmetry operation to every site and keep
4
+ * each distinct position once. The result lists every atom, with the
5
+ * identity as its only operation.
5
6
  */
6
7
  export declare function expandStructure(structure: Structure): Structure;
@@ -1,10 +1,10 @@
1
1
  import type { Lattice, LatticeParameters, Mat3, Vec3 } from "./types.js";
2
2
  /**
3
- * Cartesian row vectors for cell parameters, in the convention pymatgen uses
4
- * by default: c along z and a in the xz plane.
3
+ * A lattice from cell lengths in ångström and angles in degrees. The c axis
4
+ * points along z and a lies in the xz plane, as in pymatgen.
5
5
  */
6
6
  export declare function latticeFromParameters(parameters: LatticeParameters): Lattice;
7
- /** Cell parameters of three Cartesian row vectors. */
7
+ /** A lattice from its three cell vectors, in ångström. */
8
8
  export declare function latticeFromVectors(vectors: Mat3): Lattice;
9
9
  export declare function fractionalToCartesian(lattice: Lattice, fractional: Vec3): Vec3;
10
10
  export declare function distance(p: Vec3, q: Vec3): number;
@@ -35,9 +35,7 @@ export interface SymmetryDataset {
35
35
  standard: Structure;
36
36
  }
37
37
  /**
38
- * Analyse the symmetry of what a structure actually contains. The structure
39
- * is expanded to every atom in its cell and handed to moyo, which finds the
40
- * space group from the atoms alone, so the result does not depend on how,
41
- * or whether, the file named it.
38
+ * Find the space group of a structure from its atoms alone, whatever the
39
+ * file says. See `SymmetryDataset` for what the result holds.
42
40
  */
43
41
  export declare function symmetryDataset(structure: Structure, options?: SymmetryOptions): Promise<SymmetryDataset>;
@@ -4,10 +4,8 @@ export declare class SpaceGroupLookupError extends Error {
4
4
  constructor(message: string);
5
5
  }
6
6
  /**
7
- * Load the bundled moyo WebAssembly module, once. It is a separate file of
8
- * the package that nothing loads until a structure needs it. Every function
9
- * that needs moyo calls this itself, so calling it is only a way to pay the
10
- * start-up cost early. A failed load is not cached: the next call tries
7
+ * Load moyo, the symmetry library, ahead of first use. This is optional:
8
+ * everything that needs moyo loads it. If loading fails, the next call tries
11
9
  * again.
12
10
  */
13
11
  export declare function ensureMoyo(): Promise<void>;
@@ -47,9 +45,9 @@ export interface OperationSetting {
47
45
  */
48
46
  export declare function operationSettings(info: SpaceGroupInfo): Promise<OperationSetting[]>;
49
47
  /**
50
- * The operations of a space group named by Hall symbol, Hermann-Mauguin
51
- * symbol or number: those of the setting a suffix such as `:H` selects,
52
- * otherwise of the standard setting. Throws `SpaceGroupLookupError` when
53
- * the table has no such group.
48
+ * The symmetry operations of a space group given by Hall symbol,
49
+ * Hermann-Mauguin symbol or number, in the setting a suffix such as `:H`
50
+ * names, or else the standard setting. Throws `SpaceGroupLookupError` for
51
+ * an unknown group.
54
52
  */
55
53
  export declare function operationsForSpaceGroup(info: SpaceGroupInfo): Promise<SymmetryOperation[]>;
@@ -1,10 +1,8 @@
1
1
  /**
2
- * A Hermann-Mauguin symbol the way textbooks print it: no spaces, screw
3
- * axes with subscripts and rotoinversion axes with a bar, so `F m -3 m`
4
- * becomes Fm3̅m and `P 2_1/c` becomes P2₁/c. The ASCII forms of moyo and
5
- * spglib (`2_1`) and of CIF files (`21`, the digits run together) are both
6
- * read. A setting suffix such as `:H` is kept after a space. A symbol
7
- * written without spaces is only given bars and underscore subscripts,
8
- * since `F432` cannot be told from a screw axis without them.
2
+ * Write a space-group symbol the way textbooks print it: `F m -3 m` becomes
3
+ * Fm3̅m and `P 2_1/c` becomes P2₁/c. A setting suffix such as `:H` is kept.
4
+ * A screw axis written as two digits, as CIF files do (`P 1 21/c 1`), is
5
+ * recognised only when the symbol has spaces, since in `F432` the digits
6
+ * are separate axes.
9
7
  */
10
8
  export declare function typesetSymbol(symbol: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bravais",
3
- "version": "0.1.3",
4
- "description": "Crystal structure viewer: reads CIFs, applies their symmetry, repeats boundary sites, finds bonds with VESTA's cutoffs and renders with three.js.",
3
+ "version": "0.1.4",
4
+ "description": "A minimal crystal structure viewer for the web: reads CIF files and draws them with three.js.",
5
5
  "license": "MIT",
6
6
  "author": "Jiacheng Wang",
7
7
  "repository": {
@@ -30,7 +30,6 @@
30
30
  "exports": {
31
31
  ".": {
32
32
  "types": "./dist/types/index.d.ts",
33
- "import": "./dist/bravais.js",
34
33
  "default": "./dist/bravais.js"
35
34
  },
36
35
  "./package.json": "./package.json"