Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix simulation of only negatives chemical shift #2475

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
275 changes: 182 additions & 93 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"multiplet-analysis": "^2.1.1",
"nmr-correlation": "^2.3.3",
"nmr-load-save": "^0.13.2",
"nmr-processing": "^9.7.1",
"nmr-processing": "9.7.3-pre.1687951924",
"nmredata": "^0.9.2",
"numeral": "^2.0.6",
"openchemlib": "^8.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/component/1d/multiAnalysis/MultiAnalysisRanges.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AnalysisColumnsTypes, SpectraAnalysisColumns } from 'nmr-load-save';
import { memo } from 'react';

import { useChartData } from '../../context/ChartContext';
import { usePanelPreferences } from '../../hooks/usePanelPreferences';

import AnalysisRange from './AnalysisRange';
import { AnalysisColumnsTypes, SpectraAnalysisColumns } from 'nmr-load-save';

interface MultiAnalysisRangesInnerProps {
displayerKey: string;
Expand Down
2 changes: 1 addition & 1 deletion src/component/header/BaseLineCorrectionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Yup from 'yup';

import { useDispatch } from '../context/DispatchContext';
import ActionButtons from '../elements/ActionButtons';
import { InputStyle } from '../elements/Input';
import Label from '../elements/Label';
import Select from '../elements/Select';
import FormikCheckBox from '../elements/formik/FormikCheckBox';
Expand All @@ -14,7 +15,6 @@ import { useFilter } from '../hooks/useFilter';

import { headerLabelStyle } from './Header';
import { HeaderContainer } from './HeaderContainer';
import { InputStyle } from '../elements/Input';

interface BaseLineCorrectionInnerPanelProps {
filter: Filter | null;
Expand Down
14 changes: 12 additions & 2 deletions src/component/modal/PredictSpectraModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { StateMoleculeExtended } from '../../data/molecules/Molecule';
import { useChartData } from '../context/ChartContext';
import { useDispatch } from '../context/DispatchContext';
import { useLogger } from '../context/LoggerContext';
import Button from '../elements/Button';
import CheckBox from '../elements/CheckBox';
import CloseButton from '../elements/CloseButton';
Expand Down Expand Up @@ -77,6 +78,7 @@ function PredictSpectraModal({
});
}, [predictionPreferences, predictionIndex]);

