nmrium 0.22.0 → 0.23.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 (42) hide show
  1. package/lib/component/1d/FooterBanner.js +1 -1
  2. package/lib/component/NMRium.d.ts +3 -6
  3. package/lib/component/NMRium.js +1 -7
  4. package/lib/component/modal/PredictSpectraModal.d.ts +0 -28
  5. package/lib/component/modal/PredictSpectraModal.js +2 -32
  6. package/lib/component/modal/setting/DisplayTabContent.js +4 -0
  7. package/lib/component/panels/MoleculesPanel/MoleculePanel.d.ts +10 -1
  8. package/lib/component/panels/MoleculesPanel/MoleculePanel.js +27 -17
  9. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.d.ts +9 -1
  10. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +2 -2
  11. package/lib/component/panels/Panels.js +7 -0
  12. package/lib/component/panels/predictionPanel/PredictionOptions.d.ts +6 -0
  13. package/lib/component/panels/predictionPanel/PredictionOptions.js +88 -0
  14. package/lib/component/panels/predictionPanel/PredictionPanel.d.ts +2 -0
  15. package/lib/component/panels/predictionPanel/PredictionPanel.js +33 -0
  16. package/lib/component/reducer/actions/LoadActions.js +7 -0
  17. package/lib/component/reducer/actions/MoleculeActions.js +1 -1
  18. package/lib/component/reducer/preferencesReducer.js +3 -4
  19. package/lib/component/workspaces/basic.js +1 -0
  20. package/lib/component/workspaces/exercise1D.js +1 -0
  21. package/lib/component/workspaces/process1D.js +1 -0
  22. package/lib/data/PredictionManager.d.ts +35 -3
  23. package/lib/data/PredictionManager.js +45 -7
  24. package/lib/versionInfo.js +1 -1
  25. package/lib-cjs/component/1d/FooterBanner.js +1 -1
  26. package/lib-cjs/component/NMRium.js +1 -8
  27. package/lib-cjs/component/modal/PredictSpectraModal.js +3 -33
  28. package/lib-cjs/component/modal/setting/DisplayTabContent.js +4 -0
  29. package/lib-cjs/component/panels/MoleculesPanel/MoleculePanel.js +27 -17
  30. package/lib-cjs/component/panels/MoleculesPanel/MoleculePanelHeader.js +2 -2
  31. package/lib-cjs/component/panels/Panels.js +7 -0
  32. package/lib-cjs/component/panels/predictionPanel/PredictionOptions.js +112 -0
  33. package/lib-cjs/component/panels/predictionPanel/PredictionPanel.js +39 -0
  34. package/lib-cjs/component/reducer/actions/LoadActions.js +7 -0
  35. package/lib-cjs/component/reducer/actions/MoleculeActions.js +1 -1
  36. package/lib-cjs/component/reducer/preferencesReducer.js +3 -4
  37. package/lib-cjs/component/workspaces/basic.js +1 -0
  38. package/lib-cjs/component/workspaces/exercise1D.js +1 -0
  39. package/lib-cjs/component/workspaces/process1D.js +1 -0
  40. package/lib-cjs/data/PredictionManager.js +46 -8
  41. package/lib-cjs/versionInfo.js +1 -1
  42. package/package.json +1 -1
@@ -86,7 +86,7 @@ function FooterBannerInner({ margin, width, height, activeSpectrum, spectrum, ac
86
86
  100).toFixed(2), "%"] }, void 0)] }, void 0))] }, void 0)), activeSpectrum && (_jsxs(Fragment, { children: [_jsx("div", { className: "separator" }, void 0), _jsx(IoPulseSharp, {}, void 0), _jsxs("div", { children: [_jsx("span", { className: "label", children: "Intensity: " }, void 0), _jsx("span", { className: "value yvalue", children: format(getYValue(position.x)) }, void 0)] }, void 0)] }, void 0))] }, void 0));
87
87
  }
88
88
  const MemoizedFooterBanner = memo(FooterBannerInner);
