Approximating partition functions of spin systems and its applications