nmr-processing 8.2.0 → 8.4.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 (139) hide show
  1. package/README.md +23 -3
  2. package/lib/apodization/apodization.d.ts +22 -0
  3. package/lib/apodization/apodization.js +18 -0
  4. package/lib/apodization/apodization.js.map +1 -0
  5. package/lib/apodization/applyWindow.d.ts +28 -0
  6. package/lib/apodization/applyWindow.js +20 -0
  7. package/lib/apodization/applyWindow.js.map +1 -0
  8. package/lib/apodization/compose.d.ts +23 -0
  9. package/lib/apodization/compose.js +25 -0
  10. package/lib/apodization/compose.js.map +1 -0
  11. package/lib/apodization/getFunction.d.ts +2 -0
  12. package/lib/apodization/getFunction.js +18 -0
  13. package/lib/apodization/getFunction.js.map +1 -0
  14. package/lib/apodization/shapes/WindowFunctions.d.ts +12 -0
  15. package/lib/apodization/shapes/WindowFunctions.js +3 -0
  16. package/lib/apodization/shapes/WindowFunctions.js.map +1 -0
  17. package/lib/apodization/shapes/exponential.d.ts +11 -0
  18. package/lib/apodization/shapes/exponential.js +10 -0
  19. package/lib/apodization/shapes/exponential.js.map +1 -0
  20. package/lib/apodization/shapes/lorentzToGauss.d.ts +26 -0
  21. package/lib/apodization/shapes/lorentzToGauss.js +15 -0
  22. package/lib/apodization/shapes/lorentzToGauss.js.map +1 -0
  23. package/lib/apodization/utils/getData.d.ts +4 -0
  24. package/lib/apodization/utils/getData.js +21 -0
  25. package/lib/apodization/utils/getData.js.map +1 -0
  26. package/lib/assignment/utils/buildAssignments.d.ts +2 -2
  27. package/lib/assignment/utils/exploreTreeRec.js +1 -1
  28. package/lib/assignment/utils/exploreTreeRec.js.map +1 -1
  29. package/lib/databases/DatabaseNMREntry.d.ts +2 -0
  30. package/lib/index.d.ts +1 -0
  31. package/lib/index.js +1 -0
  32. package/lib/index.js.map +1 -1
  33. package/lib/peaks/peaksToRanges.js +1 -1
  34. package/lib/peaks/peaksToRanges.js.map +1 -1
  35. package/lib/peaks/solventSuppression.d.ts +4 -1
  36. package/lib/peaks/solventSuppression.js +10 -7
  37. package/lib/peaks/solventSuppression.js.map +1 -1
  38. package/lib/peaks/util/jAnalyzer.js +23 -29
  39. package/lib/peaks/util/jAnalyzer.js.map +1 -1
  40. package/lib/peaks/util/peakOptimizer.js +12 -16
  41. package/lib/peaks/util/peakOptimizer.js.map +1 -1
  42. package/lib/prediction/predictAllSpectra.js +7 -9
  43. package/lib/prediction/predictAllSpectra.js.map +1 -1
  44. package/lib/prediction/predictCarbon.js +1 -1
  45. package/lib/prediction/predictCarbon.js.map +1 -1
  46. package/lib/prediction/utils/queryByHOSE.js +1 -1
  47. package/lib/prediction/utils/queryByHOSE.js.map +1 -1
  48. package/lib/ranges/rangesToACS.js +8 -4
  49. package/lib/ranges/rangesToACS.js.map +1 -1
  50. package/lib/signals/signalsJoin.js +4 -3
  51. package/lib/signals/signalsJoin.js.map +1 -1
  52. package/lib/signals/simulation/getPauliMatrix.js.map +1 -1
  53. package/lib/signals/simulation/splitSpinSystem.js +11 -13
  54. package/lib/signals/simulation/splitSpinSystem.js.map +1 -1
  55. package/lib/utilities/rangeFromSignal.d.ts +9 -5
  56. package/lib/utilities/rangeFromSignal.js +7 -7
  57. package/lib/utilities/rangeFromSignal.js.map +1 -1
  58. package/lib/utilities/resurrectRange.js +4 -7
  59. package/lib/utilities/resurrectRange.js.map +1 -1
  60. package/lib/xy/xyAutoPeaksPicking.d.ts +5 -0
  61. package/lib/xy/xyAutoPeaksPicking.js +9 -4
  62. package/lib/xy/xyAutoPeaksPicking.js.map +1 -1
  63. package/lib-esm/apodization/apodization.js +14 -0
  64. package/lib-esm/apodization/apodization.js.map +1 -0
  65. package/lib-esm/apodization/applyWindow.js +16 -0
  66. package/lib-esm/apodization/applyWindow.js.map +1 -0
  67. package/lib-esm/apodization/compose.js +21 -0
  68. package/lib-esm/apodization/compose.js.map +1 -0
  69. package/lib-esm/apodization/getFunction.js +14 -0
  70. package/lib-esm/apodization/getFunction.js.map +1 -0
  71. package/lib-esm/apodization/shapes/WindowFunctions.js +2 -0
  72. package/lib-esm/apodization/shapes/WindowFunctions.js.map +1 -0
  73. package/lib-esm/apodization/shapes/exponential.js +6 -0
  74. package/lib-esm/apodization/shapes/exponential.js.map +1 -0
  75. package/lib-esm/apodization/shapes/lorentzToGauss.js +11 -0
  76. package/lib-esm/apodization/shapes/lorentzToGauss.js.map +1 -0
  77. package/lib-esm/apodization/utils/getData.js +17 -0
  78. package/lib-esm/apodization/utils/getData.js.map +1 -0
  79. package/lib-esm/assignment/utils/buildAssignments.js +3 -3
  80. package/lib-esm/assignment/utils/exploreTreeRec.js +1 -1
  81. package/lib-esm/assignment/utils/exploreTreeRec.js.map +1 -1
  82. package/lib-esm/assignment/utils/getAssignment/buildAssignments.js +3 -3
  83. package/lib-esm/index.js +1 -0
  84. package/lib-esm/index.js.map +1 -1
  85. package/lib-esm/peaks/peaksToRanges.js +1 -1
  86. package/lib-esm/peaks/peaksToRanges.js.map +1 -1
  87. package/lib-esm/peaks/solventSuppression.js +10 -7
  88. package/lib-esm/peaks/solventSuppression.js.map +1 -1
  89. package/lib-esm/peaks/util/jAnalyzer.js +23 -29
  90. package/lib-esm/peaks/util/jAnalyzer.js.map +1 -1
  91. package/lib-esm/peaks/util/peakOptimizer.js +12 -16
  92. package/lib-esm/peaks/util/peakOptimizer.js.map +1 -1
  93. package/lib-esm/prediction/predictAllSpectra.js +7 -9
  94. package/lib-esm/prediction/predictAllSpectra.js.map +1 -1
  95. package/lib-esm/prediction/predictCarbon.js +1 -1
  96. package/lib-esm/prediction/predictCarbon.js.map +1 -1
  97. package/lib-esm/prediction/utils/queryByHOSE.js +1 -1
  98. package/lib-esm/prediction/utils/queryByHOSE.js.map +1 -1
  99. package/lib-esm/ranges/rangesToACS.js +8 -4
  100. package/lib-esm/ranges/rangesToACS.js.map +1 -1
  101. package/lib-esm/signals/signalsJoin.js +4 -3
  102. package/lib-esm/signals/signalsJoin.js.map +1 -1
  103. package/lib-esm/signals/simulation/getPauliMatrix.js.map +1 -1
  104. package/lib-esm/signals/simulation/splitSpinSystem.js +11 -13
  105. package/lib-esm/signals/simulation/splitSpinSystem.js.map +1 -1
  106. package/lib-esm/utilities/rangeFromSignal.js +7 -7
  107. package/lib-esm/utilities/rangeFromSignal.js.map +1 -1
  108. package/lib-esm/utilities/resurrectRange.js +4 -7
  109. package/lib-esm/utilities/resurrectRange.js.map +1 -1
  110. package/lib-esm/xy/xyAutoPeaksPicking.js +9 -4
  111. package/lib-esm/xy/xyAutoPeaksPicking.js.map +1 -1
  112. package/package.json +13 -13
  113. package/src/apodization/apodization.ts +34 -0
  114. package/src/apodization/applyWindow.ts +51 -0
  115. package/src/apodization/compose.ts +47 -0
  116. package/src/apodization/getFunction.ts +15 -0
  117. package/src/apodization/shapes/WindowFunctions.ts +14 -0
  118. package/src/apodization/shapes/exponential.ts +16 -0
  119. package/src/apodization/shapes/lorentzToGauss.ts +41 -0
  120. package/src/apodization/utils/getData.ts +15 -0
  121. package/src/assignment/utils/buildAssignments.ts +4 -4
  122. package/src/assignment/utils/exploreTreeRec.ts +1 -1
  123. package/src/assignment/utils/getAssignment/buildAssignments.ts +3 -3
  124. package/src/databases/DatabaseNMREntry.ts +3 -0
  125. package/src/index.ts +2 -0
  126. package/src/peaks/peaksToRanges.ts +1 -1
  127. package/src/peaks/solventSuppression.ts +13 -8
  128. package/src/peaks/util/jAnalyzer.ts +22 -28
  129. package/src/peaks/util/peakOptimizer.ts +11 -15
  130. package/src/prediction/predictAllSpectra.ts +6 -8
  131. package/src/prediction/predictCarbon.ts +1 -1
  132. package/src/prediction/utils/queryByHOSE.ts +1 -1
  133. package/src/ranges/rangesToACS.ts +9 -10
  134. package/src/signals/signalsJoin.ts +5 -7
  135. package/src/signals/simulation/getPauliMatrix.ts +1 -1
  136. package/src/signals/simulation/splitSpinSystem.ts +10 -12
  137. package/src/utilities/rangeFromSignal.ts +19 -11
  138. package/src/utilities/resurrectRange.ts +4 -7
  139. package/src/xy/xyAutoPeaksPicking.ts +14 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nmr-processing",