89
- const emptyData = { info: {}, data: {} };
89
+ const emptyData = { info: {}, data: null };
90
90
  export default function FooterBanner() {
91
91
  const { margin, width, height, activeSpectrum, activeTab } = useChartData();
92
92
  const spectrum = useSpectrum(emptyData);
@@ -4,15 +4,11 @@ import { ReactElement, ReactNode } from 'react';
4
4
  import { Datum1D } from '../data/types/data1d';
5
5
  import { Datum2D } from '../data/types/data2d';
6
6
  import { State } from './reducer/Reducer';
7
- export declare enum NMRiumWorkspaces {
8
- EXERCISE_1D = "exercise1D",
9
- PROCESS_1D = "process1D",
10
- DEFAULT = "default"
11
- }
7
+ export declare type NMRIumWorkspace = 'exercise1D' | 'process1D' | 'default';
12
8
  export interface NMRiumProps {
13
9
  data?: NMRiumData;
14
10
  onDataChange?: (data: State) => void;
15
- workspace?: NMRiumWorkspaces;
11
+ workspace?: NMRIumWorkspace;
16
12
  preferences?: NMRiumPreferences;
17
13
  emptyText?: ReactNode;
18
14
  /**
@@ -39,6 +35,7 @@ export declare type NMRiumPreferences = Partial<{
39
35
  hideSummaryPanel: boolean;
40
36
  hideMultipleSpectraAnalysisPanel: boolean;
41
37
  hideDatabasePanel: boolean;
38
+ hidePredictionPanel: boolean;
42
39
  }>;
43
40
  toolBarButtons: Partial<{
44
41
  hideZoomTool: boolean;
@@ -96,12 +96,6 @@ const containerStyles = css `
96
96
  border-right: 0.55px #bbbbbb solid;
97
97
  }
98
98
  `;
99
- export var NMRiumWorkspaces;
100
- (function (NMRiumWorkspaces) {
101
- NMRiumWorkspaces["EXERCISE_1D"] = "exercise1D";
102
- NMRiumWorkspaces["PROCESS_1D"] = "process1D";
103
- NMRiumWorkspaces["DEFAULT"] = "default";
104
- })(NMRiumWorkspaces || (NMRiumWorkspaces = {}));
105
99
  const defaultPreferences = {};
106
100
  const defaultData = {
107
101
  spectra: [],
@@ -109,7 +103,7 @@ const defaultData = {
109
103
  function NMRium(props) {
110
104
  return (_jsx(RootLayout, { style: { width: '100%' }, children: _jsx(ErrorBoundary, { FallbackComponent: ErrorOverlay, children: _jsx(InnerNMRium, { ...props }, void 0) }, void 0) }, void 0));
111
105
  }
112
- function InnerNMRium({ data: dataProp = defaultData, workspace = NMRiumWorkspaces.DEFAULT, preferences = defaultPreferences, getSpinner = defaultGetSpinner, onDataChange, emptyText, }) {
106
+ function InnerNMRium({ data: dataProp = defaultData, workspace = 'default', preferences = defaultPreferences, getSpinner = defaultGetSpinner, onDataChange, emptyText, }) {
113
107
  const rootRef = useRef(null);
114
108
  const elementsWraperRef = useRef(null);
115
109
  const [show, toggle] = useToggle(false);
@@ -1,31 +1,3 @@
1
- export interface PredictionProps {
2
- frequency: number;
3
- '1d': {
4
- '1H': {
5
- from: number;
6
- to: number;
7
- };
8
- '13C': {
9
- from: number;
10
- to: number;
11
- };
12
- nbPoints: number;
13
- lineWidth: number;
14
- };
15
- '2d': {
16
- nbPoints: {
17
- x: number;
18
- y: number;
19
- };
20
- };
21
- spectra: {
22
- proton: boolean;
23
- carbon: boolean;
24
- cosy: boolean;
25
- hsqc: boolean;
26
- hmbc: boolean;
27
- };
28
- }
29
1
  interface PredictSpectraModalProps {
30
2
  onClose?: (element?: string) => void;
31
3
  molfile: any;
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
3
3
  import { css } from '@emotion/react';
4
4
  import { useCallback, useRef, useState, useMemo } from 'react';
5
5
  import * as Yup from 'yup';
6
+ import { defaultPredictionOptions, FREQUENCIES, } from '../../data/PredictionManager';
6
7
  import generateNumbersPowerOfX from '../../data/utilities/generateNumbersPowerOfX';
7
8
  import { useDispatch } from '../context/DispatchContext';
8
9
  import CheckBox from '../elements/CheckBox';
@@ -77,41 +78,10 @@ const styles = css `
77
78
  color: #005d9e;
78
79
  }
79
80
  `;
80
- const FREQUENCIES = [
81
- { key: 1, value: 60, label: '60 MHz' },
82
- { key: 2, value: 100, label: '100 MHz' },
83
- { key: 3, value: 200, label: '200 MHz' },
84
- { key: 4, value: 300, label: '300 MHz' },
85
- { key: 5, value: 400, label: '400 MHz' },
86
- { key: 6, value: 500, label: '500 MHz' },
87
- { key: 7, value: 600, label: '600 MHz' },
88
- { key: 8, value: 800, label: '800 MHz' },
89
- { key: 9, value: 1000, label: '1000 MHz' },
90
- { key: 10, value: 1200, label: '1200 MHz' },
91
- ];
92
81
  const NUMBER_OF_POINTS_1D = generateNumbersPowerOfX(12, 19);
93
82
  const NUMBER_OF_POINTS_2D = generateNumbersPowerOfX(10, 10, {
94
83
  format: (value) => value,
95
84
  });
96
- const INITIAL_VALUE = {
97
- frequency: 400,
98
- '1d': {
99
- '1H': { from: -1, to: 12 },
100
- '13C': { from: -5, to: 220 },
101
- nbPoints: 2 ** 17,
102
- lineWidth: 1,
103
- },
104
- '2d': {
105
- nbPoints: { x: 1024, y: 1024 },
106
- },
107
- spectra: {
108
- proton: true,
109
- carbon: false,
110
- cosy: false,
111
- hsqc: false,
112
- hmbc: false,
113
- },
114
- };
115
85
  const predictionFormValidation = Yup.object().shape({
116
86
  frequency: Yup.number().integer().required().label('Frequency'),
117
87
  '1d': Yup.object({
@@ -157,7 +127,7 @@ function PredictSpectraModal({ onClose = () => null, molfile, }) {
157
127
  const initValues = useMemo(() => {
158
128
  const { isApproved: isAgree, ...options } = predictionPreferences;
159
129
  setApproved(isAgree);
160
- return Object.assign(INITIAL_VALUE, options);
130
+ return Object.assign(defaultPredictionOptions, options);
161
131
  }, [predictionPreferences]);
162
132
  const submitHandler = useCallback(async (values) => {
163
133
  setPredictionPreferences({ ...values, isApproved });
@@ -46,6 +46,10 @@ const LIST = [
46
46
  label: 'Database Panel',
47
47
  name: 'display.panels.hideDatabasePanel',
48
48
  },
49
+ {
50
+ label: 'Prediction Panel',
51
+ name: 'display.panels.hidePredictionPanel',
52
+ },
49
53
  {
50
54
  label: 'Experimental Features',
51
55
  name: 'display.general.hideExperimentalFeatures',
@@ -1 +1,10 @@
1
- export default function MoleculePanel(): import("@emotion/react/jsx-runtime").JSX.Element;
1
+ import { ReactElement } from 'react';
2
+ import { Molecule } from '../../../data/molecules/Molecule';
3
+ import { MoleculeHeaderActionsOptions } from './MoleculePanelHeader';
4
+ interface MoleculePanelProps {
5
+ onMoleculeChange?: (molecule: Molecule) => void;
6
+ children?: ReactElement;
7
+ actionsOptions?: MoleculeHeaderActionsOptions;
8
+ }
9
+ export default function MoleculePanel({ onMoleculeChange, children, actionsOptions, }: MoleculePanelProps): import("@emotion/react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -18,16 +18,21 @@ import useAtomAssignment from './useAtomAssignment';
18
18
  const styles = {
19
19
  panel: css({
20
20
  display: 'flex',
21
+ overflow: 'auto',
21
22
  flexGrow: 1,
22
23
  width: '100%',
23
24
  height: '100%',
24
25
  flexDirection: 'column',
25
26
  }),
26
- molecule: css({
27
+ innerPanel: css({
27
28
  display: 'flex',
28
- flex: '1 1 0%',
29
+ flex: '1',
29
30
  flexDirection: 'column',
30
- minHeight: 0,
31
+ overflow: 'auto',
32
+ }),
33
+ molecule: css({
34
+ display: 'flex',
35
+ flex: '1',
31
36
  }),
32
37
  toolbar: css({
33
38
  display: 'flex',
@@ -52,7 +57,7 @@ const styles = {
52
57
  minHeight: 0,
53
58
  }),
54
59
  };
55
- function MoleculePanelInner({ zones, ranges, molecules: moleculesProp, activeTab, displayerMode, }) {
60
+ function MoleculePanelInner({ zones, ranges, molecules: moleculesProp, activeTab, displayerMode, onMoleculeChange, actionsOptions, children, }) {
56
61
  const [currentIndex, setCurrentIndex] = useState(0);
57
62
  const [molecules, setMolecules] = useState([]);
58
63
  const dispatch = useDispatch();
@@ -68,6 +73,9 @@ function MoleculePanelInner({ zones, ranges, molecules: moleculesProp, activeTab
68
73
  });
69
74
  }
70
75
  }, [molecules.length, moleculesProp]);
76
+ useEffect(() => {
77
+ onMoleculeChange?.(molecules[currentIndex] || null);
78
+ }, [currentIndex, molecules, onMoleculeChange]);
71
79
  const handleReplaceMolecule = useCallback((key, molfile) => {
72
80
  dispatch({ type: SET_MOLECULE, molfile, key });
73
81
  }, [dispatch]);
@@ -81,21 +89,21 @@ function MoleculePanelInner({ zones, ranges, molecules: moleculesProp, activeTab
81
89
  const moleculeIndexHandler = useCallback((index) => {
82
90
  setCurrentIndex(index);
83
91
  }, []);
84
- return (_jsxs("div", { css: styles.panel, children: [_jsx(MoleculePanelHeader, { currentIndex: currentIndex, molecules: molecules, onOpenMoleculeEditor: () => openMoleculeEditorHandler(), onMoleculeIndexChange: moleculeIndexHandler }, void 0), _jsx("div", { css: styles.molecule, children: _jsx(NextPrev, { onChange: (slideIndex) => setCurrentIndex(slideIndex), defaultIndex: currentIndex, children: molecules && molecules.length > 0 ? (molecules.map((mol, index) => (_jsxs("div", { css: styles.items, children: [_jsxs("span", { css: styles.toolbar, children: [_jsx(MF, { mf: mol.mf }, void 0), " - ", mol.mw?.toFixed(2)] }, void 0), _jsx("div", { css: styles.slider, className: "mol-svg-container", onDoubleClick: () => openMoleculeEditorHandler(mol), style: {
85
- backgroundColor: (index + 1) % 2 !== 0 ? '#fafafa' : 'white',
86
- }, children: _jsx(ResponsiveChart, { children: ({ height, width }) => {
87
- return (_jsx(OCLnmr, { OCL: OCL, id: `molSVG${index}`, width: width, height: height, molfile: mol.molfile || '', setMolfile: (molfile) => handleReplaceMolecule(mol.key, molfile), setSelectedAtom: handleOnClickAtom, atomHighlightColor: currentDiaIDsToHighlight &&
88
- currentDiaIDsToHighlight.length > 0
89
- ? 'red'
90
- : '#FFD700', atomHighlightOpacity: 0.35, highlights: currentDiaIDsToHighlight &&
91
- currentDiaIDsToHighlight.length > 0
92
- ? currentDiaIDsToHighlight
93
- : assignedDiaIDsMerged, setHoverAtom: handleOnAtomHover }, void 0));
94
- } }, void 0) }, void 0)] }, mol.key)))) : (_jsx("div", { css: styles.slider, style: { height: '100%' }, onClick: () => openMoleculeEditorHandler(), children: _jsx("span", { children: "Click to draw molecule" }, void 0) }, void 0)) }, void 0) }, void 0)] }, void 0));
92
+ return (_jsxs("div", { css: styles.panel, children: [_jsx(MoleculePanelHeader, { currentIndex: currentIndex, molecules: molecules, onOpenMoleculeEditor: () => openMoleculeEditorHandler(), onMoleculeIndexChange: moleculeIndexHandler, actionsOptions: actionsOptions }, void 0), _jsxs("div", { css: styles.innerPanel, children: [_jsx("div", { css: styles.molecule, children: _jsx(NextPrev, { onChange: (slideIndex) => setCurrentIndex(slideIndex), defaultIndex: currentIndex, children: molecules && molecules.length > 0 ? (molecules.map((mol, index) => (_jsxs("div", { css: styles.items, children: [_jsxs("span", { css: styles.toolbar, children: [_jsx(MF, { mf: mol.mf }, void 0), " - ", mol.mw?.toFixed(2)] }, void 0), _jsx("div", { css: styles.slider, className: "mol-svg-container", onDoubleClick: () => openMoleculeEditorHandler(mol), style: {
93
+ backgroundColor: (index + 1) % 2 !== 0 ? '#fafafa' : 'white',
94
+ }, children: _jsx(ResponsiveChart, { children: ({ height, width }) => {
95
+ return (_jsx(OCLnmr, { OCL: OCL, id: `molSVG${index}`, width: width, height: height, molfile: mol.molfile || '', setMolfile: (molfile) => handleReplaceMolecule(mol.key, molfile), setSelectedAtom: handleOnClickAtom, atomHighlightColor: currentDiaIDsToHighlight &&
96
+ currentDiaIDsToHighlight.length > 0
97
+ ? 'red'
98
+ : '#FFD700', atomHighlightOpacity: 0.35, highlights: currentDiaIDsToHighlight &&
99
+ currentDiaIDsToHighlight.length > 0
100
+ ? currentDiaIDsToHighlight
101
+ : assignedDiaIDsMerged, setHoverAtom: handleOnAtomHover }, void 0));
102
+ } }, void 0) }, void 0)] }, mol.key)))) : (_jsx("div", { css: styles.slider, style: { height: '100%' }, onClick: () => openMoleculeEditorHandler(), children: _jsx("span", { children: "Click to draw molecule" }, void 0) }, void 0)) }, void 0) }, void 0), children] }, void 0)] }, void 0));
95
103
  }
96
104
  const MemoizedMoleculePanel = memo(MoleculePanelInner);
97
105
  const emptyData = { ranges: {}, zones: {} };
98
- export default function MoleculePanel() {
106
+ export default function MoleculePanel({ onMoleculeChange, children, actionsOptions, }) {
99
107
  const { molecules, displayerMode, activeTab } = useChartData();
100
108
  const data = useSpectrum(emptyData);
101
109
  const ranges = data?.ranges || {};
@@ -106,5 +114,7 @@ export default function MoleculePanel() {
106
114
  activeTab,
107
115
  ranges,
108
116
  zones,
109
- } }, void 0));
117
+ onMoleculeChange,
118
+ actionsOptions,
119
+ }, children: children }, void 0));
110
120
  }
@@ -1,8 +1,16 @@
1
+ export interface MoleculeHeaderActionsOptions {
2
+ hidePast?: boolean;
3
+ hideAdd?: boolean;
4
+ hideExport?: boolean;
5
+ hideDelete?: boolean;
6
+ hidePredict?: boolean;
7
+ }
1
8
  interface MoleculePanelHeaderProps {
2
9
  currentIndex: number;
3
10
  molecules: Array<any>;
4
11
  onMoleculeIndexChange: (index: number) => void;
5
12
  onOpenMoleculeEditor: () => void;
13
+ actionsOptions?: MoleculeHeaderActionsOptions;
6
14
  }
7
- export default function MoleculePanelHeader({ currentIndex, molecules, onMoleculeIndexChange, onOpenMoleculeEditor, }: MoleculePanelHeaderProps): import("@emotion/react/jsx-runtime").JSX.Element;
15
+ export default function MoleculePanelHeader({ currentIndex, molecules, onMoleculeIndexChange, onOpenMoleculeEditor, actionsOptions, }: MoleculePanelHeaderProps): import("@emotion/react/jsx-runtime").JSX.Element;
8
16
  export {};
@@ -55,7 +55,7 @@ const MOL_EXPORT_MENU = [
55
55
  label: 'Export as SVG',
56
56
  },
57
57
  ];
58
- export default function MoleculePanelHeader({ currentIndex, molecules, onMoleculeIndexChange = () => null, onOpenMoleculeEditor = () => null, }) {
58
+ export default function MoleculePanelHeader({ currentIndex, molecules, onMoleculeIndexChange = () => null, onOpenMoleculeEditor = () => null, actionsOptions = {}, }) {
59
59
  const alert = useAlert();
60
60
  const dispatch = useDispatch();
61
61
  const modal = useModal();
@@ -121,7 +121,7 @@ export default function MoleculePanelHeader({ currentIndex, molecules, onMolecul
121
121
  width: 600,
122
122
  });
123
123
  }, [modal, molecules, currentIndex]);
124
- return (_jsxs("div", { css: toolbarStyle, children: [_jsx(MenuButton, { component: _jsx(FaFileExport, {}, void 0), toolTip: "Export As", items: MOL_EXPORT_MENU, onClick: exportHandler }, void 0), _jsx(ToolTip, { title: "Paste molfile", popupPlacement: "left", children: _jsx("button", { className: "bar-button", type: "button", onClick: handlePaste, children: _jsx(FaPaste, {}, void 0) }, void 0) }, void 0), _jsx(ToolTip, { title: "Add Molecule", popupPlacement: "left", children: _jsx("button", { className: "bar-button", type: "button", onClick: onOpenMoleculeEditor, "data-test-id": "panel-structures-button-add", children: _jsx(FaPlus, {}, void 0) }, void 0) }, void 0), _jsx(ToolTip, { title: "Delete Molecule", popupPlacement: "left", children: _jsx("button", { className: "bar-button", type: "button", onClick: handleDelete, children: _jsx(FaRegTrashAlt, {}, void 0) }, void 0) }, void 0), molecules && molecules.length > 0 && (_jsx(ButtonToolTip, { popupTitle: "Predict Spectra", popupPlacement: "left", onClick: openPredictSpectraModal, children: _jsx(SvgNmrFt, {}, void 0) }, void 0)), _jsxs("p", { children: [molecules &&
124
+ return (_jsxs("div", { css: toolbarStyle, children: [!actionsOptions.hideExport && (_jsx(MenuButton, { component: _jsx(FaFileExport, {}, void 0), toolTip: "Export As", items: MOL_EXPORT_MENU, onClick: exportHandler }, void 0)), !actionsOptions.hidePast && (_jsx(ToolTip, { title: "Paste molfile", popupPlacement: "left", children: _jsx("button", { className: "bar-button", type: "button", onClick: handlePaste, children: _jsx(FaPaste, {}, void 0) }, void 0) }, void 0)), !actionsOptions.hideAdd && (_jsx(ToolTip, { title: "Add Molecule", popupPlacement: "left", children: _jsx("button", { className: "bar-button", type: "button", onClick: onOpenMoleculeEditor, "data-test-id": "panel-structures-button-add", children: _jsx(FaPlus, {}, void 0) }, void 0) }, void 0)), !actionsOptions.hideDelete && (_jsx(ToolTip, { title: "Delete Molecule", popupPlacement: "left", children: _jsx("button", { className: "bar-button", type: "button", onClick: handleDelete, children: _jsx(FaRegTrashAlt, {}, void 0) }, void 0) }, void 0)), !actionsOptions.hidePredict && molecules && molecules.length > 0 && (_jsx(ButtonToolTip, { popupTitle: "Predict Spectra", popupPlacement: "left", onClick: openPredictSpectraModal, children: _jsx(SvgNmrFt, {}, void 0) }, void 0)), _jsxs("p", { children: [molecules &&
125
125
  molecules.length > 0 &&
126
126
  `${+(currentIndex + 1)} / ${molecules.length}`, ' '] }, void 0)] }, void 0));
127
127
  }
@@ -19,6 +19,7 @@ import SummaryPanel from './SummaryPanel/SummaryPanel';
19
19
  import ZonesPanel from './ZonesPanel/ZonesPanel';
20
20
  import DatabasePanel from './databasePanel/DatabasePanel';
21
21
  import FilterPanel from './filtersPanel/FilterPanel';
22
+ import PredictionPane from './predictionPanel/PredictionPanel';
22
23
  const accordionItems = [
23
24
  {
24
25
  title: 'Spectra',
@@ -101,6 +102,12 @@ const accordionItems = [
101
102
  mode: null,
102
103
  isExperimental: true,
103
104
  },
105
+ {
106
+ title: 'Prediction',
107
+ component: _jsx(PredictionPane, {}, void 0),
108
+ hidePreferenceKey: 'hidePredictionPanel',
109
+ mode: null,
110
+ },
104
111
  ];
105
112
  export const TOOLS_PANELS_ACCORDION = {
106
113
  null: 'Spectra',
@@ -0,0 +1,6 @@
1
+ import { PredictionOptions as PredictionOptionsInterface } from '../../../data/PredictionManager';
2
+ interface PredictionOptionsProps {
3
+ onPredict?: (options?: PredictionOptionsInterface) => void;
4
+ }
5
+ declare function PredictionOptions({ onPredict }: PredictionOptionsProps): import("@emotion/react/jsx-runtime").JSX.Element;
6
+ export default PredictionOptions;
@@ -0,0 +1,88 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
+ /** @jsxImportSource @emotion/react */
3
+ import { css } from '@emotion/react';
4
+ import { useCallback, useRef } from 'react';
5
+ import * as Yup from 'yup';
6
+ import { defaultPredictionOptions, FREQUENCIES, } from '../../../data/PredictionManager';
7
+ import IsotopesViewer from '../../elements/IsotopesViewer';
8
+ import Label from '../../elements/Label';
9
+ import FormikErrorsSummary from '../../elements/formik/FormikErrorsSummary';
10
+ import FormikForm from '../../elements/formik/FormikForm';
11
+ import FormikInput from '../../elements/formik/FormikInput';
12
+ import FormikSelect from '../../elements/formik/FormikSelect';
13
+ const styles = css `
14
+ padding: 10px;
15
+ border-top: solid #f2f2f2 1px;
16
+
17
+ .row {
18
+ flex: row;
19
+ display: flex;
20
+ padding-bottom: 10px;
21
+ }
22
+
23
+ .inner-content {
24
+ flex: 1;
25
+ }
26
+
27
+ .custom-label {
28
+ width: 160px;
29
+ }
30
+
31
+ .footer-container {
32
+ display: flex;
33
+ flex-direction: row-reverse;
34
+ align-items: flex-end;
35
+ }
36
+
37
+ .btn:not([disabled]):hover {
38
+ background-color: #ffffff;
39
+ }
40
+ .btn:hover {
41
+ background-color: #f2f2f2 !important;
42
+ }
43
+ .btn:disabled {
44
+ opacity: 0.5;
45
+ }
46
+ .btn {
47
+ border: none;
48
+ padding: 0 15px;
49
+ background-color: #ffffff;
50
+ border-radius: 5px;
51
+ height: 25px;
52
+ }
53
+
54
+ .input {
55
+ font-size: 14px;
56
+ border-radius: 5px;
57
+ border: 1px solid #cccccc;
58
+ padding: 5px;
59
+ width: 100px;
60
+ margin-right: 10px;
61
+ height: initial !important;
62
+ }
63
+ `;
64
+ const predictionFormValidation = Yup.object().shape({
65
+ frequency: Yup.number().integer().required().label('Frequency'),
66
+ '1d': Yup.object({
67
+ '1H': Yup.object({
68
+ from: Yup.number().integer().required().label("1H ' From ' "),
69
+ to: Yup.number().integer().required().label("1H ' To ' "),
70
+ }),
71
+ '13C': Yup.object().shape({
72
+ from: Yup.number().integer().required().label("13C ' From ' "),
73
+ to: Yup.number().integer().required().label("13C ' To ' "),
74
+ }),
75
+ lineWidth: Yup.number().integer().min(1).required().label('Line Width'),
76
+ }),
77
+ });
78
+ function PredictionOptions({ onPredict = () => null }) {
79
+ const refForm = useRef();
80
+ const handleSave = useCallback(() => {
81
+ refForm.current.submitForm();
82
+ }, []);
83
+ const submitHandler = useCallback(async (values) => {
84
+ onPredict(values);
85
+ }, [onPredict]);
86
+ return (_jsxs("div", { css: styles, children: [_jsx("div", { children: _jsxs(FormikForm, { ref: refForm, initialValues: defaultPredictionOptions, validationSchema: predictionFormValidation, onSubmit: submitHandler, children: [_jsx(FormikErrorsSummary, {}, void 0), _jsxs("div", { className: "row margin-10", children: [_jsx("span", { className: "custom-label", children: "Frequency : " }, void 0), _jsx(FormikSelect, { data: FREQUENCIES, style: { width: 290, height: 30, margin: 0 }, name: "frequency" }, void 0)] }, void 0), _jsxs("div", { className: "row", children: [_jsx(IsotopesViewer, { value: "1H", className: "custom-label" }, void 0), _jsx(Label, { title: "From", children: _jsx(FormikInput, { name: "1d.1H.from", type: "number" }, void 0) }, void 0), _jsx(Label, { title: "To", style: { label: { padding: '0 10px' } }, children: _jsx(FormikInput, { name: "1d.1H.to", type: "number" }, void 0) }, void 0)] }, void 0), _jsxs("div", { className: "row", children: [_jsx(IsotopesViewer, { value: "13C", className: "custom-label" }, void 0), _jsx(Label, { title: "From", children: _jsx(FormikInput, { name: "1d.13C.from", type: "number" }, void 0) }, void 0), _jsx(Label, { title: "To", style: { label: { padding: '0 10px' } }, children: _jsx(FormikInput, { name: "1d.13C.to", type: "number" }, void 0) }, void 0)] }, void 0), _jsxs("div", { className: "row margin-10 padding-h-10", children: [_jsx("span", { className: "custom-label", children: "Line Width : " }, void 0), _jsx(FormikInput, { name: "1d.lineWidth", type: "number", style: { input: { margin: 0 } } }, void 0), _jsx("span", { style: { paddingLeft: '0.4rem' }, children: " Hz " }, void 0)] }, void 0)] }, void 0) }, void 0), _jsx("div", { children: _jsx("button", { type: "button", onClick: handleSave, className: "btn", children: "Predict spectrum" }, void 0) }, void 0)] }, void 0));
87
+ }
88
+ export default PredictionOptions;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function PredictionPane(): JSX.Element;
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState, useCallback } from 'react';
3
+ import { useDispatch } from '../../context/DispatchContext';
4
+ import { useAlert } from '../../elements/popup/Alert';
5
+ import { PREDICT_SPECTRA, SET_LOADING_FLAG } from '../../reducer/types/Types';
6
+ import MoleculePanel from '../MoleculesPanel/MoleculePanel';
7
+ import PredictionPreferences from './PredictionOptions';
8
+ export default function PredictionPane() {
9
+ const [molecule, setMolecule] = useState();
10
+ const changeHandler = useCallback((molecule) => {
11
+ setMolecule(molecule);
12
+ }, []);
13
+ const dispatch = useDispatch();
14
+ const alert = useAlert();
15
+ const predictHandler = useCallback(async (values) => {
16
+ if (molecule) {
17
+ dispatch({
18
+ type: SET_LOADING_FLAG,
19
+ isLoading: true,
20
+ });
21
+ const hideLoading = await alert.showLoading(`Predict 1H, 13C, COSY, HSQC, and HMBC in progress`);
22
+ dispatch({
23
+ type: PREDICT_SPECTRA,
24
+ payload: { mol: molecule, options: values },
25
+ });
26
+ hideLoading();
27
+ }
28
+ else {
29
+ alert.error('No Molecule selected');
30
+ }
31
+ }, [alert, dispatch, molecule]);
32
+ return (_jsx(MoleculePanel, { onMoleculeChange: changeHandler, actionsOptions: { hidePredict: true, hideDelete: true, hideExport: true }, children: _jsx(PredictionPreferences, { onPredict: predictHandler }, void 0) }, void 0));
33
+ }
@@ -4,6 +4,11 @@ import * as MoleculeManager from '../../../data/molecules/MoleculeManager';
4
4
  import { DefaultTolerance } from '../../panels/SummaryPanel/CorrelationTable/Constants';
5
5
  import { changeSpectrumVerticalAlignment } from './PreferencesActions';
6
6
  import { setActiveTab } from './ToolsActions';
7
+ function resetState(draft) {
8
+ draft.activeSpectrum = null;
9
+ draft.activeTab = '';
10
+ draft.tabActiveSpectrum = {};
11
+ }
7
12
  function setIsLoading(draft, isLoading) {
8
13
  draft.isLoading = isLoading;
9
14
  }
@@ -93,6 +98,7 @@ function loadJcampFile(draft, actions) {
93
98
  draft.isLoading = false;
94
99
  }
95
100
  function handleLoadJsonFile(draft, action) {
101
+ resetState(draft);
96
102
  setData(draft, action.payload);
97
103
  const preferences = action.payload?.preferences || {};
98
104
  setActiveTab(draft, { tab: preferences?.activeTab || '' });
@@ -115,6 +121,7 @@ function handleLoadZIPFile(draft, action) {
115
121
  draft.isLoading = false;
116
122
  }
117
123
  function handleLoadNmredata(draft, action) {
124
+ resetState(draft);
118
125
  setData(draft, action.payload);
119
126
  setActiveTab(draft);
120
127
  changeSpectrumVerticalAlignment(draft, { align: 'auto-check' });
@@ -52,7 +52,7 @@ function predictSpectraFromMoleculeHandler(draft, action) {
52
52
  draft.isLoading = false;
53
53
  }
54
54
  else {
55
- for (const spectrum of generateSpectra(data, options, draft.usedColors)) {
55
+ for (const spectrum of generateSpectra(data, options)) {
56
56
  draft.data.push(spectrum);
57
57
  draft.tabActiveSpectrum[nucleusToString(spectrum.info.nucleus)] = {
58
58
  id: spectrum.id,
@@ -1,6 +1,5 @@
1
1
  import { produce } from 'immer';
2
2
  import lodashMerge from 'lodash/merge';
3
- import { NMRiumWorkspaces } from '../NMRium';
4
3
  import { getLocalStorage, removeData, storeData, } from '../utility/LocalStorage';
5
4
  import workspaces from '../workspaces';
6
5
  export const INIT_PREFERENCES = 'INIT_PREFERENCES';
@@ -10,9 +9,9 @@ export const SET_PANELS_PREFERENCES = 'SET_PANELS_PREFERENCES';
10
9
  const LOCAL_STORAGE_VERSION = 3;
11
10
  function getPreferencesByWorkspace(workspace) {
12
11
  switch (workspace) {
13
- case NMRiumWorkspaces.EXERCISE_1D:
12
+ case 'exercise1D':
14
13
  return workspaces.exercise1D;
15
- case NMRiumWorkspaces.PROCESS_1D:
14
+ case 'process1D':
16
15
  return workspaces.process1D;
17
16
  default:
18
17
  return workspaces.basic;
@@ -101,7 +100,7 @@ function handleInit(draft, action) {
101
100
  });
102
101
  mapNucleus(draft);
103
102
  }
104
- draft.display = lodashMerge({}, getPreferencesByWorkspace(NMRiumWorkspaces.DEFAULT).display, hiddenModeFeatures, hiddenLocalStorageFeatures);
103
+ draft.display = lodashMerge({}, getPreferencesByWorkspace('default').display, hiddenModeFeatures, hiddenLocalStorageFeatures);
105
104
  }
106
105
  }
107
106
  function handleSetPreferences(draft, action) {
@@ -20,6 +20,7 @@ export const basic = {
20
20
  hideSummaryPanel: false,
21
21
  hideMultipleSpectraAnalysisPanel: false,
22
22
  hideDatabasePanel: false,
23
+ hidePredictionPanel: false,
23
24
  },
24
25
  toolBarButtons: {
25
26
  hideZoomTool: false,
@@ -20,6 +20,7 @@ export const exercise1D = {
20
20
  hideSummaryPanel: true,
21
21
  hideMultipleSpectraAnalysisPanel: true,
22
22
  hideDatabasePanel: true,
23
+ hidePredictionPanel: false,
23
24
  },
24
25
  toolBarButtons: {
25
26
  hideZoomTool: false,
@@ -20,6 +20,7 @@ export const process1D = {
20
20
  hideSummaryPanel: true,
21
21
  hideMultipleSpectraAnalysisPanel: true,
22
22
  hideDatabasePanel: false,
23
+ hidePredictionPanel: false,
23
24
  },
24
25
  toolBarButtons: {
25
26
  hideZoomTool: false,
@@ -1,6 +1,38 @@
1
- import { PredictionProps } from '../component/modal/PredictSpectraModal';
2
- import { UsedColors } from '../types/UsedColors';
3
1
  import { Datum1D } from './types/data1d';
4
2
  import { Datum2D } from './types/data2d';
3
+ export interface PredictionOptions {
4
+ frequency: number;
5
+ '1d': {
6
+ '1H': {
7
+ from: number;
8
+ to: number;
9
+ };
10
+ '13C': {
11
+ from: number;
12
+ to: number;
13
+ };
14
+ nbPoints: number;
15
+ lineWidth: number;
16
+ };
17
+ '2d': {
18
+ nbPoints: {
19
+ x: number;
20
+ y: number;
21
+ };
22
+ };
23
+ spectra: {
24
+ proton: boolean;
25
+ carbon: boolean;
26
+ cosy: boolean;
27
+ hsqc: boolean;
28
+ hmbc: boolean;
29
+ };
30
+ }
31
+ export declare const defaultPredictionOptions: PredictionOptions;
32
+ export declare const FREQUENCIES: Array<{
33
+ key: number;
34
+ value: number;
35
+ label: string;
36
+ }>;
5
37
  export declare function predictSpectra(molfile: string): Promise<any>;
6
- export declare function generateSpectra(data: Record<string, any>, inputOptions: PredictionProps, usedColors: UsedColors): Array<Datum1D | Datum2D>;
38
+ export declare function generateSpectra(data: Record<string, any>, inputOptions: PredictionOptions): Array<Datum1D | Datum2D>;