Skip to content

Commit

Permalink
Merge 0c76a2f into 582cb83
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmshn committed Jan 19, 2023
2 parents 582cb83 + 0c76a2f commit 77d417c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pymatgen/electronic_structure/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,23 @@ class Dos(MSONable):
Fermi level
"""

def __init__(self, efermi: float, energies: ArrayLike, densities: Mapping[Spin, ArrayLike]):
def __init__(
self, efermi: float, energies: ArrayLike, densities: Mapping[Spin, ArrayLike], norm_vol: float | None = None
):
"""
Args:
efermi: Fermi level energy
energies: A sequences of energies
densities (dict[Spin: np.array]): representing the density of states for each Spin.
norm_vol: The volume used to normalize the densities. Defaults to if None which will not perform any
normalization. If not None, the resulting density will have units of states/eV/Angstrom^3, otherwise
the density will be in states/eV.
"""
self.efermi = efermi
self.energies = np.array(energies)
self.densities = {k: np.array(d) for k, d in densities.items()}
self.norm_vol = norm_vol
vol = norm_vol or 1.0
self.densities = {k: np.array(d) / vol for k, d in densities.items()}

def get_densities(self, spin: Spin | None = None):
"""
Expand Down Expand Up @@ -648,17 +655,23 @@ def __init__(
structure: Structure,
total_dos: Dos,
pdoss: Mapping[PeriodicSite, Mapping[Orbital, Mapping[Spin, ArrayLike]]],
normalize: bool = False,
):
"""
Args:
structure: Structure associated with this particular DOS.
total_dos: total Dos for structure
pdoss: The pdoss are supplied as an {Site: {Orbital: {Spin:Densities}}}
normalize: Whether to normalize the densities by the volume of the structure.
If True, the units of the densities are states/eV/Angstrom^3. Otherwise,
the units are states/eV.
"""
vol = structure.volume if normalize else None
super().__init__(
total_dos.efermi,
energies=total_dos.energies,
densities={k: np.array(d) for k, d in total_dos.densities.items()},
norm_vol=vol,
)
self.pdos = pdoss
self.structure = structure
Expand Down
11 changes: 11 additions & 0 deletions pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,17 @@ def complete_dos(self):
pdoss = {final_struct[i]: pdos for i, pdos in enumerate(self.pdos)}
return CompleteDos(self.final_structure, self.tdos, pdoss)

@property
def complete_dos_normalized(self):
"""
A complete dos object which incorporates the total dos and all
projected dos. Normalized by the volume of the unit cell.
The resulting dos is in units of states/eV/unit cell volume.
"""
final_struct = self.final_structure
pdoss = {final_struct[i]: pdos for i, pdos in enumerate(self.pdos)}
return CompleteDos(self.final_structure, self.tdos, pdoss, normalize=True)

@property
def hubbards(self):
"""
Expand Down
8 changes: 8 additions & 0 deletions pymatgen/io/vasp/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ def test_standard(self):
self.assertAlmostEqual(pdos0[Orbital.pz][Spin.down][16], 0.0012)
self.assertEqual(pdos0[Orbital.s][Spin.up].shape, (301,))

pdos0_norm = vasprun.complete_dos_normalized.pdos[vasprun.final_structure[0]]
self.assertAlmostEqual(pdos0_norm[Orbital.s][Spin.up][16], 0.0026) # the site data should not change
self.assertEqual(pdos0_norm[Orbital.s][Spin.up].shape, (301,))

cdos_norm, cdos = vasprun.complete_dos_normalized, vasprun.complete_dos
ratio = np.nanmax(cdos.densities[Spin.up] / cdos_norm.densities[Spin.up])
self.assertAlmostEqual(ratio, vasprun.final_structure.volume) # the site data should not change

filepath2 = self.TEST_FILES_DIR / "lifepo4.xml"
vasprun_ggau = Vasprun(filepath2, parse_projected_eigen=True, parse_potcar_file=False)
totalscsteps = sum(len(i["electronic_steps"]) for i in vasprun.ionic_steps)
Expand Down

0 comments on commit 77d417c

Please sign in to comment.