nmr-processing 3.3.4 → 5.0.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 (109) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/lib/assignment/get13CAssignments.d.ts +35 -0
  3. package/lib/assignment/get13CAssignments.js +54 -0
  4. package/lib/assignment/get13CAssignments.js.map +1 -0
  5. package/lib/assignment/get1HAssignments.d.ts +42 -0
  6. package/lib/assignment/get1HAssignments.js +55 -0
  7. package/lib/assignment/get1HAssignments.js.map +1 -0
  8. package/lib/assignment/utils/buildAssignments.d.ts +33 -0
  9. package/lib/assignment/utils/buildAssignments.js +93 -0
  10. package/lib/assignment/utils/buildAssignments.js.map +1 -0
  11. package/lib/assignment/utils/createMapPossibleAssignments.d.ts +15 -0
  12. package/lib/assignment/utils/createMapPossibleAssignments.js +51 -0
  13. package/lib/assignment/utils/createMapPossibleAssignments.js.map +1 -0
  14. package/lib/assignment/utils/exploreTreeRec.d.ts +22 -0
  15. package/lib/assignment/utils/exploreTreeRec.js +77 -0
  16. package/lib/assignment/utils/exploreTreeRec.js.map +1 -0
  17. package/lib/assignment/utils/generateID.d.ts +1 -0
  18. package/lib/assignment/utils/generateID.js +13 -0
  19. package/lib/assignment/utils/generateID.js.map +1 -0
  20. package/lib/assignment/utils/partialScore.d.ts +16 -0
  21. package/lib/assignment/utils/partialScore.js +91 -0
  22. package/lib/assignment/utils/partialScore.js.map +1 -0
  23. package/lib/index.d.ts +2 -5
  24. package/lib/index.js +2 -5
  25. package/lib/index.js.map +1 -1
  26. package/lib/peaks/peaksFilterImpurities.js +1 -1
  27. package/lib/peaks/peaksFilterImpurities.js.map +1 -1
  28. package/lib/peaks/peaksToRanges.js +11 -17
  29. package/lib/peaks/peaksToRanges.js.map +1 -1
  30. package/lib/peaks/util/determineRealTop.js +3 -2
  31. package/lib/peaks/util/determineRealTop.js.map +1 -1
  32. package/lib/peaks/util/jAnalyzer.js +33 -35
  33. package/lib/peaks/util/jAnalyzer.js.map +1 -1
  34. package/lib/ranges/rangesToXY.d.ts +2 -2
  35. package/lib/ranges/rangesToXY.js +10 -2
  36. package/lib/ranges/rangesToXY.js.map +1 -1
  37. package/lib/signals/signals2DToZ.d.ts +2 -2
  38. package/lib/signals/signalsToXY.d.ts +2 -2
  39. package/lib/signals/simulation/simulate1D.d.ts +4 -3
  40. package/lib/signals/simulation/simulate1D.js.map +1 -1
  41. package/lib/types/NMRPeak1D.d.ts +2 -9
  42. package/lib/types/NMRRange.d.ts +1 -0
  43. package/lib/types/NMRSignal1D.d.ts +1 -0
  44. package/lib/types/NMRSignal2D.d.ts +3 -4
  45. package/lib/types/NMRZone.d.ts +4 -3
  46. package/lib/xy/xyAutoPeaksPicking.d.ts +4 -60
  47. package/lib/xy/xyAutoPeaksPicking.js +3 -3
  48. package/lib/xy/xyAutoPeaksPicking.js.map +1 -1
  49. package/lib/xyz/xyzAutoPeaksPicking.js +4 -2
  50. package/lib/xyz/xyzAutoPeaksPicking.js.map +1 -1
  51. package/lib-esm/assignment/get13CAssignments.js +47 -0
  52. package/lib-esm/assignment/get13CAssignments.js.map +1 -0
  53. package/lib-esm/assignment/get1HAssignments.js +48 -0
  54. package/lib-esm/assignment/get1HAssignments.js.map +1 -0
  55. package/lib-esm/assignment/utils/buildAssignments.js +86 -0
  56. package/lib-esm/assignment/utils/buildAssignments.js.map +1 -0
  57. package/lib-esm/assignment/utils/createMapPossibleAssignments.js +47 -0
  58. package/lib-esm/assignment/utils/createMapPossibleAssignments.js.map +1 -0
  59. package/lib-esm/assignment/utils/exploreTreeRec.js +73 -0
  60. package/lib-esm/assignment/utils/exploreTreeRec.js.map +1 -0
  61. package/lib-esm/assignment/utils/generateID.js +10 -0
  62. package/lib-esm/assignment/utils/generateID.js.map +1 -0
  63. package/lib-esm/assignment/utils/partialScore.js +87 -0
  64. package/lib-esm/assignment/utils/partialScore.js.map +1 -0
  65. package/lib-esm/index.js +2 -5
  66. package/lib-esm/index.js.map +1 -1
  67. package/lib-esm/peaks/peaksFilterImpurities.js +1 -1
  68. package/lib-esm/peaks/peaksFilterImpurities.js.map +1 -1
  69. package/lib-esm/peaks/peaksToRanges.js +11 -17
  70. package/lib-esm/peaks/peaksToRanges.js.map +1 -1
  71. package/lib-esm/peaks/util/determineRealTop.js +4 -3
  72. package/lib-esm/peaks/util/determineRealTop.js.map +1 -1
  73. package/lib-esm/peaks/util/jAnalyzer.js +33 -35
  74. package/lib-esm/peaks/util/jAnalyzer.js.map +1 -1
  75. package/lib-esm/ranges/rangesToXY.js +10 -2
  76. package/lib-esm/ranges/rangesToXY.js.map +1 -1
  77. package/lib-esm/signals/simulation/simulate1D.js.map +1 -1
  78. package/lib-esm/xy/xyAutoPeaksPicking.js +3 -3
  79. package/lib-esm/xy/xyAutoPeaksPicking.js.map +1 -1
  80. package/lib-esm/xyz/xyzAutoPeaksPicking.js +4 -2
  81. package/lib-esm/xyz/xyzAutoPeaksPicking.js.map +1 -1
  82. package/package.json +4 -4
  83. package/src/assignment/get13CAssignments.ts +100 -0
  84. package/src/assignment/get1HAssignments.ts +116 -0
  85. package/src/assignment/utils/buildAssignments.ts +155 -0
  86. package/src/assignment/utils/createMapPossibleAssignments.ts +76 -0
  87. package/src/assignment/utils/exploreTreeRec.ts +138 -0
  88. package/src/assignment/utils/generateID.ts +11 -0
  89. package/src/assignment/utils/partialScore.ts +128 -0
  90. package/src/index.ts +3 -6
  91. package/src/peaks/peaksFilterImpurities.ts +1 -1
  92. package/src/peaks/peaksToRanges.ts +11 -17
  93. package/src/peaks/util/determineRealTop.ts +4 -6
  94. package/src/peaks/util/jAnalyzer.ts +34 -36
  95. package/src/ranges/rangesToXY.ts +14 -7
  96. package/src/signals/signals2DToZ.ts +2 -2
  97. package/src/signals/signalsToXY.ts +2 -2
  98. package/src/signals/simulation/simulate1D.ts +4 -3
  99. package/src/types/NMRPeak1D.ts +3 -9
  100. package/src/types/NMRRange.ts +1 -0
  101. package/src/types/NMRSignal1D.ts +1 -0
  102. package/src/types/NMRSignal2D.ts +4 -4
  103. package/src/types/NMRZone.ts +4 -3
  104. package/src/types/ml-spectra-processing/index.d.ts +8 -8
  105. package/src/types/ml-tree-set/index.d.ts +18 -0
  106. package/src/types/openchemlib-utils/index..d.ts +2 -2
  107. package/src/xy/xyAutoPeaksPicking.ts +19 -58
  108. package/src/xyz/xyzAutoPeaksPicking.ts +4 -2
  109. package/src/types/ml-gsd/index.d.ts +0 -164
