import re


def BCA_formula_from_str(BCA_str):
    """
    Get chemical formula string from BCA string

    Args:
        BCA_str: BCA ratio string (e.g. 'B3C1A1')
    """
    if len(BCA_str)==6 and BCA_str[:3]=='BCA':
        # format: BCAxyz. suitable for single-digit integer x,y,z
        funits = BCA_str[-3:]
    else:
        # format: BxCyAz. suitable for multi-digit or non-integer x,y,z
        funits = re.split('[BCA]',BCA_str)
        funits = [u for u in funits if len(u) > 0]
        funits
    components = ['BaO','CaO','Al2O3']
    formula = ''.join([f'({c}){n}' for c,n in zip(components, funits)])
    return formula