nmrium 0.58.0 → 0.59.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 (112) hide show
  1. package/lib/component/1d/integral/IntegralResizable.js +2 -2
  2. package/lib/component/1d/matrix/useMatrix.d.ts +1 -1
  3. package/lib/component/1d/multiAnalysis/AnalysisRange.js +1 -1
  4. package/lib/component/1d/ranges/Atoms.js +6 -4
  5. package/lib/component/2d/Viewer2D.js +6 -2
  6. package/lib/component/2d/zones/Zone.js +2 -2
  7. package/lib/component/EventsTrackers/KeysListenerTracker.js +8 -8
  8. package/lib/component/context/ChartContext.js +12 -1
  9. package/lib/component/context/ShareDataContext.d.ts +1 -1
  10. package/lib/component/context/ShareDataContext.js +2 -4
  11. package/lib/component/context/ToasterContext.d.ts +1 -0
  12. package/lib/component/context/ToasterContext.js +12 -3
  13. package/lib/component/elements/ActionsButtonsPopover.js +1 -3
  14. package/lib/component/elements/Alert.d.ts +20 -0
  15. package/lib/component/elements/Alert.js +80 -0
  16. package/lib/component/elements/ContextMenuBluePrint.d.ts +7 -2
  17. package/lib/component/elements/ContextMenuBluePrint.js +9 -3
  18. package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +1 -1
  19. package/lib/component/elements/ReactTable/ReactTableFlexLayout.d.ts +0 -3
  20. package/lib/component/elements/ReactTable/ReactTableFlexLayout.js +1 -1
  21. package/lib/component/elements/Select2.d.ts +12 -7
  22. package/lib/component/elements/Select2.js +5 -4
  23. package/lib/component/elements/Select2Controller.d.ts +2 -2
  24. package/lib/component/elements/Select2Controller.js +5 -5
  25. package/lib/component/elements/ToolbarPopoverItem.d.ts +7 -6
  26. package/lib/component/elements/ToolbarPopoverItem.js +13 -5
  27. package/lib/component/elements/print/PrintContent.d.ts +17 -0
  28. package/lib/component/elements/print/PrintContent.js +281 -0
  29. package/lib/component/elements/print/PrintProvider.d.ts +12 -0
  30. package/lib/component/elements/print/PrintProvider.js +28 -0
  31. package/lib/component/elements/print/index.d.ts +2 -0
  32. package/lib/component/elements/print/index.js +2 -0
  33. package/lib/component/header/BaseLineCorrectionPanel.js +3 -0
  34. package/lib/component/hooks/useToggleSpectraVisibility.d.ts +14 -9
  35. package/lib/component/hooks/useToggleSpectraVisibility.js +45 -16
  36. package/lib/component/loader/DropZone.js +3 -67
  37. package/lib/component/loader/useLoadFiles.d.ts +1 -0
  38. package/lib/component/loader/useLoadFiles.js +78 -0
  39. package/lib/component/main/InnerNMRium.d.ts +4 -3
  40. package/lib/component/main/InnerNMRium.js +4 -9
  41. package/lib/component/main/InnerNMRiumContents.d.ts +3 -2
  42. package/lib/component/main/InnerNMRiumContents.js +33 -29
  43. package/lib/component/main/NMRium.d.ts +2 -5
  44. package/lib/component/main/NMRium.js +1 -1
  45. package/lib/component/main/NMRiumRefAPI.d.ts +7 -0
  46. package/lib/component/main/NMRiumRefAPI.js +12 -0
  47. package/lib/component/main/NMRiumViewer.d.ts +10 -0
  48. package/lib/component/main/NMRiumViewer.js +35 -0
  49. package/lib/component/main/index.d.ts +1 -0
  50. package/lib/component/modal/CopyClipboardModal.d.ts +3 -2
  51. package/lib/component/modal/CopyClipboardModal.js +18 -32
  52. package/lib/component/modal/ExportAsJcampModal.d.ts +6 -3
  53. package/lib/component/modal/ExportAsJcampModal.js +69 -35
  54. package/lib/component/modal/ImportPublicationStringModal.js +1 -1
  55. package/lib/component/modal/setting/GeneralSettings.js +4 -2
  56. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.d.ts +1 -0
  57. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.js +89 -0
  58. package/lib/component/modal/setting/settingsValidation.js +15 -1
  59. package/lib/component/panels/IntegralsPanel/IntegralPanel.js +8 -5
  60. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +5 -1
  61. package/lib/component/panels/Panels.js +2 -2
  62. package/lib/component/panels/PeaksPanel/PeaksPanel.js +8 -5
  63. package/lib/component/panels/RangesPanel/RangesHeader.js +52 -12
  64. package/lib/component/panels/SpectraPanel/SpectraPanelHeader.js +13 -6
  65. package/lib/component/panels/SpectraPanel/SpectraTable.js +63 -21
  66. package/lib/component/panels/SummaryPanel/CorrelationTable/AdditionalColumnHeader.js +6 -2
  67. package/lib/component/panels/SummaryPanel/CorrelationTable/CorrelationTableRow.js +6 -2
  68. package/lib/component/panels/SummaryPanel/SummaryPanel.js +4 -0
  69. package/lib/component/panels/ZonesPanel/ZonesPanel.js +16 -8
  70. package/lib/component/panels/databasePanel/DatabasePanel.js +7 -8
  71. package/lib/component/panels/filtersPanel/FilterPanel.js +9 -6
  72. package/lib/component/panels/filtersPanel/FiltersTable.js +12 -10
  73. package/lib/component/panels/header/DefaultPanelHeader.d.ts +1 -0
  74. package/lib/component/panels/header/DefaultPanelHeader.js +2 -2
  75. package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.js +10 -12
  76. package/lib/component/reducer/IgnoreActions.js +1 -0
  77. package/lib/component/reducer/Reducer.js +2 -4
  78. package/lib/component/reducer/actions/DatabaseActions.d.ts +15 -13
  79. package/lib/component/reducer/actions/DatabaseActions.js +52 -34
  80. package/lib/component/reducer/actions/DomainActions.d.ts +2 -2
  81. package/lib/component/reducer/actions/FiltersActions.js +9 -4
  82. package/lib/component/reducer/actions/SpectraActions.d.ts +2 -1
  83. package/lib/component/reducer/actions/SpectraActions.js +53 -43
  84. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.d.ts +3 -0
  85. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.js +16 -0
  86. package/lib/component/reducer/preferences/actions/changePrintPageSettings.d.ts +3 -0
  87. package/lib/component/reducer/preferences/actions/changePrintPageSettings.js +6 -0
  88. package/lib/component/reducer/preferences/preferencesReducer.d.ts +3 -2
  89. package/lib/component/reducer/preferences/preferencesReducer.js +4 -1
  90. package/lib/component/toolbar/ToolBar.js +33 -14
  91. package/lib/component/workspaces/workspaceDefaultProperties.js +2 -0
  92. package/lib/data/SpectraManager.d.ts +7 -10
  93. package/lib/data/SpectraManager.js +51 -30
  94. package/lib/data/data1d/Spectrum1D/SumManager.d.ts +0 -1
  95. package/lib/data/data1d/Spectrum1D/SumManager.js +2 -10
  96. package/lib/data/data1d/Spectrum1D/get1DColor.d.ts +1 -1
  97. package/lib/data/data1d/Spectrum1D/index.d.ts +1 -1
  98. package/lib/data/data1d/Spectrum1D/index.js +1 -1
  99. package/lib/data/data1d/Spectrum1D/ranges/createRange.d.ts +10 -10
  100. package/lib/data/data1d/Spectrum1D/ranges/detectSignals.js +2 -1
  101. package/lib/data/data1d/Spectrum1D/ranges/initiateRanges.d.ts +10 -10
  102. package/lib/data/data1d/Spectrum1D/ranges/resizeRange.d.ts +10 -10
  103. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.d.ts +13 -0
  104. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.js +65 -0
  105. package/lib/data/molecules/MoleculeManager.js +16 -38
  106. package/lib/data/utilities/getCustomColor.d.ts +1 -1
  107. package/lib/data/utilities/removeByPaths.d.ts +3 -0
  108. package/lib/data/utilities/removeByPaths.js +33 -0
  109. package/lib/versionInfo.js +1 -1
  110. package/package.json +34 -34
  111. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.d.ts +0 -11
  112. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +0 -29
