react-cheminfo 0.138.0 → 0.140.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/credits/core/credits.d.ts +12 -0
- package/lib/credits/core/credits.d.ts.map +1 -1
- package/lib/credits/core/credits.js +16 -0
- package/lib/credits/core/credits.js.map +1 -1
- package/lib/crystal3d/ui/CrystalCanvas3D.d.ts +1 -1
- package/lib/crystal3d/ui/CrystalCanvas3D.d.ts.map +1 -1
- package/lib/crystal3d/ui/CrystalViewer3D.d.ts +1 -1
- package/lib/crystal3d/ui/CrystalViewer3D.d.ts.map +1 -1
- package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts +1 -1
- package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts.map +1 -1
- package/lib/download/ui/FigureDownloadPanel.d.ts +17 -3
- package/lib/download/ui/FigureDownloadPanel.d.ts.map +1 -1
- package/lib/download/ui/FigureDownloadPanel.js +1 -1
- package/lib/download/ui/FigureDownloadPanel.js.map +1 -1
- package/lib/download/ui/FigureQuickActions.d.ts +10 -4
- package/lib/download/ui/FigureQuickActions.d.ts.map +1 -1
- package/lib/download/ui/FigureQuickActions.js +12 -6
- package/lib/download/ui/FigureQuickActions.js.map +1 -1
- package/lib/drawing/ui/ZoomControl.d.ts +20 -1
- package/lib/drawing/ui/ZoomControl.d.ts.map +1 -1
- package/lib/drawing/ui/ZoomControl.js +9 -5
- package/lib/drawing/ui/ZoomControl.js.map +1 -1
- package/lib/ecosystem/core/home.d.ts +19 -0
- package/lib/ecosystem/core/home.d.ts.map +1 -0
- package/lib/ecosystem/core/home.js +23 -0
- package/lib/ecosystem/core/home.js.map +1 -0
- package/lib/ecosystem/core/index.d.ts +3 -0
- package/lib/ecosystem/core/index.d.ts.map +1 -1
- package/lib/ecosystem/core/index.js +2 -0
- package/lib/ecosystem/core/index.js.map +1 -1
- package/lib/ecosystem/core/searchSites.d.ts +39 -0
- package/lib/ecosystem/core/searchSites.d.ts.map +1 -0
- package/lib/ecosystem/core/searchSites.js +77 -0
- package/lib/ecosystem/core/searchSites.js.map +1 -0
- package/lib/ecosystem/core/types.d.ts +1 -1
- package/lib/ecosystem/core/types.d.ts.map +1 -1
- package/lib/ecosystem/core/unlistedSites.d.ts.map +1 -1
- package/lib/ecosystem/core/unlistedSites.js +14 -0
- package/lib/ecosystem/core/unlistedSites.js.map +1 -1
- package/lib/ecosystem/ui/EcosystemButton.d.ts +6 -0
- package/lib/ecosystem/ui/EcosystemButton.d.ts.map +1 -1
- package/lib/ecosystem/ui/EcosystemButton.js +2 -2
- package/lib/ecosystem/ui/EcosystemButton.js.map +1 -1
- package/lib/ecosystem/ui/EcosystemMenu.d.ts +13 -4
- package/lib/ecosystem/ui/EcosystemMenu.d.ts.map +1 -1
- package/lib/ecosystem/ui/EcosystemMenu.js +56 -6
- package/lib/ecosystem/ui/EcosystemMenu.js.map +1 -1
- package/lib/ecosystem/ui/SiteGroupGrid.d.ts +12 -0
- package/lib/ecosystem/ui/SiteGroupGrid.d.ts.map +1 -1
- package/lib/ecosystem/ui/SiteGroupGrid.js +15 -2
- package/lib/ecosystem/ui/SiteGroupGrid.js.map +1 -1
- package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
- package/lib/ecosystem/ui/glyphs.js +4 -0
- package/lib/ecosystem/ui/glyphs.js.map +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +10 -0
- package/lib/locales/en.json +10 -0
- package/lib/locales/es.json +10 -0
- package/lib/locales/fr.json +10 -0
- package/lib/locales/it.json +10 -0
- package/lib/molecule3d/core/bondNeighbours.d.ts +30 -0
- package/lib/molecule3d/core/bondNeighbours.d.ts.map +1 -0
- package/lib/molecule3d/core/bondNeighbours.js +108 -0
- package/lib/molecule3d/core/bondNeighbours.js.map +1 -0
- package/lib/molecule3d/core/file.d.ts +15 -4
- package/lib/molecule3d/core/file.d.ts.map +1 -1
- package/lib/molecule3d/core/file.js +10 -1
- package/lib/molecule3d/core/file.js.map +1 -1
- package/lib/molecule3d/core/index.d.ts +11 -2
- package/lib/molecule3d/core/index.d.ts.map +1 -1
- package/lib/molecule3d/core/index.js +6 -1
- package/lib/molecule3d/core/index.js.map +1 -1
- package/lib/molecule3d/core/partialBondMode.d.ts +34 -0
- package/lib/molecule3d/core/partialBondMode.d.ts.map +1 -0
- package/lib/molecule3d/core/partialBondMode.js +39 -0
- package/lib/molecule3d/core/partialBondMode.js.map +1 -0
- package/lib/molecule3d/core/partialBondRanges.d.ts +61 -0
- package/lib/molecule3d/core/partialBondRanges.d.ts.map +1 -0
- package/lib/molecule3d/core/partialBondRanges.js +89 -0
- package/lib/molecule3d/core/partialBondRanges.js.map +1 -0
- package/lib/molecule3d/core/partialBonds.d.ts +61 -0
- package/lib/molecule3d/core/partialBonds.d.ts.map +1 -0
- package/lib/molecule3d/core/partialBonds.js +115 -0
- package/lib/molecule3d/core/partialBonds.js.map +1 -0
- package/lib/molecule3d/core/settings.d.ts +13 -35
- package/lib/molecule3d/core/settings.d.ts.map +1 -1
- package/lib/molecule3d/core/settings.js +17 -25
- package/lib/molecule3d/core/settings.js.map +1 -1
- package/lib/molecule3d/core/tools.d.ts +36 -0
- package/lib/molecule3d/core/tools.d.ts.map +1 -0
- package/lib/molecule3d/core/tools.js +24 -0
- package/lib/molecule3d/core/tools.js.map +1 -0
- package/lib/molecule3d/ui/Molecule3DExport.d.ts.map +1 -1
- package/lib/molecule3d/ui/Molecule3DExport.js +19 -2
- package/lib/molecule3d/ui/Molecule3DExport.js.map +1 -1
- package/lib/molecule3d/ui/Molecule3DOptions.d.ts +5 -2
- package/lib/molecule3d/ui/Molecule3DOptions.d.ts.map +1 -1
- package/lib/molecule3d/ui/Molecule3DOptions.js +6 -4
- package/lib/molecule3d/ui/Molecule3DOptions.js.map +1 -1
- package/lib/molecule3d/ui/Molecule3DPartialBonds.d.ts +22 -0
- package/lib/molecule3d/ui/Molecule3DPartialBonds.d.ts.map +1 -0
- package/lib/molecule3d/ui/Molecule3DPartialBonds.js +53 -0
- package/lib/molecule3d/ui/Molecule3DPartialBonds.js.map +1 -0
- package/lib/molecule3d/ui/Molecule3DToolbar.d.ts +1 -1
- package/lib/molecule3d/ui/Molecule3DToolbar.d.ts.map +1 -1
- package/lib/molecule3d/ui/Molecule3DToolbar.js +1 -1
- package/lib/molecule3d/ui/Molecule3DToolbar.js.map +1 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.d.ts.map +1 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.js +3 -2
- package/lib/molecule3d/ui/MoleculeCanvas3D.js.map +1 -1
- package/lib/molecule3d/ui/drawScene.d.ts +4 -3
- package/lib/molecule3d/ui/drawScene.d.ts.map +1 -1
- package/lib/molecule3d/ui/drawScene.js +12 -2
- package/lib/molecule3d/ui/drawScene.js.map +1 -1
- package/lib/molecule3d/ui/moleculeFileFormats.d.ts +3 -2
- package/lib/molecule3d/ui/moleculeFileFormats.d.ts.map +1 -1
- package/lib/molecule3d/ui/moleculeFileFormats.js +5 -3
- package/lib/molecule3d/ui/moleculeFileFormats.js.map +1 -1
- package/lib/molecule3d/ui/moleculeViewer3DProps.d.ts +2 -1
- package/lib/molecule3d/ui/moleculeViewer3DProps.d.ts.map +1 -1
- package/lib/molecule3d/ui/partialBondShapes.d.ts +117 -0
- package/lib/molecule3d/ui/partialBondShapes.d.ts.map +1 -0
- package/lib/molecule3d/ui/partialBondShapes.js +164 -0
- package/lib/molecule3d/ui/partialBondShapes.js.map +1 -0
- package/lib/molecule3d/ui/renderMolecule.d.ts +9 -0
- package/lib/molecule3d/ui/renderMolecule.d.ts.map +1 -1
- package/lib/molecule3d/ui/renderMolecule.js +17 -0
- package/lib/molecule3d/ui/renderMolecule.js.map +1 -1
- package/lib/molecule3d/ui/renderPartialBonds.d.ts +19 -0
- package/lib/molecule3d/ui/renderPartialBonds.d.ts.map +1 -0
- package/lib/molecule3d/ui/renderPartialBonds.js +90 -0
- package/lib/molecule3d/ui/renderPartialBonds.js.map +1 -0
- package/lib/molecule3d/ui/structureGeometry.d.ts +22 -0
- package/lib/molecule3d/ui/structureGeometry.d.ts.map +1 -0
- package/lib/molecule3d/ui/structureGeometry.js +63 -0
- package/lib/molecule3d/ui/structureGeometry.js.map +1 -0
- package/lib/molecule3d/ui/usePolarSurfaceArea.d.ts +2 -2
- package/lib/molecule3d/ui/usePolarSurfaceArea.d.ts.map +1 -1
- package/lib/molecule3d/ui/usePolarSurfaceArea.js +5 -4
- package/lib/molecule3d/ui/usePolarSurfaceArea.js.map +1 -1
- package/lib/molecule3d/ui/viewer.d.ts +8 -1
- package/lib/molecule3d/ui/viewer.d.ts.map +1 -1
- package/lib/molecule3d/ui/viewer.js +10 -0
- package/lib/molecule3d/ui/viewer.js.map +1 -1
- package/lib/molecule3d/ui/viewerTypes.d.ts +18 -0
- package/lib/molecule3d/ui/viewerTypes.d.ts.map +1 -1
- package/lib/panel/ui/FilterInput.d.ts +11 -0
- package/lib/panel/ui/FilterInput.d.ts.map +1 -1
- package/lib/panel/ui/FilterInput.js +10 -1
- package/lib/panel/ui/FilterInput.js.map +1 -1
- package/lib/shell/ui/ShellFrame.d.ts.map +1 -1
- package/lib/shell/ui/ShellFrame.js +3 -2
- package/lib/shell/ui/ShellFrame.js.map +1 -1
- package/package.json +1 -1
- package/src/credits/core/credits.ts +16 -0
- package/src/crystal3d/ui/CrystalCanvas3D.tsx +1 -1
- package/src/crystal3d/ui/CrystalViewer3D.tsx +1 -1
- package/src/crystal3d/ui/crystalStructureViewerProps.ts +1 -1
- package/src/download/ui/FigureDownloadPanel.tsx +20 -4
- package/src/download/ui/FigureQuickActions.tsx +18 -6
- package/src/drawing/ui/ZoomControl.tsx +33 -8
- package/src/ecosystem/core/home.ts +27 -0
- package/src/ecosystem/core/index.ts +7 -0
- package/src/ecosystem/core/searchSites.ts +102 -0
- package/src/ecosystem/core/types.ts +1 -0
- package/src/ecosystem/core/unlistedSites.ts +15 -0
- package/src/ecosystem/ui/EcosystemButton.tsx +8 -2
- package/src/ecosystem/ui/EcosystemMenu.tsx +103 -7
- package/src/ecosystem/ui/SiteGroupGrid.tsx +28 -3
- package/src/ecosystem/ui/glyphs.tsx +14 -0
- package/src/locales/de.json +10 -0
- package/src/locales/en.json +10 -0
- package/src/locales/es.json +10 -0
- package/src/locales/fr.json +10 -0
- package/src/locales/it.json +10 -0
- package/src/molecule3d/core/bondNeighbours.ts +108 -0
- package/src/molecule3d/core/file.ts +18 -4
- package/src/molecule3d/core/index.ts +17 -3
- package/src/molecule3d/core/partialBondMode.ts +48 -0
- package/src/molecule3d/core/partialBondRanges.ts +120 -0
- package/src/molecule3d/core/partialBonds.ts +180 -0
- package/src/molecule3d/core/settings.ts +29 -52
- package/src/molecule3d/core/tools.ts +51 -0
- package/src/molecule3d/ui/Molecule3DExport.tsx +17 -2
- package/src/molecule3d/ui/Molecule3DOptions.tsx +16 -3
- package/src/molecule3d/ui/Molecule3DPartialBonds.tsx +100 -0
- package/src/molecule3d/ui/Molecule3DToolbar.tsx +2 -2
- package/src/molecule3d/ui/MoleculeCanvas3D.tsx +3 -4
- package/src/molecule3d/ui/drawScene.ts +15 -2
- package/src/molecule3d/ui/moleculeFileFormats.ts +5 -3
- package/src/molecule3d/ui/moleculeViewer3DProps.ts +2 -1
- package/src/molecule3d/ui/partialBondShapes.ts +246 -0
- package/src/molecule3d/ui/renderMolecule.ts +20 -0
- package/src/molecule3d/ui/renderPartialBonds.ts +122 -0
- package/src/molecule3d/ui/structureGeometry.ts +73 -0
- package/src/molecule3d/ui/usePolarSurfaceArea.ts +5 -4
- package/src/molecule3d/ui/viewer.ts +12 -0
- package/src/molecule3d/ui/viewerTypes.ts +19 -0
- package/src/panel/ui/FilterInput.tsx +24 -0
- package/src/shell/ui/ShellFrame.tsx +7 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How many bonds apart two atoms are, counted along the bonds drawn, up to
|
|
3
|
+
* three: a pair within two bonds is never a partial bond, and a pair three
|
|
4
|
+
* bonds apart is held to a shorter one.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { BondGraph } from '../../crystal/core/components.ts';
|
|
8
|
+
import { bondGraph } from '../../crystal/core/components.ts';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Answers, for one atom at a time, how far other atoms are along the bonds.
|
|
12
|
+
*
|
|
13
|
+
* The atoms within two bonds of the atom asked about are stamped once, so every
|
|
14
|
+
* pair tested from it costs the neighbours of the other atom only.
|
|
15
|
+
*/
|
|
16
|
+
export class BondNeighbours {
|
|
17
|
+
readonly #graph: BondGraph;
|
|
18
|
+
// within[atom] === from: the atom is `from` or one of its neighbours.
|
|
19
|
+
readonly #within: Int32Array;
|
|
20
|
+
// second[atom] === from: the atom is two bonds from `from`, and no closer.
|
|
21
|
+
readonly #second: Int32Array;
|
|
22
|
+
#stamped = -1;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Index the bonds of `count` atoms.
|
|
26
|
+
* @param count - How many atoms.
|
|
27
|
+
* @param bonds - Atom-index pairs; a pair naming an atom out of range, or
|
|
28
|
+
* one atom twice, is skipped.
|
|
29
|
+
*/
|
|
30
|
+
constructor(count: number, bonds: ArrayLike<number>) {
|
|
31
|
+
this.#graph = bondGraph(count, periodicPairs(count, bonds));
|
|
32
|
+
this.#within = new Int32Array(count).fill(-1);
|
|
33
|
+
this.#second = new Int32Array(count).fill(-1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* How many bonds separate two atoms.
|
|
38
|
+
* @param from - One atom; asking from the same atom in a row is cheapest.
|
|
39
|
+
* @param to - The other.
|
|
40
|
+
* @returns 0 for one atom, 1 for a bonded pair, 2 for a pair with a common
|
|
41
|
+
* neighbour, 3 for a pair three bonds apart, and `Infinity` beyond.
|
|
42
|
+
*/
|
|
43
|
+
separation(from: number, to: number): number {
|
|
44
|
+
if (from === to) return 0;
|
|
45
|
+
if (this.#stamped !== from) this.#stamp(from);
|
|
46
|
+
if (this.#within[to] === from) return 1;
|
|
47
|
+
const { offsets, targets } = this.#graph;
|
|
48
|
+
let closest = Infinity;
|
|
49
|
+
const last = offsets[to + 1] ?? 0;
|
|
50
|
+
for (let slot = offsets[to] ?? 0; slot < last; slot++) {
|
|
51
|
+
const neighbour = targets[slot] ?? 0;
|
|
52
|
+
if (this.#within[neighbour] === from) return 2;
|
|
53
|
+
if (this.#second[neighbour] === from) closest = 3;
|
|
54
|
+
}
|
|
55
|
+
return closest;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#stamp(from: number): void {
|
|
59
|
+
const { offsets, targets } = this.#graph;
|
|
60
|
+
const within = this.#within;
|
|
61
|
+
const second = this.#second;
|
|
62
|
+
this.#stamped = from;
|
|
63
|
+
within[from] = from;
|
|
64
|
+
const last = offsets[from + 1] ?? 0;
|
|
65
|
+
for (let slot = offsets[from] ?? 0; slot < last; slot++) {
|
|
66
|
+
within[targets[slot] ?? 0] = from;
|
|
67
|
+
}
|
|
68
|
+
for (let slot = offsets[from] ?? 0; slot < last; slot++) {
|
|
69
|
+
const neighbour = targets[slot] ?? 0;
|
|
70
|
+
const end = offsets[neighbour + 1] ?? 0;
|
|
71
|
+
for (let next = offsets[neighbour] ?? 0; next < end; next++) {
|
|
72
|
+
const atom = targets[next] ?? 0;
|
|
73
|
+
if (within[atom] !== from) second[atom] = from;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The bonds as the pairs `bondGraph` reads, all within one cell.
|
|
81
|
+
* @param count - How many atoms.
|
|
82
|
+
* @param bonds - Atom-index pairs.
|
|
83
|
+
* @returns The valid pairs.
|
|
84
|
+
*/
|
|
85
|
+
function periodicPairs(count: number, bonds: ArrayLike<number>) {
|
|
86
|
+
const from: number[] = [];
|
|
87
|
+
const to: number[] = [];
|
|
88
|
+
const pairs = Math.floor(bonds.length / 2);
|
|
89
|
+
for (let pair = 0; pair < pairs; pair++) {
|
|
90
|
+
const a = bonds[pair * 2] ?? -1;
|
|
91
|
+
const b = bonds[pair * 2 + 1] ?? -1;
|
|
92
|
+
if (!isAtom(a, count) || !isAtom(b, count) || a === b) continue;
|
|
93
|
+
from.push(a);
|
|
94
|
+
to.push(b);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
count: from.length,
|
|
98
|
+
from: Int32Array.from(from),
|
|
99
|
+
to: Int32Array.from(to),
|
|
100
|
+
shifts: new Int32Array(from.length * 3),
|
|
101
|
+
lengths: new Float64Array(from.length),
|
|
102
|
+
coincident: new Int32Array(0),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function isAtom(index: number, count: number): boolean {
|
|
107
|
+
return Number.isInteger(index) && index >= 0 && index < count;
|
|
108
|
+
}
|
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
* A molfile for the viewer, with the parser molstar has to read it with.
|
|
3
3
|
*
|
|
4
4
|
* A file of several models — an SDF of several records, an XYZ of several
|
|
5
|
-
* frames — is a series of frames of one molecule,
|
|
6
|
-
* and export as an animated PNG.
|
|
5
|
+
* frames, a PDB of several `MODEL`s — is a series of frames of one molecule,
|
|
6
|
+
* which the viewer can play and export as an animated PNG.
|
|
7
7
|
*/
|
|
8
8
|
export interface Molecule3DFile {
|
|
9
9
|
/**
|
|
10
10
|
* molstar's format id: `mol` reads V2000, `sdf` reads V2000 and V3000, `xyz`
|
|
11
|
-
* reads bare coordinates and infers the bonds from the distances
|
|
11
|
+
* reads bare coordinates and infers the bonds from the distances, `pdb`
|
|
12
|
+
* reads `ATOM` and `HETATM` records and takes the bonds its `CONECT` records
|
|
13
|
+
* give, inferring from the distances any they leave out — all of them in a
|
|
14
|
+
* file that has none.
|
|
12
15
|
*/
|
|
13
|
-
format: 'mol' | 'sdf' | 'xyz';
|
|
16
|
+
format: 'mol' | 'sdf' | 'xyz' | 'pdb';
|
|
14
17
|
/** The file text. It must carry 3D coordinates. */
|
|
15
18
|
data: string;
|
|
16
19
|
/**
|
|
@@ -21,3 +24,14 @@ export interface Molecule3DFile {
|
|
|
21
24
|
*/
|
|
22
25
|
moleculeId?: string;
|
|
23
26
|
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Whether a file is a molfile: a connection table openchemlib reads, so it can
|
|
30
|
+
* be copied as a molfile and its polar surface area computed. An XYZ has no
|
|
31
|
+
* bonds to read, and openchemlib reads no PDB.
|
|
32
|
+
* @param format - The format of the file.
|
|
33
|
+
* @returns True for `mol` and `sdf`.
|
|
34
|
+
*/
|
|
35
|
+
export function isMolfileFormat(format: Molecule3DFile['format']): boolean {
|
|
36
|
+
return format === 'mol' || format === 'sdf';
|
|
37
|
+
}
|
|
@@ -49,15 +49,28 @@ export {
|
|
|
49
49
|
sameMeasurements,
|
|
50
50
|
} from './measurement.ts';
|
|
51
51
|
export type { Molecule3DFile } from './file.ts';
|
|
52
|
+
export { isMolfileFormat } from './file.ts';
|
|
53
|
+
export type { PartialBondMode } from './partialBondMode.ts';
|
|
54
|
+
export {
|
|
55
|
+
PARTIAL_BOND_MODES,
|
|
56
|
+
isPartialBondMode,
|
|
57
|
+
showsPartialBonds,
|
|
58
|
+
} from './partialBondMode.ts';
|
|
59
|
+
export type { PartialBondReach } from './partialBondRanges.ts';
|
|
60
|
+
export { FAR_PARTIAL_BOND, NEAR_PARTIAL_BOND } from './partialBondRanges.ts';
|
|
61
|
+
export type {
|
|
62
|
+
PartialBond,
|
|
63
|
+
PartialBondGeometry,
|
|
64
|
+
PartialBondOptions,
|
|
65
|
+
} from './partialBonds.ts';
|
|
66
|
+
export { findPartialBonds } from './partialBonds.ts';
|
|
52
67
|
export type {
|
|
53
68
|
Molecule3DSettings,
|
|
54
|
-
Molecule3DTools,
|
|
55
69
|
RepresentationId,
|
|
56
70
|
SurfaceColoringId,
|
|
57
71
|
} from './settings.ts';
|
|
58
72
|
export {
|
|
59
73
|
DEFAULT_MOLECULE_3D_SETTINGS,
|
|
60
|
-
DEFAULT_MOLECULE_3D_TOOLS,
|
|
61
74
|
MOLECULE_3D_RANGES,
|
|
62
75
|
REPRESENTATIONS,
|
|
63
76
|
REPRESENTATION_LABELS,
|
|
@@ -68,6 +81,7 @@ export {
|
|
|
68
81
|
isSurfaceColoringId,
|
|
69
82
|
normalizeMolecule3DSettings,
|
|
70
83
|
resetMolecule3DSettings,
|
|
71
|
-
resolveMolecule3DTools,
|
|
72
84
|
sameMolecule3DSettings,
|
|
73
85
|
} from './settings.ts';
|
|
86
|
+
export type { Molecule3DTools } from './tools.ts';
|
|
87
|
+
export { DEFAULT_MOLECULE_3D_TOOLS, resolveMolecule3DTools } from './tools.ts';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the viewer draws the partial bonds of a molecule, as a setting a site
|
|
3
|
+
* can persist.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Molecule3DFile } from './file.ts';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `auto` draws the partial bonds of an XYZ file and not those of a molfile;
|
|
10
|
+
* `on` and `off` draw them, or not, whatever the file.
|
|
11
|
+
*/
|
|
12
|
+
export const PARTIAL_BOND_MODES = ['auto', 'on', 'off'] as const;
|
|
13
|
+
|
|
14
|
+
/** One of {@link PARTIAL_BOND_MODES}. */
|
|
15
|
+
export type PartialBondMode = (typeof PARTIAL_BOND_MODES)[number];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Narrow an arbitrary value — a stored preference — to a partial bond mode.
|
|
19
|
+
* @param value - Candidate mode.
|
|
20
|
+
* @returns True when it is one of {@link PARTIAL_BOND_MODES}.
|
|
21
|
+
*/
|
|
22
|
+
export function isPartialBondMode(value: unknown): value is PartialBondMode {
|
|
23
|
+
for (const mode of PARTIAL_BOND_MODES) {
|
|
24
|
+
if (mode === value) return true;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether a file's partial bonds are drawn.
|
|
31
|
+
*
|
|
32
|
+
* An XYZ file carries no bonds: they are guessed from the distances, and the
|
|
33
|
+
* guess is what drops the stretched bonds of a transition state, so `auto`
|
|
34
|
+
* draws them. A molfile states its bonds, the forming ones included when its
|
|
35
|
+
* author wanted them, so `auto` adds nothing to it. Nor to a PDB: its bonds
|
|
36
|
+
* are written in `CONECT` records, and where they are not, the file is mostly
|
|
37
|
+
* a measured structure, whose stretched pairs are far likelier two sites of a
|
|
38
|
+
* disorder than a bond being made.
|
|
39
|
+
* @param mode - The setting.
|
|
40
|
+
* @param format - The format of the file on screen.
|
|
41
|
+
* @returns True when the partial bonds are drawn.
|
|
42
|
+
*/
|
|
43
|
+
export function showsPartialBonds(
|
|
44
|
+
mode: PartialBondMode,
|
|
45
|
+
format: Molecule3DFile['format'],
|
|
46
|
+
): boolean {
|
|
47
|
+
return mode === 'auto' ? format === 'xyz' : mode === 'on';
|
|
48
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The distances a partial bond may span, per pair of elements.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** How far past the bonding limit a partial bond may be. */
|
|
6
|
+
export interface PartialBondReach {
|
|
7
|
+
/** The most a partial bond may be, as a multiple of the bonding limit. */
|
|
8
|
+
readonly stretch: number;
|
|
9
|
+
/** And the most it may exceed the limit by, Å. */
|
|
10
|
+
readonly reach: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The reach of a pair three bonds apart, or holding a hydrogen: 1.4 times the
|
|
15
|
+
* limit, and at most 0.7 Å past it — 2.45 Å for C–C.
|
|
16
|
+
*
|
|
17
|
+
* Three bonds apart, the ends of a ring are already close: 2.59 Å across
|
|
18
|
+
* bicyclo[2.2.2]octane, 2.63 Å across a boat cyclohexane. With a hydrogen, the
|
|
19
|
+
* stretch stops short of a hydrogen bond: O–H is bonded up to 1.1 Å, and
|
|
20
|
+
* O–H···O starts near 1.6 Å. The 0.7 Å holds back the elements whose limit is
|
|
21
|
+
* long already: 1.4 times the 2.48 Å of C–I would reach the carbon three bonds
|
|
22
|
+
* away in a gauche iodoalkane, at 3.4 Å.
|
|
23
|
+
*/
|
|
24
|
+
export const NEAR_PARTIAL_BOND: PartialBondReach = { stretch: 1.4, reach: 0.7 };
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The reach of two heavy atoms further apart, or in separate molecules: 1.5
|
|
28
|
+
* times the limit, and at most 0.85 Å past it — 2.6 Å for C–C, which takes in
|
|
29
|
+
* the forming bonds of the usual transition states, 2.0–2.6 Å, while two
|
|
30
|
+
* molecules merely in contact are 3.2 Å apart or more.
|
|
31
|
+
*/
|
|
32
|
+
export const FAR_PARTIAL_BOND: PartialBondReach = { stretch: 1.5, reach: 0.85 };
|
|
33
|
+
|
|
34
|
+
/** The limits of every pair of elements, row-major over the elements present. */
|
|
35
|
+
export interface PairRanges {
|
|
36
|
+
/** The longest bond, Å; a partial bond is longer. */
|
|
37
|
+
readonly limit: Float64Array;
|
|
38
|
+
/** The longest partial bond three bonds apart, or with a hydrogen, Å. */
|
|
39
|
+
readonly near: Float64Array;
|
|
40
|
+
/** The longest partial bond otherwise, Å. */
|
|
41
|
+
readonly far: Float64Array;
|
|
42
|
+
/** The longest partial bond of all, Å. */
|
|
43
|
+
readonly longest: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The bonding limit and the two partial bond limits of every pair of the
|
|
48
|
+
* elements present, row-major; all 0 for a pair never partially bonded.
|
|
49
|
+
* @param symbols - The elements present.
|
|
50
|
+
* @param bondLimit - The longest bond between two elements, 0 for never.
|
|
51
|
+
* @param nearReach - The reach of a pair three bonds apart, or with a hydrogen.
|
|
52
|
+
* @param farReach - The reach of any other pair.
|
|
53
|
+
* @returns The limits, and the longest partial bond of all.
|
|
54
|
+
*/
|
|
55
|
+
export function pairRanges(
|
|
56
|
+
symbols: readonly string[],
|
|
57
|
+
bondLimit: (a: string, b: string) => number,
|
|
58
|
+
nearReach: PartialBondReach,
|
|
59
|
+
farReach: PartialBondReach,
|
|
60
|
+
): PairRanges {
|
|
61
|
+
const size = symbols.length;
|
|
62
|
+
const limit = new Float64Array(size * size);
|
|
63
|
+
const near = new Float64Array(size * size);
|
|
64
|
+
const far = new Float64Array(size * size);
|
|
65
|
+
let longest = 0;
|
|
66
|
+
for (let a = 0; a < size; a++) {
|
|
67
|
+
for (let b = 0; b < size; b++) {
|
|
68
|
+
const first = symbols[a] ?? '';
|
|
69
|
+
const second = symbols[b] ?? '';
|
|
70
|
+
const bonded = bondLimit(first, second);
|
|
71
|
+
const hydrogens = Number(isHydrogen(first)) + Number(isHydrogen(second));
|
|
72
|
+
if (!(bonded > 0) || hydrogens === 2) continue;
|
|
73
|
+
const cell = a * size + b;
|
|
74
|
+
const nearest = reachOf(bonded, nearReach);
|
|
75
|
+
const farthest =
|
|
76
|
+
hydrogens === 1
|
|
77
|
+
? nearest
|
|
78
|
+
: Math.max(nearest, reachOf(bonded, farReach));
|
|
79
|
+
limit[cell] = bonded;
|
|
80
|
+
near[cell] = nearest;
|
|
81
|
+
far[cell] = farthest;
|
|
82
|
+
longest = Math.max(longest, farthest);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return { limit, near, far, longest };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function reachOf(limit: number, { stretch, reach }: PartialBondReach): number {
|
|
89
|
+
return Math.max(limit, Math.min(limit * stretch, limit + reach));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Hydrogen and its isotopes, written as molstar reads them.
|
|
93
|
+
function isHydrogen(symbol: string): boolean {
|
|
94
|
+
return HYDROGENS.has(symbol.toUpperCase());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const HYDROGENS: ReadonlySet<string> = new Set(['H', 'D', 'T']);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The elements present, and which of them each atom is.
|
|
101
|
+
* @param elements - The element of each atom.
|
|
102
|
+
* @param count - How many atoms are read.
|
|
103
|
+
* @returns The index of each atom's element, and the elements.
|
|
104
|
+
*/
|
|
105
|
+
export function elementKinds(elements: readonly string[], count: number) {
|
|
106
|
+
const indices = new Int32Array(count);
|
|
107
|
+
const symbols: string[] = [];
|
|
108
|
+
const known = new Map<string, number>();
|
|
109
|
+
for (let atom = 0; atom < count; atom++) {
|
|
110
|
+
const element = elements[atom] ?? '';
|
|
111
|
+
let kind = known.get(element);
|
|
112
|
+
if (kind === undefined) {
|
|
113
|
+
kind = symbols.length;
|
|
114
|
+
known.set(element, kind);
|
|
115
|
+
symbols.push(element);
|
|
116
|
+
}
|
|
117
|
+
indices[atom] = kind;
|
|
118
|
+
}
|
|
119
|
+
return { indices, symbols };
|
|
120
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The partial bonds of a geometry: pairs of atoms a little too far apart to be
|
|
3
|
+
* bonded, as the bonds being formed and broken in a transition state are.
|
|
4
|
+
*
|
|
5
|
+
* A viewer that infers bonds from distances drops exactly those, so a
|
|
6
|
+
* transition state loses the feature it is about. A pair is a partial bond
|
|
7
|
+
* when it is longer than the longest bond between its elements, but not by
|
|
8
|
+
* more than its {@link PartialBondReach} allows, and when its two atoms are
|
|
9
|
+
* neither both hydrogens nor within two bonds of each other: a 1,3 pair is the
|
|
10
|
+
* two ends of a bond angle, never a bond. Nor does one pass through a third
|
|
11
|
+
* atom: the oxygens either side of a proton in flight are joined through it.
|
|
12
|
+
*
|
|
13
|
+
* Free of molstar: the bonding rule is handed in, so the viewer passes the one
|
|
14
|
+
* it bonds by and a page listing the partial bonds beside it can do the same.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { BondNeighbours } from './bondNeighbours.ts';
|
|
18
|
+
import type { PartialBondReach } from './partialBondRanges.ts';
|
|
19
|
+
import {
|
|
20
|
+
FAR_PARTIAL_BOND,
|
|
21
|
+
NEAR_PARTIAL_BOND,
|
|
22
|
+
elementKinds,
|
|
23
|
+
pairRanges,
|
|
24
|
+
} from './partialBondRanges.ts';
|
|
25
|
+
|
|
26
|
+
/** The atoms a partial bond is looked for between. */
|
|
27
|
+
export interface PartialBondGeometry {
|
|
28
|
+
/** The element of each atom, e.g. `C`. */
|
|
29
|
+
readonly elements: readonly string[];
|
|
30
|
+
/** Cartesian coordinates, ångström: x, y and z of each atom in turn. */
|
|
31
|
+
readonly coordinates: ArrayLike<number>;
|
|
32
|
+
/** The bonds already drawn, in atom-index pairs: `[a0, b0, a1, b1, …]`. */
|
|
33
|
+
readonly bonds: ArrayLike<number>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Options of {@link findPartialBonds}. */
|
|
37
|
+
export interface PartialBondOptions {
|
|
38
|
+
/**
|
|
39
|
+
* The longest bond between two elements, ångström, and 0 for a pair never
|
|
40
|
+
* bonded: the viewer passes molstar's own, `bondLimit` from
|
|
41
|
+
* `react-cheminfo/molstar/bonds`.
|
|
42
|
+
*/
|
|
43
|
+
readonly bondLimit: (a: string, b: string) => number;
|
|
44
|
+
/**
|
|
45
|
+
* The reach of a pair three bonds apart, or holding a hydrogen.
|
|
46
|
+
* @default NEAR_PARTIAL_BOND
|
|
47
|
+
*/
|
|
48
|
+
readonly near?: PartialBondReach;
|
|
49
|
+
/**
|
|
50
|
+
* The reach of any other pair.
|
|
51
|
+
* @default FAR_PARTIAL_BOND
|
|
52
|
+
*/
|
|
53
|
+
readonly far?: PartialBondReach;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** One partial bond. */
|
|
57
|
+
export interface PartialBond {
|
|
58
|
+
/** One atom, from 0 in the order of the geometry. */
|
|
59
|
+
readonly first: number;
|
|
60
|
+
/** The other, always after `first`. */
|
|
61
|
+
readonly second: number;
|
|
62
|
+
/** Their distance, Å. */
|
|
63
|
+
readonly distance: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Every partial bond of a geometry.
|
|
68
|
+
* @param geometry - The atoms and the bonds already drawn between them.
|
|
69
|
+
* @param options - The bonding rule, and how far past it to look.
|
|
70
|
+
* @returns The partial bonds, ordered by `first` then `second`.
|
|
71
|
+
*/
|
|
72
|
+
export function findPartialBonds(
|
|
73
|
+
geometry: PartialBondGeometry,
|
|
74
|
+
options: PartialBondOptions,
|
|
75
|
+
): PartialBond[] {
|
|
76
|
+
const { elements, coordinates, bonds } = geometry;
|
|
77
|
+
const count = Math.min(elements.length, Math.floor(coordinates.length / 3));
|
|
78
|
+
const kinds = elementKinds(elements, count);
|
|
79
|
+
const ranges = pairRanges(
|
|
80
|
+
kinds.symbols,
|
|
81
|
+
options.bondLimit,
|
|
82
|
+
options.near ?? NEAR_PARTIAL_BOND,
|
|
83
|
+
options.far ?? FAR_PARTIAL_BOND,
|
|
84
|
+
);
|
|
85
|
+
const kindCount = kinds.symbols.length;
|
|
86
|
+
const neighbours = new BondNeighbours(count, bonds);
|
|
87
|
+
const order = alongX(coordinates, count);
|
|
88
|
+
const found: PartialBond[] = [];
|
|
89
|
+
|
|
90
|
+
for (let p = 0; p < count; p++) {
|
|
91
|
+
const i = order[p] ?? 0;
|
|
92
|
+
const xi = coordinates[i * 3] ?? 0;
|
|
93
|
+
const yi = coordinates[i * 3 + 1] ?? 0;
|
|
94
|
+
const zi = coordinates[i * 3 + 2] ?? 0;
|
|
95
|
+
const row = (kinds.indices[i] ?? 0) * kindCount;
|
|
96
|
+
for (let q = p + 1; q < count; q++) {
|
|
97
|
+
const j = order[q] ?? 0;
|
|
98
|
+
const dx = (coordinates[j * 3] ?? 0) - xi;
|
|
99
|
+
if (dx > ranges.longest) break;
|
|
100
|
+
const dy = (coordinates[j * 3 + 1] ?? 0) - yi;
|
|
101
|
+
const dz = (coordinates[j * 3 + 2] ?? 0) - zi;
|
|
102
|
+
const squared = dx * dx + dy * dy + dz * dz;
|
|
103
|
+
const pair = row + (kinds.indices[j] ?? 0);
|
|
104
|
+
const lower = ranges.limit[pair] ?? 0;
|
|
105
|
+
const far = ranges.far[pair] ?? 0;
|
|
106
|
+
if (squared <= lower * lower || squared > far * far) continue;
|
|
107
|
+
const separation = neighbours.separation(i, j);
|
|
108
|
+
if (separation < 3) continue;
|
|
109
|
+
const near = ranges.near[pair] ?? 0;
|
|
110
|
+
if (separation === 3 && squared > near * near) continue;
|
|
111
|
+
if (passesThroughAtom(coordinates, count, i, j, squared)) continue;
|
|
112
|
+
found.push({
|
|
113
|
+
first: Math.min(i, j),
|
|
114
|
+
second: Math.max(i, j),
|
|
115
|
+
distance: Math.sqrt(squared),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return found.toSorted(
|
|
120
|
+
(one, other) => one.first - other.first || one.second - other.second,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The atoms in increasing x, so that a pair further apart along x than the
|
|
126
|
+
* longest partial bond ends the search from its first atom.
|
|
127
|
+
* @param coordinates - x, y, z of each atom.
|
|
128
|
+
* @param count - How many atoms.
|
|
129
|
+
* @returns Atom indices.
|
|
130
|
+
*/
|
|
131
|
+
function alongX(coordinates: ArrayLike<number>, count: number): Int32Array {
|
|
132
|
+
const order = new Int32Array(count);
|
|
133
|
+
for (let atom = 0; atom < count; atom++) order[atom] = atom;
|
|
134
|
+
return order.toSorted(
|
|
135
|
+
(a, b) => (coordinates[a * 3] ?? 0) - (coordinates[b * 3] ?? 0),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Whether a third atom stands between two, nearly on the line joining them:
|
|
141
|
+
* seen from it, the two make an angle of 150° or more.
|
|
142
|
+
* @param coordinates - x, y, z of each atom.
|
|
143
|
+
* @param count - How many atoms.
|
|
144
|
+
* @param i - One end.
|
|
145
|
+
* @param j - The other.
|
|
146
|
+
* @param squared - Their squared distance.
|
|
147
|
+
* @returns True when the line from `i` to `j` passes through an atom.
|
|
148
|
+
*/
|
|
149
|
+
function passesThroughAtom(
|
|
150
|
+
coordinates: ArrayLike<number>,
|
|
151
|
+
count: number,
|
|
152
|
+
i: number,
|
|
153
|
+
j: number,
|
|
154
|
+
squared: number,
|
|
155
|
+
): boolean {
|
|
156
|
+
for (let k = 0; k < count; k++) {
|
|
157
|
+
if (k === i || k === j) continue;
|
|
158
|
+
const toI = squaredDistance(coordinates, k, i);
|
|
159
|
+
const toJ = squaredDistance(coordinates, k, j);
|
|
160
|
+
if (toI >= squared || toJ >= squared) continue;
|
|
161
|
+
// The law of cosines, at k.
|
|
162
|
+
const cosine = (toI + toJ - squared) / (2 * Math.sqrt(toI * toJ));
|
|
163
|
+
if (cosine <= THROUGH_COSINE) return true;
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** cos 150°. */
|
|
169
|
+
const THROUGH_COSINE = -Math.sqrt(3) / 2;
|
|
170
|
+
|
|
171
|
+
function squaredDistance(
|
|
172
|
+
coordinates: ArrayLike<number>,
|
|
173
|
+
a: number,
|
|
174
|
+
b: number,
|
|
175
|
+
): number {
|
|
176
|
+
const dx = (coordinates[a * 3] ?? 0) - (coordinates[b * 3] ?? 0);
|
|
177
|
+
const dy = (coordinates[a * 3 + 1] ?? 0) - (coordinates[b * 3 + 1] ?? 0);
|
|
178
|
+
const dz = (coordinates[a * 3 + 2] ?? 0) - (coordinates[b * 3 + 2] ?? 0);
|
|
179
|
+
return dx * dx + dy * dy + dz * dz;
|
|
180
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The display settings of the 3D molecule viewer
|
|
3
|
-
*
|
|
2
|
+
* The display settings of the 3D molecule viewer, free of React and molstar so
|
|
3
|
+
* a site can persist and validate them.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import type { PartialBondMode } from './partialBondMode.ts';
|
|
7
|
+
import { isPartialBondMode } from './partialBondMode.ts';
|
|
8
|
+
|
|
6
9
|
/** Ways the model can be drawn, in the order the picker offers them. */
|
|
7
10
|
export const REPRESENTATIONS = [
|
|
8
11
|
'ball-and-stick',
|
|
@@ -51,6 +54,14 @@ export interface Molecule3DSettings {
|
|
|
51
54
|
surfaceColoring: SurfaceColoringId;
|
|
52
55
|
/** Surface colour in `uniform` mode, `#rrggbb`. */
|
|
53
56
|
surfaceColor: string;
|
|
57
|
+
/**
|
|
58
|
+
* Whether the partial bonds are drawn dashed: pairs a little too far apart
|
|
59
|
+
* to be bonded, as the forming and breaking bonds of a transition state.
|
|
60
|
+
* `auto` draws them for an XYZ file, whose bonds are guessed from distances.
|
|
61
|
+
*/
|
|
62
|
+
partialBonds: PartialBondMode;
|
|
63
|
+
/** Whether each partial bond is labelled with its length. */
|
|
64
|
+
partialBondLengths: boolean;
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
/**
|
|
@@ -74,6 +85,8 @@ export const DEFAULT_MOLECULE_3D_SETTINGS: Molecule3DSettings = {
|
|
|
74
85
|
surfaceColoring: 'uniform',
|
|
75
86
|
// A scene colour: WebGL cannot read a CSS custom property.
|
|
76
87
|
surfaceColor: '#94a3b8', // tokens-ok
|
|
88
|
+
partialBonds: 'auto',
|
|
89
|
+
partialBondLengths: true,
|
|
77
90
|
};
|
|
78
91
|
|
|
79
92
|
/** The span, and the slider step, of every numeric setting. */
|
|
@@ -83,42 +96,6 @@ export const MOLECULE_3D_RANGES = {
|
|
|
83
96
|
probeRadius: { minimum: 1, maximum: 3, step: 0.1 },
|
|
84
97
|
} as const;
|
|
85
98
|
|
|
86
|
-
/** Which buttons the toolbar over the canvas shows. */
|
|
87
|
-
export interface Molecule3DTools {
|
|
88
|
-
/** Distance, angle and dihedral tools, and a button removing them all. */
|
|
89
|
-
measure: boolean;
|
|
90
|
-
/** A popover with the representation, the size and the surface sliders. */
|
|
91
|
-
options: boolean;
|
|
92
|
-
/** A toggle turning the model on its own. */
|
|
93
|
-
spin: boolean;
|
|
94
|
-
/** A toggle drawing the molecular surface. */
|
|
95
|
-
surface: boolean;
|
|
96
|
-
/** A button framing the model again. */
|
|
97
|
-
reset: boolean;
|
|
98
|
-
/** A popover saving the picture as a PNG or an SVG. */
|
|
99
|
-
export: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* A toggle filling the screen with the canvas and its toolbars. It is left
|
|
102
|
-
* out where the browser cannot fill the screen, as on an iPhone or in a
|
|
103
|
-
* frame not allowed to.
|
|
104
|
-
*/
|
|
105
|
-
fullscreen: boolean;
|
|
106
|
-
/** A popover listing what the mouse and the keyboard do on the canvas. */
|
|
107
|
-
help: boolean;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** Every tool on. */
|
|
111
|
-
export const DEFAULT_MOLECULE_3D_TOOLS: Molecule3DTools = {
|
|
112
|
-
measure: true,
|
|
113
|
-
options: true,
|
|
114
|
-
spin: true,
|
|
115
|
-
surface: true,
|
|
116
|
-
reset: true,
|
|
117
|
-
export: true,
|
|
118
|
-
fullscreen: true,
|
|
119
|
-
help: true,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
99
|
/**
|
|
123
100
|
* Narrow an arbitrary string — a stored preference, a picker's value — to a
|
|
124
101
|
* representation.
|
|
@@ -147,8 +124,8 @@ export function isSurfaceColoringId(value: string): value is SurfaceColoringId {
|
|
|
147
124
|
/**
|
|
148
125
|
* Complete and repair settings from any source: missing fields take their
|
|
149
126
|
* default, numbers are clamped into {@link MOLECULE_3D_RANGES}, an unknown
|
|
150
|
-
* representation or
|
|
151
|
-
* is not `#rrggbb` to its default.
|
|
127
|
+
* representation, colouring or partial bond mode falls back to the default
|
|
128
|
+
* one, and a colour that is not `#rrggbb` to its default.
|
|
152
129
|
* @param settings - Whatever a site has, possibly read back from storage.
|
|
153
130
|
* @returns Settings the viewer can draw.
|
|
154
131
|
*/
|
|
@@ -164,6 +141,8 @@ export function normalizeMolecule3DSettings(
|
|
|
164
141
|
probeRadius,
|
|
165
142
|
surfaceColoring,
|
|
166
143
|
surfaceColor,
|
|
144
|
+
partialBonds,
|
|
145
|
+
partialBondLengths,
|
|
167
146
|
} = settings;
|
|
168
147
|
return {
|
|
169
148
|
representation:
|
|
@@ -181,6 +160,13 @@ export function normalizeMolecule3DSettings(
|
|
|
181
160
|
? surfaceColoring
|
|
182
161
|
: defaults.surfaceColoring,
|
|
183
162
|
surfaceColor: hexColor(surfaceColor, defaults.surfaceColor),
|
|
163
|
+
partialBonds: isPartialBondMode(partialBonds)
|
|
164
|
+
? partialBonds
|
|
165
|
+
: defaults.partialBonds,
|
|
166
|
+
partialBondLengths:
|
|
167
|
+
typeof partialBondLengths === 'boolean'
|
|
168
|
+
? partialBondLengths
|
|
169
|
+
: defaults.partialBondLengths,
|
|
184
170
|
};
|
|
185
171
|
}
|
|
186
172
|
|
|
@@ -215,21 +201,12 @@ export function sameMolecule3DSettings(
|
|
|
215
201
|
first.surfaceAlpha === second.surfaceAlpha &&
|
|
216
202
|
first.probeRadius === second.probeRadius &&
|
|
217
203
|
first.surfaceColoring === second.surfaceColoring &&
|
|
218
|
-
first.surfaceColor === second.surfaceColor
|
|
204
|
+
first.surfaceColor === second.surfaceColor &&
|
|
205
|
+
first.partialBonds === second.partialBonds &&
|
|
206
|
+
first.partialBondLengths === second.partialBondLengths
|
|
219
207
|
);
|
|
220
208
|
}
|
|
221
209
|
|
|
222
|
-
/**
|
|
223
|
-
* Complete a partial tool selection.
|
|
224
|
-
* @param tools - The tools a site switched on or off.
|
|
225
|
-
* @returns Every tool, those not named left on.
|
|
226
|
-
*/
|
|
227
|
-
export function resolveMolecule3DTools(
|
|
228
|
-
tools: Partial<Molecule3DTools> = {},
|
|
229
|
-
): Molecule3DTools {
|
|
230
|
-
return { ...DEFAULT_MOLECULE_3D_TOOLS, ...tools };
|
|
231
|
-
}
|
|
232
|
-
|
|
233
210
|
function hexColor(value: string | undefined, fallback: string): string {
|
|
234
211
|
return typeof value === 'string' && /^#[\da-f]{6}$/i.test(value)
|
|
235
212
|
? value.toLowerCase()
|