3
- "version": "8.2.0",
3
+ "version": "8.4.0",
4
4
  "description": "Pure functions allowing to process NMR spectra.",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -38,21 +38,21 @@
38
38
  },
39
39
  "homepage": "https://github.com/cheminfo/nmr-processing#readme",
40
40
  "devDependencies": {
41
- "@types/jest": "^27.5.0",
41
+ "@types/jest": "^28.1.4",
42
42
  "cheminfo-build": "^1.1.11",
43
- "cheminfo-types": "^1.1.0",
44
- "eslint": "^8.14.0",
45
- "eslint-config-cheminfo-typescript": "^10.4.0",
46
- "jest": "^28.0.3",
43
+ "cheminfo-types": "^1.2.0",
44
+ "eslint": "^8.19.0",
45
+ "eslint-config-cheminfo-typescript": "^11.0.1",
46
+ "jest": "^28.1.2",
47
47
  "jest-matcher-deep-close-to": "^3.0.2",
48
48
  "md5": "^2.3.0",
49
49
  "ml-array-median": "^1.1.6",
50
50
  "nmr-xy-testdata": "^0.5.1",
51
51
  "openchemlib": "^7.4.3",
52
- "prettier": "^2.6.2",
52
+ "prettier": "^2.7.1",
53
53
  "rimraf": "^3.0.2",
54
- "ts-jest": "^28.0.1",
55
- "typescript": "^4.6.4"
54
+ "ts-jest": "^28.0.5",
55
+ "typescript": "^4.7.4"
56
56
  },
