def make_d_to_p(self): result = [] for site in self._defect_structure: distances = Distances(self._perfect_structure, site.frac_coords, self.same_distance_criterion) result.append(distances.atom_idx_at_center(specie=site.specie)) return result
def _atom_projection(self, structure_from, structure_to, specie=True): result = [] for site in structure_from: distances = Distances(structure_to, site.frac_coords, self.dist_tol) specie = site.specie if specie else None result.append(distances.atom_idx_at_center(specie=specie)) return result
def test_distances_w_specie(ortho_conventional): distances = Distances(ortho_conventional, center_coord=[0.25, 0.26, 0.0]) expected = [float("inf")] * 4 + [ 4.030645109656765, 1.9068560512005097, 1.9990247622278219, 3.985737071107425 ] np.testing.assert_almost_equal( distances.distances(remove_self=False, specie="He"), expected)
def test_distances_mapped_atom_idx(ortho_conventional): distances = Distances(ortho_conventional, center_coord=[0.0, 0.0, 0.49]) assert distances.atom_idx_at_center(specie="He") == 4 distances = Distances(ortho_conventional, center_coord=[0.251, 0.25, 0.25]) assert distances.atom_idx_at_center(specie="H") is None distances = Distances(ortho_conventional, center_coord=[0.0, 0.0, 0.5]) assert distances.atom_idx_at_center(specie="Li") == None
def test_coord_distances(mocker, ortho_conventional): mock = mocker.patch("pydefect.util.structure_tools.defaults") mock.cutoff_distance_factor = 3.9051248 / 2.5 + 1e-5 # = 1.562 distances = Distances(ortho_conventional, center_coord=[0.5, 0.5, 0.5]) actual = distances.coordination(include_on_site=True) expected = Coordination({"H": [2.5, 3.0, 3.5], "He": [0.0, 3.91]}, 3.905, neighboring_atom_indices=[1, 2, 3, 4, 7]) assert actual == expected actual = distances.coordination() expected = Coordination({"H": [2.5, 3.0, 3.5], "He": [3.91]}, 3.905, neighboring_atom_indices=[1, 2, 3, 4]) assert actual == expected
def neighboring_atom_indices(self, cutoff_factor=None): distances = [] for v in self.removed_indices: distances.append( Distances(self._defect_structure, self._perfect_structure[v].frac_coords, self.dist_tol)) for i in self.inserted_indices: distances.append( Distances(self._defect_structure, self._defect_structure[i].frac_coords, self.dist_tol)) result = set() for d in distances: result.update( d.coordination( cutoff_factor=cutoff_factor).neighboring_atom_indices) return sorted(list(result))
def find_inequivalent_coords(structure: Structure, df: DataFrame) -> List[CoordInfo]: result = [] initial_sg = StructureSymmetrizer(structure).sg_number added_structure = Structure.from_dict(structure.as_dict()) start_index = len(structure) for _, column in df.iterrows(): coords = [column.a, column.b, column.c] assert Element.Og not in structure.composition.elements added_structure.append(Element.Og, coords) end_index = len(added_structure) symmetrizer = StructureSymmetrizer(added_structure) if initial_sg != symmetrizer.sg_number: logger.warning("The symmetry has changed, meaning all the symmetry " "equivalent sites do not exist.") sym_data = symmetrizer.spglib_sym_data _indices = [i for i in range(start_index, end_index)] repr_atom_pairs = zip(sym_data["equivalent_atoms"][_indices], _indices) key = lambda x: x[0] for _, equiv_sites in groupby(sorted(repr_atom_pairs, key=key), key=key): coords, quantity = [], [] for repr_idx, atom_idx in equiv_sites: fcoord = added_structure[atom_idx].frac_coords coords.append(tuple(fcoord)) key = "ave_value" if "ave_value" in df else "value" quantity.append(df[key][atom_idx - start_index]) if repr_idx == atom_idx: site_sym = sym_data["site_symmetry_symbols"][atom_idx] distances = Distances(structure, fcoord) coordination = distances.coordination() coord_info = CoordInfo(site_symmetry=remove_dot(site_sym), coordination=coordination, frac_coords=coords, quantities=quantity) result.append(coord_info) return result
def test_distances(ortho_conventional): distances = Distances(ortho_conventional, center_coord=[0.25, 0.25, 0.25]) np.testing.assert_almost_equal(distances.distances(), [5.2440442 / 2] * 8) distances = Distances(ortho_conventional, center_coord=[0.5, 0.5, 0.5]) expected = [5.2440442, 3.5, 3.0, 2.5, 3.9051248, 4.3011626, 4.6097722] np.testing.assert_almost_equal(distances.distances(), expected)
def neighboring_atom_indices(self): result = set() for v in self.vacancy_indices: distances = Distances(self._defective_structure, self._perfect_structure[v].frac_coords) result.update(distances.coordination().neighboring_atom_indices) for i in self.inserted_indices: distances = Distances(self._defective_structure, self._defective_structure[i].frac_coords) result.update(distances.coordination().neighboring_atom_indices) return sorted(list(result))
def interstitial_coords(self, idx: int): interstitial = self.interstitials[idx] distances = Distances(self.structure, interstitial.frac_coords) return distances.coordination(include_on_site=True)
def coords(self, name): site = self.sites[name] coord = list(self.structure[site.equivalent_atoms[0]].frac_coords) distances = Distances(self.structure, coord) return distances.coordination()
def test_shortest_distances(ortho_conventional): distances = Distances(ortho_conventional, center_coord=[0.5, 0.5, 0.5]) assert distances.shortest_distance == 2.5
def make_p_to_d(self): result = [] for site in self._perfect_structure: distances = Distances(self._defective_structure, site.frac_coords) result.append(distances.atom_idx_at_center(specie=site.specie)) return result