예제 #1
0
def load_isotopes(symbol: str,
                  combobox: QtWidgets.QComboBox,
                  current_isotope=None,
                  show_std_mass=False):
    """Load isotopes of given element into given combobox.

    Args:
        symbol: string representation of an element, e.g. 'He'.
        combobox: QComboBox to which items are added.
        current_isotope: Current isotope to select it on combobox by default.
        show_std_mass: if True, std mass is added as the first element
    """
    combobox.clear()
    # Sort isotopes based on their natural abundance
    isotopes = Element.get_isotopes(symbol, include_st_mass=show_std_mass)

    for idx, iso in enumerate(isotopes):
        if iso["element"].isotope is None:
            # Standard mass option
            txt = f"{round(iso['element'].get_mass())} (st. mass)"
        else:
            # Isotope specific options
            txt = f"{iso['element'].isotope} ({round(iso['abundance'], 3)}%)"
        combobox.addItem(txt, userData=iso)
        if current_isotope == iso["element"].isotope:
            combobox.setCurrentIndex(idx)
예제 #2
0
    def assert_isotopes_match(self, symbol, isotopes, include_st_mass):
        isos = Element.get_isotopes(symbol, include_st_mass=include_st_mass)

        self.assertEqual(len(isotopes), len(isos))

        if include_st_mass and isos:
            self.assertIsNone(isos[0]["abundance"])

        for n, iso in zip(isotopes, isos):
            self.assertEqual(["element", "abundance", "mass"],
                             list(iso.keys()))
            self.assertEqual(Element("H", n), iso["element"])
예제 #3
0
 def test_get_isotopes(self):
     self.assert_isotopes_match("H", (1, 2), include_st_mass=False)
     self.assert_isotopes_match("H", (None, 1, 2), include_st_mass=True)
     self.assertEqual([], Element.get_isotopes("U", include_st_mass=True))