A method of directly computing the partition function (or the corresponding free energy) and accelerating configurational sampling is developed. In an expanded ensemble, the method can quickly sample a broad distribution and yield accurate results for the partition function. The method is shown to be efficient and accurate in studying thermodynamic properties, searching low-energy configurations of difficult molecular systems and counting solutions of puzzles. |