If we have one ideal dipole $\mathbf{p}$ in one electric field $\mathbf{E} = E_0\mathbf{\hat{z}}$ we know that the potential energy is:
$$U = -\mathbf{p}\cdot \mathbf{E}.$$
Once we know that the dipole has a initial orientation, one can derive that with time it will evolve until it aligns with $\mathbf{E}$.
I wanted to describe this in the Hamiltonian formalism. The reason for that is to latter use this in the context of statistical mechanics, to compute the partition function.
For that I thought on using the dipole orientation $(\theta,\phi)$ as generalized coordinates, since one ideal dipole is just a vector and since its magnitude is fixed.
In that setting since $\mathbf{E}$ is uniform, in the direction $\mathbf{\hat{z}}$ we have directly that
$$U = -E_0 p\cos \theta.$$
Because of that we could infer that
$$H(\theta,\phi,p_{\theta},p_{\phi})=-E_0p\cos \theta.$$
But this doesn't seem right, because when I try to derive the equations for the evolution of the system we have:
$$\dfrac{dp_{\theta}}{dt}=-\dfrac{\partial H}{\partial \theta}=-E_0p\sin\theta,$$
$$\dfrac{dp_{\phi}}{dt}=-\dfrac{\partial H}{\partial \phi}=0,$$
$$\dfrac{d\theta}{dt}=\dfrac{\partial H}{\partial p_{\theta}}=0,$$
$$\dfrac{d\phi}{dt}=\dfrac{\partial H}{\partial p_{\phi}}=0.$$
Now, this tells that $\theta = \theta_0$ which is certainly wrong, since with time the dipole tends to align with the field.
I've also tried to start from the Lagrangian $L = T - V$, but that's no good. The dipole is not actualy moving, indeed the dipole here is just a vector fixed somewhere with the orientation changing, so it seems that $T = 0$. With that if we were to derive the momentum $p_\theta$ and $p_\phi$ from the Lagrangian we would get just $p_\theta = p_\phi = 0$.
What am I doing wrong here? How does one treat one ideal electric dipole in Hamiltonian Mechanics?