Symmetry-general least-squares extraction of elastic coefficients from ab initio total energy calculations