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

Fix ruff D212 #3251

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions docs/conf.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pymatgen/alchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"""
This package provides the modules for performing large scale transformations on
"""This package provides the modules for performing large scale transformations on
a large number of structures.
"""
39 changes: 13 additions & 26 deletions pymatgen/alchemy/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@


class AbstractStructureFilter(MSONable, metaclass=abc.ABCMeta):
"""
AbstractStructureFilter that defines an API to perform testing of
"""AbstractStructureFilter that defines an API to perform testing of
Structures. Structures that return True to a test are retained during
transmutation while those that return False are removed.
"""

@abc.abstractmethod
def test(self, structure: Structure):
"""
Method to execute the test.
"""Method to execute the test.

Args:
structure (Structure): Input structure to test
Expand All @@ -39,8 +37,7 @@ def test(self, structure: Structure):


class ContainsSpecieFilter(AbstractStructureFilter):
"""
Filter for structures containing certain elements or species.
"""Filter for structures containing certain elements or species.
By default compares by atomic number.
"""

Expand All @@ -60,8 +57,7 @@ def __init__(self, species, strict_compare=False, AND=True, exclude=False):
self._exclude = exclude

def test(self, structure: Structure):
"""
Method to execute the test.
"""Method to execute the test.

Returns: True if structure do not contain specified species.
"""
Expand Down Expand Up @@ -121,8 +117,7 @@ def from_dict(cls, dct):


