Skip to content

Commit

Permalink
Tidy annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
utf committed Oct 10, 2023
1 parent f7fa3e0 commit 58fb941
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 130 deletions.
5 changes: 3 additions & 2 deletions src/ifermi/analysis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Isosurface and isoline analysis functions."""

from __future__ import annotations

import warnings
from typing import Union

import numpy as np

Expand Down Expand Up @@ -41,7 +42,7 @@ def isosurface_area(vertices: np.ndarray, faces: np.ndarray) -> float:

def average_properties(
vertices: np.ndarray, faces: np.ndarray, properties: np.ndarray, norm: bool = False
) -> Union[float, np.ndarray]:
) -> float | np.ndarray:
"""Average property across an isosurface.
Args:
Expand Down
18 changes: 11 additions & 7 deletions src/ifermi/brillouin_zone.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"""Brillouin zone and slice geometries."""

from __future__ import annotations

import itertools
from dataclasses import dataclass, field
from typing import Optional
from typing import TYPE_CHECKING

import numpy as np
from monty.json import MSONable
from pymatgen.core.structure import Structure

if TYPE_CHECKING:
from pymatgen.core.structure import Structure

__all__ = ["ReciprocalSlice", "ReciprocalCell", "WignerSeitzCell"]

Expand All @@ -23,10 +27,10 @@ class ReciprocalSlice(MSONable):
the 3D Brillouin zone to points on the 2D slice.
"""

reciprocal_space: "ReciprocalCell"
reciprocal_space: ReciprocalCell
vertices: np.ndarray
transformation: np.ndarray
_edges: Optional[np.ndarray] = field(default=None, init=False)
_edges: np.ndarray | None = field(default=None, init=False)

def __post_init__(self):
"""Ensure all inputs are numpy arrays."""
Expand Down Expand Up @@ -66,7 +70,7 @@ class ReciprocalCell(MSONable):
faces: list[list[int]]
centers: np.ndarray
normals: np.ndarray
_edges: Optional[np.ndarray] = field(default=None, init=False)
_edges: np.ndarray | None = field(default=None, init=False)

def __post_init__(self):
"""Ensure all inputs are numpy arrays."""
Expand All @@ -76,7 +80,7 @@ def __post_init__(self):
self.normals = np.array(self.normals)

@classmethod
def from_structure(cls, structure: Structure) -> "ReciprocalCell":
def from_structure(cls, structure: Structure) -> ReciprocalCell:
"""Initialise the reciprocal cell from a structure.
Args:
Expand Down Expand Up @@ -195,7 +199,7 @@ class WignerSeitzCell(ReciprocalCell):
"""

@classmethod
def from_structure(cls, structure: Structure) -> "WignerSeitzCell":
def from_structure(cls, structure: Structure) -> WignerSeitzCell:
"""Initialise the Wigner-Seitz cell from a structure.
Args:
Expand Down
14 changes: 9 additions & 5 deletions src/ifermi/interpolate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"""Tools for Fourier and linear interpolation."""

from typing import Optional
from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np
from pymatgen.electronic_structure.bandstructure import BandStructure
from pymatgen.electronic_structure.core import Spin

if TYPE_CHECKING:
from pymatgen.electronic_structure.core import Spin

__all__ = ["FourierInterpolator", "LinearInterpolator", "trim_bandstructure"]

Expand All @@ -23,8 +27,8 @@ class FourierInterpolator:
def __init__(
self,
band_structure: BandStructure,
magmom: Optional[np.ndarray] = None,
mommat: Optional[np.ndarray] = None,
magmom: np.ndarray | None = None,
mommat: np.ndarray | None = None,
):
from BoltzTraP2.units import Angstrom
from pymatgen.io.ase import AseAtomsAdaptor
Expand Down Expand Up @@ -160,7 +164,7 @@ def __init__(
kpoints: np.ndarray,
energies: np.ndarray,
lattice_matrix: np.ndarray,
mommat: Optional[np.ndarray] = None,
mommat: np.ndarray | None = None,
):
self.kpoints = kpoints
self.ebands = energies
Expand Down
7 changes: 6 additions & 1 deletion src/ifermi/kpoints.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
"""k-point manipulation functions."""

from __future__ import annotations

import warnings
from typing import TYPE_CHECKING

import numpy as np
from pymatgen.electronic_structure.bandstructure import BandStructure

from ifermi.defaults import KTOL

if TYPE_CHECKING:
from pymatgen.electronic_structure.bandstructure import BandStructure

__all__ = [
"kpoints_to_first_bz",
"kpoints_from_bandstructure",
Expand Down
Loading

0 comments on commit 58fb941

Please sign in to comment.