nmr-processing 9.3.0 → 9.3.1-pre.1669649322

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 (85) hide show
  1. package/lib/apodization/shapes/WindowFunctions.d.ts +1 -1
  2. package/lib/assignment/get13CAssignments.d.ts +1 -1
  3. package/lib/assignment/get1HAssignments.d.ts +3 -3
  4. package/lib/assignment/getAssignments.d.ts +2 -2
  5. package/lib/assignment/nmrAssigment.d.ts +3 -3
  6. package/lib/assignment/utils/createMapPossibleAssignments.d.ts +1 -1
  7. package/lib/assignment/utils/getAssignment/buildAssignments.d.ts +4 -4
  8. package/lib/assignment/utils/getAssignment/formatData.d.ts +1 -1
  9. package/lib/peaks/peaksFilterImpurities.d.ts +1 -1
  10. package/lib/peaks/peaksToRanges.d.ts +1 -1
  11. package/lib/peaks/peaksToRanges.js +20 -19
  12. package/lib/peaks/peaksToRanges.js.map +1 -1
  13. package/lib/peaks/util/convertWidth.d.ts +1 -1
  14. package/lib/peaks/util/convertWidthToHz.d.ts +1 -1
  15. package/lib/prediction/Prediction1D.d.ts +1 -1
  16. package/lib/prediction/dataStructure.d.ts +1 -1
  17. package/lib/prediction/predictAll.d.ts +1 -1
  18. package/lib/prediction/predictAll.js +4 -1
  19. package/lib/prediction/predictAll.js.map +1 -1
  20. package/lib/prediction/predictAllSpectra.d.ts +1 -1
  21. package/lib/prediction/predictCOSY.d.ts +1 -1
  22. package/lib/prediction/predictCarbon.d.ts +6 -2
  23. package/lib/prediction/predictCarbon.js +5 -4
  24. package/lib/prediction/predictCarbon.js.map +1 -1
  25. package/lib/prediction/predictHMBC.d.ts +1 -1
  26. package/lib/prediction/predictHSQC.d.ts +1 -1
  27. package/lib/prediction/predictProton.d.ts +6 -2
  28. package/lib/prediction/predictProton.js +1 -1
  29. package/lib/prediction/predictProton.js.map +1 -1
  30. package/lib/prediction/utils/fetchPrediction.d.ts +1 -1
  31. package/lib/prediction/utils/getFilteredIDiaIDs.d.ts +3 -4
  32. package/lib/prediction/utils/getFilteredIDiaIDs.js +5 -6
  33. package/lib/prediction/utils/getFilteredIDiaIDs.js.map +1 -1
  34. package/lib/prediction/utils/getPredictions.d.ts +1 -1
  35. package/lib/prediction/utils/predict2D.d.ts +6 -2
  36. package/lib/prediction/utils/predict2D.js +3 -3
  37. package/lib/prediction/utils/predict2D.js.map +1 -1
  38. package/lib/signals/optimization/getInternalSignals.d.ts +3 -3
  39. package/lib/signals/optimization/getSumOfShapes.d.ts +1 -1
  40. package/lib/signals/optimizeSignals.d.ts +1 -1
  41. package/lib/signals/signalsJoin.d.ts +3 -3
  42. package/lib/signals/signalsToRanges.d.ts +1 -1
  43. package/lib/signals/utils/jAnalyzer.d.ts +2 -2
  44. package/lib/utilities/MakeMandatory.d.ts +1 -1
  45. package/lib/utilities/getFrequency.d.ts +1 -1
  46. package/lib/utilities/hasProperty.d.ts +1 -1
  47. package/lib/xy/xyAutoPeaksPicking.d.ts +1 -1
  48. package/lib/xy/xyAutoPeaksPicking.js +4 -1
  49. package/lib/xy/xyAutoPeaksPicking.js.map +1 -1
  50. package/lib/xyz/xyzAutoZonesPicking.d.ts +2 -2
  51. package/lib-esm/peaks/peaksToRanges.js +20 -19
  52. package/lib-esm/peaks/peaksToRanges.js.map +1 -1
  53. package/lib-esm/prediction/predictAll.js +4 -1
  54. package/lib-esm/prediction/predictAll.js.map +1 -1
  55. package/lib-esm/prediction/predictCarbon.js +5 -4
  56. package/lib-esm/prediction/predictCarbon.js.map +1 -1
  57. package/lib-esm/prediction/predictProton.js +1 -1
  58. package/lib-esm/prediction/predictProton.js.map +1 -1
  59. package/lib-esm/prediction/utils/getFilteredIDiaIDs.js +6 -7
  60. package/lib-esm/prediction/utils/getFilteredIDiaIDs.js.map +1 -1
  61. package/lib-esm/prediction/utils/predict2D.js +4 -4
  62. package/lib-esm/prediction/utils/predict2D.js.map +1 -1
  63. package/lib-esm/xy/xyAutoPeaksPicking.js +4 -1
  64. package/lib-esm/xy/xyAutoPeaksPicking.js.map +1 -1
  65. package/package.json +7 -7
  66. package/src/assignment/get13CAssignments.ts +1 -1
  67. package/src/assignment/get1HAssignments.ts +1 -1
  68. package/src/assignment/getAssignments.ts +1 -1
  69. package/src/assignment/utils/getAssignment/buildAssignments.ts +1 -1
  70. package/src/openchemlib-utils.d.ts +6 -1
  71. package/src/peaks/peaksToRanges.ts +23 -19
  72. package/src/prediction/Prediction1D.ts +1 -1
  73. package/src/prediction/predictAll.ts +5 -3
  74. package/src/prediction/predictAllSpectra.ts +1 -1
  75. package/src/prediction/predictCOSY.ts +1 -1
  76. package/src/prediction/predictCarbon.ts +17 -9
  77. package/src/prediction/predictHMBC.ts +1 -1
  78. package/src/prediction/predictHSQC.ts +1 -1
  79. package/src/prediction/predictProton.ts +6 -2
  80. package/src/prediction/utils/fetchPrediction.ts +1 -1
  81. package/src/prediction/utils/getFilteredIDiaIDs.ts +13 -13
  82. package/src/prediction/utils/getPredictions.ts +1 -1
  83. package/src/prediction/utils/predict2D.ts +12 -6
  84. package/src/utilities/hasProperty.ts +1 -1
  85. package/src/xy/xyAutoPeaksPicking.ts +5 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nmr-processing",
