Skip to content

Commit d9f5705

Browse files
committed
ruff fix RUF031: Avoid parentheses for tuples in subscripts.
1 parent 545c20d commit d9f5705

25 files changed

+88
-90
lines changed

src/pymatgen/analysis/chemenv/connectivity/connected_components.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def draw_network(env_graph, pos, ax, sg=None, periodicity_vectors=None):
121121
xytext=xy_text_offset,
122122
textcoords="offset points",
123123
)
124-
seen[(u, v)] = rad
124+
seen[u, v] = rad
125125
ax.add_patch(e)
126126

127127

@@ -242,13 +242,13 @@ def __init__(
242242
edge_data = None
243243

244244
elif (env_node1, env_node2, key) in links_data:
245-
edge_data = links_data[(env_node1, env_node2, key)]
245+
edge_data = links_data[env_node1, env_node2, key]
246246
elif (env_node2, env_node1, key) in links_data:
247-
edge_data = links_data[(env_node2, env_node1, key)]
247+
edge_data = links_data[env_node2, env_node1, key]
248248
elif (env_node1, env_node2) in links_data:
249-
edge_data = links_data[(env_node1, env_node2)]
249+
edge_data = links_data[env_node1, env_node2]
250250
elif (env_node2, env_node1) in links_data:
251-
edge_data = links_data[(env_node2, env_node1)]
251+
edge_data = links_data[env_node2, env_node1]
252252
else:
253253
edge_data = None
254254

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,15 @@ def get_all_elementary_cycles(graph):
479479
index2edge = []
480480
edge_idx = 0
481481
for n1, n2 in graph.edges:
482-
all_edges_dict[(n1, n2)] = edge_idx
483-
all_edges_dict[(n2, n1)] = edge_idx
482+
all_edges_dict[n1, n2] = edge_idx
483+
all_edges_dict[n2, n1] = edge_idx
484484
index2edge.append((n1, n2))
485485
edge_idx += 1
486486
cycles_matrix = np.zeros(shape=(len(cycle_basis), edge_idx), dtype=bool)
487487
for icycle, cycle in enumerate(cycle_basis):
488488
for in1, n1 in enumerate(cycle, start=1):
489489
n2 = cycle[(in1) % len(cycle)]
490-
iedge = all_edges_dict[(n1, n2)]
490+
iedge = all_edges_dict[n1, n2]
491491
cycles_matrix[icycle, iedge] = True
492492

493493
elementary_cycles_list = []

src/pymatgen/analysis/diffraction/tem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ def get_positions(self, structure: Structure, points: list) -> dict[Tuple3Ints,
484484
points.remove((0, 0, 0))
485485
points.remove(first_point)
486486
points.remove(second_point)
487-
positions[(0, 0, 0)] = np.array([0, 0])
487+
positions[0, 0, 0] = np.array([0, 0])
488488
r1 = self.wavelength_rel() * self.camera_length / first_d
489489
positions[first_point] = np.array([r1, 0])
490490
r2 = self.wavelength_rel() * self.camera_length / second_d

src/pymatgen/analysis/disorder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def get_warren_cowley_parameters(structure: Structure, r: float, dr: float) -> d
2828
n_neighbors: defaultdict = defaultdict(int)
2929
for site in structure:
3030
for nn in structure.get_neighbors_in_shell(site.coords, r, dr):
31-
n_ij[(site.specie, nn.specie)] += 1
31+
n_ij[site.specie, nn.specie] += 1
3232
n_neighbors[site.specie] += 1
3333

3434
alpha_ij = {}
3535
for sp1, sp2 in itertools.product(comp, comp):
3636
pij = n_ij.get((sp1, sp2), 0) / n_neighbors[sp1]
3737
conc2 = comp.get_atomic_fraction(sp2)
38-
alpha_ij[(sp1, sp2)] = (pij - conc2) / ((1 if sp1 == sp2 else 0) - conc2)
38+
alpha_ij[sp1, sp2] = (pij - conc2) / ((1 if sp1 == sp2 else 0) - conc2)
3939

4040
return alpha_ij

src/pymatgen/analysis/eos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ def get_rms(x, y):
471471
if a * b < 0:
472472
rms = get_rms(energies, np.poly1d(coeffs)(volumes))
473473
rms_min = min(rms_min, rms * idx / n_data_fit)
474-
all_coeffs[(idx, n_data_fit)] = [coeffs.tolist(), rms]
474+
all_coeffs[idx, n_data_fit] = [coeffs.tolist(), rms]
475475
# store the fit coefficients small to large,
476476
# i.e a0, a1, .. an
477-
all_coeffs[(idx, n_data_fit)][0].reverse()
477+
all_coeffs[idx, n_data_fit][0].reverse()
478478
# remove 1 data point from each end.
479479
e_v_work.pop()
480480
e_v_work.pop(0)

src/pymatgen/analysis/graphs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ def map_indices(grp: Molecule) -> dict[int, int]:
717717

718718
if graph_dict is not None:
719719
for u, v in graph_dict:
720-
edge_props = graph_dict[(u, v)]
720+
edge_props = graph_dict[u, v]
721721
# default of (0, 0, 0) says that all edges should stay inside the initial image
722722
to_jimage = edge_props.get("to_jimage", (0, 0, 0))
723723
weight = edge_props.pop("weight", None)
@@ -2097,12 +2097,12 @@ def split_molecule_subgraphs(self, bonds, allow_reverse=False, alterations=None)
20972097
# alter any bonds before partition, to avoid remapping
20982098
if alterations is not None:
20992099
for u, v in alterations:
2100-
if "weight" in alterations[(u, v)]:
2101-
weight = alterations[(u, v)].pop("weight")
2102-
edge_properties = alterations[(u, v)] if len(alterations[(u, v)]) != 0 else None
2100+
if "weight" in alterations[u, v]:
2101+
weight = alterations[u, v].pop("weight")
2102+
edge_properties = alterations[u, v] if len(alterations[u, v]) != 0 else None
21032103
original.alter_edge(u, v, new_weight=weight, new_edge_properties=edge_properties)
21042104
else:
2105-
original.alter_edge(u, v, new_edge_properties=alterations[(u, v)])
2105+
original.alter_edge(u, v, new_edge_properties=alterations[u, v])
21062106

21072107
return original.get_disconnected_fragments()
21082108

@@ -2160,7 +2160,7 @@ def build_unique_fragments(self):
21602160
for from_index, to_index, key in remapped.edges:
21612161
edge_props = fragment.get_edge_data(from_index, to_index, key=key)
21622162

2163-
edges[(from_index, to_index)] = edge_props
2163+
edges[from_index, to_index] = edge_props
21642164

21652165
unique_mol_graph_list.append(
21662166
self.from_edges(
@@ -2261,7 +2261,7 @@ def map_indices(grp):
22612261

22622262
if graph_dict is not None:
22632263
for u, v in graph_dict:
2264-
edge_props = graph_dict[(u, v)]
2264+
edge_props = graph_dict[u, v]
22652265
weight = edge_props.pop("weight", None)
22662266
self.add_edge(
22672267
mapping[u],

src/pymatgen/analysis/local_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ def get_nn_info(self, structure: Structure, n: int):
12881288
for nn in structure.get_neighbors(site, max_rad):
12891289
dist = nn.nn_distance
12901290
# Confirm neighbor based on bond length specific to atom pair
1291-
if dist <= (bonds[(site.specie, nn.specie)]) and (nn.nn_distance > self.min_bond_distance):
1291+
if dist <= (bonds[site.specie, nn.specie]) and (nn.nn_distance > self.min_bond_distance):
12921292
weight = min_rad / dist
12931293
siw.append(
12941294
{

src/pymatgen/analysis/magnetism/heisenberg.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -886,27 +886,26 @@ def as_dict(self):
886886
def from_dict(cls, dct: dict) -> Self:
887887
"""Create a HeisenbergModel from a dict."""
888888
# Reconstitute the site ids
889-
usids = {}
890-
wids = {}
891-
nnis = {}
889+
unique_site_ids = {}
890+
wyckoff_ids = {}
891+
nn_interactions = {}
892892

893893
for k, v in dct["nn_interactions"].items():
894894
nn_dict = {}
895895
for k1, v1 in v.items():
896896
key = literal_eval(k1)
897897
nn_dict[key] = v1
898-
nnis[k] = nn_dict
898+
nn_interactions[k] = nn_dict
899899

900900
for k, v in dct["unique_site_ids"].items():
901901
key = literal_eval(k)
902902
if isinstance(key, int):
903-
usids[(key,)] = v
903+
unique_site_ids[key,] = v
904904
elif isinstance(key, tuple):
905-
usids[key] = v
905+
unique_site_ids[key] = v
906906

907907
for k, v in dct["wyckoff_ids"].items():
908-
key = literal_eval(k)
909-
wids[key] = v
908+
wyckoff_ids[literal_eval(k)] = v
910909

911910
# Reconstitute the structure and graph objects
912911
structures = []
@@ -933,9 +932,9 @@ def from_dict(cls, dct: dict) -> Self:
933932
cutoff=dct["cutoff"],
934933
tol=dct["tol"],
935934
sgraphs=sgraphs,
936-
unique_site_ids=usids,
937-
wyckoff_ids=wids,
938-
nn_interactions=nnis,
935+
unique_site_ids=unique_site_ids,
936+
wyckoff_ids=wyckoff_ids,
937+
nn_interactions=nn_interactions,
939938
dists=dct["dists"],
940939
ex_mat=ex_mat,
941940
ex_params=dct["ex_params"],
@@ -956,8 +955,7 @@ def _get_j_exc(self, i, j, dist):
956955
float: Exchange parameter J_exc in meV
957956
"""
958957
# Get unique site identifiers
959-
i_index = 0
960-
j_index = 0
958+
i_index = j_index = 0
961959
for k in self.unique_site_ids:
962960
if i in k:
963961
i_index = self.unique_site_ids[k]

src/pymatgen/analysis/phase_diagram.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,7 +3538,7 @@ def _get_matplotlib_2d_plot(
35383538
# whether an entry is a new compound or an existing (from the
35393539
# ICSD or from the MP) one.
35403540
for x, y in labels:
3541-
if labels[(x, y)].attribute is None or labels[(x, y)].attribute == "existing":
3541+
if labels[x, y].attribute is None or labels[x, y].attribute == "existing":
35423542
plt.plot(x, y, "ko", **self.plotkwargs)
35433543
else:
35443544
plt.plot(x, y, "k*", **self.plotkwargs)
@@ -3566,7 +3566,7 @@ def _get_matplotlib_2d_plot(
35663566
ii = 0
35673567
if process_attributes:
35683568
for x, y in labels:
3569-
if labels[(x, y)].attribute is None or labels[(x, y)].attribute == "existing":
3569+
if labels[x, y].attribute is None or labels[x, y].attribute == "existing":
35703570
plt.plot(x, y, "o", markerfacecolor=vals_stable[ii], markersize=12)
35713571
else:
35723572
plt.plot(x, y, "*", markerfacecolor=vals_stable[ii], markersize=18)

src/pymatgen/cli/pmg_structure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def analyze_localenv(args):
5656
for bond in args.localenv:
5757
tokens = bond.split("=")
5858
species = tokens[0].split("-")
59-
bonds[(species[0], species[1])] = float(tokens[1])
59+
bonds[species[0], species[1]] = float(tokens[1])
6060
for filename in args.filenames:
6161
print(f"Analyzing {filename}...")
6262
data = []

0 commit comments

Comments
 (0)