57
57
  "dependencies": {
58
58
  "binary-search": "^1.3.6",
@@ -65,18 +65,18 @@
65
65
  "ml-array-rescale": "^1.3.7",
66
66
  "ml-array-sequential-fill": "^1.1.8",
67
67
  "ml-array-sum": "^1.1.6",
68
- "ml-gsd": "^11.2.0",
68
+ "ml-gsd": "^11.2.1",
69
69
  "ml-hclust": "^3.1.0",
70
70
  "ml-levenberg-marquardt": "^4.1.0",
71
- "ml-matrix": "^6.10.0",
71
+ "ml-matrix": "^6.10.2",
72
72
  "ml-matrix-convolution": "^1.0.0",
73
73
  "ml-matrix-peaks-finder": "^1.0.0",
74
74
  "ml-peak-shape-generator": "^4.1.1",
75
75
  "ml-simple-clustering": "^0.1.0",
76
76
  "ml-sparse-matrix": "^2.1.0",
77
- "ml-spectra-processing": "^11.5.0",
77
+ "ml-spectra-processing": "^11.7.0",
78
78
  "ml-tree-set": "^0.1.1",
79
- "nmr-correlation": "^2.2.5",
79
+ "nmr-correlation": "^2.3.2",
80
80
  "openchemlib-utils": "^1.11.0",
81
81
  "spectrum-generator": "^8.0.2"
82
82
  }
