Potential energy and magnetic fields