3
- "version": "9.3.0",
3
+ "version": "9.3.1-pre.1669649322",
4
4
  "description": "Pure functions allowing to process NMR spectra.",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -38,20 +38,20 @@
38
38
  },
39
39
  "homepage": "https://github.com/cheminfo/nmr-processing#readme",
40
40
  "devDependencies": {
41
- "@types/jest": "^29.2.2",
41
+ "@types/jest": "^29.2.3",
42
42
  "cheminfo-build": "^1.1.11",
43
43
  "cheminfo-types": "^1.4.0",
44
- "eslint": "^8.27.0",
44
+ "eslint": "^8.28.0",
45
45
  "eslint-config-cheminfo-typescript": "^11.2.2",
46
46
  "jest": "^29.3.1",
47
47
  "jest-matcher-deep-close-to": "^3.0.2",
48
48
  "md5": "^2.3.0",
49
49
  "nmr-xy-testdata": "^0.5.1",
50
50
  "openchemlib": "^8.0.1",
51
- "prettier": "^2.7.1",
51
+ "prettier": "^2.8.0",
52
52
  "rimraf": "^3.0.2",
53
53
  "ts-jest": "^29.0.3",
54
- "typescript": "^4.8.4"
54
+ "typescript": "^4.9.3"
55
55
  },
56
56
  "dependencies": {
57
57
  "@lukeed/uuid": "^2.0.0",
@@ -77,7 +77,7 @@
77
77
  "ml-spectra-processing": "^11.14.0",
78
78
  "ml-tree-set": "^0.1.1",
79
79
  "nmr-correlation": "^2.3.3",
80
- "openchemlib-utils": "^2.0.0",
81
- "spectrum-generator": "^8.0.4"
80
+ "openchemlib-utils": "2.1.1-pre.1669644163",
81
+ "spectrum-generator": "^8.0.6"
82
82
  }