@@ -0,0 +1,34 @@
1
+ import { DoubleArray } from 'cheminfo-types';
2
+
3
+ import { applyWindow } from './applyWindow';
4
+ import { compose, ShapeOptions } from './compose';
5
+
6
+ export interface DataReIm {
7
+ /** Array of re values */
8
+ re: DoubleArray;
9
+ /** Array of im values */
10
+ im: DoubleArray;
11
+ }
12
+
13
+ interface ApodizationOptions {
14
+ /**
15
+ * number of points at the end of the shape to apply the window function inverted
16
+ * @default 0
17
+ */
18
+ pointsToShift?: number;
19
+ compose: ShapeOptions;
20
+ }
21
+ export function apodization(data: DataReIm, options: ApodizationOptions) {
22
+ const { compose: composeOptions, pointsToShift } = options;
23
+ const windowData = compose(composeOptions);
24
+
25
+ const applyWindowOptions = {
26
+ windowData,
27
+ pointsToShift,
28
+ };
29
+
30
+ const re = applyWindow(data.re, applyWindowOptions);
31
+ const im = applyWindow(data.im, applyWindowOptions);
32
+
33
+ return { re, im, windowData };
34
+ }
@@ -0,0 +1,51 @@
1
+ import { DoubleArray } from 'cheminfo-types';
2
+
3
+ export interface ApplyWindowOptions {
4
+ /**
5
+ * data of a window function it should be scaled to max = 1 to ensure compatibility with new apodizations.
6
+ */
7
+ windowData: DoubleArray;
8
+ /**
9
+ * Start Location for Applying Apodize Window
10
+ */
11
+ start?: number;
12
+ /**
13
+ * length of the window function
14
+ */
15
+ length?: number;
16
+ /**
17
+ * number of points at the end of the shape to apply the window function inverted
18
+ * @default 0
19
+ */
20
+ pointsToShift?: number;
21
+ /**
22
+ * output array
23
+ */
24
+ output?: DoubleArray;
25
+ }
26
+
27
+ /**
28
+ * pure function that applies a window function to the input data.
29
+ */
30
+ export function applyWindow(data: DoubleArray, options: ApplyWindowOptions) {
31
+ const dataLength = data.length;
32
+
33
+ const {
34
+ windowData,
35
+ start = 0,
36
+ length = dataLength,
37
+ pointsToShift = 0,
38
+ output = new Float64Array(data),
39
+ } = options;
40
+
41
+ const firstEndPoint = Math.min(start + length, dataLength - pointsToShift);
42
+ for (let i = start, j = 0; i < firstEndPoint; i++) {
43
+ output[i] *= windowData[j++];
44
+ }
45
+
46
+ for (let i = dataLength - 1, j = 0; i > dataLength - pointsToShift - 1; i--) {
47
+ output[i] *= windowData[j++];
48
+ }
49
+
50
+ return output;
51
+ }
@@ -0,0 +1,47 @@
1
+ import { applyWindow } from './applyWindow';
2
+ import { getFunction } from './getFunction';
3
+ import type { WindowFunctions } from './shapes/WindowFunctions';
4
+ import { getData } from './utils/getData';
5
+
6
+ interface ShapeToAdd {
7
+ /**
8
+ * Start Location for Applying Apodize Window
9
+ */
10
+ start?: number;
11
+ /**
12
+ * parameters of the shape plus the kind of shape to identify
13
+ */
14
+ shape: WindowFunctions;
15
+ }
16
+
17
+ export interface ShapeOptions {
18
+ /**
19
+ * length of the window shape
20
+ */
21
+ length: number;
22
+
23
+ /**
24
+ * parameters of the shape plus the kind of shape to identify
25
+ */
26
+ shapes?: ShapeToAdd[];
27
+ }
28
+
29
+ export function compose(shapeOptions: ShapeOptions) {
30
+ const { length: dataLength, shapes = [] } = shapeOptions;
31
+ let data = new Float64Array(dataLength).fill(1);
32
+ shapes.forEach((options) => {
33
+ const { shape, start = 0 } = options;
34
+ const { options: shapeOptions } = shape;
35
+ const length =
36
+ 'length' in shapeOptions ? shapeOptions.length : dataLength - start;
37
+
38
+ const windowData = getData(getFunction(shape), length);
39
+ applyWindow(data, {
40
+ windowData,
41
+ length,
42
+ start,
43
+ output: data,
44
+ });
45
+ });
46
+ return data;
47
+ }
@@ -0,0 +1,15 @@
1
+ import type { WindowFunctions } from './shapes/WindowFunctions';
2
+ import { exponential } from './shapes/exponential';
3
+ import { lorentzToGauss } from './shapes/lorentzToGauss';
4
+
5
+ export function getFunction(shape: WindowFunctions) {
6
+ const { kind, options } = shape;
7
+ switch (kind) {
8
+ case 'exponential':
9
+ return exponential(options);
10
+ case 'lorentzToGauss':
11
+ return lorentzToGauss(options);
12
+ default:
13
+ throw Error(`Unknown distribution ${kind as string}`);
14
+ }
15
+ }
@@ -0,0 +1,14 @@
1
+ import type { ExponentialOptions } from './exponential';
2
+ import type { LorentzToGaussOptions } from './lorentzToGauss';
3
+
4
+ interface Exponential {
5
+ kind: 'exponential';
6
+ options: ExponentialOptions;
7
+ }
8
+
9
+ interface LorentToGauss {
10
+ kind: 'lorentzToGauss';
11
+ options: LorentzToGaussOptions;
12
+ }
13
+
14
+ export type WindowFunctions = Exponential | LorentToGauss;
@@ -0,0 +1,16 @@
1
+ export interface ExponentialOptions {
2
+ /**
3
+ * line broadening value in Hz, a negative value will invert the shape
4
+ */
5
+ lb: number;
6
+ /**
7
+ * increment value in time or the independent value
8
+ */
9
+ dw: number;
10
+ }
11
+
12
+ export function exponential(options: ExponentialOptions) {
13
+ const { lb, dw } = options;
14
+ const coefExp = -lb * Math.PI * dw;
15
+ return (i: number) => Math.exp(coefExp * i);
16
+ }
@@ -0,0 +1,41 @@
1
+ export interface LorentzToGaussOptions {
2
+ /**
3
+ * size of the shape function
4
+ */
5
+ length: number;
6
+ /**
7
+ * increment value in time or the independent value
8
+ */
9
+ dw: number;
10
+ /**
11
+ * Gaussian Broaden Width, Hz
12
+ * @default 0
13
+ */
14
+ gaussianHz?: number;
15
+ /**
16
+ * Inverse Exponential Width, Hz
17
+ * @default 0
18
+ */
19
+ exponentialHz?: number;
20
+ /**
21
+ * Location of Gauss Maximum, this value should be between 0 to 1
22
+ * @default 0
23
+ */
24
+ center?: number;
25
+ }
26
+
27
+ export function lorentzToGauss(options: LorentzToGaussOptions) {
28
+ const { dw, length, gaussianHz = 0, exponentialHz = 0, center = 0 } = options;
29
+
30
+ if (center > 1 || center < 0) {
31
+ throw new Error(
32
+ 'The center of gaussian shape should be inside of the window function: 0 - 1',
33
+ );
34
+ }
35
+
36
+ const C5 = Math.pow(0.6 * Math.PI * gaussianHz * dw, 2);
37
+ const C2 = center * (length - 1);
38
+ const C6 = Math.PI * dw * exponentialHz;
39
+
40
+ return (i: number) => Math.exp(i * C6 - Math.pow(C2 - i, 2) * C5);
41
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * generate and scale the data of a window function
3
+ */
4
+ export function getData(func: (i: number) => number, length: number) {
5
+ const data = new Float64Array(length);
6
+ let max = Number.MIN_SAFE_INTEGER;
7
+ for (let i = 0; i < length; i++) {
8
+ const value = func(i);
9
+ data[i] = value;
10
+ if (value > max) max = value;
11
+ }
12
+
13
+ for (let i = 0; i < length; i++) data[i] /= max;
14
+ return data;
15
+ }
@@ -1,4 +1,4 @@
1
- import treeSet from 'ml-tree-set';
1
+ import TreeSet from 'ml-tree-set';
2
2
 
3
3
  import { Targets, NMRSignal1DWithAtomsAndDiaIDs } from '../get1HAssignments';
4
4
 
@@ -38,7 +38,7 @@ export interface Predictions1Dassignments {
38
38
  }
39
39
 
40
40
  export interface StoreAssignments {
41
- solutions: treeSet;
41
+ solutions: TreeSet;
42
42
  nSolutions: number;
43
43
  }
44
44
 
@@ -64,7 +64,7 @@ export async function buildAssignments(props: BuildAssignmentsProps) {
64
64
  let timeStart = date.getTime();
65
65
 
66
66
  let store: StoreAssignments = {
67
- solutions: new treeSet(comparator),
67
+ solutions: new TreeSet(comparator),
68
68
  nSolutions: 0,
69
69
  };
70
70
 
@@ -97,7 +97,7 @@ export async function buildAssignments(props: BuildAssignmentsProps) {
97
97
  let partial = fillPartial(nSources);
98
98
 
99
99
  store = {
100
- solutions: new treeSet(comparator),
100
+ solutions: new TreeSet(comparator),
101
101
  nSolutions: 0,
102
102
  };
103
103
 
@@ -113,7 +113,7 @@ function addSolution(store: StoreAssignments, props: AddSolutionProps) {
113
113
  store.nSolutions++;
114
114
  let solution: SolutionAssignment = {
115
115
  assignment: JSON.parse(JSON.stringify(partial)),
116
- score: score,
116
+ score,
117
117
  };
118
118
 
119
119
  if (store.nSolutions >= maxSolutions) {
@@ -1,4 +1,4 @@
1
- import treeSet from 'ml-tree-set';
1
+ import TreeSet from 'ml-tree-set';
2
2
  import { Values } from 'nmr-correlation';
3
3
  import { Molecule } from 'openchemlib';
4
4
  import { getConnectivityMatrix } from 'openchemlib-utils';
@@ -135,7 +135,7 @@ export async function buildAssignments(props: BuildAssignmentInput) {
135
135
  let lowerBoundScore = minScore;
136
136
 
137
137
  let store: StoreAssignments = {
138
- solutions: new treeSet(comparator),
138
+ solutions: new TreeSet(comparator),
139
139
  nSolutions: 0,
140
140
  };
141
141
 
@@ -204,7 +204,7 @@ export async function buildAssignments(props: BuildAssignmentInput) {
204
204
  );
205
205
 
206
206
  store = {
207
- solutions: new treeSet(comparator),
207
+ solutions: new TreeSet(comparator),
208
208
  nSolutions: 0,
209
209
  };
210
210
 
@@ -1,6 +1,9 @@
1
+ import { OCLMolecule } from 'cheminfo-types';
2
+
1
3
  import { NMRRange } from '../xy/NMRRange';
2
4
 
3
5
  export interface DatabaseNMREntry {
6
+ ocl?: OCLMolecule;
4
7
  smiles?: string;
5
8
  solvent: string;
6
9
  nucleus: string;
package/src/index.ts CHANGED
@@ -40,6 +40,8 @@ export * from './databases/protonImpurities';
40
40
  export * from './peaks/solventSuppression';
41
41
  export * from './ranges/markSolventSignal';
42
42
 
43
+ export * from './apodization/apodization';
44
+
43
45
  export type { NMRSignal1D } from './signals/NMRSignal1D';
44
46
  export type { NMRSignal2D, Signal2DProjection } from './xyz/NMRSignal2D';
45
47
  export type { NMRRange } from './xy/NMRRange';
@@ -174,7 +174,7 @@ export function peaksToRanges(
174
174
  let peaksO = [];
175
175
  for (let j = signal.maskPattern.length - 1; j >= 0; j--) {
176
176
  sum += computeArea(signal.peaks[j]);
177
- if (signal.maskPattern[j] === false) {
177
+ if (!signal.maskPattern[j]) {
178
178
  let peakR = signal.peaks.splice(j, 1)[0];
179
179
  peaksO.push({
180
180
  x: peakR.x,
@@ -15,7 +15,7 @@ import { NMRPeak1D } from './NMRPeak1D';
15
15
  export function solventSuppression<T extends NMRPeak1D>(
16
16
  peakList: T[],
17
17
  solvent: NMRSignal1D[],
18
- options: any = {},
18
+ options: { markSolventPeaks?: boolean; solventZoneExtension?: number } = {},
19
19
  ) {
20
20
  const peaks = [...peakList].sort((a, b) => a.x - b.x);
21
21
 
@@ -38,9 +38,9 @@ export function solventSuppression<T extends NMRPeak1D>(
38
38
  solventXYPeaks[0].x - solventZoneExtension,
39
39
  );
40
40
 
41
- if (upIndex === lowIndex) continue;
42
- const nearPeaks = peaks.slice(lowIndex, upIndex + 1);
43
-
41
+ const nearPeaks = peaks.filter(
42
+ (peak, index) => index >= lowIndex && index <= upIndex,
43
+ );
44
44
  const amplitudeResiduals = [];
45
45
  const deltaResiduals = [];
46
46
  const positionResiduals = [];
@@ -76,9 +76,14 @@ export function solventSuppression<T extends NMRPeak1D>(
76
76
  positionResiduals.push(positionResidual);
77
77
  }
78
78
 
79
- const maxAmplitude = xMaxValue(amplitudeResiduals);
80
- const maxDelta = xMaxValue(deltaResiduals);
81
- const maxPosition = xMaxValue(positionResiduals);
79
+ const [maxAmplitude, maxDelta, maxPosition] = [
80
+ amplitudeResiduals,
81
+ deltaResiduals,
82
+ positionResiduals,
83
+ ].map((data) => {
84
+ const max = xMaxValue(data);
85
+ return max === 0 ? 1 : max;
86
+ });
82
87
 
83
88
  let minIndex = -1;
84
89
  let minScore = Number.MAX_SAFE_INTEGER;
@@ -98,7 +103,7 @@ export function solventSuppression<T extends NMRPeak1D>(
98
103
  }
99
104
  }
100
105
 
101
- if (minScore < 0) {
106
+ if (minScore < 0 || minIndex < 0) {
102
107
  new Error('There is not a correct match with the pattern');
103
108
  return peaks;
104
109
  }
@@ -120,10 +120,8 @@ export default {
120
120
  // Lets check if the signal could be a singulet.
121
121
  if (peaks.length === 1 && n === 0) {
122
122
  validPattern = true;
123
- } else {
124
- if (peaks.length <= 1) {
125
- continue;
126
- }
123
+ } else if (peaks.length <= 1) {
124
+ continue;
127
125
  }
128
126
  // 1.3 Establish a range for the Heights Hi [peaks.intensity*0.85,peaks.intensity*1.15];
129
127
  let ranges = getRanges(peaks);
@@ -399,7 +397,7 @@ function getRanges(peaks: Peak1DIntern[]): GetRanges {
399
397
  }
400
398
  currentIndex[i] = 0;
401
399
  }
402
- return { values: ranges, currentIndex: currentIndex, active: 0 };
400
+ return { values: ranges, currentIndex, active: 0 };
403
401
  }
404
402
  /**
405
403
  * Performs a symmetrization of the signal by using different aproximations to the center.
@@ -533,20 +531,20 @@ function symmetrize(
533
531
  if (Math.abs(diffL - diffR) < maxError) {
534
532
  avg = Math.min(peaks[left].intensity, peaks[right].intensity);
535
533
  avgWidth = Math.min(peaks[left].width, peaks[right].width);
536
- peaks[left].intensity = peaks[right].intensity = avg;
537
- peaks[left].width = peaks[right].width = avgWidth;
534
+ peaks[left].intensity = avg;
535
+ peaks[right].intensity = avg;
536
+ peaks[left].width = avgWidth;
537
+ peaks[right].width = avgWidth;
538
538
  middle = [
539
539
  middle[0] + (peaks[right].x + peaks[left].x) / 2,
540
540
  middle[1] + 1,
541
541
  ];
542
+ } else if (Math.max(diffL, diffR) === diffR) {
543
+ mask[right] = false;
544
+ left--;
542
545
  } else {
543
- if (Math.max(diffL, diffR) === diffR) {
544
- mask[right] = false;
545
- left--;
546
- } else {
547
- mask[left] = false;
548
- right++;
549
- }
546
+ mask[left] = false;
547
+ right++;
550
548
  }
551
549
  }
552
550
  }
@@ -595,10 +593,8 @@ function symmetrize(
595
593
  weight += peaks[i].intensity;
596
594
  }
597
595
  symFactor /= weight;
598
- } else {
599
- if (peaks.length === 1) {
600
- symFactor = 1;
601
- }
596
+ } else if (peaks.length === 1) {
597
+ symFactor = 1;
602
598
  }
603
599
  let newSumHeights = 0;
604
600
  for (const peak of peaks) {
@@ -608,15 +604,13 @@ function symmetrize(
608
604
  // Sometimes we need a second opinion after the first symmetrization.
609
605
  if (symFactor > 0.8 && symFactor < 0.97 && iteration < 2) {
610
606
  return symmetrize(newSignal, maxErrorIter2, 2, key);
611
- } else {
607
+ } else if (peaks.length > 1) {
612
608
  // Center the given pattern at cs and symmetrize x
613
- if (peaks.length > 1) {
614
- let dxi;
615
- for (let i = Math.ceil(peaks.length / 2) - 1; i >= 0; i--) {
616
- dxi = (peaks[i].x - peaks[peaks.length - 1 - i].x) / 2.0;
617
- peaks[i].x = cs + dxi;
618
- peaks[peaks.length - 1 - i].x = cs - dxi;
619
- }
609
+ let dxi;
610
+ for (let i = Math.ceil(peaks.length / 2) - 1; i >= 0; i--) {
611
+ dxi = (peaks[i].x - peaks[peaks.length - 1 - i].x) / 2.0;
612
+ peaks[i].x = cs + dxi;
613
+ peaks[peaks.length - 1 - i].x = cs - dxi;
620
614
  }
621
615
  }
622
616
  newSignal.symRank = symFactor;
@@ -660,7 +654,7 @@ function normalize(signal: SignalInternMandatory, n: number) {
660
654
  let index = signal.mask2.length - 1;
661
655
  for (let i = peaks.length - 1; i >= 0; i--) {
662
656
  peaks[i].intensity *= norm;
663
- while (index >= 0 && signal.mask2[index] === false) {
657
+ while (index >= 0 && !signal.mask2[index]) {
664
658
  index--;
665
659
  }
666
660
  if (peaks[i].intensity < 0.75) {
@@ -691,7 +685,7 @@ function chemicalShift(peaks: Peak1DIntern[], mask: boolean[] = []) {
691
685
  let area;
692
686
  if (mask.length > 0) {
693
687
  for (let i = 0; i < peaks.length; i++) {
694
- if (mask[i] === true) {
688
+ if (mask[i]) {
695
689
  area = getArea(peaks[i]);
696
690
  sum += area;
697
691
  cs += area * peaks[i].x;
@@ -138,7 +138,7 @@ function completeMissingIfNeeded(
138
138
  }
139
139
  }
140
140
  }
141
- if (diagX === false) {
141
+ if (!diagX) {
142
142
  newSignal = {
143
143
  x: {
144
144
  delta: thisSignal.y.delta,
@@ -158,7 +158,7 @@ function completeMissingIfNeeded(
158
158
  properties.push(tmpProp);
159
159
  addedPeaks++;
160
160
  }
161
- if (diagY === false) {
161
+ if (!diagY) {
162
162
  newSignal = {
163
163
  x: {
164
164
  delta: thisSignal.y.delta,
@@ -202,15 +202,13 @@ function checkCrossPeaks(
202
202
  }
203
203
  crossPeaksX.push(i);
204
204
  shift += cross.x.delta;
205
- } else {
206
- if (Math.abs(cross.y.delta - signal.y.delta) < diagonalError) {
207
- hits++;
208
- if (updateProperties) {
209
- properties[i][1]++;
210
- }
211
- crossPeaksY.push(i);
212
- shift += cross.y.delta;
205
+ } else if (Math.abs(cross.y.delta - signal.y.delta) < diagonalError) {
206
+ hits++;
207
+ if (updateProperties) {
208
+ properties[i][1]++;
213
209
  }
210
+ crossPeaksY.push(i);
211
+ shift += cross.y.delta;
214
212
  }
215
213
  }
216
214
  }
@@ -278,12 +276,10 @@ function initializeProperties(signals: NMRSignal2D[]) {
278
276
  let shift = (signals[i].x.delta * 2 + signals[i].y.delta) / 3.0;
279
277
  signals[i].x.delta = shift;
280
278
  signals[i].y.delta = shift;
279
+ } else if (signals[i].x.delta - signals[i].y.delta > 0) {
280
+ signalsProperties[i][0] = 1;
281
281
  } else {
282
- if (signals[i].x.delta - signals[i].y.delta > 0) {
283
- signalsProperties[i][0] = 1;
284
- } else {
285
- signalsProperties[i][0] = -1;
286
- }
282
+ signalsProperties[i][0] = -1;
287
283
  }
288
284
  }
289
285
  return signalsProperties;
@@ -172,14 +172,12 @@ function calculateFrequency(
172
172
  ): number | string {
173
173
  if (typeof nucleus === 'string') {
174
174
  return getFrequency(nucleus, { nucleus: '1H', frequency });
175
+ } else if (nucleus[0] === nucleus[1]) {
176
+ return `${frequency},${frequency}`;
175
177
  } else {
176
- if (nucleus[0] === nucleus[1]) {
177
- return `${frequency},${frequency}`;
178
- } else {
179
- return `${frequency},${getFrequency(nucleus[1], {
180
- nucleus: nucleus[0],
181
- frequency,
182
- })}`;
183
- }
178
+ return `${frequency},${getFrequency(nucleus[1], {
179
+ nucleus: nucleus[0],
180
+ frequency,
181
+ })}`;
184
182
  }
185
183
  }
@@ -119,7 +119,7 @@ function formatSignals(predictions: Prediction[]) {
119
119
  const signal = {
120
120
  delta: delta || NaN,
121
121
  atoms,
122
- diaIDs: diaIDs,
122
+ diaIDs,
123
123
  multiplicity: 's',
124
124
  nbAtoms,
125
125
  statistic,
@@ -40,7 +40,7 @@ export function queryByHose(
40
40
  delta: res ? res[0] : null,
41
41
  atoms: [atomNumber],
42
42
  nbAtoms: 1,
43
- level: level,
43
+ level,
44
44
  statistic:
45
45
  res && res.length > 1
46
46
  ? {