where E D,q and E bulk are the total energies of defected and pristine supercells, respectively. µ i is the chemical potential of element i, and n i is the number of atoms of element i added (n i > 0) or removed (n i < 0) from the pristine supercell to create the defect D. E Fermi is the Fermi energy, which is referenced to the valence band maximum. E corr is the correction to the defect formation energy to account for the finite-size e↵ects and un-derestimation of the band gap. Following the methodology of Lany and Zunger , we included the following finite-size corrections: (i) alignment of the average electrostatic potential between supercells with and without charged defects, (ii) long-range electrostatic interactions between periodic images of point charges, and (iii) band filling due to shallow defects.