Mean-field theory of the interaction of the magnesium ion with biopolymers: the case of lysozyme