In crystal periodic structure prediction, a general equation is needed to determine the period vectors (cell edge vectors), especially when crystals are under arbitrary external stress. It has been derived in Newtonian dynamics years ago, which can be combined with quantum mechanics by further modeling. Here we derived such an equation in statistical physics, applicable to both classical physics and quantum physics by itself.