nmr-processing 7.4.3 → 8.2.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/getAssignments.js +1 -1
- package/lib/assignment/getAssignments.js.map +1 -1
- package/lib/assignment/utils/getAssignment/checkIDs.d.ts +1 -1
- package/lib/assignment/utils/getAssignment/checkIDs.js.map +1 -1
- package/lib/databases/getDatabase.d.ts +6 -1
- package/lib/databases/getDatabase.js +13 -3
- package/lib/databases/getDatabase.js.map +1 -1
- package/lib/index.d.ts +4 -2
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/peaks/NMRPeak1D.d.ts +0 -1
- package/lib/peaks/peaksToRanges.d.ts +16 -0
- package/lib/peaks/peaksToRanges.js +2 -1
- package/lib/peaks/peaksToRanges.js.map +1 -1
- package/lib/peaks/solventSuppression.d.ts +3 -0
- package/lib/peaks/solventSuppression.js +155 -0
- package/lib/peaks/solventSuppression.js.map +1 -0
- package/lib/peaks/util/jAnalyzer.d.ts +1 -1
- package/lib/peaks/util/jAnalyzer.js +3 -2
- package/lib/peaks/util/jAnalyzer.js.map +1 -1
- package/lib/prediction/predictAllSpectra.d.ts +22 -4
- package/lib/prediction/predictAllSpectra.js +102 -16
- package/lib/prediction/predictAllSpectra.js.map +1 -1
- package/lib/ranges/markSolventSignal.d.ts +3 -0
- package/lib/ranges/markSolventSignal.js +107 -0
- package/lib/ranges/markSolventSignal.js.map +1 -0
- package/lib/ranges/rangesToXY.js +27 -3
- package/lib/ranges/rangesToXY.js.map +1 -1
- package/lib/signals/addDummySignals.d.ts +2 -0
- package/lib/signals/addDummySignals.js +56 -0
- package/lib/signals/addDummySignals.js.map +1 -0
- package/lib/signals/hackSignalsToXY.js +2 -48
- package/lib/signals/hackSignalsToXY.js.map +1 -1
- package/lib/signals/simulation/simulate1D.d.ts +1 -39
- package/lib/signals/simulation/simulate1D.js +13 -240
- package/lib/signals/simulation/simulate1D.js.map +1 -1
- package/lib/signals/simulation/simulateXYPeaks.d.ts +47 -0
- package/lib/signals/simulation/simulateXYPeaks.js +246 -0
- package/lib/signals/simulation/simulateXYPeaks.js.map +1 -0
- package/lib/utilities/getFrequency.d.ts +1 -1
- package/lib/utilities/getFrequency.js +4 -4
- package/lib/utilities/getFrequency.js.map +1 -1
- package/lib/xyz/NMRSignal2D.d.ts +3 -3
- package/lib/xyz/util/formatZone.d.ts +3 -0
- package/lib/xyz/util/formatZone.js +38 -0
- package/lib/xyz/util/formatZone.js.map +1 -0
- package/lib/xyz/xyzAutoZonesPicking.d.ts +1 -2
- package/lib/xyz/xyzAutoZonesPicking.js +2 -34
- package/lib/xyz/xyzAutoZonesPicking.js.map +1 -1
- package/lib/xyz/xyzJResAnalyzer.d.ts +6 -1
- package/lib/xyz/xyzJResAnalyzer.js +9 -8
- package/lib/xyz/xyzJResAnalyzer.js.map +1 -1
- package/lib-esm/assignment/getAssignments.js +1 -1
- package/lib-esm/assignment/getAssignments.js.map +1 -1
- package/lib-esm/assignment/utils/getAssignment/checkIDs.js.map +1 -1
- package/lib-esm/databases/getDatabase.js +13 -3
- package/lib-esm/databases/getDatabase.js.map +1 -1
- package/lib-esm/index.js +3 -1
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/peaks/peaksToRanges.js +1 -1
- package/lib-esm/peaks/peaksToRanges.js.map +1 -1
- package/lib-esm/peaks/solventSuppression.js +151 -0
- package/lib-esm/peaks/solventSuppression.js.map +1 -0
- package/lib-esm/peaks/util/jAnalyzer.js +3 -2
- package/lib-esm/peaks/util/jAnalyzer.js.map +1 -1
- package/lib-esm/prediction/predictAllSpectra.js +102 -16
- package/lib-esm/prediction/predictAllSpectra.js.map +1 -1
- package/lib-esm/ranges/markSolventSignal.js +100 -0
- package/lib-esm/ranges/markSolventSignal.js.map +1 -0
- package/lib-esm/ranges/rangesToXY.js +27 -3
- package/lib-esm/ranges/rangesToXY.js.map +1 -1
- package/lib-esm/signals/addDummySignals.js +52 -0
- package/lib-esm/signals/addDummySignals.js.map +1 -0
- package/lib-esm/signals/hackSignalsToXY.js +2 -48
- package/lib-esm/signals/hackSignalsToXY.js.map +1 -1
- package/lib-esm/signals/simulation/simulate1D.js +14 -238
- package/lib-esm/signals/simulation/simulate1D.js.map +1 -1
- package/lib-esm/signals/simulation/simulateXYPeaks.js +239 -0
- package/lib-esm/signals/simulation/simulateXYPeaks.js.map +1 -0
- package/lib-esm/utilities/getFrequency.js +1 -1
- package/lib-esm/utilities/getFrequency.js.map +1 -1
- package/lib-esm/xyz/util/formatZone.js +34 -0
- package/lib-esm/xyz/util/formatZone.js.map +1 -0
- package/lib-esm/xyz/xyzAutoZonesPicking.js +1 -33
- package/lib-esm/xyz/xyzAutoZonesPicking.js.map +1 -1
- package/lib-esm/xyz/xyzJResAnalyzer.js +9 -8
- package/lib-esm/xyz/xyzJResAnalyzer.js.map +1 -1
- package/package.json +14 -12
- package/src/assignment/getAssignments.ts +1 -1
- package/src/assignment/utils/getAssignment/checkIDs.ts +1 -1
- package/src/databases/getDatabase.ts +19 -2
- package/src/index.ts +5 -2
- package/src/peaks/NMRPeak1D.ts +0 -1
- package/src/peaks/peaksToRanges.ts +1 -1
- package/src/peaks/solventSuppression.ts +209 -0
- package/src/peaks/util/jAnalyzer.ts +5 -3
- package/src/prediction/predictAllSpectra.ts +151 -14
- package/src/ranges/markSolventSignal.ts +121 -0
- package/src/ranges/rangesToXY.ts +33 -4
- package/src/signals/addDummySignals.ts +77 -0
- package/src/signals/hackSignalsToXY.ts +2 -72
- package/src/signals/simulation/simulate1D.ts +14 -319
- package/src/signals/simulation/simulateXYPeaks.ts +332 -0
- package/src/utilities/getFrequency.ts +1 -1
- package/src/xyz/NMRSignal2D.ts +3 -3
- package/src/xyz/util/formatZone.ts +36 -0
- package/src/xyz/xyzAutoZonesPicking.ts +1 -35
- package/src/xyz/xyzJResAnalyzer.ts +14 -7
- package/lib/constants/gyromagneticRatio.d.ts +0 -6
- package/lib/constants/gyromagneticRatio.js +0 -26
- package/lib/constants/gyromagneticRatio.js.map +0 -1
- package/lib-esm/constants/gyromagneticRatio.js +0 -23
- package/lib-esm/constants/gyromagneticRatio.js.map +0 -1
- package/src/constants/gyromagneticRatio.ts +0 -49
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const binary_search_1 = __importDefault(require("binary-search"));
|
|
7
|
-
const ml_matrix_1 = require("ml-matrix");
|
|
8
|
-
const ml_sparse_matrix_1 = require("ml-sparse-matrix");
|
|
9
3
|
const spectrum_generator_1 = require("spectrum-generator");
|
|
10
|
-
const
|
|
11
|
-
const smallValue = 1e-2;
|
|
4
|
+
const simulateXYPeaks_1 = require("./simulateXYPeaks");
|
|
12
5
|
/**
|
|
13
6
|
* This function simulates a one dimensional nmr spectrum. This function returns an array containing the relative intensities of the spectrum in the specified simulation window (from-to).
|
|
14
7
|
*/
|
|
@@ -17,242 +10,22 @@ function simulate1D(
|
|
|
17
10
|
* The SpinSystem object to be simulated
|
|
18
11
|
*/
|
|
19
12
|
spinSystem, options = {}) {
|
|
20
|
-
let { lineWidth = 1,
|
|
13
|
+
let { lineWidth = 1, frequency: frequencyMHz = 400, from = 0, to = 10, nbPoints = 1024, shape = {
|
|
21
14
|
kind: 'gaussian',
|
|
22
15
|
}, } = options;
|
|
23
16
|
let peakWidth = lineWidth / frequencyMHz;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
const xyPeaks = (0, simulateXYPeaks_1.simulateXYPeaks)(spinSystem, options);
|
|
18
|
+
return (0, spectrum_generator_1.generateSpectrum)(xyPeaks, {
|
|
19
|
+
generator: {
|
|
20
|
+
from,
|
|
21
|
+
to,
|
|
22
|
+
nbPoints,
|
|
23
|
+
},
|
|
24
|
+
peakOptions: {
|
|
25
|
+
shape,
|
|
26
|
+
width: peakWidth,
|
|
27
|
+
},
|
|
30
28
|
});
|
|
31
|
-
const chemicalShifts = spinSystem.chemicalShifts.slice();
|
|
32
|
-
for (let i = 0; i < chemicalShifts.length; i++) {
|
|
33
|
-
chemicalShifts[i] = chemicalShifts[i] * frequencyMHz;
|
|
34
|
-
}
|
|
35
|
-
const multiplicity = spinSystem.multiplicity;
|
|
36
|
-
for (const cluster of spinSystem.clusters) {
|
|
37
|
-
let clusterFake = cluster.map((cluster) => cluster < 0 ? -cluster - 1 : cluster);
|
|
38
|
-
let weight = 1;
|
|
39
|
-
let sumI = 0;
|
|
40
|
-
let frequencies = [];
|
|
41
|
-
let intensities = [];
|
|
42
|
-
if (cluster.length > maxClusterSize) {
|
|
43
|
-
// This is a single spin, but the cluster exceeds the maxClusterSize criteria
|
|
44
|
-
// we use the simple multiplicity algorithm
|
|
45
|
-
// Add the central peak. It will be split with every single J coupling.
|
|
46
|
-
let index = 0;
|
|
47
|
-
while (cluster[index++] < 0)
|
|
48
|
-
;
|
|
49
|
-
index = cluster[index - 1];
|
|
50
|
-
frequencies.push(-chemicalShifts[index]);
|
|
51
|
-
for (let i = 0; i < cluster.length; i++) {
|
|
52
|
-
if (cluster[i] < 0) {
|
|
53
|
-
let jc = spinSystem.couplingConstants.get(index, clusterFake[i]) / 2;
|
|
54
|
-
let currentSize = frequencies.length;
|
|
55
|
-
for (let j = 0; j < currentSize; j++) {
|
|
56
|
-
frequencies.push(frequencies[j] + jc);
|
|
57
|
-
frequencies[j] -= jc;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
frequencies.sort((a, b) => a - b);
|
|
62
|
-
sumI = frequencies.length;
|
|
63
|
-
weight = 1;
|
|
64
|
-
for (let i = 0; i < sumI; i++) {
|
|
65
|
-
intensities.push(1);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
const hamiltonian = getHamiltonian(chemicalShifts, spinSystem.couplingConstants, multiplicity, spinSystem.connectivity, clusterFake);
|
|
70
|
-
const hamSize = hamiltonian.rows;
|
|
71
|
-
// TODO: add support for sparse matrix in matrix types.
|
|
72
|
-
// @ts-expect-error sparse matrix not supported
|
|
73
|
-
const evd = new ml_matrix_1.EVD(hamiltonian);
|
|
74
|
-
const V = evd.eigenvectorMatrix;
|
|
75
|
-
const diagB = evd.realEigenvalues;
|
|
76
|
-
const assignmentMatrix = new ml_sparse_matrix_1.SparseMatrix(hamSize, hamSize);
|
|
77
|
-
const multLen = cluster.length;
|
|
78
|
-
weight = 0;
|
|
79
|
-
for (let n = 0; n < multLen; n++) {
|
|
80
|
-
const L = (0, getPauliMatrix_1.default)(multiplicity[clusterFake[n]]);
|
|
81
|
-
let temp = 1;
|
|
82
|
-
for (let j = 0; j < n; j++) {
|
|
83
|
-
temp *= multiplicity[clusterFake[j]];
|
|
84
|
-
}
|
|
85
|
-
const A = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
86
|
-
temp = 1;
|
|
87
|
-
for (let j = n + 1; j < multLen; j++) {
|
|
88
|
-
temp *= multiplicity[clusterFake[j]];
|
|
89
|
-
}
|
|
90
|
-
const B = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
91
|
-
const tempMat = A.kroneckerProduct(L.m).kroneckerProduct(B);
|
|
92
|
-
if (cluster[n] >= 0) {
|
|
93
|
-
assignmentMatrix.add(tempMat.mul(cluster[n] + 1));
|
|
94
|
-
weight++;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
assignmentMatrix.add(tempMat.mul(cluster[n]));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
let rhoip = ml_matrix_1.Matrix.zeros(hamSize, hamSize);
|
|
101
|
-
assignmentMatrix.forEachNonZero((i, j, v) => {
|
|
102
|
-
if (v > 0) {
|
|
103
|
-
for (let k = 0; k < V.columns; k++) {
|
|
104
|
-
let element = V.get(j, k);
|
|
105
|
-
if (element !== 0) {
|
|
106
|
-
rhoip.set(i, k, rhoip.get(i, k) + element);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return v;
|
|
111
|
-
});
|
|
112
|
-
let rhoip2 = rhoip.clone();
|
|
113
|
-
assignmentMatrix.forEachNonZero((i, j, v) => {
|
|
114
|
-
if (v < 0) {
|
|
115
|
-
for (let k = 0; k < V.columns; k++) {
|
|
116
|
-
let element = V.get(j, k);
|
|
117
|
-
if (element !== 0) {
|
|
118
|
-
rhoip2.set(i, k, rhoip2.get(i, k) + element);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return v;
|
|
123
|
-
});
|
|
124
|
-
const tV = V.transpose();
|
|
125
|
-
rhoip = tV.mmul(rhoip);
|
|
126
|
-
const sparseRhoip = new ml_sparse_matrix_1.SparseMatrix(rhoip.to2DArray(), {
|
|
127
|
-
threshold: smallValue,
|
|
128
|
-
});
|
|
129
|
-
triuTimesAbs(sparseRhoip, smallValue);
|
|
130
|
-
rhoip2 = tV.mmul(rhoip2);
|
|
131
|
-
const sparseRhoip2 = new ml_sparse_matrix_1.SparseMatrix(rhoip2.to2DArray(), {
|
|
132
|
-
threshold: smallValue,
|
|
133
|
-
});
|
|
134
|
-
sparseRhoip2.forEachNonZero((i, j, v) => {
|
|
135
|
-
return v;
|
|
136
|
-
});
|
|
137
|
-
triuTimesAbs(sparseRhoip2, smallValue);
|
|
138
|
-
sparseRhoip2.forEachNonZero((i, j, v) => {
|
|
139
|
-
let val = rhoip.get(i, j);
|
|
140
|
-
val = Math.min(Math.abs(val), Math.abs(v));
|
|
141
|
-
val *= val;
|
|
142
|
-
sumI += val;
|
|
143
|
-
let valFreq = diagB[i] - diagB[j];
|
|
144
|
-
let insertIn = (0, binary_search_1.default)(frequencies, valFreq, (a, b) => a - b);
|
|
145
|
-
if (insertIn < 0) {
|
|
146
|
-
frequencies.splice(-1 - insertIn, 0, valFreq);
|
|
147
|
-
intensities.splice(-1 - insertIn, 0, val);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
intensities[insertIn] += val;
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
const numFreq = frequencies.length;
|
|
155
|
-
if (numFreq > 0) {
|
|
156
|
-
weight /= sumI;
|
|
157
|
-
const diff = lineWidth / 64;
|
|
158
|
-
let valFreq = frequencies[0];
|
|
159
|
-
let inte = intensities[0];
|
|
160
|
-
let count = 1;
|
|
161
|
-
for (let i = 1; i < numFreq; i++) {
|
|
162
|
-
if (Math.abs(frequencies[i] - valFreq / count) < diff) {
|
|
163
|
-
inte += intensities[i];
|
|
164
|
-
valFreq += frequencies[i];
|
|
165
|
-
count++;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
spectrumGenerator.addPeak({
|
|
169
|
-
x: -valFreq / count / frequencyMHz,
|
|
170
|
-
y: inte * weight,
|
|
171
|
-
});
|
|
172
|
-
valFreq = frequencies[i];
|
|
173
|
-
inte = intensities[i];
|
|
174
|
-
count = 1;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
spectrumGenerator.addPeak({
|
|
178
|
-
x: -valFreq / count / frequencyMHz,
|
|
179
|
-
y: inte * weight,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return spectrumGenerator.getSpectrum();
|
|
184
29
|
}
|
|
185
30
|
exports.default = simulate1D;
|
|
186
|
-
function triuTimesAbs(A, val) {
|
|
187
|
-
A.forEachNonZero((i, j, v) => {
|
|
188
|
-
if (i > j)
|
|
189
|
-
return 0;
|
|
190
|
-
if (Math.abs(v) <= val)
|
|
191
|
-
return 0;
|
|
192
|
-
return v;
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Create a hamiltonian matrix for the given spinsystem
|
|
197
|
-
* @param {Array} chemicalShifts - An array containing the chemical shift in Hz
|
|
198
|
-
* @param {Array} couplingConstants - An array containing the coupling constants in Hz
|
|
199
|
-
* @param {Array} multiplicity - An array specifiying the multiplicities of each scalar coupling
|
|
200
|
-
* @param {Array} conMatrix - A one step connectivity matrix for the given spin system
|
|
201
|
-
* @param {Array} cluster - An binary array specifiying the spins to be considered for this hamiltonial
|
|
202
|
-
* @return {object}
|
|
203
|
-
*/
|
|
204
|
-
function getHamiltonian(chemicalShifts, couplingConstants, multiplicity, conMatrix, cluster) {
|
|
205
|
-
let hamSize = 1;
|
|
206
|
-
for (const element of cluster) {
|
|
207
|
-
hamSize *= multiplicity[element];
|
|
208
|
-
}
|
|
209
|
-
const clusterHam = new ml_sparse_matrix_1.SparseMatrix(hamSize, hamSize);
|
|
210
|
-
for (let pos = 0; pos < cluster.length; pos++) {
|
|
211
|
-
let n = cluster[pos];
|
|
212
|
-
const L = (0, getPauliMatrix_1.default)(multiplicity[n]);
|
|
213
|
-
let A1, B1;
|
|
214
|
-
let temp = 1;
|
|
215
|
-
for (let i = 0; i < pos; i++) {
|
|
216
|
-
temp *= multiplicity[cluster[i]];
|
|
217
|
-
}
|
|
218
|
-
A1 = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
219
|
-
temp = 1;
|
|
220
|
-
for (let i = pos + 1; i < cluster.length; i++) {
|
|
221
|
-
temp *= multiplicity[cluster[i]];
|
|
222
|
-
}
|
|
223
|
-
B1 = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
224
|
-
const alpha = chemicalShifts[n];
|
|
225
|
-
const kronProd = A1.kroneckerProduct(L.z).kroneckerProduct(B1);
|
|
226
|
-
clusterHam.add(kronProd.mul(alpha));
|
|
227
|
-
for (let pos2 = 0; pos2 < cluster.length; pos2++) {
|
|
228
|
-
const k = cluster[pos2];
|
|
229
|
-
if (conMatrix.get(n, k) === 1) {
|
|
230
|
-
const S = (0, getPauliMatrix_1.default)(multiplicity[k]);
|
|
231
|
-
let A2, B2;
|
|
232
|
-
let temp = 1;
|
|
233
|
-
for (let i = 0; i < pos2; i++) {
|
|
234
|
-
temp *= multiplicity[cluster[i]];
|
|
235
|
-
}
|
|
236
|
-
A2 = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
237
|
-
temp = 1;
|
|
238
|
-
for (let i = pos2 + 1; i < cluster.length; i++) {
|
|
239
|
-
temp *= multiplicity[cluster[i]];
|
|
240
|
-
}
|
|
241
|
-
B2 = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
242
|
-
const kron1 = A1.kroneckerProduct(L.x)
|
|
243
|
-
.kroneckerProduct(B1)
|
|
244
|
-
.mmul(A2.kroneckerProduct(S.x).kroneckerProduct(B2));
|
|
245
|
-
kron1.add(A1.kroneckerProduct(L.y)
|
|
246
|
-
.kroneckerProduct(B1)
|
|
247
|
-
.mul(-1)
|
|
248
|
-
.mmul(A2.kroneckerProduct(S.y).kroneckerProduct(B2)));
|
|
249
|
-
kron1.add(A1.kroneckerProduct(L.z)
|
|
250
|
-
.kroneckerProduct(B1)
|
|
251
|
-
.mmul(A2.kroneckerProduct(S.z).kroneckerProduct(B2)));
|
|
252
|
-
clusterHam.add(kron1.mul(couplingConstants.get(n, k) / 2));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return clusterHam;
|
|
257
|
-
}
|
|
258
31
|
//# sourceMappingURL=simulate1D.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulate1D.js","sourceRoot":"","sources":["../../../src/signals/simulation/simulate1D.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"simulate1D.js","sourceRoot":"","sources":["../../../src/signals/simulation/simulate1D.ts"],"names":[],"mappings":";;AACA,2DAAsD;AAKtD,uDAAoD;AAEpD;;GAEG;AAEH,SAAwB,UAAU;AAChC;;GAEG;AACH,UAAsB,EACtB,UAA6B,EAAE;IAE/B,IAAI,EACF,SAAS,GAAG,CAAC,EACb,SAAS,EAAE,YAAY,GAAG,GAAG,EAC7B,IAAI,GAAG,CAAC,EACR,EAAE,GAAG,EAAE,EACP,QAAQ,GAAG,IAAI,EACf,KAAK,GAAG;QACN,IAAI,EAAE,UAAU;KACjB,GACF,GAAG,OAAO,CAAC;IAEZ,IAAI,SAAS,GAAG,SAAS,GAAG,YAAY,CAAC;IAEzC,MAAM,OAAO,GAAG,IAAA,iCAAe,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAErD,OAAO,IAAA,qCAAgB,EAAC,OAAO,EAAE;QAC/B,SAAS,EAAE;YACT,IAAI;YACJ,EAAE;YACF,QAAQ;SACT;QACD,WAAW,EAAE;YACX,KAAK;YACL,KAAK,EAAE,SAAS;SACjB;KACF,CAAC,CAAC;AACL,CAAC;AAjCD,6BAiCC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Shape1D } from 'ml-peak-shape-generator';
|
|
2
|
+
import type { SpinSystem } from '../spinSystem';
|
|
3
|
+
export interface Simulate1DOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The linewidth of the output spectrum, expresed in Hz.
|
|
6
|
+
* @default 1
|
|
7
|
+
*/
|
|
8
|
+
lineWidth?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Maximum number of atoms on each cluster that can be considered to be simulated together. It affects the the quality and speed of the simulation.
|
|
11
|
+
* @default 8
|
|
12
|
+
*/
|
|
13
|
+
maxClusterSize?: number;
|
|
14
|
+
/**
|
|
15
|
+
* The frequency in Mhz of the fake spectrometer that records the spectrum.
|
|
16
|
+
* @default 400
|
|
17
|
+
*/
|
|
18
|
+
frequency?: number;
|
|
19
|
+
/**
|
|
20
|
+
* The low limit of the ordinate variable.
|
|
21
|
+
* @default 0
|
|
22
|
+
*/
|
|
23
|
+
from?: number;
|
|
24
|
+
/**
|
|
25
|
+
* The upper limit of the ordinate variable.
|
|
26
|
+
* @default 10
|
|
27
|
+
*/
|
|
28
|
+
to?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Number of points of the output spectrum.
|
|
31
|
+
* @default 16K
|
|
32
|
+
*/
|
|
33
|
+
nbPoints?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Shape options
|
|
36
|
+
* @default {kind:'gaussian'}
|
|
37
|
+
*/
|
|
38
|
+
shape?: Shape1D;
|
|
39
|
+
}
|
|
40
|
+
export declare function simulateXYPeaks(
|
|
41
|
+
/**
|
|
42
|
+
* The SpinSystem object to be simulated
|
|
43
|
+
*/
|
|
44
|
+
spinSystem: SpinSystem, options?: Simulate1DOptions): {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
}[];
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.simulateXYPeaks = void 0;
|
|
7
|
+
const binary_search_1 = __importDefault(require("binary-search"));
|
|
8
|
+
const ml_matrix_1 = require("ml-matrix");
|
|
9
|
+
const ml_sparse_matrix_1 = require("ml-sparse-matrix");
|
|
10
|
+
const getPauliMatrix_1 = __importDefault(require("./getPauliMatrix"));
|
|
11
|
+
const smallValue = 1e-2;
|
|
12
|
+
function simulateXYPeaks(
|
|
13
|
+
/**
|
|
14
|
+
* The SpinSystem object to be simulated
|
|
15
|
+
*/
|
|
16
|
+
spinSystem, options = {}) {
|
|
17
|
+
let { lineWidth = 1, maxClusterSize = 8, frequency: frequencyMHz = 400, } = options;
|
|
18
|
+
const chemicalShifts = spinSystem.chemicalShifts.slice();
|
|
19
|
+
for (let i = 0; i < chemicalShifts.length; i++) {
|
|
20
|
+
chemicalShifts[i] = chemicalShifts[i] * frequencyMHz;
|
|
21
|
+
}
|
|
22
|
+
const multiplicity = spinSystem.multiplicity;
|
|
23
|
+
const xyPeaks = [];
|
|
24
|
+
for (const cluster of spinSystem.clusters) {
|
|
25
|
+
let clusterFake = cluster.map((cluster) => cluster < 0 ? -cluster - 1 : cluster);
|
|
26
|
+
let weight = 1;
|
|
27
|
+
let sumI = 0;
|
|
28
|
+
let frequencies = [];
|
|
29
|
+
let intensities = [];
|
|
30
|
+
if (cluster.length > maxClusterSize) {
|
|
31
|
+
// This is a single spin, but the cluster exceeds the maxClusterSize criteria
|
|
32
|
+
// we use the simple multiplicity algorithm
|
|
33
|
+
// Add the central peak. It will be split with every single J coupling.
|
|
34
|
+
let index = 0;
|
|
35
|
+
while (cluster[index++] < 0)
|
|
36
|
+
;
|
|
37
|
+
index = cluster[index - 1];
|
|
38
|
+
frequencies.push(-chemicalShifts[index]);
|
|
39
|
+
for (let i = 0; i < cluster.length; i++) {
|
|
40
|
+
if (cluster[i] < 0) {
|
|
41
|
+
let jc = spinSystem.couplingConstants.get(index, clusterFake[i]) / 2;
|
|
42
|
+
let currentSize = frequencies.length;
|
|
43
|
+
for (let j = 0; j < currentSize; j++) {
|
|
44
|
+
frequencies.push(frequencies[j] + jc);
|
|
45
|
+
frequencies[j] -= jc;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
frequencies.sort((a, b) => a - b);
|
|
50
|
+
sumI = frequencies.length;
|
|
51
|
+
weight = 1;
|
|
52
|
+
for (let i = 0; i < sumI; i++) {
|
|
53
|
+
intensities.push(1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const hamiltonian = getHamiltonian(chemicalShifts, spinSystem.couplingConstants, multiplicity, spinSystem.connectivity, clusterFake);
|
|
58
|
+
const hamSize = hamiltonian.rows;
|
|
59
|
+
// TODO: add support for sparse matrix in matrix types.
|
|
60
|
+
// @ts-expect-error sparse matrix not supported
|
|
61
|
+
const evd = new ml_matrix_1.EVD(hamiltonian);
|
|
62
|
+
const V = evd.eigenvectorMatrix;
|
|
63
|
+
const diagB = evd.realEigenvalues;
|
|
64
|
+
const assignmentMatrix = new ml_sparse_matrix_1.SparseMatrix(hamSize, hamSize);
|
|
65
|
+
const multLen = cluster.length;
|
|
66
|
+
weight = 0;
|
|
67
|
+
for (let n = 0; n < multLen; n++) {
|
|
68
|
+
const L = (0, getPauliMatrix_1.default)(multiplicity[clusterFake[n]]);
|
|
69
|
+
let temp = 1;
|
|
70
|
+
for (let j = 0; j < n; j++) {
|
|
71
|
+
temp *= multiplicity[clusterFake[j]];
|
|
72
|
+
}
|
|
73
|
+
const A = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
74
|
+
temp = 1;
|
|
75
|
+
for (let j = n + 1; j < multLen; j++) {
|
|
76
|
+
temp *= multiplicity[clusterFake[j]];
|
|
77
|
+
}
|
|
78
|
+
const B = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
79
|
+
const tempMat = A.kroneckerProduct(L.m).kroneckerProduct(B);
|
|
80
|
+
if (cluster[n] >= 0) {
|
|
81
|
+
assignmentMatrix.add(tempMat.mul(cluster[n] + 1));
|
|
82
|
+
weight++;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
assignmentMatrix.add(tempMat.mul(cluster[n]));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
let rhoip = ml_matrix_1.Matrix.zeros(hamSize, hamSize);
|
|
89
|
+
assignmentMatrix.forEachNonZero((i, j, v) => {
|
|
90
|
+
if (v > 0) {
|
|
91
|
+
for (let k = 0; k < V.columns; k++) {
|
|
92
|
+
let element = V.get(j, k);
|
|
93
|
+
if (element !== 0) {
|
|
94
|
+
rhoip.set(i, k, rhoip.get(i, k) + element);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return v;
|
|
99
|
+
});
|
|
100
|
+
let rhoip2 = rhoip.clone();
|
|
101
|
+
assignmentMatrix.forEachNonZero((i, j, v) => {
|
|
102
|
+
if (v < 0) {
|
|
103
|
+
for (let k = 0; k < V.columns; k++) {
|
|
104
|
+
let element = V.get(j, k);
|
|
105
|
+
if (element !== 0) {
|
|
106
|
+
rhoip2.set(i, k, rhoip2.get(i, k) + element);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return v;
|
|
111
|
+
});
|
|
112
|
+
const tV = V.transpose();
|
|
113
|
+
rhoip = tV.mmul(rhoip);
|
|
114
|
+
const sparseRhoip = new ml_sparse_matrix_1.SparseMatrix(rhoip.to2DArray(), {
|
|
115
|
+
threshold: smallValue,
|
|
116
|
+
});
|
|
117
|
+
triuTimesAbs(sparseRhoip, smallValue);
|
|
118
|
+
rhoip2 = tV.mmul(rhoip2);
|
|
119
|
+
const sparseRhoip2 = new ml_sparse_matrix_1.SparseMatrix(rhoip2.to2DArray(), {
|
|
120
|
+
threshold: smallValue,
|
|
121
|
+
});
|
|
122
|
+
sparseRhoip2.forEachNonZero((i, j, v) => {
|
|
123
|
+
return v;
|
|
124
|
+
});
|
|
125
|
+
triuTimesAbs(sparseRhoip2, smallValue);
|
|
126
|
+
sparseRhoip2.forEachNonZero((i, j, v) => {
|
|
127
|
+
let val = rhoip.get(i, j);
|
|
128
|
+
val = Math.min(Math.abs(val), Math.abs(v));
|
|
129
|
+
val *= val;
|
|
130
|
+
sumI += val;
|
|
131
|
+
let valFreq = diagB[i] - diagB[j];
|
|
132
|
+
let insertIn = (0, binary_search_1.default)(frequencies, valFreq, (a, b) => a - b);
|
|
133
|
+
if (insertIn < 0) {
|
|
134
|
+
frequencies.splice(-1 - insertIn, 0, valFreq);
|
|
135
|
+
intensities.splice(-1 - insertIn, 0, val);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
intensities[insertIn] += val;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
const numFreq = frequencies.length;
|
|
143
|
+
if (numFreq > 0) {
|
|
144
|
+
weight /= sumI;
|
|
145
|
+
const diff = lineWidth / 64;
|
|
146
|
+
let valFreq = frequencies[0];
|
|
147
|
+
let inte = intensities[0];
|
|
148
|
+
let count = 1;
|
|
149
|
+
for (let i = 1; i < numFreq; i++) {
|
|
150
|
+
if (Math.abs(frequencies[i] - valFreq / count) < diff) {
|
|
151
|
+
inte += intensities[i];
|
|
152
|
+
valFreq += frequencies[i];
|
|
153
|
+
count++;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
xyPeaks.push({
|
|
157
|
+
x: -valFreq / count / frequencyMHz,
|
|
158
|
+
y: inte * weight,
|
|
159
|
+
});
|
|
160
|
+
valFreq = frequencies[i];
|
|
161
|
+
inte = intensities[i];
|
|
162
|
+
count = 1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
xyPeaks.push({
|
|
166
|
+
x: -valFreq / count / frequencyMHz,
|
|
167
|
+
y: inte * weight,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return xyPeaks;
|
|
172
|
+
}
|
|
173
|
+
exports.simulateXYPeaks = simulateXYPeaks;
|
|
174
|
+
function triuTimesAbs(A, val) {
|
|
175
|
+
A.forEachNonZero((i, j, v) => {
|
|
176
|
+
if (i > j)
|
|
177
|
+
return 0;
|
|
178
|
+
if (Math.abs(v) <= val)
|
|
179
|
+
return 0;
|
|
180
|
+
return v;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Create a hamiltonian matrix for the given spinsystem
|
|
185
|
+
* @param {Array} chemicalShifts - An array containing the chemical shift in Hz
|
|
186
|
+
* @param {Array} couplingConstants - An array containing the coupling constants in Hz
|
|
187
|
+
* @param {Array} multiplicity - An array specifiying the multiplicities of each scalar coupling
|
|
188
|
+
* @param {Array} conMatrix - A one step connectivity matrix for the given spin system
|
|
189
|
+
* @param {Array} cluster - An binary array specifiying the spins to be considered for this hamiltonial
|
|
190
|
+
* @return {object}
|
|
191
|
+
*/
|
|
192
|
+
function getHamiltonian(chemicalShifts, couplingConstants, multiplicity, conMatrix, cluster) {
|
|
193
|
+
let hamSize = 1;
|
|
194
|
+
for (const element of cluster) {
|
|
195
|
+
hamSize *= multiplicity[element];
|
|
196
|
+
}
|
|
197
|
+
const clusterHam = new ml_sparse_matrix_1.SparseMatrix(hamSize, hamSize);
|
|
198
|
+
for (let pos = 0; pos < cluster.length; pos++) {
|
|
199
|
+
let n = cluster[pos];
|
|
200
|
+
const L = (0, getPauliMatrix_1.default)(multiplicity[n]);
|
|
201
|
+
let A1, B1;
|
|
202
|
+
let temp = 1;
|
|
203
|
+
for (let i = 0; i < pos; i++) {
|
|
204
|
+
temp *= multiplicity[cluster[i]];
|
|
205
|
+
}
|
|
206
|
+
A1 = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
207
|
+
temp = 1;
|
|
208
|
+
for (let i = pos + 1; i < cluster.length; i++) {
|
|
209
|
+
temp *= multiplicity[cluster[i]];
|
|
210
|
+
}
|
|
211
|
+
B1 = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
212
|
+
const alpha = chemicalShifts[n];
|
|
213
|
+
const kronProd = A1.kroneckerProduct(L.z).kroneckerProduct(B1);
|
|
214
|
+
clusterHam.add(kronProd.mul(alpha));
|
|
215
|
+
for (let pos2 = 0; pos2 < cluster.length; pos2++) {
|
|
216
|
+
const k = cluster[pos2];
|
|
217
|
+
if (conMatrix.get(n, k) === 1) {
|
|
218
|
+
const S = (0, getPauliMatrix_1.default)(multiplicity[k]);
|
|
219
|
+
let A2, B2;
|
|
220
|
+
let temp = 1;
|
|
221
|
+
for (let i = 0; i < pos2; i++) {
|
|
222
|
+
temp *= multiplicity[cluster[i]];
|
|
223
|
+
}
|
|
224
|
+
A2 = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
225
|
+
temp = 1;
|
|
226
|
+
for (let i = pos2 + 1; i < cluster.length; i++) {
|
|
227
|
+
temp *= multiplicity[cluster[i]];
|
|
228
|
+
}
|
|
229
|
+
B2 = ml_sparse_matrix_1.SparseMatrix.eye(temp);
|
|
230
|
+
const kron1 = A1.kroneckerProduct(L.x)
|
|
231
|
+
.kroneckerProduct(B1)
|
|
232
|
+
.mmul(A2.kroneckerProduct(S.x).kroneckerProduct(B2));
|
|
233
|
+
kron1.add(A1.kroneckerProduct(L.y)
|
|
234
|
+
.kroneckerProduct(B1)
|
|
235
|
+
.mul(-1)
|
|
236
|
+
.mmul(A2.kroneckerProduct(S.y).kroneckerProduct(B2)));
|
|
237
|
+
kron1.add(A1.kroneckerProduct(L.z)
|
|
238
|
+
.kroneckerProduct(B1)
|
|
239
|
+
.mmul(A2.kroneckerProduct(S.z).kroneckerProduct(B2)));
|
|
240
|
+
clusterHam.add(kron1.mul(couplingConstants.get(n, k) / 2));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return clusterHam;
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=simulateXYPeaks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulateXYPeaks.js","sourceRoot":"","sources":["../../../src/signals/simulation/simulateXYPeaks.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAyC;AACzC,yCAAwC;AAGxC,uDAAgD;AAIhD,sEAA8C;AAE9C,MAAM,UAAU,GAAG,IAAI,CAAC;AAwCxB,SAAgB,eAAe;AAC7B;;GAEG;AACH,UAAsB,EACtB,UAA6B,EAAE;IAE/B,IAAI,EACF,SAAS,GAAG,CAAC,EACb,cAAc,GAAG,CAAC,EAClB,SAAS,EAAE,YAAY,GAAG,GAAG,GAC9B,GAAG,OAAO,CAAC;IAEZ,MAAM,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IACzD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC9C,cAAc,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC;KACtD;IAED,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;IAE7C,MAAM,OAAO,GAAG,EAAE,CAAC;IAC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,EAAE,CAAC,CAAC,CAAC;gBACvD,KAAK,CAAC,GAAG,CACP,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;qBACrB,gBAAgB,CAAC,EAAE,CAAC;qBACpB,GAAG,CAAC,CAAC,CAAC,CAAC;qBACP,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CACvD,CAAC;gBACF,KAAK,CAAC,GAAG,CACP,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;qBACrB,gBAAgB,CAAC,EAAE,CAAC;qBACpB,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CACvD,CAAC;gBAEF,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aAC5D;SACF;KACF;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFrequency = void 0;
|
|
4
|
-
const
|
|
4
|
+
const gyromagnetic_ratio_1 = require("gyromagnetic-ratio");
|
|
5
5
|
/**
|
|
6
6
|
* calculate the frequency of a nucleus with respect to a reference nucleus
|
|
7
7
|
*/
|
|
@@ -12,14 +12,14 @@ function getFrequency(
|
|
|
12
12
|
nucleus, observedNucleusData) {
|
|
13
13
|
const { nucleus: obsNucleus, frequency } = observedNucleusData;
|
|
14
14
|
checkExistence(nucleus, obsNucleus);
|
|
15
|
-
return ((frequency *
|
|
16
|
-
|
|
15
|
+
return ((frequency * gyromagnetic_ratio_1.gyromagneticRatio[nucleus]) /
|
|
16
|
+
gyromagnetic_ratio_1.gyromagneticRatio[obsNucleus]);
|
|
17
17
|
}
|
|
18
18
|
exports.getFrequency = getFrequency;
|
|
19
19
|
function checkExistence(...nucleus) {
|
|
20
20
|
let nuclei = [];
|
|
21
21
|
for (const n of nucleus) {
|
|
22
|
-
if (!(n in
|
|
22
|
+
if (!(n in gyromagnetic_ratio_1.gyromagneticRatio)) {
|
|
23
23
|
nuclei.push(n);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFrequency.js","sourceRoot":"","sources":["../../src/utilities/getFrequency.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"getFrequency.js","sourceRoot":"","sources":["../../src/utilities/getFrequency.ts"],"names":[],"mappings":";;;AAAA,2DAA+D;AAgB/D;;GAEG;AACH,SAAgB,YAAY;AAC1B;;GAEG;AACH,OAAgB,EAChB,mBAAwC;IAExC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,mBAAmB,CAAC;IAE/D,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAEpC,OAAO,CACL,CAAC,SAAS,GAAG,sCAAiB,CAAC,OAAiB,CAAC,CAAC;QAClD,sCAAiB,CAAC,UAAoB,CAAC,CACxC,CAAC;AACJ,CAAC;AAfD,oCAeC;AAED,SAAS,cAAc,CAAC,GAAG,OAAkB;IAC3C,IAAI,MAAM,GAAa,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;QACvB,IAAI,CAAC,CAAC,CAAC,IAAI,sCAAiB,CAAC,EAAE;YAC7B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAChB;KACF;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;KAC3D;AACH,CAAC"}
|
package/lib/xyz/NMRSignal2D.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FromTo } from 'cheminfo-types';
|
|
2
2
|
import type { Peak2D } from 'ml-matrix-peaks-finder';
|
|
3
|
-
export interface
|
|
3
|
+
export interface Signal2DProjection {
|
|
4
4
|
nucleus?: string;
|
|
5
5
|
delta: number;
|
|
6
6
|
resolution?: number;
|
|
@@ -8,8 +8,8 @@ export interface Signal2DAxisData {
|
|
|
8
8
|
diaIDs?: string[];
|
|
9
9
|
}
|
|
10
10
|
export interface NMRSignal2D {
|
|
11
|
-
x:
|
|
12
|
-
y:
|
|
11
|
+
x: Signal2DProjection;
|
|
12
|
+
y: Signal2DProjection;
|
|
13
13
|
j?: {
|
|
14
14
|
pathLength?: number | FromTo;
|
|
15
15
|
};
|