The calculation of free energies in semiconductors: defects, transitions and phase diagrams