83
83
  }
@@ -1,5 +1,5 @@
1
1
  import { v4 as generateID } from '@lukeed/uuid';
2
- import { Molecule } from 'openchemlib';
2
+ import { Molecule } from 'openchemlib/full';
3
3
  import { addDiastereotopicMissingChirality } from 'openchemlib-utils';
4
4
 
5
5
  import { NMRRange, NMRRangeWithIntegration } from '..';
@@ -1,5 +1,5 @@
1
1
  import { v4 as generateID } from '@lukeed/uuid';
2
- import { Molecule } from 'openchemlib';
2
+ import { Molecule } from 'openchemlib/full';
3
3
  import { addDiastereotopicMissingChirality } from 'openchemlib-utils';
4
4
 
5
5
  import { NMRRange } from '..';
@@ -1,4 +1,4 @@
1
- import { Molecule } from 'openchemlib';
1
+ import { Molecule } from 'openchemlib/full';
2
2
  import { addDiastereotopicMissingChirality } from 'openchemlib-utils';
3
3
 
4
4
  import { NMRSignal1D } from '..';
@@ -1,6 +1,6 @@
1
1
  import TreeSet from 'ml-tree-set';
2
2
  import { Values } from 'nmr-correlation';
3
- import { Molecule } from 'openchemlib';
3
+ import { Molecule } from 'openchemlib/full';
4
4
  import { getConnectivityMatrix } from 'openchemlib-utils';
5
5
 
