react-cheminfo 0.75.0 → 0.77.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 +141 -31
- package/lib/card/core/cardAddress.d.ts +19 -2
- package/lib/card/core/cardAddress.d.ts.map +1 -1
- package/lib/card/core/cardAddress.js +35 -2
- package/lib/card/core/cardAddress.js.map +1 -1
- package/lib/card/core/cardPageUrl.d.ts +7 -1
- package/lib/card/core/cardPageUrl.d.ts.map +1 -1
- package/lib/card/core/cardPageUrl.js +4 -2
- package/lib/card/core/cardPageUrl.js.map +1 -1
- package/lib/card/core/index.d.ts +1 -1
- package/lib/card/core/index.d.ts.map +1 -1
- package/lib/card/core/index.js +1 -1
- package/lib/card/core/index.js.map +1 -1
- package/lib/credits/core/credits.d.ts +30 -0
- package/lib/credits/core/credits.d.ts.map +1 -1
- package/lib/credits/core/credits.js +35 -0
- package/lib/credits/core/credits.js.map +1 -1
- package/lib/download/core/copySvg.d.ts +12 -0
- package/lib/download/core/copySvg.d.ts.map +1 -0
- package/lib/download/core/copySvg.js +38 -0
- package/lib/download/core/copySvg.js.map +1 -0
- package/lib/download/core/downloadFigure.d.ts +12 -1
- package/lib/download/core/downloadFigure.d.ts.map +1 -1
- package/lib/download/core/downloadFigure.js +21 -0
- package/lib/download/core/downloadFigure.js.map +1 -1
- package/lib/download/core/figureDpi.d.ts +59 -0
- package/lib/download/core/figureDpi.d.ts.map +1 -0
- package/lib/download/core/figureDpi.js +75 -0
- package/lib/download/core/figureDpi.js.map +1 -0
- package/lib/download/core/figurePng.d.ts +4 -1
- package/lib/download/core/figurePng.d.ts.map +1 -1
- package/lib/download/core/figurePng.js +11 -2
- package/lib/download/core/figurePng.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 +4 -1
- package/lib/download/core/index.js.map +1 -1
- package/lib/download/core/pngDpi.d.ts +22 -0
- package/lib/download/core/pngDpi.d.ts.map +1 -0
- package/lib/download/core/pngDpi.js +79 -0
- package/lib/download/core/pngDpi.js.map +1 -0
- package/lib/download/ui/FigureDownloadPanel.d.ts +13 -0
- package/lib/download/ui/FigureDownloadPanel.d.ts.map +1 -1
- package/lib/download/ui/FigureDownloadPanel.js +18 -34
- package/lib/download/ui/FigureDownloadPanel.js.map +1 -1
- package/lib/download/ui/figureDownloadHint.d.ts +5 -0
- package/lib/download/ui/figureDownloadHint.d.ts.map +1 -1
- package/lib/download/ui/figureDownloadHint.js +8 -0
- package/lib/download/ui/figureDownloadHint.js.map +1 -1
- package/lib/download/ui/figureDownloadOptions.d.ts +84 -0
- package/lib/download/ui/figureDownloadOptions.d.ts.map +1 -0
- package/lib/download/ui/figureDownloadOptions.js +2 -0
- package/lib/download/ui/figureDownloadOptions.js.map +1 -0
- package/lib/download/ui/resolutionChoices.d.ts +27 -0
- package/lib/download/ui/resolutionChoices.d.ts.map +1 -0
- package/lib/download/ui/resolutionChoices.js +48 -0
- package/lib/download/ui/resolutionChoices.js.map +1 -0
- package/lib/download/ui/useFigureActions.d.ts +4 -1
- package/lib/download/ui/useFigureActions.d.ts.map +1 -1
- package/lib/download/ui/useFigureActions.js +17 -8
- package/lib/download/ui/useFigureActions.js.map +1 -1
- package/lib/download/ui/useFigureDownload.d.ts +2 -55
- package/lib/download/ui/useFigureDownload.d.ts.map +1 -1
- package/lib/download/ui/useFigureDownload.js +45 -13
- package/lib/download/ui/useFigureDownload.js.map +1 -1
- package/lib/ecosystem/core/sites.d.ts.map +1 -1
- package/lib/ecosystem/core/sites.js +14 -0
- package/lib/ecosystem/core/sites.js.map +1 -1
- package/lib/ecosystem/core/types.d.ts +1 -1
- package/lib/ecosystem/core/types.d.ts.map +1 -1
- package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
- package/lib/ecosystem/ui/glyphs.js +3 -0
- package/lib/ecosystem/ui/glyphs.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/ir/core/bandAssignments.d.ts.map +1 -1
- package/lib/ir/core/bandAssignments.js +27 -0
- package/lib/ir/core/bandAssignments.js.map +1 -1
- package/lib/ir/ui/BandRow.d.ts +4 -4
- package/lib/ir/ui/BandRow.d.ts.map +1 -1
- package/lib/ir/ui/BandRow.js +41 -14
- package/lib/ir/ui/BandRow.js.map +1 -1
- package/lib/locales/de.json +32 -1
- package/lib/locales/en.json +32 -1
- package/lib/locales/es.json +32 -1
- package/lib/locales/fr.json +32 -1
- package/lib/locales/it.json +32 -1
- package/lib/molecule3d/ui/Molecule3DStage.d.ts +4 -33
- package/lib/molecule3d/ui/Molecule3DStage.d.ts.map +1 -1
- package/lib/molecule3d/ui/Molecule3DStage.js +3 -37
- package/lib/molecule3d/ui/Molecule3DStage.js.map +1 -1
- package/lib/osiris/core/barGeometry.d.ts +42 -0
- package/lib/osiris/core/barGeometry.d.ts.map +1 -0
- package/lib/osiris/core/barGeometry.js +46 -0
- package/lib/osiris/core/barGeometry.js.map +1 -0
- package/lib/osiris/core/computeProperties.d.ts +42 -0
- package/lib/osiris/core/computeProperties.d.ts.map +1 -0
- package/lib/osiris/core/computeProperties.js +115 -0
- package/lib/osiris/core/computeProperties.js.map +1 -0
- package/lib/osiris/core/constants.d.ts +70 -0
- package/lib/osiris/core/constants.d.ts.map +1 -0
- package/lib/osiris/core/constants.js +99 -0
- package/lib/osiris/core/constants.js.map +1 -0
- package/lib/osiris/core/fitness.d.ts +32 -0
- package/lib/osiris/core/fitness.d.ts.map +1 -0
- package/lib/osiris/core/fitness.js +48 -0
- package/lib/osiris/core/fitness.js.map +1 -0
- package/lib/osiris/core/index.d.ts +29 -0
- package/lib/osiris/core/index.d.ts.map +1 -0
- package/lib/osiris/core/index.js +19 -0
- package/lib/osiris/core/index.js.map +1 -0
- package/lib/osiris/core/poolSize.d.ts +17 -0
- package/lib/osiris/core/poolSize.d.ts.map +1 -0
- package/lib/osiris/core/poolSize.js +22 -0
- package/lib/osiris/core/poolSize.js.map +1 -0
- package/lib/osiris/core/poolTypes.d.ts +140 -0
- package/lib/osiris/core/poolTypes.d.ts.map +1 -0
- package/lib/osiris/core/poolTypes.js +12 -0
- package/lib/osiris/core/poolTypes.js.map +1 -0
- package/lib/osiris/core/predictIdCode.d.ts +39 -0
- package/lib/osiris/core/predictIdCode.d.ts.map +1 -0
- package/lib/osiris/core/predictIdCode.js +54 -0
- package/lib/osiris/core/predictIdCode.js.map +1 -0
- package/lib/osiris/core/predictProtocol.d.ts +67 -0
- package/lib/osiris/core/predictProtocol.d.ts.map +1 -0
- package/lib/osiris/core/predictProtocol.js +29 -0
- package/lib/osiris/core/predictProtocol.js.map +1 -0
- package/lib/osiris/core/predictionPool.d.ts +23 -0
- package/lib/osiris/core/predictionPool.d.ts.map +1 -0
- package/lib/osiris/core/predictionPool.js +186 -0
- package/lib/osiris/core/predictionPool.js.map +1 -0
- package/lib/osiris/core/predictionQueue.d.ts +46 -0
- package/lib/osiris/core/predictionQueue.d.ts.map +1 -0
- package/lib/osiris/core/predictionQueue.js +57 -0
- package/lib/osiris/core/predictionQueue.js.map +1 -0
- package/lib/osiris/core/predictors.d.ts +62 -0
- package/lib/osiris/core/predictors.d.ts.map +1 -0
- package/lib/osiris/core/predictors.js +100 -0
- package/lib/osiris/core/predictors.js.map +1 -0
- package/lib/osiris/core/propertyKeys.d.ts +32 -0
- package/lib/osiris/core/propertyKeys.d.ts.map +1 -0
- package/lib/osiris/core/propertyKeys.js +44 -0
- package/lib/osiris/core/propertyKeys.js.map +1 -0
- package/lib/osiris/core/riskAppearance.d.ts +60 -0
- package/lib/osiris/core/riskAppearance.d.ts.map +1 -0
- package/lib/osiris/core/riskAppearance.js +59 -0
- package/lib/osiris/core/riskAppearance.js.map +1 -0
- package/lib/osiris/core/riskDetail.d.ts +22 -0
- package/lib/osiris/core/riskDetail.d.ts.map +1 -0
- package/lib/osiris/core/riskDetail.js +86 -0
- package/lib/osiris/core/riskDetail.js.map +1 -0
- package/lib/osiris/core/riskDetailRequest.d.ts +31 -0
- package/lib/osiris/core/riskDetailRequest.d.ts.map +1 -0
- package/lib/osiris/core/riskDetailRequest.js +49 -0
- package/lib/osiris/core/riskDetailRequest.js.map +1 -0
- package/lib/osiris/core/riskFindings.d.ts +26 -0
- package/lib/osiris/core/riskFindings.d.ts.map +1 -0
- package/lib/osiris/core/riskFindings.js +79 -0
- package/lib/osiris/core/riskFindings.js.map +1 -0
- package/lib/osiris/core/runPredictionJob.d.ts +20 -0
- package/lib/osiris/core/runPredictionJob.d.ts.map +1 -0
- package/lib/osiris/core/runPredictionJob.js +43 -0
- package/lib/osiris/core/runPredictionJob.js.map +1 -0
- package/lib/osiris/core/scales.d.ts +70 -0
- package/lib/osiris/core/scales.d.ts.map +1 -0
- package/lib/osiris/core/scales.js +185 -0
- package/lib/osiris/core/scales.js.map +1 -0
- package/lib/osiris/core/types.d.ts +91 -0
- package/lib/osiris/core/types.d.ts.map +1 -0
- package/lib/osiris/core/types.js +19 -0
- package/lib/osiris/core/types.js.map +1 -0
- package/lib/osiris/core/valuation.d.ts +28 -0
- package/lib/osiris/core/valuation.d.ts.map +1 -0
- package/lib/osiris/core/valuation.js +39 -0
- package/lib/osiris/core/valuation.js.map +1 -0
- package/lib/osiris/ui/PropertyBar.d.ts +27 -0
- package/lib/osiris/ui/PropertyBar.d.ts.map +1 -0
- package/lib/osiris/ui/PropertyBar.js +27 -0
- package/lib/osiris/ui/PropertyBar.js.map +1 -0
- package/lib/osiris/ui/PropertyPanel.d.ts +91 -0
- package/lib/osiris/ui/PropertyPanel.d.ts.map +1 -0
- package/lib/osiris/ui/PropertyPanel.js +77 -0
- package/lib/osiris/ui/PropertyPanel.js.map +1 -0
- package/lib/osiris/ui/PropertyRows.d.ts +40 -0
- package/lib/osiris/ui/PropertyRows.d.ts.map +1 -0
- package/lib/osiris/ui/PropertyRows.js +23 -0
- package/lib/osiris/ui/PropertyRows.js.map +1 -0
- package/lib/osiris/ui/RiskFindings.d.ts +43 -0
- package/lib/osiris/ui/RiskFindings.d.ts.map +1 -0
- package/lib/osiris/ui/RiskFindings.js +51 -0
- package/lib/osiris/ui/RiskFindings.js.map +1 -0
- package/lib/osiris/ui/RiskPanel.d.ts +46 -0
- package/lib/osiris/ui/RiskPanel.d.ts.map +1 -0
- package/lib/osiris/ui/RiskPanel.js +32 -0
- package/lib/osiris/ui/RiskPanel.js.map +1 -0
- package/lib/osiris/ui/RiskSquare.d.ts +51 -0
- package/lib/osiris/ui/RiskSquare.d.ts.map +1 -0
- package/lib/osiris/ui/RiskSquare.js +23 -0
- package/lib/osiris/ui/RiskSquare.js.map +1 -0
- package/lib/osiris/ui/index.d.ts +15 -0
- package/lib/osiris/ui/index.d.ts.map +1 -0
- package/lib/osiris/ui/index.js +8 -0
- package/lib/osiris/ui/index.js.map +1 -0
- package/lib/osiris/ui/usePredictions.d.ts +81 -0
- package/lib/osiris/ui/usePredictions.d.ts.map +1 -0
- package/lib/osiris/ui/usePredictions.js +102 -0
- package/lib/osiris/ui/usePredictions.js.map +1 -0
- package/lib/osiris-ui.d.ts +11 -0
- package/lib/osiris-ui.d.ts.map +1 -0
- package/lib/osiris-ui.js +11 -0
- package/lib/osiris-ui.js.map +1 -0
- package/lib/osiris.d.ts +17 -0
- package/lib/osiris.d.ts.map +1 -0
- package/lib/osiris.js +17 -0
- package/lib/osiris.js.map +1 -0
- package/lib/panel/ui/FilterInput.d.ts.map +1 -1
- package/lib/panel/ui/FilterInput.js +3 -1
- package/lib/panel/ui/FilterInput.js.map +1 -1
- package/lib/panel/ui/SidePanelItem.d.ts +39 -0
- package/lib/panel/ui/SidePanelItem.d.ts.map +1 -0
- package/lib/panel/ui/SidePanelItem.js +63 -0
- package/lib/panel/ui/SidePanelItem.js.map +1 -0
- package/lib/panel/ui/SidePanelStack.d.ts +11 -10
- package/lib/panel/ui/SidePanelStack.d.ts.map +1 -1
- package/lib/panel/ui/SidePanelStack.js +22 -15
- package/lib/panel/ui/SidePanelStack.js.map +1 -1
- package/lib/panel/ui/SpectrumColorSwatch.d.ts.map +1 -1
- package/lib/panel/ui/SpectrumColorSwatch.js +4 -2
- package/lib/panel/ui/SpectrumColorSwatch.js.map +1 -1
- package/lib/panel/ui/usePanelFolds.d.ts +35 -0
- package/lib/panel/ui/usePanelFolds.d.ts.map +1 -0
- package/lib/panel/ui/usePanelFolds.js +73 -0
- package/lib/panel/ui/usePanelFolds.js.map +1 -0
- package/lib/shared/ui/FullscreenStage.d.ts +43 -0
- package/lib/shared/ui/FullscreenStage.d.ts.map +1 -0
- package/lib/shared/ui/FullscreenStage.js +38 -0
- package/lib/shared/ui/FullscreenStage.js.map +1 -0
- package/lib/shared/ui/canFillScreen.d.ts +7 -0
- package/lib/shared/ui/canFillScreen.d.ts.map +1 -0
- package/lib/shared/ui/canFillScreen.js +9 -0
- package/lib/shared/ui/canFillScreen.js.map +1 -0
- package/lib/shared/ui/index.d.ts +3 -0
- package/lib/shared/ui/index.d.ts.map +1 -1
- package/lib/shared/ui/index.js +2 -0
- package/lib/shared/ui/index.js.map +1 -1
- package/lib/split/ui/splitPanes.d.ts +3 -3
- package/lib/split/ui/splitPanes.js +1 -1
- package/lib/structure/core/structureNotations.d.ts +8 -1
- package/lib/structure/core/structureNotations.d.ts.map +1 -1
- package/lib/structure/core/structureNotations.js +14 -8
- package/lib/structure/core/structureNotations.js.map +1 -1
- package/lib/structure/ui/CardStructure.d.ts +43 -0
- package/lib/structure/ui/CardStructure.d.ts.map +1 -0
- package/lib/structure/ui/CardStructure.js +28 -0
- package/lib/structure/ui/CardStructure.js.map +1 -0
- package/lib/structure/ui/StructureExportPanel.d.ts +8 -0
- package/lib/structure/ui/StructureExportPanel.d.ts.map +1 -1
- package/lib/structure/ui/StructureExportPanel.js +9 -4
- package/lib/structure/ui/StructureExportPanel.js.map +1 -1
- package/lib/structure/ui/StructurePicturePane.d.ts +1 -1
- package/lib/structure/ui/StructurePicturePane.d.ts.map +1 -1
- package/lib/structure/ui/StructurePicturePane.js +5 -2
- package/lib/structure/ui/StructurePicturePane.js.map +1 -1
- package/lib/structure/ui/index.d.ts +3 -0
- package/lib/structure/ui/index.d.ts.map +1 -1
- package/lib/structure/ui/index.js +1 -0
- package/lib/structure/ui/index.js.map +1 -1
- package/package.json +4 -1
- package/src/card/core/cardAddress.ts +39 -3
- package/src/card/core/cardPageUrl.ts +10 -3
- package/src/card/core/index.ts +7 -1
- package/src/credits/core/credits.ts +40 -0
- package/src/download/core/copySvg.ts +40 -0
- package/src/download/core/downloadFigure.ts +26 -1
- package/src/download/core/figureDpi.ts +94 -0
- package/src/download/core/figurePng.ts +11 -2
- package/src/download/core/index.ts +14 -1
- package/src/download/core/pngDpi.ts +84 -0
- package/src/download/ui/FigureDownloadPanel.tsx +41 -51
- package/src/download/ui/figureDownloadHint.ts +13 -0
- package/src/download/ui/figureDownloadOptions.ts +85 -0
- package/src/download/ui/resolutionChoices.ts +67 -0
- package/src/download/ui/useFigureActions.ts +24 -9
- package/src/download/ui/useFigureDownload.tsx +57 -71
- package/src/ecosystem/core/sites.ts +14 -0
- package/src/ecosystem/core/types.ts +2 -1
- package/src/ecosystem/ui/glyphs.tsx +20 -0
- package/src/ir/core/bandAssignments.ts +27 -0
- package/src/ir/ui/BandRow.tsx +84 -26
- package/src/locales/de.json +32 -1
- package/src/locales/en.json +32 -1
- package/src/locales/es.json +32 -1
- package/src/locales/fr.json +32 -1
- package/src/locales/it.json +32 -1
- package/src/molecule3d/ui/Molecule3DStage.tsx +4 -88
- package/src/osiris/core/barGeometry.ts +74 -0
- package/src/osiris/core/computeProperties.ts +175 -0
- package/src/osiris/core/constants.ts +110 -0
- package/src/osiris/core/fitness.ts +59 -0
- package/src/osiris/core/index.ts +78 -0
- package/src/osiris/core/poolSize.ts +24 -0
- package/src/osiris/core/poolTypes.ts +140 -0
- package/src/osiris/core/predictIdCode.ts +69 -0
- package/src/osiris/core/predictProtocol.ts +78 -0
- package/src/osiris/core/predictionPool.ts +237 -0
- package/src/osiris/core/predictionQueue.ts +89 -0
- package/src/osiris/core/predictors.ts +142 -0
- package/src/osiris/core/propertyKeys.ts +54 -0
- package/src/osiris/core/riskAppearance.ts +86 -0
- package/src/osiris/core/riskDetail.ts +120 -0
- package/src/osiris/core/riskDetailRequest.ts +64 -0
- package/src/osiris/core/riskFindings.ts +92 -0
- package/src/osiris/core/runPredictionJob.ts +49 -0
- package/src/osiris/core/scales.ts +236 -0
- package/src/osiris/core/types.ts +103 -0
- package/src/osiris/core/valuation.ts +44 -0
- package/src/osiris/ui/PropertyBar.tsx +77 -0
- package/src/osiris/ui/PropertyPanel.tsx +227 -0
- package/src/osiris/ui/PropertyRows.tsx +92 -0
- package/src/osiris/ui/RiskFindings.tsx +137 -0
- package/src/osiris/ui/RiskPanel.tsx +81 -0
- package/src/osiris/ui/RiskSquare.tsx +108 -0
- package/src/osiris/ui/index.ts +17 -0
- package/src/osiris/ui/usePredictions.ts +194 -0
- package/src/osiris-ui.ts +11 -0
- package/src/osiris.ts +17 -0
- package/src/panel/ui/FilterInput.tsx +4 -1
- package/src/panel/ui/SidePanelItem.tsx +162 -0
- package/src/panel/ui/SidePanelStack.tsx +29 -36
- package/src/panel/ui/SpectrumColorSwatch.tsx +5 -3
- package/src/panel/ui/usePanelFolds.ts +103 -0
- package/src/shared/ui/FullscreenStage.tsx +96 -0
- package/src/shared/ui/canFillScreen.ts +8 -0
- package/src/shared/ui/index.ts +6 -0
- package/src/split/ui/splitPanes.tsx +4 -4
- package/src/structure/core/structureNotations.ts +25 -8
- package/src/structure/ui/CardStructure.tsx +76 -0
- package/src/structure/ui/StructureExportPanel.tsx +23 -4
- package/src/structure/ui/StructurePicturePane.tsx +14 -1
- package/src/structure/ui/index.ts +6 -0
- package/styles/chrome.css +3 -3
- package/styles/osiris.css +339 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ten predicted numbers, one row each: a name, a bar and a value.
|
|
3
|
+
*
|
|
4
|
+
* The order is the legacy panel's — cLogP, solubility, molweight, TPSA,
|
|
5
|
+
* drug-likeness, the two hydrogen-bond counts, stereocentres, rotatable bonds,
|
|
6
|
+
* drug score — and it is `PROPERTY_KEYS`, which the comparison table's columns
|
|
7
|
+
* and the plot's default axes also read. A reader who learned the panel reads
|
|
8
|
+
* the table without relearning it.
|
|
9
|
+
*
|
|
10
|
+
* A value the predictor could not answer prints the missing marker and draws no
|
|
11
|
+
* bar. It is never zero: `DrugScoreCalculator` consumes every sentinel and
|
|
12
|
+
* hands back a plausible number, so a bar drawn from one would be a wrong
|
|
13
|
+
* answer with nothing saying it is wrong.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { ReactElement } from 'react';
|
|
17
|
+
|
|
18
|
+
import { MISSING_VALUE } from '../../format/core/missing.ts';
|
|
19
|
+
import { formatDecimal } from '../../format/core/numbers.ts';
|
|
20
|
+
import { barGeometry } from '../core/barGeometry.ts';
|
|
21
|
+
import type { PropertyKey } from '../core/propertyKeys.ts';
|
|
22
|
+
import { PROPERTY_KEYS, propertyValue } from '../core/propertyKeys.ts';
|
|
23
|
+
import { propertyScale } from '../core/scales.ts';
|
|
24
|
+
import type { OsirisProperties } from '../core/types.ts';
|
|
25
|
+
|
|
26
|
+
import { PropertyBar } from './PropertyBar.tsx';
|
|
27
|
+
|
|
28
|
+
/** What {@link PropertyRows} needs. */
|
|
29
|
+
export interface PropertyRowsProps {
|
|
30
|
+
/**
|
|
31
|
+
* What was predicted, or `null` while the molecule is still being worked on —
|
|
32
|
+
* in which case every row stands with its name and no value, so nothing moves
|
|
33
|
+
* when the answer arrives.
|
|
34
|
+
* @default null
|
|
35
|
+
*/
|
|
36
|
+
properties?: OsirisProperties | null;
|
|
37
|
+
/**
|
|
38
|
+
* The rows to draw. They are drawn in the panel's order whatever order they
|
|
39
|
+
* are given in, so a narrowed panel still reads as the whole one does.
|
|
40
|
+
* @default PROPERTY_KEYS
|
|
41
|
+
*/
|
|
42
|
+
keys?: readonly PropertyKey[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The property rows, all ten unless fewer are asked, in the panel's order.
|
|
47
|
+
* @param props - See {@link PropertyRowsProps}.
|
|
48
|
+
* @returns One row per property.
|
|
49
|
+
*/
|
|
50
|
+
export function PropertyRows(props: PropertyRowsProps): ReactElement {
|
|
51
|
+
const { properties = null, keys = PROPERTY_KEYS } = props;
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div className="property-rows">
|
|
55
|
+
{PROPERTY_KEYS.filter((key) => keys.includes(key)).map((key) => (
|
|
56
|
+
<PropertyRow
|
|
57
|
+
key={key}
|
|
58
|
+
propertyKey={key}
|
|
59
|
+
value={properties === null ? null : propertyValue(properties, key)}
|
|
60
|
+
/>
|
|
61
|
+
))}
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface PropertyRowProps {
|
|
67
|
+
propertyKey: PropertyKey;
|
|
68
|
+
value: number | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function PropertyRow(props: PropertyRowProps): ReactElement {
|
|
72
|
+
const { propertyKey, value } = props;
|
|
73
|
+
const scale = propertyScale(propertyKey);
|
|
74
|
+
const geometry = barGeometry(propertyKey, value);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div className="property-row">
|
|
78
|
+
<span className="property-row__label">
|
|
79
|
+
{scale.label}
|
|
80
|
+
{scale.unit === '' ? null : (
|
|
81
|
+
<span className="property-row__unit">{scale.unit}</span>
|
|
82
|
+
)}
|
|
83
|
+
</span>
|
|
84
|
+
<span className="property-row__bar">
|
|
85
|
+
{geometry === null ? null : <PropertyBar geometry={geometry} />}
|
|
86
|
+
</span>
|
|
87
|
+
<span className="property-row__value">
|
|
88
|
+
{value === null ? MISSING_VALUE : formatDecimal(value, scale.decimals)}
|
|
89
|
+
</span>
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why one risk came back as it did.
|
|
3
|
+
*
|
|
4
|
+
* Two branches of the predictor reach the same red square and mean different
|
|
5
|
+
* things. *This molecule is known to be mutagenic* means the compound's own
|
|
6
|
+
* idCode is in a list derived from RTECS — data on this exact compound, and
|
|
7
|
+
* nothing on the drawing to point at. *High-risk fragments indicating
|
|
8
|
+
* Mutagenicity* means a substructure matched, and that substructure is drawn
|
|
9
|
+
* beside the molecule with its atoms painted on it.
|
|
10
|
+
*
|
|
11
|
+
* Telling them apart is the whole point of opening a square: aspirin, caffeine
|
|
12
|
+
* and paracetamol are all red through the first branch, and highlighting the
|
|
13
|
+
* whole molecule there would call the compound its own toxicophore.
|
|
14
|
+
*
|
|
15
|
+
* A fragment heading is repeated on each of the fragments under it, so it is
|
|
16
|
+
* printed once and the matches follow.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { Callout, Spinner } from '@blueprintjs/core';
|
|
20
|
+
import type { ReactElement } from 'react';
|
|
21
|
+
|
|
22
|
+
import { Structure } from '../../structure/ui/Structure.tsx';
|
|
23
|
+
import { RISK_LABELS } from '../core/constants.ts';
|
|
24
|
+
import { KNOWN_MOLECULE_NOTE } from '../core/riskAppearance.ts';
|
|
25
|
+
import type { RiskDetail, RiskFinding, RiskType } from '../core/types.ts';
|
|
26
|
+
|
|
27
|
+
/** What {@link RiskFindings} needs. */
|
|
28
|
+
export interface RiskFindingsProps {
|
|
29
|
+
/** Which risk is open. */
|
|
30
|
+
risk: RiskType;
|
|
31
|
+
/** The molecule it was assessed on: the idCode, with its coordinates after a space. */
|
|
32
|
+
structure: string;
|
|
33
|
+
/**
|
|
34
|
+
* What the predictor found, or `null` while it is being worked out.
|
|
35
|
+
* @default null
|
|
36
|
+
*/
|
|
37
|
+
detail?: RiskDetail | null;
|
|
38
|
+
/**
|
|
39
|
+
* Why the explanation could not be fetched, or `null`.
|
|
40
|
+
* @default null
|
|
41
|
+
*/
|
|
42
|
+
error?: string | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** How big a drawing in the explanation is, in pixels. */
|
|
46
|
+
const DRAWING = { width: 190, height: 130 };
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The explanation of one risk.
|
|
50
|
+
* @param props - See {@link RiskFindingsProps}.
|
|
51
|
+
* @returns The predictor's own sentences, with every matched fragment drawn.
|
|
52
|
+
*/
|
|
53
|
+
export function RiskFindings(props: RiskFindingsProps): ReactElement {
|
|
54
|
+
const { risk, structure, detail = null, error = null } = props;
|
|
55
|
+
|
|
56
|
+
if (error !== null) {
|
|
57
|
+
return <Callout intent="warning">{error}</Callout>;
|
|
58
|
+
}
|
|
59
|
+
if (detail === null) {
|
|
60
|
+
return (
|
|
61
|
+
// A div, not a paragraph: the spinner draws a div of its own.
|
|
62
|
+
<div className="osiris-note osiris-note--working">
|
|
63
|
+
<Spinner size={14} /> Working out why {RISK_LABELS[risk]} came back as
|
|
64
|
+
it did.
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div className="risk-findings">
|
|
71
|
+
{detail.findings.map((finding, index) => (
|
|
72
|
+
<Finding
|
|
73
|
+
// The predictor prints each heading once and each matching fragment
|
|
74
|
+
// once under it, so the pair names the line without an index.
|
|
75
|
+
key={`${finding.kind}:${finding.description}:${finding.idCode ?? ''}`}
|
|
76
|
+
finding={finding}
|
|
77
|
+
structure={structure}
|
|
78
|
+
heading={
|
|
79
|
+
detail.findings[index - 1]?.description === finding.description
|
|
80
|
+
? null
|
|
81
|
+
: finding.description
|
|
82
|
+
}
|
|
83
|
+
/>
|
|
84
|
+
))}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface FindingProps {
|
|
90
|
+
finding: RiskFinding;
|
|
91
|
+
structure: string;
|
|
92
|
+
heading: string | null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function Finding(props: FindingProps): ReactElement {
|
|
96
|
+
const { finding, structure, heading } = props;
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<div className="risk-finding">
|
|
100
|
+
{heading === null ? null : (
|
|
101
|
+
<p className="risk-finding__heading">{heading}</p>
|
|
102
|
+
)}
|
|
103
|
+
{finding.kind === 'known' ? (
|
|
104
|
+
<p className="osiris-note">{KNOWN_MOLECULE_NOTE}</p>
|
|
105
|
+
) : null}
|
|
106
|
+
{finding.idCode === null ? null : (
|
|
107
|
+
<div className="risk-finding__drawings">
|
|
108
|
+
<figure className="risk-finding__figure">
|
|
109
|
+
<Structure
|
|
110
|
+
idCode={finding.idCode}
|
|
111
|
+
width={DRAWING.width}
|
|
112
|
+
height={DRAWING.height}
|
|
113
|
+
/>
|
|
114
|
+
<figcaption>
|
|
115
|
+
{finding.severity === 'medium' ? 'Medium-risk' : 'High-risk'}{' '}
|
|
116
|
+
fragment
|
|
117
|
+
</figcaption>
|
|
118
|
+
</figure>
|
|
119
|
+
<figure className="risk-finding__figure">
|
|
120
|
+
<Structure
|
|
121
|
+
idCode={structure}
|
|
122
|
+
width={DRAWING.width}
|
|
123
|
+
height={DRAWING.height}
|
|
124
|
+
atomHighlight={[...finding.atoms]}
|
|
125
|
+
bondHighlight={[...finding.bonds]}
|
|
126
|
+
/>
|
|
127
|
+
<figcaption>
|
|
128
|
+
{finding.atoms.length === 0
|
|
129
|
+
? 'Not located on this drawing'
|
|
130
|
+
: 'Where it sits on the molecule'}
|
|
131
|
+
</figcaption>
|
|
132
|
+
</figure>
|
|
133
|
+
</div>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The four toxicity risks, and the sentence that keeps them honest.
|
|
3
|
+
*
|
|
4
|
+
* OSIRIS assesses mutagenicity, tumorigenicity, irritating effects and
|
|
5
|
+
* reproductive effects, in that order, and answers each with one of three
|
|
6
|
+
* levels — the same three the drug score multiplies by. A red square is very
|
|
7
|
+
* often the known-molecule branch rather than a matched fragment, which is why
|
|
8
|
+
* every assessed square opens its explanation.
|
|
9
|
+
*
|
|
10
|
+
* The caveat under them is the author's own, quoted rather than paraphrased: it
|
|
11
|
+
* is the sentence that stops a red square being read as a verdict, and softening
|
|
12
|
+
* it would be our words over his.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { H5 } from '@blueprintjs/core';
|
|
16
|
+
import type { ReactElement } from 'react';
|
|
17
|
+
|
|
18
|
+
import { RISK_CAVEAT } from '../core/riskAppearance.ts';
|
|
19
|
+
import type { RiskLevel, RiskType } from '../core/types.ts';
|
|
20
|
+
import { RISK_TYPES } from '../core/types.ts';
|
|
21
|
+
|
|
22
|
+
import { RiskSquare } from './RiskSquare.tsx';
|
|
23
|
+
|
|
24
|
+
/** What {@link RiskPanel} needs. */
|
|
25
|
+
export interface RiskPanelProps {
|
|
26
|
+
/**
|
|
27
|
+
* How the four came back, or `null` when none of them has been assessed.
|
|
28
|
+
* @default null
|
|
29
|
+
*/
|
|
30
|
+
risks?: Record<RiskType, RiskLevel> | null;
|
|
31
|
+
/**
|
|
32
|
+
* Whether a prediction is running for the molecule the panel is showing.
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
pending?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Which risk has its explanation open.
|
|
38
|
+
* @default null
|
|
39
|
+
*/
|
|
40
|
+
openRisk?: RiskType | null;
|
|
41
|
+
/**
|
|
42
|
+
* Called with the risk to open, or `null` to close the one that is open.
|
|
43
|
+
* Without it the squares are not clickable.
|
|
44
|
+
* @default undefined
|
|
45
|
+
*/
|
|
46
|
+
onOpenRisk?: (risk: RiskType | null) => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The four risk squares.
|
|
51
|
+
* @param props - See {@link RiskPanelProps}.
|
|
52
|
+
* @returns The panel, with the caveat under it.
|
|
53
|
+
*/
|
|
54
|
+
export function RiskPanel(props: RiskPanelProps): ReactElement {
|
|
55
|
+
const { risks = null, pending = false, openRisk = null, onOpenRisk } = props;
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<section className="risk-panel">
|
|
59
|
+
<H5>Predicted toxicity risks</H5>
|
|
60
|
+
<div className="risk-grid">
|
|
61
|
+
{RISK_TYPES.map((risk) => (
|
|
62
|
+
<RiskSquare
|
|
63
|
+
key={risk}
|
|
64
|
+
risk={risk}
|
|
65
|
+
level={risks?.[risk]}
|
|
66
|
+
pending={pending}
|
|
67
|
+
selected={openRisk === risk}
|
|
68
|
+
onSelect={
|
|
69
|
+
onOpenRisk === undefined
|
|
70
|
+
? undefined
|
|
71
|
+
: (chosen) => {
|
|
72
|
+
onOpenRisk(chosen === openRisk ? null : chosen);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/>
|
|
76
|
+
))}
|
|
77
|
+
</div>
|
|
78
|
+
<p className="osiris-note">{RISK_CAVEAT}</p>
|
|
79
|
+
</section>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One toxicity risk, as a coloured square with its name beside it.
|
|
3
|
+
*
|
|
4
|
+
* The square is a button whenever the page can explain it, because the
|
|
5
|
+
* explanation is the honest half of the colour: aspirin, caffeine and
|
|
6
|
+
* paracetamol come back red through the known-molecule branch, not through a
|
|
7
|
+
* toxicophore, and only opening it says so.
|
|
8
|
+
*
|
|
9
|
+
* `compact` drops the words and keeps the square, which is what a cell of the
|
|
10
|
+
* comparison table needs; the name and the level stay on the accessible label,
|
|
11
|
+
* so the cell is still readable to a screen reader and on hover.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { ReactElement } from 'react';
|
|
15
|
+
|
|
16
|
+
import { RISK_LABELS } from '../core/constants.ts';
|
|
17
|
+
import { riskAppearance } from '../core/riskAppearance.ts';
|
|
18
|
+
import type { RiskLevel, RiskType } from '../core/types.ts';
|
|
19
|
+
|
|
20
|
+
/** What {@link RiskSquare} needs. */
|
|
21
|
+
export interface RiskSquareProps {
|
|
22
|
+
/** Which of the four risks this shows. */
|
|
23
|
+
risk: RiskType;
|
|
24
|
+
/** How it came back, or `undefined` when it has not been assessed. */
|
|
25
|
+
level: RiskLevel | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Whether a prediction is running for this molecule. It is what tells an
|
|
28
|
+
* unassessed square to say it is working rather than that there is nothing
|
|
29
|
+
* to work on.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
pending?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Whether this risk's explanation is the one open.
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
selected?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Called with the risk when the square is clicked. Without it the square is
|
|
40
|
+
* not a button.
|
|
41
|
+
* @default undefined
|
|
42
|
+
*/
|
|
43
|
+
onSelect?: (risk: RiskType) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Draw the square alone, for a cell of a table.
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
compact?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* One risk's square.
|
|
53
|
+
* @param props - See {@link RiskSquareProps}.
|
|
54
|
+
* @returns The square, as a button when the page can explain it.
|
|
55
|
+
*/
|
|
56
|
+
export function RiskSquare(props: RiskSquareProps): ReactElement {
|
|
57
|
+
const {
|
|
58
|
+
risk,
|
|
59
|
+
level,
|
|
60
|
+
pending = false,
|
|
61
|
+
selected = false,
|
|
62
|
+
onSelect,
|
|
63
|
+
compact = false,
|
|
64
|
+
} = props;
|
|
65
|
+
const { tone, label, explainable } = riskAppearance(level, pending);
|
|
66
|
+
const name = RISK_LABELS[risk];
|
|
67
|
+
const description = `${name}: ${label}`;
|
|
68
|
+
const clickable = onSelect !== undefined && explainable;
|
|
69
|
+
|
|
70
|
+
const body = (
|
|
71
|
+
<>
|
|
72
|
+
<span className="risk-square__swatch" data-level={tone} />
|
|
73
|
+
{compact ? null : (
|
|
74
|
+
<span className="risk-square__text">
|
|
75
|
+
<span className="risk-square__name">{name}</span>
|
|
76
|
+
<span className="risk-square__level">{label}</span>
|
|
77
|
+
</span>
|
|
78
|
+
)}
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
if (!clickable) {
|
|
83
|
+
return (
|
|
84
|
+
<span
|
|
85
|
+
className={compact ? 'risk-square risk-square--compact' : 'risk-square'}
|
|
86
|
+
title={description}
|
|
87
|
+
aria-label={compact ? description : undefined}
|
|
88
|
+
>
|
|
89
|
+
{body}
|
|
90
|
+
</span>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<button
|
|
96
|
+
type="button"
|
|
97
|
+
className={compact ? 'risk-square risk-square--compact' : 'risk-square'}
|
|
98
|
+
title={`${description} — why?`}
|
|
99
|
+
aria-label={compact ? description : undefined}
|
|
100
|
+
aria-pressed={selected}
|
|
101
|
+
onClick={() => {
|
|
102
|
+
onSelect(risk);
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
{body}
|
|
106
|
+
</button>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type { PropertyBarProps } from './PropertyBar.tsx';
|
|
2
|
+
export { PropertyBar } from './PropertyBar.tsx';
|
|
3
|
+
export type { PropertyPanelProps } from './PropertyPanel.tsx';
|
|
4
|
+
export { PropertyPanel } from './PropertyPanel.tsx';
|
|
5
|
+
export type { PropertyRowsProps } from './PropertyRows.tsx';
|
|
6
|
+
export { PropertyRows } from './PropertyRows.tsx';
|
|
7
|
+
export type { RiskFindingsProps } from './RiskFindings.tsx';
|
|
8
|
+
export { RiskFindings } from './RiskFindings.tsx';
|
|
9
|
+
export type { RiskPanelProps } from './RiskPanel.tsx';
|
|
10
|
+
export { RiskPanel } from './RiskPanel.tsx';
|
|
11
|
+
export type { RiskSquareProps } from './RiskSquare.tsx';
|
|
12
|
+
export { RiskSquare } from './RiskSquare.tsx';
|
|
13
|
+
export type {
|
|
14
|
+
UsePredictionsOptions,
|
|
15
|
+
UsePredictionsResult,
|
|
16
|
+
} from './usePredictions.ts';
|
|
17
|
+
export { usePredictions } from './usePredictions.ts';
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prediction pool, handed to a page.
|
|
3
|
+
*
|
|
4
|
+
* The only React in the domain. Results arrive one at a time and are kept in a
|
|
5
|
+
* map the page reads by row key, so a table draws every row immediately and
|
|
6
|
+
* fills each one in as its worker answers — nothing waits for the set.
|
|
7
|
+
*
|
|
8
|
+
* The two maps are created once and mutated, and a counter beside them changes
|
|
9
|
+
* to say so. Building a new map per answer would copy a growing map once per
|
|
10
|
+
* molecule, which on a set of two thousand costs more than the predictions do.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
14
|
+
|
|
15
|
+
import type { WorkerLike } from '../../worker/core/messages.ts';
|
|
16
|
+
import type {
|
|
17
|
+
PredictionInput,
|
|
18
|
+
PredictionPool,
|
|
19
|
+
PredictionProgress,
|
|
20
|
+
} from '../core/poolTypes.ts';
|
|
21
|
+
import { createPredictionPool } from '../core/predictionPool.ts';
|
|
22
|
+
import type { ResourceSource } from '../core/predictors.ts';
|
|
23
|
+
import type { OsirisProperties, RiskDetail, RiskType } from '../core/types.ts';
|
|
24
|
+
|
|
25
|
+
/** What a page gives the hook. */
|
|
26
|
+
export interface UsePredictionsOptions {
|
|
27
|
+
/**
|
|
28
|
+
* The molecules to predict. One already answered is never asked for again,
|
|
29
|
+
* so a page may pass its whole set on every render — though memoising it
|
|
30
|
+
* saves the filtering pass.
|
|
31
|
+
*/
|
|
32
|
+
molecules: readonly PredictionInput[];
|
|
33
|
+
/**
|
|
34
|
+
* The keys of the rows the reader can see, most wanted first. They are
|
|
35
|
+
* answered before the rest.
|
|
36
|
+
* @default undefined — the reading order is kept
|
|
37
|
+
*/
|
|
38
|
+
visibleKeys?: readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* Whether to predict at all. Off while a file is still being read, so the
|
|
41
|
+
* pool is not asked for half a set.
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
enabled?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Where the workers register OpenChemLib's resources from: the absolute URL
|
|
47
|
+
* of the site's own `openchemlib-resources.json`, resolved on the main thread
|
|
48
|
+
* — a worker has no `document` to read the deployment's mount path off, and
|
|
49
|
+
* a relative address would resolve against its hashed chunk.
|
|
50
|
+
*/
|
|
51
|
+
resources: ResourceSource;
|
|
52
|
+
/**
|
|
53
|
+
* Makes one prediction worker: a module worker of the site's own, serving
|
|
54
|
+
* `runPredictionJob` for the requests `isPredictRequest` accepts. It may be
|
|
55
|
+
* a new function on every render — it is read only when a worker is made.
|
|
56
|
+
*/
|
|
57
|
+
createWorker: () => WorkerLike;
|
|
58
|
+
/**
|
|
59
|
+
* How many workers to run.
|
|
60
|
+
* @default one fewer than the machine's cores, clamped to 1 to 8
|
|
61
|
+
*/
|
|
62
|
+
size?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** What the hook gives a page back. */
|
|
66
|
+
export interface UsePredictionsResult {
|
|
67
|
+
/** What each answered row was predicted to be, by row key. */
|
|
68
|
+
results: ReadonlyMap<string, OsirisProperties>;
|
|
69
|
+
/** Why each refused row was refused, by row key. */
|
|
70
|
+
failures: ReadonlyMap<string, string>;
|
|
71
|
+
/** How far the pool has got. */
|
|
72
|
+
progress: PredictionProgress;
|
|
73
|
+
/** Why no prediction can be made at all, or `null`. */
|
|
74
|
+
error: string | null;
|
|
75
|
+
/** Drop everything still queued. */
|
|
76
|
+
cancel: () => void;
|
|
77
|
+
/**
|
|
78
|
+
* Why one risk came back as it did.
|
|
79
|
+
* @param idCode - The molecule, coordinates included or not.
|
|
80
|
+
* @param risk - Which of the four risks to explain.
|
|
81
|
+
* @returns The findings, with the matched atoms and bonds of every fragment.
|
|
82
|
+
*/
|
|
83
|
+
riskDetail: (idCode: string, risk: RiskType) => Promise<RiskDetail>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const IDLE: PredictionProgress = {
|
|
87
|
+
done: 0,
|
|
88
|
+
total: 0,
|
|
89
|
+
pending: 0,
|
|
90
|
+
running: false,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
interface Answered {
|
|
94
|
+
results: Map<string, OsirisProperties>;
|
|
95
|
+
failures: Map<string, string>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface PoolView {
|
|
99
|
+
progress: PredictionProgress;
|
|
100
|
+
error: string | null;
|
|
101
|
+
answers: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Predict a set of molecules on a pool of workers, streaming the answers back.
|
|
106
|
+
* @param options - See {@link UsePredictionsOptions}.
|
|
107
|
+
* @returns The answers so far, the progress, and the controls.
|
|
108
|
+
*/
|
|
109
|
+
export function usePredictions(
|
|
110
|
+
options: UsePredictionsOptions,
|
|
111
|
+
): UsePredictionsResult {
|
|
112
|
+
const { molecules, visibleKeys, enabled = true, size } = options;
|
|
113
|
+
const { resources, createWorker } = options;
|
|
114
|
+
// Read when the pool and its workers are made rather than listed as a
|
|
115
|
+
// dependency: a factory written inline is a new function on every render,
|
|
116
|
+
// and the progress the pool reports causes one.
|
|
117
|
+
const source = useRef({ resources, createWorker });
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
source.current = { resources, createWorker };
|
|
120
|
+
}, [resources, createWorker]);
|
|
121
|
+
|
|
122
|
+
const [answered] = useState<Answered>(() => ({
|
|
123
|
+
results: new Map(),
|
|
124
|
+
failures: new Map(),
|
|
125
|
+
}));
|
|
126
|
+
const [view, setView] = useState<PoolView>({
|
|
127
|
+
progress: IDLE,
|
|
128
|
+
error: null,
|
|
129
|
+
answers: 0,
|
|
130
|
+
});
|
|
131
|
+
const pool = useRef<PredictionPool | null>(null);
|
|
132
|
+
|
|
133
|
+
const open = useCallback((): PredictionPool => {
|
|
134
|
+
pool.current ??= createPredictionPool({
|
|
135
|
+
resources: source.current.resources,
|
|
136
|
+
createWorker: () => source.current.createWorker(),
|
|
137
|
+
...(size === undefined ? {} : { size }),
|
|
138
|
+
onResult(outcome) {
|
|
139
|
+
if (outcome.ok) answered.results.set(outcome.key, outcome.properties);
|
|
140
|
+
else answered.failures.set(outcome.key, outcome.message);
|
|
141
|
+
setView((previous) => ({ ...previous, answers: previous.answers + 1 }));
|
|
142
|
+
},
|
|
143
|
+
onProgress(progress) {
|
|
144
|
+
setView((previous) => ({ ...previous, progress }));
|
|
145
|
+
},
|
|
146
|
+
onUnavailable(message) {
|
|
147
|
+
setView((previous) => ({ ...previous, error: message }));
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
return pool.current;
|
|
151
|
+
}, [answered, size]);
|
|
152
|
+
|
|
153
|
+
const unavailable = view.error;
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (!enabled || unavailable !== null) return;
|
|
156
|
+
const waiting: PredictionInput[] = [];
|
|
157
|
+
for (const molecule of molecules) {
|
|
158
|
+
if (answered.results.has(molecule.key)) continue;
|
|
159
|
+
if (answered.failures.has(molecule.key)) continue;
|
|
160
|
+
waiting.push(molecule);
|
|
161
|
+
}
|
|
162
|
+
if (waiting.length > 0) open().submit(waiting);
|
|
163
|
+
}, [answered, molecules, enabled, open, unavailable]);
|
|
164
|
+
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (visibleKeys !== undefined) pool.current?.prioritize(visibleKeys);
|
|
167
|
+
}, [visibleKeys]);
|
|
168
|
+
|
|
169
|
+
useEffect(
|
|
170
|
+
() => () => {
|
|
171
|
+
pool.current?.terminate();
|
|
172
|
+
pool.current = null;
|
|
173
|
+
},
|
|
174
|
+
[],
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const cancel = useCallback(() => {
|
|
178
|
+
pool.current?.cancel();
|
|
179
|
+
}, []);
|
|
180
|
+
|
|
181
|
+
const riskDetail = useCallback(
|
|
182
|
+
(idCode: string, risk: RiskType) => open().riskDetail(idCode, risk),
|
|
183
|
+
[open],
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
results: answered.results,
|
|
188
|
+
failures: answered.failures,
|
|
189
|
+
progress: view.progress,
|
|
190
|
+
error: view.error,
|
|
191
|
+
cancel,
|
|
192
|
+
riskDetail,
|
|
193
|
+
};
|
|
194
|
+
}
|
package/src/osiris-ui.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OSIRIS property panel — the four risk squares, the ten bars and the
|
|
3
|
+
* explanation a square opens — and `usePredictions`, which drives a pool of
|
|
4
|
+
* prediction workers from a page.
|
|
5
|
+
*
|
|
6
|
+
* Kept apart from `react-cheminfo/osiris` so the worker that predicts loads no
|
|
7
|
+
* React and no Blueprint; everything the panel draws from is imported from
|
|
8
|
+
* there. The stylesheet is `react-cheminfo/styles/osiris.css`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export * from './osiris/ui/index.ts';
|
package/src/osiris.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What OSIRIS predicts about a molecule — the four toxicity risks, cLogP,
|
|
3
|
+
* solubility, drug-likeness and the drug score — and the pool of workers that
|
|
4
|
+
* predicts a whole set of them.
|
|
5
|
+
*
|
|
6
|
+
* Framework-free on purpose, and its own door for two reasons. A prediction
|
|
7
|
+
* worker imports `runPredictionJob` and `isPredictRequest` from here, and a dev
|
|
8
|
+
* server hands a worker its dependencies unbundled, so anything React-shaped
|
|
9
|
+
* behind this door would be evaluated in every worker. And a server answering
|
|
10
|
+
* predictions over an API loads it in Node, where nothing is tree-shaken.
|
|
11
|
+
* `openchemlib` is imported on the first prediction, never on import.
|
|
12
|
+
*
|
|
13
|
+
* The panel that draws the answer, and the hook that drives the pool from a
|
|
14
|
+
* page, are `react-cheminfo/osiris-ui`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export * from './osiris/core/index.ts';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { InputGroup } from '@blueprintjs/core';
|
|
2
2
|
|
|
3
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
4
|
+
|
|
3
5
|
import { ClearButton } from './ClearButton.tsx';
|
|
4
6
|
|
|
5
7
|
export interface FilterInputProps {
|
|
@@ -34,6 +36,7 @@ export interface FilterInputProps {
|
|
|
34
36
|
*/
|
|
35
37
|
export function FilterInput(props: FilterInputProps) {
|
|
36
38
|
const { value, onValueChange, placeholder, autoFocus = false } = props;
|
|
39
|
+
const t = useChromeT();
|
|
37
40
|
|
|
38
41
|
return (
|
|
39
42
|
<InputGroup
|
|
@@ -49,7 +52,7 @@ export function FilterInput(props: FilterInputProps) {
|
|
|
49
52
|
rightElement={
|
|
50
53
|
value.length > 0 ? (
|
|
51
54
|
<ClearButton
|
|
52
|
-
label=
|
|
55
|
+
label={t('panel.clearFilter')}
|
|
53
56
|
onClick={() => onValueChange('')}
|
|
54
57
|
/>
|
|
55
58
|
) : undefined
|