From 4e182461711f0f3d58063c08737f1d888a6eaae5 Mon Sep 17 00:00:00 2001 From: Venkata Nainala Date: Tue, 10 Nov 2026 09:18:38 +0100 Subject: [PATCH] fix(validate): keep the author's labels on diastereotopic pair rows --- app/scripts/nmr-cli/src/validation/validate.ts | 18 ++++++++++++------ app/scripts/nmr-cli/test/validation.test.mjs | 12 ++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/scripts/nmr-cli/src/validation/validate.ts b/app/scripts/nmr-cli/src/validation/validate.ts index 67d5d7d..4bbef88 100644 --- a/app/scripts/nmr-cli/src/validation/validate.ts +++ b/app/scripts/nmr-cli/src/validation/validate.ts @@ -351,10 +351,12 @@ function buildNucleusReport( const prediction = entry.prediction if (nucleus === '1H' && observed.length === 2 && (topology.hydrogenCounts.get(atom) ?? 0) >= 2) { - const stem = label.replace(/[ab]$/, '') + const [low, high] = observed.map((value) => + rowLabelForAtom(covering.find((row) => round(row.input.shift, 4) === value)!, atom), + ) const deviation = round(Math.abs(mean(observed) - prediction), 3) - atomRows.push({ ...base, label: `${stem}a`, observed: observed[0], deviation, status, pair: `${stem}b` }) - atomRows.push({ ...base, label: `${stem}b`, observed: observed[1], deviation, status, pair: `${stem}a` }) + atomRows.push({ ...base, label: low, observed: observed[0], deviation, status, pair: high }) + atomRows.push({ ...base, label: high, observed: observed[1], deviation, status, pair: low }) continue } @@ -419,9 +421,13 @@ function atomName(atom: number, nucleus: Nucleus, rows: NormalizedRow[]): string function labelForAtom(atom: number, nucleus: Nucleus, rows: NormalizedRow[]): string { const row = rows.find((item) => item.input.nucleus === nucleus && item.carriers.includes(atom)) if (!row) return String(atom) - if (row.carriers.length === 1) { - return row.input.diastereotopic ? row.label.replace(/[ab]$/, '') : row.label - } + if (row.carriers.length === 1 && row.input.diastereotopic) return row.label.replace(/[ab]$/, '') + return rowLabelForAtom(row, atom) +} + +/** The author's name for one atom of a row, as written ("H-5'", "H-2ax"). */ +function rowLabelForAtom(row: NormalizedRow, atom: number): string { + if (row.carriers.length === 1) return row.label const parts = row.label.split(/\s*(?:,|;|\band\b)\s*/).filter(Boolean) const position = row.atomCarriers.indexOf(atom) diff --git a/app/scripts/nmr-cli/test/validation.test.mjs b/app/scripts/nmr-cli/test/validation.test.mjs index b890abd..03e1cbd 100644 --- a/app/scripts/nmr-cli/test/validation.test.mjs +++ b/app/scripts/nmr-cli/test/validation.test.mjs @@ -187,6 +187,18 @@ test('nicotine: diastereotopic pairs are scored by their mean and low-sphere ato assert.equal(report.assignment_check.result, 'review') }) +test('diastereotopic pair rows keep the author\'s own labels (Mnova ax/eq, primes)', async () => { + const input = nicotine() + const renamed = { "H-5'a": "H-5'ax", "H-5'b": "H-5'eq" } + input.assignments = input.assignments.map((row) => (renamed[row.label] ? { ...row, label: renamed[row.label] } : row)) + + const { report } = await run(input, 'nicotine') + + const pairRows = report.reports['1H'].atoms.filter((row) => row.atoms[0] === 3) + assert.deepEqual(pairRows.map((row) => row.label), ["H-5'ax", "H-5'eq"]) + assert.deepEqual(pairRows.map((row) => row.pair), ["H-5'eq", "H-5'ax"]) +}) + test('the quality report follows the author\'s assignments, not the servlet\'s own matching', async () => { const response = structuredClone(responses['trimethoxybenzaldehyde-correct']) const proton = response.result.find((result) => result.id === 2)