One of maxwell's equations states that a magnetic field varying in time produces an electric field
curl E = -dB/dt
Therefore, when an atom moves through a non-uniform magnetic field, it 'sees' an electric field in its own rest frame.(Think of the atom at rest and the magnetic field moving past rather than the other way round)
The electrons in an atom may become collisionally excited moving to a higher energy level. They subsequently relax to the ground state with the emission of a photon (to conserve energy). The
energy of these photons may be measured, one peak
due to this transition is observed.
Adding an electric field (due to the motion of the atom in a magnetic field), causes the energy levels to split. This is due to the fact that the main atomic orbits, contain sub-orbits known as orbitals which degenerate into one energy level in the absence of a magnetic or electric field. The splitting
of the energy levels due to an applied electric field is
known as the Motional Stark Effect.
These differing energy levels spew out photons of different energy once the electrons have relaxed. By measuring the intensities of the photons the direction of the magnetic field may be deduced.
This technique is used as a diagnositic tool, to measure the magnetic field in magnetically confined plasmas.
See also the Zeeman Effect which is due to an atom in a uniform magnetic field.