react-cheminfo 0.131.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/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/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/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/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
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { LogGroupOptions, LogLine } from './logGroups.ts';
|
|
2
|
+
import { groupLogEntries } from './logGroups.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Log entries as plain data, to keep with a result, save in a file or post
|
|
6
|
+
* across a worker: a logged error becomes its message, and nothing else of a
|
|
7
|
+
* fifo-logger entry — its id, time and logger uuids — is kept.
|
|
8
|
+
* @param lines - What a logger collected.
|
|
9
|
+
* @returns The same messages, as plain objects in the same order.
|
|
10
|
+
*/
|
|
11
|
+
export function plainLogLines(lines: readonly LogLine[]): LogLine[] {
|
|
12
|
+
const plain: LogLine[] = [];
|
|
13
|
+
for (const line of lines) {
|
|
14
|
+
plain.push({
|
|
15
|
+
levelLabel: line.levelLabel,
|
|
16
|
+
message: line.error?.message ?? line.message,
|
|
17
|
+
...(line.meta === undefined ? {} : { meta: line.meta }),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return plain;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The messages as sentences, for an answer that carries text rather than a
|
|
25
|
+
* page: an MCP tool, a host's reply, a status line. Each message comes once,
|
|
26
|
+
* the worst first, prefixed by where it comes from and led by its title.
|
|
27
|
+
* @param lines - What one or more loggers collected.
|
|
28
|
+
* @param options - See {@link LogGroupOptions}.
|
|
29
|
+
* @returns One sentence per distinct message.
|
|
30
|
+
*/
|
|
31
|
+
export function logMessages(
|
|
32
|
+
lines: readonly LogLine[],
|
|
33
|
+
options: LogGroupOptions = {},
|
|
34
|
+
): string[] {
|
|
35
|
+
const messages: string[] = [];
|
|
36
|
+
for (const group of groupLogEntries(lines, options)) {
|
|
37
|
+
const text =
|
|
38
|
+
group.title === undefined ? group.text : `${group.title}. ${group.text}`;
|
|
39
|
+
messages.push(
|
|
40
|
+
group.source === undefined ? text : `${group.source}: ${text}`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return messages;
|
|
44
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { PopoverNextProps } from '@blueprintjs/core';
|
|
2
|
+
import { Button, PopoverNext } from '@blueprintjs/core';
|
|
3
|
+
import type { ReactElement } from 'react';
|
|
4
|
+
|
|
5
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
6
|
+
import { joinClassNames } from '../../shared/ui/joinClassNames.ts';
|
|
7
|
+
import type { LogLevelLabel, LogLine } from '../core/logGroups.ts';
|
|
8
|
+
import {
|
|
9
|
+
groupLogEntries,
|
|
10
|
+
logIntent,
|
|
11
|
+
worstLogLevel,
|
|
12
|
+
} from '../core/logGroups.ts';
|
|
13
|
+
|
|
14
|
+
import { LogGroupList } from './LogCallouts.tsx';
|
|
15
|
+
import { logIcon } from './logIcon.ts';
|
|
16
|
+
|
|
17
|
+
/** Props of {@link LogBadge}. */
|
|
18
|
+
export interface LogBadgeProps {
|
|
19
|
+
/** What one or more loggers collected, in the order they logged it. */
|
|
20
|
+
entries: readonly LogLine[];
|
|
21
|
+
/**
|
|
22
|
+
* The least serious level shown.
|
|
23
|
+
* @default 'info'
|
|
24
|
+
*/
|
|
25
|
+
minLevel?: LogLevelLabel;
|
|
26
|
+
/**
|
|
27
|
+
* How many messages the popover shows before the rest are counted instead.
|
|
28
|
+
* @default every message
|
|
29
|
+
*/
|
|
30
|
+
limit?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Which side the messages open on.
|
|
33
|
+
* @default 'bottom-start'
|
|
34
|
+
*/
|
|
35
|
+
placement?: PopoverNextProps['placement'];
|
|
36
|
+
/**
|
|
37
|
+
* Class names added to the button.
|
|
38
|
+
* @default undefined
|
|
39
|
+
*/
|
|
40
|
+
className?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* One small button standing for every message a logger collected about what
|
|
45
|
+
* sits beside it, drawn in the colour of the most serious and counting them,
|
|
46
|
+
* which opens them all as callouts on hover. The messages stay one pointer
|
|
47
|
+
* away from the chart or the result they qualify instead of pushing it down
|
|
48
|
+
* the page.
|
|
49
|
+
* @param props - See {@link LogBadgeProps}.
|
|
50
|
+
* @returns The button, or nothing when there is no message to show.
|
|
51
|
+
*/
|
|
52
|
+
export function LogBadge(props: LogBadgeProps): ReactElement | null {
|
|
53
|
+
const {
|
|
54
|
+
entries,
|
|
55
|
+
minLevel,
|
|
56
|
+
limit,
|
|
57
|
+
placement = 'bottom-start',
|
|
58
|
+
className,
|
|
59
|
+
} = props;
|
|
60
|
+
const t = useChromeT();
|
|
61
|
+
const groups = groupLogEntries(entries, { minLevel });
|
|
62
|
+
const worst = worstLogLevel(groups);
|
|
63
|
+
if (worst === null) return null;
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<PopoverNext
|
|
67
|
+
interactionKind="hover"
|
|
68
|
+
hoverOpenDelay={150}
|
|
69
|
+
placement={placement}
|
|
70
|
+
popoverClassName="log-badge__popover"
|
|
71
|
+
content={<LogGroupList groups={groups} limit={limit} />}
|
|
72
|
+
>
|
|
73
|
+
<Button
|
|
74
|
+
variant="minimal"
|
|
75
|
+
size="small"
|
|
76
|
+
intent={logIntent(worst)}
|
|
77
|
+
icon={logIcon(worst)}
|
|
78
|
+
className={joinClassNames('log-badge', 'no-print', className)}
|
|
79
|
+
aria-label={
|
|
80
|
+
groups.length === 1
|
|
81
|
+
? t('log.badge.one')
|
|
82
|
+
: t('log.badge.other', { count: groups.length })
|
|
83
|
+
}
|
|
84
|
+
>
|
|
85
|
+
{groups.length > 1 ? groups.length : undefined}
|
|
86
|
+
</Button>
|
|
87
|
+
</PopoverNext>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Callout } from '@blueprintjs/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
5
|
+
import { InlineText } from '../../pedagogy/ui/InlineText.tsx';
|
|
6
|
+
import { joinClassNames } from '../../shared/ui/joinClassNames.ts';
|
|
7
|
+
import type { LogGroup, LogLevelLabel, LogLine } from '../core/logGroups.ts';
|
|
8
|
+
import { groupLogEntries, logIntent } from '../core/logGroups.ts';
|
|
9
|
+
|
|
10
|
+
import { logIcon } from './logIcon.ts';
|
|
11
|
+
|
|
12
|
+
/** Props of {@link LogCallouts}. */
|
|
13
|
+
export interface LogCalloutsProps {
|
|
14
|
+
/** What one or more loggers collected, in the order they logged it. */
|
|
15
|
+
entries: readonly LogLine[];
|
|
16
|
+
/**
|
|
17
|
+
* The least serious level shown.
|
|
18
|
+
* @default 'info'
|
|
19
|
+
*/
|
|
20
|
+
minLevel?: LogLevelLabel;
|
|
21
|
+
/**
|
|
22
|
+
* How many messages are shown before the rest are counted instead.
|
|
23
|
+
* @default every message
|
|
24
|
+
*/
|
|
25
|
+
limit?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Class names added to the list.
|
|
28
|
+
* @default undefined
|
|
29
|
+
*/
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* What a logger collected, as callouts in the page: one per distinct message,
|
|
35
|
+
* the most serious first, each in the colour and with the icon of its level.
|
|
36
|
+
*
|
|
37
|
+
* A message is authored prose — `` `code` ``, `{{CO2}}`, `**strong**`. A string
|
|
38
|
+
* `title` in its meta heads it and a string `source` labels where it comes
|
|
39
|
+
* from. A message said several times is shown once, with how many times.
|
|
40
|
+
* @param props - See {@link LogCalloutsProps}.
|
|
41
|
+
* @returns The callouts, or nothing when there is no message to show.
|
|
42
|
+
*/
|
|
43
|
+
export function LogCallouts(props: LogCalloutsProps): ReactElement | null {
|
|
44
|
+
const { entries, minLevel, limit, className } = props;
|
|
45
|
+
const groups = groupLogEntries(entries, { minLevel });
|
|
46
|
+
if (groups.length === 0) return null;
|
|
47
|
+
return <LogGroupList groups={groups} limit={limit} className={className} />;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Props of {@link LogGroupList}. */
|
|
51
|
+
export interface LogGroupListProps {
|
|
52
|
+
/** The messages, as {@link groupLogEntries} ordered them. */
|
|
53
|
+
groups: readonly LogGroup[];
|
|
54
|
+
/**
|
|
55
|
+
* How many messages are shown before the rest are counted instead.
|
|
56
|
+
* @default every message
|
|
57
|
+
*/
|
|
58
|
+
limit?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Class names added to the list.
|
|
61
|
+
* @default undefined
|
|
62
|
+
*/
|
|
63
|
+
className?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Messages already grouped, as callouts.
|
|
68
|
+
* @param props - See {@link LogGroupListProps}.
|
|
69
|
+
* @returns The callouts.
|
|
70
|
+
*/
|
|
71
|
+
export function LogGroupList(props: LogGroupListProps): ReactElement {
|
|
72
|
+
const { groups, limit = groups.length, className } = props;
|
|
73
|
+
const t = useChromeT();
|
|
74
|
+
const hidden = Math.max(0, groups.length - limit);
|
|
75
|
+
return (
|
|
76
|
+
<div className={joinClassNames('log-callouts', className)}>
|
|
77
|
+
{groups.slice(0, limit).map((group) => (
|
|
78
|
+
<Callout
|
|
79
|
+
key={group.key}
|
|
80
|
+
compact
|
|
81
|
+
intent={logIntent(group.level)}
|
|
82
|
+
icon={logIcon(group.level)}
|
|
83
|
+
title={group.title}
|
|
84
|
+
>
|
|
85
|
+
{group.source !== undefined && (
|
|
86
|
+
<span className="log-callouts__source">{group.source}</span>
|
|
87
|
+
)}
|
|
88
|
+
<InlineText text={group.text} />
|
|
89
|
+
{group.count > 1 && (
|
|
90
|
+
<span className="log-callouts__count">×{group.count}</span>
|
|
91
|
+
)}
|
|
92
|
+
</Callout>
|
|
93
|
+
))}
|
|
94
|
+
{hidden > 0 && (
|
|
95
|
+
<span className="log-callouts__more">
|
|
96
|
+
{hidden === 1
|
|
97
|
+
? t('log.more.one')
|
|
98
|
+
: t('log.more.other', { count: hidden })}
|
|
99
|
+
</span>
|
|
100
|
+
)}
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { LogBadgeProps } from './LogBadge.tsx';
|
|
2
|
+
export { LogBadge } from './LogBadge.tsx';
|
|
3
|
+
export type { LogCalloutsProps, LogGroupListProps } from './LogCallouts.tsx';
|
|
4
|
+
export { LogCallouts, LogGroupList } from './LogCallouts.tsx';
|
|
5
|
+
export { logIcon } from './logIcon.ts';
|
|
6
|
+
export { useLogEntries } from './useLogEntries.ts';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IconName } from '@blueprintjs/core';
|
|
2
|
+
|
|
3
|
+
import type { LogLevelLabel } from '../core/logGroups.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The icon a message of this level is shown with.
|
|
7
|
+
* @param level - The level it was logged at.
|
|
8
|
+
* @returns A Blueprint icon name.
|
|
9
|
+
*/
|
|
10
|
+
export function logIcon(level: LogLevelLabel): IconName {
|
|
11
|
+
return ICONS[level];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ICONS: Record<LogLevelLabel, IconName> = {
|
|
15
|
+
trace: 'console',
|
|
16
|
+
debug: 'console',
|
|
17
|
+
info: 'info-sign',
|
|
18
|
+
warn: 'warning-sign',
|
|
19
|
+
error: 'error',
|
|
20
|
+
fatal: 'error',
|
|
21
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { FifoLogger, LogEntry } from 'fifo-logger';
|
|
2
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What a logger holds, kept up to date as it logs: a page shows the messages
|
|
6
|
+
* of a long run while it is still running, and the list redraws only when
|
|
7
|
+
* something was logged.
|
|
8
|
+
*
|
|
9
|
+
* The logger is named, never read from a context: each result keeps a logger
|
|
10
|
+
* of its own, so a new run replaces its own messages and leaves the others'.
|
|
11
|
+
* react-science's `useFifoLogs` is for the one page-wide logger its
|
|
12
|
+
* `FifoLoggerProvider` holds.
|
|
13
|
+
* @param logger - The logger to read, or nothing while there is none.
|
|
14
|
+
* @returns Its entries, the same array until it logs again.
|
|
15
|
+
*/
|
|
16
|
+
export function useLogEntries(
|
|
17
|
+
logger: FifoLogger | null | undefined,
|
|
18
|
+
): readonly LogEntry[] {
|
|
19
|
+
const subscribe = useCallback(
|
|
20
|
+
(onChange: () => void) => {
|
|
21
|
+
if (logger == null) return noSubscription;
|
|
22
|
+
const listener = () => {
|
|
23
|
+
snapshots.delete(logger);
|
|
24
|
+
onChange();
|
|
25
|
+
};
|
|
26
|
+
logger.addEventListener('change', listener);
|
|
27
|
+
return () => {
|
|
28
|
+
logger.removeEventListener('change', listener);
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
[logger],
|
|
32
|
+
);
|
|
33
|
+
const read = useCallback(() => snapshotOf(logger), [logger]);
|
|
34
|
+
return useSyncExternalStore(subscribe, read, read);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// One array per logger until it logs again: `getLogs` builds a new one on every
|
|
38
|
+
// call, and a store has to answer the same value while nothing changed.
|
|
39
|
+
const snapshots = new WeakMap<FifoLogger, readonly LogEntry[]>();
|
|
40
|
+
|
|
41
|
+
const NO_ENTRIES: readonly LogEntry[] = [];
|
|
42
|
+
|
|
43
|
+
function snapshotOf(
|
|
44
|
+
logger: FifoLogger | null | undefined,
|
|
45
|
+
): readonly LogEntry[] {
|
|
46
|
+
if (logger == null) return NO_ENTRIES;
|
|
47
|
+
let entries = snapshots.get(logger);
|
|
48
|
+
if (entries === undefined) {
|
|
49
|
+
entries = logger.getLogs({ includeChildren: true });
|
|
50
|
+
snapshots.set(logger, entries);
|
|
51
|
+
}
|
|
52
|
+
return entries;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function noSubscription(): void {
|
|
56
|
+
// Nothing was subscribed to.
|
|
57
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { Molecule } from 'openchemlib';
|
|
|
2
2
|
import { ForceFieldMMFF94 } from 'openchemlib';
|
|
3
3
|
|
|
4
4
|
import { ordinal } from '../../format/core/words.ts';
|
|
5
|
+
import type { LogLine } from '../../log/core/logGroups.ts';
|
|
5
6
|
|
|
6
7
|
import type { ConformerOptions } from './conformerOptions.ts';
|
|
7
8
|
|
|
@@ -13,19 +14,20 @@ import type { ConformerOptions } from './conformerOptions.ts';
|
|
|
13
14
|
* than an exception. A non-zero return code from `minimise()` is *not* a
|
|
14
15
|
* failure: ethyne returns 2 with a perfect geometry.
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
-
* number never means two things — a row
|
|
17
|
+
* A warning names its conformer by the count of conformers the generator
|
|
18
|
+
* handed back, kept or not, so one number never means two things — a row
|
|
19
|
+
* number would, once one is dropped.
|
|
18
20
|
* @param conformer - The conformer to relax. Mutated.
|
|
19
21
|
* @param options - Force field and iteration budget.
|
|
20
22
|
* @param produced - 1-based position of the conformer in the generator's output.
|
|
21
|
-
* @param
|
|
23
|
+
* @param logs - Receives one warning when the energy is unknown.
|
|
22
24
|
* @returns Total energy in kcal/mol, or `null` when none was computed.
|
|
23
25
|
*/
|
|
24
26
|
export function minimiseConformer(
|
|
25
27
|
conformer: Molecule,
|
|
26
28
|
options: ConformerOptions,
|
|
27
29
|
produced: number,
|
|
28
|
-
|
|
30
|
+
logs: LogLine[],
|
|
29
31
|
): number | null {
|
|
30
32
|
const algorithm = options.minimisation;
|
|
31
33
|
if (algorithm === 'none') return null;
|
|
@@ -35,20 +37,44 @@ export function minimiseConformer(
|
|
|
35
37
|
forceField.minimise({ maxIts: options.maxIterations });
|
|
36
38
|
energy = forceField.getTotalEnergy();
|
|
37
39
|
} catch (error) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
logs.push(
|
|
41
|
+
producedWarning(
|
|
42
|
+
produced,
|
|
43
|
+
`It could not be minimised with ${algorithm} (${readable(error)}), so its energy is unknown.`,
|
|
44
|
+
),
|
|
40
45
|
);
|
|
41
46
|
return null;
|
|
42
47
|
}
|
|
43
48
|
if (!Number.isFinite(energy)) {
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
logs.push(
|
|
50
|
+
producedWarning(
|
|
51
|
+
produced,
|
|
52
|
+
`It minimised to a non-finite ${algorithm} energy, so its energy is unknown.`,
|
|
53
|
+
),
|
|
46
54
|
);
|
|
47
55
|
return null;
|
|
48
56
|
}
|
|
49
57
|
return energy;
|
|
50
58
|
}
|
|
51
59
|
|
|
60
|
+
/**
|
|
61
|
+
* The label of a conformer as the generator handed it back, which a message
|
|
62
|
+
* about it is shown under.
|
|
63
|
+
* @param produced - 1-based position of the conformer in the generator's output.
|
|
64
|
+
* @returns E.g. `3rd conformer produced`.
|
|
65
|
+
*/
|
|
66
|
+
export function producedSource(produced: number): string {
|
|
67
|
+
return `${ordinal(produced)} conformer produced`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function producedWarning(produced: number, message: string): LogLine {
|
|
71
|
+
return {
|
|
72
|
+
levelLabel: 'warn',
|
|
73
|
+
message,
|
|
74
|
+
meta: { source: producedSource(produced) },
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
52
78
|
/** What {@link rankByEnergy} reads and rewrites on a conformer. */
|
|
53
79
|
export interface RankedConformer {
|
|
54
80
|
id: number;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { FifoLogger } from 'fifo-logger';
|
|
1
2
|
import { Molecule } from 'openchemlib';
|
|
2
3
|
|
|
3
4
|
import { ordinal } from '../../format/core/words.ts';
|
|
5
|
+
import type { LogLine } from '../../log/core/logGroups.ts';
|
|
4
6
|
|
|
5
7
|
import type { RefinedMinimum } from './conformerRefineRank.ts';
|
|
6
8
|
import {
|
|
@@ -20,6 +22,7 @@ import {
|
|
|
20
22
|
writeRelaxedCoordinates,
|
|
21
23
|
} from './moleculeCoordinates.ts';
|
|
22
24
|
import { toMolfileExport } from './molfileExport.ts';
|
|
25
|
+
import { relaxerLogLines } from './relaxerLogLines.ts';
|
|
23
26
|
|
|
24
27
|
/** What refining one conformer produced, on top of its force-field numbers. */
|
|
25
28
|
export interface ConformerRefinement {
|
|
@@ -70,8 +73,11 @@ export interface ConformerSetRefinement {
|
|
|
70
73
|
reordered: number;
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
/** How a refinement
|
|
74
|
-
export interface RefineConformersOptions extends
|
|
76
|
+
/** How a refinement is tuned and watched; what it logs is kept on the set. */
|
|
77
|
+
export interface RefineConformersOptions extends Omit<
|
|
78
|
+
RelaxerOptions,
|
|
79
|
+
'logger'
|
|
80
|
+
> {
|
|
75
81
|
/**
|
|
76
82
|
* Name of the method, for the label the UI shows.
|
|
77
83
|
* @default 'GFN2-xTB'
|
|
@@ -155,11 +161,13 @@ export async function refineConformers(
|
|
|
155
161
|
});
|
|
156
162
|
}
|
|
157
163
|
|
|
164
|
+
const relaxerLog = new FifoLogger({ level: 'info' });
|
|
158
165
|
const relaxed = await relax(
|
|
159
166
|
prepared.map((entry) => entry.geometry),
|
|
160
167
|
{
|
|
161
168
|
onSettled: options.onSettled,
|
|
162
169
|
signal: options.signal,
|
|
170
|
+
logger: relaxerLog,
|
|
163
171
|
},
|
|
164
172
|
);
|
|
165
173
|
if (relaxed.length !== set.conformers.length) {
|
|
@@ -170,7 +178,9 @@ export async function refineConformers(
|
|
|
170
178
|
|
|
171
179
|
const tolerance =
|
|
172
180
|
options.sameEnergyTolerance ?? REFINED_SAME_ENERGY_TOLERANCE;
|
|
173
|
-
const
|
|
181
|
+
const own: LogLine[] = [];
|
|
182
|
+
// Each structure's label, `null` for one merged away with its messages.
|
|
183
|
+
const sources = new Array<string | null>(prepared.length).fill(null);
|
|
174
184
|
const kept: Conformer[] = [];
|
|
175
185
|
const minima: RefinedMinimum[] = [];
|
|
176
186
|
let merged = 0;
|
|
@@ -188,13 +198,14 @@ export async function refineConformers(
|
|
|
188
198
|
merged++;
|
|
189
199
|
continue;
|
|
190
200
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
201
|
+
const source = `${ordinal(conformer.id)} conformer`;
|
|
202
|
+
sources[index] = source;
|
|
194
203
|
if (!result.converged) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
204
|
+
own.push({
|
|
205
|
+
levelLabel: 'warn',
|
|
206
|
+
message: `It did not reach a ${method} minimum in ${result.cycles} cycles, so its refined energy is an upper bound.`,
|
|
207
|
+
meta: { source },
|
|
208
|
+
});
|
|
198
209
|
}
|
|
199
210
|
kept.push({
|
|
200
211
|
...conformer,
|
|
@@ -214,15 +225,20 @@ export async function refineConformers(
|
|
|
214
225
|
}
|
|
215
226
|
|
|
216
227
|
if (merged > 0) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
228
|
+
own.push({
|
|
229
|
+
levelLabel: 'info',
|
|
230
|
+
message: `${merged} conformer(s) relaxed into a ${method} minimum the set already held, so they were dropped.`,
|
|
231
|
+
});
|
|
220
232
|
}
|
|
221
233
|
const ranked = rankByRefinedEnergy(kept);
|
|
222
234
|
return {
|
|
223
235
|
...set,
|
|
224
236
|
conformers: ranked.conformers,
|
|
225
|
-
|
|
237
|
+
logs: [
|
|
238
|
+
...set.logs,
|
|
239
|
+
...relaxerLogLines(relaxerLog.getLogs(), sources),
|
|
240
|
+
...own,
|
|
241
|
+
],
|
|
226
242
|
rankedBy: REFINED_RANKING,
|
|
227
243
|
refinement: {
|
|
228
244
|
method,
|
|
@@ -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';
|