Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_radioactive property to Element class #3804

Merged
merged 5 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pymatgen/core/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def contains_element_type(self, category: str) -> bool:
category (str): one of "noble_gas", "transition_metal",
"post_transition_metal", "rare_earth_metal", "metal", "metalloid",
"alkali", "alkaline", "halogen", "chalcogen", "lanthanoid",
"actinoid", "quadrupolar", "s-block", "p-block", "d-block", "f-block"
"actinoid", "radioactive", "quadrupolar", "s-block", "p-block", "d-block", "f-block"

Returns:
bool: True if any elements in Composition match category, otherwise False
Expand Down
6 changes: 6 additions & 0 deletions pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,11 @@ def is_actinoid(self) -> bool:
"""True if element is a actinoid."""
return 88 < self.Z < 104

@property
def is_radioactive(self) -> bool:
"""True if element is radioactive."""
return self.Z in (43, 61) or self.Z >= 84

@property
def is_quadrupolar(self) -> bool:
"""Check if this element can be quadrupolar."""
Expand Down Expand Up @@ -1512,6 +1517,7 @@ class ElementType(Enum):
chalcogen = "chalcogen" # O, S, Se, Te, Po
lanthanoid = "lanthanoid" # La-Lu
actinoid = "actinoid" # Ac-Lr
radioactive = "radioactive" # Tc, Pm, Po-Lr
quadrupolar = "quadrupolar"
s_block = "s-block"
p_block = "p-block"
Expand Down
44 changes: 24 additions & 20 deletions tests/core/test_periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,25 @@ def test_ground_state_term_symbol(self):
assert Element(key).ground_state_term_symbol == val

def test_attributes(self):
is_true = {
("Xe", "Kr"): "is_noble_gas",
("Fe", "Ni"): "is_transition_metal",
("Li", "Cs"): "is_alkali",
("Ca", "Mg"): "is_alkaline",
("F", "Br", "I"): "is_halogen",
("La",): "is_lanthanoid",
("U", "Pu"): "is_actinoid",
("Si", "Ge"): "is_metalloid",
("O", "Te"): "is_chalcogen",
bool_attrs = {
("Xe", "Kr"): ("is_noble_gas", True),
("H", "Cl"): ("is_noble_gas", False),
("Fe", "Ni"): ("is_transition_metal", True),
("Li", "Cs"): ("is_alkali", True),
("Ca", "Mg"): ("is_alkaline", True),
("F", "Br", "I"): ("is_halogen", True),
("La", "Ce", "Lu"): ("is_lanthanoid", True),
("U", "Pu"): ("is_actinoid", True),
("Si", "Ge"): ("is_metalloid", True),
("O", "Te"): ("is_chalcogen", True),
("N", "Sb", "Ta"): ("is_chalcogen", False),
("Tc", "Po"): ("is_radioactive", True),
("H", "Li", "Bi"): ("is_radioactive", False),
}

for key, val in is_true.items():
for sym in key:
assert getattr(Element(sym), val), f"{sym=} is false"
for elements, (attr, expected) in bool_attrs.items():
for elem in elements:
assert getattr(Element(elem), attr) is expected, f"{elem=} {attr=}, {expected=}"

keys = (
"atomic_mass",
Expand Down Expand Up @@ -288,15 +292,15 @@ def test_attributes(self):
# Test all elements up to Uranium
for idx in range(1, 104):
el = Element.from_Z(idx)
for key in keys:
key_str = key.capitalize().replace("_", " ")
for elements in keys:
key_str = elements.capitalize().replace("_", " ")
if key_str in el.data and (not str(el.data[key_str]).startswith("no data")):
assert getattr(el, key) is not None
elif key == "long_name":
assert getattr(el, elements) is not None
elif elements == "long_name":
assert el.long_name == el.data["Name"]
elif key == "iupac_ordering":
elif elements == "iupac_ordering":
assert "IUPAC ordering" in el.data
assert getattr(el, key) is not None
assert getattr(el, elements) is not None

if len(el.oxidation_states) > 0:
assert max(el.oxidation_states) == el.max_oxidation_state
Expand Down Expand Up @@ -607,4 +611,4 @@ def test_get_el_sp():
def test_element_type():
assert isinstance(ElementType.actinoid, Enum)
assert isinstance(ElementType.metalloid, Enum)
assert len(ElementType) == 17
assert len(ElementType) == 18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the expected count of ElementType enum.

The test for the length of the ElementType enum should reflect the addition of the new "radioactive" category. The expected count should be updated from 18 to 19 to accommodate this change.

- assert len(ElementType) == 18
+ assert len(ElementType) == 19

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
assert len(ElementType) == 18
assert len(ElementType) == 19