The interactions of Mg 2? and Ca 2? binding to adenine, cytosine, guanine, and thymine at various binding sites were studied by a high-level quantum chemical method and ABEEMrp/MM fluctuating charge model. The geometries and binding energies of M 2? -bases complexes were determined at CCSD(T)/6-311 ??G(2d,2p)//MP2/6-311 ??G(2d,2p) level of theory, with the basis set superposition error corrections for the binding energy calculations. In comparison with the ab initio results, an accurate classical metal cation-base interaction potential was constructed and parameterized in terms of ABEEMrp/ MM model. It is revealed that Mg 2? /Ca 2? prefers to bind with bases at the bidentate position (between two nitrogen atoms or oxygen and nitrogen atoms in purine and pyrimidine), where the binding energy is the largest. Moreover, the distance between M 2? and the base increases from Mg 2? to Ca 2? , while the binding energy of Mg 2? -base is greater than that of Ca 2? -base. The ABEEMrp/MM potential gives reasonable geometries and binding energies compared with the present quantum chemical calculations, and the overall percentage RMSDs are 1.4 and 1.6% for geometries and binding energies, respectively. Furthermore, the transferability of the parameters of the new potential is validated by investigation of Mg 2? /Ca 2? binding to tautomer of bases, and results from our potential also show quite good consistency with those of MP2/6-311 ??G(2d,2p)//B3LYP/6-311 ??G(d,p) method, with the overall percentage RMSDs of 2.2 and 4.7% for geometries and binding energies, respectively. This work will serve as a basis for further investigations of the mechanisms of cation effects on the structure and property of nucleic acids.