Example #1
0
def _is_element_or_specie(s: str) -> bool:
    if s in ['D', 'D+', 'D-', 'T']:
        return True
    try:
        _ = Element(s)
    except ValueError:
        try:
            _ = Specie.from_string(s)
        except ValueError:
            print(s)
            return False
    return True
Example #2
0
def _get_atomic_mass(element_or_specie: str) -> float:
    """
    Get atomic mass from element or specie string

    Args:
        element_or_specie (str): specie or element string

    Returns: float mass

    """
    try:
        return Element(element_or_specie).atomic_mass
    except Exception:
        return Specie.from_string(element_or_specie).element.atomic_mass
Example #3
0
def _get_charge(element_or_specie: Union[str, Element, Specie]) -> float:
    """
    Get charge from element or specie

    Args:
        element_or_specie (str or Element or Specie): element or specie

    Returns: charge float

    """

    if isinstance(element_or_specie, Specie):
        return element_or_specie.oxi_state
    if isinstance(element_or_specie, str):
        try:
            return Specie.from_string(element_or_specie).oxi_state
        except Exception:
            return 0.0
    return 0.0