@@ -6,6 +6,7 @@ import { addWorkspace } from './actions/addWorkspace';
6
6
  import { analyzeSpectra, changeAnalysisColumnValueKey, deleteAnalysisColumn, setSpectraAnalysisPanelsPreferences, } from './actions/analyzeSpectra';
7
7
  import { applyGeneralPreferences } from './actions/applyGeneralPreferences';
8
8
  import { changeInformationBlockPosition } from './actions/changeInformationBlockPosition';
9
+ import { changePrintPageSettings } from './actions/changePrintPageSettings';
9
10
  import { initPreferences } from './actions/initPreferences';
10
11
  import { setMatrixGenerationOptions, addExclusionZone, deleteExclusionZone, toggleMatrixGenerationViewProperty, changeMatrixGenerationScale, changeMatrixGenerationStocsyChemicalShift, } from './actions/matrixGeneration';
11
12
  import { removeWorkspace } from './actions/removeWorkspace';
@@ -14,8 +15,8 @@ import { setPanelsPreferences } from './actions/setPanelsPreferences';
14
15
  import { setPreferences } from './actions/setPreferences';
15
16
  import { setVerticalSplitterPosition } from './actions/setVerticalSplitterPosition';
16
17
  import { setWorkspace } from './actions/setWorkspace';
17
- import { mapWorkspaces } from './utilities/mapWorkspaces';
18
18
  import { toggleInformationBlock } from './actions/toggleInformationBlock';
19
+ import { mapWorkspaces } from './utilities/mapWorkspaces';
19
20
  const LOCAL_STORAGE_SETTINGS_KEY = 'nmr-general-settings';
