Skip to content

Commit

Permalink
relocate magic method
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Jun 13, 2024
1 parent 00b7134 commit 952e206
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pymatgen/electronic_structure/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 952e206

Please sign in to comment.