nmr-processing 9.9.2 → 10.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 (136) hide show
  1. package/lib/assignment/get13CAssignments.js +7 -4
  2. package/lib/assignment/get13CAssignments.js.map +1 -1
  3. package/lib/assignment/get1HAssignments.js +7 -5
  4. package/lib/assignment/get1HAssignments.js.map +1 -1
  5. package/lib/assignment/utils/generalAssignment/buildAssignments.d.ts +3 -1
  6. package/lib/assignment/utils/generalAssignment/buildAssignments.js +18 -7
  7. package/lib/assignment/utils/generalAssignment/buildAssignments.js.map +1 -1
  8. package/lib/index.d.ts +2 -7
  9. package/lib/index.js +2 -7
  10. package/lib/index.js.map +1 -1
  11. package/lib/prediction/GroupDiastereotopicAtomIDs.d.ts +6 -0
  12. package/lib/prediction/GroupDiastereotopicAtomIDs.js +3 -0
  13. package/lib/prediction/GroupDiastereotopicAtomIDs.js.map +1 -0
  14. package/lib/prediction/Prediction1D.d.ts +2 -7
  15. package/lib/prediction/Prediction2D.d.ts +2 -7
  16. package/lib/prediction/PredictionBase1D.d.ts +8 -0
  17. package/lib/prediction/PredictionBase1D.js +3 -0
  18. package/lib/prediction/PredictionBase1D.js.map +1 -0
  19. package/lib/prediction/PredictionBase2D.d.ts +8 -0
  20. package/lib/prediction/PredictionBase2D.js +3 -0
  21. package/lib/prediction/PredictionBase2D.js.map +1 -0
  22. package/lib/prediction/predict.d.ts +55 -0
  23. package/lib/prediction/predict.js +113 -0
  24. package/lib/prediction/predict.js.map +1 -0
  25. package/lib/prediction/predictCOSY.d.ts +15 -13
  26. package/lib/prediction/predictCOSY.js +3 -6
  27. package/lib/prediction/predictCOSY.js.map +1 -1
  28. package/lib/prediction/predictCarbon.d.ts +12 -4
  29. package/lib/prediction/predictCarbon.js +10 -16
  30. package/lib/prediction/predictCarbon.js.map +1 -1
  31. package/lib/prediction/predictHMBC.d.ts +16 -25
  32. package/lib/prediction/predictHMBC.js +3 -7
  33. package/lib/prediction/predictHMBC.js.map +1 -1
  34. package/lib/prediction/predictHSQC.d.ts +16 -25
  35. package/lib/prediction/predictHSQC.js +3 -7
  36. package/lib/prediction/predictHSQC.js.map +1 -1
  37. package/lib/prediction/predictProton.d.ts +7 -4
  38. package/lib/prediction/predictProton.js +8 -21
  39. package/lib/prediction/predictProton.js.map +1 -1
  40. package/lib/prediction/{predictAllSpectra.d.ts → predictSpectra.d.ts} +1 -1
  41. package/lib/prediction/{predictAllSpectra.js → predictSpectra.js} +7 -5
  42. package/lib/prediction/predictSpectra.js.map +1 -0
  43. package/lib/prediction/utils/fetchPrediction.d.ts +2 -3
  44. package/lib/prediction/utils/fetchPrediction.js +12 -7
  45. package/lib/prediction/utils/fetchPrediction.js.map +1 -1
  46. package/lib/prediction/utils/getFilteredIDiaIDs.d.ts +4 -13
  47. package/lib/prediction/utils/getFilteredIDiaIDs.js +7 -20
  48. package/lib/prediction/utils/getFilteredIDiaIDs.js.map +1 -1
  49. package/lib/prediction/utils/isMolfileNotEmpty.d.ts +1 -0
  50. package/lib/prediction/utils/isMolfileNotEmpty.js +12 -0
  51. package/lib/prediction/utils/isMolfileNotEmpty.js.map +1 -0
  52. package/lib/prediction/utils/predict2D.d.ts +13 -16
  53. package/lib/prediction/utils/predict2D.js +41 -18
  54. package/lib/prediction/utils/predict2D.js.map +1 -1
  55. package/lib/prediction/utils/queryByHOSE.d.ts +1 -2
  56. package/lib/prediction/utils/queryByHOSE.js.map +1 -1
  57. package/lib/prediction/utils/shouldPredict.d.ts +2 -0
  58. package/lib/prediction/utils/shouldPredict.js +15 -0
  59. package/lib/prediction/utils/shouldPredict.js.map +1 -0
  60. package/lib-esm/assignment/get13CAssignments.js +7 -4
  61. package/lib-esm/assignment/get13CAssignments.js.map +1 -1
  62. package/lib-esm/assignment/get1HAssignments.js +7 -5
  63. package/lib-esm/assignment/get1HAssignments.js.map +1 -1
  64. package/lib-esm/assignment/utils/generalAssignment/buildAssignments.js +18 -7
  65. package/lib-esm/assignment/utils/generalAssignment/buildAssignments.js.map +1 -1
  66. package/lib-esm/index.js +2 -7
  67. package/lib-esm/index.js.map +1 -1
  68. package/lib-esm/prediction/GroupDiastereotopicAtomIDs.js +2 -0
  69. package/lib-esm/prediction/GroupDiastereotopicAtomIDs.js.map +1 -0
  70. package/lib-esm/prediction/PredictionBase1D.js +2 -0
  71. package/lib-esm/prediction/PredictionBase1D.js.map +1 -0
  72. package/lib-esm/prediction/PredictionBase2D.js +2 -0
  73. package/lib-esm/prediction/PredictionBase2D.js.map +1 -0
  74. package/lib-esm/prediction/predict.js +109 -0
  75. package/lib-esm/prediction/predict.js.map +1 -0
  76. package/lib-esm/prediction/predictCOSY.js +3 -6
  77. package/lib-esm/prediction/predictCOSY.js.map +1 -1
  78. package/lib-esm/prediction/predictCarbon.js +10 -16
  79. package/lib-esm/prediction/predictCarbon.js.map +1 -1
  80. package/lib-esm/prediction/predictHMBC.js +3 -7
  81. package/lib-esm/prediction/predictHMBC.js.map +1 -1
  82. package/lib-esm/prediction/predictHSQC.js +3 -7
  83. package/lib-esm/prediction/predictHSQC.js.map +1 -1
  84. package/lib-esm/prediction/predictProton.js +8 -21
  85. package/lib-esm/prediction/predictProton.js.map +1 -1
  86. package/lib-esm/prediction/{predictAllSpectra.js → predictSpectra.js} +7 -5
  87. package/lib-esm/prediction/predictSpectra.js.map +1 -0
  88. package/lib-esm/prediction/utils/fetchPrediction.js +12 -7
  89. package/lib-esm/prediction/utils/fetchPrediction.js.map +1 -1
  90. package/lib-esm/prediction/utils/getFilteredIDiaIDs.js +7 -20
  91. package/lib-esm/prediction/utils/getFilteredIDiaIDs.js.map +1 -1
  92. package/lib-esm/prediction/utils/isMolfileNotEmpty.js +8 -0
  93. package/lib-esm/prediction/utils/isMolfileNotEmpty.js.map +1 -0
  94. package/lib-esm/prediction/utils/predict2D.js +41 -18
  95. package/lib-esm/prediction/utils/predict2D.js.map +1 -1
  96. package/lib-esm/prediction/utils/queryByHOSE.js.map +1 -1
  97. package/lib-esm/prediction/utils/shouldPredict.js +11 -0
  98. package/lib-esm/prediction/utils/shouldPredict.js.map +1 -0
  99. package/package.json +2 -3
  100. package/src/assignment/get13CAssignments.ts +9 -8
  101. package/src/assignment/get1HAssignments.ts +8 -9
  102. package/src/assignment/utils/generalAssignment/buildAssignments.ts +28 -12
  103. package/src/index.ts +3 -8
  104. package/src/prediction/GroupDiastereotopicAtomIDs.ts +6 -0
  105. package/src/prediction/Prediction1D.ts +2 -7
  106. package/src/prediction/Prediction2D.ts +2 -7
  107. package/src/prediction/PredictionBase1D.ts +9 -0
  108. package/src/prediction/PredictionBase2D.ts +9 -0
  109. package/src/prediction/predict.ts +201 -0
  110. package/src/prediction/predictCOSY.ts +18 -18
  111. package/src/prediction/predictCarbon.ts +28 -26
  112. package/src/prediction/predictHMBC.ts +17 -27
  113. package/src/prediction/predictHSQC.ts +18 -25
  114. package/src/prediction/predictProton.ts +16 -30
  115. package/src/prediction/{predictAllSpectra.ts → predictSpectra.ts} +6 -4
  116. package/src/prediction/utils/fetchPrediction.ts +15 -10
  117. package/src/prediction/utils/getFilteredIDiaIDs.ts +16 -49
  118. package/src/prediction/utils/isMolfileNotEmpty.ts +8 -0
  119. package/src/prediction/utils/predict2D.ts +69 -69
  120. package/src/prediction/utils/queryByHOSE.ts +2 -2
  121. package/src/prediction/utils/shouldPredict.ts +14 -0
  122. package/lib/prediction/predictAll.d.ts +0 -64
  123. package/lib/prediction/predictAll.js +0 -82
  124. package/lib/prediction/predictAll.js.map +0 -1
  125. package/lib/prediction/predictAllSpectra.js.map +0 -1
  126. package/lib/prediction/utils/getPredictions.d.ts +0 -4
  127. package/lib/prediction/utils/getPredictions.js +0 -18
  128. package/lib/prediction/utils/getPredictions.js.map +0 -1
  129. package/lib-esm/prediction/predictAll.js +0 -78
  130. package/lib-esm/prediction/predictAll.js.map +0 -1
  131. package/lib-esm/prediction/predictAllSpectra.js.map +0 -1
  132. package/lib-esm/prediction/utils/getPredictions.js +0 -14
  133. package/lib-esm/prediction/utils/getPredictions.js.map +0 -1
  134. package/src/openchemlib-utils.d.ts +0 -167
  135. package/src/prediction/predictAll.ts +0 -157
  136. package/src/prediction/utils/getPredictions.ts +0 -24
