react-cheminfo 0.29.0 → 0.31.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/README.md +62 -2
- package/lib/chrome/ui/AccountButton.d.ts +76 -0
- package/lib/chrome/ui/AccountButton.d.ts.map +1 -0
- package/lib/chrome/ui/AccountButton.js +66 -0
- package/lib/chrome/ui/AccountButton.js.map +1 -0
- package/lib/chrome/ui/index.d.ts +2 -0
- package/lib/chrome/ui/index.d.ts.map +1 -1
- package/lib/chrome/ui/index.js +1 -0
- package/lib/chrome/ui/index.js.map +1 -1
- package/lib/clipboard/ui/ClickToCopy.d.ts +6 -0
- package/lib/clipboard/ui/ClickToCopy.d.ts.map +1 -1
- package/lib/clipboard/ui/ClickToCopy.js +3 -3
- package/lib/clipboard/ui/ClickToCopy.js.map +1 -1
- package/lib/download/core/downloadFigure.d.ts +7 -5
- package/lib/download/core/downloadFigure.d.ts.map +1 -1
- package/lib/download/core/downloadFigure.js +7 -6
- package/lib/download/core/downloadFigure.js.map +1 -1
- package/lib/download/core/figureLayout.d.ts +55 -0
- package/lib/download/core/figureLayout.d.ts.map +1 -0
- package/lib/download/core/figureLayout.js +89 -0
- package/lib/download/core/figureLayout.js.map +1 -0
- package/lib/download/core/figureScale.d.ts +9 -0
- package/lib/download/core/figureScale.d.ts.map +1 -1
- package/lib/download/core/figureScale.js +10 -0
- package/lib/download/core/figureScale.js.map +1 -1
- package/lib/download/core/figureSettle.d.ts +51 -0
- package/lib/download/core/figureSettle.d.ts.map +1 -0
- package/lib/download/core/figureSettle.js +81 -0
- package/lib/download/core/figureSettle.js.map +1 -0
- package/lib/download/core/figureSvg.d.ts +7 -1
- package/lib/download/core/figureSvg.d.ts.map +1 -1
- package/lib/download/core/figureSvg.js +1 -0
- package/lib/download/core/figureSvg.js.map +1 -1
- package/lib/download/core/figureSvgDocument.d.ts +7 -0
- package/lib/download/core/figureSvgDocument.d.ts.map +1 -1
- package/lib/download/core/figureSvgDocument.js +11 -2
- package/lib/download/core/figureSvgDocument.js.map +1 -1
- package/lib/download/core/index.d.ts +5 -1
- package/lib/download/core/index.d.ts.map +1 -1
- package/lib/download/core/index.js +3 -1
- package/lib/download/core/index.js.map +1 -1
- package/lib/download/ui/FigureDownload.d.ts +18 -4
- package/lib/download/ui/FigureDownload.d.ts.map +1 -1
- package/lib/download/ui/FigureDownload.js +35 -9
- package/lib/download/ui/FigureDownload.js.map +1 -1
- package/lib/download/ui/FigureDownloadPanel.d.ts +17 -7
- package/lib/download/ui/FigureDownloadPanel.d.ts.map +1 -1
- package/lib/download/ui/FigureDownloadPanel.js +30 -22
- package/lib/download/ui/FigureDownloadPanel.js.map +1 -1
- package/lib/download/ui/FigureSizeField.d.ts +27 -0
- package/lib/download/ui/FigureSizeField.d.ts.map +1 -0
- package/lib/download/ui/FigureSizeField.js +87 -0
- package/lib/download/ui/FigureSizeField.js.map +1 -0
- package/lib/download/ui/FigureSizeRows.d.ts +34 -0
- package/lib/download/ui/FigureSizeRows.d.ts.map +1 -0
- package/lib/download/ui/FigureSizeRows.js +54 -0
- package/lib/download/ui/FigureSizeRows.js.map +1 -0
- package/lib/download/ui/index.d.ts +2 -0
- package/lib/download/ui/index.d.ts.map +1 -1
- package/lib/download/ui/index.js.map +1 -1
- package/lib/download/ui/useFigureRedraw.d.ts +27 -0
- package/lib/download/ui/useFigureRedraw.d.ts.map +1 -0
- package/lib/download/ui/useFigureRedraw.js +78 -0
- package/lib/download/ui/useFigureRedraw.js.map +1 -0
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +13 -2
- package/lib/locales/en.json +13 -2
- package/lib/locales/es.json +13 -2
- package/lib/locales/fr.json +13 -2
- package/lib/overlay/ui/OverlayValueMenu.d.ts.map +1 -1
- package/lib/overlay/ui/OverlayValueMenu.js +7 -1
- package/lib/overlay/ui/OverlayValueMenu.js.map +1 -1
- package/lib/structure/core/conformerBoltzmann.d.ts +56 -0
- package/lib/structure/core/conformerBoltzmann.d.ts.map +1 -0
- package/lib/structure/core/conformerBoltzmann.js +96 -0
- package/lib/structure/core/conformerBoltzmann.js.map +1 -0
- package/lib/structure/core/conformerEnergy.d.ts +69 -0
- package/lib/structure/core/conformerEnergy.d.ts.map +1 -0
- package/lib/structure/core/conformerEnergy.js +47 -0
- package/lib/structure/core/conformerEnergy.js.map +1 -0
- package/lib/structure/core/index.d.ts +3 -0
- package/lib/structure/core/index.d.ts.map +1 -1
- package/lib/structure/core/index.js +2 -0
- package/lib/structure/core/index.js.map +1 -1
- package/lib/structure/ui/ConformerTable.d.ts +73 -0
- package/lib/structure/ui/ConformerTable.d.ts.map +1 -0
- package/lib/structure/ui/ConformerTable.js +259 -0
- package/lib/structure/ui/ConformerTable.js.map +1 -0
- package/lib/structure/ui/conformerColumns.d.ts +30 -0
- package/lib/structure/ui/conformerColumns.d.ts.map +1 -0
- package/lib/structure/ui/conformerColumns.js +37 -0
- package/lib/structure/ui/conformerColumns.js.map +1 -0
- package/lib/ui.d.ts +4 -0
- package/lib/ui.d.ts.map +1 -1
- package/lib/ui.js +2 -0
- package/lib/ui.js.map +1 -1
- package/package.json +1 -1
- package/src/chrome/ui/AccountButton.tsx +185 -0
- package/src/chrome/ui/index.ts +2 -0
- package/src/clipboard/ui/ClickToCopy.tsx +9 -1
- package/src/download/core/downloadFigure.ts +12 -9
- package/src/download/core/figureLayout.ts +114 -0
- package/src/download/core/figureScale.ts +13 -0
- package/src/download/core/figureSettle.ts +112 -0
- package/src/download/core/figureSvg.ts +8 -1
- package/src/download/core/figureSvgDocument.ts +19 -2
- package/src/download/core/index.ts +13 -0
- package/src/download/ui/FigureDownload.tsx +88 -35
- package/src/download/ui/FigureDownloadPanel.tsx +45 -22
- package/src/download/ui/FigureSizeField.tsx +153 -0
- package/src/download/ui/FigureSizeRows.tsx +108 -0
- package/src/download/ui/index.ts +2 -0
- package/src/download/ui/useFigureRedraw.tsx +115 -0
- package/src/locales/de.json +13 -2
- package/src/locales/en.json +13 -2
- package/src/locales/es.json +13 -2
- package/src/locales/fr.json +13 -2
- package/src/overlay/ui/OverlayValueMenu.tsx +7 -1
- package/src/structure/core/conformerBoltzmann.ts +102 -0
- package/src/structure/core/conformerEnergy.ts +97 -0
- package/src/structure/core/index.ts +15 -0
- package/src/structure/ui/ConformerTable.tsx +429 -0
- package/src/structure/ui/conformerColumns.ts +55 -0
- package/src/ui.ts +12 -0
- package/styles/chrome.css +55 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A conformer set, most stable first, as a table one row of which is selected.
|
|
3
|
+
*
|
|
4
|
+
* Two sites read the same set for different reasons — one picks the geometry a
|
|
5
|
+
* calculation runs on, the other reads the ranking itself — so the columns are
|
|
6
|
+
* a prop rather than a variant. Everything else is the same table: rows ordered
|
|
7
|
+
* by energy, one selected, the arrows walking it.
|
|
8
|
+
*
|
|
9
|
+
* The population column is the reason the ranking matters. A share is
|
|
10
|
+
* exponential in the energy gap, so it inherits the error of whatever produced
|
|
11
|
+
* the energies and magnifies it; the caption under the table says which method
|
|
12
|
+
* that was, and `boltzmannConfidence` says what its error is worth. A table
|
|
13
|
+
* that prints a force field's populations without that line is stating a
|
|
14
|
+
* percentage it cannot support.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { HTMLTable } from '@blueprintjs/core';
|
|
18
|
+
import type { CSSProperties, KeyboardEvent, ReactElement } from 'react';
|
|
19
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
20
|
+
|
|
21
|
+
import { ClickToCopy } from '../../clipboard/ui/ClickToCopy.tsx';
|
|
22
|
+
import { formatPercent } from '../../format/core/numbers.ts';
|
|
23
|
+
import { handleListNavigationKey } from '../../hooks/ui/listNavigation.ts';
|
|
24
|
+
import {
|
|
25
|
+
ROOM_TEMPERATURE,
|
|
26
|
+
boltzmannShares,
|
|
27
|
+
} from '../core/conformerBoltzmann.ts';
|
|
28
|
+
import type { ConformerRow } from '../core/conformerEnergy.ts';
|
|
29
|
+
import { relativeEnergyOf, totalEnergyOf } from '../core/conformerEnergy.ts';
|
|
30
|
+
import type { ConformerRanking } from '../core/conformers.ts';
|
|
31
|
+
|
|
32
|
+
import type { ConformerColumn } from './conformerColumns.ts';
|
|
33
|
+
import {
|
|
34
|
+
CONFORMER_COLUMN_LABELS,
|
|
35
|
+
NUMERIC_CONFORMER_COLUMNS,
|
|
36
|
+
PICKER_COLUMNS,
|
|
37
|
+
} from './conformerColumns.ts';
|
|
38
|
+
|
|
39
|
+
/** Props of {@link ConformerTable}. */
|
|
40
|
+
export interface ConformerTableProps {
|
|
41
|
+
/** The set, already ordered most stable first. */
|
|
42
|
+
conformers: readonly ConformerRow[];
|
|
43
|
+
/**
|
|
44
|
+
* Which columns to draw, in order.
|
|
45
|
+
* @default PICKER_COLUMNS
|
|
46
|
+
*/
|
|
47
|
+
columns?: readonly ConformerColumn[];
|
|
48
|
+
/**
|
|
49
|
+
* Which method's energies every column reads.
|
|
50
|
+
* @default 'force-field'
|
|
51
|
+
*/
|
|
52
|
+
ranking?: ConformerRanking;
|
|
53
|
+
/**
|
|
54
|
+
* The selected conformer's id, or `null` when none is.
|
|
55
|
+
* @default null
|
|
56
|
+
*/
|
|
57
|
+
selectedId?: number | null;
|
|
58
|
+
/** Called with the id of the row the reader picked. */
|
|
59
|
+
onSelect?: (id: number) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Temperature the shares are quoted at, in kelvin.
|
|
62
|
+
* @default ROOM_TEMPERATURE
|
|
63
|
+
*/
|
|
64
|
+
temperature?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Accessible name of the table.
|
|
67
|
+
* @default 'Conformers, most stable first'
|
|
68
|
+
*/
|
|
69
|
+
label?: string;
|
|
70
|
+
/**
|
|
71
|
+
* What the `id` column says for a conformer. A dense table wants the bare
|
|
72
|
+
* rank; a picker in a narrow column reads better naming the thing.
|
|
73
|
+
* @default String — the rank on its own
|
|
74
|
+
*/
|
|
75
|
+
rowName?: (id: number) => string;
|
|
76
|
+
/**
|
|
77
|
+
* Headings to use instead of the default ones, per column.
|
|
78
|
+
* @default undefined — every column keeps its own
|
|
79
|
+
*/
|
|
80
|
+
columnLabels?: Partial<Record<ConformerColumn, string>>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The conformers of a set, as a selectable table.
|
|
85
|
+
*
|
|
86
|
+
* The arrows walk the rows once the table has the focus, rather than from
|
|
87
|
+
* anywhere on the page: a conformer list usually sits beside a drawing surface
|
|
88
|
+
* or a 3D canvas, both of which read the arrows themselves.
|
|
89
|
+
* @param props - See {@link ConformerTableProps}.
|
|
90
|
+
* @returns The table, or `null` when there is nothing to show.
|
|
91
|
+
*/
|
|
92
|
+
export function ConformerTable(
|
|
93
|
+
props: ConformerTableProps,
|
|
94
|
+
): ReactElement | null {
|
|
95
|
+
const {
|
|
96
|
+
conformers,
|
|
97
|
+
columns = PICKER_COLUMNS,
|
|
98
|
+
ranking = 'force-field',
|
|
99
|
+
selectedId = null,
|
|
100
|
+
onSelect,
|
|
101
|
+
temperature = ROOM_TEMPERATURE,
|
|
102
|
+
label = 'Conformers, most stable first',
|
|
103
|
+
rowName = String,
|
|
104
|
+
columnLabels,
|
|
105
|
+
} = props;
|
|
106
|
+
|
|
107
|
+
const bodyRef = useRef<HTMLTableSectionElement>(null);
|
|
108
|
+
|
|
109
|
+
const shares = useMemo(() => {
|
|
110
|
+
if (!columns.includes('population')) return [];
|
|
111
|
+
const energies = new Array<number | null>(conformers.length);
|
|
112
|
+
for (let index = 0; index < conformers.length; index++) {
|
|
113
|
+
const conformer = conformers[index];
|
|
114
|
+
energies[index] =
|
|
115
|
+
conformer === undefined ? null : relativeEnergyOf(conformer, ranking);
|
|
116
|
+
}
|
|
117
|
+
return boltzmannShares(energies, temperature);
|
|
118
|
+
}, [conformers, columns, ranking, temperature]);
|
|
119
|
+
|
|
120
|
+
const largestShare = useMemo(() => {
|
|
121
|
+
let largest = 0;
|
|
122
|
+
for (const share of shares) {
|
|
123
|
+
if (share != null && share > largest) largest = share;
|
|
124
|
+
}
|
|
125
|
+
return largest;
|
|
126
|
+
}, [shares]);
|
|
127
|
+
|
|
128
|
+
// The picked row is brought into view rather than left under the fold, which
|
|
129
|
+
// is what makes walking a long set with the arrows usable.
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (bodyRef.current === null || selectedId === null) return;
|
|
132
|
+
bodyRef.current
|
|
133
|
+
.querySelector('[aria-selected="true"]')
|
|
134
|
+
?.scrollIntoView({ block: 'nearest' });
|
|
135
|
+
}, [selectedId]);
|
|
136
|
+
|
|
137
|
+
if (conformers.length === 0) return null;
|
|
138
|
+
|
|
139
|
+
function onKeyDown(event: KeyboardEvent<HTMLTableSectionElement>): void {
|
|
140
|
+
if (onSelect === undefined) return;
|
|
141
|
+
handleListNavigationKey(event, {
|
|
142
|
+
length: conformers.length,
|
|
143
|
+
selectedIndex: conformers.findIndex(
|
|
144
|
+
(conformer) => conformer.id === selectedId,
|
|
145
|
+
),
|
|
146
|
+
onSelect: (index) => {
|
|
147
|
+
const conformer = conformers[index];
|
|
148
|
+
if (conformer !== undefined) onSelect(conformer.id);
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<HTMLTable compact interactive striped style={tableStyle}>
|
|
155
|
+
<thead>
|
|
156
|
+
<tr>
|
|
157
|
+
{columns.map((column) => (
|
|
158
|
+
<th key={column} style={headerStyle(column)}>
|
|
159
|
+
{columnLabels?.[column] ?? CONFORMER_COLUMN_LABELS[column]}
|
|
160
|
+
</th>
|
|
161
|
+
))}
|
|
162
|
+
</tr>
|
|
163
|
+
</thead>
|
|
164
|
+
<tbody
|
|
165
|
+
ref={bodyRef}
|
|
166
|
+
onKeyDown={onKeyDown}
|
|
167
|
+
// Reached by Tab and then walked with the arrows: the surfaces beside a
|
|
168
|
+
// conformer list read the arrows themselves.
|
|
169
|
+
tabIndex={onSelect === undefined ? undefined : 0}
|
|
170
|
+
role="listbox"
|
|
171
|
+
aria-label={label}
|
|
172
|
+
>
|
|
173
|
+
{conformers.map((conformer, index) => {
|
|
174
|
+
const active = conformer.id === selectedId;
|
|
175
|
+
const copyableHere = onSelect === undefined || active;
|
|
176
|
+
return (
|
|
177
|
+
<tr
|
|
178
|
+
key={conformer.id}
|
|
179
|
+
data-testid="conformer-row"
|
|
180
|
+
data-conformer-id={String(conformer.id)}
|
|
181
|
+
role="option"
|
|
182
|
+
aria-selected={active}
|
|
183
|
+
// `aria-selected` is the contract for a reader; `data-selected`
|
|
184
|
+
// is the one an end-to-end suite can select on without asserting
|
|
185
|
+
// against the accessibility tree.
|
|
186
|
+
data-selected={active ? 'true' : 'false'}
|
|
187
|
+
style={rowStyle(active, onSelect !== undefined)}
|
|
188
|
+
onClick={() => onSelect?.(conformer.id)}
|
|
189
|
+
>
|
|
190
|
+
{columns.map((column) => {
|
|
191
|
+
const content = cellContent(
|
|
192
|
+
column,
|
|
193
|
+
conformer,
|
|
194
|
+
ranking,
|
|
195
|
+
shares[index] ?? null,
|
|
196
|
+
largestShare,
|
|
197
|
+
rowName,
|
|
198
|
+
);
|
|
199
|
+
// An energy is a value a reader takes away; a rank and a bar
|
|
200
|
+
// are not. A copy stops the click at the cell, so only the row
|
|
201
|
+
// already selected offers one: on any other row the click has
|
|
202
|
+
// to reach the row and select it, which is what a reader means
|
|
203
|
+
// by clicking a conformer they are not on.
|
|
204
|
+
return copyableHere &&
|
|
205
|
+
COPY_LABELS[column] !== undefined &&
|
|
206
|
+
typeof content === 'string' &&
|
|
207
|
+
content !== '—' ? (
|
|
208
|
+
<ClickToCopy
|
|
209
|
+
key={column}
|
|
210
|
+
as="td"
|
|
211
|
+
style={cellStyle(column)}
|
|
212
|
+
value={content}
|
|
213
|
+
label={COPY_LABELS[column]}
|
|
214
|
+
testId={CELL_TEST_IDS[column]}
|
|
215
|
+
>
|
|
216
|
+
{content}
|
|
217
|
+
</ClickToCopy>
|
|
218
|
+
) : (
|
|
219
|
+
<td
|
|
220
|
+
key={column}
|
|
221
|
+
style={cellStyle(column)}
|
|
222
|
+
data-testid={CELL_TEST_IDS[column]}
|
|
223
|
+
>
|
|
224
|
+
{content}
|
|
225
|
+
</td>
|
|
226
|
+
);
|
|
227
|
+
})}
|
|
228
|
+
</tr>
|
|
229
|
+
);
|
|
230
|
+
})}
|
|
231
|
+
</tbody>
|
|
232
|
+
</HTMLTable>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* What a copyable column is called in the hover title, and which columns are
|
|
238
|
+
* copyable at all.
|
|
239
|
+
*
|
|
240
|
+
* Only the relative energy: it is the number a chemist reads off the set and
|
|
241
|
+
* quotes elsewhere. A total force-field energy is an internal quantity nobody
|
|
242
|
+
* pastes, and a rank and a share are read on the page rather than taken away.
|
|
243
|
+
*/
|
|
244
|
+
const COPY_LABELS: Partial<Record<ConformerColumn, string>> = {
|
|
245
|
+
relative: 'relative energy in kcal/mol',
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* A stable hook per cell, so a suite can read one column without counting
|
|
250
|
+
* table cells — which changes the moment a column is added.
|
|
251
|
+
*/
|
|
252
|
+
const CELL_TEST_IDS: Record<ConformerColumn, string> = {
|
|
253
|
+
id: 'conformer-id',
|
|
254
|
+
population: 'conformer-population',
|
|
255
|
+
relative: 'conformer-relative-energy',
|
|
256
|
+
total: 'conformer-total-energy',
|
|
257
|
+
forceFieldRelative: 'conformer-force-field-relative',
|
|
258
|
+
forceFieldRank: 'conformer-force-field-rank',
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* The share of a conformer, drawn as a bar.
|
|
263
|
+
*
|
|
264
|
+
* It takes its colour from the row it sits in — `currentColor` — so it is
|
|
265
|
+
* legible on a plain row and on the selected one without a rule per state.
|
|
266
|
+
*
|
|
267
|
+
* It is drawn against the largest share rather than against the whole: the
|
|
268
|
+
* column is narrow, and against the whole a set of twelve near-equal conformers
|
|
269
|
+
* would be twelve bars of three pixels.
|
|
270
|
+
* @param props - The share to draw, against the largest one in the set.
|
|
271
|
+
* @param props.share - The share from 0 to 1, or `null` when there is no energy.
|
|
272
|
+
* @param props.largest - The largest share in the set, which is the full width.
|
|
273
|
+
* @returns The bar.
|
|
274
|
+
*/
|
|
275
|
+
function ShareBar(props: {
|
|
276
|
+
share: number | null;
|
|
277
|
+
largest: number;
|
|
278
|
+
}): ReactElement {
|
|
279
|
+
const { share, largest } = props;
|
|
280
|
+
const width =
|
|
281
|
+
share === null || largest <= 0
|
|
282
|
+
? 0
|
|
283
|
+
: Math.max(0, Math.min(1, share / largest)) * 100;
|
|
284
|
+
return (
|
|
285
|
+
<span style={barTrackStyle} aria-hidden="true">
|
|
286
|
+
<span style={{ ...barFillStyle, width: `${width}%` }} />
|
|
287
|
+
</span>
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function cellContent(
|
|
292
|
+
column: ConformerColumn,
|
|
293
|
+
conformer: ConformerRow,
|
|
294
|
+
ranking: ConformerRanking,
|
|
295
|
+
share: number | null,
|
|
296
|
+
largest: number,
|
|
297
|
+
rowName: (id: number) => string,
|
|
298
|
+
): ReactElement | string {
|
|
299
|
+
switch (column) {
|
|
300
|
+
case 'id':
|
|
301
|
+
return rowName(conformer.id);
|
|
302
|
+
case 'population':
|
|
303
|
+
return (
|
|
304
|
+
<span style={populationStyle}>
|
|
305
|
+
<ShareBar share={share} largest={largest} />
|
|
306
|
+
<span>{shareLabel(share)}</span>
|
|
307
|
+
</span>
|
|
308
|
+
);
|
|
309
|
+
case 'relative':
|
|
310
|
+
return energyLabel(relativeEnergyOf(conformer, ranking));
|
|
311
|
+
case 'total':
|
|
312
|
+
return energyLabel(totalEnergyOf(conformer, ranking));
|
|
313
|
+
case 'forceFieldRelative':
|
|
314
|
+
return energyLabel(conformer.relativeEnergy);
|
|
315
|
+
case 'forceFieldRank':
|
|
316
|
+
return conformer.refinement == null
|
|
317
|
+
? '—'
|
|
318
|
+
: String(conformer.refinement.forceFieldId);
|
|
319
|
+
default:
|
|
320
|
+
return '—';
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* The share of molecules in a conformer, as a percentage.
|
|
326
|
+
*
|
|
327
|
+
* A share that rounds to zero is written as `<0.1 %` instead: a conformer the
|
|
328
|
+
* search found and kept is populated by something, and `0 %` says it is not.
|
|
329
|
+
* @param share - The share from 0 to 1, or `null` when there is no energy.
|
|
330
|
+
* @returns The percentage, or a dash when it cannot be worked out.
|
|
331
|
+
*/
|
|
332
|
+
function shareLabel(share: number | null): string {
|
|
333
|
+
if (share === null) return '—';
|
|
334
|
+
if (share > 0 && share < 0.001) return '<0.1 %';
|
|
335
|
+
return formatPercent(share);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* The energy to two decimals, or a dash when there is none.
|
|
340
|
+
*
|
|
341
|
+
* The unit is in the column header rather than in every cell, so the numbers
|
|
342
|
+
* line up and a row stays readable in a narrow panel.
|
|
343
|
+
* @param energy - kcal/mol, or `null`.
|
|
344
|
+
* @returns The label.
|
|
345
|
+
*/
|
|
346
|
+
function energyLabel(energy: number | null): string {
|
|
347
|
+
if (energy === null) return '—';
|
|
348
|
+
if (Math.abs(energy) < ENERGY_RESOLUTION) return '0.00';
|
|
349
|
+
return energy > 0 ? `+${energy.toFixed(2)}` : energy.toFixed(2);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Below this, two force-field energies are the same number to anyone reading
|
|
354
|
+
* them, and the duplicate-minimum test upstream has already decided they are
|
|
355
|
+
* distinct shapes.
|
|
356
|
+
*/
|
|
357
|
+
const ENERGY_RESOLUTION = 0.005;
|
|
358
|
+
|
|
359
|
+
function headerStyle(column: ConformerColumn): CSSProperties | undefined {
|
|
360
|
+
return NUMERIC_CONFORMER_COLUMNS.has(column) ? numericStyle : undefined;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function cellStyle(column: ConformerColumn): CSSProperties | undefined {
|
|
364
|
+
return NUMERIC_CONFORMER_COLUMNS.has(column) ? numericStyle : undefined;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const tableStyle = { width: '100%' } as const satisfies CSSProperties;
|
|
368
|
+
|
|
369
|
+
const numericStyle = {
|
|
370
|
+
textAlign: 'right',
|
|
371
|
+
fontVariantNumeric: 'tabular-nums',
|
|
372
|
+
} as const satisfies CSSProperties;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* The selected row is tinted with the site's own accent, so the table belongs
|
|
376
|
+
* to whichever site draws it; a row is a pointer only where a click does
|
|
377
|
+
* something.
|
|
378
|
+
* @param active - Whether this row is the selected one.
|
|
379
|
+
* @param selectable - Whether a click selects a row at all.
|
|
380
|
+
* @returns The row's inline style, or `undefined` when it needs none.
|
|
381
|
+
*/
|
|
382
|
+
function rowStyle(
|
|
383
|
+
active: boolean,
|
|
384
|
+
selectable: boolean,
|
|
385
|
+
): CSSProperties | undefined {
|
|
386
|
+
if (active) return selectable ? SELECTED_ROW : SELECTED_ROW_STATIC;
|
|
387
|
+
return selectable ? SELECTABLE_ROW : undefined;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const SELECTED_ROW_STATIC = {
|
|
391
|
+
background: 'color-mix(in oklab, var(--accent) 12%, white)',
|
|
392
|
+
fontWeight: 600,
|
|
393
|
+
} as const satisfies CSSProperties;
|
|
394
|
+
|
|
395
|
+
const SELECTED_ROW = {
|
|
396
|
+
...SELECTED_ROW_STATIC,
|
|
397
|
+
cursor: 'pointer',
|
|
398
|
+
} as const satisfies CSSProperties;
|
|
399
|
+
|
|
400
|
+
const SELECTABLE_ROW = { cursor: 'pointer' } as const satisfies CSSProperties;
|
|
401
|
+
|
|
402
|
+
const populationStyle = {
|
|
403
|
+
display: 'flex',
|
|
404
|
+
alignItems: 'center',
|
|
405
|
+
gap: 6,
|
|
406
|
+
fontVariantNumeric: 'tabular-nums',
|
|
407
|
+
} as const satisfies CSSProperties;
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* The track is tinted with `color-mix` rather than `opacity`, which the fill
|
|
411
|
+
* would inherit: an opacity on the track composites its child too, so the bar
|
|
412
|
+
* would be as faint as the groove it sits in.
|
|
413
|
+
*/
|
|
414
|
+
const barTrackStyle = {
|
|
415
|
+
display: 'block',
|
|
416
|
+
flex: '1 1 auto',
|
|
417
|
+
minWidth: 24,
|
|
418
|
+
height: 5,
|
|
419
|
+
borderRadius: 3,
|
|
420
|
+
backgroundColor: 'color-mix(in srgb, currentColor 22%, transparent)',
|
|
421
|
+
overflow: 'hidden',
|
|
422
|
+
} as const satisfies CSSProperties;
|
|
423
|
+
|
|
424
|
+
const barFillStyle = {
|
|
425
|
+
display: 'block',
|
|
426
|
+
height: '100%',
|
|
427
|
+
borderRadius: 3,
|
|
428
|
+
backgroundColor: 'currentColor',
|
|
429
|
+
} as const satisfies CSSProperties;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The columns a conformer table can draw, and the two sets a site usually
|
|
3
|
+
* wants.
|
|
4
|
+
*
|
|
5
|
+
* Their own module so `ConformerTable.tsx` exports a component and nothing
|
|
6
|
+
* else, which is what keeps fast refresh working on the sites that render it.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** One column of a conformer table. */
|
|
10
|
+
export type ConformerColumn =
|
|
11
|
+
/** The 1-based rank, which is also the conformer's id. */
|
|
12
|
+
| 'id'
|
|
13
|
+
/** The Boltzmann share, as a bar and a percentage. */
|
|
14
|
+
| 'population'
|
|
15
|
+
/** Energy above the most stable conformer, in the active ranking. */
|
|
16
|
+
| 'relative'
|
|
17
|
+
/** Total energy, in the active ranking. */
|
|
18
|
+
| 'total'
|
|
19
|
+
/** What the force field said before a refinement reordered the set. */
|
|
20
|
+
| 'forceFieldRelative'
|
|
21
|
+
/** The rank the conformer held before a refinement reordered the set. */
|
|
22
|
+
| 'forceFieldRank';
|
|
23
|
+
|
|
24
|
+
/** The columns a picker needs: which shape, how much of it, how far up. */
|
|
25
|
+
export const PICKER_COLUMNS: readonly ConformerColumn[] = [
|
|
26
|
+
'id',
|
|
27
|
+
'population',
|
|
28
|
+
'relative',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
/** The columns a reader of the ranking itself needs. */
|
|
32
|
+
export const RANKING_COLUMNS: readonly ConformerColumn[] = [
|
|
33
|
+
'id',
|
|
34
|
+
'population',
|
|
35
|
+
'relative',
|
|
36
|
+
'total',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
/** The heading of each column. The unit lives here, never in a cell. */
|
|
40
|
+
export const CONFORMER_COLUMN_LABELS: Record<ConformerColumn, string> = {
|
|
41
|
+
id: '#',
|
|
42
|
+
population: 'share',
|
|
43
|
+
relative: 'ΔE kcal/mol',
|
|
44
|
+
total: 'total kcal/mol',
|
|
45
|
+
forceFieldRelative: 'force field ΔE',
|
|
46
|
+
forceFieldRank: 'force field rank',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** The columns whose cells are numbers, and so are right-aligned and tabular. */
|
|
50
|
+
export const NUMERIC_CONFORMER_COLUMNS: ReadonlySet<ConformerColumn> = new Set([
|
|
51
|
+
'relative',
|
|
52
|
+
'total',
|
|
53
|
+
'forceFieldRelative',
|
|
54
|
+
'forceFieldRank',
|
|
55
|
+
]);
|
package/src/ui.ts
CHANGED
|
@@ -27,3 +27,15 @@ export * from './scatter/ui/index.ts';
|
|
|
27
27
|
export * from './scatter3d/ui/index.ts';
|
|
28
28
|
export * from './share/ui/index.ts';
|
|
29
29
|
export * from './shared/ui/index.ts';
|
|
30
|
+
// The conformer table, from the structure module's file rather than its
|
|
31
|
+
// barrel: `structure/ui/index.ts` is the door that must never reach react-ocl,
|
|
32
|
+
// and this component does not, but `react-cheminfo/conformers` is imported by
|
|
33
|
+
// workers and must never reach React.
|
|
34
|
+
export type { ConformerTableProps } from './structure/ui/ConformerTable.tsx';
|
|
35
|
+
export { ConformerTable } from './structure/ui/ConformerTable.tsx';
|
|
36
|
+
export type { ConformerColumn } from './structure/ui/conformerColumns.ts';
|
|
37
|
+
export {
|
|
38
|
+
CONFORMER_COLUMN_LABELS,
|
|
39
|
+
PICKER_COLUMNS,
|
|
40
|
+
RANKING_COLUMNS,
|
|
41
|
+
} from './structure/ui/conformerColumns.ts';
|
package/styles/chrome.css
CHANGED
|
@@ -278,6 +278,61 @@ button {
|
|
|
278
278
|
color: var(--accent);
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
+
/* ── Who is signed in ────────────────────────────────────────────────────── */
|
|
282
|
+
|
|
283
|
+
/* The invitation keeps its words. It carries no glyph, so the rule above that
|
|
284
|
+
reduces a utility to its mark leaves it written out — which is the point: an
|
|
285
|
+
arrow through a door is what being signed in looks like too, and a bar that
|
|
286
|
+
reports the wrong one of those is a bar nobody can read. */
|
|
287
|
+
.account-button--out {
|
|
288
|
+
color: var(--text);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/* Signed in, the utility is the account's own mark; the name is in the menu it
|
|
292
|
+
opens. */
|
|
293
|
+
.account-button--in {
|
|
294
|
+
padding: 0.25rem 0.35rem;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.account-mark {
|
|
298
|
+
display: inline-flex;
|
|
299
|
+
width: 22px;
|
|
300
|
+
height: 22px;
|
|
301
|
+
align-items: center;
|
|
302
|
+
justify-content: center;
|
|
303
|
+
border-radius: 50%;
|
|
304
|
+
background: color-mix(in oklab, var(--accent) 16%, white);
|
|
305
|
+
color: var(--accent);
|
|
306
|
+
font-size: 0.6875rem;
|
|
307
|
+
font-weight: 700;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/* Still asking: the width the mark will take, so the bar does not jump under
|
|
311
|
+
the pointer when the answer lands. */
|
|
312
|
+
.account-button__pending {
|
|
313
|
+
display: inline-block;
|
|
314
|
+
width: 22px;
|
|
315
|
+
height: 22px;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.account-menu__identity {
|
|
319
|
+
display: flex;
|
|
320
|
+
flex-direction: column;
|
|
321
|
+
padding: 0.35rem 0.6rem;
|
|
322
|
+
gap: 0.1rem;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.account-menu__name {
|
|
326
|
+
color: var(--text);
|
|
327
|
+
font-size: 0.8125rem;
|
|
328
|
+
font-weight: 600;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.account-menu__detail {
|
|
332
|
+
color: var(--text-muted);
|
|
333
|
+
font-size: 0.75rem;
|
|
334
|
+
}
|
|
335
|
+
|
|
281
336
|
/* The share dialog's preset tabs sit on a rule, and wrap onto a second row
|
|
282
337
|
rather than overflow a phone-width dialog. */
|
|
283
338
|
.share-presets > .bp6-tab-list {
|