def test_site_diff(): site_diff_vac = SiteDiff(removed=[(1, "H", (0.0, 0.0, 0.0))], inserted=[], removed_by_sub=[], inserted_by_sub=[]) site_diff_int = SiteDiff(removed=[], inserted=[(1, "H", (0.0, 0.0, 0.0))], removed_by_sub=[], inserted_by_sub=[]) site_diff_sub = SiteDiff(removed=[], inserted=[], removed_by_sub=[(1, "H", (0.0, 0.0, 0.0))], inserted_by_sub=[(1, "He", (0.0, 0.0, 0.0))]) assert site_diff_vac.is_complex_defect is False assert site_diff_sub.is_complex_defect is False assert site_diff_vac.is_vacancy assert site_diff_int.is_vacancy is False assert site_diff_sub.is_vacancy is False assert site_diff_vac.is_interstitial is False assert site_diff_int.is_interstitial assert site_diff_sub.is_interstitial is False assert site_diff_vac.is_substituted is False assert site_diff_int.is_substituted is False assert site_diff_sub.is_substituted
def def_str_info(displacements): site_diff = SiteDiff(removed=[(0, 'H', (0.25, 0.25, 0.25))], inserted=[(0, 'H', (0.27, 0.25, 0.25))], removed_by_sub=[(2, 'Li', (0.5, 0.5, 0.5))], inserted_by_sub=[(2, 'Be', (0.5, 0.5, 0.5009))]) site_diff_from_init = SiteDiff(removed=[(0, 'H', (0.25, 0.25, 0.25))], inserted=[(0, 'H', (0.27, 0.25, 0.25))], removed_by_sub=[(2, 'Li', (0.5, 0.5, 0.5))], inserted_by_sub=[(2, 'Be', (0.5, 0.5, 0.5)) ]) shifted_final = Structure(Lattice.cubic(10), species=["H", "He", "Be", "U"], coords=[[0.27, 0.25, 0.25], [0.76, 0.75, 0.75], [0.5, 0.5, 0.5009], [0.0, 0.0, 0.0]]) return DefectStructureInfo(shifted_final_structure=shifted_final, initial_site_sym="3m", final_site_sym="m", site_diff=site_diff, site_diff_from_initial=site_diff_from_init, symprec=0.1, dist_tol=0.2, anchor_atom_idx=3, neighbor_atom_indices=[0], neighbor_cutoff_factor=1.2, drift_vector=(0.0, 0.0, 0.0001), drift_dist=0.001, center=(0.38, 0.375, 0.375175), displacements=displacements)
def test_judge_defect_type(): """The structures remain as they could be used in the future""" perfect = Structure(Lattice.cubic(10), species=["H"]*4, coords=[[0.0, 0.0, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]]) defect = Structure(Lattice.cubic(10), species=["H"]*3, coords=[[0.0, 0.0, 0.0], [0.25, 0.25, 0.5], [0.5, 0.5, 0.0]]) site_diff = SiteDiff(removed=[(1, "H", (0.0, 0.5, 0.5)), (2, "H", (0.5, 0.0, 0.5))], inserted=[(1, "H", (0.25, 0.25, 0.5))], removed_by_sub=[], inserted_by_sub=[]) assert judge_defect_type(site_diff) == DefectType.vacancy_split defect_2 = Structure(Lattice.cubic(10), species=["H"]*5, coords=[[0.0, 0.0, 0.0], [0.25, 0.25, 0.5], [0.75, 0.25, 0.5], [0.25, 0.75, 0.5], [0.5, 0.5, 0.0]]) site_diff_2 = SiteDiff(removed=[(1, "H", (0.0, 0.5, 0.5)), (2, "H", (0.5, 0.0, 0.5))], inserted=[(1, "H", (0.25, 0.25, 0.5)), (2, "H", (0.75, 0.25, 0.5)), (3, "H", (0.25, 0.75, 0.5))], removed_by_sub=[], inserted_by_sub=[]) assert judge_defect_type(site_diff_2) == DefectType.interstitial_split defect_3 = Structure(Lattice.cubic(10), species=["H", "He", "H"], coords=[[0.0, 0.0, 0.0], [0.25, 0.25, 0.5], [0.5, 0.5, 0.0]]) site_diff_3 = SiteDiff(removed=[(1, "H", (0.0, 0.5, 0.5)), (2, "H", (0.5, 0.0, 0.5))], inserted=[(1, "He", (0.25, 0.25, 0.5))], removed_by_sub=[], inserted_by_sub=[]) assert judge_defect_type(site_diff_3) == DefectType.unknown
def test_site_diff_is_no_diff(): site_diff = SiteDiff(removed=[], inserted=[], removed_by_sub=[], inserted_by_sub=[]) assert site_diff.is_no_diff is True site_diff = SiteDiff(removed=[(1, "H", (0.0, 0.0, 0.0))], inserted=[], removed_by_sub=[], inserted_by_sub=[]) assert site_diff.is_no_diff is False
def test_make_site_diff_wo_diff(): s1 = IStructure(Lattice.cubic(10), species=["H"], coords=[[0] * 3]) s2 = s1.copy() structure_comparator = DefectStructureComparator(s1, s2) site_diff = structure_comparator.make_site_diff() assert site_diff == SiteDiff([], [], [], []) assert site_diff.is_no_diff s1 = IStructure(Lattice.cubic(10), species=["H", "He"], coords=[[0] * 3, [0.5] * 3]) s2 = IStructure(Lattice.cubic(10), species=["H"], coords=[[0] * 3]) structure_comparator = DefectStructureComparator(defect_structure=s2, perfect_structure=s1) site_diff = structure_comparator.make_site_diff() assert site_diff == SiteDiff([(1, "He", (0.5, 0.5, 0.5))], [], [], []) assert site_diff.is_no_diff is False
def site_diff(): return SiteDiff(removed=[(1, "Cu", (0.25, 0.74, 0.74))], inserted=[(0, "Cu", (0.25, 0.5, 0.5))], removed_by_sub=[(0, "Cu", (0.25, 0.25, 0.25))], inserted_by_sub=[(5, "H", (0.25, 0.25, 0.25))])