def formula2components(formula):
    """Convert a glass/any composition formula to component dictionary.

    Parameters
    ----------
    formula : string
        Glass/any composition for e.g. 50Na2O-50SiO2.

    Returns
    -------
    dictionary
        Dictionary where keys are components of glass/any composition and values are their ratio.

    """
    dict1 = {}
    parts = formula.split('-')
    if len(parts)==1:
        dict1[parts[0]] = 1.0
    else:
        for i in parts:
            k = ''
            p = ''
            for ind, j in enumerate(i):
                try:
                    float(j)
                    p += j
                except:
                    if j == '.':
                        p += j
                    else:
                        k = i[ind:]
                        break
            dict1[k] = float(p)
    if sum(dict1.values())==100:
        for k,v in dict1.items():
            dict1[k] = dict1[k]/100
        return dict1
    elif sum(dict1.values())==1.0:
        return dict1
    else:
        try:
            raise Exception("Invalid Formula: {}.".format(formula))
        except Exception as e:
            print(e)
            raise