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

+1-2
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

+1-2
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

+5-6
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

+2-4
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

+3-3
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

+11-10
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

+1-2
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

+10-11
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

+2-6
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

+6-7
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

src/pymatgen/analysis/piezo_sensitivity.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,7 @@ def get_unstable_FCM(self, max_force=1):
360360
n_sites = len(struct)
361361
D = (1 / max_force) * 2 * (np.ones([n_sites * 3, n_sites * 3]))
362362
for op in operations:
363-
same = 0
364-
transpose = 0
363+
same = transpose = 0
365364
if op[0] == op[1] and op[0] == op[2] and op[0] == op[3]:
366365
same = 1
367366
if op[0] == op[3] and op[1] == op[2]:
@@ -413,8 +412,7 @@ def get_symmetrized_FCM(self, unsymmetrized_fcm, max_force=1):
413412
"""
414413
operations = self.FCM_operations
415414
for op in operations:
416-
same = 0
417-
transpose = 0
415+
same = transpose = 0
418416
if op[0] == op[1] and op[0] == operations[2] and op[0] == op[3]:
419417
same = 1
420418
if op[0] == op[3] and op[1] == op[2]:
@@ -423,10 +421,10 @@ def get_symmetrized_FCM(self, unsymmetrized_fcm, max_force=1):
423421
unsymmetrized_fcm[3 * op[0] : 3 * op[0] + 3, 3 * op[1] : 3 * op[1] + 3] = np.zeros([3, 3])
424422

425423
for symop in op[4]:
426-
tempfcm = unsymmetrized_fcm[3 * op[2] : 3 * op[2] + 3, 3 * op[3] : 3 * op[3] + 3]
427-
tempfcm = symop.transform_tensor(tempfcm)
424+
temp_fcm = unsymmetrized_fcm[3 * op[2] : 3 * op[2] + 3, 3 * op[3] : 3 * op[3] + 3]
425+
temp_fcm = symop.transform_tensor(temp_fcm)
428426

429-
unsymmetrized_fcm[3 * op[0] : 3 * op[0] + 3, 3 * op[1] : 3 * op[1] + 3] += tempfcm
427+
unsymmetrized_fcm[3 * op[0] : 3 * op[0] + 3, 3 * op[1] : 3 * op[1] + 3] += temp_fcm
430428

431429
if len(op[4]) != 0:
432430
unsymmetrized_fcm[3 * op[0] : 3 * op[0] + 3, 3 * op[1] : 3 * op[1] + 3] /= len(op[4])
@@ -468,8 +466,7 @@ def get_stable_FCM(self, fcm, fcmasum=10):
468466
Returns:
469467
3Nx3N numpy array representing the force constant matrix
470468
"""
471-
check = 0
472-
count = 0
469+
check = count = 0
473470
while check == 0:
474471
# if re-symmetrizing brings back unstable modes 20 times, the method breaks
475472
if count > 20:
@@ -535,8 +532,7 @@ def get_asum_FCM(self, fcm: np.ndarray, numiter: int = 15):
535532

536533
total /= n_sites
537534
for op in operations:
538-
same = 0
539-
transpose = 0
535+
same = transpose = 0
540536
if op[0] == op[1] and op[0] == op[2] and op[0] == op[3]:
541537
same = 1
542538
if op[0] == op[3] and op[1] == op[2]:

src/pymatgen/analysis/quasirrho.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ def _get_quasirrho_thermo(
226226
er = 3 * ideal_gas_const * self.temp / 2
227227

228228
# Vibrational component of Entropy and Energy
229-
ev = 0
230-
sv_quasiRRHO = 0
231-
sv = 0
229+
ev = sv_quasiRRHO = sv = 0
232230

233231
for vt in vib_temps:
234232
ev += vt * (1 / 2 + 1 / (np.exp(vt / self.temp) - 1))

src/pymatgen/analysis/solar/slme.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def to_matrix(xx, yy, zz, xy, yz, xz):
6464
xz (float): xz component of the matrix.
6565
6666
Returns:
67-
np.array: The matrix, as a 3x3 numpy array.
67+
np.ndarray: The matrix, as a 3x3 numpy array.
6868
"""
6969
return np.array([[xx, xy, xz], [xy, yy, yz], [xz, yz, zz]])
7070

@@ -79,7 +79,7 @@ def parse_dielectric_data(data):
7979
a list of ``[xx, yy, zz, xy , xz, yz ]`` dielectric tensor elements.
8080
8181
Returns:
82-
np.array: a Nx3 numpy array. Each row contains the eigenvalues
82+
np.ndarray: a Nx3 numpy array. Each row contains the eigenvalues
8383
for the corresponding row in `data`.
8484
"""
8585
return np.array([np.linalg.eig(to_matrix(*eps))[0] for eps in data])
@@ -98,7 +98,7 @@ def absorption_coefficient(dielectric):
9898
- element 2: imaginary dielectric tensors, in ``[xx, yy, zz, xy, xz, yz]`` format.
9999
100100
Returns:
101-
np.array: absorption coefficient using eV as frequency units (cm^-1).
101+
np.ndarray: absorption coefficient using eV as frequency units (cm^-1).
102102
"""
103103
energies_in_eV = np.array(dielectric[0])
104104
real_dielectric = parse_dielectric_data(dielectric[1])

src/pymatgen/analysis/structure_analyzer.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,7 @@ def parse_oxide(self) -> tuple[str, int]:
457457
return "hydroxide", int(len(np.where(dist_matrix < relative_cutoff * 0.93)[0]) / 2)
458458
dist_matrix = lattice.get_all_distances(o_sites_frac_coords, o_sites_frac_coords)
459459
np.fill_diagonal(dist_matrix, 1000)
460-
is_superoxide = False
461-
is_peroxide = False
462-
is_ozonide = False
460+
is_superoxide = is_peroxide = is_ozonide = False
463461
bond_atoms = []
464462
if np.any(dist_matrix < relative_cutoff * 1.35):
465463
bond_atoms = np.where(dist_matrix < relative_cutoff * 1.35)[0]

src/pymatgen/analysis/structure_prediction/volume_predictor.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ def predict(self, structure: Structure, ref_structure):
8282
):
8383
raise ValueError("Not all the ionic radii are available!")
8484

85-
numerator = 0
86-
denominator = 0
85+
numerator = denominator = 0
8786
# Here, the 1/3 factor on the composition accounts for atomic
8887
# packing. We want the number per unit length.
8988
for k, v in comp.items():
@@ -102,8 +101,7 @@ def predict(self, structure: Structure, ref_structure):
102101
ref_comp = ref_structure.composition
103102
# Here, the 1/3 factor on the composition accounts for atomic
104103
# packing. We want the number per unit length.
105-
numerator = 0
106-
denominator = 0
104+
numerator = denominator = 0
107105
for k, v in comp.items():
108106
numerator += k.atomic_radius * v ** (1 / 3)
109107
for k, v in ref_comp.items():

0 commit comments

Comments
 (0)