6
6
  import {
@@ -1,5 +1,5 @@
1
1
  declare module 'openchemlib-utils' {
2
- import { Molecule } from 'openchemlib';
2
+ import { Molecule } from 'openchemlib/full';
3
3
 
4
4
  export interface GroupDiastereotopicAtomIDs {
5
5
  counter: number;
@@ -7,10 +7,13 @@ declare module 'openchemlib-utils' {
7
7
  oclID: string;
8
8
  atomLabel: string;
9
9
  }
10
+
10
11
  export type GroupedDiastereotopicAtomIDs = GroupDiastereotopicAtomIDs[];
11
12
  function getGroupedDiastereotopicAtomIDs(
12
13
  molecule: Molecule,
14
+ options?: { atomLabel: string }
13
15
  ): GroupedDiastereotopicAtomIDs;
16
+
14
17
  interface GetHoseCodesForAtomOptions {
15
18
  minSphereSize?: number;
16
19
  maxSphereSize?: number;
@@ -155,4 +158,6 @@ declare module 'openchemlib-utils' {
155
158
  ): number[][] | Float64Array[];
156
159
 
157
160
  function getDiastereotopicAtomIDs(molecule: Molecule): string[];
161
+
162
+ function groupDiasterotopicAtomIDs(diaIDs: string[], molecule: Molecule, options?: { atomLabel: string }): GroupedDiastereotopicAtomIDs
158
163
  }
@@ -206,17 +206,7 @@ export function peaksToRanges(
206
206
  }
207
207
  }
208
208
  // it was a updateIntegrals function.
209
- let sumIntegral = 0;
210
- let sumObserved = 0;
211
- for (const signal of signals) {
212
- sumObserved += Math.abs(Math.round(signal.integralData.value));
213
- }
214
- if (sumObserved !== integrationSum) {
215
- sumIntegral = integrationSum / sumObserved;
216
- for (const signal of signals) {
217
- signal.integralData.value *= sumIntegral;
218
- }
219
- }
209
+ updateIntegration(signals, integrationSum);
220
210
  }
221
211
 
222
212
  signals.sort((a, b) => {
@@ -230,6 +220,7 @@ export function peaksToRanges(
230
220
  }
231
221
  }
232
222
  }
223
+
233
224
  let ranges: NMRRange[] = [];
234
225
  for (let i = 0; i < signals.length; i++) {
235
226
  let signal = signals[i];
@@ -243,7 +234,6 @@ export function peaksToRanges(
243
234
  delta: signal.delta,
244
235
  kind: signal.kind || 'signal',
245
236
  multiplicity: signal.multiplicity,
246
- integration: signal.integralData.value,
247
237
  };
248
238
  if (keepPeaks) {
249
239
  signalResult.peaks = signal.peaks.map((peak) => {
@@ -299,7 +289,7 @@ export function detectSignals(
299
289
  let peaks;
300
290
  let signals = [];
301
291
  let prevPeak = { x: Number.MIN_SAFE_INTEGER };
302
- let spectrumIntegral = 0;
292
+
303
293
  frequencyCluster /= frequency;
304
294
  for (const peak of peakList) {
305
295
  if (Math.abs(peak.x - prevPeak.x) > frequencyCluster) {
@@ -349,15 +339,10 @@ export function detectSignals(
349
339
  } else {
350
340
  integration.value = integralPeaks;
351
341
  }
352
- spectrumIntegral += integration.value;
353
342
  }
354
343
 
355
344
  if (integrationSum > 0) {
356
- let integralFactor = integrationSum / spectrumIntegral;
357
- for (let signal of signals) {
358
- let integration = signal.integralData;
359
- integration.value *= integralFactor;
360
- }
345
+ updateIntegration(signals, integrationSum);
361
346
  }
362
347
 
363
348
  return signals;
@@ -370,3 +355,22 @@ export function detectSignals(
370
355
  function computeArea(peak: Peak1DIntern, frequency: number) {
371
356
  return Math.abs(((peak.intensity * peak.width) / frequency) * 1.57); // todo add an option with this value: 1.772453851
372
357
  }
358
+
359
+ /**
360
+ * update the integration Values
361
+ * @param signals
362
+ * @param integrationSum
363
+ */
364
+ function updateIntegration(signals: SignalIntern[], integrationSum: number) {
365
+ let sumIntegral = 0;
366
+ let sumObserved = 0;
367
+ for (const signal of signals) {
368
+ sumObserved += Math.abs(Math.round(signal.integralData.value));
369
+ }
370
+ if (sumObserved !== integrationSum) {
371
+ sumIntegral = integrationSum / sumObserved;
372
+ for (const signal of signals) {
373
+ signal.integralData.value *= sumIntegral;
374
+ }
375
+ }
376
+ }
@@ -1,4 +1,4 @@
1
- import type { Molecule } from 'openchemlib';
1
+ import type { Molecule } from 'openchemlib/full';
2
2
 
3
3
  import type { NMRSignal1D } from '../signals/NMRSignal1D';
4
4
  import type { NMRRange } from '../xy/NMRRange';
@@ -1,5 +1,5 @@
1
- import type { Molecule } from 'openchemlib';
2
-
1
+ import type { Molecule } from 'openchemlib/full';
2
+ import { getDiastereotopicAtomIDs, getGroupedDiastereotopicAtomIDs } from 'openchemlib-utils';
3
3
  import type { Prediction1D } from './Prediction1D';
4
4
  import { predictCOSY } from './predictCOSY';
5
5
  import { predictCarbon, PredictCarbonOptions } from './predictCarbon';
@@ -75,6 +75,8 @@ export async function predictAll(
75
75
  predictOptions = {},
76
76
  } = options;
77
77
 
78
+ const diaIDs = getDiastereotopicAtomIDs(molecule);
79
+ console.log('entra correction')
78
80
  const xPrediction = await getPredictions(
79
81
  from,
80
82
  molecule,
@@ -100,7 +102,7 @@ export async function predictAll(
100
102
  C: yPrediction,
101
103
  };
102
104
 
103
- const { molfile, diaIDs } = xPrediction;
105
+ const { molfile } = xPrediction;
104
106
 
105
107
  const spectra: any = {
106
108
  proton: predictions.H,
@@ -1,5 +1,5 @@
1
1
  import { FromTo, PointXY } from 'cheminfo-types';
2
- import type { Molecule } from 'openchemlib';
2
+ import type { Molecule } from 'openchemlib/full';
3
3
 
4
4
  import { signals2DToZ } from '../signals/signals2DToZ';
5
5
  import { OptionsSignalsToXY, signalsToXY } from '../signals/signalsToXY';
@@ -1,4 +1,4 @@
1
- import { Molecule } from 'openchemlib';
1
+ import { Molecule } from 'openchemlib/full';
2
2
 
3
3
  import type { Prediction1D } from './Prediction1D';
4
4
  import { predictProton, PredictProtonOptions } from './predictProton';
@@ -1,6 +1,6 @@
1
1
  import { v4 as generateID } from '@lukeed/uuid';
2
2
  import fetch from 'cross-fetch';
3
- import type { Molecule } from 'openchemlib';
3
+ import type { Molecule } from 'openchemlib/full';
4
4
 
5
5
  import { setIDs } from '../peaks/util/setIDs';
6
6
  import type { NMRSignal1D } from '../signals/NMRSignal1D';
@@ -13,6 +13,7 @@ import { fetchPrediction } from './utils/fetchPrediction';
13
13
  import { flatGroupedDiaIDs } from './utils/flatGroupedDiaIDs';
14
14
  import { getFilteredIDiaIDs } from './utils/getFilteredIDiaIDs';
15
15
  import { Prediction, queryByHose } from './utils/queryByHOSE';
16
+ import { getDiastereotopicAtomIDs } from 'openchemlib-utils';
16
17
 
17
18
  const cache: { [key: string]: DataBaseStructure } = {};
18
19
 
@@ -48,6 +49,10 @@ export interface PredictCarbonOptions {
48
49
  * @default 'maximum level in the database'
49
50
  */
50
51
  maxSphereSize?: number;
52
+ /**
53
+ * diastereotopic atom ids.
54
+ */
55
+ diaIDs?: string[];
51
56
  }
52
57
 
53
58
  export type PredictCarbon = typeof predictCarbon;
@@ -72,7 +77,12 @@ export async function predictCarbon(
72
77
  molecule: Molecule,
73
78
  options: PredictCarbonOptions = {},
74
79
  ): Promise<Prediction1D> {
75
- let { url, database, webserviceURL } = options;
80
+ let {
81
+ url,
82
+ database,
83
+ webserviceURL,
84
+ diaIDs = getDiastereotopicAtomIDs(molecule),
85
+ } = options;
76
86
 
77
87
  if (webserviceURL) {
78
88
  return fetchPrediction(molecule, { webserviceURL });
@@ -90,12 +100,10 @@ export async function predictCarbon(
90
100
 
91
101
  if (maxSphereSize > maxLevel) maxSphereSize = maxLevel;
92
102
 
93
- const { groupedDiaIDs, carbonDiaIDs, molfile } = getFilteredIDiaIDs(
94
- molecule,
95
- {
96
- maxSphereSize,
97
- },
98
- );
103
+ const { carbonDiaIDs, molfile } = getFilteredIDiaIDs(molecule, {
104
+ maxSphereSize,
105
+ diaIDs,
106
+ });
99
107
 
100
108
  let predictions = queryByHose(carbonDiaIDs, database, {
101
109
  maxSphereSize,
@@ -106,7 +114,7 @@ export async function predictCarbon(
106
114
  return {
107
115
  molfile,
108
116
  nucleus: '13C',
109
- diaIDs: flatGroupedDiaIDs(groupedDiaIDs),
117
+ diaIDs,
110
118
  joinedSignals,
111
119
  signals,
112
120
  ranges: signalsToRanges(joinedSignals),
@@ -1,4 +1,4 @@
1
- import { Molecule } from 'openchemlib';
1
+ import { Molecule } from 'openchemlib/full';
2
2
 
3
3
  import type { Prediction1D } from './Prediction1D';
4
4
  import { predictCarbon } from './predictCarbon';
@@ -1,4 +1,4 @@
1
- import { Molecule } from 'openchemlib';
1
+ import { Molecule } from 'openchemlib/full';
2
2
 
3
3
  import type { Prediction1D } from './Prediction1D';
4
4
  import { predictCarbon, PredictCarbonOptions } from './predictCarbon';
@@ -1,7 +1,7 @@
1
1
  import { v4 as generateID } from '@lukeed/uuid';
2
2
  import fetch from 'cross-fetch';
3
3
  import FormData from 'form-data';
4
- import type { Molecule } from 'openchemlib';
4
+ import type { Molecule } from 'openchemlib/full';
5
5
  import {
6
6
  addDiastereotopicMissingChirality,
7
7
  getConnectivityMatrix,
@@ -24,6 +24,10 @@ export interface PredictProtonOptions {
24
24
  * A callback receiving a molfile and the result
25
25
  */
26
26
  cache?: (molfile: string, result?: string) => void | string | undefined;
27
+ /**
28
+ * diastereotopic atom ids.
29
+ */
30
+ diaIDs?: string[];
27
31
  }
28
32
 
29
33
  export type PredictProton = typeof predictProton;
@@ -56,7 +60,7 @@ export async function predictProton(
56
60
  }
57
61
  }
58
62
 
59
- const diaIDs = getDiastereotopicAtomIDs(molecule);
63
+ const { diaIDs = getDiastereotopicAtomIDs(molecule) } = options;
60
64
  const signals = protonParser(result, molecule, diaIDs);
61
65
  const joinedSignals = signalsJoin(signals);
62
66
  return {
@@ -1,5 +1,5 @@
1
1
  import { fetch } from 'cross-fetch';
2
- import { Molecule } from 'openchemlib';
2
+ import { Molecule } from 'openchemlib/full';
3
3
 
4
4
  import type { Prediction1D } from '../Prediction1D';
5
5
 
@@ -1,8 +1,9 @@
1
- import type { Molecule } from 'openchemlib';
1
+ import type { Molecule } from 'openchemlib/full';
2
2
  import {
3
3
  getGroupedDiastereotopicAtomIDs,
4
4
  getHoseCodesFromDiastereotopicID,
5
5
  addDiastereotopicMissingChirality,
6
+ groupDiasterotopicAtomIDs,
6
7
  } from 'openchemlib-utils';
7
8
  import type { GroupDiastereotopicAtomIDs } from 'openchemlib-utils';
8
9
 
@@ -14,9 +15,9 @@ export type GroupedDiaIDsWithHose = GroupDiaIDsWithHose[];
14
15
 
15
16
  export function getFilteredIDiaIDs(
16
17
  molecule: Molecule,
17
- options: { maxSphereSize: number },
18
+ options: { maxSphereSize: number; diaIDs: string[] },
18
19
  ) {
19
- const { maxSphereSize } = options;
20
+ const { maxSphereSize, diaIDs } = options;
20
21
 
21
22
  molecule.addImplicitHydrogens();
22
23
  molecule.addMissingChirality();
@@ -24,16 +25,16 @@ export function getFilteredIDiaIDs(
24
25
 
25
26
  const molfile = molecule.toMolfile();
26
27
 
27
- let groupedDiaIDs = getGroupedDiastereotopicAtomIDs(molecule);
28
+ let groupedDiaIDs = groupDiasterotopicAtomIDs(diaIDs, molecule, {
29
+ atomLabel: 'C',
30
+ });
28
31
 
29
- let carbonDiaIDs = groupedDiaIDs
30
- .filter((e) => e.atomLabel === 'C')
31
- .sort((a, b) => {
32
- if (a.atomLabel === b.atomLabel) {
33
- return b.counter - a.counter;
34
- }
35
- return a.atomLabel < b.atomLabel ? 1 : -1;
36
- }) as any;
32
+ let carbonDiaIDs = groupedDiaIDs.sort((a, b) => {
33
+ if (a.atomLabel === b.atomLabel) {
34
+ return b.counter - a.counter;
35
+ }
36
+ return a.atomLabel < b.atomLabel ? 1 : -1;
37
+ }) as any;
37
38
 
38
39
  const OCL = molecule.getOCL();
39
40
  for (const diaId of carbonDiaIDs) {
@@ -48,7 +49,6 @@ export function getFilteredIDiaIDs(
48
49
  let toReturn = {
49
50
  molfile,
50
51
  carbonDiaIDs: carbonDiaIDs as GroupedDiaIDsWithHose,
51
- groupedDiaIDs,
52
52
  };
53
53
 
54
54
  return toReturn;
@@ -1,4 +1,4 @@
1
- import type { Molecule } from 'openchemlib';
1
+ import type { Molecule } from 'openchemlib/full';
2
2
 
3
3
  import type { Prediction1D } from '../Prediction1D';
4
4
 
@@ -1,10 +1,11 @@
1
1
  import { v4 as generateID } from '@lukeed/uuid';
2
2
  import { agnes, Cluster } from 'ml-hclust';
3
3
  import { Matrix } from 'ml-matrix';
4
- import { Molecule } from 'openchemlib';
4
+ import { Molecule } from 'openchemlib/full';
5
5
  import {
6
6
  getGroupedDiastereotopicAtomIDs,
7
7
  getPathsInfo,
8
+ groupDiasterotopicAtomIDs,
8
9
  } from 'openchemlib-utils';
9
10
  import type {
10
11
  AtomInfo,
@@ -86,6 +87,10 @@ export interface Predict2DOptions {
86
87
  * @default false
87
88
  */
88
89
  includeDiagonal?: boolean;
90
+ /**
91
+ * diastereotopic atom ids of the molecule.
92
+ */
93
+ diaIDs?: string[];
89
94
  }
90
95
 
91
96
  export interface PredictOptions {
@@ -125,9 +130,12 @@ export async function predict2D(
125
130
  ) {
126
131
  checkFromTo(options);
127
132
 
133
+ molecule.addImplicitHydrogens();
134
+
128
135
  let {
129
136
  from,
130
137
  to,
138
+ diaIDs,
131
139
  minLength = 0,
132
140
  maxLength,
133
141
  predictOptions = {},
@@ -137,10 +145,6 @@ export async function predict2D(
137
145
  includeDiagonal = false,
138
146
  } = options;
139
147
 
140
- molecule.addImplicitHydrogens();
141
-
142
- let diaIDs = getGroupedDiastereotopicAtomIDs(molecule);
143
-
144
148
  const pathsInfo = getPathsInfo(molecule, {
145
149
  fromLabel: from,
146
150
  toLabel: to,
@@ -148,8 +152,10 @@ export async function predict2D(
148
152
  maxLength,
149
153
  });
150
154
 
155
+ const groupedDiaIDS = diaIDs ? groupDiasterotopicAtomIDs(diaIDs, molecule) : getGroupedDiastereotopicAtomIDs(molecule)
156
+
151
157
  let diaIDswithAtomInfo: GroupDiastereotopicAtomIDsWithAtomInfo[] = [];
152
- for (let diaID of diaIDs) {
158
+ for (let diaID of groupedDiaIDS) {
153
159
  diaIDswithAtomInfo.push({
154
160
  ...diaID,
155
161
  pathInfo: JSON.parse(
@@ -1,4 +1,4 @@
1
- export function hasProperty<T, K extends keyof T>(
1
+ export function hasProperty<T extends object, K extends keyof T>(
2
2
  data: T,
3
3
  key: K,
4
4
  ): data is T & { [P in K]-?: T[P] } {
@@ -106,7 +106,11 @@ export function xyAutoPeaksPicking(
106
106
  direction = 'positive',
107
107
  } = options;
108
108
 
109
- const { windowSize = 9, polynomial = 3 } = sgOptions;
109
+ let pointsPerHz = 1 / frequency / (data.x[1] - data.x[0]);
110
+ // we can consider a peak with of 0.5 Hz for the windowSize
111
+ let ws = Math.max(Math.round(pointsPerHz / 2), 5);
112
+
113
+ const { windowSize = ws - (ws % 2) + 1, polynomial = 3 } = sgOptions;
110
114
 
111
115
  if (data.x.length < windowSize) return [];
112
116