@@ -91,22 +91,20 @@ const assignSignal = (
91
91
  delta: NaN,
92
92
  nbPeaks: 1,
93
93
  kind: 'signal',
94
- startX: peak.x - peak.shape.width,
95
- stopX: peak.x + peak.shape.width,
94
+ startX: peak.x - peak.width,
95
+ stopX: peak.x + peak.width,
96
96
  observe: frequency,
97
97
  nucleus,
98
98
  integralData: {
99
- from: peak.x - peak.shape.width * 3,
100
- to: peak.x + peak.shape.width * 3,
99
+ from: peak.x - peak.width * 3,
100
+ to: peak.x + peak.width * 3,
101
101
  value: 0,
102
102
  },
103
103
  peaks: [
104
104
  {
105
105
  x: peak.x,
106
106
  intensity: peak.y,
107
- shape: {
108
- width: peak.shape.width,
109
- },
107
+ width: peak.width,
110
108
  },
111
109
  ],
112
110
  };
@@ -177,9 +175,7 @@ export function peaksToRanges(
177
175
  peaksO.push({
178
176
  x: peakR.x,
179
177
  y: peakR.intensity,
180
- shape: {
181
- width: peakR.shape.width,
182
- },
178
+ width: peakR.width,
183
179
  });
184
180
  signal.mask.splice(j, 1);
185
181
  signal.mask2.splice(j, 1);
@@ -306,24 +302,22 @@ function detectSignals(
306
302
  if (peak.kind) signal1D.kind = peak.kind;
307
303
  signals.push(signal1D);
308
304
  } else {
309
- let tmp = peak.x + peak.shape.width;
305
+ let tmp = peak.x + peak.width;
310
306
  signal1D.stopX = Math.max(signal1D.stopX, tmp);
311
307
  signal1D.startX = Math.min(signal1D.startX, tmp);
312
308
  signal1D.nbPeaks++;
313
309
  signal1D.peaks.push({
314
310
  x: peak.x,
315
311
  intensity: peak.y,
316
- shape: {
317
- width: peak.shape.width,
318
- },
312
+ width: peak.width,
319
313
  });
320
314
  signal1D.integralData.from = Math.min(
321
315
  signal1D.integralData.from,
322
- peak.x - peak.shape.width * 3,
316
+ peak.x - peak.width * 3,
323
317
  );
324
318
  signal1D.integralData.to = Math.max(
325
319
  signal1D.integralData.to,
326
- peak.x + peak.shape.width * 3,
320
+ peak.x + peak.width * 3,
327
321
  );
328
322
  if (peak.kind) signal1D.kind = peak.kind;
329
323
  }
@@ -371,5 +365,5 @@ function detectSignals(
371
365
  * @private
372
366
  */
373
367
  function computeArea(peak: Peak1DIntern) {
374
- return Math.abs(peak.intensity * peak.shape.width * 1.57); // todo add an option with this value: 1.772453851
368
+ return Math.abs(peak.intensity * peak.width * 1.57); // todo add an option with this value: 1.772453851
375
369
  }
@@ -1,10 +1,8 @@
1
1
  import LM from 'ml-levenberg-marquardt';
2
- import { gaussian2D } from 'ml-peak-shape-generator';
2
+ import { Gaussian2D } from 'ml-peak-shape-generator';
3
3
 
4
4
  import type { MPFPeak } from '../../types/MPFPeak';
5
5
 
6
- const { fct: gaussian2DFct } = gaussian2D;
7
-
8
6
  const direction8X = [-1, -1, -1, 0, 0, 1, 1, 1];
9
7
  const direction8Y = [-1, 0, 1, -1, 1, -1, 0, 1];
10
8
  const direction16X = [-2, -2, -2, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2];
@@ -142,6 +140,7 @@ function fitGaussian(
142
140
  }
143
141
 
144
142
  function paramGaussian2D(intervalX: number, intervalY: number, nCols: number) {
143
+ const gaussian2D = new Gaussian2D();
145
144
  return (p: number[]) => {
146
145
  return (t: number) => {
147
146
  let nL = p.length / 5;
@@ -149,13 +148,12 @@ function paramGaussian2D(intervalX: number, intervalY: number, nCols: number) {
149
148
  let xIndex = t % nCols;
150
149
  let yIndex = (t - xIndex) / nCols;
151
150
  for (let i = 0; i < nL; i++) {
151
+ gaussian2D.fwhm = {x: p[i + 3 * nL], y: p[i + 4 * nL]};
152
152
  result +=
153
153
  p[i + 2 * nL] *
154
- gaussian2DFct(
154
+ gaussian2D.fct(
155
155
  (xIndex - p[i]) * intervalX,
156
156
  (yIndex - p[i + nL]) * intervalY,
157
- p[i + 3 * nL],
158
- p[i + 4 * nL],
159
157
  );
160
158
  }
161
159
  return result;
@@ -106,7 +106,7 @@ export default {
106
106
  signal.asymmetric = false;
107
107
  let P1, n2, maxFlagged;
108
108
  let k = 1;
109
- let Jc = [];
109
+ let jCouplings = [];
110
110
 
111
111
  // Loop over the possible number of coupling contributing to the multiplet
112
112
  for (let n = 0; n < 9; n++) {
@@ -144,17 +144,17 @@ export default {
144
144
  }
145
145
  }
146
146
 
147
- Jc = []; // The array to store the detected j-coupling
147
+ jCouplings = []; // The array to store the detected j-coupling
148
148
  // 2.2 Set j = 1; J1 = P2 - P1. Flag components 1 and 2 as accounted for.
149
149
  let j = 1;
150
- Jc.push(peaks[1].x - peaks[0].x);
150
+ jCouplings.push(peaks[1].x - peaks[0].x);
151
151
  P1 = peaks[0].x;
152
152
  numbering[0].splice(0, 1); // Flagged
153
153
  numbering[1].splice(0, 1); // Flagged
154
154
  k = 1;
155
155
  let nFlagged = 2;
156
156
  maxFlagged = Math.pow(2, n) - 1;
157
- while (Jc.length < n && nFlagged < maxFlagged && k < peaks.length) {
157
+ while (jCouplings.length < n && nFlagged < maxFlagged && k < peaks.length) {
158
158
  counter += 1;
159
159
  // 4.1. Increment j. Set k to the number of the first unflagged component.
160
160
  j++;
@@ -163,7 +163,7 @@ export default {
163
163
  }
164
164
  if (k < peaks.length) {
165
165
  // 4.2 Jj = Pk - P1.
166
- Jc.push(peaks[k].x - peaks[0].x);
166
+ jCouplings.push(peaks[k].x - peaks[0].x);
167
167
  // Flag component k and, for each sum of the...
168
168
  numbering[k].splice(0, 1); // Flageed
169
169
  nFlagged++;
@@ -171,7 +171,7 @@ export default {
171
171
  for (let u = 2; u <= j; u++) {
172
172
  let jSum = 0;
173
173
  for (let i = 0; i < u; i++) {
174
- jSum += Jc[i];
174
+ jSum += jCouplings[i];
175
175
  }
176
176
  for (let i = 1; i < numbering.length; i++) {
177
177
  // Maybe 0.25 Hz is too much?
@@ -185,7 +185,7 @@ export default {
185
185
  }
186
186
  }
187
187
  // Calculate the ideal patter by using the extracted j-couplings
188
- let pattern = idealPattern(Jc);
188
+ let pattern = idealPattern(jCouplings);
189
189
  // Compare the ideal pattern with the proposed intensities.
190
190
  // All the intensities have to match to accept the multiplet
191
191
  validPattern = true;
@@ -197,7 +197,7 @@ export default {
197
197
  }
198
198
  // If we found a valid pattern we should inform about the pattern.
199
199
  if (validPattern) {
200
- updateSignal(signal, Jc);
200
+ updateSignal(signal, jCouplings);
201
201
  }
202
202
  }
203
203
  }
@@ -213,58 +213,58 @@ export default {
213
213
  * @private
214
214
  * update the signal
215
215
  * @param {*} signal
216
- * @param {*} Jc
216
+ * @param {*} jCouplings
217
217
  */
218
- function updateSignal(signal: SignalInternMandatory, Jc: number[]) {
218
+ function updateSignal(signal: SignalInternMandatory, jCouplings: number[]) {
219
219
  // Update the limits of the signal
220
220
  let peaks = signal.peaksComp; // Always in Hz
221
221
  let nbPeaks = peaks.length;
222
- signal.startX = peaks[0].x / signal.observe - peaks[0].shape.width;
222
+ signal.startX = peaks[0].x / signal.observe - peaks[0].width;
223
223
  signal.stopX =
224
- peaks[nbPeaks - 1].x / signal.observe + peaks[nbPeaks - 1].shape.width;
224
+ peaks[nbPeaks - 1].x / signal.observe + peaks[nbPeaks - 1].width;
225
225
  signal.integralData.from =
226
- peaks[0].x / signal.observe - peaks[0].shape.width * 3;
226
+ peaks[0].x / signal.observe - peaks[0].width * 3;
227
227
  signal.integralData.to =
228
- peaks[nbPeaks - 1].x / signal.observe + peaks[nbPeaks - 1].shape.width * 3;
228
+ peaks[nbPeaks - 1].x / signal.observe + peaks[nbPeaks - 1].width * 3;
229
229
  // Compile the pattern and format the constant couplings
230
230
  signal.maskPattern = signal.mask2;
231
- signal.multiplicity = abstractPattern(signal, Jc);
231
+ signal.multiplicity = abstractPattern(signal, jCouplings);
232
232
  signal.pattern = signal.multiplicity; // Our library depends on this parameter, but it is old
233
233
  }
234
234
 
235
235
  /**
236
236
  * Returns the multiplet in the compact format
237
237
  * @param {object} signal
238
- * @param {object} Jc
238
+ * @param {object} jCouplings
239
239
  * @return {String}
240
240
  * @private
241
241
  */
242
- function abstractPattern(signal: SignalInternMandatory, Jc: number[]) {
242
+ function abstractPattern(signal: SignalInternMandatory, jCouplings: number[]) {
243
243
  let tol = 0.05;
244
244
  let pattern = '';
245
245
  let cont = 1;
246
246
  let newNmrJs = [];
247
247
 
248
- if (Jc && Jc.length > 0) {
249
- Jc.sort((a, b) => {
248
+ if (jCouplings && jCouplings.length > 0) {
249
+ jCouplings.sort((a, b) => {
250
250
  return b - a;
251
251
  });
252
252
 
253
- for (let i = 0; i < Jc.length - 1; i++) {
254
- if (Math.abs(Jc[i] - Jc[i + 1]) < tol) {
253
+ for (let i = 0; i < jCouplings.length - 1; i++) {
254
+ if (Math.abs(jCouplings[i] - jCouplings[i + 1]) < tol) {
255
255
  cont++;
256
256
  } else {
257
257
  newNmrJs.push({
258
- coupling: Math.abs(Jc[i]),
258
+ coupling: Math.abs(jCouplings[i]),
259
259
  multiplicity: patterns[cont],
260
260
  });
261
261
  pattern += patterns[cont];
262
262
  cont = 1;
263
263
  }
264
264
  }
265
- let index = Jc.length - 1;
265
+ let index = jCouplings.length - 1;
266
266
  newNmrJs.push({
267
- coupling: Math.abs(Jc[index]),
267
+ coupling: Math.abs(jCouplings[index]),
268
268
  multiplicity: patterns[cont],
269
269
  });
270
270
  pattern += patterns[cont];
@@ -281,15 +281,15 @@ function abstractPattern(signal: SignalInternMandatory, Jc: number[]) {
281
281
  /**
282
282
  * This function creates an ideal pattern from the given J-couplings
283
283
  * @private
284
- * @param {Array} Jc
284
+ * @param {Array} jCouplings
285
285
  * @return {*[]}
286
286
  * @private
287
287
  */
288
- function idealPattern(Jc: number[]) {
289
- let hsum = Math.pow(2, Jc.length);
288
+ function idealPattern(jCouplings: number[]) {
289
+ let hsum = Math.pow(2, jCouplings.length);
290
290
  let pattern = [{ x: 0, intensity: hsum }];
291
291
  // To split the initial height
292
- for (const jc of Jc) {
292
+ for (const jc of jCouplings) {
293
293
  for (let j = pattern.length - 1; j >= 0; j--) {
294
294
  pattern.push({
295
295
  x: pattern[j].x + jc / 2,
@@ -466,9 +466,7 @@ function symmetrize(
466
466
  peaks[i] = {
467
467
  x: peak[jAxis] * newSignal.observe,
468
468
  intensity: peak[intensity],
469
- shape: {
470
- width: peak.shape.width,
471
- },
469
+ width: peak.width,
472
470
  };
473
471
  }
474
472
  // Join the peaks that are closer than 0.25 Hz
@@ -480,7 +478,7 @@ function symmetrize(
480
478
  peaks[i].intensity = peaks[i].intensity + peaks[i + 1].intensity;
481
479
  peaks[i].x /= peaks[i].intensity;
482
480
  peaks[i].intensity /= 2;
483
- peaks[i].shape.width += peaks[i + 1].shape.width;
481
+ peaks[i].width += peaks[i + 1].width;
484
482
  peaks.splice(i + 1, 1);
485
483
  }
486
484
  }
@@ -528,11 +526,11 @@ function symmetrize(
528
526
  if (Math.abs(diffL - diffR) < maxError) {
529
527
  avg = Math.min(peaks[left].intensity, peaks[right].intensity);
530
528
  avgWidth = Math.min(
531
- peaks[left].shape.width,
532
- peaks[right].shape.width,
529
+ peaks[left].width,
530
+ peaks[right].width,
533
531
  );
534
532
  peaks[left].intensity = peaks[right].intensity = avg;
535
- peaks[left].shape.width = peaks[right].shape.width = avgWidth;
533
+ peaks[left].width = peaks[right].width = avgWidth;
536
534
  middle = [
537
535
  middle[0] + (peaks[right].x + peaks[left].x) / 2,
538
536
  middle[1] + 1,
@@ -712,5 +710,5 @@ function chemicalShift(peaks: Peak1DIntern[], mask: boolean[] = []) {
712
710
  * @private
713
711
  */
714
712
  function getArea(peak: Peak1DIntern) {
715
- return Math.abs(peak.intensity * peak.shape.width * 1.57); // 1.772453851);
713
+ return Math.abs(peak.intensity * peak.width * 1.57); // 1.772453851);
716
714
  }
@@ -1,15 +1,14 @@
1
1
  import { DoubleArray } from 'cheminfo-types';
2
2
  import arraySequentialFill from 'ml-array-sequential-fill';
3
+ import type { Shape1D } from 'ml-peak-shape-generator';
3
4
  import { SpectrumGenerator } from 'spectrum-generator';
4
- import type { Shape1DOptions } from 'spectrum-generator';
5
5
 
6
6
  import { hackSignalsToXY } from '../signals/hackSignalsToXY';
7
7
  import type { MakeMandatory } from '../types/MakeMandatory';
8
8
  import type { NMRRange } from '../types/NMRRange';
9
9
  import type { NMRSignal1D } from '../types/NMRSignal1D';
10
10
 
11
-
12
- type rangeWithSignal = MakeMandatory<NMRRange, 'signals'>;
11
+ type RangeWithSignal = MakeMandatory<NMRRange, 'signals'>;
13
12
 
14
13
  export interface RangeToXYOptions {
15
14
  /**
@@ -41,11 +40,11 @@ export interface RangeToXYOptions {
41
40
  * options of signals.
42
41
  * @default { kind: 'gaussian' }
43
42
  */
44
- shape: Shape1DOptions;
43
+ shape: Shape1D;
45
44
  }
46
45
  function checkForSignals(
47
46
  ranges: NMRRange[],
48
- ): asserts ranges is rangeWithSignal[] {
47
+ ): asserts ranges is RangeWithSignal[] {
49
48
  for (let range of ranges) {
50
49
  if (!range.signals) throw new Error('range has not signals');
51
50
  }
@@ -78,7 +77,15 @@ export function rangesToXY(ranges: NMRRange[], options: any = {}) {
78
77
 
79
78
  let spectrum: DoubleArray = new Float64Array(nbPoints);
80
79
  for (const range of ranges) {
81
- const { integration, signals } = range;
80
+ const { integration, signals = [] } = range;
81
+ const { multiplicity: rangeMulplicity = '' } = range;
82
+ if (rangeMulplicity === 'm' && signals.length < 1) {
83
+ const { from, to } = range;
84
+ signals.push({
85
+ delta: (from + to) / 2,
86
+ multiplicity: 'm',
87
+ });
88
+ }
82
89
  let rangeSpectrum: DoubleArray = new Float64Array(nbPoints);
83
90
  for (const signal of signals) {
84
91
  const { multiplicity } = signal;
@@ -168,8 +175,8 @@ function normalizeSpectrum(
168
175
  0,
169
176
  );
170
177
 
171
- const norma = (integration / sum) * 1e6;
172
178
  if (sum !== 0) {
179
+ const norma = (integration / sum) * 1e6;
173
180
  for (let i = 0; i < spectrum.length; i++) {
174
181
  spectrum[i] *= norma;
175
182
  }
@@ -3,7 +3,7 @@ import type { XYNumber } from 'spectrum-generator';
3
3
 
4
4
  import type { NMRSignal2D } from '../types/NMRSignal2D';
5
5
 
6
- interface signals2DToZOptions {
6
+ interface Signals2DToZOptions {
7
7
  /**
8
8
  * lower limit in the spectrum, if it is a number the value will be defined for both axes
9
9
  * @default -1
@@ -36,7 +36,7 @@ export interface Peak2DSeries {
36
36
 
37
37
  export function signals2DToZ(
38
38
  signals: NMRSignal2D[],
39
- options: signals2DToZOptions = {},
39
+ options: Signals2DToZOptions = {},
40
40
  ) {
41
41
  let { from = -1, to = 12, nbPoints = 512, width = 0.02 } = options;
42
42
 
@@ -1,6 +1,6 @@
1
1
  import rescale from 'ml-array-rescale';
2
2
  import arraySequentialFill from 'ml-array-sequential-fill';
3
- import type { Shape1DOptions } from 'spectrum-generator';
3
+ import type { Shape1D } from 'ml-peak-shape-generator';
4
4
 
5
5
  import type { MakeMandatory } from '../types/MakeMandatory';
6
6
  import type { NMRSignal1D } from '../types/NMRSignal1D';
@@ -25,7 +25,7 @@ export interface OptionsSignalsToXY {
25
25
  /**
26
26
  * Shape options for ml-spectrum-generator
27
27
  */
28
- shape?: Shape1DOptions;
28
+ shape?: Shape1D;
29
29
  /**
30
30
  * The linewidth of the output spectrum, expresed in Hz.
31
31
  * @default 1
@@ -1,9 +1,10 @@
1
1
  import binarySearch from 'binary-search';
2
+ import { DataXY } from 'cheminfo-types';
2
3
  import { Matrix, EVD } from 'ml-matrix';
3
4
  import type { Matrix as MatrixClassType } from 'ml-matrix';
5
+ import type { Shape1D } from 'ml-peak-shape-generator';
4
6
  import { SparseMatrix } from 'ml-sparse-matrix';
5
7
  import { SpectrumGenerator } from 'spectrum-generator';
6
- import type { Shape1DOptions } from 'spectrum-generator';
7
8
 
8
9
  import type { SpinSystem } from '../../types/spinSystem';
9
10
 
@@ -46,7 +47,7 @@ interface Simulate1DOptions {
46
47
  * Shape options
47
48
  * @default {kind:'gaussian'}
48
49
  */
49
- shape?: Shape1DOptions;
50
+ shape?: Shape1D;
50
51
  }
51
52
 
52
53
  /**
@@ -59,7 +60,7 @@ export default function simulate1D(
59
60
  */
60
61
  spinSystem: SpinSystem,
61
62
  options: Simulate1DOptions = {},
62
- ) {
63
+ ): DataXY {
63
64
  let {
64
65
  lineWidth = 1,
65
66
  maxClusterSize = 8,
@@ -1,11 +1,5 @@
1
- export interface NMRPeak1D {
1
+ import type { Peak1D } from 'ml-gsd';
2
+
3
+ export interface NMRPeak1D extends Peak1D {
2
4
  kind?: string;
3
- x: number;
4
- y: number;
5
- shape: {
6
- width: number;
7
- noiseLevel?: number;
8
- soft?: boolean;
9
- kind?: string;
10
- };
11
5
  }
@@ -3,6 +3,7 @@ import type { NMRSignal1D } from './NMRSignal1D';
3
3
  export interface NMRRange {
4
4
  from: number;
5
5
  to: number;
6
+ id?: string;
6
7
  diaIDs?: string[];
7
8
  kind?: string;
8
9
  pubIntegral?: number;
@@ -3,6 +3,7 @@ import type { Jcoupling } from './jcoupling';
3
3
 
4
4
  export interface NMRSignal1D {
5
5
  delta: number;
6
+ id?: string;
6
7
  js?: Jcoupling[];
7
8
  atoms?: number[];
8
9
  assignment?: string;
@@ -6,15 +6,15 @@ export interface Signal2DAxisData {
6
6
  resolution?: number;
7
7
  atoms?: number[];
8
8
  diaIDs?: string[];
9
- fromTo?: {
10
- from: number;
11
- to: number
12
- };
9
+ from: number;
10
+ to: number;
13
11
  }
14
12
  export interface NMRSignal2D {
15
13
  x: Signal2DAxisData;
16
14
  y: Signal2DAxisData;
15
+ id?: string;
17
16
  peaks?: MPFPeak[];
18
17
  kind?: string;
18
+ //eslint-disable-next-line
19
19
  _highlight?: (number | string)[];
20
20
  }
@@ -1,9 +1,10 @@
1
1
  import type { NMRSignal2D } from "./NMRSignal2D";
2
2
 
3
- interface fromTo { from: number, to: number }
3
+ interface FromTo { from: number, to: number }
4
4
 
5
5
  export interface NMRZone {
6
- x: fromTo,
7
- y: fromTo,
6
+ x: FromTo,
7
+ y: FromTo,
8
+ id?: string;
8
9
  signals: NMRSignal2D
9
10
  }
@@ -9,7 +9,7 @@ declare module 'ml-spectra-processing' {
9
9
  options?: { zones: { from: number; to: number }[] },
10
10
  ): XYNumberArray;
11
11
 
12
- interface xNoiseSanPlotOptions {
12
+ interface XNoiseSanPlotOptions {
13
13
  mask?: boolean[];
14
14
  cutOff?: number;
15
15
  logBaseY?: number;
@@ -20,7 +20,7 @@ declare module 'ml-spectra-processing' {
20
20
  fixOffset?: boolean;
21
21
  }
22
22
 
23
- interface xNoiseSanPlotResult {
23
+ interface XNoiseSanPlotResult {
24
24
  positive: number;
25
25
  negative: number;
26
26
  snr: number;
@@ -31,21 +31,21 @@ declare module 'ml-spectra-processing' {
31
31
  }
32
32
  function xNoiseSanPlot(
33
33
  data: number[] | Float64Array,
34
- options?: xNoiseSanPlotOptions,
35
- ): xNoiseSanPlotResult;
34
+ options?: XNoiseSanPlotOptions,
35
+ ): XNoiseSanPlotResult;
36
36
 
37
37
  function xAbsoluteMedian(data: number[] | Float64Array): number;
38
38
 
39
- interface xGetFromToIndexOptions {
39
+ interface XGetFromToIndexOptions {
40
40
  fromIndex?: number;
41
41
  toIndex?: number;
42
42
  from?: number;
43
43
  to?: number;
44
44
  }
45
45
 
46
- interface xyIntegrationOptions extends xGetFromToIndexOptions {}
46
+ interface XYIntegrationOptions extends XGetFromToIndexOptions {}
47
47
 
48
- function xyIntegration(data: XYNumberArray, options?: xyIntegrationOptions): number;
48
+ function xyIntegration(data: XYNumberArray, options?: XYIntegrationOptions): number;
49
49
 
50
- function xGetFromToIndex(x: number[] | Float64Array, options?: xGetFromToIndexOptions): number;
50
+ function xGetFromToIndex(x: number[] | Float64Array, options?: XGetFromToIndexOptions): number;
51
51
  }
@@ -0,0 +1,18 @@
1
+ declare module 'ml-tree-set' {
2
+ type Comparator = (a: Elements, b: Elements) => number;
3
+ type Elements = any;
4
+ export default class TreeSet {
5
+ public length: number;
6
+ public elements: Array<Elements>;
7
+
8
+ public constructor(comparator: Comparator);
9
+
10
+ public size: () => number;
11
+ public last: () => Elements;
12
+ public first: () => Elements;
13
+ public isEmpty: () => boolean;
14
+ public pollLast: () => void;
15
+ public pollFirst: () => void;
16
+ public add(element: Elements): () => void;
17
+ }
18
+ }
@@ -110,7 +110,7 @@ declare module 'openchemlib-utils' {
110
110
 
111
111
  function getHoseCodesForPath(molecule: Molecule, from: string, to: string, maxLength: number): HoseCodesForPath;
112
112
 
113
- export interface getConnectivityMatrixOptions {
113
+ export interface GetConnectivityMatrixOptions {
114
114
  /**
115
115
  * get the path length between atoms
116
116
  * @default false
@@ -142,7 +142,7 @@ declare module 'openchemlib-utils' {
142
142
  */
143
143
  stda?: boolean | number;
144
144
  }
145
- function getConnectivityMatrix(molecule: Molecule, options?: getConnectivityMatrixOptions): number[][] | Float64Array[];
145
+ function getConnectivityMatrix(molecule: Molecule, options?: GetConnectivityMatrixOptions): number[][] | Float64Array[];
146
146
 
147
147
  function getDiastereotopicAtomIDs(molecule: Molecule): string[];
148
148
  }