Determination of the crystal structure of magnesium perchlorate hydrates by X-ray powder diffraction and the charge-flipping method.