def test_interstitial(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] int_site = PeriodicSite("V", struc[V_index].coords + [0.1, 0.1, 0.1], struc.lattice) interstitial = Interstitial(struc, int_site) # test generation and super cell int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.composition.as_dict(), {"V": 3, "O": 4}) # Ensure the site is in the right place self.assertEqual(int_site, int_struc.get_sites_in_sphere(int_site.coords, 0.1)[0][0]) int_struc = interstitial.generate_defect_structure(2) self.assertEqual(int_struc.composition.as_dict(), {"V": 17, "O": 32}) int_struc = interstitial.generate_defect_structure(3) self.assertEqual(int_struc.composition.as_dict(), {"V": 55, "O": 108}) int_struc = interstitial.generate_defect_structure([[2.0, 0, 0], [0, 0, -3.0], [0, 2.0, 0]]) self.assertEqual(int_struc.composition.as_dict(), {"V": 25, "O": 48}) # test charge interstitial = Interstitial(struc, int_site) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 0.0) interstitial = Interstitial(struc, int_site, charge=1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 1.0) interstitial = Interstitial(struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, -1.0) # test multiplicity interstitial = Interstitial(struc, int_site) self.assertEqual(interstitial.multiplicity, 8.0) # test manual setting of multiplicity interstitial = Interstitial(struc, int_site, multiplicity=4.0) self.assertEqual(interstitial.multiplicity, 4.0) # Test composition self.assertEqual(dict(interstitial.defect_composition.as_dict()), {"V": 3, "O": 4}) # test that structure generation doesn't break if velocities existed previously # (previously caused failures for structure printing) vel_struc = Structure( struc.lattice, struc.species, struc.frac_coords, site_properties={"velocities": [[0.0, 0.0, 0.0]] * len(struc)}, ) interstitial = Interstitial(vel_struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertTrue("velocities" not in int_struc.site_properties)
def test_interstitial(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] int_site = PeriodicSite("V", struc[V_index].coords + [0.1, 0.1, 0.1], struc.lattice) interstitial = Interstitial(struc, int_site) # test generation and super cell int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.composition.as_dict(), {"V": 3, "O": 4}) # Ensure the site is in the right place self.assertEqual(int_site, int_struc.get_sites_in_sphere(int_site.coords, 0.1)[0][0]) int_struc = interstitial.generate_defect_structure(2) self.assertEqual(int_struc.composition.as_dict(), {"V": 17, "O": 32}) int_struc = interstitial.generate_defect_structure(3) self.assertEqual(int_struc.composition.as_dict(), {"V": 55, "O": 108}) int_struc = interstitial.generate_defect_structure([[2., 0, 0], [0, 0, -3.], [0, 2., 0]]) self.assertEqual(int_struc.composition.as_dict(), {"V": 25, "O": 48}) # test charge interstitial = Interstitial(struc, int_site) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 0.0) interstitial = Interstitial(struc, int_site, charge=1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 1.0) interstitial = Interstitial(struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, -1.0) # test multiplicity interstitial = Interstitial(struc, int_site) self.assertEqual(interstitial.multiplicity, 1.0) interstitial = Interstitial(struc, int_site, multiplicity=4.0) self.assertEqual(interstitial.multiplicity, 4.0) # Test composoition self.assertEqual(dict(interstitial.defect_composition.as_dict()), {"V": 3, "O": 4}) # test that structure has all velocities equal if velocities previously existed # (previously caused failures for structure printing) vel_struc = Structure( struc.lattice, struc.species, struc.frac_coords, site_properties= {'velocities': [[0., 0., 0.]]*len(struc) } ) interstitial = Interstitial(vel_struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertTrue( (np.array(int_struc.site_properties['velocities']) == 0.).all()) self.assertEqual( len(int_struc.site_properties['velocities']), len(int_struc))
def test_interstitial(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] int_site = PeriodicSite("V", struc[V_index].coords + [0.1, 0.1, 0.1], struc.lattice) interstitial = Interstitial(struc, int_site) # test generation and super cell int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.composition.as_dict(), {"V": 3, "O": 4}) # Ensure the site is in the right place self.assertEqual( int_site, int_struc.get_sites_in_sphere(int_site.coords, 0.1)[0][0]) int_struc = interstitial.generate_defect_structure(2) self.assertEqual(int_struc.composition.as_dict(), {"V": 17, "O": 32}) int_struc = interstitial.generate_defect_structure(3) self.assertEqual(int_struc.composition.as_dict(), {"V": 55, "O": 108}) int_struc = interstitial.generate_defect_structure([[2., 0, 0], [0, 0, -3.], [0, 2., 0]]) self.assertEqual(int_struc.composition.as_dict(), {"V": 25, "O": 48}) # test charge interstitial = Interstitial(struc, int_site) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 0.0) interstitial = Interstitial(struc, int_site, charge=1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 1.0) interstitial = Interstitial(struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, -1.0) # test multiplicity interstitial = Interstitial(struc, int_site) self.assertEqual(interstitial.multiplicity, 1.0) interstitial = Interstitial(struc, int_site, multiplicity=4.0) self.assertEqual(interstitial.multiplicity, 4.0) # Test composoition self.assertEqual(dict(interstitial.defect_composition.as_dict()), { "V": 3, "O": 4 })
def test_interstitial(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] int_site = PeriodicSite("V", struc[V_index].coords + [0.1, 0.1, 0.1], struc.lattice) interstitial = Interstitial(struc, int_site) # test generation and super cell int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.composition.as_dict(), {"V": 3, "O": 4}) # Ensure the site is in the right place self.assertEqual(int_site, int_struc.get_sites_in_sphere(int_site.coords, 0.1)[0][0]) int_struc = interstitial.generate_defect_structure(2) self.assertEqual(int_struc.composition.as_dict(), {"V": 17, "O": 32}) int_struc = interstitial.generate_defect_structure(3) self.assertEqual(int_struc.composition.as_dict(), {"V": 55, "O": 108}) int_struc = interstitial.generate_defect_structure([[2., 0, 0], [0, 0, -3.], [0, 2., 0]]) self.assertEqual(int_struc.composition.as_dict(), {"V": 25, "O": 48}) # test charge interstitial = Interstitial(struc, int_site) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 0.0) interstitial = Interstitial(struc, int_site, charge=1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 1.0) interstitial = Interstitial(struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, -1.0) # test multiplicity interstitial = Interstitial(struc, int_site) self.assertEqual(interstitial.multiplicity, 1.0) interstitial = Interstitial(struc, int_site, multiplicity=4.0) self.assertEqual(interstitial.multiplicity, 4.0) # Test composoition self.assertEqual(dict(interstitial.defect_composition.as_dict()), {"V": 3, "O": 4})
def test_check_final_relaxed_structure_delocalized(self): # test structure delocalization analysis # first test no movement in atoms initial_defect_structure = self.vac.generate_defect_structure() final_defect_structure = initial_defect_structure.copy() sampling_radius = 4.55 defect_frac_sc_coords = self.vac.site.frac_coords[:] params = { "initial_defect_structure": initial_defect_structure, "final_defect_structure": final_defect_structure, "sampling_radius": sampling_radius, "defect_frac_sc_coords": defect_frac_sc_coords, "is_compatible": True, } dentry = DefectEntry(self.vac, 0.0, corrections={}, parameters=params, entry_id=None) dc = DefectCompatibility(tot_relax_tol=0.1, perc_relax_tol=0.1, defect_tot_relax_tol=0.1) dentry = dc.check_final_relaxed_structure_delocalized(dentry) struc_delocal = dentry.parameters["delocalization_meta"]["structure_relax"] self.assertTrue(dentry.parameters["is_compatible"]) self.assertTrue(struc_delocal["is_compatible"]) self.assertTrue(struc_delocal["metadata"]["structure_tot_relax_compatible"]) self.assertEqual(struc_delocal["metadata"]["tot_relax_outside_rad"], 0.0) self.assertTrue(struc_delocal["metadata"]["structure_perc_relax_compatible"]) self.assertEqual(struc_delocal["metadata"]["perc_relax_outside_rad"], 0.0) self.assertEqual( len(struc_delocal["metadata"]["full_structure_relax_data"]), len(initial_defect_structure), ) self.assertIsNone(struc_delocal["metadata"]["defect_index"]) defect_delocal = dentry.parameters["delocalization_meta"]["defectsite_relax"] self.assertTrue(defect_delocal["is_compatible"]) self.assertIsNone(defect_delocal["metadata"]["relax_amount"]) # next test for when structure has delocalized outside of radius from defect pert_struct_fin_struct = initial_defect_structure.copy() pert_struct_fin_struct.perturb(0.1) dentry.parameters.update({"final_defect_structure": pert_struct_fin_struct}) dentry = dc.check_final_relaxed_structure_delocalized(dentry) struc_delocal = dentry.parameters["delocalization_meta"]["structure_relax"] self.assertFalse(dentry.parameters["is_compatible"]) self.assertFalse(struc_delocal["is_compatible"]) self.assertFalse(struc_delocal["metadata"]["structure_tot_relax_compatible"]) self.assertAlmostEqual(struc_delocal["metadata"]["tot_relax_outside_rad"], 12.5) self.assertFalse(struc_delocal["metadata"]["structure_perc_relax_compatible"]) self.assertAlmostEqual(struc_delocal["metadata"]["perc_relax_outside_rad"], 77.63975155) # now test for when an interstitial defect has migrated too much inter_def_site = PeriodicSite( "H", [7.58857304, 11.70848069, 12.97817518], self.vac.bulk_structure.lattice, to_unit_cell=True, coords_are_cartesian=True, ) inter = Interstitial(self.vac.bulk_structure, inter_def_site, charge=0) initial_defect_structure = inter.generate_defect_structure() final_defect_structure = initial_defect_structure.copy() poss_deflist = sorted( final_defect_structure.get_sites_in_sphere(inter.site.coords, 2, include_index=True), key=lambda x: x[1], ) def_index = poss_deflist[0][2] final_defect_structure.translate_sites( indices=[def_index], vector=[0.0, 0.0, 0.008] ) # fractional coords translation defect_frac_sc_coords = inter_def_site.frac_coords[:] params = { "initial_defect_structure": initial_defect_structure, "final_defect_structure": final_defect_structure, "sampling_radius": sampling_radius, "defect_frac_sc_coords": defect_frac_sc_coords, "is_compatible": True, } dentry = DefectEntry(inter, 0.0, corrections={}, parameters=params, entry_id=None) dentry = dc.check_final_relaxed_structure_delocalized(dentry) defect_delocal = dentry.parameters["delocalization_meta"]["defectsite_relax"] self.assertFalse(defect_delocal["is_compatible"]) self.assertAlmostEqual(defect_delocal["metadata"]["relax_amount"], 0.10836054)
def test_interstitial(self): struc = PymatgenTest.get_structure("VO2") V_index = struc.indices_from_symbol("V")[0] int_site = PeriodicSite("V", struc[V_index].coords + [0.1, 0.1, 0.1], struc.lattice) interstitial = Interstitial(struc, int_site) # test generation and super cell int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.composition.as_dict(), {"V": 3, "O": 4}) # Ensure the site is in the right place self.assertEqual( int_site, int_struc.get_sites_in_sphere(int_site.coords, 0.1)[0][0]) int_struc = interstitial.generate_defect_structure(2) self.assertEqual(int_struc.composition.as_dict(), {"V": 17, "O": 32}) int_struc = interstitial.generate_defect_structure(3) self.assertEqual(int_struc.composition.as_dict(), {"V": 55, "O": 108}) int_struc = interstitial.generate_defect_structure([[2., 0, 0], [0, 0, -3.], [0, 2., 0]]) self.assertEqual(int_struc.composition.as_dict(), {"V": 25, "O": 48}) # test charge interstitial = Interstitial(struc, int_site) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 0.0) interstitial = Interstitial(struc, int_site, charge=1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, 1.0) interstitial = Interstitial(struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertEqual(int_struc.charge, -1.0) # test multiplicity interstitial = Interstitial(struc, int_site) self.assertEqual(interstitial.multiplicity, 1.0) interstitial = Interstitial(struc, int_site, multiplicity=4.0) self.assertEqual(interstitial.multiplicity, 4.0) # Test composoition self.assertEqual(dict(interstitial.defect_composition.as_dict()), { "V": 3, "O": 4 }) # test that structure has all velocities equal if velocities previously existed # (previously caused failures for structure printing) vel_struc = Structure( struc.lattice, struc.species, struc.frac_coords, site_properties={'velocities': [[0., 0., 0.]] * len(struc)}) interstitial = Interstitial(vel_struc, int_site, charge=-1.0) int_struc = interstitial.generate_defect_structure(1) self.assertTrue( (np.array(int_struc.site_properties['velocities']) == 0.).all()) self.assertEqual(len(int_struc.site_properties['velocities']), len(int_struc))
def test_check_final_relaxed_structure_delocalized(self): # test structure delocalization analysis # first test no movement in atoms initial_defect_structure = self.vac.generate_defect_structure() final_defect_structure = initial_defect_structure.copy() sampling_radius = 4.55 defect_frac_sc_coords = self.vac.site.frac_coords[:] params = {'initial_defect_structure': initial_defect_structure, 'final_defect_structure': final_defect_structure, 'sampling_radius': sampling_radius, 'defect_frac_sc_coords': defect_frac_sc_coords, 'is_compatible': True} dentry = DefectEntry(self.vac, 0., corrections={}, parameters=params, entry_id=None) dc = DefectCompatibility( tot_relax_tol=0.1, perc_relax_tol=0.1, defect_tot_relax_tol=0.1) dentry = dc.check_final_relaxed_structure_delocalized( dentry) struc_delocal = dentry.parameters['delocalization_meta']['structure_relax'] self.assertTrue( dentry.parameters['is_compatible']) self.assertTrue( struc_delocal['is_compatible']) self.assertTrue( struc_delocal['metadata']['structure_tot_relax_compatible']) self.assertEqual( struc_delocal['metadata']['tot_relax_outside_rad'], 0.) self.assertTrue( struc_delocal['metadata']['structure_perc_relax_compatible']) self.assertEqual( struc_delocal['metadata']['perc_relax_outside_rad'], 0.) self.assertEqual( len(struc_delocal['metadata']['full_structure_relax_data']), len(initial_defect_structure)) self.assertIsNone( struc_delocal['metadata']['defect_index']) defect_delocal = dentry.parameters['delocalization_meta']['defectsite_relax'] self.assertTrue( defect_delocal['is_compatible']) self.assertIsNone( defect_delocal['metadata']['relax_amount']) # next test for when structure has delocalized outside of radius from defect pert_struct_fin_struct = initial_defect_structure.copy() pert_struct_fin_struct.perturb( 0.1) dentry.parameters.update( {'final_defect_structure': pert_struct_fin_struct}) dentry = dc.check_final_relaxed_structure_delocalized( dentry) struc_delocal = dentry.parameters['delocalization_meta']['structure_relax'] self.assertFalse( dentry.parameters['is_compatible']) self.assertFalse( struc_delocal['is_compatible']) self.assertFalse( struc_delocal['metadata']['structure_tot_relax_compatible']) self.assertAlmostEqual( struc_delocal['metadata']['tot_relax_outside_rad'], 12.5) self.assertFalse( struc_delocal['metadata']['structure_perc_relax_compatible']) self.assertAlmostEqual( struc_delocal['metadata']['perc_relax_outside_rad'], 77.63975155) # now test for when an interstitial defect has migrated too much inter_def_site = PeriodicSite('H', [7.58857304, 11.70848069, 12.97817518], self.vac.bulk_structure.lattice, to_unit_cell=True, coords_are_cartesian=True) inter = Interstitial(self.vac.bulk_structure, inter_def_site, charge=0) initial_defect_structure = inter.generate_defect_structure() final_defect_structure = initial_defect_structure.copy() poss_deflist = sorted( final_defect_structure.get_sites_in_sphere(inter.site.coords, 2, include_index=True), key=lambda x: x[1]) def_index = poss_deflist[0][2] final_defect_structure.translate_sites(indices=[def_index], vector=[0., 0., 0.008]) #fractional coords translation defect_frac_sc_coords = inter_def_site.frac_coords[:] params = {'initial_defect_structure': initial_defect_structure, 'final_defect_structure': final_defect_structure, 'sampling_radius': sampling_radius, 'defect_frac_sc_coords': defect_frac_sc_coords, 'is_compatible': True} dentry = DefectEntry(inter, 0., corrections={}, parameters=params, entry_id=None) dentry = dc.check_final_relaxed_structure_delocalized( dentry) defect_delocal = dentry.parameters['delocalization_meta']['defectsite_relax'] self.assertFalse( defect_delocal['is_compatible']) self.assertAlmostEqual( defect_delocal['metadata']['relax_amount'], 0.10836054)
def test_is_final_relaxed_structure_delocalized(self): # test structure delocalization analysis # first test no movement in atoms initial_defect_structure = self.vac.generate_defect_structure() final_defect_structure = initial_defect_structure.copy() sampling_radius = 4.55 params = { 'initial_defect_structure': initial_defect_structure, 'final_defect_structure': final_defect_structure, 'sampling_radius': sampling_radius, 'is_compatible': True } dentry = DefectEntry(self.vac, 0., corrections={}, parameters=params, entry_id=None) dc = DefectCompatibility(tot_relax_tol=0.1, perc_relax_tol=0.1, defect_tot_relax_tol=0.1) dentry = dc.is_final_relaxed_structure_delocalized(dentry) struc_delocal = dentry.parameters['delocalization_meta'][ 'structure_relax'] self.assertTrue(dentry.parameters['is_compatible']) self.assertTrue(struc_delocal['is_compatible']) self.assertTrue( struc_delocal['metadata']['structure_tot_relax_compatible']) self.assertEqual(struc_delocal['metadata']['tot_relax_outside_rad'], 0.) self.assertTrue( struc_delocal['metadata']['structure_perc_relax_compatible']) self.assertEqual(struc_delocal['metadata']['perc_relax_outside_rad'], 0.) self.assertEqual( len(struc_delocal['metadata']['full_structure_relax_data']), len(initial_defect_structure)) self.assertIsNone(struc_delocal['metadata']['defect_index']) defect_delocal = dentry.parameters['delocalization_meta'][ 'defectsite_relax'] self.assertTrue(defect_delocal['is_compatible']) self.assertIsNone(defect_delocal['metadata']['relax_amount']) # next test for when structure has delocalized outside of radius from defect pert_struct_fin_struct = initial_defect_structure.copy() pert_struct_fin_struct.perturb(0.1) dentry.parameters.update( {'final_defect_structure': pert_struct_fin_struct}) dentry = dc.is_final_relaxed_structure_delocalized(dentry) struc_delocal = dentry.parameters['delocalization_meta'][ 'structure_relax'] self.assertFalse(dentry.parameters['is_compatible']) self.assertFalse(struc_delocal['is_compatible']) self.assertFalse( struc_delocal['metadata']['structure_tot_relax_compatible']) self.assertAlmostEqual( struc_delocal['metadata']['tot_relax_outside_rad'], 12.5) self.assertFalse( struc_delocal['metadata']['structure_perc_relax_compatible']) self.assertAlmostEqual( struc_delocal['metadata']['perc_relax_outside_rad'], 77.63975155) # now test for when an interstitial defect has migrated too much inter_def_site = PeriodicSite('H', [7.58857304, 11.70848069, 12.97817518], self.vac.bulk_structure.lattice, to_unit_cell=True, coords_are_cartesian=True) inter = Interstitial(self.vac.bulk_structure, inter_def_site, charge=0) initial_defect_structure = inter.generate_defect_structure() final_defect_structure = initial_defect_structure.copy() poss_deflist = sorted(final_defect_structure.get_sites_in_sphere( inter.site.coords, 2, include_index=True), key=lambda x: x[1]) def_index = poss_deflist[0][2] final_defect_structure.translate_sites( indices=[def_index], vector=[0., 0., 0.008]) #fractional coords translation params = { 'initial_defect_structure': initial_defect_structure, 'final_defect_structure': final_defect_structure, 'sampling_radius': sampling_radius, 'is_compatible': True } dentry = DefectEntry(inter, 0., corrections={}, parameters=params, entry_id=None) dentry = dc.is_final_relaxed_structure_delocalized(dentry) defect_delocal = dentry.parameters['delocalization_meta'][ 'defectsite_relax'] self.assertFalse(defect_delocal['is_compatible']) self.assertAlmostEqual(defect_delocal['metadata']['relax_amount'], 0.10836054)
def __init__(self, structure, max_min_oxi=None, substitutions=None, oxi_states=None, cellmax=128, antisites_flag=True, include_interstitials=False, interstitial_elements=None, intersites=None, standardized=False, struct_type='semiconductor'): """ Args: structure (Structure): the bulk structure. max_min_oxi (dict): The minimal and maximum oxidation state of each element as a dict. For instance {"O":(-2,0)}. If not given, the oxi-states of pymatgen are considered. substitutions (dict): The allowed substitutions of elements as a dict. If not given, intrinsic defects are computed. If given, intrinsic (e.g., anti-sites) and extrinsic are considered explicitly specified. Example: {"Co":["Zn","Mn"]} means Co sites can be substituted by Mn or Zn. oxi_states (dict): The oxidation state of the elements in the compound e.g. {"Fe":2,"O":-2}. If not given, the oxidation state of each site is computed with bond valence sum. WARNING: Bond-valence method can fail for mixed-valence compounds. cellmax (int): Maximum number of atoms allowed in the supercell. antisites_flag (bool): If False, don't generate antisites. include_interstitials (bool): If true, do generate interstitial defect configurations (default: False). interstitial_elements ([str]): List of strings containing symbols of the elements that are to be considered for interstitial sites. The default (None) triggers self-interstitial generation, given that include_interstitials is True. intersites ([PeriodicSite]): A list of PeriodicSites in the bulk structure on which we put interstitials. Note that you still have to set flag include_interstitials to True in order to make use of this manual way of providing interstitial sites. If this is used, then no additional interstitials are generated beyond the list that is provided in intersites. standardized (bool): If True, use the primitive standard structure as unit cell for generating the defect configurations (default is False). The primitive standard structure is obtained from the SpacegroupAnalyzer class with a symprec of 0.01. struct_type (string): Options are 'semiconductor' and 'insulator'. If semiconductor is selected, charge states based on database of semiconductors is used to assign defect charges. For insulators, defect charges are conservatively assigned. """ max_min_oxi = max_min_oxi if max_min_oxi is not None else {} substitutions = substitutions if substitutions is not None else {} oxi_states = oxi_states if oxi_states is not None else {} interstitial_elements = interstitial_elements if interstitial_elements is not None else [] intersites = intersites if intersites is not None else [] self.defects = [] self.cellmax = cellmax self.substitutions = {} self.struct_type = struct_type for key, val in substitutions.items(): self.substitutions[key] = val spa = SpacegroupAnalyzer(structure, symprec=1e-2) prim_struct = spa.get_primitive_standard_structure() if standardized: self.struct = prim_struct else: self.struct = structure struct_species = self.struct.types_of_specie if self.struct_type == 'semiconductor': self.defect_charger = DefectChargerSemiconductor( self.struct, min_max_oxi=max_min_oxi) elif self.struct_type == 'insulator': self.defect_charger = DefectChargerInsulator(self.struct) elif self.struct_type == 'manual': self.defect_charger = DefectChargerUserCustom( self.struct, oxi_states=oxi_states) elif self.struct_type == 'ionic': self.defect_charger = DefectChargerIonic(self.struct) else: raise NotImplementedError if include_interstitials and interstitial_elements: for elem_str in interstitial_elements: if not Element.is_valid_symbol(elem_str): raise ValueError("invalid interstitial element" " \"{}\"".format(elem_str)) sc_scale = get_optimized_sc_scale(self.struct, cellmax) self.defects = {} sc = self.struct.copy() sc.make_supercell(sc_scale) self.defects['bulk'] = { 'name': 'bulk', 'supercell': { 'size': sc_scale, 'structure': sc } } # If interstitials are provided as a list of PeriodicSites, # make sure that the lattice has not changed. if include_interstitials and intersites: for intersite in intersites: #list of PeriodicSite objects if intersite.lattice != self.struct.lattice: raise RuntimeError( "Discrepancy between lattices" " underlying the input interstitials and" " the bulk structure; possibly because of" " standardizing the input structure.") vacancies = [] as_defs = [] sub_defs = [] VG = VacancyGenerator(self.struct) print("Setting up defects...") for i, vac in enumerate(VG): vac_site = vac.site vac_symbol = vac.site.specie.symbol vac_sc = vac.generate_defect_structure(sc_scale) #create a trivial defect structure to find where supercell transformation moves the lattice struct_for_defect_site = Structure( vac.bulk_structure.copy().lattice, [vac.site.specie], [vac.site.frac_coords], to_unit_cell=True, coords_are_cartesian=False) struct_for_defect_site.make_supercell(sc_scale) vac_sc_site = struct_for_defect_site[0] charges_vac = self.defect_charger.get_charges( 'vacancy', vac_symbol) vacancies.append({ 'name': "vac_{}_{}".format(i + 1, vac_symbol), 'unique_site': vac_site, 'bulk_supercell_site': vac_sc_site, 'defect_type': 'vacancy', 'site_specie': vac_symbol, 'site_multiplicity': vac.multiplicity, 'supercell': { 'size': sc_scale, 'structure': vac_sc }, 'charges': charges_vac }) if antisites_flag: for as_specie in set(struct_species): SG = SubstitutionGenerator(self.struct, as_specie) for i, sub in enumerate(SG): as_symbol = as_specie.symbol as_sc = sub.generate_defect_structure(sc_scale) # create a trivial defect structure to find where supercell transformation moves the defect struct_for_defect_site = Structure( sub.bulk_structure.copy().lattice, [sub.site.specie], [sub.site.frac_coords], to_unit_cell=True, coords_are_cartesian=False) struct_for_defect_site.make_supercell(sc_scale) as_sc_site = struct_for_defect_site[0] #get bulk_site (non sc) poss_deflist = sorted( sub.bulk_structure.get_sites_in_sphere( sub.site.coords, 0.01, include_index=True), key=lambda x: x[1]) if not len(poss_deflist): raise ValueError( "Could not find substitution site inside bulk structure for {}?" .format(sub.name)) defindex = poss_deflist[0][2] as_site = sub.bulk_structure[defindex] vac_symbol = as_site.specie charges_as = self.defect_charger.get_charges( 'antisite', vac_symbol, as_symbol) as_defs.append({ 'name': "as_{}_{}_on_{}".format(i + 1, as_symbol, vac_symbol), 'unique_site': as_site, 'bulk_supercell_site': as_sc_site, 'defect_type': 'antisite', 'site_specie': vac_symbol, 'substitution_specie': as_symbol, 'site_multiplicity': sub.multiplicity, 'supercell': { 'size': sc_scale, 'structure': as_sc }, 'charges': charges_as }) for vac_symbol, subspecie_list in self.substitutions.items(): for subspecie_symbol in subspecie_list: SG = SubstitutionGenerator(self.struct, subspecie_symbol) for i, sub in enumerate(SG): sub_symbol = sub.site.specie.symbol #get bulk_site (non sc) poss_deflist = sorted( sub.bulk_structure.get_sites_in_sphere( sub.site.coords, 0.1, include_index=True), key=lambda x: x[1]) if not len(poss_deflist): raise ValueError( "Could not find substitution site inside bulk structure for {}?" .format(sub.name)) defindex = poss_deflist[0][2] sub_site = self.struct[defindex] this_vac_symbol = sub_site.specie.symbol if (sub_symbol != subspecie_symbol) or (this_vac_symbol != vac_symbol): continue else: sub_sc = sub.generate_defect_structure(sc_scale) # create a trivial defect structure to find where supercell transformation moves the defect struct_for_defect_site = Structure( sub.bulk_structure.copy().lattice, [sub.site.specie], [sub.site.frac_coords], to_unit_cell=True, coords_are_cartesian=False) struct_for_defect_site.make_supercell(sc_scale) sub_sc_site = struct_for_defect_site[0] charges_sub = self.defect_charger.get_charges( 'substitution', vac_symbol, subspecie_symbol) sub_defs.append({ 'name': "sub_{}_{}_on_{}".format(i + 1, subspecie_symbol, vac_symbol), 'unique_site': sub_site, 'bulk_supercell_site': sub_sc_site, 'defect_type': 'substitution', 'site_specie': vac_symbol, 'substitution_specie': subspecie_symbol, 'site_multiplicity': sub.multiplicity, 'supercell': { 'size': sc_scale, 'structure': sub_sc }, 'charges': charges_sub }) self.defects['vacancies'] = vacancies self.defects['substitutions'] = sub_defs self.defects['substitutions'] += as_defs if include_interstitials: interstitials = [] if interstitial_elements: inter_elems = interstitial_elements else: inter_elems = [elem.symbol for elem in \ self.struct.composition.elements] if len(inter_elems) == 0: raise RuntimeError("empty element list for interstitials") if intersites: #manual specification of interstitials for i, intersite in enumerate(intersites): for elt in inter_elems: name = "inter_{}_{}".format(i + 1, elt) if intersite.lattice != self.struct.lattice: err_msg = "Lattice matching error occurs between provided interstitial and the bulk structure." if standardized: err_msg += "\nLikely because the standardized flag was used. Turn this flag off or reset " \ "your interstitial PeriodicSite to match the standardized form of the bulk structure." raise ValueError(err_msg) else: intersite_object = Interstitial( self.struct, intersite) # create a trivial defect structure to find where supercell transformation moves the defect site struct_for_defect_site = Structure( intersite_object.bulk_structure.copy().lattice, [intersite_object.site.specie], [intersite_object.site.frac_coords], to_unit_cell=True, coords_are_cartesian=False) struct_for_defect_site.make_supercell(sc_scale) site_sc = struct_for_defect_site[0] sc_with_inter = intersite_object.generate_defect_structure( sc_scale) charges_inter = self.defect_charger.get_charges( 'interstitial', elt) interstitials.append({ 'name': name, 'unique_site': intersite_object.site, 'bulk_supercell_site': site_sc, 'defect_type': 'interstitial', 'site_specie': intersite_object.site.specie.symbol, 'site_multiplicity': intersite_object.multiplicity, 'supercell': { 'size': sc_scale, 'structure': sc_with_inter }, 'charges': charges_inter }) else: print( "Searching for interstitial sites (this can take awhile)..." ) for elt in inter_elems: #TODO: Add ability to use other interstitial finding methods in pymatgen IG = InterstitialGenerator(self.struct, elt) for i, intersite_object in enumerate(IG): name = intersite_object.name # create a trivial defect structure to find where supercell transformation moves the defect site struct_for_defect_site = Structure( intersite_object.bulk_structure.copy().lattice, [intersite_object.site.specie], [intersite_object.site.frac_coords], to_unit_cell=True, coords_are_cartesian=False) struct_for_defect_site.make_supercell(sc_scale) site_sc = struct_for_defect_site[0] sc_with_inter = intersite_object.generate_defect_structure( sc_scale) charges_inter = self.defect_charger.get_charges( 'interstitial', elt) interstitials.append({ 'name': "inter_{}_{}".format( i + 1, elt), #TODO fix naming convention 'unique_site': intersite_object.site, 'bulk_supercell_site': site_sc, 'defect_type': 'interstitial', 'site_specie': intersite_object.site.specie.symbol, 'site_multiplicity': intersite_object.multiplicity, 'supercell': { 'size': sc_scale, 'structure': sc_with_inter }, 'charges': charges_inter }) self.defects['interstitials'] = interstitials print("\nNumber of jobs created:") tottmp = 0 for j in self.defects.keys(): if j == 'bulk': print(" bulk = 1") tottmp += 1 else: print(" {}:".format(j)) for lis in self.defects[j]: print(" {} = {}".format(lis['name'], len(lis['charges']))) tottmp += len(lis['charges']) print("Total (non dielectric) jobs created = {}\n".format(tottmp))