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,9 +1,8 @@
1
1
  import type { Molecule } from 'openchemlib/full';
2
2
 
3
- import type { Prediction1D } from './Prediction1D';
4
- import { predictCarbon, PredictCarbonOptions } from './predictCarbon';
5
- import { predictProton, PredictProtonOptions } from './predictProton';
6
- import { predict2D, Predictor } from './utils/predict2D';
3
+ import { GroupDiastereotopicAtomIDs } from './GroupDiastereotopicAtomIDs';
4
+ import { PredictionBase1D } from './PredictionBase1D';
5
+ import { predict2D } from './utils/predict2D';
7
6
 
8
7
  export interface PredictHSQCOptions {
9
8
  /**
@@ -16,16 +15,6 @@ export interface PredictHSQCOptions {
16
15
  * @default 1
17
16
  */
18
17
  minLength?: number;
19
- /**
20
- * mono dimensional predictors. The object should has properties with name
21
- * equal to "H" and "C".
22
- */
23
- predictor?: { H?: Predictor; C?: Predictor };
24
- /**
25
- * mono dimensional signal to generate the bidimenionals cross peaks.
26
- * The object should has properties with name equal to "H" and "C".
27
- */
28
- predictOptions?: { H?: PredictProtonOptions; C?: PredictCarbonOptions };
29
18
  /**
30
19
  * signals with euclidean distance in ppm less than this it will
31
20
  * joined into a zone.
@@ -37,11 +26,20 @@ export interface PredictHSQCOptions {
37
26
  * The object should has properties with name equal to "H" and "C".
38
27
  * the value of each prediction should be similar that predictProton and predictCarbon.
39
28
  */
40
- predictions?: {
41
- [key: string]: Prediction1D | undefined;
42
- H?: Prediction1D;
43
- C?: Prediction1D;
29
+ predictions: {
30
+ [key: string]: PredictionBase1D | undefined;
31
+ H?: PredictionBase1D;
32
+ C?: PredictionBase1D;
44
33
  };
34
+ /**
35
+ * diastereotopic atom ids of the molecule.
36
+ */
37
+ diaIDs: string[];
38
+ /**
39
+ * grouped diastereotopic atom ids of the molecule.
40
+ */
41
+ groupedDiaIDs: GroupDiastereotopicAtomIDs[];
42
+ distanceMatrix: number[][];
45
43
  }
46
44
  /**
47
45
  * Generate the correlation bidimensional nmr peaks based on the number of bonds between a pair of atoms
@@ -50,25 +48,20 @@ export interface PredictHSQCOptions {
50
48
 
51
49
  export async function predictHSQC(
52
50
  molecule: Molecule,
53
- options: PredictHSQCOptions = {},
51
+ options: PredictHSQCOptions,
54
52
  ) {
55
53
  const {
56
54
  minLength = 1,
57
55
  maxLength = 1,
58
- predictor = { H: predictProton, C: predictCarbon },
59
- predictions,
60
56
  joinDistance = { H: 0.05, C: 0.5 },
61
- predictOptions,
62
57
  } = options;
63
58
 
64
59
  return predict2D(molecule, {
60
+ ...options,
65
61
  from: 'H',
66
62
  to: 'C',
67
- predictor,
68
63
  minLength,
69
64
  maxLength,
70
- predictions,
71
- predictOptions,
72
65
  joinDistance,
73
66
  });
74
67
  }
@@ -1,19 +1,13 @@
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/full';
5
- import {
6
- ensureHeterotopicChiralBonds,
7
- getConnectivityMatrix,
8
- getDiastereotopicAtomIDs,
9
- } from 'openchemlib-utils';
10
4
 
11
5
  import type { NMRSignal1D } from '../signals/NMRSignal1D';
12
6
  import { signalsJoin } from '../signals/signalsJoin';
13
7
  import { signalsToRanges } from '../signals/signalsToRanges';
14
8
 
15
- import type { Prediction1D } from './Prediction1D';
16
- import { isEmptyMolecule } from './utils/isEmptyMolecule';
9
+ import { PredictionBase1D } from './PredictionBase1D';
10
+ import { isMolfileNotEmpty } from './utils/isMolfileNotEmpty';
17
11
 
18
12
  /**
19
13
  * Makes a prediction using proton.
@@ -28,31 +22,28 @@ export interface PredictProtonOptions {
28
22
  /**
29
23
  * diastereotopic atom ids.
30
24
  */
31
- diaIDs?: string[];
25
+ diaIDs: string[];
26
+ /**
27
+ * distance matrix
28
+ */
29
+ distanceMatrix: number[][];
32
30
  }
