def calc_formation_enthalpy(ergs_react,erg_prod,coeffs):
    """
    Calculate the formation enthalpy using energies and coefficients of reactants,
    and energy of product.
    """
    if len(ergs_react) != len(coeffs):
        raise ValueError('len(ergs_react) != len(coeffs)')
    dH = erg_prod
    for i in range(len(ergs_react)):
        ei = ergs_react[i]
        ai = coeffs[i]
        dH -= ai*ei
    dH = -dH
    return dH