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.
- package/lib/assignment/get13CAssignments.js +7 -4
- package/lib/assignment/get13CAssignments.js.map +1 -1
- package/lib/assignment/get1HAssignments.js +7 -5
- package/lib/assignment/get1HAssignments.js.map +1 -1
- package/lib/assignment/utils/generalAssignment/buildAssignments.d.ts +3 -1
- package/lib/assignment/utils/generalAssignment/buildAssignments.js +18 -7
- package/lib/assignment/utils/generalAssignment/buildAssignments.js.map +1 -1
- package/lib/index.d.ts +2 -7
- package/lib/index.js +2 -7
- package/lib/index.js.map +1 -1
- package/lib/prediction/GroupDiastereotopicAtomIDs.d.ts +6 -0
- package/lib/prediction/GroupDiastereotopicAtomIDs.js +3 -0
- package/lib/prediction/GroupDiastereotopicAtomIDs.js.map +1 -0
- package/lib/prediction/Prediction1D.d.ts +2 -7
- package/lib/prediction/Prediction2D.d.ts +2 -7
- package/lib/prediction/PredictionBase1D.d.ts +8 -0
- package/lib/prediction/PredictionBase1D.js +3 -0
- package/lib/prediction/PredictionBase1D.js.map +1 -0
- package/lib/prediction/PredictionBase2D.d.ts +8 -0
- package/lib/prediction/PredictionBase2D.js +3 -0
- package/lib/prediction/PredictionBase2D.js.map +1 -0
- package/lib/prediction/predict.d.ts +55 -0
- package/lib/prediction/predict.js +113 -0
- package/lib/prediction/predict.js.map +1 -0
- package/lib/prediction/predictCOSY.d.ts +15 -13
- package/lib/prediction/predictCOSY.js +3 -6
- package/lib/prediction/predictCOSY.js.map +1 -1
- package/lib/prediction/predictCarbon.d.ts +12 -4
- package/lib/prediction/predictCarbon.js +10 -16
- package/lib/prediction/predictCarbon.js.map +1 -1
- package/lib/prediction/predictHMBC.d.ts +16 -25
- package/lib/prediction/predictHMBC.js +3 -7
- package/lib/prediction/predictHMBC.js.map +1 -1
- package/lib/prediction/predictHSQC.d.ts +16 -25
- package/lib/prediction/predictHSQC.js +3 -7
- package/lib/prediction/predictHSQC.js.map +1 -1
- package/lib/prediction/predictProton.d.ts +7 -4
- package/lib/prediction/predictProton.js +8 -21
- package/lib/prediction/predictProton.js.map +1 -1
- package/lib/prediction/{predictAllSpectra.d.ts → predictSpectra.d.ts} +1 -1
- package/lib/prediction/{predictAllSpectra.js → predictSpectra.js} +7 -5
- package/lib/prediction/predictSpectra.js.map +1 -0
- package/lib/prediction/utils/fetchPrediction.d.ts +2 -3
- package/lib/prediction/utils/fetchPrediction.js +12 -7
- package/lib/prediction/utils/fetchPrediction.js.map +1 -1
- package/lib/prediction/utils/getFilteredIDiaIDs.d.ts +4 -13
- package/lib/prediction/utils/getFilteredIDiaIDs.js +7 -20
- package/lib/prediction/utils/getFilteredIDiaIDs.js.map +1 -1
- package/lib/prediction/utils/isMolfileNotEmpty.d.ts +1 -0
- package/lib/prediction/utils/isMolfileNotEmpty.js +12 -0
- package/lib/prediction/utils/isMolfileNotEmpty.js.map +1 -0
- package/lib/prediction/utils/predict2D.d.ts +13 -16
- package/lib/prediction/utils/predict2D.js +41 -18
- package/lib/prediction/utils/predict2D.js.map +1 -1
- package/lib/prediction/utils/queryByHOSE.d.ts +1 -2
- package/lib/prediction/utils/queryByHOSE.js.map +1 -1
- package/lib/prediction/utils/shouldPredict.d.ts +2 -0
- package/lib/prediction/utils/shouldPredict.js +15 -0
- package/lib/prediction/utils/shouldPredict.js.map +1 -0
- package/lib-esm/assignment/get13CAssignments.js +7 -4
- package/lib-esm/assignment/get13CAssignments.js.map +1 -1
- package/lib-esm/assignment/get1HAssignments.js +7 -5
- package/lib-esm/assignment/get1HAssignments.js.map +1 -1
- package/lib-esm/assignment/utils/generalAssignment/buildAssignments.js +18 -7
- package/lib-esm/assignment/utils/generalAssignment/buildAssignments.js.map +1 -1
- package/lib-esm/index.js +2 -7
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/prediction/GroupDiastereotopicAtomIDs.js +2 -0
- package/lib-esm/prediction/GroupDiastereotopicAtomIDs.js.map +1 -0
- package/lib-esm/prediction/PredictionBase1D.js +2 -0
- package/lib-esm/prediction/PredictionBase1D.js.map +1 -0
- package/lib-esm/prediction/PredictionBase2D.js +2 -0
- package/lib-esm/prediction/PredictionBase2D.js.map +1 -0
- package/lib-esm/prediction/predict.js +109 -0
- package/lib-esm/prediction/predict.js.map +1 -0
- package/lib-esm/prediction/predictCOSY.js +3 -6
- package/lib-esm/prediction/predictCOSY.js.map +1 -1
- package/lib-esm/prediction/predictCarbon.js +10 -16
- package/lib-esm/prediction/predictCarbon.js.map +1 -1
- package/lib-esm/prediction/predictHMBC.js +3 -7
- package/lib-esm/prediction/predictHMBC.js.map +1 -1
- package/lib-esm/prediction/predictHSQC.js +3 -7
- package/lib-esm/prediction/predictHSQC.js.map +1 -1
- package/lib-esm/prediction/predictProton.js +8 -21
- package/lib-esm/prediction/predictProton.js.map +1 -1
- package/lib-esm/prediction/{predictAllSpectra.js → predictSpectra.js} +7 -5
- package/lib-esm/prediction/predictSpectra.js.map +1 -0
- package/lib-esm/prediction/utils/fetchPrediction.js +12 -7
- package/lib-esm/prediction/utils/fetchPrediction.js.map +1 -1
- package/lib-esm/prediction/utils/getFilteredIDiaIDs.js +7 -20
- package/lib-esm/prediction/utils/getFilteredIDiaIDs.js.map +1 -1
- package/lib-esm/prediction/utils/isMolfileNotEmpty.js +8 -0
- package/lib-esm/prediction/utils/isMolfileNotEmpty.js.map +1 -0
- package/lib-esm/prediction/utils/predict2D.js +41 -18
- package/lib-esm/prediction/utils/predict2D.js.map +1 -1
- package/lib-esm/prediction/utils/queryByHOSE.js.map +1 -1
- package/lib-esm/prediction/utils/shouldPredict.js +11 -0
- package/lib-esm/prediction/utils/shouldPredict.js.map +1 -0
- package/package.json +2 -3
- package/src/assignment/get13CAssignments.ts +9 -8
- package/src/assignment/get1HAssignments.ts +8 -9
- package/src/assignment/utils/generalAssignment/buildAssignments.ts +28 -12
- package/src/index.ts +3 -8
- package/src/prediction/GroupDiastereotopicAtomIDs.ts +6 -0
- package/src/prediction/Prediction1D.ts +2 -7
- package/src/prediction/Prediction2D.ts +2 -7
- package/src/prediction/PredictionBase1D.ts +9 -0
- package/src/prediction/PredictionBase2D.ts +9 -0
- package/src/prediction/predict.ts +201 -0
- package/src/prediction/predictCOSY.ts +18 -18
- package/src/prediction/predictCarbon.ts +28 -26
- package/src/prediction/predictHMBC.ts +17 -27
- package/src/prediction/predictHSQC.ts +18 -25
- package/src/prediction/predictProton.ts +16 -30
- package/src/prediction/{predictAllSpectra.ts → predictSpectra.ts} +6 -4
- package/src/prediction/utils/fetchPrediction.ts +15 -10
- package/src/prediction/utils/getFilteredIDiaIDs.ts +16 -49
- package/src/prediction/utils/isMolfileNotEmpty.ts +8 -0
- package/src/prediction/utils/predict2D.ts +69 -69
- package/src/prediction/utils/queryByHOSE.ts +2 -2
- package/src/prediction/utils/shouldPredict.ts +14 -0
- package/lib/prediction/predictAll.d.ts +0 -64
- package/lib/prediction/predictAll.js +0 -82
- package/lib/prediction/predictAll.js.map +0 -1
- package/lib/prediction/predictAllSpectra.js.map +0 -1
- package/lib/prediction/utils/getPredictions.d.ts +0 -4
- package/lib/prediction/utils/getPredictions.js +0 -18
- package/lib/prediction/utils/getPredictions.js.map +0 -1
- package/lib-esm/prediction/predictAll.js +0 -78
- package/lib-esm/prediction/predictAll.js.map +0 -1
- package/lib-esm/prediction/predictAllSpectra.js.map +0 -1
- package/lib-esm/prediction/utils/getPredictions.js +0 -14
- package/lib-esm/prediction/utils/getPredictions.js.map +0 -1
- package/src/openchemlib-utils.d.ts +0 -167
- package/src/prediction/predictAll.ts +0 -157
- package/src/prediction/utils/getPredictions.ts +0 -24
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Molecule } from 'openchemlib/full';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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]:
|
|
42
|
-
H?:
|
|
43
|
-
C?:
|
|
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
|
|
16
|
-
import {
|
|
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
|
|
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
|
-
|
|
38
|
-
options: PredictProtonOptions
|
|
39
|
-
): Promise<
|
|
40
|
-
if (
|
|
35
|
+
molfile: string,
|
|
36
|
+
options: PredictProtonOptions,
|
|
37
|
+
): Promise<PredictionBase1D> {
|
|
38
|
+
if (!isMolfileNotEmpty(molfile)) {
|
|
41
39
|
return {
|
|
42
|
-
|
|
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
|
|
76
|
-
const signals = protonParser(result,
|
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
|
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 {
|
|
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
|
|
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
|
-
|
|
12
|
+
molfile: string,
|
|
12
13
|
options: FetchPredictionOptions,
|
|
13
|
-
): Promise<
|
|
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
|
|
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
|
-
|
|
30
|
-
.getOCL()
|
|
31
|
-
.Molecule.fromMolfile(prediction.molfile);
|
|
32
|
-
return prediction;
|
|
37
|
+
return (await response.json()).data;
|
|
33
38
|
}
|
|
@@ -1,54 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 =
|
|
41
|
-
OCL.Molecule.fromIDCode(diaId.oclID),
|
|
42
|
-
{
|
|
43
|
-
maxSphereSize,
|
|
44
|
-
},
|
|
45
|
-
);
|
|
17
|
+
diaId.hose = hoses[diaId.atoms[0]];
|
|
46
18
|
}
|
|
47
19
|
|
|
48
|
-
|
|
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
|
|
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
|
|
22
|
-
import {
|
|
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
|
|
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
|
|
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,
|
|
90
|
+
export type Predictions = Record<string, PredictionBase1D | undefined>;
|
|
105
91
|
|
|
106
92
|
type GroupDiastereotopicAtomIDsWithAtomInfo = GroupDiastereotopicAtomIDs & {
|
|
107
|
-
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
|
-
|
|
124
|
+
distanceMatrix,
|
|
142
125
|
joinDistance = { H: 0.05, C: 0.5 },
|
|
143
126
|
includeDiagonal = false,
|
|
144
127
|
} = options;
|
|
145
128
|
|
|
146
|
-
const pathsInfo =
|
|
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
|
|
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
|
|
168
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
277
|
+
paths: AtomPartialPathInfo[];
|
|
278
278
|
signalsByDiaID: Signal1DByDiaID;
|
|
279
279
|
}
|
|
280
|
-
function
|
|
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:
|
|
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
|
+
}
|