Skip to content

Commit 9458db0

Browse files
committed
str refactors
1 parent a77c088 commit 9458db0

File tree

6 files changed

+44
-44
lines changed

6 files changed

+44
-44
lines changed

pymatgen/analysis/chemenv/connectivity/connected_components.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ def elastic_centered_graph(self, start_node=None):
751751
)
752752
logging.debug(
753753
f" Delta image from node {str(node)} to neighbor {str(node_neighbor)} : "
754-
f"({', '.join([str(iii) for iii in myddelta])})"
754+
f"({', '.join(map(str, myddelta))})"
755755
)
756756
# Loop on the edges of this neighbor
757757
for n1, n2, key, edata in node_neighbor_edges:
@@ -905,13 +905,14 @@ def from_graph(cls, g):
905905
def description(self, full=False):
906906
"""
907907
Args:
908-
full ():
908+
full (bool): Whether to return a short or full description.
909909
910910
Returns:
911+
str: A description of the connected component.
911912
"""
912913
out = ["Connected component with environment nodes :"]
913914
if not full:
914-
out.extend([str(en) for en in sorted(self.graph.nodes())])
915+
out.extend(map(str, sorted(self.graph.nodes())))
915916
return "\n".join(out)
916917
for en in sorted(self.graph.nodes()):
917918
out.append(f"{en}, connected to :")

