Improve atom quality calculation