class SpecieProximityFilter(AbstractStructureFilter):
"""
This filter removes structures that have certain species that are too close
"""This filter removes structures that have certain species that are too close
together.
"""

Expand All @@ -139,8 +134,7 @@ def __init__(self, specie_and_min_dist_dict):
self.specie_and_min_dist = {get_el_sp(k): v for k, v in specie_and_min_dist_dict.items()}

def test(self, structure: Structure):
"""
Method to execute the test.
"""Method to execute the test.

Args:
structure (Structure): Input structure to test
Expand Down Expand Up @@ -185,8 +179,7 @@ class RemoveDuplicatesFilter(AbstractStructureFilter):
"""This filter removes exact duplicate structures from the transmuter."""

def __init__(self, structure_matcher: dict | StructureMatcher | None = None, symprec: float | None = None) -> None:
"""
Remove duplicate structures based on the structure matcher
"""Remove duplicate structures based on the structure matcher
and symmetry (if symprec is given).

Args:
Expand Down Expand Up @@ -235,8 +228,7 @@ class RemoveExistingFilter(AbstractStructureFilter):
"""This filter removes structures existing in a given list from the transmuter."""

def __init__(self, existing_structures, structure_matcher=None, symprec=None):
"""
Remove existing structures based on the structure matcher
"""Remove existing structures based on the structure matcher
and symmetry (if symprec is given).

Args:
Expand All @@ -256,8 +248,7 @@ def __init__(self, existing_structures, structure_matcher=None, symprec=None):
self.structure_matcher = structure_matcher or StructureMatcher(comparator=ElementComparator())

def test(self, structure: Structure):
"""
Method to execute the test.
"""Method to execute the test.

Args:
structure (Structure): Input structure to test
Expand Down Expand Up @@ -291,8 +282,7 @@ def as_dict(self):


class ChargeBalanceFilter(AbstractStructureFilter):
"""
This filter removes structures that are not charge balanced from the
"""This filter removes structures that are not charge balanced from the
transmuter. This only works if the structure is oxidation state
decorated, as structures with only elemental sites are automatically
assumed to have net charge of 0.
Expand All @@ -302,8 +292,7 @@ def __init__(self):
"""No args required."""

def test(self, structure: Structure):
"""
Method to execute the test.
"""Method to execute the test.

Args:
structure (Structure): Input structure to test
Expand All @@ -314,8 +303,7 @@ def test(self, structure: Structure):


class SpeciesMaxDistFilter(AbstractStructureFilter):
"""
This filter removes structures that do have two particular species that are
"""This filter removes structures that do have two particular species that are
not nearest neighbors by a predefined max_dist. For instance, if you are
analyzing Li battery materials, you would expect that each Li+ would be
nearest neighbor to lower oxidation state transition metal for
Expand All @@ -336,8 +324,7 @@ def __init__(self, sp1, sp2, max_dist):
self.max_dist = max_dist

def test(self, structure: Structure):
"""
Method to execute the test.
"""Method to execute the test.

Args:
structure (Structure): Input structure to test
Expand Down
51 changes: 17 additions & 34 deletions pymatgen/alchemy/materials.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
This module provides various representations of transformed structures. A
"""This module provides various representations of transformed structures. A
TransformedStructure is a structure that has been modified by undergoing a
series of transformations.
"""
Expand All @@ -26,8 +25,7 @@


class TransformedStructure(MSONable):
"""
Container object for new structures that include history of
"""Container object for new structures that include history of
transformations.

Each transformed structure is made up of a sequence of structures with
Expand All @@ -41,8 +39,7 @@ def __init__(
history: list[AbstractTransformation | dict[str, Any]] | None = None,
other_parameters: dict[str, Any] | None = None,
) -> None:
"""
Initializes a transformed structure from a structure.
"""Initializes a transformed structure from a structure.

Args:
structure (Structure): Input structure
Expand All @@ -61,8 +58,7 @@ def __init__(
self.append_transformation(trafo)

def undo_last_change(self) -> None:
"""
Undo the last change in the TransformedStructure.
"""Undo the last change in the TransformedStructure.

Raises:
IndexError: If already at the oldest change.
Expand All @@ -79,8 +75,7 @@ def undo_last_change(self) -> None:
self.final_structure = struct

def redo_next_change(self) -> None:
"""
Redo the last undone change in the TransformedStructure.
"""Redo the last undone change in the TransformedStructure.

Raises:
IndexError: If already at the latest change.
Expand All @@ -101,8 +96,7 @@ def __len__(self) -> int:
def append_transformation(
self, transformation, return_alternatives: bool = False, clear_redo: bool = True
) -> list[TransformedStructure] | None:
"""
Appends a transformation to the TransformedStructure.
"""Appends a transformation to the TransformedStructure.

Args:
transformation: Transformation to append
Expand Down Expand Up @@ -157,8 +151,7 @@ def append_transformation(
return None

def append_filter(self, structure_filter: AbstractStructureFilter) -> None:
"""
Adds a filter.
"""Adds a filter.

Args:
structure_filter (StructureFilter): A filter implementing the
Expand All @@ -171,8 +164,7 @@ def append_filter(self, structure_filter: AbstractStructureFilter) -> None:
def extend_transformations(
self, transformations: list[AbstractTransformation], return_alternatives: bool = False
) -> None:
"""
Extends a sequence of transformations to the TransformedStructure.
"""Extends a sequence of transformations to the TransformedStructure.

Args:
transformations: Sequence of Transformations
Expand All @@ -185,8 +177,7 @@ def extend_transformations(
self.append_transformation(t, return_alternatives=return_alternatives)

def get_vasp_input(self, vasp_input_set: type[VaspInputSet] = MPRelaxSet, **kwargs) -> dict[str, Any]:
"""
Returns VASP input as a dict of VASP objects.
"""Returns VASP input as a dict of VASP objects.

Args:
vasp_input_set (pymatgen.io.vasp.sets.VaspInputSet): input set
Expand All @@ -204,8 +195,7 @@ def write_vasp_input(
create_directory: bool = True,
**kwargs,
) -> None:
"""
Writes VASP input to an output_dir.
"""Writes VASP input to an output_dir.

Args:
vasp_input_set: pymatgen.io.vasp.sets.VaspInputSet like object that creates vasp input files from
Expand All @@ -230,8 +220,7 @@ def __str__(self) -> str:
return "\n".join(output)

def set_parameter(self, key: str, value: Any) -> None:
"""
Set a parameter.
"""Set a parameter.

:param key: The string key
:param value: The value.
Expand All @@ -240,8 +229,7 @@ def set_parameter(self, key: str, value: Any) -> None:

@property
def was_modified(self) -> bool:
"""
Boolean describing whether the last transformation on the structure
"""Boolean describing whether the last transformation on the structure
made any alterations to it one example of when this would return false
is in the case of performing a substitution transformation on the
structure when the specie to replace isn't in the structure.
Expand All @@ -250,8 +238,7 @@ def was_modified(self) -> bool:

@property
def structures(self) -> list[Structure]:
"""
Copy of all structures in the TransformedStructure. A
"""Copy of all structures in the TransformedStructure. A
structure is stored after every single transformation.
"""
h_structs = [Structure.from_dict(s["input_structure"]) for s in self.history if "input_structure" in s]
Expand All @@ -264,8 +251,7 @@ def from_cif_string(
primitive: bool = True,
occupancy_tolerance: float = 1.0,
) -> TransformedStructure:
"""
Generates TransformedStructure from a cif string.
"""Generates TransformedStructure from a cif string.

Args:
cif_string (str): Input cif string. Should contain only one
Expand Down Expand Up @@ -307,8 +293,7 @@ def from_cif_string(
def from_poscar_string(
poscar_string: str, transformations: list[AbstractTransformation] | None = None
) -> TransformedStructure:
"""
Generates TransformedStructure from a poscar string.
"""Generates TransformedStructure from a poscar string.

Args:
poscar_string (str): Input POSCAR string.
Expand Down Expand Up @@ -346,8 +331,7 @@ def from_dict(cls, d) -> TransformedStructure:
return cls(struct, history=d["history"], other_parameters=d.get("other_parameters"))

def to_snl(self, authors, **kwargs) -> StructureNL:
"""
Generate SNL from TransformedStructure.
"""Generate SNL from TransformedStructure.

:param authors: List of authors
:param **kwargs: All kwargs supported by StructureNL.
Expand All @@ -370,8 +354,7 @@ def to_snl(self, authors, **kwargs) -> StructureNL:

@classmethod
def from_snl(cls, snl: StructureNL) -> TransformedStructure:
"""
Create TransformedStructure from SNL.
"""Create TransformedStructure from SNL.

Args:
snl (StructureNL): Starting snl
Expand Down
Loading