Molecular cluster approach to magnesium and calcium oxide crystals. I. Perfect crystals