@@ -1,12 +1,8 @@
1
1
  import { v4 as generateID } from '@lukeed/uuid';
2
2
  import { Molecule } from 'openchemlib/full';
3
- import { ensureHeterotopicChiralBonds } from 'openchemlib-utils';
4
3
 
5
- import { NMRRange } from '..';
6
- import {
7
- predictProton,
8
- PredictProtonOptions,
9
- } from '../prediction/predictProton';
4
+ import { NMRRange, predict } from '..';
5
+ import { PredictProtonOptions } from '../prediction/predictProton';
10
6
  import type { NMRSignal1D } from '../signals/NMRSignal1D';
11
7
  import { MakeMandatory } from '../utilities/MakeMandatory';
12
8
 
@@ -90,10 +86,13 @@ export async function get1HAssignments(
90
86
  throw new Error('It is needed a OCL molecule instance to assign');
91
87
  }
92
88
 
93
- molecule.addImplicitHydrogens();
94
- ensureHeterotopicChiralBonds(molecule);
89
+ const { spectra } = await predict(molecule, {
90
+ predictOptions: {
91
+ H: predictionOptions,
92
+ },
93
+ });
95
94
 
96
- const { joinedSignals } = await predictProton(molecule, predictionOptions);
95
+ const joinedSignals = spectra.proton?.joinedSignals || [];
97
96
 
