Calculation of diffusion coefficient