Exemplo n.º 1
0
def test_make_calc_summary(mocker):
    defect_entry = mocker.Mock(spec=DefectEntry, autospec=True)
    defect_entry.name = "Va_O1"
    defect_entry.charge = 1
    defect_entry.full_name = "Va_O1_1"

    calc_results = mocker.Mock(spec=CalcResults, autospec=True)
    calc_results.structure = \
        IStructure(Lattice.cubic(1.0), ["Mg"], [[0.0]*3])
    calc_results.energy = 10.0 + defaults.abs_strange_energy - 0.1

    structure_info = mocker.Mock(spec=DefectStructureInfo, autospec=True)

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

    actual = make_calc_summary(calc_set=[(calc_results, defect_entry,
                                          structure_info)],
                               p_calc_results=p_calc_results)
    single_summary = SingleCalcSummary(
        charge=1,
        atom_io={"O": -1},
        electronic_conv=calc_results.electronic_conv,
        ionic_conv=calc_results.ionic_conv,
        is_energy_strange=False,
        same_config_from_init=structure_info.same_config_from_init,
        defect_type=structure_info.defect_type,
        symm_relation=structure_info.symm_relation)
    expected = CalcSummary({"Va_O1_1": single_summary})

    assert actual == expected
Exemplo n.º 2
0
def test_make_single_defect_energy(mocker):
    perfect = mocker.Mock(CalcResults, autospec=True)
    perfect.energy = 1.0
    perfect.structure = IStructure(Lattice.cubic(1), ["H"] * 2, [[0] * 3] * 2)

    defect = mocker.Mock(CalcResults, autospec=True)
    defect.energy = 3.0
    defect.structure = IStructure(Lattice.cubic(1), ["H"], [[0] * 3])

    name, charge = "Va_H1", 5
    defect_entry = mocker.Mock(DefectEntry, autospec=True)
    defect_entry.name = name
    defect_entry.charge = charge

    single_defect_energy = \
        make_single_defect_energy(perfect=perfect,
                                  defect=defect,
                                  defect_entry=defect_entry,
                                  abs_chem_pot={Element.H: 100},
                                  correction=ManualCorrection(7.0))
    energy = 3.0 - 1.0 + 100

    assert isinstance(single_defect_energy, SingleDefectEnergy)
    assert single_defect_energy == SingleDefectEnergy(name, charge, energy,
                                                      7.0)
def structure_analyzer():
    cu2o_perfect = IStructure(
        Lattice.cubic(5),
        species=["Cu"] * 4 + ["O"] * 2,
        coords=[
            [0.25, 0.25, 0.25],  # removed
            [0.25, 0.74, 0.74],  # removed
            [0.75, 0.75, 0.25],
            [0.75, 0.25, 0.75],
            [0, 0, 0],
            [0.5, 0.5, 0.5]
        ])

    # add [0.1, -0.1, 0]
    # 3rd -- 6th
    # [0.85, 0.65, 0.25] - [0.76, 0.73, 0.24] = [0.09, -0.08, 0.01]
    # [0.85, 0.15, 0.75] - [0.75, 0.25, 0.73] = [0.10, -0.10, 0.02]
    # [0.1, -0.1, 0] -[0.1, -0.1, 0] = [0, 0, 0]
    # [0.6, 0.4, 0.5] - [0.5, 0.5, 0.5] = [0.1, -0.1, 0]
    cu2o_defect = IStructure(
        Lattice.cubic(5),
        species=["Cu"] * 3 + ["O"] * 2 + ["H"],
        coords=[
            [0.25, 0.5, 0.5],  # defect
            [0.76, 0.73, 0.24],
            [0.75, 0.25, 0.73],
            [0.05, 0.95, 0],
            [0.5, 0.5, 0.5],
            [0.25] * 3
        ])  # defect

    return DefectStructureComparator(defect_structure=cu2o_defect,
                                     perfect_structure=cu2o_perfect)
