react-cheminfo 0.135.0 → 0.136.0
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.
- package/lib/crystal/core/cellAtoms.d.ts +43 -0
- package/lib/crystal/core/cellAtoms.d.ts.map +1 -0
- package/lib/crystal/core/cellAtoms.js +70 -0
- package/lib/crystal/core/cellAtoms.js.map +1 -0
- package/lib/crystal/core/index.d.ts +2 -0
- package/lib/crystal/core/index.d.ts.map +1 -1
- package/lib/crystal/core/index.js +1 -0
- package/lib/crystal/core/index.js.map +1 -1
- package/lib/crystal/core/molecules.d.ts.map +1 -1
- package/lib/crystal/core/molecules.js +6 -40
- package/lib/crystal/core/molecules.js.map +1 -1
- package/lib/crystal3d/core/cellClip.d.ts +46 -0
- package/lib/crystal3d/core/cellClip.d.ts.map +1 -0
- package/lib/crystal3d/core/cellClip.js +198 -0
- package/lib/crystal3d/core/cellClip.js.map +1 -0
- package/lib/crystal3d/core/cellGeometry.d.ts +63 -0
- package/lib/crystal3d/core/cellGeometry.d.ts.map +1 -0
- package/lib/crystal3d/core/cellGeometry.js +153 -0
- package/lib/crystal3d/core/cellGeometry.js.map +1 -0
- package/lib/crystal3d/core/cellStack.d.ts +51 -0
- package/lib/crystal3d/core/cellStack.d.ts.map +1 -0
- package/lib/crystal3d/core/cellStack.js +79 -0
- package/lib/crystal3d/core/cellStack.js.map +1 -0
- package/lib/crystal3d/core/crystalView.d.ts +71 -0
- package/lib/crystal3d/core/crystalView.d.ts.map +1 -0
- package/lib/crystal3d/core/crystalView.js +48 -0
- package/lib/crystal3d/core/crystalView.js.map +1 -0
- package/lib/crystal3d/core/drawingSet.d.ts +31 -0
- package/lib/crystal3d/core/drawingSet.d.ts.map +1 -0
- package/lib/crystal3d/core/drawingSet.js +63 -0
- package/lib/crystal3d/core/drawingSet.js.map +1 -0
- package/lib/crystal3d/core/elementDrawing.d.ts +50 -0
- package/lib/crystal3d/core/elementDrawing.d.ts.map +1 -0
- package/lib/crystal3d/core/elementDrawing.js +100 -0
- package/lib/crystal3d/core/elementDrawing.js.map +1 -0
- package/lib/crystal3d/core/elementExtent.d.ts +42 -0
- package/lib/crystal3d/core/elementExtent.d.ts.map +1 -0
- package/lib/crystal3d/core/elementExtent.js +56 -0
- package/lib/crystal3d/core/elementExtent.js.map +1 -0
- package/lib/crystal3d/core/elementLabels.d.ts +31 -0
- package/lib/crystal3d/core/elementLabels.d.ts.map +1 -0
- package/lib/crystal3d/core/elementLabels.js +99 -0
- package/lib/crystal3d/core/elementLabels.js.map +1 -0
- package/lib/crystal3d/core/elementShapes.d.ts +43 -0
- package/lib/crystal3d/core/elementShapes.d.ts.map +1 -0
- package/lib/crystal3d/core/elementShapes.js +115 -0
- package/lib/crystal3d/core/elementShapes.js.map +1 -0
- package/lib/crystal3d/core/frame.d.ts +36 -0
- package/lib/crystal3d/core/frame.d.ts.map +1 -0
- package/lib/crystal3d/core/frame.js +35 -0
- package/lib/crystal3d/core/frame.js.map +1 -0
- package/lib/crystal3d/core/framing.d.ts +41 -0
- package/lib/crystal3d/core/framing.d.ts.map +1 -0
- package/lib/crystal3d/core/framing.js +79 -0
- package/lib/crystal3d/core/framing.js.map +1 -0
- package/lib/crystal3d/core/index.d.ts +42 -0
- package/lib/crystal3d/core/index.d.ts.map +1 -0
- package/lib/crystal3d/core/index.js +29 -0
- package/lib/crystal3d/core/index.js.map +1 -0
- package/lib/crystal3d/core/labelText.d.ts +19 -0
- package/lib/crystal3d/core/labelText.d.ts.map +1 -0
- package/lib/crystal3d/core/labelText.js +42 -0
- package/lib/crystal3d/core/labelText.js.map +1 -0
- package/lib/crystal3d/core/latticeBasis.d.ts +49 -0
- package/lib/crystal3d/core/latticeBasis.d.ts.map +1 -0
- package/lib/crystal3d/core/latticeBasis.js +89 -0
- package/lib/crystal3d/core/latticeBasis.js.map +1 -0
- package/lib/crystal3d/core/mat3.d.ts +68 -0
- package/lib/crystal3d/core/mat3.d.ts.map +1 -0
- package/lib/crystal3d/core/mat3.js +146 -0
- package/lib/crystal3d/core/mat3.js.map +1 -0
- package/lib/crystal3d/core/operationMatrix.d.ts +44 -0
- package/lib/crystal3d/core/operationMatrix.d.ts.map +1 -0
- package/lib/crystal3d/core/operationMatrix.js +172 -0
- package/lib/crystal3d/core/operationMatrix.js.map +1 -0
- package/lib/crystal3d/core/orientation.d.ts +62 -0
- package/lib/crystal3d/core/orientation.d.ts.map +1 -0
- package/lib/crystal3d/core/orientation.js +166 -0
- package/lib/crystal3d/core/orientation.js.map +1 -0
- package/lib/crystal3d/core/palette.d.ts +24 -0
- package/lib/crystal3d/core/palette.d.ts.map +1 -0
- package/lib/crystal3d/core/palette.js +34 -0
- package/lib/crystal3d/core/palette.js.map +1 -0
- package/lib/crystal3d/core/primitives.d.ts +133 -0
- package/lib/crystal3d/core/primitives.d.ts.map +1 -0
- package/lib/crystal3d/core/primitives.js +80 -0
- package/lib/crystal3d/core/primitives.js.map +1 -0
- package/lib/crystal3d/core/structureText.d.ts +20 -0
- package/lib/crystal3d/core/structureText.d.ts.map +1 -0
- package/lib/crystal3d/core/structureText.js +37 -0
- package/lib/crystal3d/core/structureText.js.map +1 -0
- package/lib/crystal3d/core/supercell.d.ts +20 -0
- package/lib/crystal3d/core/supercell.d.ts.map +1 -0
- package/lib/crystal3d/core/supercell.js +35 -0
- package/lib/crystal3d/core/supercell.js.map +1 -0
- package/lib/crystal3d/core/types.d.ts +166 -0
- package/lib/crystal3d/core/types.d.ts.map +1 -0
- package/lib/crystal3d/core/types.js +10 -0
- package/lib/crystal3d/core/types.js.map +1 -0
- package/lib/crystal3d/core/vec3.d.ts +75 -0
- package/lib/crystal3d/core/vec3.d.ts.map +1 -0
- package/lib/crystal3d/core/vec3.js +119 -0
- package/lib/crystal3d/core/vec3.js.map +1 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.d.ts +52 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.js +242 -0
- package/lib/crystal3d/ui/CrystalCanvas3D.js.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureView.d.ts +17 -0
- package/lib/crystal3d/ui/CrystalStructureView.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureView.js +76 -0
- package/lib/crystal3d/ui/CrystalStructureView.js.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.d.ts +22 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.js +29 -0
- package/lib/crystal3d/ui/CrystalStructureViewer.js.map +1 -0
- package/lib/crystal3d/ui/CrystalViewControls.d.ts +25 -0
- package/lib/crystal3d/ui/CrystalViewControls.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalViewControls.js +22 -0
- package/lib/crystal3d/ui/CrystalViewControls.js.map +1 -0
- package/lib/crystal3d/ui/CrystalViewer3D.d.ts +72 -0
- package/lib/crystal3d/ui/CrystalViewer3D.d.ts.map +1 -0
- package/lib/crystal3d/ui/CrystalViewer3D.js +70 -0
- package/lib/crystal3d/ui/CrystalViewer3D.js.map +1 -0
- package/lib/crystal3d/ui/crystalScene.d.ts +91 -0
- package/lib/crystal3d/ui/crystalScene.d.ts.map +1 -0
- package/lib/crystal3d/ui/crystalScene.js +10 -0
- package/lib/crystal3d/ui/crystalScene.js.map +1 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts +52 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts.map +1 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.js +2 -0
- package/lib/crystal3d/ui/crystalStructureViewerProps.js.map +1 -0
- package/lib/crystal3d/ui/index.d.ts +16 -0
- package/lib/crystal3d/ui/index.d.ts.map +1 -0
- package/lib/crystal3d/ui/index.js +12 -0
- package/lib/crystal3d/ui/index.js.map +1 -0
- package/lib/crystal3d/ui/useCrystalCaption.d.ts +14 -0
- package/lib/crystal3d/ui/useCrystalCaption.d.ts.map +1 -0
- package/lib/crystal3d/ui/useCrystalCaption.js +32 -0
- package/lib/crystal3d/ui/useCrystalCaption.js.map +1 -0
- package/lib/crystal3d/viewer/animate.d.ts +49 -0
- package/lib/crystal3d/viewer/animate.d.ts.map +1 -0
- package/lib/crystal3d/viewer/animate.js +83 -0
- package/lib/crystal3d/viewer/animate.js.map +1 -0
- package/lib/crystal3d/viewer/camera.d.ts +44 -0
- package/lib/crystal3d/viewer/camera.d.ts.map +1 -0
- package/lib/crystal3d/viewer/camera.js +103 -0
- package/lib/crystal3d/viewer/camera.js.map +1 -0
- package/lib/crystal3d/viewer/index.d.ts +13 -0
- package/lib/crystal3d/viewer/index.d.ts.map +1 -0
- package/lib/crystal3d/viewer/index.js +8 -0
- package/lib/crystal3d/viewer/index.js.map +1 -0
- package/lib/crystal3d/viewer/layerRegistry.d.ts +24 -0
- package/lib/crystal3d/viewer/layerRegistry.d.ts.map +1 -0
- package/lib/crystal3d/viewer/layerRegistry.js +39 -0
- package/lib/crystal3d/viewer/layerRegistry.js.map +1 -0
- package/lib/crystal3d/viewer/meshPrimitives.d.ts +13 -0
- package/lib/crystal3d/viewer/meshPrimitives.d.ts.map +1 -0
- package/lib/crystal3d/viewer/meshPrimitives.js +76 -0
- package/lib/crystal3d/viewer/meshPrimitives.js.map +1 -0
- package/lib/crystal3d/viewer/plugin.d.ts +133 -0
- package/lib/crystal3d/viewer/plugin.d.ts.map +1 -0
- package/lib/crystal3d/viewer/plugin.js +181 -0
- package/lib/crystal3d/viewer/plugin.js.map +1 -0
- package/lib/crystal3d/viewer/renderCell.d.ts +43 -0
- package/lib/crystal3d/viewer/renderCell.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderCell.js +53 -0
- package/lib/crystal3d/viewer/renderCell.js.map +1 -0
- package/lib/crystal3d/viewer/renderElements.d.ts +54 -0
- package/lib/crystal3d/viewer/renderElements.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderElements.js +77 -0
- package/lib/crystal3d/viewer/renderElements.js.map +1 -0
- package/lib/crystal3d/viewer/renderStructure.d.ts +55 -0
- package/lib/crystal3d/viewer/renderStructure.d.ts.map +1 -0
- package/lib/crystal3d/viewer/renderStructure.js +103 -0
- package/lib/crystal3d/viewer/renderStructure.js.map +1 -0
- package/lib/crystal3d/viewer/sceneParts.d.ts +32 -0
- package/lib/crystal3d/viewer/sceneParts.d.ts.map +1 -0
- package/lib/crystal3d/viewer/sceneParts.js +77 -0
- package/lib/crystal3d/viewer/sceneParts.js.map +1 -0
- package/lib/crystal3d/viewer/shapeLayer.d.ts +41 -0
- package/lib/crystal3d/viewer/shapeLayer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/shapeLayer.js +57 -0
- package/lib/crystal3d/viewer/shapeLayer.js.map +1 -0
- package/lib/crystal3d/viewer/textLayer.d.ts +21 -0
- package/lib/crystal3d/viewer/textLayer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/textLayer.js +59 -0
- package/lib/crystal3d/viewer/textLayer.js.map +1 -0
- package/lib/crystal3d/viewer/viewer.d.ts +110 -0
- package/lib/crystal3d/viewer/viewer.d.ts.map +1 -0
- package/lib/crystal3d/viewer/viewer.js +157 -0
- package/lib/crystal3d/viewer/viewer.js.map +1 -0
- package/lib/crystal3d.d.ts +12 -0
- package/lib/crystal3d.d.ts.map +1 -0
- package/lib/crystal3d.js +12 -0
- package/lib/crystal3d.js.map +1 -0
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +19 -1
- package/lib/locales/en.json +19 -1
- package/lib/locales/es.json +19 -1
- package/lib/locales/fr.json +19 -1
- package/lib/locales/it.json +19 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.d.ts.map +1 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.js +16 -27
- package/lib/molecule3d/ui/MoleculeCanvas3D.js.map +1 -1
- package/lib/molstar/bonds/bondRule.d.ts +16 -0
- package/lib/molstar/bonds/bondRule.d.ts.map +1 -0
- package/lib/molstar/bonds/bondRule.js +23 -0
- package/lib/molstar/bonds/bondRule.js.map +1 -0
- package/lib/molstar/bonds/index.d.ts +9 -0
- package/lib/molstar/bonds/index.d.ts.map +1 -0
- package/lib/molstar/bonds/index.js +9 -0
- package/lib/molstar/bonds/index.js.map +1 -0
- package/lib/molstar/ui/MolstarToolbar.d.ts +47 -0
- package/lib/molstar/ui/MolstarToolbar.d.ts.map +1 -0
- package/lib/molstar/ui/MolstarToolbar.js +28 -0
- package/lib/molstar/ui/MolstarToolbar.js.map +1 -0
- package/lib/molstar/ui/index.d.ts +10 -0
- package/lib/molstar/ui/index.d.ts.map +1 -0
- package/lib/molstar/ui/index.js +8 -0
- package/lib/molstar/ui/index.js.map +1 -0
- package/lib/molstar/ui/useMolstarTools.d.ts +63 -0
- package/lib/molstar/ui/useMolstarTools.d.ts.map +1 -0
- package/lib/molstar/ui/useMolstarTools.js +36 -0
- package/lib/molstar/ui/useMolstarTools.js.map +1 -0
- package/package.json +2 -1
- package/src/crystal/core/cellAtoms.ts +106 -0
- package/src/crystal/core/index.ts +2 -0
- package/src/crystal/core/molecules.ts +7 -44
- package/src/crystal3d/core/cellClip.ts +229 -0
- package/src/crystal3d/core/cellGeometry.ts +193 -0
- package/src/crystal3d/core/cellStack.ts +87 -0
- package/src/crystal3d/core/crystalView.ts +114 -0
- package/src/crystal3d/core/drawingSet.ts +71 -0
- package/src/crystal3d/core/elementDrawing.ts +147 -0
- package/src/crystal3d/core/elementExtent.ts +81 -0
- package/src/crystal3d/core/elementLabels.ts +130 -0
- package/src/crystal3d/core/elementShapes.ts +141 -0
- package/src/crystal3d/core/frame.ts +56 -0
- package/src/crystal3d/core/framing.ts +101 -0
- package/src/crystal3d/core/index.ts +132 -0
- package/src/crystal3d/core/labelText.ts +44 -0
- package/src/crystal3d/core/latticeBasis.ts +110 -0
- package/src/crystal3d/core/mat3.ts +163 -0
- package/src/crystal3d/core/operationMatrix.ts +255 -0
- package/src/crystal3d/core/orientation.ts +229 -0
- package/src/crystal3d/core/palette.ts +43 -0
- package/src/crystal3d/core/primitives.ts +183 -0
- package/src/crystal3d/core/structureText.ts +43 -0
- package/src/crystal3d/core/supercell.ts +40 -0
- package/src/crystal3d/core/types.ts +186 -0
- package/src/crystal3d/core/vec3.ts +127 -0
- package/src/crystal3d/ui/CrystalCanvas3D.tsx +384 -0
- package/src/crystal3d/ui/CrystalStructureView.tsx +148 -0
- package/src/crystal3d/ui/CrystalStructureViewer.tsx +39 -0
- package/src/crystal3d/ui/CrystalViewControls.tsx +100 -0
- package/src/crystal3d/ui/CrystalViewer3D.tsx +183 -0
- package/src/crystal3d/ui/crystalScene.ts +100 -0
- package/src/crystal3d/ui/crystalStructureViewerProps.ts +54 -0
- package/src/crystal3d/ui/index.ts +20 -0
- package/src/crystal3d/ui/useCrystalCaption.ts +38 -0
- package/src/crystal3d/viewer/animate.ts +113 -0
- package/src/crystal3d/viewer/camera.ts +139 -0
- package/src/crystal3d/viewer/index.ts +13 -0
- package/src/crystal3d/viewer/layerRegistry.ts +47 -0
- package/src/crystal3d/viewer/meshPrimitives.ts +102 -0
- package/src/crystal3d/viewer/plugin.ts +258 -0
- package/src/crystal3d/viewer/renderCell.ts +98 -0
- package/src/crystal3d/viewer/renderElements.ts +121 -0
- package/src/crystal3d/viewer/renderStructure.ts +144 -0
- package/src/crystal3d/viewer/sceneParts.ts +119 -0
- package/src/crystal3d/viewer/shapeLayer.ts +108 -0
- package/src/crystal3d/viewer/textLayer.ts +85 -0
- package/src/crystal3d/viewer/viewer.ts +207 -0
- package/src/crystal3d.ts +12 -0
- package/src/locales/de.json +19 -1
- package/src/locales/en.json +19 -1
- package/src/locales/es.json +19 -1
- package/src/locales/fr.json +19 -1
- package/src/locales/it.json +19 -1
- package/src/molecule3d/ui/MoleculeCanvas3D.tsx +45 -71
- package/src/molstar/bonds/bondRule.ts +34 -0
- package/src/molstar/bonds/index.ts +9 -0
- package/src/molstar/ui/MolstarToolbar.tsx +103 -0
- package/src/molstar/ui/index.ts +14 -0
- package/src/molstar/ui/useMolstarTools.ts +98 -0
- package/styles/chrome.css +90 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The atoms on screen.
|
|
3
|
+
*
|
|
4
|
+
* They arrive already expanded and already repeated over the lattice, as
|
|
5
|
+
* Cartesian ångström, and go in as XYZ — the one format that carries elements
|
|
6
|
+
* and coordinates and invites molstar to apply nothing of its own.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Structure } from 'molstar/lib/mol-model/structure.js';
|
|
10
|
+
import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
11
|
+
import { PluginStateObject } from 'molstar/lib/mol-plugin-state/objects.js';
|
|
12
|
+
import type { Representation } from 'molstar/lib/mol-repr/representation.js';
|
|
13
|
+
|
|
14
|
+
import { toXyzText } from '../core/structureText.ts';
|
|
15
|
+
import type { ViewerAtom } from '../core/types.ts';
|
|
16
|
+
|
|
17
|
+
/** How the atoms are drawn. */
|
|
18
|
+
export interface StructureStyle {
|
|
19
|
+
/**
|
|
20
|
+
* Balls and sticks, or space-filling spheres.
|
|
21
|
+
* @default 'ball-and-stick'
|
|
22
|
+
*/
|
|
23
|
+
representation?: 'ball-and-stick' | 'spacefill';
|
|
24
|
+
/**
|
|
25
|
+
* Ball and stick radius multiplier. A handful of atoms reads better slightly
|
|
26
|
+
* thinner than molstar's protein-oriented default.
|
|
27
|
+
* @default 0.25
|
|
28
|
+
*/
|
|
29
|
+
sizeFactor?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Replace the atoms on screen.
|
|
34
|
+
* @param plugin - The molstar context.
|
|
35
|
+
* @param atoms - The whole scene, Cartesian ångström; an empty list clears it.
|
|
36
|
+
* @param style - See {@link StructureStyle}.
|
|
37
|
+
* @throws {Error} When molstar parses the file to no atoms at all.
|
|
38
|
+
*/
|
|
39
|
+
export async function renderStructure(
|
|
40
|
+
plugin: PluginContext,
|
|
41
|
+
atoms: readonly ViewerAtom[],
|
|
42
|
+
style: StructureStyle = {},
|
|
43
|
+
): Promise<void> {
|
|
44
|
+
await clearStructure(plugin);
|
|
45
|
+
if (atoms.length === 0) return;
|
|
46
|
+
const { representation = 'ball-and-stick', sizeFactor = 0.25 } = style;
|
|
47
|
+
|
|
48
|
+
const data = await plugin.builders.data.rawData(
|
|
49
|
+
{ data: toXyzText(atoms) },
|
|
50
|
+
{ ref: STRUCTURE_DATA_REF, state: { isGhost: true } },
|
|
51
|
+
);
|
|
52
|
+
const trajectory = await plugin.builders.structure.parseTrajectory(
|
|
53
|
+
data,
|
|
54
|
+
'xyz',
|
|
55
|
+
);
|
|
56
|
+
const model = await plugin.builders.structure.createModel(trajectory);
|
|
57
|
+
if ((model.data?.atomicHierarchy.atoms._rowCount ?? 0) !== atoms.length) {
|
|
58
|
+
await clearStructure(plugin);
|
|
59
|
+
throw new Error(
|
|
60
|
+
`molstar read ${model.data?.atomicHierarchy.atoms._rowCount ?? 0} of the ${atoms.length} atoms it was given.`,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const structure = await plugin.builders.structure.createStructure(model);
|
|
64
|
+
structureRefs.set(plugin, structure.ref);
|
|
65
|
+
const drawn =
|
|
66
|
+
await plugin.builders.structure.representation.addRepresentation(
|
|
67
|
+
structure,
|
|
68
|
+
representation === 'spacefill'
|
|
69
|
+
? {
|
|
70
|
+
type: 'spacefill',
|
|
71
|
+
typeParams: { sizeFactor: 1 },
|
|
72
|
+
color: 'element-symbol',
|
|
73
|
+
}
|
|
74
|
+
: {
|
|
75
|
+
type: 'ball-and-stick',
|
|
76
|
+
// A benzene drawn with molstar's dashed aromatic bond already shows
|
|
77
|
+
// the π cloud, which is a different lesson from the one here.
|
|
78
|
+
typeParams: {
|
|
79
|
+
sizeFactor,
|
|
80
|
+
sizeAspectRatio: 2 / 3,
|
|
81
|
+
aromaticBonds: false,
|
|
82
|
+
},
|
|
83
|
+
color: 'element-symbol',
|
|
84
|
+
colorParams: {
|
|
85
|
+
carbonColor: { name: 'element-symbol', params: {} },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
representationRefs.set(plugin, drawn.ref);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Remove the atoms, leaving every drawn layer in place.
|
|
94
|
+
* @param plugin - The molstar context.
|
|
95
|
+
*/
|
|
96
|
+
export async function clearStructure(plugin: PluginContext): Promise<void> {
|
|
97
|
+
representationRefs.delete(plugin);
|
|
98
|
+
structureRefs.delete(plugin);
|
|
99
|
+
if (!plugin.state.data.cells.has(STRUCTURE_DATA_REF)) return;
|
|
100
|
+
await plugin.build().delete(STRUCTURE_DATA_REF).commit();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The representation the atoms are drawn by, which is what an operation moves.
|
|
105
|
+
*
|
|
106
|
+
* It is resolved from the state tree rather than kept, because a rebuild
|
|
107
|
+
* replaces the object behind the same address.
|
|
108
|
+
* @param plugin - The molstar context.
|
|
109
|
+
* @returns The representation, or `undefined` when nothing is drawn.
|
|
110
|
+
*/
|
|
111
|
+
export function structureRepresentation(
|
|
112
|
+
plugin: PluginContext,
|
|
113
|
+
): Representation.Any | undefined {
|
|
114
|
+
const ref = representationRefs.get(plugin);
|
|
115
|
+
if (ref === undefined) return undefined;
|
|
116
|
+
const object = plugin.state.data.cells.get(ref)?.obj;
|
|
117
|
+
if (!PluginStateObject.Molecule.Structure.Representation3D.is(object)) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
return object.data.repr;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The structure the atoms on screen were built into, which is what a
|
|
125
|
+
* measurement names its atoms in.
|
|
126
|
+
* @param plugin - The molstar context.
|
|
127
|
+
* @returns The structure, or `undefined` when nothing is drawn.
|
|
128
|
+
*/
|
|
129
|
+
export function crystalStructure(plugin: PluginContext): Structure | undefined {
|
|
130
|
+
const ref = structureRefs.get(plugin);
|
|
131
|
+
if (ref === undefined) return undefined;
|
|
132
|
+
const object = plugin.state.data.cells.get(ref)?.obj;
|
|
133
|
+
if (!PluginStateObject.Molecule.Structure.is(object)) return undefined;
|
|
134
|
+
return object.data;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Deleting this ref deletes the model and the representation under it. */
|
|
138
|
+
const STRUCTURE_DATA_REF = 'crystal3d-structure-data';
|
|
139
|
+
|
|
140
|
+
/** Where the structure the atoms were built into sits, per plugin. */
|
|
141
|
+
const structureRefs = new WeakMap<PluginContext, string>();
|
|
142
|
+
|
|
143
|
+
/** Where the drawn representation sits in the state tree, per plugin. */
|
|
144
|
+
const representationRefs = new WeakMap<PluginContext, string>();
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drawing a part of the scene and telling the camera how far it reaches, in one
|
|
3
|
+
* call, so the two can never disagree.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
7
|
+
|
|
8
|
+
import { cellEdges } from '../core/cellGeometry.ts';
|
|
9
|
+
import type { ElementGroup } from '../core/elementDrawing.ts';
|
|
10
|
+
import {
|
|
11
|
+
boundingSphereOf,
|
|
12
|
+
primitivesExtent,
|
|
13
|
+
unionSpheres,
|
|
14
|
+
} from '../core/framing.ts';
|
|
15
|
+
import type { MeshPrimitive } from '../core/primitives.ts';
|
|
16
|
+
import type {
|
|
17
|
+
CellRepeat,
|
|
18
|
+
Point3,
|
|
19
|
+
SymmetryDrawing,
|
|
20
|
+
UnitCell,
|
|
21
|
+
ViewerAtom,
|
|
22
|
+
} from '../core/types.ts';
|
|
23
|
+
|
|
24
|
+
import { setSceneExtent } from './camera.ts';
|
|
25
|
+
import type { CellStyle } from './renderCell.ts';
|
|
26
|
+
import { renderUnitCell } from './renderCell.ts';
|
|
27
|
+
import type { ElementLayerStyle } from './renderElements.ts';
|
|
28
|
+
import { renderSymmetryElements } from './renderElements.ts';
|
|
29
|
+
import type { StructureStyle } from './renderStructure.ts';
|
|
30
|
+
import { renderStructure } from './renderStructure.ts';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Replace the atoms, and record how far they reach.
|
|
34
|
+
* @param plugin - The molstar context.
|
|
35
|
+
* @param atoms - The whole scene, Cartesian ångström.
|
|
36
|
+
* @param style - See {@link StructureStyle}.
|
|
37
|
+
*/
|
|
38
|
+
export async function drawStructure(
|
|
39
|
+
plugin: PluginContext,
|
|
40
|
+
atoms: readonly ViewerAtom[],
|
|
41
|
+
style?: StructureStyle,
|
|
42
|
+
): Promise<void> {
|
|
43
|
+
await renderStructure(plugin, atoms, style);
|
|
44
|
+
if (atoms.length === 0) {
|
|
45
|
+
setSceneExtent(plugin, 'atoms', null);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const positions: Point3[] = [];
|
|
49
|
+
for (const atom of atoms) positions.push(atom.position);
|
|
50
|
+
// The largest van der Waals radius an ordinary structure carries is about
|
|
51
|
+
// 2 Å, and the representation draws a ball of that times the size factor.
|
|
52
|
+
setSceneExtent(plugin, 'atoms', boundingSphereOf(positions, ATOM_PADDING));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Replace the cell, and record how far it reaches.
|
|
57
|
+
* @param plugin - The molstar context.
|
|
58
|
+
* @param cell - The six cell parameters, or `null` to draw none.
|
|
59
|
+
* @param repeat - Cells along a, b and c.
|
|
60
|
+
* @param style - See {@link CellStyle}.
|
|
61
|
+
*/
|
|
62
|
+
export async function drawCell(
|
|
63
|
+
plugin: PluginContext,
|
|
64
|
+
cell: UnitCell | null,
|
|
65
|
+
repeat: CellRepeat = [1, 1, 1],
|
|
66
|
+
style?: CellStyle,
|
|
67
|
+
): Promise<void> {
|
|
68
|
+
await renderUnitCell(plugin, cell, repeat, style);
|
|
69
|
+
if (cell === null) {
|
|
70
|
+
setSceneExtent(plugin, 'cell', null);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const corners: Point3[] = [];
|
|
74
|
+
for (const edge of cellEdges(cell, repeat)) {
|
|
75
|
+
corners.push(edge.start, edge.end);
|
|
76
|
+
}
|
|
77
|
+
setSceneExtent(plugin, 'cell', boundingSphereOf(corners));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Replace the symmetry elements, and record how far they reach.
|
|
82
|
+
* @param plugin - The molstar context.
|
|
83
|
+
* @param drawings - The elements.
|
|
84
|
+
* @param style - See {@link ElementLayerStyle}.
|
|
85
|
+
*/
|
|
86
|
+
export async function drawElements(
|
|
87
|
+
plugin: PluginContext,
|
|
88
|
+
drawings: readonly SymmetryDrawing[],
|
|
89
|
+
style?: ElementLayerStyle,
|
|
90
|
+
): Promise<void> {
|
|
91
|
+
const groups: ElementGroup[] = await renderSymmetryElements(
|
|
92
|
+
plugin,
|
|
93
|
+
drawings,
|
|
94
|
+
style,
|
|
95
|
+
);
|
|
96
|
+
if (groups.length === 0) {
|
|
97
|
+
setSceneExtent(plugin, 'elements', null);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const primitives: MeshPrimitive[] = [];
|
|
101
|
+
// A name sits past the end of the element it names, so the elements reach
|
|
102
|
+
// further than their shapes do and framing the shapes alone cuts the names
|
|
103
|
+
// off at the edge of the canvas.
|
|
104
|
+
const names: Point3[] = [];
|
|
105
|
+
for (const group of groups) {
|
|
106
|
+
primitives.push(...group.primitives);
|
|
107
|
+
for (const item of group.labels) names.push(item.position);
|
|
108
|
+
}
|
|
109
|
+
const shapes = primitivesExtent(primitives);
|
|
110
|
+
setSceneExtent(
|
|
111
|
+
plugin,
|
|
112
|
+
'elements',
|
|
113
|
+
names.length === 0
|
|
114
|
+
? shapes
|
|
115
|
+
: unionSpheres([shapes, boundingSphereOf(names)]),
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const ATOM_PADDING = 0.5;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A layer of shapes: one mesh with one group per item, so every item picks up
|
|
3
|
+
* its own colour and its own hover label while the whole layer is added and
|
|
4
|
+
* removed in one call.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { MeshBuilder } from 'molstar/lib/mol-geo/geometry/mesh/mesh-builder.js';
|
|
8
|
+
import { Mesh } from 'molstar/lib/mol-geo/geometry/mesh/mesh.js';
|
|
9
|
+
import { Shape } from 'molstar/lib/mol-model/shape.js';
|
|
10
|
+
import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
11
|
+
// Lowercased on import: it is a factory, not a constructor.
|
|
12
|
+
import { ShapeRepresentation as createShapeRepresentation } from 'molstar/lib/mol-repr/shape/representation.js';
|
|
13
|
+
import { Color } from 'molstar/lib/mol-util/color/color.js';
|
|
14
|
+
|
|
15
|
+
import type { MeshPrimitive } from '../core/primitives.ts';
|
|
16
|
+
|
|
17
|
+
import { clearShapeLayer, storeLayer } from './layerRegistry.ts';
|
|
18
|
+
import { addMeshPrimitive } from './meshPrimitives.ts';
|
|
19
|
+
|
|
20
|
+
/** One pickable, labelled item of a layer. */
|
|
21
|
+
export interface ShapeGroup {
|
|
22
|
+
/** What the pointer reads. */
|
|
23
|
+
readonly label: string;
|
|
24
|
+
/** `#rrggbb`. */
|
|
25
|
+
readonly colour: string;
|
|
26
|
+
/** Its shapes. */
|
|
27
|
+
readonly primitives: readonly MeshPrimitive[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** How solid a layer looks. */
|
|
31
|
+
export interface ShapeLayerStyle {
|
|
32
|
+
/**
|
|
33
|
+
* Opacity.
|
|
34
|
+
* @default 1
|
|
35
|
+
*/
|
|
36
|
+
alpha?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Draw it flat, so a square reads as one even surface whatever angle it is
|
|
39
|
+
* seen from.
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
ignoreLight?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Replace a layer of shapes.
|
|
47
|
+
* @param plugin - The molstar context.
|
|
48
|
+
* @param key - Which layer; a second call with the same key replaces it.
|
|
49
|
+
* @param name - What the layer is called in a picking label.
|
|
50
|
+
* @param groups - The items; an empty list clears the layer.
|
|
51
|
+
* @param style - See {@link ShapeLayerStyle}.
|
|
52
|
+
* @throws {Error} When the canvas is not initialised yet.
|
|
53
|
+
*/
|
|
54
|
+
export async function renderShapeLayer(
|
|
55
|
+
plugin: PluginContext,
|
|
56
|
+
key: string,
|
|
57
|
+
name: string,
|
|
58
|
+
groups: readonly ShapeGroup[],
|
|
59
|
+
style: ShapeLayerStyle = {},
|
|
60
|
+
): Promise<void> {
|
|
61
|
+
const canvas3d = plugin.canvas3d;
|
|
62
|
+
if (canvas3d === undefined) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`renderShapeLayer: the molstar canvas is not ready (${key}).`,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
clearShapeLayer(plugin, key);
|
|
68
|
+
if (groups.length === 0) return;
|
|
69
|
+
|
|
70
|
+
const state = MeshBuilder.createState(4096, 2048);
|
|
71
|
+
const colours: Color[] = [];
|
|
72
|
+
const labels: string[] = [];
|
|
73
|
+
for (const group of groups) {
|
|
74
|
+
state.currentGroup = colours.length;
|
|
75
|
+
colours.push(Color.fromHexStyle(group.colour));
|
|
76
|
+
labels.push(group.label);
|
|
77
|
+
for (const primitive of group.primitives) {
|
|
78
|
+
addMeshPrimitive(state, primitive);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const mesh = MeshBuilder.getMesh(state);
|
|
82
|
+
Mesh.computeNormals(mesh);
|
|
83
|
+
const shape = Shape.create(
|
|
84
|
+
name,
|
|
85
|
+
{},
|
|
86
|
+
mesh,
|
|
87
|
+
(group: number) => colours[group] ?? BLACK,
|
|
88
|
+
() => 1,
|
|
89
|
+
(group: number) => labels[group] ?? name,
|
|
90
|
+
);
|
|
91
|
+
const representation = createShapeRepresentation(() => shape, Mesh.Utils);
|
|
92
|
+
await plugin.runTask(
|
|
93
|
+
representation.createOrUpdate(
|
|
94
|
+
{
|
|
95
|
+
alpha: style.alpha ?? 1,
|
|
96
|
+
doubleSided: true,
|
|
97
|
+
ignoreLight: style.ignoreLight ?? false,
|
|
98
|
+
},
|
|
99
|
+
shape,
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
storeLayer(plugin, key, representation);
|
|
103
|
+
canvas3d.add(representation);
|
|
104
|
+
// add() only queues; nothing appears until the queue is committed.
|
|
105
|
+
canvas3d.commit();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const BLACK = Color.fromHexStyle('#000000'); // tokens-ok: the fallback ink of a picking label.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A layer of text floating in the scene: an element's name, a cell's a, b and c.
|
|
3
|
+
*
|
|
4
|
+
* The text is written on a pale card rather than straight onto the scene: a
|
|
5
|
+
* name over a dark atom, or over three translucent planes, is otherwise read
|
|
6
|
+
* as part of them.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { TextBuilder } from 'molstar/lib/mol-geo/geometry/text/text-builder.js';
|
|
10
|
+
import { Text } from 'molstar/lib/mol-geo/geometry/text/text.js';
|
|
11
|
+
import { Shape } from 'molstar/lib/mol-model/shape.js';
|
|
12
|
+
import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
13
|
+
// Lowercased on import: it is a factory, not a constructor.
|
|
14
|
+
import { ShapeRepresentation as createShapeRepresentation } from 'molstar/lib/mol-repr/shape/representation.js';
|
|
15
|
+
import { Color } from 'molstar/lib/mol-util/color/color.js';
|
|
16
|
+
|
|
17
|
+
import { LABEL_CARD_COLOUR } from '../core/palette.ts';
|
|
18
|
+
import type { TextItem } from '../core/primitives.ts';
|
|
19
|
+
|
|
20
|
+
import { clearShapeLayer, storeLayer } from './layerRegistry.ts';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Replace a layer of floating text.
|
|
24
|
+
* @param plugin - The molstar context.
|
|
25
|
+
* @param key - Which layer; a second call with the same key replaces it.
|
|
26
|
+
* @param name - What the layer is called in a picking label.
|
|
27
|
+
* @param items - The lines; an empty list clears the layer.
|
|
28
|
+
* @param colour - What a line with no colour of its own is written in,
|
|
29
|
+
* `#rrggbb`.
|
|
30
|
+
* @throws {Error} When the canvas is not initialised yet.
|
|
31
|
+
*/
|
|
32
|
+
export async function renderTextLayer(
|
|
33
|
+
plugin: PluginContext,
|
|
34
|
+
key: string,
|
|
35
|
+
name: string,
|
|
36
|
+
items: readonly TextItem[],
|
|
37
|
+
colour: string,
|
|
38
|
+
): Promise<void> {
|
|
39
|
+
const canvas3d = plugin.canvas3d;
|
|
40
|
+
if (canvas3d === undefined) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`renderTextLayer: the molstar canvas is not ready (${key}).`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
clearShapeLayer(plugin, key);
|
|
46
|
+
if (items.length === 0) return;
|
|
47
|
+
|
|
48
|
+
const builder = TextBuilder.create({}, items.length * 4, items.length * 4);
|
|
49
|
+
const fallback = Color.fromHexStyle(colour);
|
|
50
|
+
const inks: Color[] = [];
|
|
51
|
+
for (let index = 0; index < items.length; index++) {
|
|
52
|
+
const item = items[index];
|
|
53
|
+
if (item === undefined) continue;
|
|
54
|
+
const [x, y, z] = item.position;
|
|
55
|
+
builder.add(item.text, x, y, z, item.size, item.size, index);
|
|
56
|
+
inks.push(
|
|
57
|
+
item.colour === undefined ? fallback : Color.fromHexStyle(item.colour),
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const shape = Shape.create(
|
|
61
|
+
name,
|
|
62
|
+
{},
|
|
63
|
+
builder.getText(),
|
|
64
|
+
(group: number) => inks[group] ?? fallback,
|
|
65
|
+
() => 1,
|
|
66
|
+
(group: number) => items[group]?.text ?? name,
|
|
67
|
+
);
|
|
68
|
+
const representation = createShapeRepresentation(() => shape, Text.Utils);
|
|
69
|
+
await plugin.runTask(
|
|
70
|
+
representation.createOrUpdate(
|
|
71
|
+
{
|
|
72
|
+
attachment: 'middle-center',
|
|
73
|
+
background: true,
|
|
74
|
+
backgroundMargin: 0.25,
|
|
75
|
+
backgroundColor: Color.fromHexStyle(LABEL_CARD_COLOUR),
|
|
76
|
+
backgroundOpacity: 0.85,
|
|
77
|
+
fontWeight: 'bold',
|
|
78
|
+
},
|
|
79
|
+
shape,
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
storeLayer(plugin, key, representation);
|
|
83
|
+
canvas3d.add(representation);
|
|
84
|
+
canvas3d.commit();
|
|
85
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The viewer a crystal page drives: a structure, a cell, a set of symmetry
|
|
3
|
+
* elements, and an operation applied to the first of them.
|
|
4
|
+
*
|
|
5
|
+
* Nothing here parses a space group or expands an orbit. The atoms arrive in
|
|
6
|
+
* their final places, because molstar's own expansion neither wraps into the
|
|
7
|
+
* cell nor deduplicates a special position, and falls back to `P 1` without a
|
|
8
|
+
* word on several common settings.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { clearMeasurements } from '../../molstar/core/index.ts';
|
|
12
|
+
import { mergeDrawings, withoutDrawings } from '../core/drawingSet.ts';
|
|
13
|
+
import type {
|
|
14
|
+
CellRepeat,
|
|
15
|
+
SymmetryDrawing,
|
|
16
|
+
UnitCell,
|
|
17
|
+
ViewerAtom,
|
|
18
|
+
ViewerOperation,
|
|
19
|
+
} from '../core/types.ts';
|
|
20
|
+
|
|
21
|
+
import type { PlayOptions } from './animate.ts';
|
|
22
|
+
import {
|
|
23
|
+
playOperation,
|
|
24
|
+
resetOperation,
|
|
25
|
+
setOperationFraction,
|
|
26
|
+
} from './animate.ts';
|
|
27
|
+
import type { CrystalViewerOptions } from './plugin.ts';
|
|
28
|
+
import { CrystalViewerPlugin } from './plugin.ts';
|
|
29
|
+
import type { CellStyle } from './renderCell.ts';
|
|
30
|
+
import type { ElementLayerStyle } from './renderElements.ts';
|
|
31
|
+
import type { StructureStyle } from './renderStructure.ts';
|
|
32
|
+
import { drawCell, drawElements, drawStructure } from './sceneParts.ts';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create a crystal viewer inside `container` and start initialising it.
|
|
36
|
+
* @param container - An element with `position: relative`; molstar inserts its
|
|
37
|
+
* own canvas into it.
|
|
38
|
+
* @param options - See {@link CrystalViewerOptions}.
|
|
39
|
+
* @returns A handle that is safe to dispose immediately.
|
|
40
|
+
*/
|
|
41
|
+
export function createCrystalViewer(
|
|
42
|
+
container: HTMLElement,
|
|
43
|
+
options: CrystalViewerOptions = {},
|
|
44
|
+
): CrystalViewer {
|
|
45
|
+
return new CrystalViewer(container, options);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Everything a crystal page draws, on one canvas: the lifecycle, the camera,
|
|
50
|
+
* the measurements and the hover readout come from {@link CrystalViewerPlugin},
|
|
51
|
+
* the scene is here.
|
|
52
|
+
*/
|
|
53
|
+
export class CrystalViewer extends CrystalViewerPlugin {
|
|
54
|
+
#drawings: readonly SymmetryDrawing[] = [];
|
|
55
|
+
#elementStyle: ElementLayerStyle = {};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The symmetry elements drawn right now, in drawing order.
|
|
59
|
+
* @returns The drawings on screen.
|
|
60
|
+
*/
|
|
61
|
+
get elements(): readonly SymmetryDrawing[] {
|
|
62
|
+
return this.#drawings;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Replace the atoms on screen.
|
|
67
|
+
* @param atoms - The whole scene, expanded and repeated already, in Cartesian
|
|
68
|
+
* ångström. An empty list clears them.
|
|
69
|
+
* @param style - See {@link StructureStyle}.
|
|
70
|
+
* @returns Resolves once the atoms are drawn.
|
|
71
|
+
*/
|
|
72
|
+
showStructure(
|
|
73
|
+
atoms: readonly ViewerAtom[],
|
|
74
|
+
style?: StructureStyle,
|
|
75
|
+
): Promise<void> {
|
|
76
|
+
// A measurement names atoms of the structure it was taken on.
|
|
77
|
+
return this.run(async (plugin) => {
|
|
78
|
+
await clearMeasurements(plugin);
|
|
79
|
+
await drawStructure(plugin, atoms, style);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Remove the atoms, leaving the cell and the elements in place.
|
|
85
|
+
* @returns Resolves once the atoms are gone.
|
|
86
|
+
*/
|
|
87
|
+
hideStructure(): Promise<void> {
|
|
88
|
+
return this.run(async (plugin) => {
|
|
89
|
+
await clearMeasurements(plugin);
|
|
90
|
+
await drawStructure(plugin, []);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Replace the unit cell box, and the stack of cells around it.
|
|
96
|
+
* @param cell - The six cell parameters, or `null` to draw none.
|
|
97
|
+
* @param repeat - Cells along a, b and c.
|
|
98
|
+
* @param style - See {@link CellStyle}.
|
|
99
|
+
* @returns Resolves once the cell is drawn.
|
|
100
|
+
*/
|
|
101
|
+
showCell(
|
|
102
|
+
cell: UnitCell | null,
|
|
103
|
+
repeat: CellRepeat = [1, 1, 1],
|
|
104
|
+
style?: CellStyle,
|
|
105
|
+
): Promise<void> {
|
|
106
|
+
return this.run((plugin) => drawCell(plugin, cell, repeat, style));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Remove the cell.
|
|
111
|
+
* @returns Resolves once the cell is gone.
|
|
112
|
+
*/
|
|
113
|
+
hideCell(): Promise<void> {
|
|
114
|
+
return this.run((plugin) => drawCell(plugin, null));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Replace every drawn symmetry element.
|
|
119
|
+
* @param drawings - The elements; an empty list clears them.
|
|
120
|
+
* @param style - See {@link ElementLayerStyle}; kept for later edits.
|
|
121
|
+
* @returns Resolves once the elements are drawn.
|
|
122
|
+
*/
|
|
123
|
+
showElements(
|
|
124
|
+
drawings: readonly SymmetryDrawing[],
|
|
125
|
+
style?: ElementLayerStyle,
|
|
126
|
+
): Promise<void> {
|
|
127
|
+
if (style !== undefined) this.#elementStyle = style;
|
|
128
|
+
this.#drawings = [...drawings];
|
|
129
|
+
return this.#redrawElements();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Draw these elements as well, replacing any already drawn under the same id.
|
|
134
|
+
* @param drawings - What to add.
|
|
135
|
+
* @returns Resolves once the elements are drawn.
|
|
136
|
+
*/
|
|
137
|
+
addElements(drawings: readonly SymmetryDrawing[]): Promise<void> {
|
|
138
|
+
this.#drawings = mergeDrawings(this.#drawings, drawings);
|
|
139
|
+
return this.#redrawElements();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Stop drawing these elements, leaving the rest alone.
|
|
144
|
+
* @param ids - The ids to remove; an id that is not drawn is ignored.
|
|
145
|
+
* @returns Resolves once the rest are redrawn.
|
|
146
|
+
*/
|
|
147
|
+
removeElements(ids: readonly string[]): Promise<void> {
|
|
148
|
+
this.#drawings = withoutDrawings(this.#drawings, ids);
|
|
149
|
+
return this.#redrawElements();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Remove every symmetry element.
|
|
154
|
+
* @returns Resolves once they are gone.
|
|
155
|
+
*/
|
|
156
|
+
hideElements(): Promise<void> {
|
|
157
|
+
this.#drawings = [];
|
|
158
|
+
return this.#redrawElements();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Apply an operation to the structure, once, and leave it where it lands.
|
|
163
|
+
*
|
|
164
|
+
* The elements stay where they are: an axis that turned with the molecule
|
|
165
|
+
* would prove nothing.
|
|
166
|
+
* @param operation - What to apply.
|
|
167
|
+
* @param options - See {@link PlayOptions}.
|
|
168
|
+
* @returns Resolves once the operation has been applied in full.
|
|
169
|
+
*/
|
|
170
|
+
playOperation(
|
|
171
|
+
operation: ViewerOperation,
|
|
172
|
+
options?: PlayOptions,
|
|
173
|
+
): Promise<void> {
|
|
174
|
+
return this.run((plugin) => playOperation(plugin, operation, options));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Hold the structure part-way through an operation, for a slider.
|
|
179
|
+
* @param operation - What is being applied.
|
|
180
|
+
* @param fraction - How far through, 0 to 1.
|
|
181
|
+
* @returns Resolves once the structure is held there.
|
|
182
|
+
*/
|
|
183
|
+
setOperationFraction(
|
|
184
|
+
operation: ViewerOperation,
|
|
185
|
+
fraction: number,
|
|
186
|
+
): Promise<void> {
|
|
187
|
+
return this.run((plugin) => {
|
|
188
|
+
setOperationFraction(plugin, operation, fraction);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Put the structure back where it started.
|
|
194
|
+
* @returns Resolves once the structure is back.
|
|
195
|
+
*/
|
|
196
|
+
resetOperation(): Promise<void> {
|
|
197
|
+
return this.run((plugin) => {
|
|
198
|
+
resetOperation(plugin);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
#redrawElements(): Promise<void> {
|
|
203
|
+
const drawings = this.#drawings;
|
|
204
|
+
const style = this.#elementStyle;
|
|
205
|
+
return this.run((plugin) => drawElements(plugin, drawings, style));
|
|
206
|
+
}
|
|
207
|
+
}
|
package/src/crystal3d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crystals in 3D: the atoms of a cell, the box around it, the symmetry
|
|
3
|
+
* elements over it and an operation applied to it, drawn by molstar.
|
|
4
|
+
*
|
|
5
|
+
* An entry point of its own because molstar is several megabytes: the canvas
|
|
6
|
+
* sits behind `React.lazy`, so importing this costs a page the drawing
|
|
7
|
+
* geometry and the components, never the viewer. The geometry needs neither
|
|
8
|
+
* React nor molstar and is exported beside the components.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export * from './crystal3d/core/index.ts';
|
|
12
|
+
export * from './crystal3d/ui/index.ts';
|