Discrepancy between energy calculated via the equipartition theorem and the partition function I am doing some homework on statistical mechanics, and I'm facing something I can't seem to understand/find what I'm doing wrong.
Suppose we have a diatomic molecule, both atoms have mass $m$. Suppose the molecule isn't moving, and it is in thermal equilibrium with a heat bath at a temperature $T$. The chemical bond can be modelled as a simple harmonic oscillator, such that the Hamiltonian is given by
$$ H = K (x_1 - x_2)^2, $$
where $x_1$ and $x_2$ are the positions of atom $1$ and $2$.
We now apply the equipartition theorem:
$$ \left\langle x_1 \frac{\partial H}{\partial x_1} \right\rangle = \langle 2K x_1 (x_1 - x_2 ) \rangle = k_BT $$
$$ \left\langle x_2 \frac{\partial H}{\partial x_2} \right\rangle = \langle -2K x_2 (x_1 - x_2 ) \rangle = k_BT $$
When we take the sum of both, we get
$$ \langle 2K (x_1 - x_2)(x_1 - x_2) \rangle = 2 \langle K (x_1 - x_2)^2 \rangle = 2 \langle H\rangle = 2k_BT \implies \langle H\rangle = k_{B}T.$$
This result isn't in agreement with the energy calculated via the canonical partition function, or just the energy of an harmonic oscillator in one-dimension: which gives
$$ \langle H\rangle = \frac{k_{B}T}{2}.$$
If someone can point out what I'm doing wrong, I would greatly appreciate it! Thanks.
 A: There is something funny about this Hamiltonian since it "hides" an interaction term:
$$H(x_1,x_2)=K(x_1^2+x_2^2-2x_1x_2).$$
I'd feel safer working with other coordinates, in which you see clearly the distinction between the roles of the different degrees of freedom. Say I work with the coordinates $x=x_1$ and $d=x_1-x_2$. The Hamiltonian in these coordinates is a function only of $d$:
$$H(d)=Kd^2.$$
The other spatial degree of freedom, $x$, has no potential associated. Therefore, the particle has to be contained in a box of limited length (say $L$); otherwise the canonical partition function would "blow up".
In this setting, the equipartition theorem associates $1/2 k_BT$ to the spatial contribution to the energy (only one quadratic degree of freedom in the Hamiltonian). If you compute the canonical partition function, you'll have $Z=\lim_{L\to\infty} L \sqrt{\frac{\pi k_B T}{2K}}$, so that the energy per molecule is again $1/2 k_BT$.
I am not sure why the equipartition theorem doesn't work well in the coordinates $x_1$, and $x_2$. But this is my bet, let's compute $\langle x_1\partial_{x_1} H(x_1,x_2)\rangle$:
$$\langle x_1\partial_{x_1} H(x_1,x_2)\rangle=\lim_{L\to \infty}\int_{x_1\in[-\frac{L}{2},\frac{L}{2}]}dx_1\int_{x2\in[-\frac{L}{2},\frac{L}{2}]}dx_2\,  x_1 \partial_{x_1} \left[-\frac{1}{\beta}e^{-\beta H(x_1,x_2)}\right].$$
Integrating by parts:
$$-\beta\langle x_1\partial_{x_1} H(x_1,x_2)\rangle=\lim_{L\to \infty}\int_{x2\in[-\frac{L}{2},\frac{L}{2}]}dx_2\,    \left[x_1e^{ H(x_1,x_2)}\right]_{x_1=-L/2}^{x_1=L/2}-1.$$
The thing is that I am not that sure that you can equal the first summand to zero (as one would do when working with the coordinates $r$ and $x$ that I proposed earlier). I'd say that the equipartition theorem is less subtle when $e^{-\beta H}$ factorizes.
A: You have used two variables to describe a system with only one degree of freedom.  If you define a new variable $y=x_{1}-x_{2}$ and write the Hamiltonian in terms of this $y$, $H=Ky^{2}$, then $\left\langle y\frac{\partial H}{\partial y}\right\rangle$ gives the correct energy.
The complementary position variable to $y$ is $z=x_{1}+x_{2}$, and since you have assumed that the center of the dipole is fixed in position, $z$ takes on a fixed value.  There is only one state of $z$ possible; it is always just twice the coordinate of the midpoint of the molecule, and since it cannot vary, its available states cannot serve as a reservoir of energy, and it does not contribute a $\frac{1}{2}kT$ to the mean energy.  Formally, you can see that it is impossible to have $\left\langle z\frac{\partial H}{\partial z}\right\rangle$ be nonzero, because $H$ does not depend on $z$, so $\frac{\partial H}{\partial z}$ vanishes identically.
Knowing the correct number of degrees of freedom that can contribute to the mean energy of a system via equipartition is often easier when there kinetic terms included.  Counting the number of degrees of freedom for the kinetic terms is relatively easy, and that counting process helps identify spurious degrees of freedom that do not have any possibility of physical variation.
A: Equipartition theorem assigns energy $k_B T/2$ per degree of freedom. Here you have two atoms with positions $x_1, x_2$ (and momenta $p_1,p_2$), that is two degrees of freedom:
$$
H=\frac{p_1^2}{2M}+\frac{p_2^2}{2M} + K(x_1-x_2)^2
$$
Alternatively, one could treat the molecule in its center-of-mas reference frame, in which case we have one degree of freedom corresponding to the motion of the molecule as a whole, and one corresponding to the oscillations of the atoms in respect to each other: $$P=p_1+p_2,p=p_1-p_2,X=(x_1+x_2)/2,x=x_1-x_2\\\longrightarrow
H=\frac{P^2}{4M}+\frac{p^2}{4M}+Kx^2
$$
