Skip to content

Commit

Permalink
Reinstate neutron as element Z=0, but exclude it from the iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Kienzle committed Oct 8, 2024
1 parent 48135c6 commit 3b5c431
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
9 changes: 6 additions & 3 deletions periodictable/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ def __iter__(self):
"""
Process the elements in Z order
"""
for _, el in sorted(self._element.items()):
# CRUFT: Since 3.7 dictionaries use insertion order, so no need to sort
elements = sorted(self._element.items())
# Skipping the first entry (neutron) in the iterator
for _, el in elements[1:]:
yield el

def symbol(self, input):
Expand Down Expand Up @@ -604,7 +607,7 @@ def _make_isotope_ion(table, Z, n, c):
element_base = {
# number: name symbol common_ions uncommon_ions
# ion info comes from Wikipedia: list of oxidation states of the elements.
# 0: ['Neutron', 'n', [], []],
0: ['neutron', 'n', [], []],
1: ['Hydrogen', 'H', [-1, 1], []],
2: ['Helium', 'He', [], [1, 2]], # +1,+2 http://periodic.lanl.gov/2.shtml
3: ['Lithium', 'Li', [1], []],
Expand Down Expand Up @@ -764,7 +767,7 @@ def define_elements(table, namespace):
for el in table:
names[el.symbol] = el
names[el.name] = el
for el in [table.D, table.T]:
for el in [table.D, table.T, table.n]:
names[el.symbol] = el
names[el.name] = el

Expand Down
2 changes: 1 addition & 1 deletion periodictable/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def init(table, reload=False):
el.density_caveat = ""

element_densities = dict(
# n=None, # No longer using element 0 for a bare neutron
n=None, # No longer using element 0 for a bare neutron
H=(0.0708, "T=-252.87"),
He=(0.122, "T=-268.93"),
Li=0.534,
Expand Down
12 changes: 6 additions & 6 deletions periodictable/mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ def init(table, reload=False):
iso._abundance, iso._abundance_unc = 0, 0

# # A single neutron is an isotope of element 0
# from .constants import neutron_mass, neutron_mass_unc
# el = table[0]
# el._mass, el._mass_unc = neutron_mass, neutron_mass_unc
# iso = el.add_isotope(1)
# iso._mass, iso._mass_unc = neutron_mass, neutron_mass_unc
# iso._abundance, iso._abundance_unc = 100, 0
from .constants import neutron_mass, neutron_mass_unc
el = table.n
el._mass, el._mass_unc = neutron_mass, neutron_mass_unc
iso = el.add_isotope(1)
iso._mass, iso._mass_unc = neutron_mass, neutron_mass_unc
iso._abundance, iso._abundance_unc = 100, 0

# Parse element mass table where each line looks like:
# z El element mass(unc)|[low,high]|- note note ...
Expand Down
5 changes: 1 addition & 4 deletions periodictable/nsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,6 @@ def init(table, reload=False):
symbol = parts[1]
isotope_number = int(parts[2]) if len(parts) == 3 else 0

if Z == 0: # Skip row 0-n-1
continue

# Fetch element from the table and check that the symbol matches
element = table[Z]
assert element.symbol == symbol, \
Expand All @@ -580,7 +577,7 @@ def init(table, reload=False):
nsf._number_density = element.number_density # N/cm^3 = N/cm^3

if isotope_number == 0:
# Bulk values using laboratory abundances of isotopes
# Value for element using laboratory abundances of isotopes
element.neutron = nsf
else:
# Values for the individual isotope
Expand Down
15 changes: 14 additions & 1 deletion test/test_nsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import periodictable
from periodictable import elements, formula, nsf
from periodictable.nsf import neutron_scattering, neutron_sld
from periodictable.constants import avogadro_number as N_A
from periodictable.constants import avogadro_number as N_A, neutron_mass

def test():
H,He,D,O = elements.H,elements.He,elements.D,elements.O
Expand Down Expand Up @@ -135,6 +135,19 @@ def test():
assert all(abs(v-w)<1e-14 for v,w in zip(xs,xs2))
assert abs(depth-depth2)<1e-14

def test_bare_neutron():
n = elements.n
assert n == elements[0]
assert n == periodictable.neutron
n_iso = elements[0][1]
assert n.mass == neutron_mass
assert n_iso.mass == neutron_mass
assert n.neutron.b_c == -37.0
assert n.density is None
assert n.number_density is None
assert n.neutron.scattering()[0] is None


def test_formula():
density = 2.52
M = formula('B4C', density=density)
Expand Down

0 comments on commit 3b5c431

Please sign in to comment.