20
21
  export const WORKSPACES_KEYS = {
21
22
  componentKey: `nmrium-component-workspace`,
@@ -139,6 +140,8 @@ function innerPreferencesReducer(draft, action) {
139
140
  return changeInformationBlockPosition(draft, action);
140
141
  case 'TOGGLE_INFORMATION_BLOCK':
141
142
  return toggleInformationBlock(draft, action);
143
+ case 'CHANGE_PRINT_PAGE_SETTINGS':
144
+ return changePrintPageSettings(draft, action);
142
145
  default:
143
146
  return draft;
144
147
  }
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { SvgNmrAlignBottom, SvgNmrAlignCenter, SvgNmrApodization, SvgNmrBaselineCorrection, SvgNmrFourierTransform, SvgNmrIntegrate, SvgNmrMultipleAnalysis, SvgNmrOverlay3, SvgNmrOverlay3Aligned, SvgNmrPeakPicking, SvgNmrPhaseCorrection, SvgNmrRangePicking, SvgNmrRealImag, SvgNmrZeroFilling, } from 'cheminfo-font';
3
3
  import { useCallback } from 'react';
4
- import { FaSearchPlus, FaExpand, FaDiceFour, FaFileImport, FaFileExport, } from 'react-icons/fa';
4
+ import { FaSearchPlus, FaExpand, FaDiceFour, FaFileImport, FaFileExport, FaDownload, } from 'react-icons/fa';
5
5
  import { PiKnifeBold } from 'react-icons/pi';
6
6
  import { Toolbar, TooltipHelpContent, } from 'react-science/ui';
7
7
  import { useChartData } from '../context/ChartContext';
@@ -9,6 +9,7 @@ import { useDispatch } from '../context/DispatchContext';
9
9
  import { useLoader } from '../context/LoaderContext';
10
10
  import { usePreferences } from '../context/PreferencesContext';
11
11
  import { ToolbarPopoverItem, } from '../elements/ToolbarPopoverItem';
12
+ import { useActiveSpectrum } from '../hooks/useActiveSpectrum';
12
13
  import useCheckExperimentalFeature from '../hooks/useCheckExperimentalFeature';
13
14
  import { useCheckToolsVisibility, } from '../hooks/useCheckToolsVisibility';
14
15
  import useDatumWithSpectraStatistics from '../hooks/useDatumWithSpectraStatistics';
@@ -16,6 +17,7 @@ import { useDialogToggle } from '../hooks/useDialogToggle';
16
17
  import useExport from '../hooks/useExport';
17
18
  import useToolsFunctions from '../hooks/useToolsFunctions';
18
19
  import { useVerticalAlign } from '../hooks/useVerticalAlign';
20
+ import ExportAsJcampModal from '../modal/ExportAsJcampModal';
19
21
  import { ImportPublicationStringModal } from '../modal/ImportPublicationStringModal';
20
22
  import { LoadJCAMPModal } from '../modal/LoadJCAMPModal';
21
23
  import SaveAsModal from '../modal/SaveAsModal';
@@ -25,6 +27,21 @@ import { EXPORT_MENU, IMPORT_MENU } from './toolbarMenu';
25
27
  function isPopoverToolItem(item) {
26
28
  return !!item?.menuItems;
27
29
  }
30
+ function useExportList() {
31
+ const isExperimentalFeature = useCheckExperimentalFeature();
32
+ const spectrum = useActiveSpectrum();
33
+ const exportMenu = isExperimentalFeature
34
+ ? EXPORT_MENU
35
+ : EXPORT_MENU.filter((item) => item.id !== 'nmre');
36
+ if (spectrum) {
37
+ exportMenu.push({
38
+ icon: _jsx(FaDownload, {}),
39
+ text: 'Export as JCAMP-DX',
40
+ data: { id: 'exportAsJcamp' },
41
+ });
42
+ }
43
+ return exportMenu;
44
+ }
28
45
  export default function ToolBar() {
29
46
  const { toolOptions: { selectedTool }, } = useChartData();
30
47
  const isButtonVisible = useCheckToolsVisibility();
@@ -40,15 +57,14 @@ export default function ToolBar() {
40
57
  importPublicationString: false,
41
58
  metaImportation: false,
42
59
  saveAs: false,
60
+ exportAsJcamp: false,
43
61
  });
44
62
  const verticalAlign = useVerticalAlign();
45
63
  const { fidCounter, ftCounter } = useDatumWithSpectraStatistics();
46
64
  const importMenu = isExperimentalFeature
47
65
  ? IMPORT_MENU
48
66
  : IMPORT_MENU.filter((item) => item.id !== 'importPublicationString');
49
- const exportMenu = isExperimentalFeature
50
- ? EXPORT_MENU
51
- : EXPORT_MENU.filter((item) => item.id !== 'nmre');
67
+ const exportMenu = useExportList();
52
68
  const { current: { general: { invert }, }, } = usePreferences();
53
69
  const handleOnFFTFilter = useCallback(() => {
54
70
  dispatch({
@@ -100,6 +116,9 @@ export default function ToolBar() {
100
116
  case 'copy':
101
117
  void saveToClipboardHandler();
102
118
  break;
119
+ case 'exportAsJcamp':
120
+ openDialog('exportAsJcamp');
121
+ break;
103
122
  default:
104
123
  break;
105
124
  }
@@ -137,7 +156,7 @@ export default function ToolBar() {
137
156
  title: options.peakPicking.label,
138
157
  shortcuts: ['p'],
139
158
  description: 'Detect peaks manually or automatically in the spectrum.',
140
- link: 'https://docs.nmrium.org/20_1d-spectra/peaks/peaks',
159
+ link: 'https://docs.nmrium.org/20_1d-spectra/peaks',
141
160
  },
142
161
  icon: _jsx(SvgNmrPeakPicking, {}),
143
162
  },
@@ -157,7 +176,7 @@ export default function ToolBar() {
157
176
  title: options.zonePicking.label,
158
177
  shortcuts: ['r'],
159
178
  description: `Draw 2D zones by clicking, dragging, and releasing${!invert ? 'while holding SHIFT' : ''}. Alternatively, detect zones automatically.`,
160
- link: 'https://docs.nmrium.org/30_2d-spectra/zones/zones',
179
+ link: 'https://docs.nmrium.org/30_2d-spectra/zones',
161
180
  },
162
181
  icon: _jsx(FaDiceFour, {}),
163
182
  },
@@ -166,7 +185,7 @@ export default function ToolBar() {
166
185
  tooltip: {
167
186
  title: options.slicing.label,
168
187
  description: 'Display the horizontal and vertical slices of the selected 2D spectrum at the level of the pointer.',
169
- link: 'https://docs.nmrium.org/30_2d-spectra/slicing/slicing',
188
+ link: 'https://docs.nmrium.org/30_2d-spectra/slicing',
170
189
  },
171
190
  icon: _jsx(PiKnifeBold, {}),
172
191
  },
@@ -176,7 +195,7 @@ export default function ToolBar() {
176
195
  title: options.rangePicking.label,
177
196
  shortcuts: ['r'],
178
197
  description: `Define ranges and analyse multiplet automatically or manually. Click, drag, and release ${!invert ? 'while holding SHIFT' : ''} to draw the range. Ranges can be resized by moving the edges.`,
179
- link: 'https://docs.nmrium.org/20_1d-spectra/ranges/ranges',
198
+ link: 'https://docs.nmrium.org/20_1d-spectra/ranges',
180
199
  },
181
200
  icon: _jsx(SvgNmrRangePicking, {}),
182
201
  },
@@ -202,7 +221,7 @@ export default function ToolBar() {
202
221
  title: options.zeroFilling.label,
203
222
  shortcuts: ['z'],
204
223
  description: 'Improve spectrum quality by increasing the number of points. By default, the number of points is twice as many as in the original FID.',
205
- link: 'https://docs.nmrium.org/20_1d-spectra/preprocessing/preprocessing#zero-filling',
224
+ link: 'https://docs.nmrium.org/20_1d-spectra/preprocessing#zero-filling',
206
225
  },
207
226
  icon: _jsx(SvgNmrZeroFilling, {}),
208
227
  },
@@ -212,7 +231,7 @@ export default function ToolBar() {
212
231
  title: options.phaseCorrection.label,
213
232
  shortcuts: ['a'],
214
233
  description: `Correct the spectrum phase manually or automatically. For manual phase correction, define the pivot${!invert ? ' using SHIFT +' : ''} click, then press the PH0 and PH1 button, and move the mouse horizontally.`,
215
- link: 'https://docs.nmrium.org/20_1d-spectra/phase/phase',
234
+ link: 'https://docs.nmrium.org/20_1d-spectra/phase',
216
235
  },
217
236
  icon: _jsx(SvgNmrPhaseCorrection, {}),
218
237
  },
