We report the results of first-principles calculations carried out within a relativistic density-functional method, on the molecular trimers of the MX2 compounds (with M = Zn or Cd and X = Cl, Br, or I), showing how a distorted tetrahedral coordination of a group-2B metal atom by halogens first arises. The trimers of HgX2 are also discussed, both in unstable and in stable configurations.