98
97
  checkForIntegration(ranges);
99
98
  checkAtomsAndDiaIDs(joinedSignals);
@@ -4,12 +4,12 @@ import type { Molecule } from 'openchemlib/full';
4
4
  import { getConnectivityMatrix } from 'openchemlib-utils';
5
5
 
6
6
  import {
7
- NMRSignal1D,
8
- PredictCarbonOptions,
9
- PredictProtonOptions,
10
- } from '../../..';
11
- import { predictCarbon } from '../../../prediction/predictCarbon';
12
- import { predictProton } from '../../../prediction/predictProton';
7
+ PredictionOptionsByExperiment,
8
+ predict,
9
+ } from '../../../prediction/predict';
10
+ import { PredictCarbonOptions } from '../../../prediction/predictCarbon';
11
+ import { PredictProtonOptions } from '../../../prediction/predictProton';
12
+ import { NMRSignal1D } from '../../../signals/NMRSignal1D';
13
13
  import { MakeMandatory } from '../../../utilities/MakeMandatory';
14
14
  import { SpectraDataWithIds } from '../../nmrAssigment';
15
15
  import { StoreAssignments } from '../oneDimensionalAssignment/buildAssignments';
@@ -27,8 +27,6 @@ const comparator = (a: AssignmentSolution, b: AssignmentSolution) => {
27
27
  return b.score - a.score;
28
28
  };
29
29
 
30
- const predictor = { H: predictProton, C: predictCarbon };
31
-
32
30
  export type AtomTypes = 'H' | 'C';
33
31
  export type CurrentAtoms = AtomTypes[];
34
32
  export type Partial = Record<string, Array<string | null>>;