@@ -231,7 +250,7 @@ export default function ToolBar() {
231
250
  title: options.baselineCorrection.label,
232
251
  shortcuts: ['b'],
233
252
  description: `Correct the baseline of the spectrum. You should draw zones corresponding to the noise using click, drag, release${!invert ? 'while holding SHIFT' : ''}.`,
234
- link: 'https://docs.nmrium.org/20_1d-spectra/baseline/baseline',
253
+ link: 'https://docs.nmrium.org/20_1d-spectra/baseline',
235
254
  },
236
255
  icon: _jsx(SvgNmrBaselineCorrection, {}),
237
256
  },
@@ -252,7 +271,7 @@ export default function ToolBar() {
252
271
  title: options.fft.label,
253
272
  shortcuts: ['t'],
254
273
  description: 'Perform a Fourier transform on the FID.',
255
- link: 'https://docs.nmrium.org/20_1d-spectra/ft/ft/',
274
+ link: 'https://docs.nmrium.org/20_1d-spectra/ft',
256
275
  },
257
276
  onClick: handleOnFFTFilter,
258
277
  icon: _jsx(SvgNmrFourierTransform, {}),
@@ -299,7 +318,7 @@ export default function ToolBar() {
299
318
  tooltip: {
300
319
  title: `Display ${isRealSpectrumShown ? 'real' : 'imaginary'}`,
301
320
  description: 'Toggle between the imaginary and real parts of the spectrum.',
302
- link: 'https://docs.nmrium.org/20_1d-spectra/views/views',
321
+ link: 'https://docs.nmrium.org/20_1d-spectra/views',
303
322
  },
304
323
  icon: _jsx(SvgNmrRealImag, {}),
305
324
  onClick: changeSpectrumViewHandler,
@@ -316,7 +335,7 @@ export default function ToolBar() {
316
335
  onClick: alignSpectraVerticallyHandler,
317
336
  },
318
337
  ];
