Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type annotations for io.vasp.outputs #3776

Merged
merged 24 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a5f5236
remove a lot of ignore tags
DanielYang59 May 17, 2024
edb1419
first go: quick look and comment/type tweaks
DanielYang59 May 17, 2024
d926588
Merge branch 'materialsproject:master' into types-core-structure
DanielYang59 May 17, 2024
deb62e5
remove ALL type: ignore[reportPossiblyUnboundVariable]
DanielYang59 May 17, 2024
f29bb05
a quick look
DanielYang59 May 17, 2024
2e3ebd3
tweak module docstring
DanielYang59 May 18, 2024
9ec4267
Merge branch 'master' into types-core-structure
DanielYang59 May 18, 2024
3218004
fix/supress PossiblyUnboundVariable
DanielYang59 May 18, 2024
338c2f3
pre-commit fix
DanielYang59 May 18, 2024
b83361c
revert changes from other branch
DanielYang59 May 24, 2024
891c728
Merge branch 'master' into type-vasp-outputs
DanielYang59 May 25, 2024
c990b01
[Need Discussion] set IVDW default to 0
DanielYang59 May 29, 2024
c90ea52
Merge branch 'master' into type-vasp-outputs
DanielYang59 May 29, 2024
0346b92
suppress None error for ElementTree searches
DanielYang59 May 29, 2024
09b2930
replace dict update with |=
DanielYang59 May 29, 2024
d60de4f
fix typo in update -> |=, and mypy fixes
DanielYang59 May 29, 2024
01134fd
fix another typo in update -> |=
DanielYang59 May 29, 2024
2061ecc
add DEBUG tag and mypy fixes
DanielYang59 May 29, 2024
8bd6ccd
remove DEBUG tag
DanielYang59 May 29, 2024
3845e9c
more mypy fixes
DanielYang59 May 29, 2024
b6f82ac
more mypy fixes
DanielYang59 May 29, 2024
242e443
mypy fixes
DanielYang59 May 30, 2024
805b687
finish mypy errors
DanielYang59 May 30, 2024
495909d
Merge branch 'master' into type-vasp-outputs
DanielYang59 May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pymatgen/core/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from pymatgen.core.structure import Composition, DummySpecies, Element, Lattice, Molecule, Species, Structure
from pymatgen.io.ase import AseAtomsAdaptor
from pymatgen.io.vasp.outputs import Vasprun, Xdatcar

if TYPE_CHECKING:
from collections.abc import Iterator
Expand Down Expand Up @@ -547,9 +546,13 @@ def from_file(cls, filename: str | Path, constant_lattice: bool = True, **kwargs
structures = []

if fnmatch(filename, "*XDATCAR*"):
from pymatgen.io.vasp.outputs import Xdatcar

structures = Xdatcar(filename).structures

elif fnmatch(filename, "vasprun*.xml*"):
from pymatgen.io.vasp.outputs import Vasprun

structures = Vasprun(filename).structures

elif fnmatch(filename, "*.traj"):
Expand Down
11 changes: 7 additions & 4 deletions pymatgen/entries/computed_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def __init__(
energy_adjustments: list | None = None,
parameters: dict | None = None,
data: dict | None = None,
entry_id: object | None = None,
entry_id: str | None = None,
):
"""Initialize a ComputedEntry.

Expand Down Expand Up @@ -557,7 +557,7 @@ def __init__(
energy_adjustments: list | None = None,
parameters: dict | None = None,
data: dict | None = None,
entry_id: object | None = None,
entry_id: str | None = None,
) -> None:
"""Initialize a ComputedStructureEntry.

Expand Down Expand Up @@ -647,7 +647,10 @@ def from_dict(cls, dct: dict) -> Self:
entry_id=dct.get("entry_id"),
)

def normalize(self, mode: Literal["formula_unit", "atom"] = "formula_unit") -> ComputedStructureEntry:
def normalize(
self,
mode: Literal["formula_unit", "atom"] = "formula_unit",
) -> ComputedStructureEntry:
"""Normalize the entry's composition and energy. The structure remains unchanged.

Args:
Expand Down Expand Up @@ -698,7 +701,7 @@ def __init__(
energy_adjustments: list | None = None,
parameters: dict | None = None,
data: dict | None = None,
entry_id: object | None = None,
entry_id: str | None = None,
):
"""
Args:
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/io/lobster/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,14 +1380,14 @@ def __init__(
iband = 0
if line.split()[0] != "#":
if linenumber < self.nbands:
if ifilename == 0:
if ifilename == 0 and self.efermi is not None:
eigenvals[Spin.up][iband][idx_kpt] = float(line.split()[1]) + self.efermi

p_eigenvals[Spin.up][iband][idx_kpt][atom_names[ifilename]][orbital_names[ifilename]] = float(
line.split()[2]
)
if linenumber >= self.nbands and self.is_spinpolarized:
if ifilename == 0:
if ifilename == 0 and self.efermi is not None:
eigenvals[Spin.down][iband][idx_kpt] = float(line.split()[1]) + self.efermi
p_eigenvals[Spin.down][iband][idx_kpt][atom_names[ifilename]][orbital_names[ifilename]] = float(
line.split()[2]
Expand Down
8 changes: 7 additions & 1 deletion pymatgen/io/vasp/optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ class DielectricFunctionCalculator(MSONable):

@classmethod
def from_vasp_objects(cls, vrun: Vasprun, waveder: Waveder) -> Self:
"""Construct a DielectricFunction from Vasprun, Kpoint, and Waveder objects.
"""Construct a DielectricFunction from Vasprun, Kpoint, and Waveder.

Args:
vrun: Vasprun object
kpoint: Kpoint object
waveder: Waveder object
"""
bands = vrun.eigenvalues
if bands is None:
raise RuntimeError("eigenvalues cannot be None.")

sspins = [Spin.up, Spin.down]
eigs = np.stack([bands[spin] for spin in sspins[: vrun.parameters["ISPIN"]]], axis=2)[..., 0]
eigs = np.swapaxes(eigs, 0, 1)
Expand All @@ -95,6 +98,9 @@ def from_vasp_objects(cls, vrun: Vasprun, waveder: Waveder) -> Self:
if vrun.parameters["ISYM"] != 0:
raise NotImplementedError("ISYM != 0 is not implemented yet")

if efermi is None:
raise ValueError("efermi cannot be None.")

return cls(
cder_real=waveder.cder_real,
cder_imag=waveder.cder_imag,
Expand Down
Loading