Skip to content

Spell EXFOR symbols by reaction-string slot (fixes #17) - #18

Open
beykyle wants to merge 2 commits into
mainfrom
fix-light-nuclide-symbols
Open

beykyle wants to merge 2 commits into
mainfrom
fix-light-nuclide-symbols

Conversation

@beykyle

@beykyle beykyle commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Fixes #17.

Problem

get_exfor_particle_symbol spelled every nucleus the same way regardless of where it sits in the reaction string. EXFOR's light-particle codes (N, P, D, T, A) are only legal in the incident and outgoing slots (SF2/SF3); targets and residuals (SF1/SF4) are always nuclides. So a proton target was sent to x4i3 as target='P', but the index only knows H-1 — and the same for d, t and α targets. Every such query came back empty.

The projectile slot had the mirror-image problem: the x4i3 index spells ³He as HE3 and heavy ions as Z-SYM-A (e.g. 6-C-12), whereas we sent He-3 / C-12, so ³He and heavy-ion projectiles (and ³He / heavy ejectiles in the reaction= string) also matched nothing.

Fix

Split the function by slot:

  • get_exfor_nuclide_symbol(A, Z) → Sym-A (H-1, He-4, Fe-0), for target and residual. Raises on Z=0: a neutron is never a target or residual, and N-1 would read as nitrogen.
  • get_exfor_particle_symbol(A, Z) → N/P/D/T/HE3/A, else Z-Sym-A, for projectile and product.

Adding HE3 to the particle codes is only safe because ³He targets now go through the nuclide function.

is_match and parsing are untouched: they compare (A, Z) tuples, and work unchanged once the query returns the right entries.

reaction_string changes for light targets and heavy-ion projectiles, e.g. P(N,el) → H-1(N,el) and C-12(C-12,el) → C-12(6-C-12,el). Anything keyed on that string will shift, but those reactions returned no data before.

Tests

tests/test_light_nuclides.py:

  • Unit tests for both symbol functions across the light nuclides, ³He, a heavy ion, natural targets and the neutron.
  • reaction_string for light targets and a ³He projectile.
  • Query and parse tests, pinned against x4i3_X4-2023-04-29, for n+p (10036), p+p (A0192), d+d (A1003), α+⁴He (A1146), p+³He (A1022), p+⁴He (A0925), ³He+⁵⁸Ni (C1976) and ¹²C+¹²C (A0842). These assert membership, not counts, so they survive database updates. A0192, A1003 and A1146 carry both DATA-ERR and ERR-1, so their error attribution is passed explicitly, read from each entry's ERR-ANALYSIS.
  • A regression test that heavy-target queries (p+²⁰⁸Pb, n+⁵⁶Fe, p+⁴⁸Ca) still return the entries they did before. I checked the full result sets for these by hand across dXS/dA, dXS/dRuth and Ay, and they are identical.

All 35 tests pass.


Generated by Claude Code

EXFOR's light-particle codes (N, P, D, T, A) are only legal in the incident
and outgoing slots of a reaction string; targets and residuals are always
nuclides. get_exfor_particle_symbol ignored the slot, so querying with a
proton, deuteron, triton or alpha target sent target='P' etc. to x4i3, whose
index only has 'H-1', 'H-2', 'H-3', 'HE-4' -- every such query came back
empty (#17).

Split it in two:
- get_exfor_nuclide_symbol: Sym-A, for target and residual; raises on Z=0.
- get_exfor_particle_symbol: light-particle code, else Z-Sym-A, for
  projectile and product.

The projectile slot had the mirror-image bug: the x4i3 index spells 3He as
HE3 and heavy ions as Z-SYM-A (6-C-12), so 3He and heavy-ion projectiles
also returned nothing. HE3 is added to the particle codes, which is only
safe now that 3He targets go through the nuclide function.

Tests pin entries for n+p, p+p, d+d, a+4He, p+3He, p+4He, 3He+58Ni and
12C+12C against x4i3_X4-2023-04-29, and check that heavy-target queries
still return the entries they did before.

Fixes #17

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A0192, A1003 and A1146 carry both DATA-ERR and ERR-1, which exfor_tools
correctly refuses to attribute on its own. Pass the attribution read from
each entry's ERR-ANALYSIS so every query case also checks parsing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Not finding reactions with proton target.

2 participants