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.
Files changed (201) hide show
  1. package/lib/credits/core/credits.d.ts +12 -0
  2. package/lib/credits/core/credits.d.ts.map +1 -1
  3. package/lib/credits/core/credits.js +16 -0
  4. package/lib/credits/core/credits.js.map +1 -1
  5. package/lib/crystal3d/ui/CrystalCanvas3D.d.ts +1 -1
  6. package/lib/crystal3d/ui/CrystalCanvas3D.d.ts.map +1 -1
  7. package/lib/crystal3d/ui/CrystalViewer3D.d.ts +1 -1
  8. package/lib/crystal3d/ui/CrystalViewer3D.d.ts.map +1 -1
  9. package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts +1 -1
  10. package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts.map +1 -1
  11. package/lib/download/ui/FigureDownloadPanel.d.ts +17 -3
  12. package/lib/download/ui/FigureDownloadPanel.d.ts.map +1 -1
  13. package/lib/download/ui/FigureDownloadPanel.js +1 -1
  14. package/lib/download/ui/FigureDownloadPanel.js.map +1 -1
  15. package/lib/download/ui/FigureQuickActions.d.ts +10 -4
  16. package/lib/download/ui/FigureQuickActions.d.ts.map +1 -1
  17. package/lib/download/ui/FigureQuickActions.js +12 -6
  18. package/lib/download/ui/FigureQuickActions.js.map +1 -1
  19. package/lib/drawing/ui/ZoomControl.d.ts +20 -1
  20. package/lib/drawing/ui/ZoomControl.d.ts.map +1 -1
  21. package/lib/drawing/ui/ZoomControl.js +9 -5
  22. package/lib/drawing/ui/ZoomControl.js.map +1 -1
  23. package/lib/ecosystem/core/home.d.ts +19 -0
  24. package/lib/ecosystem/core/home.d.ts.map +1 -0
  25. package/lib/ecosystem/core/home.js +23 -0
  26. package/lib/ecosystem/core/home.js.map +1 -0
  27. package/lib/ecosystem/core/index.d.ts +3 -0
  28. package/lib/ecosystem/core/index.d.ts.map +1 -1
  29. package/lib/ecosystem/core/index.js +2 -0
  30. package/lib/ecosystem/core/index.js.map +1 -1
  31. package/lib/ecosystem/core/searchSites.d.ts +39 -0
  32. package/lib/ecosystem/core/searchSites.d.ts.map +1 -0
  33. package/lib/ecosystem/core/searchSites.js +77 -0
  34. package/lib/ecosystem/core/searchSites.js.map +1 -0
  35. package/lib/ecosystem/core/types.d.ts +1 -1
  36. package/lib/ecosystem/core/types.d.ts.map +1 -1
  37. package/lib/ecosystem/core/unlistedSites.d.ts.map +1 -1
  38. package/lib/ecosystem/core/unlistedSites.js +14 -0
  39. package/lib/ecosystem/core/unlistedSites.js.map +1 -1
  40. package/lib/ecosystem/ui/EcosystemButton.d.ts +6 -0
  41. package/lib/ecosystem/ui/EcosystemButton.d.ts.map +1 -1
  42. package/lib/ecosystem/ui/EcosystemButton.js +2 -2
  43. package/lib/ecosystem/ui/EcosystemButton.js.map +1 -1
  44. package/lib/ecosystem/ui/EcosystemMenu.d.ts +13 -4
  45. package/lib/ecosystem/ui/EcosystemMenu.d.ts.map +1 -1
  46. package/lib/ecosystem/ui/EcosystemMenu.js +56 -6
  47. package/lib/ecosystem/ui/EcosystemMenu.js.map +1 -1
  48. package/lib/ecosystem/ui/SiteGroupGrid.d.ts +12 -0
  49. package/lib/ecosystem/ui/SiteGroupGrid.d.ts.map +1 -1
  50. package/lib/ecosystem/ui/SiteGroupGrid.js +15 -2
  51. package/lib/ecosystem/ui/SiteGroupGrid.js.map +1 -1
  52. package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
  53. package/lib/ecosystem/ui/glyphs.js +4 -0
  54. package/lib/ecosystem/ui/glyphs.js.map +1 -1
  55. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  56. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  57. package/lib/locales/de.json +10 -0
  58. package/lib/locales/en.json +10 -0
  59. package/lib/locales/es.json +10 -0
  60. package/lib/locales/fr.json +10 -0
  61. package/lib/locales/it.json +10 -0
  62. package/lib/molecule3d/core/bondNeighbours.d.ts +30 -0
  63. package/lib/molecule3d/core/bondNeighbours.d.ts.map +1 -0
  64. package/lib/molecule3d/core/bondNeighbours.js +108 -0
  65. package/lib/molecule3d/core/bondNeighbours.js.map +1 -0
  66. package/lib/molecule3d/core/file.d.ts +15 -4
  67. package/lib/molecule3d/core/file.d.ts.map +1 -1
  68. package/lib/molecule3d/core/file.js +10 -1
  69. package/lib/molecule3d/core/file.js.map +1 -1
  70. package/lib/molecule3d/core/index.d.ts +11 -2
  71. package/lib/molecule3d/core/index.d.ts.map +1 -1
  72. package/lib/molecule3d/core/index.js +6 -1
  73. package/lib/molecule3d/core/index.js.map +1 -1
  74. package/lib/molecule3d/core/partialBondMode.d.ts +34 -0
  75. package/lib/molecule3d/core/partialBondMode.d.ts.map +1 -0
  76. package/lib/molecule3d/core/partialBondMode.js +39 -0
  77. package/lib/molecule3d/core/partialBondMode.js.map +1 -0
  78. package/lib/molecule3d/core/partialBondRanges.d.ts +61 -0
  79. package/lib/molecule3d/core/partialBondRanges.d.ts.map +1 -0
  80. package/lib/molecule3d/core/partialBondRanges.js +89 -0
  81. package/lib/molecule3d/core/partialBondRanges.js.map +1 -0
  82. package/lib/molecule3d/core/partialBonds.d.ts +61 -0
  83. package/lib/molecule3d/core/partialBonds.d.ts.map +1 -0
  84. package/lib/molecule3d/core/partialBonds.js +115 -0
  85. package/lib/molecule3d/core/partialBonds.js.map +1 -0
  86. package/lib/molecule3d/core/settings.d.ts +13 -35
  87. package/lib/molecule3d/core/settings.d.ts.map +1 -1
  88. package/lib/molecule3d/core/settings.js +17 -25
  89. package/lib/molecule3d/core/settings.js.map +1 -1
  90. package/lib/molecule3d/core/tools.d.ts +36 -0
  91. package/lib/molecule3d/core/tools.d.ts.map +1 -0
  92. package/lib/molecule3d/core/tools.js +24 -0
  93. package/lib/molecule3d/core/tools.js.map +1 -0
  94. package/lib/molecule3d/ui/Molecule3DExport.d.ts.map +1 -1
  95. package/lib/molecule3d/ui/Molecule3DExport.js +19 -2
  96. package/lib/molecule3d/ui/Molecule3DExport.js.map +1 -1
  97. package/lib/molecule3d/ui/Molecule3DOptions.d.ts +5 -2
  98. package/lib/molecule3d/ui/Molecule3DOptions.d.ts.map +1 -1
  99. package/lib/molecule3d/ui/Molecule3DOptions.js +6 -4
  100. package/lib/molecule3d/ui/Molecule3DOptions.js.map +1 -1
  101. package/lib/molecule3d/ui/Molecule3DPartialBonds.d.ts +22 -0
  102. package/lib/molecule3d/ui/Molecule3DPartialBonds.d.ts.map +1 -0
  103. package/lib/molecule3d/ui/Molecule3DPartialBonds.js +53 -0
  104. package/lib/molecule3d/ui/Molecule3DPartialBonds.js.map +1 -0
  105. package/lib/molecule3d/ui/Molecule3DToolbar.d.ts +1 -1
  106. package/lib/molecule3d/ui/Molecule3DToolbar.d.ts.map +1 -1
  107. package/lib/molecule3d/ui/Molecule3DToolbar.js +1 -1
  108. package/lib/molecule3d/ui/Molecule3DToolbar.js.map +1 -1
  109. package/lib/molecule3d/ui/MoleculeCanvas3D.d.ts.map +1 -1
  110. package/lib/molecule3d/ui/MoleculeCanvas3D.js +3 -2
  111. package/lib/molecule3d/ui/MoleculeCanvas3D.js.map +1 -1
  112. package/lib/molecule3d/ui/drawScene.d.ts +4 -3
  113. package/lib/molecule3d/ui/drawScene.d.ts.map +1 -1
  114. package/lib/molecule3d/ui/drawScene.js +12 -2
  115. package/lib/molecule3d/ui/drawScene.js.map +1 -1
  116. package/lib/molecule3d/ui/moleculeFileFormats.d.ts +3 -2
  117. package/lib/molecule3d/ui/moleculeFileFormats.d.ts.map +1 -1
  118. package/lib/molecule3d/ui/moleculeFileFormats.js +5 -3
  119. package/lib/molecule3d/ui/moleculeFileFormats.js.map +1 -1
  120. package/lib/molecule3d/ui/moleculeViewer3DProps.d.ts +2 -1
  121. package/lib/molecule3d/ui/moleculeViewer3DProps.d.ts.map +1 -1
  122. package/lib/molecule3d/ui/partialBondShapes.d.ts +117 -0
  123. package/lib/molecule3d/ui/partialBondShapes.d.ts.map +1 -0
  124. package/lib/molecule3d/ui/partialBondShapes.js +164 -0
  125. package/lib/molecule3d/ui/partialBondShapes.js.map +1 -0
  126. package/lib/molecule3d/ui/renderMolecule.d.ts +9 -0
  127. package/lib/molecule3d/ui/renderMolecule.d.ts.map +1 -1
  128. package/lib/molecule3d/ui/renderMolecule.js +17 -0
  129. package/lib/molecule3d/ui/renderMolecule.js.map +1 -1
  130. package/lib/molecule3d/ui/renderPartialBonds.d.ts +19 -0
  131. package/lib/molecule3d/ui/renderPartialBonds.d.ts.map +1 -0
  132. package/lib/molecule3d/ui/renderPartialBonds.js +90 -0
  133. package/lib/molecule3d/ui/renderPartialBonds.js.map +1 -0
  134. package/lib/molecule3d/ui/structureGeometry.d.ts +22 -0
  135. package/lib/molecule3d/ui/structureGeometry.d.ts.map +1 -0
  136. package/lib/molecule3d/ui/structureGeometry.js +63 -0
  137. package/lib/molecule3d/ui/structureGeometry.js.map +1 -0
  138. package/lib/molecule3d/ui/usePolarSurfaceArea.d.ts +2 -2
  139. package/lib/molecule3d/ui/usePolarSurfaceArea.d.ts.map +1 -1
  140. package/lib/molecule3d/ui/usePolarSurfaceArea.js +5 -4
  141. package/lib/molecule3d/ui/usePolarSurfaceArea.js.map +1 -1
  142. package/lib/molecule3d/ui/viewer.d.ts +8 -1
  143. package/lib/molecule3d/ui/viewer.d.ts.map +1 -1
  144. package/lib/molecule3d/ui/viewer.js +10 -0
  145. package/lib/molecule3d/ui/viewer.js.map +1 -1
  146. package/lib/molecule3d/ui/viewerTypes.d.ts +18 -0
  147. package/lib/molecule3d/ui/viewerTypes.d.ts.map +1 -1
  148. package/lib/panel/ui/FilterInput.d.ts +11 -0
  149. package/lib/panel/ui/FilterInput.d.ts.map +1 -1
  150. package/lib/panel/ui/FilterInput.js +10 -1
  151. package/lib/panel/ui/FilterInput.js.map +1 -1
  152. package/lib/shell/ui/ShellFrame.d.ts.map +1 -1
  153. package/lib/shell/ui/ShellFrame.js +3 -2
  154. package/lib/shell/ui/ShellFrame.js.map +1 -1
  155. package/package.json +1 -1
  156. package/src/credits/core/credits.ts +16 -0
  157. package/src/crystal3d/ui/CrystalCanvas3D.tsx +1 -1
  158. package/src/crystal3d/ui/CrystalViewer3D.tsx +1 -1
  159. package/src/crystal3d/ui/crystalStructureViewerProps.ts +1 -1
  160. package/src/download/ui/FigureDownloadPanel.tsx +20 -4
  161. package/src/download/ui/FigureQuickActions.tsx +18 -6
  162. package/src/drawing/ui/ZoomControl.tsx +33 -8
  163. package/src/ecosystem/core/home.ts +27 -0
  164. package/src/ecosystem/core/index.ts +7 -0
  165. package/src/ecosystem/core/searchSites.ts +102 -0
  166. package/src/ecosystem/core/types.ts +1 -0
  167. package/src/ecosystem/core/unlistedSites.ts +15 -0
  168. package/src/ecosystem/ui/EcosystemButton.tsx +8 -2
  169. package/src/ecosystem/ui/EcosystemMenu.tsx +103 -7
  170. package/src/ecosystem/ui/SiteGroupGrid.tsx +28 -3
  171. package/src/ecosystem/ui/glyphs.tsx +14 -0
  172. package/src/locales/de.json +10 -0
  173. package/src/locales/en.json +10 -0
  174. package/src/locales/es.json +10 -0
  175. package/src/locales/fr.json +10 -0
  176. package/src/locales/it.json +10 -0
  177. package/src/molecule3d/core/bondNeighbours.ts +108 -0
  178. package/src/molecule3d/core/file.ts +18 -4
  179. package/src/molecule3d/core/index.ts +17 -3
  180. package/src/molecule3d/core/partialBondMode.ts +48 -0
  181. package/src/molecule3d/core/partialBondRanges.ts +120 -0
  182. package/src/molecule3d/core/partialBonds.ts +180 -0
  183. package/src/molecule3d/core/settings.ts +29 -52
  184. package/src/molecule3d/core/tools.ts +51 -0
  185. package/src/molecule3d/ui/Molecule3DExport.tsx +17 -2
  186. package/src/molecule3d/ui/Molecule3DOptions.tsx +16 -3
  187. package/src/molecule3d/ui/Molecule3DPartialBonds.tsx +100 -0
  188. package/src/molecule3d/ui/Molecule3DToolbar.tsx +2 -2
  189. package/src/molecule3d/ui/MoleculeCanvas3D.tsx +3 -4
  190. package/src/molecule3d/ui/drawScene.ts +15 -2
  191. package/src/molecule3d/ui/moleculeFileFormats.ts +5 -3
  192. package/src/molecule3d/ui/moleculeViewer3DProps.ts +2 -1
  193. package/src/molecule3d/ui/partialBondShapes.ts +246 -0
  194. package/src/molecule3d/ui/renderMolecule.ts +20 -0
  195. package/src/molecule3d/ui/renderPartialBonds.ts +122 -0
  196. package/src/molecule3d/ui/structureGeometry.ts +73 -0
  197. package/src/molecule3d/ui/usePolarSurfaceArea.ts +5 -4
  198. package/src/molecule3d/ui/viewer.ts +12 -0
  199. package/src/molecule3d/ui/viewerTypes.ts +19 -0
  200. package/src/panel/ui/FilterInput.tsx +24 -0
  201. package/src/shell/ui/ShellFrame.tsx +7 -1
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Which buttons the toolbar over the 3D molecule canvas shows, free of React
3
+ * and molstar so a site can persist them.
4
+ */
5
+
6
+ /** Which buttons the toolbar over the canvas shows. */
7
+ export interface Molecule3DTools {
8
+ /** Distance, angle and dihedral tools, and a button removing them all. */
9
+ measure: boolean;
10
+ /** A popover with the representation, the size and the surface sliders. */
11
+ options: boolean;
12
+ /** A toggle turning the model on its own. */
13
+ spin: boolean;
14
+ /** A toggle drawing the molecular surface. */
15
+ surface: boolean;
16
+ /** A button framing the model again. */
17
+ reset: boolean;
18
+ /** A popover saving the picture as a PNG or an SVG. */
19
+ export: boolean;
20
+ /**
21
+ * A toggle filling the screen with the canvas and its toolbars. It is left
22
+ * out where the browser cannot fill the screen, as on an iPhone or in a
23
+ * frame not allowed to.
24
+ */
25
+ fullscreen: boolean;
26
+ /** A popover listing what the mouse and the keyboard do on the canvas. */
27
+ help: boolean;
28
+ }
29
+
30
+ /** Every tool on. */
31
+ export const DEFAULT_MOLECULE_3D_TOOLS: Molecule3DTools = {
32
+ measure: true,
33
+ options: true,
34
+ spin: true,
35
+ surface: true,
36
+ reset: true,
37
+ export: true,
38
+ fullscreen: true,
39
+ help: true,
40
+ };
41
+
42
+ /**
43
+ * Complete a partial tool selection.
44
+ * @param tools - The tools a site switched on or off.
45
+ * @returns Every tool, those not named left on.
46
+ */
47
+ export function resolveMolecule3DTools(
48
+ tools: Partial<Molecule3DTools> = {},
49
+ ): Molecule3DTools {
50
+ return { ...DEFAULT_MOLECULE_3D_TOOLS, ...tools };
51
+ }
@@ -7,6 +7,7 @@
7
7
  import type { ReactElement } from 'react';
