Skip to content

Commit dc6a292

Browse files
authored
Fix typo in Cp2kOutput.parse_hirshfeld add_site_property("hirshf[i->'']eld") (materialsproject#4055)
* fix typo in Cp2kOutput.parse_hirshfeld add_site_property("hirshf[i->'']eld") * fix Polarization doc str format * fix pwmat type hints: np.array->np.ndarray * rename single-letter index vars * fix doc str return type np.(''->nd)array * define successive immutable same-value vars on one line found with regex \w+ = (\w+)\n\s+\w+ = \1 more left
1 parent f6b4073 commit dc6a292

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+195
-284
lines changed

src/pymatgen/analysis/chemenv/coordination_environments/coordination_geometries.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,7 @@ def pauling_stability_ratio(self):
668668
if self.ce_symbol in ["S:1", "L:2"]:
669669
self._pauling_stability_ratio = 0.0
670670
else:
671-
min_dist_anions = 1_000_000
672-
min_dist_cation_anion = 1_000_000
671+
min_dist_anions = min_dist_cation_anion = 1_000_000
673672
for ipt1 in range(len(self.points)):
674673
pt1 = np.array(self.points[ipt1])
675674
min_dist_cation_anion = min(min_dist_cation_anion, np.linalg.norm(pt1 - self.central_site))

src/pymatgen/analysis/chemenv/utils/defs_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class AdditionalConditions:
5252
ONLY_ANION_CATION_BONDS_AND_NO_ELEMENT_TO_SAME_ELEMENT_BONDS = 3
5353
ONLY_ELEMENT_TO_OXYGEN_BONDS = 4
5454
# Short versions
55-
NONE = NO_ADDITIONAL_CONDITION
56-
NO_AC = NO_ADDITIONAL_CONDITION
55+
NONE = NO_AC = NO_ADDITIONAL_CONDITION
5756
ONLY_ACB = ONLY_ANION_CATION_BONDS
5857
NO_E2SEB = NO_ELEMENT_TO_SAME_ELEMENT_BONDS
5958
ONLY_ACB_AND_NO_E2SEB = ONLY_ANION_CATION_BONDS_AND_NO_ELEMENT_TO_SAME_ELEMENT_BONDS

src/pymatgen/analysis/chemenv/utils/scripts_utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ def compute_environments(chemenv_configuration):
358358
deltas = [np.zeros(3, float)]
359359
if first_time and StructureVis is not None:
360360
vis = StructureVis(show_polyhedron=False, show_unit_cell=True)
361-
vis.show_help = False
362-
first_time = False
361+
vis.show_help = first_time = False
363362
else:
364363
vis = None # TODO: following code logic seems buggy
365364

@@ -375,17 +374,17 @@ def compute_environments(chemenv_configuration):
375374
ce = strategy.get_site_coordination_environment(site)
376375
if ce is not None and ce[0] != UNCLEAR_ENVIRONMENT_SYMBOL:
377376
for delta in deltas:
378-
psite = PeriodicSite(
377+
p_site = PeriodicSite(
379378
site.species,
380379
site.frac_coords + delta,
381380
site.lattice,
382381
properties=site.properties,
383382
)
384-
vis.add_site(psite)
385-
neighbors = strategy.get_site_neighbors(psite)
383+
vis.add_site(p_site)
384+
neighbors = strategy.get_site_neighbors(p_site)
386385
draw_cg(
387386
vis,
388-
psite,
387+
p_site,
389388
neighbors,
390389
cg=lgf.allcg.get_geometry_from_mp_symbol(ce[0]),
391390
perm=ce[1]["permutation"],

src/pymatgen/analysis/chempot_diagram.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,9 @@ def get_centroid_2d(vertices: np.ndarray) -> np.ndarray:
670670
circumferentially
671671
672672
Returns:
673-
np.array: Giving 2-d centroid coordinates.
673+
np.ndarray: Giving 2-d centroid coordinates.
674674
"""
675-
cx = 0
676-
cy = 0
677-
a = 0
675+
cx = cy = a = 0
678676

679677
for idx in range(len(vertices) - 1):
680678
xi = vertices[idx, 0]

src/pymatgen/analysis/diffraction/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ def plot_structures(self, structures, fontsize=6, **kwargs):
188188
n_rows = len(structures)
189189
fig, axes = plt.subplots(nrows=n_rows, ncols=1, sharex=True, squeeze=False)
190190

191-
for i, (ax, structure) in enumerate(zip(axes.ravel(), structures, strict=True)):
192-
self.get_plot(structure, fontsize=fontsize, ax=ax, with_labels=i == n_rows - 1, **kwargs)
191+
for idx, (ax, structure) in enumerate(zip(axes.ravel(), structures, strict=True)):
192+
self.get_plot(structure, fontsize=fontsize, ax=ax, with_labels=idx == n_rows - 1, **kwargs)
193193
spg_symbol, spg_number = structure.get_space_group_info()
194194
ax.set_title(f"{structure.formula} {spg_symbol} ({spg_number}) ")
195195

@@ -207,7 +207,7 @@ def get_unique_families(hkls):
207207
{hkl: multiplicity}: A dict with unique hkl and multiplicity.
208208
"""
209209

210-
# TODO: Definitely can be sped up.
210+
# TODO can definitely be sped up
211211
def is_perm(hkl1, hkl2) -> bool:
212212
h1 = np.abs(hkl1)
213213
h2 = np.abs(hkl2)

src/pymatgen/analysis/ferroelectricity/polarization.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ def __init__(
147147
self, p_elecs, p_ions, structures: Sequence[Structure], p_elecs_in_cartesian=True, p_ions_in_cartesian=False
148148
):
149149
"""
150-
p_elecs: np.array of electronic contribution to the polarization with shape [N, 3]
151-
p_ions: np.array of ionic contribution to the polarization with shape [N, 3]
150+
p_elecs (np.ndarray): electronic contribution to the polarization with shape [N, 3]
151+
p_ions (np.ndarray): ionic contribution to the polarization with shape [N, 3]
152152
p_elecs_in_cartesian: whether p_elecs is along Cartesian directions (rather than lattice directions).
153153
Default is True because that is the convention for VASP.
154154
p_ions_in_cartesian: whether p_ions is along Cartesian directions (rather than lattice directions).
@@ -158,13 +158,14 @@ def __init__(
158158
if len(p_elecs) != len(p_ions) or len(p_elecs) != len(structures):
159159
raise ValueError("The number of electronic polarization and ionic polarization values must be equal.")
160160
if p_elecs_in_cartesian:
161-
p_elecs = np.array(
162-
[struct.lattice.get_vector_along_lattice_directions(p_elecs[i]) for i, struct in enumerate(structures)]
163-
)
161+
p_elecs = [
162+
struct.lattice.get_vector_along_lattice_directions(p_elecs[idx])
163+
for idx, struct in enumerate(structures)
164+
]
164165
if p_ions_in_cartesian:
165-
p_ions = np.array(
166-
[struct.lattice.get_vector_along_lattice_directions(p_ions[i]) for i, struct in enumerate(structures)]
167-
)
166+
p_ions = [
167+
struct.lattice.get_vector_along_lattice_directions(p_ions[idx]) for idx, struct in enumerate(structures)
168+
]
168169
self.p_elecs = np.array(p_elecs)
169170
self.p_ions = np.array(p_ions)
170171
self.structures = structures
@@ -392,9 +393,9 @@ def max_spline_jumps(self, convert_to_muC_per_cm2=True, all_in_polar=True):
392393
)
393394
sps = self.same_branch_splines(convert_to_muC_per_cm2=convert_to_muC_per_cm2, all_in_polar=all_in_polar)
394395
max_jumps = [None, None, None]
395-
for i, sp in enumerate(sps):
396+
for idx, sp in enumerate(sps):
396397
if sp is not None:
397-
max_jumps[i] = max(tot[:, i].ravel() - sp(range(len(tot[:, i].ravel()))))
398+
max_jumps[idx] = max(tot[:, idx].ravel() - sp(range(len(tot[:, idx].ravel()))))
398399
return max_jumps
399400

400401
def smoothness(self, convert_to_muC_per_cm2=True, all_in_polar=True):

src/pymatgen/analysis/hhi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def get_hhi(self, comp_or_form):
6363
if not isinstance(comp_or_form, Composition):
6464
comp_or_form = Composition(comp_or_form)
6565

66-
hhi_p = 0
67-
hhi_r = 0
66+
hhi_p = hhi_r = 0
6867

6968
for e in comp_or_form.elements:
7069
percent = comp_or_form.get_wt_fraction(e)

src/pymatgen/analysis/local_env.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,27 +1770,27 @@ def get_nn_info(self, structure: Structure, n: int):
17701770
except Exception:
17711771
eln = site.species_string
17721772

1773-
reldists_neighs = []
1773+
rel_dists_neighs = []
17741774
for nn in neighs_dists:
17751775
neigh = nn
17761776
dist = nn.nn_distance
17771777
try:
17781778
el2 = neigh.specie.element
17791779
except Exception:
17801780
el2 = neigh.species_string
1781-
reldists_neighs.append([dist / get_okeeffe_distance_prediction(eln, el2), neigh])
1781+
rel_dists_neighs.append([dist / get_okeeffe_distance_prediction(eln, el2), neigh])
17821782

17831783
siw = []
1784-
min_reldist = min(reldist for reldist, neigh in reldists_neighs)
1785-
for reldist, s in reldists_neighs:
1786-
if reldist < (1 + self.tol) * min_reldist:
1787-
w = min_reldist / reldist
1784+
min_rel_dist = min(reldist for reldist, neigh in rel_dists_neighs)
1785+
for rel_dist, site in rel_dists_neighs:
1786+
if rel_dist < (1 + self.tol) * min_rel_dist:
1787+
w = min_rel_dist / rel_dist
17881788
siw.append(
17891789
{
1790-
"site": s,
1791-
"image": self._get_image(structure, s),
1790+
"site": site,
1791+
"image": self._get_image(structure, site),
17921792
"weight": w,
1793-
"site_index": self._get_original_site(structure, s),
1793+
"site_index": self._get_original_site(structure, site),
17941794
}
17951795
)
17961796

@@ -2967,8 +2967,7 @@ def get_order_parameters(
29672967
twothird = 2 / 3.0
29682968
for j in range(n_neighbors): # Neighbor j is put to the North pole.
29692969
zaxis = rij_norm[j]
2970-
kc = 0
2971-
idx = 0
2970+
kc = idx = 0
29722971
for k in range(n_neighbors): # From neighbor k, we construct
29732972
if j != k: # the prime meridian.
29742973
for idx in range(len(self._types)):

src/pymatgen/analysis/magnetism/heisenberg.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,7 @@ def get_low_energy_orderings(self):
394394
fm_struct, afm_struct = None, None
395395
mag_min = np.inf
396396
mag_max = 0.001
397-
fm_e = 0
398-
afm_e = 0
399-
fm_e_min = 0
400-
afm_e_min = 0
397+
fm_e = afm_e = fm_e_min = afm_e_min = 0
401398

402399
# epas = [e / len(s) for (e, s) in zip(self.energies, self.ordered_structures)]
403400

@@ -589,8 +586,7 @@ def _get_j_exc(self, i, j, dist):
589586
float: Exchange parameter J_exc in meV
590587
"""
591588
# Get unique site identifiers
592-
i_index = 0
593-
j_index = 0
589+
i_index = j_index = 0
594590
for k, v in self.unique_site_ids.items():
595591
if i in k:
596592
i_index = v

src/pymatgen/analysis/phase_diagram.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ def as_dict(self) -> dict[str, Any]:
16731673
to a dictionary.
16741674
16751675
NOTE unlike PhaseDiagram the computation involved in constructing the
1676-
PatchedPhaseDiagram is not saved on serialisation. This is done because
1676+
PatchedPhaseDiagram is not saved on serialization. This is done because
16771677
hierarchically calling the `PhaseDiagram.as_dict()` method would break the
16781678
link in memory between entries in overlapping patches leading to a
16791679
ballooning of the amount of memory used.
@@ -1694,10 +1694,10 @@ def as_dict(self) -> dict[str, Any]:
16941694

16951695
@classmethod
16961696
def from_dict(cls, dct: dict) -> Self:
1697-
"""Reconstruct PatchedPhaseDiagram from dictionary serialisation.
1697+
"""Reconstruct PatchedPhaseDiagram from dictionary serialization.
16981698
16991699
NOTE unlike PhaseDiagram the computation involved in constructing the
1700-
PatchedPhaseDiagram is not saved on serialisation. This is done because
1700+
PatchedPhaseDiagram is not saved on serialization. This is done because
17011701
hierarchically calling the `PhaseDiagram.as_dict()` method would break the
17021702
link in memory between entries in overlapping patches leading to a
17031703
ballooning of the amount of memory used.
@@ -1725,8 +1725,8 @@ def remove_redundant_spaces(spaces, keep_all_spaces=False):
17251725
sorted_spaces = sorted(spaces, key=len, reverse=True)
17261726

17271727
result = []
1728-
for i, space_i in enumerate(sorted_spaces):
1729-
if not any(space_i.issubset(larger_space) for larger_space in sorted_spaces[:i]):
1728+
for idx, space_i in enumerate(sorted_spaces):
1729+
if not any(space_i.issubset(larger_space) for larger_space in sorted_spaces[:idx]):
17301730
result.append(space_i)
17311731

17321732
return result
@@ -2408,8 +2408,7 @@ class (pymatgen.analysis.chempot_diagram).
24082408

24092409
for entry, lines in chempot_ranges.items():
24102410
comp = entry.composition
2411-
center_x = 0
2412-
center_y = 0
2411+
center_x = center_y = 0
24132412
coords = []
24142413
contain_zero = any(comp.get_atomic_fraction(el) == 0 for el in elements)
24152414
is_boundary = (not contain_zero) and sum(comp.get_atomic_fraction(el) for el in elements) == 1

0 commit comments

Comments
 (0)