Skip to content

Commit 9122d21

Browse files
authored
ruff . --fix (#3176)
64 cases of RUF015 and PERF102
1 parent f9f2508 commit 9122d21

30 files changed

+67
-67
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ci:
88

99
repos:
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.0.278
11+
rev: v0.0.279
1212
hooks:
1313
- id: ruff
1414
args: [--fix]

pymatgen/analysis/adsorption.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def substitute(site, i):
558558
props = self.slab.site_properties
559559
if sub_both_sides:
560560
# Find an equivalent site on the other surface
561-
eq_indices = [indices for indices in sym_slab.equivalent_indices if i in indices][0]
561+
eq_indices = next(indices for indices in sym_slab.equivalent_indices if i in indices)
562562
for ii in eq_indices:
563563
if f"{sym_slab[ii].frac_coords[2]:.6f}" != f"{site.frac_coords[2]:.6f}":
564564
props["surface_properties"][ii] = "substitute"

pymatgen/analysis/chemenv/connectivity/connected_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ def elastic_centered_graph(self, start_node=None):
665665
# Loop on start_nodes, sometimes some nodes cannot be elastically taken
666666
# inside the cell if you start from a specific node
667667
ntest_nodes = 0
668-
start_node = list(self.graph.nodes())[0]
668+
start_node = next(iter(self.graph.nodes()))
669669

670670
ntest_nodes += 1
671671
centered_connected_subgraph = nx.MultiGraph()

pymatgen/analysis/chemenv/connectivity/tests/test_connected_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ def test_coordination_sequences(self):
872872
assert len(ccs_all) == 1
873873
cc_oct = ccs_oct[0]
874874
cc_all = ccs_all[0]
875-
cc_oct_node = list(cc_oct.graph.nodes())[0]
875+
cc_oct_node = next(iter(cc_oct.graph.nodes()))
876876
cseq = cc_oct.coordination_sequence(source_node=cc_oct_node, path_size=6)
877877
assert cseq == {1: 6, 2: 18, 3: 38, 4: 66, 5: 102, 6: 146}
878878
cc_all_oct_node = next(n for n in cc_all.graph.nodes() if n.coordination_environment == "O:6")

pymatgen/analysis/chemenv/utils/scripts_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def draw_cg(
123123
else:
124124
faces = cg.faces(neighbors)
125125
edges = cg.edges(neighbors)
126-
symbol = list(site.species)[0].symbol
126+
symbol = next(iter(site.species)).symbol
127127
if faces_color_override:
128128
mycolor = faces_color_override
129129
else:
@@ -233,7 +233,7 @@ def compute_environments(chemenv_configuration):
233233
source_type = questions[test]
234234
else:
235235
found = False
236-
source_type = list(questions.values())[0]
236+
source_type = next(iter(questions.values()))
237237
if found and len(questions) > 1:
238238
input_source = test
239239
if source_type == "cif":

pymatgen/analysis/dimensionality.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def get_structure_components(
129129
components = []
130130
for graph in comp_graphs:
131131
dimensionality, vertices = calculate_dimensionality_of_site(
132-
bonded_structure, list(graph.nodes())[0], inc_vertices=True
132+
bonded_structure, next(iter(graph.nodes())), inc_vertices=True
133133
)
134134

135135
component = {"dimensionality": dimensionality}
@@ -267,7 +267,7 @@ def zero_d_graph_to_molecule_graph(bonded_structure, graph):
267267
seen_indices = []
268268
sites = []
269269

270-
start_index = list(graph.nodes())[0]
270+
start_index = next(iter(graph.nodes()))
271271
queue = [(start_index, (0, 0, 0), bonded_structure.structure[start_index])]
272272
while len(queue) > 0:
273273
comp_i, image_i, site_i = queue.pop(0)

pymatgen/analysis/graphs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def add_edge(
401401

402402
# ensure that the first non-zero jimage index is positive
403403
# assumes that at least one non-zero index is present
404-
is_positive = [idx for idx in to_jimage if idx != 0][0] > 0
404+
is_positive = next(idx for idx in to_jimage if idx != 0) > 0
405405

406406
if not is_positive:
407407
# let's flip the jimage,

pymatgen/analysis/local_env.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,15 +1459,15 @@ def get_nn_info(self, structure: Structure, n: int):
14591459
siw = []
14601460

14611461
# Get only the atom of interest
1462-
site_atom = [
1462+
site_atom = next(
14631463
a
14641464
for i, a in enumerate(openbabel.OBMolAtomDFSIter(obmol))
14651465
if [a.GetX(), a.GetY(), a.GetZ()] == list(structure[n].coords)
1466-
][0]
1466+
)
14671467

14681468
for neighbor in openbabel.OBAtomAtomIter(site_atom):
14691469
coords = [neighbor.GetX(), neighbor.GetY(), neighbor.GetZ()]
1470-
site = [a for a in structure if list(a.coords) == coords][0]
1470+
site = next(a for a in structure if list(a.coords) == coords)
14711471
index = structure.index(site)
14721472

14731473
bond = site_atom.GetBond(neighbor)

pymatgen/analysis/structure_prediction/dopant_predictor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def get_dopants_from_substitution_probabilities(structure, num_dopants=5, thresh
4545
subs = [
4646
{
4747
"probability": pred["probability"],
48-
"dopant_species": list(pred["substitutions"])[0],
49-
"original_species": list(pred["substitutions"].values())[0],
48+
"dopant_species": next(iter(pred["substitutions"])),
49+
"original_species": next(iter(pred["substitutions"].values())),
5050
}
5151
for species_preds in subs
5252
for pred in species_preds

pymatgen/analysis/surface_analysis.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def __init__(
134134
self.label = label
135135
self.adsorbates = adsorbates if adsorbates else []
136136
self.clean_entry = clean_entry
137-
self.ads_entries_dict = {str(list(ads.composition.as_dict())[0]): ads for ads in self.adsorbates}
137+
self.ads_entries_dict = {str(next(iter(ads.composition.as_dict()))): ads for ads in self.adsorbates}
138138
self.mark = marker
139139
self.color = color
140140

@@ -199,14 +199,14 @@ def surface_energy(self, ucell_entry, ref_entries=None):
199199
ucell_entry_comp = ucell_entry.composition.reduced_composition.as_dict()
200200
slab_clean_comp = Composition({el: slab_comp[el] for el in ucell_entry_comp})
201201
if slab_clean_comp.reduced_composition != ucell_entry.composition.reduced_composition:
202-
list_els = [list(entry.composition.as_dict())[0] for entry in ref_entries]
202+
list_els = [next(iter(entry.composition.as_dict())) for entry in ref_entries]
203203
if not any(el in list_els for el in ucell_entry.composition.as_dict()):
204204
warnings.warn("Elemental references missing for the non-dopant species.")
205205

206206
gamma = (Symbol("E_surf") - Symbol("Ebulk")) / (2 * Symbol("A"))
207207
ucell_comp = ucell_entry.composition
208208
ucell_reduced_comp = ucell_comp.reduced_composition
209-
ref_entries_dict = {str(list(ref.composition.as_dict())[0]): ref for ref in ref_entries}
209+
ref_entries_dict = {str(next(iter(ref.composition.as_dict()))): ref for ref in ref_entries}
210210
ref_entries_dict.update(self.ads_entries_dict)
211211

212212
# Calculate Gibbs free energy of the bulk per unit formula
@@ -613,7 +613,7 @@ def area_frac_vs_chempot_plot(
613613
axes = plt.gca()
614614

615615
for hkl in self.all_slab_entries:
616-
clean_entry = list(self.all_slab_entries[hkl])[0]
616+
clean_entry = next(iter(self.all_slab_entries[hkl]))
617617
# Ignore any facets that never show up on the
618618
# Wulff shape regardless of chemical potential
619619
if all(a == 0 for a in hkl_area_dict[hkl]):

0 commit comments

Comments
 (0)