react-cheminfo 0.130.0 → 0.132.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 +29 -0
- package/lib/core.d.ts +1 -0
- package/lib/core.d.ts.map +1 -1
- package/lib/core.js +1 -0
- package/lib/core.js.map +1 -1
- package/lib/drawing/render/index.d.ts +3 -1
- package/lib/drawing/render/index.d.ts.map +1 -1
- package/lib/drawing/render/index.js +1 -0
- package/lib/drawing/render/index.js.map +1 -1
- package/lib/drawing/render/motion.d.ts +3 -2
- package/lib/drawing/render/motion.d.ts.map +1 -1
- package/lib/drawing/render/motion.js +25 -3
- package/lib/drawing/render/motion.js.map +1 -1
- package/lib/drawing/render/primitives.d.ts +10 -0
- package/lib/drawing/render/primitives.d.ts.map +1 -1
- package/lib/drawing/render/spinning.d.ts +29 -0
- package/lib/drawing/render/spinning.d.ts.map +1 -0
- package/lib/drawing/render/spinning.js +38 -0
- package/lib/drawing/render/spinning.js.map +1 -0
- package/lib/drawing/render/svg.d.ts.map +1 -1
- package/lib/drawing/render/svg.js +8 -2
- package/lib/drawing/render/svg.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 +4 -0
- package/lib/locales/en.json +4 -0
- package/lib/locales/es.json +4 -0
- package/lib/locales/fr.json +4 -0
- package/lib/locales/it.json +4 -0
- package/lib/log/core/index.d.ts +4 -0
- package/lib/log/core/index.d.ts.map +1 -0
- package/lib/log/core/index.js +3 -0
- package/lib/log/core/index.js.map +1 -0
- package/lib/log/core/logGroups.d.ts +87 -0
- package/lib/log/core/logGroups.d.ts.map +1 -0
- package/lib/log/core/logGroups.js +85 -0
- package/lib/log/core/logGroups.js.map +1 -0
- package/lib/log/core/logLines.d.ts +19 -0
- package/lib/log/core/logLines.d.ts.map +1 -0
- package/lib/log/core/logLines.js +36 -0
- package/lib/log/core/logLines.js.map +1 -0
- package/lib/log/ui/LogBadge.d.ts +39 -0
- package/lib/log/ui/LogBadge.d.ts.map +1 -0
- package/lib/log/ui/LogBadge.js +28 -0
- package/lib/log/ui/LogBadge.js.map +1 -0
- package/lib/log/ui/LogCallouts.d.ts +55 -0
- package/lib/log/ui/LogCallouts.d.ts.map +1 -0
- package/lib/log/ui/LogCallouts.js +38 -0
- package/lib/log/ui/LogCallouts.js.map +1 -0
- package/lib/log/ui/index.d.ts +7 -0
- package/lib/log/ui/index.d.ts.map +1 -0
- package/lib/log/ui/index.js +5 -0
- package/lib/log/ui/index.js.map +1 -0
- package/lib/log/ui/logIcon.d.ts +9 -0
- package/lib/log/ui/logIcon.d.ts.map +1 -0
- package/lib/log/ui/logIcon.js +17 -0
- package/lib/log/ui/logIcon.js.map +1 -0
- package/lib/log/ui/useLogEntries.d.ts +15 -0
- package/lib/log/ui/useLogEntries.d.ts.map +1 -0
- package/lib/log/ui/useLogEntries.js +47 -0
- package/lib/log/ui/useLogEntries.js.map +1 -0
- package/lib/overlay/ui/OverlayBarButton.d.ts.map +1 -1
- package/lib/overlay/ui/OverlayBarButton.js +1 -1
- package/lib/overlay/ui/OverlayBarButton.js.map +1 -1
- package/lib/overlay/ui/OverlayInfo.d.ts.map +1 -1
- package/lib/overlay/ui/OverlayInfo.js +1 -1
- package/lib/overlay/ui/OverlayInfo.js.map +1 -1
- package/lib/structure/core/conformerMinimise.d.ts +13 -4
- package/lib/structure/core/conformerMinimise.d.ts.map +1 -1
- package/lib/structure/core/conformerMinimise.js +23 -6
- package/lib/structure/core/conformerMinimise.js.map +1 -1
- package/lib/structure/core/conformerRefine.d.ts +2 -2
- package/lib/structure/core/conformerRefine.d.ts.map +1 -1
- package/lib/structure/core/conformerRefine.js +23 -7
- package/lib/structure/core/conformerRefine.js.map +1 -1
- package/lib/structure/core/conformers.d.ts +8 -3
- package/lib/structure/core/conformers.d.ts.map +1 -1
- package/lib/structure/core/conformers.js +10 -7
- package/lib/structure/core/conformers.js.map +1 -1
- package/lib/structure/core/geometryRelaxer.d.ts +10 -3
- package/lib/structure/core/geometryRelaxer.d.ts.map +1 -1
- package/lib/structure/core/relaxerLogLines.d.ts +16 -0
- package/lib/structure/core/relaxerLogLines.d.ts.map +1 -0
- package/lib/structure/core/relaxerLogLines.js +33 -0
- package/lib/structure/core/relaxerLogLines.js.map +1 -0
- package/lib/ui.d.ts +1 -0
- package/lib/ui.d.ts.map +1 -1
- package/lib/ui.js +1 -0
- package/lib/ui.js.map +1 -1
- package/lib/xtb/core/taggedLogger.d.ts +11 -0
- package/lib/xtb/core/taggedLogger.d.ts.map +1 -0
- package/lib/xtb/core/taggedLogger.js +31 -0
- package/lib/xtb/core/taggedLogger.js.map +1 -0
- package/lib/xtb/core/xtbRelaxer.d.ts.map +1 -1
- package/lib/xtb/core/xtbRelaxer.js +13 -5
- package/lib/xtb/core/xtbRelaxer.js.map +1 -1
- package/package.json +4 -3
- package/src/core.ts +1 -0
- package/src/drawing/render/index.ts +3 -0
- package/src/drawing/render/motion.ts +25 -3
- package/src/drawing/render/primitives.ts +11 -0
- package/src/drawing/render/spinning.ts +48 -0
- package/src/drawing/render/svg.ts +8 -2
- package/src/locales/de.json +4 -0
- package/src/locales/en.json +4 -0
- package/src/locales/es.json +4 -0
- package/src/locales/fr.json +4 -0
- package/src/locales/it.json +4 -0
- package/src/log/core/index.ts +9 -0
- package/src/log/core/logGroups.ts +159 -0
- package/src/log/core/logLines.ts +44 -0
- package/src/log/ui/LogBadge.tsx +89 -0
- package/src/log/ui/LogCallouts.tsx +103 -0
- package/src/log/ui/index.ts +6 -0
- package/src/log/ui/logIcon.ts +21 -0
- package/src/log/ui/useLogEntries.ts +57 -0
- package/src/overlay/ui/OverlayBarButton.tsx +1 -0
- package/src/overlay/ui/OverlayInfo.tsx +1 -0
- package/src/structure/core/conformerMinimise.ts +34 -8
- package/src/structure/core/conformerRefine.ts +29 -13
- package/src/structure/core/conformers.ts +23 -12
- package/src/structure/core/geometryRelaxer.ts +11 -3
- package/src/structure/core/relaxerLogLines.ts +39 -0
- package/src/ui.ts +1 -0
- package/src/xtb/core/taggedLogger.ts +35 -0
- package/src/xtb/core/xtbRelaxer.ts +15 -5
- package/styles/chrome.css +34 -0
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { Molecule } from 'openchemlib';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { LogLine } from '../../log/core/logGroups.ts';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
minimiseConformer,
|
|
7
|
+
producedSource,
|
|
8
|
+
rankByEnergy,
|
|
9
|
+
} from './conformerMinimise.ts';
|
|
6
10
|
import { isKeptMinimum, minimisedShapes } from './conformerMinimum.ts';
|
|
7
11
|
import type {
|
|
8
12
|
ConformerOptions,
|
|
@@ -62,8 +66,12 @@ export interface ConformerSet {
|
|
|
62
66
|
stoppedBy: StopReason;
|
|
63
67
|
/** Wall-clock duration of the run, initialisation and continuations included. */
|
|
64
68
|
elapsedMilliseconds: number;
|
|
65
|
-
/**
|
|
66
|
-
|
|
69
|
+
/**
|
|
70
|
+
* What the run has to say: conformers dropped (`error`), left without an
|
|
71
|
+
* energy (`warn`), merged by a refinement (`info`). Plain, so the set can be
|
|
72
|
+
* posted from a worker and saved in a figure with them.
|
|
73
|
+
*/
|
|
74
|
+
logs: LogLine[];
|
|
67
75
|
/** The force field that was asked for, echoed so a reader knows what the energies mean. */
|
|
68
76
|
minimisation: MinimisationAlgorithm;
|
|
69
77
|
/** Conformers the generator handed back, dropped ones included: where a continuation resumes. */
|
|
@@ -109,7 +117,7 @@ export type ConformerLimits = Pick<
|
|
|
109
117
|
* @param molecule - Structure to embed. Not mutated.
|
|
110
118
|
* @param options - Strategy, limits, seed and force field.
|
|
111
119
|
* @param now - Clock used for the time budget, injectable for tests.
|
|
112
|
-
* @returns Every conformer kept, most stable first, with relative energies and
|
|
120
|
+
* @returns Every conformer kept, most stable first, with relative energies and what the run logged.
|
|
113
121
|
* @throws {Error} When the structure is empty or OpenChemLib refuses to initialise it.
|
|
114
122
|
*/
|
|
115
123
|
export function generateConformers(
|
|
@@ -162,7 +170,7 @@ interface Accumulator {
|
|
|
162
170
|
conformers: Conformer[];
|
|
163
171
|
/** Shape of each conformer, `null` for one without an energy. */
|
|
164
172
|
shapes: Array<ConformerShape | null>;
|
|
165
|
-
|
|
173
|
+
logs: LogLine[];
|
|
166
174
|
}
|
|
167
175
|
|
|
168
176
|
function runConformers(
|
|
@@ -197,7 +205,7 @@ function runConformers(
|
|
|
197
205
|
const into: Accumulator = {
|
|
198
206
|
conformers,
|
|
199
207
|
shapes: minimisedShapes(conformers),
|
|
200
|
-
|
|
208
|
+
logs: previous === null ? [] : [...previous.logs],
|
|
201
209
|
};
|
|
202
210
|
const budget = Math.max(options.timeoutSeconds * 1000, 0);
|
|
203
211
|
const stoppedBy = collect(
|
|
@@ -214,7 +222,7 @@ function runConformers(
|
|
|
214
222
|
potentialConformerCount,
|
|
215
223
|
stoppedBy,
|
|
216
224
|
elapsedMilliseconds: (previous?.elapsedMilliseconds ?? 0) + now() - start,
|
|
217
|
-
|
|
225
|
+
logs: into.logs,
|
|
218
226
|
minimisation: options.minimisation,
|
|
219
227
|
produced: session.produced,
|
|
220
228
|
options,
|
|
@@ -245,16 +253,19 @@ function collect(
|
|
|
245
253
|
}
|
|
246
254
|
session.produced++;
|
|
247
255
|
if (!hasFiniteCoordinates(conformer)) {
|
|
248
|
-
into.
|
|
249
|
-
|
|
250
|
-
|
|
256
|
+
into.logs.push({
|
|
257
|
+
levelLabel: 'error',
|
|
258
|
+
message:
|
|
259
|
+
'It was dropped: the generator placed some of its atoms at non-finite coordinates.',
|
|
260
|
+
meta: { source: producedSource(session.produced) },
|
|
261
|
+
});
|
|
251
262
|
continue;
|
|
252
263
|
}
|
|
253
264
|
const energy = minimiseConformer(
|
|
254
265
|
conformer,
|
|
255
266
|
options,
|
|
256
267
|
session.produced,
|
|
257
|
-
into.
|
|
268
|
+
into.logs,
|
|
258
269
|
);
|
|
259
270
|
const shape = energy === null ? null : conformerShape(conformer);
|
|
260
271
|
if (
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { LightLogger } from 'cheminfo-types';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* A geometry a relaxer is handed: element symbols plus flat Cartesian
|
|
3
5
|
* coordinates in ångström, `x,y,z` per atom.
|
|
@@ -33,12 +35,18 @@ export interface RelaxedGeometry {
|
|
|
33
35
|
cycles: number;
|
|
34
36
|
/** Whether the optimizer met its convergence criteria. */
|
|
35
37
|
converged: boolean;
|
|
36
|
-
/** Plain sentences about anything the caller should know. */
|
|
37
|
-
warnings: string[];
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/** How a relaxation run is watched and
|
|
40
|
+
/** How a relaxation run is watched, cancelled and heard from. */
|
|
41
41
|
export interface RelaxerOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Receives what the relaxer has to say: `error` for something dropped while
|
|
44
|
+
* the rest went on, `warn` for what changes how a result must be read, `info`
|
|
45
|
+
* for context. An entry about one structure carries `structure`, its index
|
|
46
|
+
* in the batch; one without it is about the whole batch.
|
|
47
|
+
* @default nothing is reported
|
|
48
|
+
*/
|
|
49
|
+
logger?: LightLogger;
|
|
42
50
|
/**
|
|
43
51
|
* Called as each structure finishes, so a caller can show progress over a
|
|
44
52
|
* batch that runs for seconds.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { LogEntry } from 'fifo-logger';
|
|
2
|
+
|
|
3
|
+
import type { LogLine } from '../../log/core/logGroups.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What a relaxer logged about a batch, as lines a conformer set keeps: an
|
|
7
|
+
* entry about one structure is labelled with that structure's source, an entry
|
|
8
|
+
* about a structure that was dropped is dropped with it, and an entry naming no
|
|
9
|
+
* structure is about the whole batch — or, in a batch of one, about its only
|
|
10
|
+
* structure.
|
|
11
|
+
* @param entries - What the relaxer logged, each entry about one structure
|
|
12
|
+
* carrying `structure`, its index in the batch.
|
|
13
|
+
* @param sources - The label of each structure, `null` for one that was
|
|
14
|
+
* dropped.
|
|
15
|
+
* @returns Plain lines, in the order they were logged.
|
|
16
|
+
*/
|
|
17
|
+
export function relaxerLogLines(
|
|
18
|
+
entries: readonly LogEntry[],
|
|
19
|
+
sources: ReadonlyArray<string | null>,
|
|
20
|
+
): LogLine[] {
|
|
21
|
+
const lines: LogLine[] = [];
|
|
22
|
+
for (const entry of entries) {
|
|
23
|
+
const { structure, ...meta } = entry.meta ?? {};
|
|
24
|
+
const index =
|
|
25
|
+
typeof structure === 'number'
|
|
26
|
+
? structure
|
|
27
|
+
: sources.length === 1
|
|
28
|
+
? 0
|
|
29
|
+
: null;
|
|
30
|
+
const source = index === null ? undefined : sources[index];
|
|
31
|
+
if (source === null) continue;
|
|
32
|
+
lines.push({
|
|
33
|
+
levelLabel: entry.levelLabel,
|
|
34
|
+
message: entry.error?.message ?? entry.message,
|
|
35
|
+
meta: source === undefined ? meta : { ...meta, source },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return lines;
|
|
39
|
+
}
|
package/src/ui.ts
CHANGED
|
@@ -22,6 +22,7 @@ export * from './highlight/ui/index.ts';
|
|
|
22
22
|
export * from './hooks/ui/index.ts';
|
|
23
23
|
export * from './i18n/ui/index.ts';
|
|
24
24
|
export * from './language/ui/index.ts';
|
|
25
|
+
export * from './log/ui/index.ts';
|
|
25
26
|
export * from './moleculesSources/ui/index.ts';
|
|
26
27
|
export * from './moleculesToken/ui/index.ts';
|
|
27
28
|
export * from './number/ui/index.ts';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { LightLogger } from 'cheminfo-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A logger that adds some fields to every entry before passing it on — what
|
|
5
|
+
* xtb-wasm's pool does for the structures of a batch, done here for the ones
|
|
6
|
+
* relaxed in turn on this thread.
|
|
7
|
+
* @param logger - Where the entries go.
|
|
8
|
+
* @param context - The fields every entry gains, e.g. `{ structure: 2 }`.
|
|
9
|
+
* @returns The tagging logger.
|
|
10
|
+
*/
|
|
11
|
+
export function taggedLogger(
|
|
12
|
+
logger: LightLogger,
|
|
13
|
+
context: Record<string, unknown>,
|
|
14
|
+
): LightLogger {
|
|
15
|
+
function forward(level: Level) {
|
|
16
|
+
return (value: unknown, message?: string): void => {
|
|
17
|
+
if (value instanceof Error) {
|
|
18
|
+
logger[level](context, message ?? value.message);
|
|
19
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
20
|
+
logger[level]({ ...context, ...value }, message ?? '');
|
|
21
|
+
} else {
|
|
22
|
+
logger[level](context, message ?? String(value));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
trace: forward('trace'),
|
|
28
|
+
debug: forward('debug'),
|
|
29
|
+
info: forward('info'),
|
|
30
|
+
warn: forward('warn'),
|
|
31
|
+
error: forward('error'),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type Level = 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
@@ -8,6 +8,8 @@ import type {
|
|
|
8
8
|
RelaxerOptions,
|
|
9
9
|
} from '../../structure/core/geometryRelaxer.ts';
|
|
10
10
|
|
|
11
|
+
import { taggedLogger } from './taggedLogger.ts';
|
|
12
|
+
|
|
11
13
|
/**
|
|
12
14
|
* kcal/mol per hartree, CODATA 2018. Every energy a relaxer reports is in
|
|
13
15
|
* kcal/mol, so it can be read against a force-field energy without the reader
|
|
@@ -73,6 +75,7 @@ export function xtbRelaxer(options: XtbRelaxerOptions = {}): GeometryRelaxer {
|
|
|
73
75
|
maxWorkers: options.maxWorkers,
|
|
74
76
|
onSettled: runOptions.onSettled,
|
|
75
77
|
signal: runOptions.signal,
|
|
78
|
+
logger: runOptions.logger,
|
|
76
79
|
})
|
|
77
80
|
: await relaxHere(xtb, requests, runOptions);
|
|
78
81
|
const relaxed: RelaxedGeometry[] = [];
|
|
@@ -86,7 +89,6 @@ export function xtbRelaxer(options: XtbRelaxerOptions = {}): GeometryRelaxer {
|
|
|
86
89
|
: result.energy.dispersion * KCAL_PER_MOL_PER_HARTREE,
|
|
87
90
|
cycles: result.cycles,
|
|
88
91
|
converged: result.converged,
|
|
89
|
-
warnings: result.warnings,
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
return relaxed;
|
|
@@ -118,7 +120,8 @@ export async function disposeXtbRelaxer(): Promise<void> {
|
|
|
118
120
|
* Relax one structure after another on this thread, for want of a pool.
|
|
119
121
|
* @param xtb - The loaded `xtb-wasm` module.
|
|
120
122
|
* @param requests - The structures to relax, with their settings.
|
|
121
|
-
* @param runOptions - Progress and
|
|
123
|
+
* @param runOptions - Progress, cancellation, and the logger each structure's
|
|
124
|
+
* messages go to under its index, as the pool would have logged them.
|
|
122
125
|
* @returns One `xtb-wasm` result per request, in request order.
|
|
123
126
|
* @throws {Error} When the run is cancelled, or when occ fails.
|
|
124
127
|
*/
|
|
@@ -127,15 +130,22 @@ async function relaxHere(
|
|
|
127
130
|
requests: ReadonlyArray<Parameters<XtbModule['relaxGeometryInProcess']>[0]>,
|
|
128
131
|
runOptions: RelaxerOptions,
|
|
129
132
|
): Promise<Array<Awaited<ReturnType<XtbModule['relaxGeometryInProcess']>>>> {
|
|
133
|
+
const { logger, signal, onSettled } = runOptions;
|
|
130
134
|
const results = [];
|
|
131
135
|
for (const [index, request] of requests.entries()) {
|
|
132
|
-
if (
|
|
136
|
+
if (signal?.aborted === true) {
|
|
133
137
|
throw new Error('calculation cancelled');
|
|
134
138
|
}
|
|
139
|
+
const options = {
|
|
140
|
+
logger:
|
|
141
|
+
logger === undefined
|
|
142
|
+
? undefined
|
|
143
|
+
: taggedLogger(logger, { structure: index }),
|
|
144
|
+
};
|
|
135
145
|
/* eslint-disable-next-line no-await-in-loop -- there is one thread: the
|
|
136
146
|
whole point of this path is that the structures run in turn. */
|
|
137
|
-
results.push(await xtb.relaxGeometryInProcess(request));
|
|
138
|
-
|
|
147
|
+
results.push(await xtb.relaxGeometryInProcess(request, options));
|
|
148
|
+
onSettled?.(index + 1, requests.length);
|
|
139
149
|
}
|
|
140
150
|
return results;
|
|
141
151
|
}
|
package/styles/chrome.css
CHANGED
|
@@ -1778,6 +1778,40 @@ span.taxon-lineage__name {
|
|
|
1778
1778
|
color: var(--accent);
|
|
1779
1779
|
}
|
|
1780
1780
|
|
|
1781
|
+
/* ── What a logger collected ────────────────────────────────────────────── */
|
|
1782
|
+
|
|
1783
|
+
/*
|
|
1784
|
+
`<LogCallouts>` and the popover of `<LogBadge>`: one callout per message,
|
|
1785
|
+
worst first, close enough to read as one list.
|
|
1786
|
+
*/
|
|
1787
|
+
.log-callouts {
|
|
1788
|
+
display: flex;
|
|
1789
|
+
flex-direction: column;
|
|
1790
|
+
gap: 6px;
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
.log-badge__popover .log-callouts {
|
|
1794
|
+
max-width: 460px;
|
|
1795
|
+
padding: 8px;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
.log-callouts__count {
|
|
1799
|
+
margin-left: 0.4em;
|
|
1800
|
+
color: var(--text-muted);
|
|
1801
|
+
font-variant-numeric: tabular-nums;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
/* Where a message comes from — a file, a line — read before the message. */
|
|
1805
|
+
.log-callouts__source {
|
|
1806
|
+
margin-right: 0.4em;
|
|
1807
|
+
font-weight: 600;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
.log-callouts__more {
|
|
1811
|
+
color: var(--text-muted);
|
|
1812
|
+
font-size: 12px;
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1781
1815
|
/* ── The splitter ───────────────────────────────────────────────────────── */
|
|
1782
1816
|
|
|
1783
1817
|
/*
|