319
- return (_jsxs(_Fragment, { children: [_jsx(LoadJCAMPModal, { isOpen: dialog.loadJCAMP, onCloseDialog: closeDialog }), _jsx(ImportPublicationStringModal, { isOpen: dialog.importPublicationString, onClose: closeDialog }), _jsx(MetaImportationModal, { isOpen: dialog.metaImportation, onCloseDialog: closeDialog }), _jsx(SaveAsModal, { isOpen: dialog.saveAs, onCloseDialog: closeDialog }), _jsx(Toolbar, { vertical: true, children: toolItems.map((item) => {
338
+ return (_jsxs(_Fragment, { children: [_jsx(LoadJCAMPModal, { isOpen: dialog.loadJCAMP, onCloseDialog: closeDialog }), _jsx(ImportPublicationStringModal, { isOpen: dialog.importPublicationString, onClose: closeDialog }), _jsx(MetaImportationModal, { isOpen: dialog.metaImportation, onCloseDialog: closeDialog }), dialog.exportAsJcamp && (_jsx(ExportAsJcampModal, { exportActiveSpectrum: true, closeDialog: closeDialog })), _jsx(SaveAsModal, { isOpen: dialog.saveAs, onCloseDialog: closeDialog }), _jsx(Toolbar, { vertical: true, children: toolItems.map((item) => {
320
339
  const { id, icon, tooltip, checkOptions, condition } = item;
321
340
  const show = isButtonVisible(id, checkOptions) &&
322
341
  (condition === undefined || condition);
@@ -221,4 +221,6 @@ export const workspaceDefaultProperties = {
221
221
  },
222
222
  ],
223
223
  },
224
+ printPageOptions: {},
225
+ externalAPIs: [],
224
226
  };
@@ -1,4 +1,4 @@
1
- import { Spectrum, Workspace } from 'nmr-load-save';
1
+ import { Spectrum, Workspace, StateMolecule } from 'nmr-load-save';
2
2
  import { State } from '../component/reducer/Reducer';
3
3
  export declare enum DataExportOptions {
4
4
  ROW_DATA = "ROW_DATA",
@@ -22,14 +22,11 @@ export declare function addJcamp(output: any, jcamp: any, options: any, usedColo
22
22
  export declare function toJSON(state: Partial<State>, preferencesState: Partial<{
23
23
  current: Workspace;
24
24
  }>, options?: ExportOptions): any;
25
- export declare const DataExportStage: {
26
- readonly Original: "ORIGINAL";
27
- readonly Processed: "PROCESSED";
28
- };
29
- export type DataExportStageStrings = (typeof DataExportStage)[keyof typeof DataExportStage];
30
- export interface ExportAsJcampOptions {
31
- onlyReal?: boolean;
32
- dataExportStage?: DataExportStageStrings;
25
+ export type DataExportStage = 'originalFid' | 'originalFtReal' | 'originalFtRealImaginary' | 'processedReal' | 'processedRealImaginary';
26
+ export declare function exportAsJcamp(spectrum: Spectrum, dataExportStage: DataExportStage): void;
27
+ interface ExportForCTOptions {
28
+ spectrum: Spectrum;
29
+ molecules: StateMolecule[];
33
30
  }
34
- export declare function exportAsJcamp(spectrum: Spectrum, options?: ExportAsJcampOptions): void;
31
+ export declare function exportForCT(options: ExportForCTOptions): Promise<void>;
35
32
  export {};
@@ -1,5 +1,7 @@
1
1
  import { saveAs } from 'file-saver';
2
+ import JSZip from 'jszip';
2
3
  import { processJcamp, serializeNmriumState, CURRENT_EXPORT_VERSION, spectrum1DToJcamp, } from 'nmr-load-save';
4
+ import OCL from 'openchemlib/full';
3
5
  import { isSpectrum1D, initiateDatum1D } from './data1d/Spectrum1D';
4
6
  import { initiateDatum2D } from './data2d/Spectrum2D';
5
7
  import * as Molecule from './molecules/Molecule';
@@ -75,44 +77,63 @@ export function toJSON(state, preferencesState, options = {}) {
75
77
  });
76
78
  }
77
79
  }
78
- export const DataExportStage = {
79
- Original: 'ORIGINAL',
80
- Processed: 'PROCESSED',
81
- };
82
- export function exportAsJcamp(spectrum, options = {}) {
80
+ export function exportAsJcamp(spectrum, dataExportStage) {
83
81
  let jcamp = null;
84
- if (isSpectrum1D(spectrum)) {
85
- const { dataExportStage = 'PROCESSED', onlyReal } = options;
86
- const { originalData, originalInfo, data, info, filters } = spectrum;
87
- if (onlyReal && info.isFid) {
88
- throw new Error('FID data should be complex');
89
- }
82
+ if (!isSpectrum1D(spectrum)) {
83
+ throw new Error('convert 2D spectrum to JCAMP is not supported');
84
+ }
85
+ const { originalData, originalInfo, ...otherSpectrum } = spectrum;
86
+ const exportedSpectrum = { ...otherSpectrum };
87
+ if (!['processedReal', 'processedRealImaginary'].includes(dataExportStage)) {
90
88
  if (!originalData || !originalInfo) {
91
89
  throw new Error('original data should exists');
92
90
  }
93
- if (dataExportStage === 'PROCESSED') {
94
- jcamp = spectrum1DToJcamp({
95
- ...spectrum,
96
- data,
97
- info,
98
- filters,
99
- }, { onlyReal });
100
- }
101
- else {
102
- jcamp = spectrum1DToJcamp({
103
- ...spectrum,
104
- data: originalData,
105
- info: originalInfo,
106
- filters: [],
107
- }, { onlyReal });
108
- }
109
- }
110
- else {
111
- throw new Error('convert 2D spectrum to JCAMP is not supported');
91
+ exportedSpectrum.filters = [];
92
+ exportedSpectrum.data = originalData;
93
+ exportedSpectrum.info = originalInfo;
112
94
  }
95
+ const onlyReal = dataExportStage === 'processedReal' || dataExportStage === 'originalFtReal';
96
+ jcamp = spectrum1DToJcamp(exportedSpectrum, {
97
+ onlyReal,
98
+ });
113
99
  if (!jcamp) {
114
100
  throw new Error('convert spectrum to JCAMP failed');
115
101
  }
116
102
  const blob = new Blob([jcamp], { type: 'text/plain' });
117
103
  saveAs(blob, `${spectrum.info.name}.jdx`);
118
104
  }
105
+ export async function exportForCT(options) {
106
+ const { spectrum, molecules } = options;
107
+ if (!isSpectrum1D(spectrum)) {
108
+ throw new Error('2D spectrum is not supported');
109
+ }
110
+ if (!spectrum.info.isFt) {
111
+ throw new Error('The spectrum must be a Fourier Transform (FT) spectrum.');
112
+ }
113
+ if (!(Array.isArray(molecules) && molecules.length > 0)) {
114
+ throw new Error('Molecule file is required. Please add a molecule');
115
+ }
116
+ const jcamp = spectrum1DToJcamp(spectrum, {
117
+ onlyReal: true,
118
+ });
119
+ if (!jcamp) {
120
+ throw new Error('Failed to convert the 1D spectrum to JCAMP');
121
+ }
122
+ const name = spectrum.info.name;
123
+ const zip = new JSZip();
124
+ //add jcamp file
125
+ zip.file(`${name}.dx`, jcamp);
126
+ //add mol file
127
+ const { molfile } = molecules[0];
128
+ const molecule = OCL.Molecule.fromMolfile(molfile);
129
+ const molFileName = molecule.getMolecularFormula().formula;
130
+ zip.file(`${molFileName}.mol`, molecule.toMolfile());
131
+ const blob = await zip.generateAsync({
132
+ type: 'blob',
133
+ compression: 'DEFLATE',
134
+ compressionOptions: {
135
+ level: 9,
136
+ },
137
+ });
138
+ saveAs(blob, name);
139
+ }
@@ -13,7 +13,6 @@ export declare function setSumOptions(data: Ranges | Integrals, params: {
13
13
  options: SetSumOptions;
14
14
  nucleus: string;
15
15
  }): void;
16
- export declare function getAtoms(mf: string): Record<string, number>;
17
16
  /**
18
17
  * change the sum for ranges and integrals in all spectra based on molecule
19
18
  * it handle three cases
@@ -1,3 +1,4 @@
1
+ import { MF } from 'mf-parser';
1
2
  import getAtom from '../../utilities/getAtom';
2
3
  import { isSpectrum1D, updateRangesRelativeValues, updateIntegralsRelativeValues, } from '.';
3
4
  export function initSumOptions(options, params) {
@@ -26,7 +27,7 @@ export function getSum(mf, nucleus) {
26
27
  if (!mf || !nucleus)
27
28
  return defaultSum;
28
29
  const atom = getAtom(nucleus);
29
- const atoms = getAtoms(mf);
30
+ const atoms = new MF(mf).getInfo().atoms;
30
31
  return atoms[atom] || defaultSum;
31
32
  }
32
33
  export function setSumOptions(data, params) {
@@ -47,15 +48,6 @@ export function setSumOptions(data, params) {
47
48
  data.options = { ...resOptions, sumAuto: false, sum: options.sum };
48
49
  }
49
50
  }
50
- export function getAtoms(mf) {
51
- const result = {};
52
- // eslint-disable-next-line prefer-named-capture-group
53
- const data = mf.split(/(\d+)/);
54
- for (let i = 0; i < data.length - 1; i = i + 2) {
55
- result[data[i]] = Number(data[i + 1]);
56
- }
57
- return result;
58
- }
59
51
  /**
60
52
  * change the sum for ranges and integrals in all spectra based on molecule
61
53
  * it handle three cases
@@ -11,7 +11,7 @@ interface RandomColorOptions extends BaseColorOptions {
11
11
  regenerate: true;
12
12
  random?: boolean;
13
13
  }
14
- export declare const COLORS: Readonly<string[]>;
14
+ export declare const COLORS: readonly string[];
15
15
  export declare function get1DColor(spectrum: any, options: ColorOptions | RandomColorOptions): {
16
16
  color: string;
17
17
  };
@@ -12,6 +12,6 @@ export { changeRangeSignal } from './ranges/changeRangeSignal';
12
12
  export { checkRangeKind } from './ranges/checkRangeKind';
13
13
  export { detectRange } from './ranges/detectRange';
14
14
  export { detectRanges } from './ranges/detectRanges';
15
- export { generateSpectrumFromRanges } from './ranges/generateSpectrumFromRanges';
15
+ export { resurrectSpectrumFromRanges, resurrectSpectrumFromSignals, } from './ranges/resurrectSpectrum';
16
16
  export { mapRanges, getShiftX, checkIntegralKind, updateRangesRelativeValues, updateIntegralsRelativeValues, } from 'nmr-processing';
17
17
  export { get1DColor } from './get1DColor';
@@ -12,6 +12,6 @@ export { changeRangeSignal } from './ranges/changeRangeSignal';
12
12
  export { checkRangeKind } from './ranges/checkRangeKind';
13
13
  export { detectRange } from './ranges/detectRange';
14
14
  export { detectRanges } from './ranges/detectRanges';
15
- export { generateSpectrumFromRanges } from './ranges/generateSpectrumFromRanges';
15
+ export { resurrectSpectrumFromRanges, resurrectSpectrumFromSignals, } from './ranges/resurrectSpectrum';
16
16
  export { mapRanges, getShiftX, checkIntegralKind, updateRangesRelativeValues, updateIntegralsRelativeValues, } from 'nmr-processing';
17
17
  export { get1DColor } from './get1DColor';
@@ -11,18 +11,18 @@ export declare function createRange(spectrum: Spectrum1D, options: Pick<Range, '
11
11
  delta: number;
12
12
  multiplicity: string;
13
13
  js: import("nmr-processing").Jcoupling[];
14
- atoms?: number[];
15
- assignment?: string;
16
- diaIDs?: string[];
17
- nbAtoms?: number;
18
- integration?: number;
14
+ atoms?: number[] | undefined;
15
+ assignment?: string | undefined;
16
+ diaIDs?: string[] | undefined;
17
+ nbAtoms?: number | undefined;
18
+ integration?: number | undefined;
19
19
  statistic?: {
20
20
  mean: number;
21
21
  sd: number;
22
22
  min: number;
23
23
  max: number;
24
24
  nb: number;
25
- };
25
+ } | undefined;
26
26
  kind: string;
27
27
  id: string;
28
28
  peaks: {
@@ -43,8 +43,8 @@ export declare function createRange(spectrum: Spectrum1D, options: Pick<Range, '
43
43
  kind: string;
44
44
  integration: number;
45
45
  nbAtoms?: number;
46
- multiplicity?: string;
47
- assignment?: string;
48
- diaIDs?: string[];
49
- pubIntegral?: number;
46
+ multiplicity?: string | undefined;
47
+ assignment?: string | undefined;
48
+ diaIDs?: string[] | undefined;
49
+ pubIntegral?: number | undefined;
50
50
  } | undefined;
@@ -7,6 +7,7 @@ export default function detectSignals(data, options) {
7
7
  const { fromIndex, toIndex } = xGetFromToIndex(data.x, { from, to });
8
8
  const size = toIndex - fromIndex;
9
9
  if (size <= 16 || size >= MAX_LENGTH) {
10
+ const frequencyCluster = (to - from) * frequency;
10
11
  const ranges = xyAutoRangesPicking(data, {
11
12
  logger,
12
13
  peakPicking: {
@@ -25,7 +26,7 @@ export default function detectSignals(data, options) {
25
26
  frequency,
26
27
  nucleus,
27
28
  compile: true,
28
- frequencyCluster: 16,
29
+ frequencyCluster,
29
30
  keepPeaks: true,
30
31
  clean: 0.3,
31
32
  },
@@ -11,18 +11,18 @@ export declare function initiateRanges(inputSpectrum: Partial<Spectrum1D>, spect
11
11
  delta: number;
12
12
  multiplicity: string;
13
13
  js: import("nmr-processing").Jcoupling[];
14
- atoms?: number[];
15
- assignment?: string;
16
- diaIDs?: string[];
17
- nbAtoms?: number;
18
- integration?: number;
14
+ atoms?: number[] | undefined;
15
+ assignment?: string | undefined;
16
+ diaIDs?: string[] | undefined;
17
+ nbAtoms?: number | undefined;
18
+ integration?: number | undefined;
19
19
  statistic?: {
20
20
  mean: number;
21
21
  sd: number;
22
22
  min: number;
23
23
  max: number;
24
24
  nb: number;
25
- };
25
+ } | undefined;
26
26
  kind: string;
27
27
  id: string;
28
28
  peaks: {
@@ -43,9 +43,9 @@ export declare function initiateRanges(inputSpectrum: Partial<Spectrum1D>, spect
43
43
  kind: string;
44
44
  integration: number;
45
45
  nbAtoms?: number;
46
- multiplicity?: string;
47
- assignment?: string;
48
- diaIDs?: string[];
49
- pubIntegral?: number;
46
+ multiplicity?: string | undefined;
47
+ assignment?: string | undefined;
48
+ diaIDs?: string[] | undefined;
49
+ pubIntegral?: number | undefined;
50
50
  }[];
51
51
  };
@@ -13,18 +13,18 @@ export declare function resizeRange(spectrum: Spectrum1D, options: {
13
13
  delta: number;
14
14
  multiplicity: string;
15
15
  js: import("nmr-processing").Jcoupling[];
16
- atoms?: number[];
17
- assignment?: string;
18
- diaIDs?: string[];
19
- nbAtoms?: number;
20
- integration?: number;
16
+ atoms?: number[] | undefined;
17
+ assignment?: string | undefined;
18
+ diaIDs?: string[] | undefined;
19
+ nbAtoms?: number | undefined;
20
+ integration?: number | undefined;
21
21
  statistic?: {
22
22
  mean: number;
23
23
  sd: number;
24
24
  min: number;
25
25
  max: number;
26
26
  nb: number;
27
- };
27
+ } | undefined;
28
28
  kind: string;
29
29
  id: string;
30
30
  peaks: {
@@ -45,8 +45,8 @@ export declare function resizeRange(spectrum: Spectrum1D, options: {
45
45
  kind: string;
46
46
  integration: number;
47
47
  nbAtoms?: number;
48
- multiplicity?: string;
49
- assignment?: string;
50
- diaIDs?: string[];
51
- pubIntegral?: number;
48
+ multiplicity?: string | undefined;
49
+ assignment?: string | undefined;
50
+ diaIDs?: string[] | undefined;
51
+ pubIntegral?: number | undefined;
52
52
  };
@@ -0,0 +1,13 @@
1
+ import { Spectrum1D } from 'nmr-load-save';
2
+ import { Info1D, NMRRange, NMRSignal1D } from 'nmr-processing';
3
+ import { UsedColors } from '../../../../types/UsedColors';
4
+ interface ResurrectSpectrumOptions {
5
+ info: Partial<Info1D>;
6
+ usedColors: UsedColors;
7
+ from?: number;
8
+ to?: number;
9
+ spectrumID?: string;
10
+ }
11
+ declare function resurrectSpectrumFromRanges(ranges: NMRRange[], options: ResurrectSpectrumOptions): Spectrum1D | undefined;
12
+ declare function resurrectSpectrumFromSignals(signals: NMRSignal1D[], options: ResurrectSpectrumOptions): Spectrum1D | undefined;
13
+ export { resurrectSpectrumFromRanges, resurrectSpectrumFromSignals };
@@ -0,0 +1,65 @@
1
+ import { rangesToXY, signalsToXY, } from 'nmr-processing';
2
+ import { initiateDatum1D } from '../initiateDatum1D';
3
+ function resurrectSpectrumFromRanges(ranges, options) {
4
+ const { spectrumID, usedColors, from, to, info } = options;
5
+ const { nucleus, solvent, name = null, baseFrequency = 400, originFrequency = 400, numberOfPoints = 2 ** 17, } = info;
6
+ try {
7
+ const { x, y } = rangesToXY(ranges, {
8
+ nucleus,
9
+ frequency: baseFrequency,
10
+ nbPoints: numberOfPoints,
11
+ from,
12
+ to,
13
+ });
14
+ const datum = initiateDatum1D({
15
+ id: spectrumID,
16
+ data: { x, im: null, re: y },
17
+ info: {
18
+ numberOfPoints,
19
+ nucleus,
20
+ originFrequency,
21
+ baseFrequency,
22
+ pulseSequence: '',
23
+ solvent,
24
+ isFt: true,
25
+ name,
26
+ },
27
+ ranges: { values: ranges, options: { sum: 100 } },
28
+ }, { usedColors });
29
+ return datum;
30
+ }
31
+ catch (error) {
32
+ reportError(error);
33
+ }
34
+ }
35
+ function resurrectSpectrumFromSignals(signals, options) {
36
+ const { spectrumID, usedColors, from, to, info } = options;
37
+ const { nucleus, solvent, name = null, baseFrequency = 400, originFrequency = 400, numberOfPoints: nbPoints = 2 ** 17, } = info;
38
+ try {
39
+ const { x, y } = signalsToXY(signals, {
40
+ frequency: baseFrequency,
41
+ nbPoints,
42
+ from,
43
+ to,
44
+ });
45
+ const datum = initiateDatum1D({
46
+ id: spectrumID,
47
+ data: { x, im: null, re: y },
48
+ info: {
49
+ nucleus,
50
+ originFrequency,
51
+ baseFrequency,
52
+ pulseSequence: '',
53
+ solvent,
54
+ isFt: true,
55
+ name,
56
+ },
57
+ ranges: { values: signals, options: { sum: 100 } },
58
+ }, { usedColors });
59
+ return datum;
60
+ }
61
+ catch (error) {
62
+ reportError(error);
63
+ }
64
+ }
65
+ export { resurrectSpectrumFromRanges, resurrectSpectrumFromSignals };