Skip to content

utils.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: float) -> 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, float]:
    """
    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

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