def __str__(self): elem = f"{self.element:>4}" dist = f"{self.distance:4.2f}" ini_coords = pretty_coords(self.initial_coords) p_coords = pretty_coords(self.perturbed_coords) disp = f"{self.displacement:7.2f}" return f"{elem} {dist} {ini_coords} -> {p_coords} {disp}"
def __str__(self): sym_transition = f"{self.initial_site_sym} " \ f"-> {self.final_site_sym} ({self.symm_relation})" center_coords = pretty_coords(self.center) lines = [ " -- defect structure info", f"Defect type: {self.defect_type}", f"Site symmetry: {sym_transition}", f"Has same configuration from initial structure: " f"{self.same_config_from_init}", f"Drift distance: {self.drift_dist:5.3f}", f"Defect center: {center_coords}" ] def _site_info(header: str, site_info: List[SiteInfo]): if not site_info: return [] _table = tabulate([[idx, elem, pretty_coords(coords)] for idx, elem, coords in site_info], tablefmt="plain") return [header, _table, ""] lines.extend(_site_info("Removed atoms:", self.site_diff.removed)) lines.extend(_site_info("Added atoms:", self.site_diff.inserted)) if self.same_config_from_init is False: lines.extend( _site_info("Removed atoms from initial structure:", self.site_diff_from_initial.removed)) lines.extend( _site_info("Inserted atoms to initial structure:", self.site_diff_from_initial.inserted)) lines.append("Displacements") idxs = [[i, d] for i, d in enumerate(self.displacements) if d is not None] table = [[ "Elem", "Dist", "Displace", "Angle", "Index", "Initial site", "", "Final site" ]] for final_idx, d in sorted(idxs, key=lambda y: y[1].distance_from_defect): if d.distance_from_defect > defaults.show_structure_cutoff: break i_pos = pretty_coords(d.original_pos) f_pos = pretty_coords(d.final_pos) angle = int(round(d.angle, -1)) if d.angle else "" table.append([ d.specie, round(d.distance_from_defect, 2), round(d.displace_distance, 2), angle, final_idx, i_pos, "->", f_pos ]) lines.append(tabulate(table, tablefmt="plain")) return "\n".join(lines)
def show_edge_info(edge_info: EdgeInfo): return [ edge_info.band_idx, edge_info.energy, f"{edge_info.occupation:5.2f}", pretty_orbital(edge_info.orbital_info.orbitals), pretty_coords(edge_info.kpt_coord) ]
def _site_info(header: str, site_info: List[SiteInfo]): if not site_info: return [] _table = tabulate([[idx, elem, pretty_coords(coords)] for idx, elem, coords in site_info], tablefmt="plain") return [header, _table, ""]
def _kpt_block(self): kpt_block = [["Index", "Coords", "Weight"]] for index, (kpt_coord, kpt_weight) in enumerate( zip(self.kpt_coords, self.kpt_weights), 1): coord = pretty_coords(kpt_coord) weight = f"{kpt_weight:4.3f}" kpt_block.append([index, coord, weight]) return tabulate(kpt_block, tablefmt="plain")
def _show_edge_info(edge_info: EdgeInfo, orb_diff: float): return [ edge_info.band_idx + 1, f"{edge_info.energy:7.3f}", f"{edge_info.p_ratio:5.2f}", f"{edge_info.occupation:5.2f}", f"{orb_diff:5.2f}", pretty_orbital(edge_info.orbital_info.orbitals), pretty_coords(edge_info.kpt_coord) ]
def _add_band_info(self, band_idx, c_dist, lines, spin): try: radius = f"{self.half_charge_radius(band_idx, spin):6.3f}" except ValueError: radius = "None" spin_idx = 0 if spin == Spin.up else 1 spin_str = "up" if spin == Spin.up else "down" center = pretty_coords(c_dist[spin_idx].charge_center) lines.append([band_idx + 1, spin_str, radius, center])
def __str__(self): min_or_max = "min" if self.is_min else "max" extrema_points = [[ "#", "site_sym", "coordination", "frac_coords", "quantity" ]] for idx, ep in enumerate(self.extrema_points, 1): extrema_points.append([ idx, ep.site_symmetry, ep.coordination.distance_dict, pretty_coords(ep.frac_coords[0]), f"{ep.quantities[0]:.2g}" ]) lines = [ f"info: {self.info}", f"min_or_max: {min_or_max}", f"extrema_points:", tabulate(extrema_points, tablefmt="plain") ] return "\n".join(lines)
def _orbital_info(self): inner_table = [[ "Index", "Energy", "P-ratio", "Occupation", "Orbitals" ]] w_radius = self.localized_orbitals and self.localized_orbitals[0].radius if w_radius: inner_table[0].extend(["Radius", "Center"]) for lo in self.localized_orbitals: participation_ratio = f"{lo.participation_ratio:5.2f}" \ if lo.participation_ratio else "None" inner = [ lo.band_idx + 1, f"{lo.ave_energy:7.3f}", participation_ratio, f"{lo.occupation:5.2f}", pretty_orbital(lo.orbitals) ] if w_radius: inner.extend([f"{lo.radius:5.2f}", pretty_coords(lo.center)]) inner_table.append(inner) return tabulate(inner_table, tablefmt="plain")
def test_pretty_coords(): assert pretty_coords([0.1, 0.2, 0.3]) == "( 0.100, 0.200, 0.300)" assert pretty_coords([1, -2, 0]) == "( 1.000, -2.000, 0.000)"