Exemplo n.º 4
0
def test_make_defect_entry(defect_entry):
    relaxed_coords = \
        [[0.25, 0.0, 0.0], [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5],
         [0.0, 0.0, 0.51], [0.0, 0.51, 0.0], [0.5, 0.0, 0.0], [0.5, 0.5, 0.5]]
    relaxed_defect = IStructure(
        Lattice.cubic(10.0), ["Li"] + ["H"] * 3 + ["He"] * 4, relaxed_coords)

    unrelaxed_coords = \
        [[0.25, 0.0, 0.0], [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5],
         [0.0, 0.0, 0.5], [0.0, 0.5, 0.0], [0.5, 0.0, 0.0], [0.5, 0.5, 0.5]]

    unrelaxed_defect = IStructure(
        Lattice.cubic(10.0), ["Li"] + ["H"] * 3 + ["He"] * 4, unrelaxed_coords)

    actual = make_defect_entry(name="Va_O1",
                               charge=1,
                               perfect_structure=perfect,
                               defect_structure=relaxed_defect)

    expected = DefectEntry(name="Va_O1",
                           charge=1,
                           structure=unrelaxed_defect,
                           perturbed_structure=None,
                           site_symmetry="4mm",
                           defect_center=(0.125, 0.0, 0.0))

    assert actual == expected
Exemplo n.º 5
0
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
Exemplo n.º 6
0
def complex_monoclinic():
    lattice = Lattice.monoclinic(3, 4, 5, 100)
    coords = [[0.0, 0.0, 0.0], [0.1, 0.0, 0.0], [0.9, 0.0, 0.0],
              [0.2, 0.0, 0.0], [0.8, 0.0, 0.0]]
    return IStructure(lattice=lattice,
                      species=["H", "He", "He", "He", "He"],
                      coords=coords)
Exemplo n.º 7
0
def simple_cubic_2x2x2():
    lattice = Lattice.cubic(2.0)
    coords = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0], [0.5, 0.0,
                                                 0.5], [0.0, 0.5, 0.5],
              [0.0, 0.0, 0.5], [0.0, 0.5, 0.0], [0.5, 0.0, 0.0],
              [0.5, 0.5, 0.5]]
    return IStructure(lattice=lattice, species=["H"] * 8, coords=coords)
def structure_analyzer_periodic_issue():
    cu2o_perfect = IStructure(Lattice.cubic(5),
                              species=["Cu"] * 4 + ["O"] * 2,
                              coords=[[0.25, 0.25, 0.25], [0.25, 0.75, 0.75],
                                      [0.75, 0.75, 0.25], [0.75, 0.25, 0.75],
                                      [0, 0, 0], [0.5, 0.5, 0.5]])

    # defect center is ([1.0, 1.0, 1.0] + [0.99, 0.99, 0.99]) / 2 = [0.995]*3
    cu2o_defect = IStructure(Lattice.cubic(5),
                             species=["Cu"] * 4 + ["O"] + ["H"],
                             coords=[[0.25, 0.25, 0.25], [0.25, 0.75, 0.75],
                                     [0.75, 0.75, 0.25], [0.75, 0.25, 0.75],
                                     [0.5, 0.5, 0.5], [0.99, 0.99, 0.99]])

    return DefectStructureComparator(defect_structure=cu2o_defect,
                                     perfect_structure=cu2o_perfect)
Exemplo n.º 9
0
def make_defect_entry(name: str, charge: int, perfect_structure: IStructure,
                      defect_structure: IStructure):

    analyzer = DefectStructureAnalyzer(perfect_structure, defect_structure)

    species = []
    frac_coords = []
    for d, p in enumerate(analyzer.p_to_d):
        if p is None:
            site = defect_structure[d]
        else:
            site = perfect_structure[p]
        species.append(site.specie)
        frac_coords.append(site.frac_coords)

    initial_structure = IStructure(perfect_structure.lattice, species,
                                   frac_coords)
    symmetrizer = StructureSymmetrizer(initial_structure)

    return DefectEntry(name,
                       charge,
                       initial_structure,
                       None,
                       site_symmetry=symmetrizer.point_group,
                       defect_center=tuple(analyzer.defect_center_coord))
Exemplo n.º 10
0
def calc_results():
    return CalcResults(structure=IStructure(Lattice.cubic(1.0), ["H"],
                                            [[0.0] * 3]),
                       energy=1.0,
                       magnetization=0.0,
                       potentials=[0.0],
                       electronic_conv=False,
                       ionic_conv=False)
