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.
Files changed (97) hide show
  1. package/README.md +29 -0
  2. package/lib/core.d.ts +1 -0
  3. package/lib/core.d.ts.map +1 -1
  4. package/lib/core.js +1 -0
  5. package/lib/core.js.map +1 -1
  6. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  7. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  8. package/lib/locales/de.json +4 -0
  9. package/lib/locales/en.json +4 -0
  10. package/lib/locales/es.json +4 -0
  11. package/lib/locales/fr.json +4 -0
  12. package/lib/locales/it.json +4 -0
  13. package/lib/log/core/index.d.ts +4 -0
  14. package/lib/log/core/index.d.ts.map +1 -0
  15. package/lib/log/core/index.js +3 -0
  16. package/lib/log/core/index.js.map +1 -0
  17. package/lib/log/core/logGroups.d.ts +87 -0
  18. package/lib/log/core/logGroups.d.ts.map +1 -0
  19. package/lib/log/core/logGroups.js +85 -0
  20. package/lib/log/core/logGroups.js.map +1 -0
  21. package/lib/log/core/logLines.d.ts +19 -0
  22. package/lib/log/core/logLines.d.ts.map +1 -0
  23. package/lib/log/core/logLines.js +36 -0
  24. package/lib/log/core/logLines.js.map +1 -0
  25. package/lib/log/ui/LogBadge.d.ts +39 -0
  26. package/lib/log/ui/LogBadge.d.ts.map +1 -0
  27. package/lib/log/ui/LogBadge.js +28 -0
  28. package/lib/log/ui/LogBadge.js.map +1 -0
  29. package/lib/log/ui/LogCallouts.d.ts +55 -0
  30. package/lib/log/ui/LogCallouts.d.ts.map +1 -0
  31. package/lib/log/ui/LogCallouts.js +38 -0
  32. package/lib/log/ui/LogCallouts.js.map +1 -0
  33. package/lib/log/ui/index.d.ts +7 -0
  34. package/lib/log/ui/index.d.ts.map +1 -0
  35. package/lib/log/ui/index.js +5 -0
  36. package/lib/log/ui/index.js.map +1 -0
  37. package/lib/log/ui/logIcon.d.ts +9 -0
  38. package/lib/log/ui/logIcon.d.ts.map +1 -0
  39. package/lib/log/ui/logIcon.js +17 -0
  40. package/lib/log/ui/logIcon.js.map +1 -0
  41. package/lib/log/ui/useLogEntries.d.ts +15 -0
  42. package/lib/log/ui/useLogEntries.d.ts.map +1 -0
  43. package/lib/log/ui/useLogEntries.js +47 -0
  44. package/lib/log/ui/useLogEntries.js.map +1 -0
  45. package/lib/structure/core/conformerMinimise.d.ts +13 -4
  46. package/lib/structure/core/conformerMinimise.d.ts.map +1 -1
  47. package/lib/structure/core/conformerMinimise.js +23 -6
  48. package/lib/structure/core/conformerMinimise.js.map +1 -1
  49. package/lib/structure/core/conformerRefine.d.ts +2 -2
  50. package/lib/structure/core/conformerRefine.d.ts.map +1 -1
  51. package/lib/structure/core/conformerRefine.js +23 -7
  52. package/lib/structure/core/conformerRefine.js.map +1 -1
  53. package/lib/structure/core/conformers.d.ts +8 -3
  54. package/lib/structure/core/conformers.d.ts.map +1 -1
  55. package/lib/structure/core/conformers.js +10 -7
  56. package/lib/structure/core/conformers.js.map +1 -1
  57. package/lib/structure/core/geometryRelaxer.d.ts +10 -3
  58. package/lib/structure/core/geometryRelaxer.d.ts.map +1 -1
  59. package/lib/structure/core/relaxerLogLines.d.ts +16 -0
  60. package/lib/structure/core/relaxerLogLines.d.ts.map +1 -0
  61. package/lib/structure/core/relaxerLogLines.js +33 -0
  62. package/lib/structure/core/relaxerLogLines.js.map +1 -0
  63. package/lib/ui.d.ts +1 -0
  64. package/lib/ui.d.ts.map +1 -1
  65. package/lib/ui.js +1 -0
  66. package/lib/ui.js.map +1 -1
  67. package/lib/xtb/core/taggedLogger.d.ts +11 -0
  68. package/lib/xtb/core/taggedLogger.d.ts.map +1 -0
  69. package/lib/xtb/core/taggedLogger.js +31 -0
  70. package/lib/xtb/core/taggedLogger.js.map +1 -0
  71. package/lib/xtb/core/xtbRelaxer.d.ts.map +1 -1
  72. package/lib/xtb/core/xtbRelaxer.js +13 -5
  73. package/lib/xtb/core/xtbRelaxer.js.map +1 -1
  74. package/package.json +4 -3
  75. package/src/core.ts +1 -0
  76. package/src/locales/de.json +4 -0
  77. package/src/locales/en.json +4 -0
  78. package/src/locales/es.json +4 -0
  79. package/src/locales/fr.json +4 -0
  80. package/src/locales/it.json +4 -0
  81. package/src/log/core/index.ts +9 -0
  82. package/src/log/core/logGroups.ts +159 -0
  83. package/src/log/core/logLines.ts +44 -0
  84. package/src/log/ui/LogBadge.tsx +89 -0
  85. package/src/log/ui/LogCallouts.tsx +103 -0
  86. package/src/log/ui/index.ts +6 -0
  87. package/src/log/ui/logIcon.ts +21 -0
  88. package/src/log/ui/useLogEntries.ts +57 -0
  89. package/src/structure/core/conformerMinimise.ts +34 -8
  90. package/src/structure/core/conformerRefine.ts +29 -13
  91. package/src/structure/core/conformers.ts +23 -12
  92. package/src/structure/core/geometryRelaxer.ts +11 -3
  93. package/src/structure/core/relaxerLogLines.ts +39 -0
  94. package/src/ui.ts +1 -0
  95. package/src/xtb/core/taggedLogger.ts +35 -0
  96. package/src/xtb/core/xtbRelaxer.ts +15 -5
  97. package/styles/chrome.css +34 -0
@@ -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 cancellation.
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 (runOptions.signal?.aborted === true) {
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
- runOptions.onSettled?.(index + 1, requests.length);
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
  /*