Skip to content

Commit

Permalink
Revert Self usage (#3401)
Browse files Browse the repository at this point in the history
  • Loading branch information
ab5424 committed Oct 11, 2023
1 parent 38db1dd commit b9a4ef4
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
12 changes: 6 additions & 6 deletions pymatgen/io/lammps/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import Any, Self
from typing import Any

from pymatgen.core.sites import Site
from pymatgen.core.structure import SiteCollection
Expand Down Expand Up @@ -639,7 +639,7 @@ def label_topo(t) -> tuple:
return self.box, ff, topo_list

@classmethod
def from_file(cls, filename: str, atom_style: str = "full", sort_id: bool = False) -> Self:
def from_file(cls, filename: str, atom_style: str = "full", sort_id: bool = False) -> LammpsData:
"""
Constructor that parses a file.
Expand Down Expand Up @@ -1204,7 +1204,7 @@ def to_file(self, filename: str) -> None:
yaml.dump(d, f)

@classmethod
def from_file(cls, filename: str) -> Self:
def from_file(cls, filename: str) -> ForceField:
"""
Constructor that reads in a file in YAML format.
Expand All @@ -1217,7 +1217,7 @@ def from_file(cls, filename: str) -> Self:
return cls.from_dict(d)

@classmethod
def from_dict(cls, d: dict) -> Self:
def from_dict(cls, d: dict) -> ForceField:
"""
Constructor that reads in a dictionary.
Expand Down Expand Up @@ -1416,7 +1416,7 @@ def parse_xyz(cls, filename: str | Path) -> pd.DataFrame:
return df

@classmethod
def from_files(cls, coordinate_file: str, list_of_numbers: list, *filenames) -> Self:
def from_files(cls, coordinate_file: str, list_of_numbers: list, *filenames) -> CombinedData:
"""
Constructor that parse a series of data file.
Expand All @@ -1442,7 +1442,7 @@ def from_files(cls, coordinate_file: str, list_of_numbers: list, *filenames) ->
@classmethod
def from_lammpsdata(
cls, mols: list, names: list, list_of_numbers: list, coordinates: pd.DataFrame, atom_style: str | None = None
) -> Self:
) -> CombinedData:
"""
Constructor that can infer atom_style.
The input LammpsData objects are used non-destructively.
Expand Down
5 changes: 2 additions & 3 deletions pymatgen/io/lammps/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

if TYPE_CHECKING:
from os import PathLike
from typing import Self

from pymatgen.io.core import InputSet

Expand Down Expand Up @@ -539,7 +538,7 @@ def write_file(self, filename: str | PathLike, ignore_comments: bool = False, ke

@classmethod
@np.deprecate(message="Use from_str instead")
def from_string(cls, *args, **kwargs) -> Self:
def from_string(cls, *args, **kwargs) -> LammpsInputFile:
return cls.from_str(*args, **kwargs)

@classmethod
Expand Down Expand Up @@ -918,7 +917,7 @@ def md(
temperature: float,
nsteps: int,
other_settings: dict | None = None,
) -> Self:
) -> LammpsRun:
r"""
Example for a simple MD run based on template md.template.
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/io/lammps/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pymatgen.io.lammps.data import LammpsBox

if TYPE_CHECKING:
from typing import Any, Self
from typing import Any