const { logger } = useLogger();
const submitHandler = useCallback(
(values) => {
void (async () => {
Expand All @@ -96,7 +98,7 @@ function PredictSpectraModal({
);

try {
const data = await predictSpectra(molfile);
const data = await predictSpectra(molfile, logger);
dispatch({
type: 'PREDICT_SPECTRA',
payload: {
Expand All @@ -114,7 +116,15 @@ function PredictSpectraModal({
}
})();
},
[alert, dispatch, isApproved, molecule, onClose, setPredictionPreferences],
[
alert,
dispatch,
isApproved,
molecule,
onClose,
logger,
setPredictionPreferences,
],
);

const approveCheckHandler = useCallback((e) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useFormikContext } from 'formik';
import { AnalysisColumnsTypes } from 'nmr-load-save';
import { useMemo, useCallback } from 'react';
import { FaPlus, FaTimes } from 'react-icons/fa';

import Button from '../../../elements/Button';
import ReactTable, { Column } from '../../../elements/ReactTable/ReactTable';
import FormikInput from '../../../elements/formik/FormikInput';
import { AnalysisColumnsTypes } from 'nmr-load-save';

const inputStyle = { input: { width: '100%', fontSize: '1.15em' } };

Expand Down
4 changes: 3 additions & 1 deletion src/component/panels/predictionPanel/PredictionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { predictSpectra } from '../../../data/PredictionManager';
import { StateMoleculeExtended } from '../../../data/molecules/Molecule';
import { useChartData } from '../../context/ChartContext';
import { useDispatch } from '../../context/DispatchContext';
import { useLogger } from '../../context/LoggerContext';
import Button from '../../elements/Button';
import NextPrev from '../../elements/NextPrev';
import { useAlert } from '../../elements/popup/Alert';
Expand Down Expand Up @@ -40,6 +41,7 @@ export default function PredictionPanel() {
} = useChartData();
const dispatch = useDispatch();
const alert = useAlert();
const { logger } = useLogger();
const [currentIndex, setCurrentIndex] = useState(0);
const [molfile, setMolfile] = useState<string | null>(null);
const [isFlipped, setFlipStatus] = useState(false);
Expand Down Expand Up @@ -93,7 +95,7 @@ export default function PredictionPanel() {
);

try {
const data = await predictSpectra(molfile);
const data = await predictSpectra(molfile, logger);
dispatch({
type: 'PREDICT_SPECTRA',
payload: {
Expand Down
11 changes: 6 additions & 5 deletions src/component/reducer/actions/DatabaseActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ function handleResurrectSpectrumFromRanges(
action: ResurrectSpectrumFromRangesAction,
) {
const { ranges, info } = action.payload;

const datum = generateSpectrumFromRanges(ranges, info, draft.usedColors);
draft.data.push(datum);
setDomain(draft, { isYDomainShared: false });
setIntegralsYDomain(draft, [datum]);
setZoom(draft, { scale: 0.8, spectrumID: datum.id });
if (datum) {
draft.data.push(datum);
setDomain(draft, { isYDomainShared: false });
setIntegralsYDomain(draft, [datum]);
setZoom(draft, { scale: 0.8, spectrumID: datum.id });
}
}

export { handleResurrectSpectrumFromRanges, handleResurrectSpectrumFromJcamp };
8 changes: 6 additions & 2 deletions src/component/reducer/actions/IntegralsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ function handleAddIntegral(draft: Draft<State>, action: AddIntegralAction) {
const { x, re } = datum.data;

const shiftX = getShiftX(datum);

const integration = xyIntegration(
{ x, y: re },
{ from, to, reverse: true },
);
const integral = {
id: v4(),
originFrom: from - shiftX,
originTo: to - shiftX,
from,
to,
absolute: xyIntegration({ x, y: re }, { from, to, reverse: true }), // the real value
integral: integration,
absolute: integration,
kind: 'signal',
};
datum.integrals.values.push(integral);
Expand Down
1 change: 0 additions & 1 deletion src/component/reducer/actions/MoleculeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ function handlePredictSpectraFromMolecule(
molecule,
action: predictionAction = 'save',
} = action.payload;

const color = generateColor(false, draft.usedColors['1d']);
const spectraIds: string[] = [];
for (const spectrum of generateSpectra(predictedSpectra, options, color)) {
Expand Down
8 changes: 5 additions & 3 deletions src/component/reducer/actions/SpectrumsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,11 @@ function handleGenerateSpectrumFromPublicationStringHandler(
publicationString,
draft.usedColors,
);
draft.data.push(spectrum);
setActiveTab(draft);
setZoom(draft, { scale: 0.8, spectrumID: spectrum.id });
if (spectrum) {
draft.data.push(spectrum);
setActiveTab(draft);
setZoom(draft, { scale: 0.8, spectrumID: spectrum.id });
}
}

//action
Expand Down
8 changes: 7 additions & 1 deletion src/data/PredictionManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { v4 } from '@lukeed/uuid';
import { FifoLogger } from 'fifo-logger';
import { Spectrum } from 'nmr-load-save';
import {
Signal2D,
Expand Down Expand Up @@ -37,6 +38,7 @@ export interface PredictionOptions {
nbPoints: { x: number; y: number };
};
spectra: SpectraPredictionOptions;
logger?: FifoLogger;
}

export const defaultPredictionOptions: PredictionOptions = {
Expand Down Expand Up @@ -75,10 +77,14 @@ export const FREQUENCIES: Array<{ value: number; label: string }> = [

const baseURL = 'https://nmr-prediction.service.zakodium.com';

export async function predictSpectra(molfile: string): Promise<PredictedAll> {
export async function predictSpectra(
molfile: string,
logger: FifoLogger,
): Promise<PredictedAll> {
const molecule = OCL.Molecule.fromMolfile(molfile);

return predictAll(molecule, {
logger,
predictOptions: {
C: {
webserviceURL: `${baseURL}/v1/predict/carbon`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Spectrum1D } from 'nmr-load-save';
import { resurrect } from 'nmr-processing';

import { UsedColors } from '../../../types/UsedColors';
Expand All @@ -8,7 +7,7 @@
export function generateSpectrumFromPublicationString(
publicationString: string,
usedColors: UsedColors,
): Spectrum1D {
) {

Check warning on line 10 in src/data/data1d/Spectrum1D/generateSpectrumFromPublicationString.ts

View check run for this annotation

Codecov / codecov/patch

src/data/data1d/Spectrum1D/generateSpectrumFromPublicationString.ts#L10

Added line #L10 was not covered by tests
const {
ranges,
experiment: { nucleus, solvent },
Expand Down
25 changes: 15 additions & 10 deletions src/data/data1d/Spectrum1D/ranges/detectSignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,22 @@

function joinCouplings(result: any) {
const { chemShift: delta, js } = result;
let jCouplings = js;
if (js.length > 1) {
try {
jCouplings = signalJoinCouplings(
{
delta,
js,
},
{ tolerance: 0.6, ignoreDiaIDs: true },
).js;
} catch (error) {
reportError(error);
}

Check warning on line 92 in src/data/data1d/Spectrum1D/ranges/detectSignal.ts

View check run for this annotation

Codecov / codecov/patch

src/data/data1d/Spectrum1D/ranges/detectSignal.ts#L91-L92

Added lines #L91 - L92 were not covered by tests
}
return {
delta,
js:
js.length > 1
? signalJoinCouplings(
{
delta,
js,
},
{ tolerance: 0.6, ignoreDiaIDs: true },
).js
: js,
js: jCouplings,
};
}
49 changes: 26 additions & 23 deletions src/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,34 @@
ranges: NMRRange[],
info: ResurrectSpectrumInfo,
usedColors: UsedColors,
): Spectrum1D {
): Spectrum1D | undefined {

Check warning on line 19 in src/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.ts

View check run for this annotation

Codecov / codecov/patch

src/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.ts#L19

Added line #L19 was not covered by tests
const { nucleus, solvent, name = null, frequency = 400 } = info;

const { x, y } = rangesToXY(ranges, {
nucleus,
frequency,
nbPoints: 2 ** 17,
});

const datum = initiateDatum1D(
{
data: { x, im: null, re: y },
info: {
nucleus,
originFrequency: frequency,
baseFrequency: frequency,
pulseSequence: '',
solvent,
isFt: true,
name,
try {
const { x, y } = rangesToXY(ranges, {
nucleus,
frequency,
nbPoints: 2 ** 17,
});
const datum = initiateDatum1D(
{
data: { x, im: null, re: y },
info: {
nucleus,
originFrequency: frequency,
baseFrequency: frequency,
pulseSequence: '',
solvent,
isFt: true,
name,
},
ranges: { values: ranges, options: { sum: 100 } },

Check warning on line 40 in src/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.ts

View check run for this annotation

Codecov / codecov/patch

src/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.ts#L22-L40

Added lines #L22 - L40 were not covered by tests
},
ranges: { values: ranges, options: { sum: 100 } },
},
{ usedColors },
);
{ usedColors },
);

Check warning on line 43 in src/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.ts

View check run for this annotation

Codecov / codecov/patch

src/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.ts#L42-L43

Added lines #L42 - L43 were not covered by tests

return datum;
return datum;
} catch (error) {
reportError(error);
}

Check warning on line 48 in src/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.ts

View check run for this annotation

Codecov / codecov/patch

src/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.ts#L45-L48

Added lines #L45 - L48 were not covered by tests
}
Loading