Diagrammatic evaluation of the density operator for nonlinear optical calculations