Electric dipole interaction with electric field in the Hamiltonian formalism 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?
 A: Your 'ideal' dipole is a uniform rigid rod with no mass (and hence its moment of inertia about any axis, through any point, is zero). As such, $p_{\theta}$ and its derivative $\dot{p_{\theta}}$ are trivially (always) zero since, assuming the dipole is fixed at its centre but is free to rotate in $\theta$ and $\phi$, $p_{\theta} = I_{CoM}\dot{\theta}$. Since $I_{CoM}$ is zero, so is $p_{\theta}$. The linear analogue of this would be trying to derive the equations of motion for a massless particle.
If you give your dipole a moment of inertia about an axis through its centre of mass and perpendicular to its length $I \equiv I_{Rod,CoM}$ (alternatively, you could model the dipole as a massless rod with two point masses on either end, giving a different $I$), and call the dipole moment $w$ (I won't use $p$ to avoid confusion with the momenta) one obtains the following Lagrangian (defining the $z$-axis (polar axis) to lie in the direction of $\vec{E_0}$):
$$\mathcal{L} = \frac{I}{2}[\dot{\theta}^2+sin(\theta)^2 \dot{\phi}^2] + wEcos(\theta)cos(\phi)$$
Note the presence of $cos{(\phi)}$ in the dipole interaction term; as per your original post, we're allowing freedom in both $\phi$ and $\theta$. This gives rise to the following conjugate momenta:
$$p_{\theta} = I \dot{\theta}\ ,\ p_{\phi} = Isin(\theta)^2 \dot{\phi}$$
This gives the Hamiltonian, expressed in $p_{\theta}$, $\theta$, $p_{\phi}$ and $\phi$ only: 
$$H = \frac{p_{\theta}^2}{2I} + \frac{p_{\phi}^2}{2Isin(\theta)^2} - wEcos(\theta)cos(\phi)$$
From this, one can turn the handle and obtain the expressions for $\dot{\theta}$, etc, as desired, using Hamilton's equations as stated in your original post.