@@ -141,11 +139,15 @@ export async function buildAssignments(props: BuildAssignmentInput) {
141
139
 
142
140
  for (const atomTypesToPredict of assignmentOrder) {
143
141
  for (const atomType of atomTypesToPredict) {
144
- const options = predictionOptions[atomType];
142
+ const options: PredictionOptionsByExperiment = {};
143
+ options[atomType] = predictionOptions[atomType];
145
144
  const predictedSignals = inputPrediction[atomType];
146
- const { joinedSignals } = predictedSignals
147
- ? { joinedSignals: predictedSignals }
148
- : await predictor[atomType](molecule, options);
145
+ const joinedSignals = await getJoinedSignals({
146
+ molecule,
147
+ predictedSignals,
148
+ options,
149
+ atomType,
150
+ });
149
151
 
150
152
  checkNMRSignal1D(joinedSignals);
151
153
 
@@ -338,3 +340,17 @@ function fillPartial(nSources: number, value: string | null = null) {
338
340
  }
339
341
  return partial;
340
342
  }
343
+
344
+ async function getJoinedSignals(input: {
345
+ atomType: AtomTypes;
346
+ molecule: Molecule;
347
+ predictedSignals?: NMRSignal1D[];
348
+ options: PredictionOptionsByExperiment;
349
+ }) {
350
+ const { molecule, predictedSignals, options, atomType } = input;
351
+ if (predictedSignals) return predictedSignals;
352
+ const { spectra } = await predict(molecule, {
353
+ predictOptions: options,
354
+ });
355
+ return spectra[atomType === 'C' ? 'carbon' : 'proton']?.joinedSignals || [];
356
+ }
package/src/index.ts CHANGED
@@ -7,14 +7,6 @@ export * from './peaks/peaksFilterImpurities';
7
7
  export * from './peaks/peaksToXY';
8
8
  export * from './peaks/peakToXY';
9
9
 
10
- export * from './prediction/predictProton';
11
- export * from './prediction/predictCarbon';
12
- export * from './prediction/predictCOSY';
13
- export * from './prediction/predictHSQC';
14
- export * from './prediction/predictHMBC';
15
- export * from './prediction/predictAll';
16
- export * from './prediction/predictAllSpectra';
17
-
18
10
  export * from './assignment/get1HAssignments';
19
11
  export * from './assignment/get13CAssignments';
20
12
  export * from './assignment/getAssignments';
@@ -31,6 +23,9 @@ export * from './signals/simulation/simulate1D';
31
23
  export * from './signal/signalJoinCouplings';
32
24
  export * from './signal/signalMultiplicityPattern';
33
25
 
26
+ export * from './prediction/predict';
27
+ export * from './prediction/predictSpectra';
28
+
34
29
  export * from './utilities/resurrect';
35
30
  export * from './utilities/rangeFromSignal';
36
31
  export * from './utilities/getFrequency';
@@ -0,0 +1,6 @@
1
+ export interface GroupDiastereotopicAtomIDs {
2
+ counter: number;
3
+ atoms: number[];
4
+ oclID: string;
5
+ atomLabel: string;
6
+ }
@@ -1,14 +1,9 @@
1
1
  import type { Molecule } from 'openchemlib/full';
2
2
 
3
- import type { NMRSignal1D } from '../signals/NMRSignal1D';
4
- import type { NMRRange } from '../xy/NMRRange';
3
+ import type { PredictionBase1D } from './PredictionBase1D';
5
4
 
6
- export interface Prediction1D {
5
+ export interface Prediction1D extends PredictionBase1D {
7
6
  molfile: string;
8
7
  diaIDs: string[];
9
- nucleus: string;
10
- joinedSignals: NMRSignal1D[];
11
- signals: NMRSignal1D[];
12
- ranges: NMRRange[];
13
8
  molecule: Molecule;
14
9
  }
@@ -1,14 +1,9 @@
1
1
  import type { Molecule } from 'openchemlib/full';
2
2
 
3
- import { NMRSignal2D } from '../xyz/NMRSignal2D';
4
- import { NMRZone } from '../xyz/NMRZone';
3
+ import { PredictionBase2D } from './PredictionBase2D';
5
4
 
6
- export interface Prediction2D {
5
+ export interface Prediction2D extends PredictionBase2D {
7
6
  molfile: string;
8
7
  diaIDs: string[];
9
- nuclei: string[];
10
- joinedSignals: NMRSignal2D[];
11
- signals: NMRSignal2D[];
12
- zones: NMRZone[];
13
8
  molecule: Molecule;
14
9
  }
@@ -0,0 +1,9 @@
1
+ import type { NMRSignal1D } from '../signals/NMRSignal1D';
2
+ import type { NMRRange } from '../xy/NMRRange';
3
+
4
+ export interface PredictionBase1D {
5
+ nucleus: string;
6
+ joinedSignals: NMRSignal1D[];
7
+ signals: NMRSignal1D[];
8
+ ranges: NMRRange[];
9
+ }
@@ -0,0 +1,9 @@
1
+ import { NMRSignal2D } from '../xyz/NMRSignal2D';
2
+ import { NMRZone } from '../xyz/NMRZone';
3
+
4
+ export interface PredictionBase2D {
5
+ nuclei: string[];
6
+ joinedSignals: NMRSignal2D[];
7
+ signals: NMRSignal2D[];
8
+ zones: NMRZone[];
9
+ }
@@ -0,0 +1,201 @@
1
+ import type { Logger } from 'cheminfo-types';
2
+ import type { Molecule } from 'openchemlib/full';
3
+ import {
4
+ getHoseCodesAndInfo,
5
+ groupDiastereotopicAtomIDs,
6
+ } from 'openchemlib-utils';
7
+
8
+ import { PredictionBase1D } from './PredictionBase1D';
9
+ import { PredictionBase2D } from './PredictionBase2D';
10
+ import { predictCOSY, PredictCOSYOptions } from './predictCOSY';
11
+ import { predictCarbon, PredictCarbonOptions } from './predictCarbon';
12
+ import { predictHMBC, PredictHMBCOptions } from './predictHMBC';
13
+ import { predictHSQC, PredictHSQCOptions } from './predictHSQC';
14
+ import { predictProton, PredictProtonOptions } from './predictProton';
15
+ import { shouldPredict } from './utils/shouldPredict';
16
+
17
+ export interface PredictionOptionsByExperiment {
18
+ H?: Partial<PredictProtonOptions>;
19
+ C?: Partial<PredictCarbonOptions>;
20
+ hsqc?: Partial<PredictHSQCOptions>;
21
+ cosy?: Partial<PredictCOSYOptions>;
22
+ hmbc?: Partial<PredictHMBCOptions>;
23
+ }
24
+
25
+ interface ToPredictBase {
26
+ required: Array<'H' | 'C'>;
27
+ message: string;
28
+ }
29
+ interface ToPredictCOSY extends ToPredictBase {
30
+ predictor: typeof predictCOSY;
31
+ }
32
+ interface ToPredictHSQC extends ToPredictBase {
33
+ predictor: typeof predictHSQC;
34
+ }
35
+ interface ToPredictHMBC extends ToPredictBase {
36
+ predictor: typeof predictHMBC;
37
+ }
38
+ interface ToPredict {
39
+ cosy: ToPredictCOSY;
40
+ hsqc: ToPredictHSQC;
41
+ hmbc: ToPredictHMBC;
42
+ }
43
+ const toPredict: ToPredict = {
44
+ cosy: {
45
+ predictor: predictCOSY,
46
+ required: ['H'],
47
+ message: 'Proton prediction is missing so COSY could not be generated.',
48
+ },
49
+ hsqc: {
50
+ predictor: predictHSQC,
51
+ required: ['H', 'C'],
52
+ message:
53
+ 'Carbon and / or proton prediction is missing so HSQC could not be generated.',
54
+ },
55
+ hmbc: {
56
+ predictor: predictHMBC,
57
+ required: ['H', 'C'],
58
+ message:
59
+ 'Carbon and / or proton prediction is missing so HMBC could not be generated.',
60
+ },
61
+ };
62
+
63
+ export interface PredictAllOptions {
64
+ /**
65
+ * mono dimensional signal to generate the bidimenionals cross peaks.
66
+ * The object should has properties with name equal to "H" and "C".
67
+ */
68
+ predictOptions?: PredictionOptionsByExperiment;
69
+ /**
70
+ * signals with euclidean distance in ppm less than this it will
71
+ * joined into a zone.
72
+ * @default {H:0.05,C:0.5}
73
+ */
74
+ joinDistance?: { H: number; C: number };
75
+ logger?: Logger;
76
+ }
77
+
78
+ export interface PredictedSpectra {
79
+ proton?: PredictionBase1D;
80
+ carbon?: PredictionBase1D;
81
+ cosy?: PredictionBase2D;
82
+ hsqc?: PredictionBase2D;
83
+ hmbc?: PredictionBase2D;
84
+ }
85
+
86
+ export interface Predicted {
87
+ molfile: string;
88
+ molfileWithH: string;
89
+ hoses: any[];
90
+ diaIDs: any[] | undefined;
91
+ groupedDiaIDs: any[];
92
+ moleculeWithHydrogens: Molecule;
93
+ distanceMatrix: any[];
94
+ spectra: PredictedSpectra;
95
+ }
96
+
97
+ /**
98
+ * Generate the correlation bidimensional nmr peaks based on the number of bonds between a pair of atoms
99
+ * @returns {Promise<object>} - object with molfile, diaIDs, 1D and 2D signals, joined signals, ranges and zones.
100
+ */
101
+ export async function predict(
102
+ molecule: Molecule,
103
+ options: PredictAllOptions = {},
104
+ ): Promise<Predicted> {
105
+ const {
106
+ logger,
107
+ joinDistance = { H: 0.05, C: 0.5 },
108
+ predictOptions = {
109
+ H: {},
110
+ C: {},
111
+ hsqc: {},
112
+ hmbc: {},
113
+ cosy: {},
114
+ } as PredictionOptionsByExperiment,
115
+ } = options;
116
+
117
+ const hoseCodesAndInfo = getHoseCodesAndInfo(molecule, {
118
+ maxSphereSize: predictOptions?.C?.maxSphereSize,
119
+ });
120
+ const {
121
+ diaIDs = [],
122
+ moleculeWithHydrogens,
123
+ hoses,
124
+ molfileWithH,
125
+ distanceMatrix,
126
+ } = hoseCodesAndInfo;
127
+
128
+ const groupedDiaIDs = groupDiastereotopicAtomIDs(
129
+ diaIDs,
130
+ moleculeWithHydrogens,
131
+ );
132
+
133
+ const protonPrediction = shouldPredict('H', predictOptions)
134
+ ? await predictProton(molfileWithH, {
135
+ ...predictOptions?.H,
136
+ diaIDs,
137
+ distanceMatrix,
138
+ })
139
+ : undefined;
140
+
141
+ const carbonPrediction = shouldPredict('C', predictOptions)
142
+ ? await predictCarbon({
143
+ ...predictOptions?.C,
144
+ molfile: molfileWithH,
145
+ groupedDiaIDs,
146
+ hoses,
147
+ })
148
+ : undefined;
149
+
150
+ const spectra: any = {};
151
+ const predictions: Record<string, PredictionBase1D> = {};
152
+ if (check1DPrediction(protonPrediction, diaIDs)) {
153
+ predictions.H = protonPrediction;
154
+ if ('H' in predictOptions) spectra.proton = protonPrediction;
155
+ }
156
+ if (check1DPrediction(carbonPrediction, diaIDs)) {
157
+ predictions.C = carbonPrediction;
158
+ if ('C' in predictOptions) spectra.carbon = carbonPrediction;
159
+ }
160
+
161
+ const optionsTwoD = {
162
+ predictions,
163
+ joinDistance,
164
+ distanceMatrix,
165
+ groupedDiaIDs,
166
+ diaIDs,
167
+ };
168
+
169
+ for (const key in predictOptions) {
170
+ if (key === 'H' || key === 'C') continue;
171
+ const { predictor, required, message } = toPredict[key as keyof ToPredict];
172
+ if (required.every((key) => key in predictions)) {
173
+ spectra[key] = await predictor(molecule, {
174
+ ...optionsTwoD,
175
+ ...predictOptions[key as keyof PredictionOptionsByExperiment],
176
+ });
177
+ } else if (logger) {
178
+ logger.warn(message);
179
+ }
180
+ }
181
+
182
+ return {
183
+ ...hoseCodesAndInfo,
184
+ groupedDiaIDs,
185
+ spectra,
186
+ };
187
+ }
188
+
189
+ function check1DPrediction(
190
+ prediction?: PredictionBase1D,
191
+ diaIDs: string[] = [],
192
+ ): prediction is PredictionBase1D {
193
+ if (!prediction) return false;
194
+ if (prediction.ranges.length === 0) return false;
195
+ const { signals } = prediction;
196
+ for (const signal of signals) {
197
+ const isCorrect = signal.diaIDs?.every((diaID) => diaIDs.includes(diaID));
198
+ if (!isCorrect) return false;
199
+ }
200
+ return true;
201
+ }
@@ -1,8 +1,9 @@
1
1
  import type { Molecule } from 'openchemlib/full';
2
2
 
3
- import type { Prediction1D } from './Prediction1D';
4
- import { predictProton, PredictProtonOptions } from './predictProton';
5
- import { predict2D, Predictor } from './utils/predict2D';
3
+ import { GroupDiastereotopicAtomIDs } from './GroupDiastereotopicAtomIDs';
4
+ import type { PredictionBase1D } from './PredictionBase1D';
5
+ import { PredictProtonOptions } from './predictProton';
6
+ import { predict2D } from './utils/predict2D';
6
7
 
7
8
  export interface PredictCOSYOptions {
8
9
  /**
@@ -15,11 +16,6 @@ export interface PredictCOSYOptions {
15
16
  * @default 2
16
17
  */
17
18
  minLength?: number;
18
- /**
19
- * mono dimensional predictors. The object should has properties with name
20
- * equal to "H" and "C".
21
- */
22
- predictor?: { H?: Predictor };
23
19
  /**
24
20
  * mono dimensional signal to generate the bidimenionals cross peaks.
25
21
  * The object should has properties with name equal to "H" and "C".
@@ -36,15 +32,24 @@ export interface PredictCOSYOptions {
36
32
  * The object should has properties with name equal to "H" and "C".
37
33
  * the value of each prediction should be similar that predictProton and predictCarbon.
38
34
  */
39
- predictions?: {
40
- [key: string]: Prediction1D | undefined;
41
- H?: Prediction1D;
35
+ predictions: {
36
+ [key: string]: PredictionBase1D | undefined;
37
+ H?: PredictionBase1D;
42
38
  };
43
39
  /**
44
40
  * if true, the self correlation signal will be add to the prediction.
45
41
  * @default true
46
42
  */
47
43
  includeDiagonal?: boolean;
44
+ /**
45
+ * diastereotopic atom ids of the molecule.
46
+ */
47
+ diaIDs: string[];
48
+ /**
49
+ * grouped diastereotopic atom ids of the molecule.
50
+ */
51
+ groupedDiaIDs: GroupDiastereotopicAtomIDs[];
52
+ distanceMatrix: number[][];
48
53
  }
49
54
  /**
50
55
  * Generate the correlation bidimensional nmr peaks based on the number of bonds between a pair of atoms
@@ -53,27 +58,22 @@ export interface PredictCOSYOptions {
53
58
 
54
59
  export async function predictCOSY(
55
60
  molecule: Molecule,
56
- options: PredictCOSYOptions = {},
61
+ options: PredictCOSYOptions,
57
62
  ) {
58
63
  const {
59
64
  minLength = 2,
60
65
  maxLength = 3,
61
- predictions,
62
- predictor = { H: predictProton },
63
- predictOptions,
64
66
  joinDistance = { H: 0.05, C: 0.5 },
65
67
  includeDiagonal = true,
66
68
  } = options;
67
69
 
68
70
  return predict2D(molecule, {
71
+ ...options,
69
72
  from: 'H',
70
73
  to: 'H',
71
- predictor,
72
74
  minLength,
73
75
  maxLength,
74
76
  joinDistance,
75
- predictions,
76
77
  includeDiagonal,
77
- predictOptions,
78
78
  });
79
79
  }
@@ -1,17 +1,15 @@
1
1
  import { v4 as generateID } from '@lukeed/uuid';
2
- import type { Molecule } from 'openchemlib/full';
3
- import { getDiastereotopicAtomIDs } from 'openchemlib-utils';
4
2
 
5
3
  import { setIDs } from '../peaks/util/setIDs';
6
4
  import type { NMRSignal1D } from '../signals/NMRSignal1D';
7
5
  import { signalsToRanges } from '../signals/signalsToRanges';
8
6
  import type { MakeMandatory } from '../utilities/MakeMandatory';
9
7
 
10
- import type { Prediction1D } from './Prediction1D';
8
+ import { PredictionBase1D } from './PredictionBase1D';
11
9
  import type { DataBaseStructure } from './dataStructure';
12
10
  import { fetchPrediction } from './utils/fetchPrediction';
13
11
  import { getFilteredIDiaIDs } from './utils/getFilteredIDiaIDs';
14
- import { isEmptyMolecule } from './utils/isEmptyMolecule';
12
+ import { isMolfileNotEmpty } from './utils/isMolfileNotEmpty';
15
13
  import { Prediction, queryByHose } from './utils/queryByHOSE';
16
14
 
17
15
  export interface PredictCarbonOptions {
@@ -33,7 +31,16 @@ export interface PredictCarbonOptions {
33
31
  /**
34
32
  * diastereotopic atom ids.
35
33
  */
36
- diaIDs?: string[];
34
+ groupedDiaIDs: string[];
35
+ /**
36
+ * hoses code of the molecule.
37
+ */
38
+ hoses: Array<any[] | undefined>;
39
+ /**
40
+ * molfile of the molecule, it could be used if there is not a database provided.
41
+ * so the prediction will be fetched to the web service (webserviceURL)
42
+ */
43
+ molfile?: string;
37
44
  }
38
45
 
39
46
  export type PredictCarbon = typeof predictCarbon;
@@ -55,29 +62,27 @@ function checkFromPrediction(
55
62
  */
56
63
 
57
64
  export async function predictCarbon(
58
- molecule: Molecule,
59
- options: PredictCarbonOptions = {},
60
- ): Promise<Prediction1D> {
61
- if (isEmptyMolecule(molecule)) {
65
+ options: PredictCarbonOptions,
66
+ ): Promise<PredictionBase1D> {
67
+ const {
68
+ hoses,
69
+ molfile,
70
+ database,
71
+ webserviceURL = 'https://nmr-prediction.service.zakodium.com/v1/predict/carbon',
72
+ groupedDiaIDs,
73
+ } = options;
74
+
75
+ if (!database && isMolfileNotEmpty(molfile)) {
76
+ return fetchPrediction(molfile, { webserviceURL });
77
+ } else if (!isMolfileNotEmpty(molfile)) {
62
78
  return {
63
- molfile: molecule.toMolfile(),
64
79
  nucleus: '13C',
65
- diaIDs: [],
66
80
  joinedSignals: [],
67
81
  signals: [],
68
82
  ranges: [],
69
- molecule,
70
83
  };
71
84
  }
72
85
 
73
- const {
74
- database,
75
- webserviceURL = 'https://nmr-prediction.service.zakodium.com/v1/predict/carbon',
76
- diaIDs = getDiastereotopicAtomIDs(molecule),
77
- } = options;
78
-
79
- if (!database) return fetchPrediction(molecule, { webserviceURL });
80
-
81
86
  if (!database) {
82
87
  throw new Error('There is not a database');
83
88
  }
@@ -88,9 +93,9 @@ export async function predictCarbon(
88
93
 
89
94
  if (maxSphereSize > maxLevel) maxSphereSize = maxLevel;
90
95
 
91
- const { carbonDiaIDs, molfile } = getFilteredIDiaIDs(molecule, {
92
- maxSphereSize,
93
- diaIDs,
96
+ const carbonDiaIDs = getFilteredIDiaIDs({
97
+ groupedDiaIDs,
98
+ hoses,
94
99
  });
95
100
 
96
101
  const predictions = queryByHose(carbonDiaIDs, database, {
@@ -100,13 +105,10 @@ export async function predictCarbon(
100
105
  const signals = formatSignals(predictions);
101
106
  const joinedSignals = joinSignalByDiaID(signals);
102
107
  return {
103
- molfile,
104
108
  nucleus: '13C',
105
- diaIDs,
106
109
  joinedSignals,
107
110
  signals,
108
111
  ranges: signalsToRanges(joinedSignals),
109
- molecule,
110
112
  };
111
113
  }
112
114
 
@@ -1,12 +1,8 @@
1
1
  import type { Molecule } from 'openchemlib/full';
2
2
 
3
- import type { Prediction1D } from './Prediction1D';
4
- import { predictCarbon } from './predictCarbon';
5
- import type { PredictCarbonOptions } from './predictCarbon';
6
- import { predictProton } from './predictProton';
7
- import type { PredictProtonOptions } from './predictProton';
3
+ import { GroupDiastereotopicAtomIDs } from './GroupDiastereotopicAtomIDs';
4
+ import { PredictionBase1D } from './PredictionBase1D';
8
5
  import { predict2D } from './utils/predict2D';
9
- import type { Predictor } from './utils/predict2D';
10
6
 
11
7
  /**
12
8
  * Generate the correlation bidimensional nmr peaks based on the number of bonds between a pair of atoms
@@ -24,16 +20,6 @@ export interface PredictHMBCOptions {
24
20
  * @default 2
25
21
  */
26
22
  minLength?: number;
27
- /**
28
- * mono dimensional predictors. The object should has properties with name
29
- * equal to "H" and "C".
30
- */
31
- predictor?: { H?: Predictor; C?: Predictor };
32
- /**
33
- * mono dimensional signal to generate the bidimenionals cross peaks.
34
- * The object should has properties with name equal to "H" and "C".
35
- */
36
- predictOptions?: { H?: PredictProtonOptions; C?: PredictCarbonOptions };
37
23
  /**
38
24
  * signals with euclidean distance in ppm less than this it will
39
25
  * joined into a zone.
@@ -45,34 +31,38 @@ export interface PredictHMBCOptions {
45
31
  * The object should has properties with name equal to "H" and "C".
46
32
  * the value of each prediction should be similar that predictProton and predictCarbon.
47
33
  */
48
- predictions?: {
49
- [key: string]: Prediction1D | undefined;
50
- H?: Prediction1D;
51
- C?: Prediction1D;
34
+ predictions: {
35
+ [key: string]: PredictionBase1D | undefined;
36
+ H?: PredictionBase1D;
37
+ C?: PredictionBase1D;
52
38
  };
39
+ /**
40
+ * diastereotopic atom ids of the molecule.
41
+ */
42
+ diaIDs: string[];
43
+ /**
44
+ * grouped diastereotopic atom ids of the molecule.
45
+ */
46
+ groupedDiaIDs: GroupDiastereotopicAtomIDs[];
47
+ distanceMatrix: number[][];
53
48
  }
54
49
 
55
50
  export async function predictHMBC(
56
51
  molecule: Molecule,
57
- options: PredictHMBCOptions = {},
52
+ options: PredictHMBCOptions,
58
53
  ) {
59
54
  const {
60
55
  minLength = 2,
61
56
  maxLength = 3,
62
- predictor = { H: predictProton, C: predictCarbon },
63
- predictOptions,
64
- predictions,
65
57
  joinDistance = { H: 0.05, C: 0.5 },
66
58
  } = options;
67
59
 
68
60
  return predict2D(molecule, {
61
+ ...options,
69
62
  from: 'H',
70
63
  to: 'C',
71
- predictor,
72
64
  minLength,
73
65
  maxLength,
74
- predictions,
75
- predictOptions,
76
66
  joinDistance,
77
67
  });
78
68
  }