33
31
 
34
32
  export type PredictProton = typeof predictProton;
35
33
 
36
34
  export async function predictProton(
37
- molecule: Molecule,
38
- options: PredictProtonOptions = {},
39
- ): Promise<Prediction1D> {
40
- if (isEmptyMolecule(molecule)) {
35
+ molfile: string,
36
+ options: PredictProtonOptions,
37
+ ): Promise<PredictionBase1D> {
38
+ if (!isMolfileNotEmpty(molfile)) {
41
39
  return {
42
- molfile: molecule.toMolfile(),
43
- nucleus: '13C',
44
- diaIDs: [],
40
+ nucleus: '1H',
45
41
  joinedSignals: [],
46
42
  signals: [],
47
43
  ranges: [],
48
- molecule,
49
44
  };
50
45
  }
51
46
  const { cache } = options;
52
- molecule = molecule.getCompactCopy();
53
- molecule.addImplicitHydrogens();
54
- ensureHeterotopicChiralBonds(molecule);
55
- const molfile = molecule.toMolfile();
56
47
 
57
48
  let result;
58
49
  if (cache) {
@@ -72,30 +63,25 @@ export async function predictProton(
72
63
  }
73
64
  }
74
65
 
75
- const { diaIDs = getDiastereotopicAtomIDs(molecule) } = options;
76
- const signals = protonParser(result, molecule, diaIDs);
66
+ const { diaIDs, distanceMatrix } = options;
67
+ const signals = protonParser(result, { diaIDs, distanceMatrix });
77
68
  const joinedSignals = signalsJoin(signals);
78
69
  return {
79
- molfile,
80
- diaIDs,
81
70
  nucleus: '1H',
82
71
  joinedSignals,
83
72
  signals,
84
73
  ranges: signalsToRanges(joinedSignals),
85
- molecule,
86
74
  };
87
75
  }
88
76
 
89
77
  function protonParser(
90
78
  result: string,
91
- molecule: Molecule,
92
- diaIDs: string[],
79
+ options: { diaIDs: string[]; distanceMatrix: number[][] },
93
80
  ): NMRSignal1D[] {
94
- if (molecule.getAllAtoms() === 0) return [];
95
81
  if (result.includes('ERR')) {
96
82
  throw Error(`Spinus optimization: ${result}`);
97
83
  }
98
- const distanceMatrix = getConnectivityMatrix(molecule, { pathLength: true });
84
+ const { diaIDs, distanceMatrix } = options;
99
85
  const lines = result.split('\n').filter((line) => line);
100
86
  const signals = [];
101
87
  for (const line of lines) {
@@ -5,7 +5,7 @@ import { signals2DToZ } from '../signals/signals2DToZ';
5
5
  import { OptionsSignalsToXY, signalsToXY } from '../signals/signalsToXY';
6
6
  import { getFrequency } from '../utilities/getFrequency';
7
7
 
8
- import { PredictAllOptions, predictAll } from './predictAll';
8
+ import { PredictAllOptions, predict } from './predict';
9
9
  /**
10
10
  * This function will generate an object compatible with NMR-ium
11
11
  *
@@ -44,8 +44,7 @@ export async function predictAllSpectra(
44
44
  prediction: predictionOptions = {},
45
45
  } = options;
46
46
 
47
- const predictions = await predictAll(molecule, predictionOptions);
48
- const { molfile, spectra } = predictions;
47
+ const { spectra } = await predict(molecule, predictionOptions);
49
48
 
50
49
  const oneDOptions: OneDOptions = {
51
50
  ...{
@@ -99,7 +98,10 @@ export async function predictAllSpectra(
99
98
  }
100
99
  }
101
100
 
102
- return { spectra: newSpectra, molecules: [{ molfile }] };
101
+ return {
102
+ spectra: newSpectra,
103
+ molecules: [{ molfile: molecule.toMolfile() }],
104
+ };
103
105
  }
104
106
 
105
107
  type Get2DSpectrumOptions = TwoDOptions & {
@@ -1,33 +1,38 @@
1
1
  import fetch from 'cross-fetch';
2
- import type { Molecule } from 'openchemlib/full';
3
2
 
4
- import type { Prediction1D } from '../Prediction1D';
3
+ import { PredictionBase1D } from '../PredictionBase1D';
4
+
5
+ import { isMolfileNotEmpty } from './isMolfileNotEmpty';
5
6
 
6
7
  interface FetchPredictionOptions {
7
8
  webserviceURL: string;
8
9
  }
9
10
 
10
11
  export async function fetchPrediction(
11
- molecule: Molecule,
12
+ molfile: string,
12
13
  options: FetchPredictionOptions,
13
- ): Promise<Prediction1D> {
14
+ ): Promise<PredictionBase1D> {
15
+ if (!isMolfileNotEmpty(molfile)) {
16
+ return {
17
+ nucleus: '13C',
18
+ joinedSignals: [],
19
+ signals: [],
20
+ ranges: [],
21
+ };
22
+ }
14
23
  const { webserviceURL } = options;
15
24
  const response = await fetch(webserviceURL, {
16
25
  headers: {
17
26
  accept: 'application/json',
18
27
  'content-type': 'application/json',
19
28
  },
20
- body: JSON.stringify({ molfile: molecule.toMolfile() }),
29
+ body: JSON.stringify({ molfile }),
21
30
  method: 'POST',
22
31
  });
23
32
 
24
33
  if (response.status >= 400) {
25
34
  throw new Error(response.statusText);
26
35
  }
27
- const prediction = (await response.json()).data;
28
36
 
29
- prediction.molecule = molecule
30
- .getOCL()
31
- .Molecule.fromMolfile(prediction.molfile);
32
- return prediction;
37
+ return (await response.json()).data;
33
38
  }
@@ -1,54 +1,21 @@
1
- import type { Molecule } from 'openchemlib/full';
2
- import {
3
- getHoseCodesFromDiastereotopicID,
4
- ensureHeterotopicChiralBonds,
5
- groupDiastereotopicAtomIDs,
6
- } from 'openchemlib-utils';
7
- import type { GroupDiastereotopicAtomIDs } from 'openchemlib-utils';
1
+ export function getFilteredIDiaIDs(options: {
2
+ groupedDiaIDs: any[];
3
+ hoses: any;
4
+ }) {
5
+ const { groupedDiaIDs, hoses } = options;
6
+
7
+ const carbonDiaIDs = groupedDiaIDs
8
+ .filter((group) => group.atomLabel === 'C')
9
+ .sort((a, b) => {
10
+ if (a.atomLabel === b.atomLabel) {
11
+ return b.counter - a.counter;
12
+ }
13
+ return a.atomLabel < b.atomLabel ? 1 : -1;
14
+ });
8
15
 
9
- export interface GroupDiaIDsWithHose extends GroupDiastereotopicAtomIDs {
10
- hose: string[];
11
- }
12
-
13
- export type GroupedDiaIDsWithHose = GroupDiaIDsWithHose[];
14
-
15
- export function getFilteredIDiaIDs(
16
- molecule: Molecule,
17
- options: { maxSphereSize: number; diaIDs: string[] },
18
- ) {
19
- const { maxSphereSize, diaIDs } = options;
20
-
21
- molecule.addImplicitHydrogens();
22
- molecule.addMissingChirality();
23
- ensureHeterotopicChiralBonds(molecule);
24
-
25
- const molfile = molecule.toMolfile();
26
-
27
- const groupedDiaIDs = groupDiastereotopicAtomIDs(diaIDs, molecule, {
28
- atomLabel: 'C',
29
- });
30
-
31
- const carbonDiaIDs = groupedDiaIDs.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;
37
-
38
- const OCL = molecule.getOCL();
39
16
  for (const diaId of carbonDiaIDs) {
40
- diaId.hose = getHoseCodesFromDiastereotopicID(
41
- OCL.Molecule.fromIDCode(diaId.oclID),
42
- {
43
- maxSphereSize,
44
- },
45
- );
17
+ diaId.hose = hoses[diaId.atoms[0]];
46
18
  }
47
19
 
48
- const toReturn = {
49
- molfile,
50
- carbonDiaIDs: carbonDiaIDs as GroupedDiaIDsWithHose,
51
- };
52
-
53
- return toReturn;
20
+ return carbonDiaIDs;
54
21
  }
@@ -0,0 +1,8 @@
1
+ import { Molecule } from 'openchemlib/full';
2
+
3
+ import { isEmptyMolecule } from './isEmptyMolecule';
4
+
5
+ export function isMolfileNotEmpty(molFile?: string): molFile is string {
6
+ if (!molFile?.match(/V[23]0/)) return false;
7
+ return !isEmptyMolecule(Molecule.fromMolfile(molFile));
8
+ }
@@ -1,30 +1,20 @@
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 type { Molecule } from 'openchemlib/full';
5
- import {
6
- getGroupedDiastereotopicAtomIDs,
7
- getPathsInfo,
8
- groupDiastereotopicAtomIDs,
9
- } from 'openchemlib-utils';
10
- import type {
11
- AtomInfo,
12
- GroupDiastereotopicAtomIDs,
13
- PathInfo,
14
- } from 'openchemlib-utils';
4
+ import { Molecule } from 'openchemlib/full';
15
5
 
16
6
  import { setIDs } from '../../peaks/util/setIDs';
17
7
  import type { NMRSignal1D } from '../../signals/NMRSignal1D';
18
8
  import type { MakeMandatory } from '../../utilities/MakeMandatory';
19
9
  import type { NMRSignal2D } from '../../xyz/NMRSignal2D';
20
10
  import { NMRZone } from '../../xyz/NMRZone';
21
- import type { Prediction1D } from '../Prediction1D';
22
- import { Prediction2D } from '../Prediction2D';
11
+ import { GroupDiastereotopicAtomIDs } from '../GroupDiastereotopicAtomIDs';
12
+ import { PredictionBase1D } from '../PredictionBase1D';
13
+ import { PredictionBase2D } from '../PredictionBase2D';
23
14
  import type { PredictCarbon, PredictCarbonOptions } from '../predictCarbon';
24
15
  import type { PredictProton, PredictProtonOptions } from '../predictProton';
25
16
 
26
17
  import { getNuclei } from './getNuclei';
27
- import { getPredictions } from './getPredictions';
28
18
 
29
19
  /**
30
20
  * Generate the correlation bidimensional nmr peaks based on the number of bonds between a pair of atoms
@@ -63,15 +53,6 @@ export interface Predict2DOptions {
63
53
  * @default 0
64
54
  */
65
55
  minLength?: number;
66
- /**
67
- * mono dimensional predictors.
68
- */
69
- predictor?: Predictors;
70
- /**
71
- * mono dimensional signal to generate the bidimenionals cross peaks.
72
- * The object should has properties with name equal to "H" and "C".
73
- */
74
- predictOptions?: PredictOptions;
75
56
  /**
76
57
  * signals with euclidean distance in ppm less than this it will
77
58
  * joined into a zone.
@@ -83,7 +64,7 @@ export interface Predict2DOptions {
83
64
  * The object should has properties with name equal to "H" and "C".
84
65
  * the value of each prediction should be similar that predictProton and predictCarbon.
85
66
  */
86
- predictions?: Predictions;
67
+ predictions: Predictions;
87
68
  /**
88
69
  * if true, the self correlation signal will be add to the prediction.
89
70
  * @default false
@@ -92,7 +73,12 @@ export interface Predict2DOptions {
92
73
  /**
93
74
  * diastereotopic atom ids of the molecule.
94
75
  */
95
- diaIDs?: string[];
76
+ diaIDs: string[];
77
+ /**
78
+ * grouped diastereotopic atom ids of the molecule.
79
+ */
80
+ groupedDiaIDs: GroupDiastereotopicAtomIDs[];
81
+ distanceMatrix: number[][];
96
82
  }
97
83
 
98
84
  export interface PredictOptions {
@@ -101,10 +87,10 @@ export interface PredictOptions {
101
87
  C?: PredictCarbonOptions;
102
88
  }
103
89
 
104
- export type Predictions = Record<string, Prediction1D | undefined>;
90
+ export type Predictions = Record<string, PredictionBase1D | undefined>;
105
91
 
106
92
  type GroupDiastereotopicAtomIDsWithAtomInfo = GroupDiastereotopicAtomIDs & {
107
- pathInfo: PathInfo;
93
+ pathInfo: AtomPartialPathInfo;
108
94
  };
109
95
 
110
96
  type PredictHMBCOptionsWithFromTo = MakeMandatory<
@@ -122,10 +108,7 @@ function checkFromTo(
122
108
 
123
109
  type Signal1DByDiaID = Record<string, Record<string, NMRSignal1D>>;
124
110
 
125
- export async function predict2D(
126
- molecule: Molecule,
127
- options: Predict2DOptions = {},
128
- ) {
111
+ export async function predict2D(molecule: Molecule, options: Predict2DOptions) {
129
112
  checkFromTo(options);
130
113
 
131
114
  molecule.addImplicitHydrogens();
@@ -134,60 +117,41 @@ export async function predict2D(
134
117
  from,
135
118
  to,
136
119
  diaIDs,
120
+ groupedDiaIDs,
137
121
  minLength = 0,
138
122
  maxLength,
139
- predictOptions = {},
140
123
  predictions,
141
- predictor,
124
+ distanceMatrix,
142
125
  joinDistance = { H: 0.05, C: 0.5 },
143
126
  includeDiagonal = false,
144
127
  } = options;
145
128
 
146
- const pathsInfo = getPathsInfo(molecule, {
129
+ const pathsInfo = getPossibleCorrelations({
130
+ molecule,
147
131
  fromLabel: from,
148
132
  toLabel: to,
133
+ diaIDs,
134
+ distanceMatrix,
149
135
  minLength,
150
136
  maxLength,
151
137
  });
152
138
 
153
- const groupedDiaIDS = diaIDs
154
- ? groupDiastereotopicAtomIDs(diaIDs, molecule)
155
- : getGroupedDiastereotopicAtomIDs(molecule);
156
-
157
139
  const diaIDswithAtomInfo: GroupDiastereotopicAtomIDsWithAtomInfo[] = [];
158
- for (const diaID of groupedDiaIDS) {
140
+ for (const diaID of groupedDiaIDs) {
159
141
  diaIDswithAtomInfo.push({
160
142
  ...diaID,
161
- pathInfo: JSON.parse(
162
- JSON.stringify(pathsInfo[diaID.atoms[0]]),
163
- ) as PathInfo,
143
+ pathInfo: JSON.parse(JSON.stringify(pathsInfo[diaID.atoms[0]])),
164
144
  });
165
145
  }
166
146
 
167
- const xPrediction = await getPredictions(
168
- from,
169
- molecule,
170
- predictOptions,
171
- predictor,
172
- predictions,
173
- );
174
-
175
- const yPrediction =
176
- from === to
177
- ? xPrediction
178
- : await getPredictions(
179
- to,
180
- molecule,
181
- predictOptions,
182
- predictor,
183
- predictions,
184
- );
147
+ const yPrediction = predictions[to];
148
+ const xPrediction = predictions[from];
185
149
 
186
150
  if (!xPrediction || !yPrediction) {
187
151
  throw new Error('predictions are not availaible');
188
152
  }
189
153
 
190
- const spectra: Record<string, Prediction1D> = {
154
+ const spectra: Record<string, PredictionBase1D> = {
191
155
  x: xPrediction,
192
156
  y: yPrediction,
193
157
  };
@@ -202,6 +166,7 @@ export async function predict2D(
202
166
  signalsByDiaID[axis][signal.diaIDs[0]] = signal;
203
167
  }
204
168
  }
169
+
205
170
  const group: Record<string, NMRSignal2D> = {};
206
171
  for (const diaID of diaIDswithAtomInfo) {
207
172
  const pathInfo = diaID.pathInfo;
@@ -213,13 +178,12 @@ export async function predict2D(
213
178
  for (const path of currentPaths) {
214
179
  if (!signalsByDiaID.y[pathsInfo[path.to].oclID]) continue;
215
180
 
216
- const fromToDiaID: Record<string, AtomInfo> = {
181
+ const fromToDiaID: Record<string, AtomPartialPathInfo> = {
217
182
  x: pathInfo,
218
183
  y: pathsInfo[path.to],
219
184
  };
220
185
 
221
186
  const key = `${fromToDiaID.x.oclID}-${fromToDiaID.y.oclID}`;
222
-
223
187
  if (key === `${pathInfo.oclID}-${pathInfo.oclID}` || group[key]) {
224
188
  continue;
225
189
  }
@@ -240,7 +204,7 @@ export async function predict2D(
240
204
  }
241
205
 
242
206
  if (includeDiagonal) {
243
- addSelftCorrelation(group, { paths: pathsInfo, signalsByDiaID });
207
+ addSelfCorrelation(group, { paths: pathsInfo, signalsByDiaID });
244
208
  }
245
209
 
246
210
  // clusterize signals by distance
@@ -248,14 +212,50 @@ export async function predict2D(
248
212
  const zones = createZones(joinedSignals, { joinDistance, from, to });
249
213
 
250
214
  return {
251
- molfile: molecule.toMolfile(),
252
- diaIDs: spectra.x.diaIDs,
253
215
  nuclei: getNuclei({ from, to }),
254
216
  joinedSignals,
255
217
  signals: splitSignals(joinedSignals),
256
218
  zones,
219
+ } as PredictionBase2D;
220
+ }
221
+
222
+ interface AtomPartialPathInfo {
223
+ oclID: string;
224
+ paths: Array<{ from: number; to: number }>;
225
+ }
226
+ function getPossibleCorrelations(options: any) {
227
+ const {
228
+ fromLabel,
229
+ toLabel,
230
+ distanceMatrix,
257
231
  molecule,
258
- } as Prediction2D;
232
+ diaIDs,
233
+ minLength,
234
+ maxLength,
235
+ } = options;
236
+ const fromAtomicNumber = Molecule.getAtomicNoFromLabel(fromLabel);
237
+ const toAtomicNumber = Molecule.getAtomicNoFromLabel(toLabel);
238
+ const atomPathInfo: AtomPartialPathInfo[] = [];
239
+ for (let from = 0; from < molecule.getAllAtoms(); from++) {
240
+ const toSave: AtomPartialPathInfo = {
241
+ oclID: diaIDs[from],
242
+ paths: [],
243
+ };
244
+ for (let to = 0; to < molecule.getAllAtoms(); to++) {
245
+ if (from === to) continue;
246
+ if (molecule.getAtomicNo(to) !== toAtomicNumber) continue;
247
+ if (molecule.getAtomicNo(from) !== fromAtomicNumber) continue;
248
+ const pathLength = distanceMatrix[from][to];
249
+ if (pathLength >= minLength && pathLength <= maxLength) {
250
+ toSave.paths.push({
251
+ from,
252
+ to,
253
+ });
254
+ }
255
+ }
256
+ atomPathInfo.push(toSave);
257
+ }
258
+ return atomPathInfo;
259
259
  }
260
260
 
261
261
  function splitSignals(joinedSignals: NMRSignal2D[]) {
@@ -274,10 +274,10 @@ function splitSignals(joinedSignals: NMRSignal2D[]) {
274
274
  }
275
275
 
276
276
  interface AddSelftCorrelationOptions {
277
- paths: PathInfo[];
277
+ paths: AtomPartialPathInfo[];
278
278
  signalsByDiaID: Signal1DByDiaID;
279
279
  }
280
- function addSelftCorrelation(
280
+ function addSelfCorrelation(
281
281
  group: Record<string, NMRSignal2D>,
282
282
  options: AddSelftCorrelationOptions,
283
283
  ) {
@@ -1,6 +1,6 @@
1
1
  import type { DataBaseStructure } from '../dataStructure';
2
2
 
3
- import type { GroupedDiaIDsWithHose } from './getFilteredIDiaIDs';
3
+ // import type { GroupedDiaIDsWithHose } from './getFilteredIDiaIDs';
4
4
 
5
5
  export interface Prediction {
6
6
  diaIDs: string[];
@@ -17,7 +17,7 @@ export interface Prediction {
17
17
  };
18
18
  }
19
19
  export function queryByHose(
20
- diaIDs: GroupedDiaIDsWithHose,
20
+ diaIDs: any,
21
21
  db: DataBaseStructure,
22
22
  options: { maxSphereSize: number },
23
23
  ): Prediction[] {
@@ -0,0 +1,14 @@
1
+ import { PredictionOptionsByExperiment } from '../predict';
2
+
3
+ export function shouldPredict(
4
+ key: keyof PredictionOptionsByExperiment,
5
+ options: PredictionOptionsByExperiment,
6
+ ) {
7
+ if (key in options) return true;
8
+ const heteroRequired = 'hsqc' in options || 'hmbc' in options;
9
+ return key === 'C'
10
+ ? heteroRequired
11
+ : key === 'H'
12
+ ? heteroRequired || 'cosy' in options
13
+ : false;
14
+ }