def test_make_defect_entries(tmpdir, supercell_info): tmpdir.chdir() supercell_info.to_json_file() defect_set = DefectSet({SimpleDefect(None, "He1", [-1, 0])}) defect_set.to_yaml() args = Namespace() make_defect_entries(args) names = {str(name) for name in Path(".").glob("*")} assert names == { 'Va_He1_-1', 'defect_in.yaml', 'perfect', 'Va_He1_0', 'supercell_info.json' } perfect_structure = Structure.from_file(str(Path("perfect") / "POSCAR")) assert perfect_structure == supercell_info.structure file_names = { str(file_name.name) for file_name in Path("Va_He1_-1").glob("*") } assert file_names == {"POSCAR", "defect_entry.json", "prior_info.yaml"} expected = """charge: -1 """ assert Path("Va_He1_-1/prior_info.yaml").read_text() == expected
def test_defect_entries_maker(cubic_supercell_info, cubic_supercell, mocker): mock = mocker.patch("pydefect.input_maker.defect_entries_maker.defaults") mock.displace_distance = 0.0 defect_set = DefectSet(defects={ SimpleDefect(None, "H1", [1]), SimpleDefect("Ne", "He1", [0]) }) maker = DefectEntriesMaker(cubic_supercell_info, defect_set) va_h1_str = cubic_supercell.copy() va_h1_str.pop(0) va_h1_str = to_istructure(va_h1_str) ne_he1_str = cubic_supercell.copy() coords = ne_he1_str.pop(32).frac_coords ne_he1_str.append("Ne", coords) ne_he1_str = to_istructure(ne_he1_str) defect_entries = { DefectEntry("Ne_He1", 0, ne_he1_str, ne_he1_str.copy(), "m-3m", (0.25, 0.0, 0.0)), DefectEntry("Va_H1", 1, va_h1_str, va_h1_str.copy(), "m-3m", (0.0, 0.0, 0.0)), } assert maker.defect_entries == defect_entries
def make_defect_entries(args): supercell_info: SupercellInfo = loadfn("supercell_info.json") perfect = Path("perfect") try: perfect.mkdir() logger.info("Making perfect dir...") supercell_info.structure.to(filename=perfect / "POSCAR") except FileExistsError: logger.info(f"perfect dir exists, so skipped...") defect_set = DefectSet.from_yaml() maker = DefectEntriesMaker(supercell_info, defect_set) for defect_entry in maker.defect_entries: dir_path = Path(defect_entry.full_name) try: dir_path.mkdir() logger.info(f"Making {dir_path} dir...") if defect_entry.perturbed_structure: defect_entry.perturbed_structure.to(filename=dir_path / "POSCAR") else: defect_entry.structure.to(filename=dir_path / "POSCAR") defect_entry.to_json_file(filename=dir_path / "defect_entry.json") defect_entry.to_prior_info(filename=dir_path / "prior_info.yaml") except FileExistsError: logger.info(f"{dir_path} dir exists, so skipped...")
def test_defect_entries_interstitials(cubic_supercell_info, mocker): mock = mocker.patch("pydefect.input_maker.defect_entries_maker.defaults") mock.displace_distance = 0.0 defect_set = DefectSet(defects={SimpleDefect("H", "i1", [0])}) maker = DefectEntriesMaker(cubic_supercell_info, defect_set) defect_entry = maker.defect_entries.pop() actual = defect_entry.structure[0].frac_coords np.testing.assert_array_equal(actual, [0.25, 0.25, 0.25])
def test_make_defect_set(oxi_states, he_vacancy_charge, tmpdir, supercell_info): tmpdir.chdir() supercell_info.to_json_file() args = Namespace(oxi_states=oxi_states, dopants=["Li"], kwargs=["Li_H1", "Va_He1", "Va_H1_-1"]) make_defect_set(args) simple_defects = {SimpleDefect(None, "He1", he_vacancy_charge), SimpleDefect(None, "H1", [-1]), SimpleDefect("Li", "H1", [0])} DefectSet(defects=simple_defects).to_yaml("expected.yaml") assert Path("defect_in.yaml").read_text() == Path("expected.yaml").read_text()
def test_defect_entries_maker_insert_host_atoms(cubic_supercell_info, mocker): mock = mocker.patch("pydefect.input_maker.defect_entries_maker.defaults") mock.displace_distance = 0.0 defect_set = DefectSet(defects={SimpleDefect("He", "H1", [0]), SimpleDefect("H", "He1", [0])}) maker = DefectEntriesMaker(cubic_supercell_info, defect_set) for defect_entry in maker.defect_entries: if defect_entry.name == "H_He1": actual = defect_entry.structure[0].frac_coords np.testing.assert_array_equal(actual, [0.25, 0.0, 0.0]) if defect_entry.name == "He_H1": actual = defect_entry.structure[31].frac_coords np.testing.assert_array_equal(actual, [0.0, 0.0, 0.0])
def _create_defect_set(self): result = self._create_vacancy_set() result.update(self._create_substitutional_set()) result.update(self._create_interstitial_set()) return DefectSet(result)