Skip to content

Species

Utilities for species.

get_sign(charge)

Get string representation of a number's sign.

Parameters:

Name Type Description Default
charge int

The number whose sign to derive.

required

Returns:

Name Type Description
sign str

either '+', '-', or '' for neutral.

Source code in src/elementembeddings/utils/species.py
def get_sign(charge: int) -> str:
    """Get string representation of a number's sign.

    Args:
        charge (int): The number whose sign to derive.

    Returns:
        sign (str): either '+', '-', or '' for neutral.

    """
    if charge > 0:
        return "+"
    elif charge < 0:
        return "-"
    else:
        return ""

parse_species(species)

Parse a species string into its atomic symbol and oxidation state.

:param species: the species string :return: a tuple of the atomic symbol and oxidation state

Source code in src/elementembeddings/utils/species.py
def parse_species(species: str) -> Tuple[str, int]:
    """
    Parse a species string into its atomic symbol and oxidation state.

    :param species: the species string
    :return: a tuple of the atomic symbol and oxidation state

    """
    try:
        ele, oxi_state = re.match(r"([A-Za-z]+)([0-9]*[\+\-])", species).groups()
        if oxi_state[-1] in ["+", "-"]:
            charge = (int(oxi_state[:-1] or 1)) * (-1 if "-" in oxi_state else 1)
            return ele, charge
        else:
            return ele, 0
    except AttributeError:
        return _parse_species_old(species)