Skip to content

Commit

Permalink
[ENH] Add isotope method to access isotopes from Element (#225)
Browse files Browse the repository at this point in the history
* add isotope accessor

* relock
  • Loading branch information
lmmentel authored Jan 7, 2025
1 parent 392b15f commit 9aaed9a
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 149 deletions.
27 changes: 27 additions & 0 deletions mendeleev/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,33 @@ def inchi(self) -> str:
"""
return f"InchI=1S/{self.symbol}"

@hybrid_method
def isotope(self, mass_number: int) -> Isotope:
"""
Return the isotope with the given atomic mass number.
Examples:
>>> from mendeleev import H
>>> H.isotopes
[<Isotope(Z=1, A=1, mass=1.00782503190(1), abundance=99.986(8))>,
<Isotope(Z=1, A=2, mass=2.01410177784(2), abundance=0.015(8))>,
<Isotope(Z=1, A=3, mass=3.01604928132(8), abundance=None)>,
<Isotope(Z=1, A=4, mass=4.0264(1), abundance=None)>,
<Isotope(Z=1, A=5, mass=5.03531(10), abundance=None)>,
<Isotope(Z=1, A=6, mass=6.0450(3), abundance=None)>,
<Isotope(Z=1, A=7, mass=7.053(1), abundance=None)>]
>>> H.isotope(2)
<Isotope(Z=1, A=2, mass=2.01410177784(2), abundance=0.015(8))>
"""
selected = next(
(iso for iso in self.isotopes if iso.mass_number == mass_number), None
)
if selected is None:
raise ValueError(f"No Isotope with mass number {mass_number} found")
else:
return selected

@property
def annotation(self):
"Temporary property before before removing annotation"
Expand Down
Loading

0 comments on commit 9aaed9a

Please sign in to comment.