How to understand the relation of the two representation of dipole moment? On one hand, the dipole moment is define as
$$\vec{\mu} = q\vec{r},$$
where q is the charge and $\vec{r}$ is a position vector.
On the other hand,
I know the transition dipole operator of a two level system can be expressed as
$$
\vec{\mu} = \mu_{ge}|g\rangle \langle e| + \mu_{eg}|e\rangle \langle g|.
$$
The interaction term between a two level system and the external electric field is usually written as
$$
H_{\mathrm{int}} = -\vec{\mu}\cdot \vec{E}(t),
$$
where $\vec{\mu}$ is the dipole moment operator and $\vec{E}(t)$ is the time-dependent electric field.
I want to know three exponents of $\vec{\mu}$ and their commutation relations, e.g.,
$\vec{\mu}_x=?$ and
$[\vec{\mu}_x,\vec{\mu}_y]=?$.
But I don't know how to relate $\vec{\mu}=\mu_0\vec{r}$ with $\vec{\mu} = \mu_{ge}|g\rangle \langle e| + \mu_{eg}|e\rangle \langle g|$ .
 A: Let me first note that this form of the interaction is independent on the direction of the electric field - liek any scalar product.
The dipole moment is usually defined as
$$
\vec{\mu} = \mu_0\vec{r},
$$
where $\vec{r}$ is just the position operator. One then needs to calculate the matrix elements of this operator between the states of interest.
Remark: There are a bit more details about how the dipole approximation comes about in my other post here.
Update
Given a complete basis of states, $|n\rangle$ we can expand the arbitrary wave function as
$$|\psi\rangle=\sum_n\psi_n|n\rangle,
$$
and represent an arbitarry operator in terms of its matrix elements in this basis:
$$
\hat{O}=\sum_{n,m}|n\rangle\langle n|\hat{O}|m\rangle\langle m |
=\sum_{n,m}|n\rangle O_{nm}\langle m |
$$
WHen dealing with the absorption of atoms/molecules one often restricst this basis to only two states (since others are energetically inaccessible): the ground state $|g\rangle$ and the excited state $|e\rangle$. One can than, e.g., express the dipole interaction as
$$
-\vec{\mu}\cdot\vec{E} = 
-|e\rangle\langle e|\vec{\mu}\cdot\vec{E}|e\rangle \langle e| 
-|e\rangle\langle e|\vec{\mu}\cdot\vec{E}|g\rangle \langle g|
-|g\rangle\langle g|\vec{\mu}\cdot\vec{E}|e\rangle \langle e|
-|g\rangle\langle g|\vec{\mu}\cdot\vec{E}|g\rangle \langle g|
$$
The diagonal elements are usually absorbed in the main two-level Hamiltonian
$$
H=
|e\rangle E_e \langle e| +
|g\rangle E_g \langle g|,
$$
and the quantization axis is often taken along the z_direction, leaving us with
$$
-\vec{\mu}\cdot\vec{E} = 
-|e\rangle\langle e|\mu_z E_z|g\rangle \langle g|
-|g\rangle\langle g|\mu_z E_z|e\rangle \langle e|
= - \mu_0 E_z\left( |e\rangle\langle e|z|g\rangle \langle g|
+|g\rangle\langle g|z|e\rangle \langle e|\right).
$$
