Esempio n. 1
0
def _is_aromatic(atom_symbol: str) -> bool:
    """Checks whether a SMILES atom symbol is an aromatic SMILES atom symbol.

    An aromatic SMILES atom symbol is indicated by an element substring
    that is not capitalized.

    :param atom_symbol: a SMILES atom symbol.
    :return: True, if ``atom_symbol`` is an aromatic atom symbol,
        and False otherwise.
    """

    s, e = find_element(atom_symbol)

    if e == len(atom_symbol):  # optimization to prevent string copying
        element = atom_symbol
    else:
        element = atom_symbol[s:e]

    if element[0].isupper():  # check if element is capitalized
        return False

    if element not in _aromatic_valences:
        raise ValueError(
            "unrecognized aromatic symbol '{}'".format(atom_symbol))
    return True
Esempio n. 2
0
def _capitalize(atom_symbol: str) -> str:
    """Capitalizes the element portion of an aromatic SMILES atom symbol,
    converting it into a standard SMILES atom symbol.

    :param atom_symbol: an aromatic SMILES atom symbol.
    :return: the capitalized ``atom_symbol``.
    """

    s, _ = find_element(atom_symbol)
    return atom_symbol[:s] + atom_symbol[s].upper() + atom_symbol[s + 1:]