improved mass calculation for chemical formula generation