def setUp(self): blk_entry_file = os.path.join(file_loc, 'Cr2O3_defects.json') blk_entry = loadfn(blk_entry_file, cls=MontyDecoder) bulk_struct = blk_entry['bulk']['supercell']['structure'] bulk_energy = -100 bulk_entry = ComputedStructureEntry(bulk_struct, bulk_energy) e_vbm = 0.5 mu_elts = {Element('Cr'): -10, Element('O'): -5} bandgap = 3.0 self.da = DefectsAnalyzer(bulk_entry, e_vbm, mu_elts, bandgap) d1_entry_file = os.path.join(file_loc, 'Cr2O3_defects.json') d1_entry = loadfn(d1_entry_file, cls=MontyDecoder) structure = d1_entry['vacancies'][0]['supercell']['structure'] site_in_bulk = d1_entry['vacancies'][0]['bulk_supercell_site'] mult = d1_entry['vacancies'][0]['site_multiplicity'] sc_size = d1_entry['vacancies'][0]['supercell']['size'] entry_defect = ComputedStructureEntry(structure, -99) self.cd = ComputedDefect(entry_defect, site_in_bulk, multiplicity=mult, supercell_size=sc_size, charge=2, name='vac_1_Cr') entry_defect2 = ComputedStructureEntry(structure, -99) self.cd2 = ComputedDefect(entry_defect2, site_in_bulk, multiplicity=mult, supercell_size=sc_size, charge=1, name='vac_1_Cr')
def setUp(self): entry_file = os.path.join(file_loc, 'vac_cr2o3_struct_entry.json') entry = loadfn(entry_file, cls=MontyDecoder) lattice = Lattice([[9.995004137201189, -2.1469568e-08, 0.0], [-4.997501105922451, 8.655927903729987, 0.0], [0.0, 0.0, 13.67956098598296]]) coords = [0.1666665000000016, 0.3333334999999984, 0.014505185117094302] site_in_bulk = PeriodicSite('Cr', coords, lattice) multiplicity = 12 supercell_size = [2, 2, 1] q = -2 q_corr = 0.98716 o_corr = 0.39139821874799996 name = "vac_1_Cr" self.com_def = ComputedDefect(entry, site_in_bulk, multiplicity, supercell_size, q, q_corr, o_corr, name)
class ComputedDefectTest(PymatgenTest): def setUp(self): entry_file = os.path.join(file_loc, 'vac_cr2o3_struct_entry.json') entry = loadfn(entry_file, cls=MontyDecoder) lattice = Lattice([[9.995004137201189, -2.1469568e-08, 0.0], [-4.997501105922451, 8.655927903729987, 0.0], [0.0, 0.0, 13.67956098598296]]) coords = [0.1666665000000016, 0.3333334999999984, 0.014505185117094302] site_in_bulk = PeriodicSite('Cr', coords, lattice) multiplicity = 12 supercell_size = [2, 2, 1] q = -2 q_corr = 0.98716 o_corr = 0.39139821874799996 name = "vac_1_Cr" self.com_def = ComputedDefect(entry, site_in_bulk, multiplicity, supercell_size, q, q_corr, o_corr, name) def test_as_from_dict(self): d = self.com_def.as_dict() comp_def = ComputedDefect.from_dict(d) self.assertIsInstance(comp_def, ComputedDefect) with ScratchDir('.'): dumpfn(self.com_def, 'tmp.json', cls=MontyEncoder) comp_def = loadfn('tmp.json', cls=MontyDecoder) self.assertIsInstance(comp_def, ComputedDefect)
def test_convert_cd_to_de(self): #create a ComputedDefect object similar to legacy format # Vacancy type first struc = PymatgenTest.get_structure("VO2") struc.make_supercell(3) vac = Vacancy(struc, struc.sites[0], charge=-3) ids = vac.generate_defect_structure(1) defect_data = { "locpot_path": "defect/path/to/files/LOCPOT", "encut": 520 } bulk_data = {"locpot_path": "bulk/path/to/files/LOCPOT"} cse_defect = ComputedStructureEntry(ids, 100., data=defect_data) cd = ComputedDefect(cse_defect, struc.sites[0], charge=-3, name="Vac_1_O") b_cse = ComputedStructureEntry(struc, 10., data=bulk_data) de = convert_cd_to_de(cd, b_cse) self.assertIsInstance(de.defect, Vacancy) self.assertIsInstance(de, DefectEntry) self.assertEqual(de.parameters["defect_path"], "defect/path/to/files") self.assertEqual(de.parameters["bulk_path"], "bulk/path/to/files") self.assertEqual(de.parameters["encut"], 520) self.assertEqual(de.site.specie.symbol, "O") # try again for substitution type # (site object had bulk specie for ComputedDefects, # while it should have substituional site specie for DefectEntrys...) de_site_type = PeriodicSite("Sb", vac.site.frac_coords, struc.lattice) sub = Substitution(struc, de_site_type, charge=1) ids = sub.generate_defect_structure(1) cse_defect = ComputedStructureEntry(ids, 100., data=defect_data) cd = ComputedDefect(cse_defect, struc.sites[0], charge=1, name="Sub_1_Sb_on_O") de = convert_cd_to_de(cd, b_cse) self.assertIsInstance(de.defect, Substitution) self.assertIsInstance(de, DefectEntry) self.assertEqual(de.site.specie.symbol, "Sb")
def test_as_from_dict(self): d = self.com_def.as_dict() comp_def = ComputedDefect.from_dict(d) self.assertIsInstance(comp_def, ComputedDefect) with ScratchDir('.'): dumpfn(self.com_def, 'tmp.json', cls=MontyEncoder) comp_def = loadfn('tmp.json', cls=MontyDecoder) self.assertIsInstance(comp_def, ComputedDefect)