materialsproject / pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
https://pymatgen.org
Other
1.52k stars 867 forks source link

[Breaking/Fix] Skip isotopes when iterating through `core.Element` #4180

Open DanielYang59 opened 1 week ago

DanielYang59 commented 1 week ago

Summary

This would be a breaking change (also might be called a fix), so comments are hugely appreciated.


from pymatgen.core import Element

for idx, ele in enumerate(Element):
    print(idx, ele)

Before

0 H
1 H  # Deuterium
2 H  # Tritium
3 He
4 Li
5 Be
6 B
7 C
......

Now (nothing special, just skip isotopes of hydrogen)

0 H
1 He
2 Li
3 Be
4 B
5 C
......
shyuep commented 1 week ago

I agree isotopes shouldn't appear as part of default behavior.

esoteric-ephemera commented 1 week ago

That was an oversight on my part, thanks for the fix! Also agree that enumerating over elements shouldn't list isotopes. Maybe adding a method to Element to show people which isotopes are available would be useful tho?

DanielYang59 commented 6 days ago

That was an oversight on my part, thanks for the fix!

No problem at all, cannot blame anyone, it's the test that is missing, together we improve test coverage :)

Maybe adding a method to Element to show people which isotopes are available would be useful tho?

Fair point, is current implementation looking good to you @esoteric-ephemera (I don't have much experience overwriting an Enum so not sure if there's any pitfall like builtin dict/list/..., do review with a pinch of salt)?

Element.named_isotopes # ---> (Element.D, Element.T)
DanielYang59 commented 6 days ago

@janosh I believe you're very experienced with Enum (while I'm not), perhaps you could help me double-check the implementation?