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

Replace-species #2291

Merged
merged 1 commit into from
Nov 18, 2021
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
6 changes: 4 additions & 2 deletions pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,16 @@ def X(self) -> float:
@property
def atomic_radius(self) -> Optional[FloatWithUnit]:
"""
Returns: The atomic radius of the element in Ångstroms.
Returns:
float | None: The atomic radius of the element in Ångstroms.
"""
return self._atomic_radius

@property
def atomic_mass(self) -> Optional[FloatWithUnit]:
"""
Returns: The atomic mass of the element in amu.
Returns:
float | None: The atomic mass of the element in amu.
"""
return self._atomic_mass

Expand Down
29 changes: 14 additions & 15 deletions pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ def remove_site_property(self, property_name: str):
for site in self.sites:
del site.properties[property_name]

def replace_species(self, species_mapping: Dict[SpeciesLike, SpeciesLike]):
def replace_species(self, species_mapping: Dict[SpeciesLike, SpeciesLike]) -> None:
"""
Swap species.
Swap species. Note that this method modifies the structure in place.

Args:
species_mapping (dict): dict of species to swap. Species can be
Expand All @@ -477,9 +477,8 @@ def replace_species(self, species_mapping: Dict[SpeciesLike, SpeciesLike]):
sp_in_structure = set(self.composition.keys())
if not sp_in_structure.issuperset(sp_to_replace):
warnings.warn(
"Some species to be substituted are not present in "
"structure. Pls check your input. Species to be "
"substituted = %s; Species in structure = %s" % (sp_to_replace, sp_in_structure)
"Some species to be substituted are not present in structure. Pls check your input. Species to be "
f"substituted = {sp_to_replace}; Species in structure = {sp_in_structure}"
)

for site in self.sites:
Expand Down Expand Up @@ -652,7 +651,7 @@ def __init__(
to_unit_cell: bool = False,
coords_are_cartesian: bool = False,
site_properties: dict = None,
):
) -> None:
"""
Create a periodic structure.

Expand Down Expand Up @@ -726,7 +725,7 @@ def from_sites(
charge: float = None,
validate_proximity: bool = False,
to_unit_cell: bool = False,
):
) -> Union["IStructure", "Structure"]:
"""
Convenience constructor to make a Structure from a list of sites.

Expand Down Expand Up @@ -1024,7 +1023,7 @@ def get_space_group_info(self, symprec=1e-2, angle_tolerance=5.0) -> Tuple[str,
a = SpacegroupAnalyzer(self, symprec=symprec, angle_tolerance=angle_tolerance)
return a.get_space_group_symbol(), a.get_space_group_number()

def matches(self, other, anonymous=False, **kwargs):
def matches(self, other, anonymous=False, **kwargs) -> bool:
"""
Check whether this structure is similar to another structure.
Basically a convenience method to call structure matching.
Expand All @@ -1045,7 +1044,7 @@ def matches(self, other, anonymous=False, **kwargs):
return m.fit(self, other)
return m.fit_anonymous(self, other)

def __eq__(self, other):
def __eq__(self, other) -> bool:
if other is self:
return True
if other is None:
Expand All @@ -1059,14 +1058,14 @@ def __eq__(self, other):
return False
return True

def __ne__(self, other):
def __ne__(self, other) -> bool:
return not self.__eq__(other)

def __hash__(self):
def __hash__(self) -> int:
# For now, just use the composition hash code.
return self.composition.__hash__()

def __mul__(self, scaling_matrix):
def __mul__(self, scaling_matrix: Union[int, Sequence[int], Sequence[Sequence[int]]]) -> "Structure":
"""
Makes a supercell. Allowing to have sites outside the unit cell

Expand All @@ -1075,11 +1074,11 @@ def __mul__(self, scaling_matrix):
vectors. Has to be all integers. Several options are possible:

a. A full 3x3 scaling matrix defining the linear combination
the old lattice vectors. E.g., [[2,1,0],[0,3,0],[0,0,
of the old lattice vectors. E.g., [[2,1,0],[0,3,0],[0,0,
1]] generates a new structure with lattice vectors a' =
2a + b, b' = 3b, c' = c where a, b, and c are the lattice
vectors of the original structure.
b. An sequence of three scaling factors. E.g., [2, 1, 1]
b. A sequence of three scaling factors. E.g., [2, 1, 1]
specifies that the supercell should have dimensions 2a x b x
c.
c. A number, which simply scales all lattice vectors by the
Expand Down Expand Up @@ -1131,7 +1130,7 @@ def frac_coords(self):
return np.array([site.frac_coords for site in self._sites])

@property
def volume(self):
def volume(self) -> float:
"""
Returns the volume of the structure.
"""
Expand Down