react-cheminfo 0.139.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/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/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,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The partial bond section of the options popover: whether they are drawn,
|
|
3
|
+
* and whether their lengths are written over them.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Switch } from '@blueprintjs/core';
|
|
7
|
+
import type { CSSProperties, ReactElement } from 'react';
|
|
8
|
+
|
|
9
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
10
|
+
import type { Molecule3DFile } from '../core/file.ts';
|
|
11
|
+
import type { PartialBondMode } from '../core/partialBondMode.ts';
|
|
12
|
+
import { showsPartialBonds } from '../core/partialBondMode.ts';
|
|
13
|
+
import type { Molecule3DSettings } from '../core/settings.ts';
|
|
14
|
+
import { normalizeMolecule3DSettings } from '../core/settings.ts';
|
|
15
|
+
|
|
16
|
+
/** Props of {@link Molecule3DPartialBonds}. */
|
|
17
|
+
export interface Molecule3DPartialBondsProps {
|
|
18
|
+
settings: Molecule3DSettings;
|
|
19
|
+
onChange: (settings: Molecule3DSettings) => void;
|
|
20
|
+
/** The format of the file on screen, which `auto` follows. */
|
|
21
|
+
format: Molecule3DFile['format'];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The two switches. The first shows what is drawn for the file on screen, and
|
|
26
|
+
* turning it back to what `auto` draws for that file stores `auto` again.
|
|
27
|
+
* @param props - See {@link Molecule3DPartialBondsProps}.
|
|
28
|
+
* @returns The section.
|
|
29
|
+
*/
|
|
30
|
+
export function Molecule3DPartialBonds(
|
|
31
|
+
props: Molecule3DPartialBondsProps,
|
|
32
|
+
): ReactElement {
|
|
33
|
+
const { settings, onChange, format } = props;
|
|
34
|
+
const t = useChromeT();
|
|
35
|
+
// A site owning the settings may hand over a record from before they existed.
|
|
36
|
+
const { partialBonds, partialBondLengths } =
|
|
37
|
+
normalizeMolecule3DSettings(settings);
|
|
38
|
+
const shown = showsPartialBonds(partialBonds, format);
|
|
39
|
+
const byDefault = showsPartialBonds('auto', format);
|
|
40
|
+
// Spacefill draws no bond: a disabled switch fires no hover, so the section
|
|
41
|
+
// carries the why.
|
|
42
|
+
const spacefill = settings.representation === 'spacefill';
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div
|
|
46
|
+
style={SECTION_STYLE}
|
|
47
|
+
title={spacefill ? t('molecule3d.partialBondsSpacefill') : undefined}
|
|
48
|
+
>
|
|
49
|
+
<Switch
|
|
50
|
+
alignIndicator="end"
|
|
51
|
+
style={SWITCH_STYLE}
|
|
52
|
+
checked={shown && !spacefill}
|
|
53
|
+
disabled={spacefill}
|
|
54
|
+
labelElement={
|
|
55
|
+
<span title={t('molecule3d.partialBondsHelp')}>
|
|
56
|
+
{t('molecule3d.partialBonds')}
|
|
57
|
+
</span>
|
|
58
|
+
}
|
|
59
|
+
data-testid="molecule3d-partial-bonds"
|
|
60
|
+
onChange={(event) => {
|
|
61
|
+
const checked = event.currentTarget.checked;
|
|
62
|
+
onChange({ ...settings, partialBonds: modeOf(checked, byDefault) });
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
<Switch
|
|
66
|
+
alignIndicator="end"
|
|
67
|
+
style={SWITCH_STYLE}
|
|
68
|
+
checked={partialBondLengths}
|
|
69
|
+
disabled={spacefill || !shown}
|
|
70
|
+
label={t('molecule3d.partialBondLengths')}
|
|
71
|
+
data-testid="molecule3d-partial-bond-lengths"
|
|
72
|
+
onChange={(event) => {
|
|
73
|
+
onChange({
|
|
74
|
+
...settings,
|
|
75
|
+
partialBondLengths: event.currentTarget.checked,
|
|
76
|
+
});
|
|
77
|
+
}}
|
|
78
|
+
/>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The mode a switch stores: `auto` when it lands on what `auto` draws.
|
|
85
|
+
* @param checked - Whether the partial bonds are to be drawn.
|
|
86
|
+
* @param byDefault - Whether `auto` draws them for the file on screen.
|
|
87
|
+
* @returns The mode.
|
|
88
|
+
*/
|
|
89
|
+
function modeOf(checked: boolean, byDefault: boolean): PartialBondMode {
|
|
90
|
+
if (checked === byDefault) return 'auto';
|
|
91
|
+
return checked ? 'on' : 'off';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const SECTION_STYLE: CSSProperties = {
|
|
95
|
+
display: 'flex',
|
|
96
|
+
flexDirection: 'column',
|
|
97
|
+
gap: 2,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const SWITCH_STYLE: CSSProperties = { marginBottom: 0, fontSize: 12 };
|
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
MEASUREMENT_KINDS,
|
|
17
17
|
MEASUREMENT_LABELS,
|
|
18
18
|
} from '../core/measurement.ts';
|
|
19
|
-
import type { Molecule3DTools } from '../core/
|
|
20
|
-
import { resolveMolecule3DTools } from '../core/
|
|
19
|
+
import type { Molecule3DTools } from '../core/tools.ts';
|
|
20
|
+
import { resolveMolecule3DTools } from '../core/tools.ts';
|
|
21
21
|
|
|
22
22
|
import { Molecule3DHelp } from './Molecule3DHelp.tsx';
|
|
23
23
|
import {
|
|
@@ -15,10 +15,8 @@ import { MolstarToolbar } from '../../molstar/ui/MolstarToolbar.tsx';
|
|
|
15
15
|
import { useMolstarTools } from '../../molstar/ui/useMolstarTools.ts';
|
|
16
16
|
import { DEFAULT_FRAMES_PER_SECOND } from '../core/animatedPng.ts';
|
|
17
17
|
import type { Molecule3DHighlight } from '../core/highlight.ts';
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
resolveMolecule3DTools,
|
|
21
|
-
} from '../core/settings.ts';
|
|
18
|
+
import { normalizeMolecule3DSettings } from '../core/settings.ts';
|
|
19
|
+
import { resolveMolecule3DTools } from '../core/tools.ts';
|
|
22
20
|
|
|
23
21
|
import { Molecule3DOptions } from './Molecule3DOptions.tsx';
|
|
24
22
|
import { Molecule3DStage } from './Molecule3DStage.tsx';
|
|
@@ -186,6 +184,7 @@ export function MoleculeCanvas3D(props: MoleculeCanvas3DProps): ReactElement {
|
|
|
186
184
|
onChange={setSettings}
|
|
187
185
|
polarSurfaceArea={polarSurfaceArea}
|
|
188
186
|
defaults={initialSettings}
|
|
187
|
+
format={molfile.format}
|
|
189
188
|
/>
|
|
190
189
|
}
|
|
191
190
|
exportLabel={
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Molecule3DFile } from '../core/file.ts';
|
|
2
2
|
import type { Measurement } from '../core/measurement.ts';
|
|
3
|
+
import { showsPartialBonds } from '../core/partialBondMode.ts';
|
|
3
4
|
import type { Molecule3DSettings } from '../core/settings.ts';
|
|
4
5
|
import { normalizeMolecule3DSettings } from '../core/settings.ts';
|
|
5
6
|
|
|
@@ -10,6 +11,7 @@ export type SceneViewer = Pick<
|
|
|
10
11
|
Molecule3DViewer,
|
|
11
12
|
| 'showMolecule'
|
|
12
13
|
| 'hideMolecule'
|
|
14
|
+
| 'showPartialBonds'
|
|
13
15
|
| 'showSurface'
|
|
14
16
|
| 'showMeasurements'
|
|
15
17
|
| 'resetCamera'
|
|
@@ -17,8 +19,9 @@ export type SceneViewer = Pick<
|
|
|
17
19
|
>;
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
|
-
* Draw the whole scene. `showMolecule` empties it, so the
|
|
21
|
-
* measurements are added after the model, and the camera is
|
|
22
|
+
* Draw the whole scene. `showMolecule` empties it, so the partial bonds, the
|
|
23
|
+
* surface and the measurements are added after the model, and the camera is
|
|
24
|
+
* framed last. Spacefill draws no bonds, and so no partial ones either.
|
|
22
25
|
* @param viewer - The viewer holding the canvas.
|
|
23
26
|
* @param molfile - What to draw, or `null` to empty the scene.
|
|
24
27
|
* @param settings - How to draw it.
|
|
@@ -44,6 +47,16 @@ export async function drawScene(
|
|
|
44
47
|
representation: safe.representation,
|
|
45
48
|
sizeFactor: safe.sizeFactor,
|
|
46
49
|
});
|
|
50
|
+
if (
|
|
51
|
+
safe.representation !== 'spacefill' &&
|
|
52
|
+
showsPartialBonds(safe.partialBonds, molfile.format)
|
|
53
|
+
) {
|
|
54
|
+
await viewer.showPartialBonds({
|
|
55
|
+
representation: safe.representation,
|
|
56
|
+
sizeFactor: safe.sizeFactor,
|
|
57
|
+
lengths: safe.partialBondLengths,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
47
60
|
if (safe.showSurface) {
|
|
48
61
|
await viewer.showSurface({
|
|
49
62
|
alpha: safe.surfaceAlpha,
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
} from '../../structure/core/molfileExport.ts';
|
|
20
20
|
import { notationText } from '../../structure/ui/structureNotationText.ts';
|
|
21
21
|
import type { Molecule3DFile } from '../core/file.ts';
|
|
22
|
+
import { isMolfileFormat } from '../core/file.ts';
|
|
22
23
|
|
|
23
24
|
/** A molfile the viewer's export writes. */
|
|
24
25
|
export type MoleculeFileFormat = 'molfileV2000' | 'molfileV3000';
|
|
@@ -30,8 +31,9 @@ const DIALECTS: Readonly<Record<MoleculeFileFormat, MolfileDialect>> = {
|
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* How many atoms a molfile can be written with, when one can: the file on
|
|
33
|
-
* screen has to be a
|
|
34
|
-
*
|
|
34
|
+
* screen has to be a molfile of a single model, so neither an XYZ, which has
|
|
35
|
+
* no bonds, nor a PDB, which openchemlib does not read, nor a series of
|
|
36
|
+
* frames, which is not one molecule.
|
|
35
37
|
* @param file - The file on screen.
|
|
36
38
|
* @param frameCount - How many frames the scene holds.
|
|
37
39
|
* @returns The atoms, or `0` when no molfile can be written.
|
|
@@ -40,7 +42,7 @@ export function moleculeFileAtoms(
|
|
|
40
42
|
file: Molecule3DFile | null | undefined,
|
|
41
43
|
frameCount: number,
|
|
42
44
|
): number {
|
|
43
|
-
if (!file || file.format
|
|
45
|
+
if (!file || !isMolfileFormat(file.format) || frameCount > 1) return 0;
|
|
44
46
|
return classifyMolfile(file.data).atomCount;
|
|
45
47
|
}
|
|
46
48
|
|
|
@@ -5,7 +5,8 @@ import type { Molecule3DCamera } from '../core/camera.ts';
|
|
|
5
5
|
import type { Molecule3DFile } from '../core/file.ts';
|
|
6
6
|
import type { Molecule3DHighlight } from '../core/highlight.ts';
|
|
7
7
|
import type { AtomReference, Measurement } from '../core/measurement.ts';
|
|
8
|
-
import type { Molecule3DSettings
|
|
8
|
+
import type { Molecule3DSettings } from '../core/settings.ts';
|
|
9
|
+
import type { Molecule3DTools } from '../core/tools.ts';
|
|
9
10
|
|
|
10
11
|
/** The scene on screen, rendered as a picture on request. */
|
|
11
12
|
export interface Molecule3DCapture {
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The partial bonds of the structure on screen, as molstar draws them: each
|
|
3
|
+
* one a dashed cylinder, each half in the colour of the atom it starts from as
|
|
4
|
+
* a bond of the model is, with its length written over its middle.
|
|
5
|
+
*
|
|
6
|
+
* The pairs are found by `findPartialBonds`, from the atoms and the bonds
|
|
7
|
+
* molstar itself drew, so a partial bond is never a bond molstar already has.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { addFixedCountDashedCylinder } from 'molstar/lib/mol-geo/geometry/mesh/builder/cylinder.js';
|
|
11
|
+
import { MeshBuilder } from 'molstar/lib/mol-geo/geometry/mesh/mesh-builder.js';
|
|
12
|
+
import { Mesh } from 'molstar/lib/mol-geo/geometry/mesh/mesh.js';
|
|
13
|
+
import { TextBuilder } from 'molstar/lib/mol-geo/geometry/text/text-builder.js';
|
|
14
|
+
import { Text } from 'molstar/lib/mol-geo/geometry/text/text.js';
|
|
15
|
+
import { Vec3 } from 'molstar/lib/mol-math/linear-algebra.js';
|
|
16
|
+
import { Shape } from 'molstar/lib/mol-model/shape.js';
|
|
17
|
+
import type { Structure } from 'molstar/lib/mol-model/structure.js';
|
|
18
|
+
import type { RepresentationContext } from 'molstar/lib/mol-repr/representation.js';
|
|
19
|
+
import { Representation } from 'molstar/lib/mol-repr/representation.js';
|
|
20
|
+
import type { ShapeGetter } from 'molstar/lib/mol-repr/shape/representation.js';
|
|
21
|
+
// Lowercased on import: it is a factory, not a constructor.
|
|
22
|
+
import { ShapeRepresentation as createShapeRepresentation } from 'molstar/lib/mol-repr/shape/representation.js';
|
|
23
|
+
import {
|
|
24
|
+
ElementSymbolColors,
|
|
25
|
+
elementSymbolColor,
|
|
26
|
+
} from 'molstar/lib/mol-theme/color/element-symbol.js';
|
|
27
|
+
import { Color } from 'molstar/lib/mol-util/color/color.js';
|
|
28
|
+
import { MarkerAction } from 'molstar/lib/mol-util/marker-action.js';
|
|
29
|
+
import { ParamDefinition as PD } from 'molstar/lib/mol-util/param-definition.js';
|
|
30
|
+
|
|
31
|
+
import { bondLimit } from '../../molstar/bonds/bondRule.ts';
|
|
32
|
+
import type { PartialBond } from '../core/partialBonds.ts';
|
|
33
|
+
import { findPartialBonds } from '../core/partialBonds.ts';
|
|
34
|
+
|
|
35
|
+
import { structureGeometry } from './structureGeometry.ts';
|
|
36
|
+
|
|
37
|
+
/** The partial bonds of one structure, and the atoms they join. */
|
|
38
|
+
export interface PartialBondScene {
|
|
39
|
+
/** The element of each atom, uppercase as molstar's colours name them. */
|
|
40
|
+
readonly elements: readonly string[];
|
|
41
|
+
/** x, y and z of each atom in turn, Å. */
|
|
42
|
+
readonly coordinates: Float64Array;
|
|
43
|
+
/** The partial bonds, by atom index. */
|
|
44
|
+
readonly bonds: readonly PartialBond[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The partial bonds of a structure, between the atoms molstar draws in it.
|
|
49
|
+
* @param structure - The structure on screen.
|
|
50
|
+
* @returns The bonds, with the atoms they need to be drawn.
|
|
51
|
+
*/
|
|
52
|
+
export function partialBondScene(structure: Structure): PartialBondScene {
|
|
53
|
+
const geometry = structureGeometry(structure);
|
|
54
|
+
const elements: string[] = [];
|
|
55
|
+
for (let atom = 0; atom < geometry.elements.length; atom++) {
|
|
56
|
+
elements.push((geometry.elements[atom] ?? '').toUpperCase());
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
elements,
|
|
60
|
+
coordinates: geometry.coordinates,
|
|
61
|
+
bonds: findPartialBonds(geometry, { bondLimit }),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Lowercased: molstar's parameter definitions are factories, not constructors.
|
|
66
|
+
const {
|
|
67
|
+
Boolean: booleanParam,
|
|
68
|
+
Color: colorParam,
|
|
69
|
+
MultiSelect: multiSelectParam,
|
|
70
|
+
Numeric: numericParam,
|
|
71
|
+
} = PD;
|
|
72
|
+
|
|
73
|
+
/** How the partial bonds are drawn. */
|
|
74
|
+
export const PartialBondParams = {
|
|
75
|
+
...Mesh.Params,
|
|
76
|
+
...Text.Params,
|
|
77
|
+
/** Radius of the dashes, Å. */
|
|
78
|
+
radius: numericParam(0.14, { min: 0.01, max: 1, step: 0.01 }),
|
|
79
|
+
textColor: colorParam(Color.fromHexStyle('#1f2937')), // tokens-ok: a scene colour
|
|
80
|
+
textSize: numericParam(0.36, { min: 0.1, max: 10, step: 0.1 }),
|
|
81
|
+
// On a pale card, as the crystal viewer writes its labels: written straight
|
|
82
|
+
// over the dashes, the digits are read as part of them.
|
|
83
|
+
background: booleanParam(true),
|
|
84
|
+
backgroundMargin: numericParam(0.2, { min: 0, max: 1, step: 0.01 }),
|
|
85
|
+
backgroundColor: colorParam(Color.fromHexStyle('#ffffff')), // tokens-ok: a scene colour
|
|
86
|
+
backgroundOpacity: numericParam(0.85, { min: 0, max: 1, step: 0.01 }),
|
|
87
|
+
// In front of the dashes, as the measurement labels are.
|
|
88
|
+
offsetZ: numericParam(0.75, { min: 0, max: 10, step: 0.1 }),
|
|
89
|
+
visuals: multiSelectParam(
|
|
90
|
+
['dashes', 'lengths'],
|
|
91
|
+
[
|
|
92
|
+
['dashes', 'Dashes'],
|
|
93
|
+
['lengths', 'Lengths'],
|
|
94
|
+
],
|
|
95
|
+
),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** Values of {@link PartialBondParams}. */
|
|
99
|
+
export type PartialBondProps = PD.Values<typeof PartialBondParams>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The representation drawing the dashes and, when asked, their lengths.
|
|
103
|
+
* @param context - molstar's representation context.
|
|
104
|
+
* @returns The representation; `createOrUpdate` it with a {@link PartialBondScene}.
|
|
105
|
+
*/
|
|
106
|
+
export function createPartialBondRepresentation(
|
|
107
|
+
context: RepresentationContext,
|
|
108
|
+
): Representation<PartialBondScene, typeof PartialBondParams> {
|
|
109
|
+
return Representation.createMulti(
|
|
110
|
+
'Partial bonds',
|
|
111
|
+
context,
|
|
112
|
+
() => PartialBondParams,
|
|
113
|
+
Representation.StateBuilder,
|
|
114
|
+
{
|
|
115
|
+
dashes: () => createShapeRepresentation(dashesShape, Mesh.Utils),
|
|
116
|
+
lengths: () =>
|
|
117
|
+
createShapeRepresentation(lengthsShape, Text.Utils, {
|
|
118
|
+
modifyState: (state) => ({
|
|
119
|
+
...state,
|
|
120
|
+
markerActions: MarkerAction.None,
|
|
121
|
+
}),
|
|
122
|
+
}),
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const dashesShape: ShapeGetter<
|
|
128
|
+
PartialBondScene,
|
|
129
|
+
Mesh,
|
|
130
|
+
typeof PartialBondParams
|
|
131
|
+
> = (_context, scene, props, shape) => {
|
|
132
|
+
const state = MeshBuilder.createState(1024, 512, shape?.geometry);
|
|
133
|
+
const start = Vec3.zero();
|
|
134
|
+
const end = Vec3.zero();
|
|
135
|
+
const cylinder = {
|
|
136
|
+
radiusTop: props.radius,
|
|
137
|
+
radiusBottom: props.radius,
|
|
138
|
+
radialSegments: 16,
|
|
139
|
+
topCap: true,
|
|
140
|
+
bottomCap: true,
|
|
141
|
+
};
|
|
142
|
+
const { bonds, coordinates } = scene;
|
|
143
|
+
for (let index = 0; index < bonds.length; index++) {
|
|
144
|
+
const bond = bonds[index];
|
|
145
|
+
if (bond === undefined) continue;
|
|
146
|
+
position(start, coordinates, bond.first);
|
|
147
|
+
position(end, coordinates, bond.second);
|
|
148
|
+
const dashes = dashCount(bond.distance);
|
|
149
|
+
// Each half from its own atom, as molstar draws the halves of a bond.
|
|
150
|
+
state.currentGroup = index * 2;
|
|
151
|
+
addFixedCountDashedCylinder(state, start, end, 0.5, dashes, true, cylinder);
|
|
152
|
+
state.currentGroup = index * 2 + 1;
|
|
153
|
+
addFixedCountDashedCylinder(state, end, start, 0.5, dashes, true, cylinder);
|
|
154
|
+
}
|
|
155
|
+
return Shape.create(
|
|
156
|
+
'Partial bonds',
|
|
157
|
+
scene,
|
|
158
|
+
MeshBuilder.getMesh(state),
|
|
159
|
+
(group) => halfColor(scene, group),
|
|
160
|
+
() => 1,
|
|
161
|
+
(group) => bondLabel(scene, Math.floor(group / 2)),
|
|
162
|
+
undefined,
|
|
163
|
+
bonds.length * 2,
|
|
164
|
+
);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const lengthsShape: ShapeGetter<
|
|
168
|
+
PartialBondScene,
|
|
169
|
+
Text,
|
|
170
|
+
typeof PartialBondParams
|
|
171
|
+
> = (_context, scene, props, shape) => {
|
|
172
|
+
const builder = TextBuilder.create(props, 64, 32, shape?.geometry);
|
|
173
|
+
const start = Vec3.zero();
|
|
174
|
+
const end = Vec3.zero();
|
|
175
|
+
const { bonds, coordinates } = scene;
|
|
176
|
+
for (let index = 0; index < bonds.length; index++) {
|
|
177
|
+
const bond = bonds[index];
|
|
178
|
+
if (bond === undefined) continue;
|
|
179
|
+
position(start, coordinates, bond.first);
|
|
180
|
+
position(end, coordinates, bond.second);
|
|
181
|
+
Vec3.add(start, start, end);
|
|
182
|
+
Vec3.scale(start, start, 0.5);
|
|
183
|
+
const x = start[0] ?? 0;
|
|
184
|
+
const y = start[1] ?? 0;
|
|
185
|
+
const z = start[2] ?? 0;
|
|
186
|
+
builder.add(lengthText(bond.distance), x, y, z, 1, 1, index);
|
|
187
|
+
}
|
|
188
|
+
return Shape.create(
|
|
189
|
+
'Partial bond lengths',
|
|
190
|
+
scene,
|
|
191
|
+
builder.getText(),
|
|
192
|
+
() => props.textColor,
|
|
193
|
+
() => props.textSize,
|
|
194
|
+
(group) => bondLabel(scene, group),
|
|
195
|
+
undefined,
|
|
196
|
+
bonds.length,
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* What a length reads, as molstar writes the distances it measures.
|
|
202
|
+
* @param distance - In ångström.
|
|
203
|
+
* @returns E.g. `2.27 Å`.
|
|
204
|
+
*/
|
|
205
|
+
function lengthText(distance: number): string {
|
|
206
|
+
return `${distance.toFixed(2)} Å`;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Dashes along one half, under 0.2 Å each and never fewer than four: an even
|
|
210
|
+
// count, so every dash has its full length.
|
|
211
|
+
function dashCount(distance: number): number {
|
|
212
|
+
return Math.max(4, 2 * Math.round(distance / 0.8));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function position(out: Vec3, coordinates: Float64Array, atom: number): void {
|
|
216
|
+
Vec3.set(
|
|
217
|
+
out,
|
|
218
|
+
coordinates[atom * 3] ?? 0,
|
|
219
|
+
coordinates[atom * 3 + 1] ?? 0,
|
|
220
|
+
coordinates[atom * 3 + 2] ?? 0,
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function halfColor(scene: PartialBondScene, group: number): Color {
|
|
225
|
+
const bond = scene.bonds[Math.floor(group / 2)];
|
|
226
|
+
const atom = group % 2 === 0 ? bond?.first : bond?.second;
|
|
227
|
+
const element = atom === undefined ? '' : (scene.elements[atom] ?? '');
|
|
228
|
+
return elementSymbolColor(
|
|
229
|
+
ElementSymbolColors,
|
|
230
|
+
element as Parameters<typeof elementSymbolColor>[1],
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// `C1–C6 2.27 Å`: the atoms numbered as in the file.
|
|
235
|
+
function bondLabel(scene: PartialBondScene, index: number): string {
|
|
236
|
+
const bond = scene.bonds[index];
|
|
237
|
+
if (bond === undefined) return 'Partial bond';
|
|
238
|
+
const { first, second, distance } = bond;
|
|
239
|
+
const atom = (at: number) => `${symbolOf(scene.elements[at] ?? '')}${at + 1}`;
|
|
240
|
+
return `${atom(first)}–${atom(second)} ${lengthText(distance)}`;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// `CL` as it is written, `Cl`.
|
|
244
|
+
function symbolOf(element: string): string {
|
|
245
|
+
return element.charAt(0) + element.slice(1).toLowerCase();
|
|
246
|
+
}
|
|
@@ -44,6 +44,9 @@ const SPACEFILL_SCALE = 4;
|
|
|
44
44
|
/** Sticks take the factor as a radius in ångström; 0.3 Å is licorice. */
|
|
45
45
|
const STICK_SCALE = 1.2;
|
|
46
46
|
|
|
47
|
+
/** molstar's van der Waals radius of carbon, which sizes a C–C bond, Å. */
|
|
48
|
+
const CARBON_VDW_RADIUS = 1.7;
|
|
49
|
+
|
|
47
50
|
/**
|
|
48
51
|
* Replace the displayed molecule. Everything already on screen goes first.
|
|
49
52
|
* @param plugin - The molstar context.
|
|
@@ -126,6 +129,23 @@ export function moleculeStructure(
|
|
|
126
129
|
return object.data;
|
|
127
130
|
}
|
|
128
131
|
|
|
132
|
+
/**
|
|
133
|
+
* The radius molstar gives a C–C bond of the model, so what is drawn beside
|
|
134
|
+
* the bonds can be sized after them.
|
|
135
|
+
* @param representation - Which representation.
|
|
136
|
+
* @param sizeFactor - The settings' radius multiplier.
|
|
137
|
+
* @returns The radius in ångström; 0 for spacefill, which draws no bonds.
|
|
138
|
+
*/
|
|
139
|
+
export function bondRadius(
|
|
140
|
+
representation: RepresentationId,
|
|
141
|
+
sizeFactor: number,
|
|
142
|
+
): number {
|
|
143
|
+
const factor = sizeFactor * NATURAL_SIZE_FACTOR;
|
|
144
|
+
if (representation === 'spacefill') return 0;
|
|
145
|
+
if (representation === 'stick') return factor * STICK_SCALE;
|
|
146
|
+
return factor * BALL_AND_STICK_ASPECT_RATIO * CARBON_VDW_RADIUS;
|
|
147
|
+
}
|
|
148
|
+
|
|
129
149
|
/**
|
|
130
150
|
* Translate one of the three representations into molstar's own. `stick` is a
|
|
131
151
|
* genuine licorice model: a uniform size theme and an aspect ratio of 1 give
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The partial bonds drawn over the model: a node of the state tree hanging off
|
|
3
|
+
* the structure, as the surface does.
|
|
4
|
+
*
|
|
5
|
+
* Hanging there, it is rebuilt from the structure each time the structure
|
|
6
|
+
* changes — another frame of a trajectory included, so the bonds forming along
|
|
7
|
+
* a reaction path are found again at every step — and it goes with the
|
|
8
|
+
* molecule when that is replaced.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { PluginContext } from 'molstar/lib/mol-plugin/context.js';
|
|
12
|
+
import { PluginStateObject } from 'molstar/lib/mol-plugin-state/objects.js';
|
|
13
|
+
import { StateTransformer } from 'molstar/lib/mol-state/index.js';
|
|
14
|
+
import { Task } from 'molstar/lib/mol-task/index.js';
|
|
15
|
+
import { ParamDefinition as PD } from 'molstar/lib/mol-util/param-definition.js';
|
|
16
|
+
|
|
17
|
+
import type { RepresentationId } from '../core/settings.ts';
|
|
18
|
+
|
|
19
|
+
import type { PartialBondProps } from './partialBondShapes.ts';
|
|
20
|
+
import {
|
|
21
|
+
createPartialBondRepresentation,
|
|
22
|
+
partialBondScene,
|
|
23
|
+
} from './partialBondShapes.ts';
|
|
24
|
+
import { MOLECULE_STRUCTURE_REF, bondRadius } from './renderMolecule.ts';
|
|
25
|
+
import type { PartialBondStyle } from './viewerTypes.ts';
|
|
26
|
+
|
|
27
|
+
/** The partial bond node, replaced in place whenever the style changes. */
|
|
28
|
+
const PARTIAL_BONDS_REF = 'molecule3d-partial-bonds';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A dash is thinner than a bond, so a partial bond never reads as a full one
|
|
32
|
+
* seen end on.
|
|
33
|
+
*/
|
|
34
|
+
const DASH_RADIUS_SCALE = 0.5;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Draw the partial bonds of the molecule on screen, or restyle them.
|
|
38
|
+
* @param plugin - The molstar context.
|
|
39
|
+
* @param style - See {@link PartialBondStyle}.
|
|
40
|
+
* @returns Nothing; resolves once they are on screen.
|
|
41
|
+
*/
|
|
42
|
+
export async function renderPartialBonds(
|
|
43
|
+
plugin: PluginContext,
|
|
44
|
+
style: PartialBondStyle = {},
|
|
45
|
+
): Promise<void> {
|
|
46
|
+
const {
|
|
47
|
+
representation = 'ball-and-stick',
|
|
48
|
+
sizeFactor = 1,
|
|
49
|
+
lengths = true,
|
|
50
|
+
} = style;
|
|
51
|
+
if (!plugin.state.data.cells.has(MOLECULE_STRUCTURE_REF)) return;
|
|
52
|
+
await plugin
|
|
53
|
+
.build()
|
|
54
|
+
.to(MOLECULE_STRUCTURE_REF)
|
|
55
|
+
.applyOrUpdate(PARTIAL_BONDS_REF, PartialBonds3D, {
|
|
56
|
+
radius: dashRadius(representation, sizeFactor),
|
|
57
|
+
lengths,
|
|
58
|
+
})
|
|
59
|
+
.commit();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function dashRadius(representation: RepresentationId, sizeFactor: number) {
|
|
63
|
+
return Math.max(
|
|
64
|
+
0.02,
|
|
65
|
+
bondRadius(representation, sizeFactor) * DASH_RADIUS_SCALE,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const createTransformer = StateTransformer.builderFactory('react-cheminfo');
|
|
70
|
+
|
|
71
|
+
// Lowercased: molstar's parameter definitions are factories, not constructors.
|
|
72
|
+
const { Boolean: booleanParam, Numeric: numericParam } = PD;
|
|
73
|
+
|
|
74
|
+
/** The structure's partial bonds, as a representation of their own. */
|
|
75
|
+
const PartialBonds3D = createTransformer({
|
|
76
|
+
name: 'molecule3d-partial-bonds-3d',
|
|
77
|
+
display: 'Partial bonds',
|
|
78
|
+
from: PluginStateObject.Molecule.Structure,
|
|
79
|
+
to: PluginStateObject.Shape.Representation3D,
|
|
80
|
+
params: {
|
|
81
|
+
radius: numericParam(0.14, { min: 0.01, max: 1, step: 0.01 }),
|
|
82
|
+
lengths: booleanParam(true),
|
|
83
|
+
},
|
|
84
|
+
})({
|
|
85
|
+
canAutoUpdate() {
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
apply({ a, params }, plugin: PluginContext) {
|
|
89
|
+
return Task.create('Partial bonds', async (runtime) => {
|
|
90
|
+
const scene = partialBondScene(a.data);
|
|
91
|
+
const repr = createPartialBondRepresentation({
|
|
92
|
+
webgl: plugin.canvas3d?.webgl,
|
|
93
|
+
...plugin.representation.structure.themes,
|
|
94
|
+
});
|
|
95
|
+
await repr.createOrUpdate(reprProps(params), scene).runInContext(runtime);
|
|
96
|
+
return new PluginStateObject.Shape.Representation3D(
|
|
97
|
+
{ repr, sourceData: scene },
|
|
98
|
+
{ label: 'Partial bonds' },
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
update({ a, b, newParams }) {
|
|
103
|
+
return Task.create('Partial bonds', async (runtime) => {
|
|
104
|
+
const scene = partialBondScene(a.data);
|
|
105
|
+
await b.data.repr
|
|
106
|
+
.createOrUpdate(reprProps(newParams), scene)
|
|
107
|
+
.runInContext(runtime);
|
|
108
|
+
b.data.sourceData = scene;
|
|
109
|
+
return StateTransformer.UpdateResult.Updated;
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
function reprProps(params: {
|
|
115
|
+
radius: number;
|
|
116
|
+
lengths: boolean;
|
|
117
|
+
}): Partial<PartialBondProps> {
|
|
118
|
+
return {
|
|
119
|
+
radius: params.radius,
|
|
120
|
+
visuals: params.lengths ? ['dashes', 'lengths'] : ['dashes'],
|
|
121
|
+
};
|
|
122
|
+
}
|