Definition of the magnetic Hamiltonian