__author__ = "Kiran Mathew, Zhi Deng"
__copyright__ = "Copyright 2018, The Materials Virtual Lab"
Expand Down Expand Up @@ -48,11 +48,11 @@ def __init__(self, timestep: int, natoms: int, box: LammpsBox, data: pd.DataFram

@classmethod
@np.deprecate(message="Use from_str instead")
def from_string(cls, *args, **kwargs) -> Self:
def from_string(cls, *args, **kwargs) -> LammpsDump:
return cls.from_str(*args, **kwargs)

@classmethod
def from_str(cls, string: str) -> Self:
def from_str(cls, string: str) -> LammpsDump:
"""
Constructor from string parsing.
Expand All @@ -76,7 +76,7 @@ def from_str(cls, string: str) -> Self:
return cls(timestep, n_atoms, box, data)

@classmethod
def from_dict(cls, d: dict) -> Self:
def from_dict(cls, d: dict) -> LammpsDump:
"""
Args:
d (dict): Dict representation.
Expand Down
3 changes: 1 addition & 2 deletions pymatgen/io/lammps/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

if TYPE_CHECKING:
from pathlib import Path
from typing import Self

__author__ = "Ryan Kingsbury, Guillaume Brunin (Matgenix)"
__copyright__ = "Copyright 2021, The Materials Project"
Expand Down Expand Up @@ -73,7 +72,7 @@ def __init__(
super().__init__(inputs={"in.lammps": self.inputfile, "system.data": self.data})

@classmethod
def from_directory(cls, directory: str | Path, keep_stages: bool = False) -> Self:
def from_directory(cls, directory: str | Path, keep_stages: bool = False) -> LammpsInputSet:
"""
Construct a LammpsInputSet from a directory of two or more files.
TODO: accept directories with only the input file, that should include the structure as well.
Expand Down
5 changes: 2 additions & 3 deletions pymatgen/phonon/bandstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
if TYPE_CHECKING:
from collections.abc import Sequence
from os import PathLike
from typing import Self

from numpy.typing import ArrayLike

Expand Down Expand Up @@ -263,7 +262,7 @@ def as_dict(self):
return dct

@classmethod
def from_dict(cls, dct) -> Self:
def from_dict(cls, dct) -> PhononBandStructure:
"""
Args:
dct (dict): Dict representation.
Expand Down Expand Up @@ -592,7 +591,7 @@ def as_dict(self) -> dict:
return dct

@classmethod
def from_dict(cls, dct: dict) -> Self:
def from_dict(cls, dct: dict) -> PhononBandStructureSymmLine:
"""
Args:
dct: Dict representation.
Expand Down
9 changes: 4 additions & 5 deletions pymatgen/phonon/dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import Self

BOLTZ_THZ_PER_K = const.value("Boltzmann constant in Hz/K") / const.tera # Boltzmann constant in THz/K
THZ_TO_J = const.value("hertz-joule relationship") * const.tera
Expand Down Expand Up @@ -63,7 +62,7 @@ def get_smeared_densities(self, sigma: float) -> np.ndarray:

return gaussian_filter1d(self.densities, sigma / avgdiff)

def __add__(self, other: Self) -> Self:
def __add__(self, other: PhononDos) -> PhononDos:
"""Adds two DOS together. Checks that frequency scales are the same.
Otherwise, a ValueError is thrown.
Expand All @@ -78,7 +77,7 @@ def __add__(self, other: Self) -> Self:
densities = self.densities + other.densities
return PhononDos(self.frequencies, densities)

def __radd__(self, other: Self) -> Self:
def __radd__(self, other: PhononDos) -> PhononDos:
"""Reflected addition of two DOS objects.
Args:
Expand All @@ -105,7 +104,7 @@ def __str__(self) -> str:
return "\n".join(stringarray)

@classmethod
def from_dict(cls, d: dict[str, Sequence]) -> Self:
def from_dict(cls, d: dict[str, Sequence]) -> PhononDos:
"""Returns PhononDos object from dict representation of PhononDos."""
return cls(d["frequencies"], d["densities"])

Expand Down Expand Up @@ -344,7 +343,7 @@ def get_element_dos(self) -> dict:
return {el: PhononDos(self.frequencies, densities) for el, densities in el_dos.items()}

@classmethod
def from_dict(cls, dct: dict) -> Self:
def from_dict(cls, dct: dict) -> CompletePhononDos:
"""Returns CompleteDos object from dict representation."""
tdos = PhononDos.from_dict(dct)
struct = Structure.from_dict(dct["structure"])
Expand Down
3 changes: 1 addition & 2 deletions pymatgen/phonon/ir_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
if TYPE_CHECKING:
from collections.abc import Sequence
from os import PathLike
from typing import Self

from matplotlib.axes import Axes
from numpy.typing import ArrayLike
Expand Down Expand Up @@ -59,7 +58,7 @@ def __init__(
self.epsilon_infinity = np.array(epsilon_infinity)

@classmethod
def from_dict(cls, dct: dict) -> Self:
def from_dict(cls, dct: dict) -> IRDielectricTensor:
"""Returns IRDielectricTensor from dict representation."""
structure = Structure.from_dict(dct["structure"])
oscillator_strength = dct["oscillator_strength"]
Expand Down
5 changes: 3 additions & 2 deletions pymatgen/phonon/thermal_displacements.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

if TYPE_CHECKING:
from os import PathLike
from typing import Self

from numpy.typing import ArrayLike

Expand Down Expand Up @@ -250,7 +249,9 @@ def _angle_dot(a: ArrayLike, b: ArrayLike) -> float:
description="Angle: A new tool for validating theoretically derived anisotropic displacement "
"parameters with experiment.",
)
def compute_directionality_quality_criterion(self, other: Self) -> list:
def compute_directionality_quality_criterion(
self, other: ThermalDisplacementMatrices
) -> list[dict[str, ArrayLike]]:
"""Will compute directionality of prolate displacement ellipsoids as described in
https://doi.org/10.1039/C9CE00794F with the earlier implementation: https://github.com/damMroz/Angle/.
Expand Down

0 comments on commit b9a4ef4

Please sign in to comment.