def test_make_efnv_correction(mocker):
    mock_perfect = mocker.Mock(spec=CalcResults, autospec=True)
    mock_defect = mocker.Mock(spec=CalcResults, autospec=True)

    mock_perfect.structure = IStructure(Lattice.cubic(10),
                                        species=["H"] + ["He"] * 3 + ["Li"],
                                        coords=[[0, 0, 0], [1 / 2, 1 / 2, 0],
                                                [1 / 2, 0, 1 / 2],
                                                [0, 1 / 2, 1 / 2],
                                                [0, 0, 1 / 2]])
    mock_defect.structure = IStructure(Lattice.cubic(10),
                                       species=["He"] * 3 + ["Li"],
                                       coords=[[1 / 2, 1 / 2, 0],
                                               [1 / 2, 0, 1 / 2],
                                               [0, 1 / 2, 1 / 2],
                                               [0, 0, 1 / 2]])
    mock_perfect.potentials = [3.0, 4.0, 5.0, 6.0, 7.0]
    mock_defect.potentials = [14.0, 25.0, 36.0, 47.0]

    mock_ewald = mocker.patch("pydefect.cli.vasp.make_efnv_correction.Ewald")
    ewald = mocker.Mock()
    ewald.lattice_energy = 1e3
    ewald.atomic_site_potential.return_value = 1e4
    mock_ewald.return_value = ewald

    efnvc = make_efnv_correction(charge=2,
                                 calc_results=mock_defect,
                                 perfect_calc_results=mock_perfect,
                                 dielectric_tensor=np.eye(3))

    unit_conversion = 180.95128169876497

    assert efnvc.charge == 2
    assert efnvc.point_charge_correction == -4e3 * unit_conversion
    assert efnvc.defect_region_radius == 5.0
    assert efnvc.sites == [
        PotentialSite("He", 5 * np.sqrt(2), 10.0, 2e4 * unit_conversion),
        PotentialSite("He", 5 * np.sqrt(2), 20.0, 2e4 * unit_conversion),
        PotentialSite("He", 5 * np.sqrt(2), 30.0, 2e4 * unit_conversion),
        PotentialSite("Li", 5.0, 40.0, None),
    ]
Exemplo n.º 12
0
def ortho_conventional():
    lattice = Lattice.orthorhombic(5, 6, 7)
    coords = [
        [0.0, 0.0, 0.0],
        [0.5, 0.5, 0.0],
        [0.5, 0.0, 0.5],
        [0.0, 0.5, 0.5],
        [0.0, 0.0, 0.5],
        [0.0, 0.5, 0.0],
        [0.5, 0.0, 0.0],
        [0.5, 0.5, 0.5],
    ]
    return IStructure(lattice=lattice,
                      species=["H"] * 4 + ["He"] * 4,
                      coords=coords)
Exemplo n.º 13
0
    def setUpClass(cls):
        coords = [[0, 0, 0], [0.75, 0.5, 0.75]]
        lattice = Lattice([[3.8401979337, 0.00, 0.00],
                           [1.9200989668, 3.3257101909, 0.00],
                           [0.00, -2.2171384943, 3.1355090603]])
        cls.struct_si = IStructure(lattice, ["Si"] * 2, coords)

        cls.ref_incar = Incar.from_file(
            os.path.join(module_dir, "..", "test_files", "setup_test",
                         "INCAR"))
        cls.ref_poscar = Poscar.from_file(
            os.path.join(module_dir, "..", "test_files", "setup_test",
                         "POSCAR"))
        cls.ref_potcar = Potcar.from_file(
            os.path.join(module_dir, "..", "test_files", "setup_test",
                         "POTCAR"))
        cls.ref_kpoints = Kpoints.from_file(
            os.path.join(module_dir, "..", "test_files", "setup_test",
                         "KPOINTS"))
Exemplo n.º 14
0
    def setUpClass(cls):
        if not SETTINGS.get("VASP_PSP_DIR"):
            raise unittest.SkipTest(
                'This system is not set up to run VASP jobs. '
                'Please set VASP_PSP_DIR variable in your ~/.pmgrc.yaml file.')

        coords = [[0, 0, 0], [0.75, 0.5, 0.75]]
        lattice = Lattice([[3.8401979337, 0.00, 0.00],
                           [1.9200989668, 3.3257101909, 0.00],
                           [0.00, -2.2171384943, 3.1355090603]])
        cls.struct_si = IStructure(lattice, ["Si"] * 2, coords)

        cls.ref_incar = Incar.from_file(
            os.path.join(module_dir, "reference_files", "setup_test", "INCAR"))
        cls.ref_poscar = Poscar.from_file(
            os.path.join(module_dir, "reference_files", "setup_test",
                         "POSCAR"))
        cls.ref_potcar = Potcar.from_file(
            os.path.join(module_dir, "reference_files", "setup_test",
                         "POTCAR"))
        cls.ref_kpoints = Kpoints.from_file(
            os.path.join(module_dir, "reference_files", "setup_test",
                         "KPOINTS"))
