Skip to content

Commit

Permalink
Fix NotImplementedError messages in InputSet subclasses
Browse files Browse the repository at this point in the history
also remove unused test file (also in wrong directory)
looks like it was accidentally committed in 8abc50e
  • Loading branch information
janosh committed Feb 15, 2024
1 parent 0f474f6 commit 988da0c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 49 deletions.
8 changes: 4 additions & 4 deletions pymatgen/core/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,19 +423,19 @@ def write_Xdatcar(
syms = [site.specie.symbol for site in self[0]]
n_atoms = [len(tuple(a[1])) for a in itertools.groupby(syms)]

for si, coords in enumerate(self.coords):
for idx, coords in enumerate(self.coords):
# Only print out the info block if
if si == 0 or not self.constant_lattice:
if idx == 0 or not self.constant_lattice:
lines.extend([system, "1.0"])

_lattice = self.lattice if self.constant_lattice else self.lattice[si] # type: ignore
_lattice = self.lattice if self.constant_lattice else self.lattice[idx] # type: ignore

for latt_vec in _lattice:
lines.append(f'{" ".join(map(str, latt_vec))}')

lines.extend((" ".join(site_symbols), " ".join(map(str, n_atoms))))

lines.append(f"Direct configuration= {si + 1}")
lines.append(f"Direct configuration= {idx + 1}")

for coord, specie in zip(coords, self.species):
line = f'{" ".join(format_str.format(c) for c in coord)} {specie}'
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/io/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __getattr__(self, key):
raise AttributeError(f"'{type(self).__name__}' object has no attribute {key!r}")

def __copy__(self) -> InputSet:
cls = self.__class__
cls = type(self)
new_instance = cls.__new__(cls)

for key, val in self.__dict__.items():
Expand All @@ -153,7 +153,7 @@ def __copy__(self) -> InputSet:
return new_instance

def __deepcopy__(self, memo: dict[int, InputSet]) -> InputSet:
cls = self.__class__
cls = type(self)
new_instance = cls.__new__(cls)
memo[id(self)] = new_instance

Expand Down Expand Up @@ -233,7 +233,7 @@ def from_directory(cls, directory: str | Path):
Args:
directory: Directory to read input files from
"""
raise NotImplementedError(f"from_directory has not been implemented in {cls}")
raise NotImplementedError(f"from_directory has not been implemented in {cls.__name__}")

def validate(self) -> bool:
"""
Expand All @@ -242,7 +242,7 @@ def validate(self) -> bool:
Will raise a NotImplementedError unless overloaded by the inheriting class.
"""
raise NotImplementedError(f".validate() has not been implemented in {self.__class__}")
raise NotImplementedError(f".validate() has not been implemented in {type(self).__name__}")


class InputGenerator(MSONable):
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/lammps/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ def validate(self) -> bool:
input set. Can be as simple or as complex as desired.
Will raise a NotImplementedError unless overloaded by the inheriting class.
"""
raise NotImplementedError(f".validate() has not been implemented in {self.__class__}")
raise NotImplementedError(f".validate() has not been implemented in {type(self).__name__}")
2 changes: 1 addition & 1 deletion pymatgen/io/packmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def from_directory(cls, directory: str | Path):
Args:
directory (str | Path): Directory to read input files from.
"""
raise NotImplementedError(f"from_directory has not been implemented in {cls}")
raise NotImplementedError(f"from_directory has not been implemented in {cls.__name__}")


class PackmolBoxGen(InputGenerator):
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/res.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def __init__(self, res: Res, parse_rems: Literal["gentle", "strict"] = "gentle")
"""The :func:`from_str` and :func:`from_file` methods should be used instead of constructing this directly."""
super().__init__(res)
if self._res.TITL is None:
raise ResError(f"{self.__class__} can only be constructed from a res file with a valid TITL entry.")
raise ResError(f"{type(self).__name__} can only be constructed from a res file with a valid TITL entry.")
if parse_rems not in ["gentle", "strict"]:
raise ValueError(f"{parse_rems} not valid, must be either 'gentle' or 'strict'.")
self._TITL = self._res.TITL # alias for the object so it is guarded by the None check
Expand Down
38 changes: 0 additions & 38 deletions tests/core/slab.cif

This file was deleted.

0 comments on commit 988da0c

Please sign in to comment.