pymatgen/analysis/diffraction/core.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def get_plot(
119119
for two_theta, i, hkls in zip(xrd.x, xrd.y, xrd.hkls):
120120
if two_theta_range[0] <= two_theta <= two_theta_range[1]:
121121
hkl_tuples = [hkl["hkl"] for hkl in hkls]
122-
label = ", ".join([str(hkl_tuple) for hkl_tuple in hkl_tuples]) # 'full' label
122+
label = ", ".join(map(str, hkl_tuples)) # 'full' label
123123
ax.plot([two_theta, two_theta], [0, i], color="k", linewidth=3, label=label)
124124

125125
if annotate_peaks == "full":
@@ -131,7 +131,7 @@ def get_plot(
131131
)
132132
elif annotate_peaks == "compact":
133133
if all(all(i < 10 for i in hkl_tuple) for hkl_tuple in hkl_tuples):
134-
label = ",".join(["".join([str(i) for i in hkl_tuple]) for hkl_tuple in hkl_tuples])
134+
label = ",".join(["".join(map(str, hkl_tuple)) for hkl_tuple in hkl_tuples])
135135
# 'compact' label. Would be unclear for indices >= 10
136136
# It would have more than 3 figures, e.g. 1031
137137

@@ -222,7 +222,6 @@ def get_unique_families(hkls):
222222
Returns:
223223
{hkl: multiplicity}: A dict with unique hkl and multiplicity.
224224
"""
225-
226225
# TODO: Definitely can be sped up.
227226
def is_perm(hkl1, hkl2):
228227
h1 = np.abs(hkl1)

pymatgen/analysis/structure_analyzer.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ def connectivity_array(self):
274274
Provides connectivity array.
275275
276276
Returns:
277-
connectivity: An array of shape [atomi, atomj, imagej]. atomi is
277+
connectivity: An array of shape [atom_i, atom_j, image_j]. atom_i is
278278
the index of the atom in the input structure. Since the second
279279
atom can be outside of the unit cell, it must be described
280280
by both an atom index and an image index. Array data is the
281-
solid angle of polygon between atomi and imagej of atomj
281+
solid angle of polygon between atom_i and image_j of atom_j
282282
"""
283283
# shape = [site, axis]
284284
cart_coords = np.array(self.s.cart_coords)
@@ -290,24 +290,24 @@ def connectivity_array(self):
290290
connectivity = np.zeros(cs)
291291
vts = np.array(vt.vertices)
292292
for (ki, kj), v in vt.ridge_dict.items():
293-
atomi = ki // n_images
294-
atomj = kj // n_images
293+
atom_i = ki // n_images
294+
atom_j = kj // n_images
295295

296-
imagei = ki % n_images
297-
imagej = kj % n_images
296+
image_i = ki % n_images
297+
image_j = kj % n_images
298298

299-
if imagei != n_images // 2 and imagej != n_images // 2:
299+
if image_i != n_images // 2 and image_j != n_images // 2:
300300
continue
301301

302-
if imagei == n_images // 2:
303-
# atomi is in original cell
302+
if image_i == n_images // 2:
303+
# atom_i is in original cell
304304
val = solid_angle(vt.points[ki], vts[v])
305-
connectivity[atomi, atomj, imagej] = val
305+
connectivity[atom_i, atom_j, image_j] = val
306306

307-
if imagej == n_images // 2:
308-
# atomj is in original cell
307+
if image_j == n_images // 2:
308+
# atom_j is in original cell
309309
val = solid_angle(vt.points[kj], vts[v])
310-
connectivity[atomj, atomi, imagei] = val
310+
connectivity[atom_j, atom_i, image_i] = val
311311

312312
if -10.101 in vts[v]:
313313
warn("Found connectivity with infinite vertex. Cutoff is too low, and results may be incorrect")
@@ -327,10 +327,10 @@ def get_connections(self):
327327
with their real-space distances.
328328
"""
329329
con = []
330-
maxconn = self.max_connectivity
331-
for ii in range(0, maxconn.shape[0]):
332-
for jj in range(0, maxconn.shape[1]):
333-
if maxconn[ii][jj] != 0:
330+
max_conn = self.max_connectivity
331+
for ii in range(0, max_conn.shape[0]):
332+
for jj in range(0, max_conn.shape[1]):
333+
if max_conn[ii][jj] != 0:
334334
dist = self.s.get_distance(ii, jj)
335335
con.append([ii, jj, dist])
336336
return con
@@ -383,7 +383,7 @@ def get_max_bond_lengths(structure, el_radius_updates=None):
383383
384384
Args:
385385
structure: (structure)
386-
el_radius_updates: (dict) symbol->float to update atomic radii
386+
el_radius_updates: (dict) symbol->float to update atom_ic radii
387387
388388
Returns: (dict) - (Element1, Element2) -> float. The two elements are
389389
ordered by Z.
@@ -488,9 +488,9 @@ def parse_oxide(self) -> tuple[str, int]:
488488
is_superoxide = False
489489
is_ozonide = True
490490
try:
491-
nbonds = len(set(bond_atoms))
491+
n_bonds = len(set(bond_atoms))
492492
except UnboundLocalError:
493-
nbonds = 0
493+
n_bonds = 0
494494
if is_ozonide:
495495
str_oxide = "ozonide"
496496
elif is_superoxide:
@@ -500,8 +500,8 @@ def parse_oxide(self) -> tuple[str, int]:
500500
else:
501501
str_oxide = "oxide"
502502
if str_oxide == "oxide":
503-
nbonds = int(comp["O"])
504-
return str_oxide, nbonds
503+
n_bonds = int(comp["O"])
504+
return str_oxide, n_bonds
505505

506506

507507
def oxide_type(

pymatgen/core/trajectory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def write_Xdatcar(
364364
syms = [site.specie.symbol for site in self[0]]
365365
site_symbols = [a[0] for a in itertools.groupby(syms)]
366366
syms = [site.specie.symbol for site in self[0]]
367-
natoms = [len(tuple(a[1])) for a in itertools.groupby(syms)]
367+
n_atoms = [len(tuple(a[1])) for a in itertools.groupby(syms)]
368368

369369
for si, frac_coords in enumerate(self.frac_coords):
370370
# Only print out the info block if
@@ -377,10 +377,10 @@ def write_Xdatcar(
377377
_lattice = self.lattice[si]
378378

379379
for latt_vec in _lattice:
380-
lines.append(f'{" ".join([str(el) for el in latt_vec])}')
380+
lines.append(f'{" ".join(map(str, latt_vec))}')
381381

382382
lines.append(" ".join(site_symbols))
383-
lines.append(" ".join([str(x) for x in natoms]))
383+
lines.append(" ".join(map(str, n_atoms)))
384384

385385
lines.append(f"Direct configuration= {si + 1}")
386386

pymatgen/io/vasp/inputs.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def get_string(self, direct: bool = True, vasp4_compatible: bool = False, signif
483483

484484
if self.true_names and not vasp4_compatible:
485485
lines.append(" ".join(self.site_symbols))
486-
lines.append(" ".join([str(x) for x in self.natoms]))
486+
lines.append(" ".join(map(str, self.natoms)))
487487
if self.selective_dynamics:
488488
lines.append("Selective dynamics")
489489
lines.append("direct" if direct else "cartesian")
@@ -721,7 +721,7 @@ def get_string(self, sort_keys: bool = False, pretty: bool = False) -> str:
721721

722722
lines.append([k, " ".join(value)])
723723
elif isinstance(self[k], list):
724-
lines.append([k, " ".join([str(i) for i in self[k]])])
724+
lines.append([k, " ".join(map(str, self[k]))])
725725
else:
726726
lines.append([k, self[k]])
727727

@@ -1512,17 +1512,17 @@ def __str__(self):
15121512
style = self.style.name.lower()[0]
15131513
if style == "l":
15141514
lines.append(self.coord_type)
1515-
for i in range(len(self.kpts)):
1516-
lines.append(" ".join([str(x) for x in self.kpts[i]]))
1515+
for idx, kpt in enumerate(self.kpts):
1516+
lines.append(" ".join(map(str, kpt)))
15171517
if style == "l":
1518-
lines[-1] += " ! " + self.labels[i]
1519-
if i % 2 == 1:
1518+
lines[-1] += " ! " + self.labels[idx]
1519+
if idx % 2 == 1:
15201520
lines[-1] += "\n"
15211521
elif self.num_kpts > 0:
15221522
if self.labels is not None:
1523-
lines[-1] += f" {int(self.kpts_weights[i])} {self.labels[i]}"
1523+
lines[-1] += f" {int(self.kpts_weights[idx])} {self.labels[idx]}"
15241524
else:
1525-
lines[-1] += f" {int(self.kpts_weights[i])}"
1525+
lines[-1] += f" {int(self.kpts_weights[idx])}"
15261526

15271527
# Print tetrahedron parameters if the number of tetrahedrons > 0
15281528
if style not in "lagm" and self.tet_number > 0:
@@ -1534,7 +1534,7 @@ def __str__(self):
15341534

15351535
# Print shifts for automatic kpoints types if not zero.
15361536
if self.num_kpts <= 0 and tuple(self.kpts_shift) != (0, 0, 0):
1537-
lines.append(" ".join([str(x) for x in self.kpts_shift]))
1537+
lines.append(" ".join(map(str, self.kpts_shift)))
15381538
return "\n".join(lines) + "\n"
15391539

15401540
def as_dict(self):

pymatgen/symmetry/tests/test_maggroups.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_is_compatible(self):
7575

7676
def test_symmetry_ops(self):
7777

78-
msg_1_symmops = "\n".join([str(op) for op in self.msg_1.symmetry_ops])
78+
msg_1_symmops = "\n".join(map(str, self.msg_1.symmetry_ops))
7979
msg_1_symmops_ref = """x, y, z, +1
8080
-x+3/4, -y+3/4, z, +1
8181
-x, -y, -z, +1
@@ -110,7 +110,7 @@ def test_symmetry_ops(self):
110110
x+3/4, -y+1/2, z+1/4, -1"""
111111
self.assertStrContentEqual(msg_1_symmops, msg_1_symmops_ref)
112112

113-
msg_2_symmops = "\n".join([str(op) for op in self.msg_2.symmetry_ops])
113+
msg_2_symmops = "\n".join(map(str, self.msg_2.symmetry_ops))
114114
msg_2_symmops_ref = """x, y, z, +1
115115
-x, y+1/2, -z, +1
116116
-x, -y, -z, +1
@@ -121,7 +121,7 @@ def test_symmetry_ops(self):
121121
x+1/2, y, -z+1/2, -1"""
122122
self.assertStrContentEqual(msg_2_symmops, msg_2_symmops_ref)
123123

124-
msg_3_symmops = "\n".join([str(op) for op in self.msg_3.symmetry_ops])
124+
msg_3_symmops = "\n".join(map(str, self.msg_3.symmetry_ops))
125125
msg_3_symmops_ref = """x, y, z, +1
126126
x, -y, -z, +1
127127
-x, y, -z+1/2, +1
@@ -140,7 +140,7 @@ def test_symmetry_ops(self):
140140
-x, -y+1/2, z, -1"""
141141
assert msg_3_symmops == msg_3_symmops_ref
142142

143-
msg_4_symmops = "\n".join([str(op) for op in self.msg_4.symmetry_ops])
143+
msg_4_symmops = "\n".join(map(str, self.msg_4.symmetry_ops))
144144
msg_4_symmops_ref = """x, y, z, +1
145145
-x, -y, -z, +1
146146
x+1/2, y, z, -1

0 commit comments

Comments
 (0)