Exemplo n.º 15
0
def test_num_atom_diff():
    s1 = IStructure(Lattice.cubic(1), ["H", "He"], [[0] * 3] * 2)
    s2 = IStructure(Lattice.cubic(1), ["H", "Li"], [[0] * 3] * 2)
    assert num_atom_differences(s1, s2) == {Element.He: 1, Element.Li: -1}
Exemplo n.º 16
0
def simple_cubic_2x1x1():
    lattice = Lattice.orthorhombic(2.0, 1.0, 1.0)
    coords = [[0.0, 0.0, 0.0], [0.5, 0.0, 0.0]]
    return IStructure(lattice=lattice, species=["H", "H"], coords=coords)
Exemplo n.º 17
0
def bcc():
    lattice = Lattice.cubic(1.0)
    coords = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]
    return IStructure(lattice=lattice, species=["H"] * 2, coords=coords)
Exemplo n.º 18
0
def c_centered_monoclinic():
    lattice = Lattice.monoclinic(3, 4, 5, 100)
    coords = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0]]
    return IStructure(lattice=lattice, species=["H", "H"], coords=coords)
Exemplo n.º 19
0
from pydefect.tests.helpers.assertion import assert_json_roundtrip, \
    assert_msonable
from pymatgen import Lattice, IStructure

# "H" at [0.0, 0.0, 0.0] is removed here.
perf_coords = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5],
               [0.0, 0.0, 0.5], [0.0, 0.5, 0.0], [0.5, 0.0, 0.0], [0.5, 0.5, 0.5]]

coords = deepcopy(perf_coords)
coords.pop(0)

perturbed_coords = \
    [[0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5],
     [0.0, 0.0, 0.501], [0.0, 0.501, 0.0], [0.501, 0.0, 0.0], [0.5, 0.5, 0.5]]

perfect = IStructure(
    Lattice.cubic(10.0), ["H"] * 4 + ["He"] * 4, perf_coords)
defect_structure = IStructure(
    Lattice.cubic(10.0), ["H"] * 3 + ["He"] * 4, coords)
perturbed_defect = IStructure(
    Lattice.cubic(10.0), ["H"] * 3 + ["He"] * 4, perturbed_coords)


@pytest.fixture
def defect_entry():
    return DefectEntry(name="Va_O1",
                       charge=1,
                       structure=defect_structure,
                       perturbed_structure=perturbed_defect,
                       site_symmetry="m-3m",
                       defect_center=(0, 0, 0))
Exemplo n.º 20
0
def rhombohedral():
    lattice = Lattice.rhombohedral(a=1, alpha=45)
    coords = [[0.0, 0.0, 0.0]]
    return IStructure(lattice=lattice, species=["H"], coords=coords)
Exemplo n.º 21
0
def monoclinic():
    lattice = Lattice.monoclinic(3, 4, 5, 100)
    coords = [[0.0, 0.0, 0.0]]
    return IStructure(lattice=lattice, species=["H"], coords=coords)
Exemplo n.º 22
0
def elongated_tetragonal():
    lattice = Lattice.tetragonal(a=1, c=3 * sqrt(2))
    coords = [[0.0, 0.0, 0.0]]
    return IStructure(lattice=lattice, species=["H"], coords=coords)
Exemplo n.º 23
0
def simple_cubic():
    lattice = Lattice.cubic(1.0)
    coords = [[0.0, 0.0, 0.0]]
    return IStructure(lattice=lattice, species=["H"], coords=coords)
Exemplo n.º 24
0
def a_centered_orthorhombic():
    lattice = Lattice([[1, 0, 0], [0, 2, 3], [0, -2, 3]])
    coords = [[0.5, 0.8, 0.8], [0.0, 0.3, 0.0], [0.0, 0.0, 0.3]]

    return IStructure(lattice=lattice, species=["H"] * 3, coords=coords)
Exemplo n.º 25
0
def tetra_close_to_cubic():
    lattice = Lattice.tetragonal(1.001 * 10 / sqrt(2), 10)
    coords = [[0.0, 0.0, 0.0]]
    return IStructure(lattice=lattice, species=["H"], coords=coords)
Exemplo n.º 26
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math
from pymatgen import Lattice
from pymatgen import IStructure
a = 4.209
latt = Lattice.cubic(a)
structure = IStructure(latt, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]])
print(structure.density)
print(structure.distance_matrix)
print(structure.get_distance)