8
8
  import { useCallback, useState } from 'react';
9
9
 
10
+ import { writeToClipboard } from '../../clipboard/core/writeToClipboard.ts';
10
11
  import type { FigureNotice } from '../../download/core/copyFigure.ts';
11
12
  import type { FigureFormat } from '../../download/core/downloadFigure.ts';
12
13
  import {
@@ -99,7 +100,8 @@ export function Molecule3DExport(props: Molecule3DExportProps): ReactElement {
99
100
  const versions = moleculeFileChoices(atoms, t);
100
101
  const writtenVersion = versions[0]?.disabled ? 'molfileV3000' : version;
101
102
 
102
- // Written once picked, so Save has it at hand.
103
+ // Written once picked rather than on the press: Safari only allows a
104
+ // clipboard write the click itself started, and Save has it at hand too.
103
105
  const written = useAsync(
104
106
  useCallback(
105
107
  () =>
@@ -110,6 +112,12 @@ export function Molecule3DExport(props: Molecule3DExportProps): ReactElement {
110
112
  ),
111
113
  );
112
114
  const text = written.pending ? null : written.data;
115
+ const versionLabel = writtenVersion === 'molfileV3000' ? 'V3000' : 'V2000';
116
+
117
+ async function copyMolfile(molfileText: string): Promise<FigureNotice> {
118
+ if (await writeToClipboard(molfileText)) return 'copied';
119
+ throw new Error(t('clipboard.failed'));
120
+ }
113
121
 
114
122
  // What the last copy came to only describes the choices it was made with.
115
123
  function changed<T>(apply: (value: T) => void): (value: T) => void {
@@ -134,6 +142,12 @@ export function Molecule3DExport(props: Molecule3DExportProps): ReactElement {
134
142
  value: file,
135
143
  onChange: changed(setFile),
136
144
  hint: t('molecule3d.molfileHint', { count: atoms }),
145
+ copy: {
146
+ ready: t('molecule3d.copyMolfile', { version: versionLabel }),
147
+ copied: t('molecule3d.copiedMolfile', {
148
+ version: versionLabel,
149
+ }),
150
+ },
137
151
  }
138
152
  : undefined
139
153
  }
@@ -155,7 +169,8 @@ export function Molecule3DExport(props: Molecule3DExportProps): ReactElement {
155
169
  }
156
170
  }}
157
171
  onCopy={() => {
158
- run(onCopy(scale));
172
+ if (file === null) run(onCopy(scale));
173
+ else if (text) run(copyMolfile(text));
159
174
  }}
160
175
  onSend={
161
176
  writeFile === undefined
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The display options of the molecule viewer, shown in the toolbar's popover:
3
- * the representation, the size, and the surface's opacity, solvent probe and
4
- * colours, with a button returning them all to the defaults.
3
+ * the representation, the size, the partial bonds, and the surface's opacity,
4
+ * solvent probe and colours, with a button returning them all to the defaults.
5
5
  */
6
6
 
7
7
  import { Button, SegmentedControl, Slider } from '@blueprintjs/core';
@@ -9,6 +9,7 @@ import type { CSSProperties, ReactElement } from 'react';
9
9
 
10
10
  import { formatDecimal } from '../../format/core/numbers.ts';
11
11
  import { useChromeT } from '../../i18n/ui/useT.ts';
12
+ import type { Molecule3DFile } from '../core/file.ts';
12
13
  import type { Molecule3DSettings } from '../core/settings.ts';
13
14
  import {
14
15
  MOLECULE_3D_RANGES,
@@ -19,6 +20,7 @@ import {
19
20
  sameMolecule3DSettings,
20
21
  } from '../core/settings.ts';
21
22
 
23
+ import { Molecule3DPartialBonds } from './Molecule3DPartialBonds.tsx';
22
24
  import { Molecule3DSurfaceColors } from './Molecule3DSurfaceColors.tsx';
23
25
 
24
26
  /** Props of {@link Molecule3DOptions}. */
@@ -29,6 +31,8 @@ export interface Molecule3DOptionsProps {
29
31
  polarSurfaceArea: number | null;
30
32
  /** What the reset button returns to; `showSurface` is left as it is. */
31
33
  defaults: Molecule3DSettings;
34
+ /** The format of the file on screen, which decides the partial bonds' `auto`. */
35
+ format: Molecule3DFile['format'];
32
36
  }
33
37
 
34
38
  /**
@@ -37,7 +41,7 @@ export interface Molecule3DOptionsProps {
37
41
  * @returns The panel.
38
42
  */
39
43
  export function Molecule3DOptions(props: Molecule3DOptionsProps): ReactElement {
40
- const { settings, onChange, polarSurfaceArea, defaults } = props;
44
+ const { settings, onChange, polarSurfaceArea, defaults, format } = props;
41
45
  const t = useChromeT();
42
46
  const reset = resetMolecule3DSettings(settings, defaults);
43
47
  const atDefaults = sameMolecule3DSettings(settings, reset);
@@ -73,6 +77,13 @@ export function Molecule3DOptions(props: Molecule3DOptionsProps): ReactElement {
73
77
  onChange({ ...settings, sizeFactor });
74
78
  }}
75
79
  />
80
+ <div style={FULL_ROW_STYLE}>
81
+ <Molecule3DPartialBonds
82
+ settings={settings}
83
+ onChange={onChange}
84
+ format={format}
85
+ />
86
+ </div>
76
87
  {settings.showSurface ? null : (
77
88
  <span style={SURFACE_OFF_STYLE} data-testid="molecule3d-surface-off">
78
89
  {t('molecule3d.surfaceOff')}
@@ -194,6 +205,8 @@ const GRID_STYLE: CSSProperties = {
194
205
 
195
206
  const LABEL_STYLE: CSSProperties = { fontSize: 12 };
196
207
 
208
+ const FULL_ROW_STYLE: CSSProperties = { gridColumn: '1 / -1' };
209
+
197
210
  /** Spans the grid, between the size and the surface rows it explains. */
198
211
  const SURFACE_OFF_STYLE: CSSProperties = {
199
212
  display: 'flex',
@@ -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/settings.ts';
20
- import { resolveMolecule3DTools } from '../core/settings.ts';
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
- normalizeMolecule3DSettings,
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 surface and the
21
- * measurements are added after the model, and the camera is framed last.
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 connection table of a single model, so neither an XYZ,
34
- * which has no bonds, nor a series of frames, which is not one molecule.
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 === 'xyz' || frameCount > 1) return 0;
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, Molecule3DTools } from '../core/settings.ts';
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