A theoretical study of the positive and dipositive ions of M(NH3)n and M(H2O)n for M = Mg, Ca, or Sr