예제 #1
0
    def test_get_transition_level_and_energy(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = DefectChargeState(2, -1, 1)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])

        assert defect.get_transition_level_and_energy(0, 2) == (1.5, 2)
예제 #2
0
    def test_charge_state_concentrations(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = FrozenDefectChargeState(2, 0.1234)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])
        assert defect.charge_state_concentrations(0.2, 300) == {
            0: 2.520453931443997e-34,
            2: 0.1234
        }
예제 #3
0
 def test_update_frozen_chgstates(self):
     string = "V_Ga -1 0.19E+19\nGa_i 1 0.5E+20"
     string = string.splitlines()
     defects = [
         DefectSpecies('V_Ga', 1, [DefectChargeState(-1, 1, 1)]),
         DefectSpecies('Ga_i', 1, [DefectChargeState(1, 1, 1)])
     ]
     update_frozen_chgstates(string, defects, 1, 2)
     assert_almost_equal(defects[0].get_concentration(0.1, 300), 1.9e-06)
     assert_almost_equal(defects[1].get_concentration(0.1, 300), 5e-05)
예제 #4
0
    def test_fixed_concentration_charge_states(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = DefectChargeState(2, -1, 1)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])
        assert defect.fixed_conc_charge_states() == {}
        defect.charge_states[2] = FrozenDefectChargeState(2, 0.1234)
        assert defect.fixed_conc_charge_states() == {
            2: defect.charge_states[2]
        }
예제 #5
0
    def test_min_energy_charge_state(self):

        charge_state_1 = DefectChargeState(-1, 0.1, 1)
        charge_state_2 = DefectChargeState(-2, 0.2, 1)
        defect = DefectSpecies('O_i', 1, [charge_state_1, charge_state_2])

        self.assertEqual(defect.min_energy_charge_state(0),
                         defect.charge_states[-1])
        self.assertEqual(defect.min_energy_charge_state(2),
                         defect.charge_states[-2])
예제 #6
0
    def test_variable_concentration_charge_states(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = DefectChargeState(2, -1, 1)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])
        assert defect.variable_conc_charge_states() == {
            0: charge_state_1,
            2: charge_state_2
        }
        defect.charge_states[2] = FrozenDefectChargeState(2, 0.1234)
        assert defect.variable_conc_charge_states() == {0: charge_state_1}
예제 #7
0
 def setUp(self):
     name = "V_O"
     nsites = 2
     mock_charge_states = [
         Mock(spec=DefectChargeState),
         Mock(spec=DefectChargeState),
     ]
     mock_charge_states[0].charge = 0
     mock_charge_states[1].charge = 1
     mock_charge_states[0].concentration_is_fixed = False
     mock_charge_states[1].concentration_is_fixed = False
     self.defect_species = DefectSpecies(name=name,
                                         nsites=nsites,
                                         charge_states=mock_charge_states)
예제 #8
0
 def test_update_frozen_defect_species(self):
     string = "V_Ga  0.3285677364522E+20"
     string = string.splitlines()
     defects = [DefectSpecies('V_Ga', 1, [])]
     update_frozen_defect_species(string, defects, 1, 1)
     assert_almost_equal(defects[0].get_concentration(0.1, 298),
                         3.285677364522e-05)
예제 #9
0
 def test_charge_states_by_formation_energy_with_frozen_charge_state(self):
     name = "V_O"
     nsites = 2
     mock_charge_states = [
         Mock(spec=DefectChargeState),
         Mock(spec=FrozenDefectChargeState),
     ]
     mock_charge_states[0].charge = 0
     mock_charge_states[1].charge = 1
     defect_species = DefectSpecies(name=name,
                                    nsites=nsites,
                                    charge_states=mock_charge_states)
     defect_species.variable_conc_charge_states = Mock(
         return_value={0: defect_species.charge_states[0]})
     defect_species.charge_states[0].get_formation_energy = Mock(
         return_value=0.3)
     sorted_charge_states = defect_species.charge_states_by_formation_energy(
         e_fermi=0.0)
     self.assertEqual(sorted_charge_states,
                      [defect_species.charge_states[0]])
예제 #10
0
    def test_get_concentrations(self):

        charge_state_1 = DefectChargeState(-1, 1.1, 1)
        charge_state_2 = DefectChargeState(-2, 1.2, 1)
        defect = DefectSpecies('O_i', 1, [charge_state_1, charge_state_2])

        assert_almost_equal(defect.get_concentration(0.2, 300),
                            3.7117030892903665e-14)
        defect.fix_concentration(0.1234)
        assert_almost_equal(defect.get_concentration(0.2, 300), 0.1234)
예제 #11
0
 def test_defect_species_is_initialised(self):
     name = "foo"
     nsites = 2
     mock_charge_states = [
         Mock(spec=DefectChargeState),
         Mock(spec=DefectChargeState),
     ]
     mock_charge_states[0].charge = 0
     mock_charge_states[1].charge = 1
     defect_species = DefectSpecies(name=name,
                                    nsites=nsites,
                                    charge_states=mock_charge_states)
     self.assertEqual(defect_species._name, name)
     self.assertEqual(defect_species._nsites, nsites)
     self.assertEqual(defect_species._charge_states[0],
                      mock_charge_states[0])
     self.assertEqual(defect_species._charge_states[1],
                      mock_charge_states[1])
     self.assertEqual(defect_species._fixed_concentration, None)
예제 #12
0
class TestDefectSpecies(unittest.TestCase):
    def setUp(self):
        name = "V_O"
        nsites = 2
        mock_charge_states = [
            Mock(spec=DefectChargeState),
            Mock(spec=DefectChargeState),
        ]
        mock_charge_states[0].charge = 0
        mock_charge_states[1].charge = 1
        mock_charge_states[0].concentration_is_fixed = False
        mock_charge_states[1].concentration_is_fixed = False
        self.defect_species = DefectSpecies(name=name,
                                            nsites=nsites,
                                            charge_states=mock_charge_states)

    def test_name_property(self):
        self.assertEqual(self.defect_species.name, self.defect_species._name)

    def test_nsites_property(self):
        self.assertEqual(self.defect_species.nsites,
                         self.defect_species._nsites)

    def test_charge_states_property(self):
        self.assertEqual(self.defect_species.charge_states,
                         self.defect_species._charge_states)

    def test_fixed_concentration_property(self):
        self.defect_species._fixed_concentration = 0.1234
        self.assertEqual(
            self.defect_species.fixed_concentration,
            self.defect_species._fixed_concentration,
        )

    def test_fix_concentration(self):
        assert self.defect_species.fixed_concentration == None
        self.defect_species.fix_concentration(0.1234)
        self.assertEqual(self.defect_species.fixed_concentration, 0.1234)

    def test_charge_states_by_formation_energy(self):
        self.defect_species.charge_states[0].get_formation_energy = Mock(
            return_value=0.3)
        self.defect_species.charge_states[1].get_formation_energy = Mock(
            return_value=0.1)
        self.defect_species.variable_conc_charge_states = Mock(
            return_value={
                0: self.defect_species.charge_states[0],
                1: self.defect_species.charge_states[1],
            })
        sorted_charge_states = self.defect_species.charge_states_by_formation_energy(
            e_fermi=0.0)
        self.assertEqual(sorted_charge_states[0],
                         self.defect_species.charge_states[1])
        self.assertEqual(sorted_charge_states[1],
                         self.defect_species.charge_states[0])

    def test_charge_states_by_formation_energy_with_frozen_charge_state(self):
        name = "V_O"
        nsites = 2
        mock_charge_states = [
            Mock(spec=DefectChargeState),
            Mock(spec=FrozenDefectChargeState),
        ]
        mock_charge_states[0].charge = 0
        mock_charge_states[1].charge = 1
        defect_species = DefectSpecies(name=name,
                                       nsites=nsites,
                                       charge_states=mock_charge_states)
        defect_species.variable_conc_charge_states = Mock(
            return_value={0: defect_species.charge_states[0]})
        defect_species.charge_states[0].get_formation_energy = Mock(
            return_value=0.3)
        sorted_charge_states = defect_species.charge_states_by_formation_energy(
            e_fermi=0.0)
        self.assertEqual(sorted_charge_states,
                         [defect_species.charge_states[0]])

    def test_get_formation_energies(self):
        self.defect_species.charge_states[0].get_formation_energy = Mock(
            return_value=0.3)
        self.defect_species.charge_states[1].get_formation_energy = Mock(
            return_value=0.1)
        self.defect_species.variable_conc_charge_states = Mock(
            return_value={
                0: self.defect_species.charge_states[0],
                1: self.defect_species.charge_states[1],
            })
        formation_energies_dict = self.defect_species.get_formation_energies(
            0.0)
        self.assertEqual(formation_energies_dict, {0: 0.3, 1: 0.1})

    def test_min_energy_charge_state(self):

        charge_state_1 = DefectChargeState(-1, 0.1, 1)
        charge_state_2 = DefectChargeState(-2, 0.2, 1)
        defect = DefectSpecies('O_i', 1, [charge_state_1, charge_state_2])

        self.assertEqual(defect.min_energy_charge_state(0),
                         defect.charge_states[-1])
        self.assertEqual(defect.min_energy_charge_state(2),
                         defect.charge_states[-2])

    def test_get_concentrations(self):

        charge_state_1 = DefectChargeState(-1, 1.1, 1)
        charge_state_2 = DefectChargeState(-2, 1.2, 1)
        defect = DefectSpecies('O_i', 1, [charge_state_1, charge_state_2])

        assert_almost_equal(defect.get_concentration(0.2, 300),
                            3.7117030892903665e-14)
        defect.fix_concentration(0.1234)
        assert_almost_equal(defect.get_concentration(0.2, 300), 0.1234)

    def test_get_transition_level_and_energy(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = DefectChargeState(2, -1, 1)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])

        assert defect.get_transition_level_and_energy(0, 2) == (1.5, 2)

    def test_fixed_concentration_charge_states(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = DefectChargeState(2, -1, 1)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])
        assert defect.fixed_conc_charge_states() == {}
        defect.charge_states[2] = FrozenDefectChargeState(2, 0.1234)
        assert defect.fixed_conc_charge_states() == {
            2: defect.charge_states[2]
        }

    def test_variable_concentration_charge_states(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = DefectChargeState(2, -1, 1)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])
        assert defect.variable_conc_charge_states() == {
            0: charge_state_1,
            2: charge_state_2
        }
        defect.charge_states[2] = FrozenDefectChargeState(2, 0.1234)
        assert defect.variable_conc_charge_states() == {0: charge_state_1}

    def test_variable_concentration_charge_states(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = DefectChargeState(2, -1, 1)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])
        assert defect.variable_conc_charge_states() == {
            0: charge_state_1,
            2: charge_state_2
        }
        defect.charge_states[2] = FrozenDefectChargeState(2, 0.1234)
        assert defect.variable_conc_charge_states() == {0: charge_state_1}

    def test_charge_state_concentrations(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = FrozenDefectChargeState(2, 0.1234)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])
        assert defect.charge_state_concentrations(0.2, 300) == {
            0: 2.520453931443997e-34,
            2: 0.1234
        }

    def test_defect_charge_contributions(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = FrozenDefectChargeState(2, 0.1234)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])
        assert defect.defect_charge_contributions(0.2, 300) == (0.2468, 0.0)

    def test_tl_profile(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = DefectChargeState(2, -1, 1)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])
        assert_equal(defect.tl_profile(0, 5), [[0, -1], [1.5, 2], [5, 2]])
예제 #13
0
    def test_tl_profile(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = DefectChargeState(2, -1, 1)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])
        assert_equal(defect.tl_profile(0, 5), [[0, -1], [1.5, 2], [5, 2]])
예제 #14
0
    def test_defect_charge_contributions(self):

        charge_state_1 = DefectChargeState(0, 2, 1)
        charge_state_2 = FrozenDefectChargeState(2, 0.1234)
        defect = DefectSpecies('V_O', 1, [charge_state_1, charge_state_2])
        assert defect.defect_charge_contributions(0.2, 300) == (0.2468, 0.0)