Skip to content

Commit

Permalink
rename single-letter vars
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Oct 6, 2023
1 parent 170a5da commit dcea6b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
34 changes: 17 additions & 17 deletions pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,8 +1230,8 @@ def lattice(self) -> Lattice:
@property
def density(self) -> float:
"""Returns the density in units of g/cm^3."""
m = Mass(self.composition.weight, "amu")
return m.to("g") / (self.volume * Length(1, "ang").to("cm") ** 3)
mass = Mass(self.composition.weight, "amu")
return mass.to("g") / (self.volume * Length(1, "ang").to("cm") ** 3)

@property
def pbc(self) -> tuple[bool, bool, bool]:
Expand All @@ -1258,8 +1258,8 @@ def get_space_group_info(self, symprec=1e-2, angle_tolerance=5.0) -> tuple[str,
# Import within method needed to avoid cyclic dependency.
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer

spga = SpacegroupAnalyzer(self, symprec=symprec, angle_tolerance=angle_tolerance)
return spga.get_space_group_symbol(), spga.get_space_group_number()
spg_analyzer = SpacegroupAnalyzer(self, symprec=symprec, angle_tolerance=angle_tolerance)
return spg_analyzer.get_space_group_symbol(), spg_analyzer.get_space_group_number()

def matches(self, other: IStructure | Structure, anonymous: bool = False, **kwargs) -> bool:
"""Check whether this structure is similar to another structure.
Expand Down Expand Up @@ -2308,9 +2308,9 @@ def pbc_coord_intersection(fc1, fc2, tol):
# reduction.
# This reduction is O(n^3) so usually is an improvement. Using double
# the tolerance because both vectors are approximate
for g in sorted(grouped_fcoords, key=lambda x: len(x)):
for f in g:
min_vecs = pbc_coord_intersection(min_vecs, g - f, super_ftol_2)
for group in sorted(grouped_fcoords, key=lambda x: len(x)):
for frac_coords in group:
min_vecs = pbc_coord_intersection(min_vecs, group - frac_coords, super_ftol_2)

def get_hnf(fu):
"""Returns all possible distinct supercell matrices given a
Expand All @@ -2321,10 +2321,10 @@ def get_hnf(fu):
and b first, though unlikely to reduce to O(n^2).
"""

def factors(n):
for i in range(1, n + 1):
if n % i == 0:
yield i
def factors(n: int):
for idx in range(1, n + 1):
if n % idx == 0:
yield idx

for det in factors(fu):
if det == 1:
Expand Down Expand Up @@ -2387,8 +2387,8 @@ def factors(n):
break

# check that groups are all cliques
for g in groups:
if not np.all(groups[g][:, g]):
for group in groups:
if not np.all(groups[group][:, group]):
valid = False
break
if not valid:
Expand Down Expand Up @@ -3507,7 +3507,7 @@ def from_file(cls, filename):
installed.
Args:
filename (str): The filename to read from.
filename (str | Path): The filename to read from.
Returns:
Molecule
Expand All @@ -3530,9 +3530,9 @@ def from_file(cls, filename):
return cls.from_str(contents, fmt="yaml")
from pymatgen.io.babel import BabelMolAdaptor

m = re.search(r"\.(pdb|mol|mdl|sdf|sd|ml2|sy2|mol2|cml|mrv)", filename.lower())
if m:
new = BabelMolAdaptor.from_file(filename, m.group(1)).pymatgen_mol
match = re.search(r"\.(pdb|mol|mdl|sdf|sd|ml2|sy2|mol2|cml|mrv)", filename.lower())
if match:
new = BabelMolAdaptor.from_file(filename, match.group(1)).pymatgen_mol
new.__class__ = cls
return new
raise ValueError("Cannot determine file type.")
Expand Down
7 changes: 2 additions & 5 deletions pymatgen/io/cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,8 @@ def _sanitize_data(self, data):
data.data["_atom_site_fract_x"] += new_fract_x
data.data["_atom_site_fract_y"] += new_fract_y
data.data["_atom_site_fract_z"] += new_fract_z
"""
This fixes inconsistencies in naming of several magCIF tags
as a result of magCIF being in widespread use prior to
specification being finalized (on advice of Branton Campbell).
"""
# This fixes inconsistencies in naming of several magCIF tags as a result of magCIF
# being in widespread use prior to specification being finalized (on advice of Branton Campbell).
if self.feature_flags["magcif"]:
# CIF-1 style has all underscores, interim standard
# had period before magn instead of before the final
Expand Down

0 comments on commit dcea6b6

Please sign in to comment.