Role of magnesium ions in the reaction mechanism at the interface between Tm1631 protein and its DNA ligand