From 952e2060755a53455f38311334fa41fac6e3b2b2 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Thu, 13 Jun 2024 17:32:09 +0800 Subject: [PATCH] relocate magic method --- pymatgen/electronic_structure/dos.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pymatgen/electronic_structure/dos.py b/pymatgen/electronic_structure/dos.py index cdb3074838d..68f62faf701 100644 --- a/pymatgen/electronic_structure/dos.py +++ b/pymatgen/electronic_structure/dos.py @@ -52,6 +52,18 @@ def __init__(self, energies: ArrayLike, densities: ArrayLike, efermi: float) -> super().__init__(energies, densities, efermi) self.efermi = efermi + def __str__(self) -> str: + """Get a string which can be easily plotted (using gnuplot).""" + if Spin.down in self.densities: + str_arr = [f"#{'Energy':30s} {'DensityUp':30s} {'DensityDown':30s}"] + for idx, energy in enumerate(self.energies): + str_arr.append(f"{energy:.5f} {self.densities[Spin.up][idx]:.5f} {self.densities[Spin.down][idx]:.5f}") + else: + str_arr = [f"#{'Energy':30s} {'DensityUp':30s}"] + for idx, energy in enumerate(self.energies): + str_arr.append(f"{energy:.5f} {self.densities[Spin.up][idx]:.5f}") + return "\n".join(str_arr) + def get_interpolated_gap(self, tol: float = 0.001, abs_tol: bool = False, spin: Spin | None = None): """Expects a DOS object and finds the gap. @@ -148,18 +160,6 @@ def get_gap(self, tol: float = 0.001, abs_tol: bool = False, spin: Spin | None = cbm, vbm = self.get_cbm_vbm(tol, abs_tol, spin) return max(cbm - vbm, 0.0) - def __str__(self) -> str: - """Get a string which can be easily plotted (using gnuplot).""" - if Spin.down in self.densities: - str_arr = [f"#{'Energy':30s} {'DensityUp':30s} {'DensityDown':30s}"] - for i, energy in enumerate(self.energies): - str_arr.append(f"{energy:.5f} {self.densities[Spin.up][i]:.5f} {self.densities[Spin.down][i]:.5f}") - else: - str_arr = [f"#{'Energy':30s} {'DensityUp':30s}"] - for i, energy in enumerate(self.energies): - str_arr.append(f"{energy:.5f} {self.densities[Spin.up][i]:.5f}") - return "\n".join(str_arr) - class Dos(MSONable): """Basic DOS object. All other DOS objects are extended versions of this