Skip to content

Commit

Permalink
Return preferred pdgid in from_nucleus_info
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Sep 6, 2024
1 parent 0236134 commit b727c65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/particle/particle/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,11 @@ def from_nucleus_info(
pdgid = int(1e9 + l_strange * 1e5 + z * 1e4 + a * 10 + i)

if anti:
return cls.from_pdgid(-pdgid)
pdgid = -pdgid

# replace nucleon ids of single hadrons with quark version
if pdgid in _PREFERRED_PDGID:

Check warning on line 1123 in src/particle/particle/particle.py

View workflow job for this annotation

GitHub Actions / pre-commit

Consider using dict.get for getting values from a dict if a key is present or a default if not
pdgid = _PREFERRED_PDGID[pdgid]

return cls.from_pdgid(pdgid)

Expand Down
4 changes: 4 additions & 0 deletions tests/particle/test_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def test_from_nucleus_info():
p = Particle.from_nucleus_info(1, 2, anti=True)
assert p.pdgid == -1000010020

# proton and neutron should return the preferred quark representation
assert Particle.from_nucleus_info(a=1, z=1).pdgid == 2212
assert Particle.from_nucleus_info(a=1, z=0).pdgid == 2112


def test_from_nucleus_info_ParticleNotFound():
with pytest.raises(ParticleNotFound):
Expand Down

0 comments on commit b727c65

Please sign in to comment.