def test_calc_max_sphere_radius(): lattice_vectors_1 = np.array([[5, 0, 0], [0, 10, 0], [0, 0, 20]]) lattice_vectors_2 = np.array([[10, 0, 0], [0, 10, 0], [10, 10, 10]]) radius_1 = calc_max_sphere_radius(lattice_vectors_1) radius_2 = calc_max_sphere_radius(lattice_vectors_2) assert radius_1 == 10.0 assert radius_2 == 5.0
def __init__(self, parchg: Chgcar, center_coords: List[float]): self.data = parchg.spin_data self.dim = parchg.dim self.lattice = parchg.structure.lattice self.center = center_coords self.radius = calc_max_sphere_radius(self.lattice.matrix) self._distances_data = None
def spherical_dist(self, data: np.ndarray, center: List[int], distance_bins: np.ndarray): assert distance_bins[-1] <= calc_max_sphere_radius(self.lattice.matrix) shifted_dist = self.shifted_distance_data(center) _sum, _ = np.histogram(shifted_dist, distance_bins, weights=data) counts, _ = np.histogram(shifted_dist, distance_bins) histogram = _sum / counts / self.lattice.volume return histogram.tolist()
def make_defect_charge_info(parchgs: List[Chgcar], band_idxs: List[int], bin_interval: float, grids: Grids): radius = calc_max_sphere_radius(parchgs[0].structure.lattice.matrix) num_bins = int(np.ceil(radius / bin_interval)) distance_bins = np.array([bin_interval * i for i in range(num_bins)] + [radius]) ave_charge_density = 1.0 / parchgs[0].structure.volume charge_dists = [] for parchg in parchgs: charge_dists.append(make_charge_dist(parchg, grids, distance_bins)) return DefectChargeInfo(distance_bins.tolist(), band_idxs, charge_dists, ave_charge_density)