Skip to content

Commit

Permalink
Propagate changes to other implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
mobiusklein committed Nov 26, 2023
1 parent 9ec0bb1 commit 8e271a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/brainpy/_speedup.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,21 @@ cpdef Element make_fixed_isotope_element(Element element, int neutrons):

def _isotopes_of(element):
freqs = dict()
for i, mass_freqs in nist_mass[element].items():
mono_neutrons = None
element_data = nist_mass[element]
for i, mass_freqs in element_data.items():
if i == 0:
if isinstance(mass_freqs[0], int):
mono_neutrons = mass_freqs[0]
continue
if mass_freqs[1] > 0:
freqs[i] = mass_freqs
if len(freqs) == 0:
return dict()
if mono_neutrons is not None and mono_neutrons in element_data:
freqs = [
(0, Isotope(*element_data[mono_neutrons], neutron_shift=0, neutrons=mono_neutrons))
]
return dict(freqs)
mono_neutrons = max(freqs.items(), key=lambda x: x[1][1])[0]
freqs = list(sorted(
[(k - mono_neutrons, Isotope(*v, neutron_shift=k - mono_neutrons, neutrons=k))
Expand Down
12 changes: 10 additions & 2 deletions src/brainpy/brainpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,21 @@ def make_fixed_isotope_element(element, neutrons):

def _isotopes_of(element):
freqs = dict()
for i, mass_freqs in nist_mass[element].items():
mono_neutrons = None
element_data = nist_mass[element]
for i, mass_freqs in element_data.items():
if i == 0:
if isinstance(mass_freqs[0], int):
mono_neutrons = mass_freqs[0]
continue
if mass_freqs[1] > 0:
freqs[i] = mass_freqs
if len(freqs) == 0:
return OrderedDict()
if mono_neutrons is not None and mono_neutrons in element_data:
freqs = [
(0, Isotope(*element_data[mono_neutrons], neutron_shift=0, neutrons=mono_neutrons))
]
return OrderedDict(freqs)
mono_neutrons = max(freqs.items(), key=lambda x: x[1][1])[0]
freqs = OrderedDict(sorted(((k - mono_neutrons, Isotope(*v, neutron_shift=k - mono_neutrons, neutrons=k))
for k, v in freqs.items()), key=lambda x: x[0]))
Expand Down
5 changes: 5 additions & 0 deletions tests/test_isotopic_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def test_neutral_mass(self):
self.assertAlmostEqual(inst.mz, ref.mz, 3)
self.assertAlmostEqual(inst.intensity, ref.intensity, 3)

def test_bad_isotopic_specification(self):
comp = {"Cm": 1}
dist = isotopic_variants(comp)
assert len(dist) == 1

if _has_c:
def test_pure_python(self):
hexnac = {'H': 13, 'C': 8, 'O': 5, 'N': 1}
Expand Down

0 comments on commit 8e271a5

Please sign in to comment.