Skip to content
Open
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
18 changes: 12 additions & 6 deletions app/scripts/nmr-cli/src/validation/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions app/scripts/nmr-cli/test/validation.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading