def test_make_defect_energy_info(mocker):
    defect_entry = mocker.Mock(DefectEntry, autospec=True)
    defect_entry.name = "Va_Mg1"
    defect_entry.charge = -1

    calc_results = mocker.Mock(CalcResults, autospec=True)
    calc_results.structure = IStructure(Lattice.cubic(1.0), ["O"], [[0.0]*3])
    calc_results.energy = 10.0
    calc_results.electronic_conv = False

    correction = mocker.Mock(Correction, autospec=True)
    correction.correction_dict = {"a": 10.0}

    p_calc_results = mocker.Mock(CalcResults, autospec=True)
    p_calc_results.structure = IStructure(Lattice.cubic(1.0),
                                          ["Mg", "O"], [[0.0]*3]*2)
    p_calc_results.energy = 1.0

    standard_energies = StandardEnergies({"Mg": 10.0, "O": 20.0})

    unitcell = mocker.Mock()
    unitcell.vbm = 100.0

    actual = make_defect_energy_info(defect_entry, calc_results, correction,
                                     p_calc_results, standard_energies, unitcell)
    energy = DefectEnergy(formation_energy=10.0 - 1.0 + 10 - 100.0,
                          energy_corrections={"a": 10.0},
                          is_shallow=None)
    expected = DefectEnergyInfo(name="Va_Mg1", charge=-1,
                                atom_io={"Mg": -1}, defect_energy=energy)
    assert actual == expected
Ejemplo n.º 2
0
def make_defect_energy_info(
        defect_entry: DefectEntry,
        calc_results: CalcResults,
        correction: Correction,
        perfect_calc_results: CalcResults,
        standard_energies: StandardEnergies,
        unitcell: Unitcell,
        band_edge_states: BandEdgeStates = None) -> DefectEnergyInfo:
    atom_io = num_atom_differences(calc_results.structure,
                                   perfect_calc_results.structure)

    formation_energy = calc_results.energy - perfect_calc_results.energy
    formation_energy += defect_entry.charge * unitcell.vbm
    for k, v in atom_io.items():
        formation_energy -= standard_energies[k] * v

    is_shallow = band_edge_states.is_shallow if band_edge_states else None
    energy = DefectEnergy(formation_energy=formation_energy,
                          energy_corrections=correction.correction_dict,
                          is_shallow=is_shallow)

    return DefectEnergyInfo(defect_entry.name,
                            defect_entry.charge,
                            atom_io=atom_io,
                            defect_energy=energy)
Ejemplo n.º 3
0
def test_make_defect_energy_summary(mocker):
    energy1 = DefectEnergy(0.0, {"PC correction": 2.0}, False)
    energy2 = DefectEnergy(1.0, {"PC correction": 3.0}, True)
    defect_infos = [
        DefectEnergyInfo("Va_Mg1", 0, {"Mg": -1}, energy1),
        DefectEnergyInfo("Va_Mg1", 1, {"Mg": -1}, energy2)
    ]
    target_vertices = TargetVertices(target="MgO",
                                     vertices={"A": TargetVertex({"Mg": 5.0})})

    unitcell = mocker.Mock()
    unitcell.vbm = 1.0
    unitcell.cbm = 11.0

    perf_be_state = mocker.Mock()
    perf_be_state.vbm_info.energy = 0.0
    perf_be_state.cbm_info.energy = 12.0

    actual = make_defect_energy_summary(defect_infos, target_vertices,
                                        unitcell, perf_be_state)

    defect_energies = {
        "Va_Mg1":
        DefectEnergies(atom_io={"Mg": -1},
                       charges=[0, 1],
                       defect_energies=[energy1, energy2])
    }

    expected = DefectEnergySummary(title=unitcell.system,
                                   defect_energies=defect_energies,
                                   rel_chem_pots={"A": {
                                       "Mg": 5.0
                                   }},
                                   cbm=10.0,
                                   supercell_vbm=-1.0,
                                   supercell_cbm=11.0)
    assert actual == expected
Ejemplo n.º 4
0
def defect_energy_info2():
    energy = DefectEnergy(formation_energy=0.0,
                          energy_corrections={"no correction": 0.0})
    return DefectEnergyInfo(name="hole polaron", charge=1, atom_io={},
                            defect_energy=energy)
Ejemplo n.º 5
0
def defect_energy_info(defect_energy):
    return DefectEnergyInfo(name="Va_O1", charge=1, atom_io={"O": -1},
                            defect_energy=defect_energy)
Ejemplo n.º 6
0
 def _inner(_dir: Path):
     return DefectEnergyInfo.from_yaml(str(_dir /
                                           "defect_energy_info.yaml"))