def convert_formula_to_atomic_fractions(formula):
    """
    Converts a chemical formula to an atomic fraction :class:`dict`.

    Args:
        formula (str): chemical formula, like Al2O3. No wildcard are accepted.
    """
    mole_fractions = {}
    total_mole_fraction = 0.0

    for match in CHEMICAL_FORMULA_PATTERN.finditer(formula):
        symbol, mole_fraction = match.groups()

        z = pyxray.element_atomic_number(symbol.strip())

        if mole_fraction == '':
            mole_fraction = 1.0
        mole_fraction = float(mole_fraction)

        mole_fraction = float(mole_fraction)
        mole_fractions[z] = mole_fraction
        total_mole_fraction += mole_fraction

    # Calculate atomic fractions
    atomic_fractions = {}
    for z, mole_fraction in mole_fractions.items():
        atomic_fractions[z] = mole_fraction / total_mole_fraction

    return atomic_fractions
def convert_formula_to_atomic_fractions ( formula ) : mole_fractions = { } total_mole_fraction = 0.0 for match in CHEMICAL_FORMULA_PATTERN . finditer ( formula ) : symbol , mole_fraction = match . groups ( ) z = pyxray . element_atomic_number ( symbol . strip ( ) ) if mole_fraction == '' : mole_fraction = 1.0 mole_fraction = float ( mole_fraction ) mole_fraction = float ( mole_fraction ) mole_fractions [ z ] = mole_fraction total_mole_fraction += mole_fraction atomic_fractions = { } for z , mole_fraction in mole_fractions . items ( ) : atomic_fractions [ z ] = mole_fraction / total_mole_fraction return atomic_fractions
Converts a chemical formula to an atomic fraction :class:`dict`.

    Args:
        formula (str): chemical formula, like Al2O3. No wildcard are accepted.