Skip to content

Commit f6b4073

Browse files
authored
Fix ruff PLC0206 and PLR6104 (materialsproject#4035)
* fix ruff PLC0206 * fix/ignore ruff PLR6104 * simplify np.prod(arr.shape) -> arr.size * add missing args to get_partial_doses doc str * fix ruff N818 Exception name `SymmetryUndetermined` should be named with an Error suffix * fix TestGruneisenParameter.test_average_gruneisen def test_average_gruneisen(self): assert self.gruneisen_obj.average_gruneisen() == approx(1.164231026696211) > assert self.gruneisen_obj.average_gruneisen(squared=False) == approx(0.849759667411049) E assert 1.3554338835221134 == 0.849759667411049 ± 8.5e-07 E E comparison failed E Obtained: 1.3554338835221134 E Expected: 0.849759667411049 ± 8.5e-07 * auto-format .github/workflows/issue-metrics.yml * rename index variables
1 parent 13182c5 commit f6b4073

Some content is hidden

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

64 files changed

+383
-391
lines changed

.github/workflows/issue-metrics.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Monthly issue metrics
22
on:
33
workflow_dispatch:
44
schedule:
5-
- cron: '3 2 1 * *'
5+
- cron: "3 2 1 * *" # Run at 2:03am on the first of every month
66

77
permissions:
88
contents: read
@@ -17,28 +17,28 @@ jobs:
1717
issues: write
1818
pull-requests: read
1919
steps:
20-
- name: Get dates for last month
21-
shell: bash
22-
run: |
23-
# Calculate the first day of the previous month
24-
first_day=$(date -d "last month" +%Y-%m-01)
20+
- name: Get dates for last month
21+
shell: bash
22+
run: |
23+
# Calculate the first day of the previous month
24+
first_day=$(date -d "last month" +%Y-%m-01)
2525
26-
# Calculate the last day of the previous month
27-
last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d)
26+
# Calculate the last day of the previous month
27+
last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d)
2828
29-
#Set an environment variable with the date range
30-
echo "$first_day..$last_day"
31-
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
29+
#Set an environment variable with the date range
30+
echo "$first_day..$last_day"
31+
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
3232
33-
- name: Run issue-metrics tool
34-
uses: github/issue-metrics@v3
35-
env:
36-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37-
SEARCH_QUERY: 'repo:materialsproject/pymatgen is:issue created:${{ env.last_month }} -reason:"not planned"'
33+
- name: Run issue-metrics tool
34+
uses: github/issue-metrics@v3
35+
env:
36+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
SEARCH_QUERY: 'repo:materialsproject/pymatgen is:issue created:${{ env.last_month }} -reason:"not planned"'
3838

39-
- name: Create issue
40-
uses: peter-evans/create-issue-from-file@v5
41-
with:
42-
title: Monthly issue metrics report
43-
token: ${{ secrets.GITHUB_TOKEN }}
44-
content-filepath: ./issue_metrics.md
39+
- name: Create issue
40+
uses: peter-evans/create-issue-from-file@v5
41+
with:
42+
title: Monthly issue metrics report
43+
token: ${{ secrets.GITHUB_TOKEN }}
44+
content-filepath: ./issue_metrics.md

dev_scripts/chemenv/strategies/multi_weights_strategy_parameters.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def simple_expansion(
6565
CoordinationEnvironmentMorphing
6666
"""
6767
morphing_description = [
68-
{"ineighbor": i_nb, "site_type": "neighbor", "expansion_origin": "central_site"}
69-
for i_nb in neighbors_indices
68+
{"ineighbor": nbr_idx, "site_type": "neighbor", "expansion_origin": "central_site"}
69+
for nbr_idx in neighbors_indices
7070
]
7171
return cls(
7272
initial_environment_symbol=initial_environment_symbol,
@@ -158,11 +158,11 @@ def get_structure(self, morphing_factor):
158158
if morphing["site_type"] != "neighbor":
159159
raise ValueError(f"Key \"site_type\" is {morphing['site_type']} while it can only be neighbor")
160160

161-
i_site = morphing["ineighbor"] + 1
161+
site_idx = morphing["ineighbor"] + 1
162162
if morphing["expansion_origin"] == "central_site":
163163
origin = bare_points[0]
164-
vector = bare_points[i_site] - origin
165-
coords[i_site] += vector * (morphing_factor - 1.0)
164+
vector = bare_points[site_idx] - origin
165+
coords[site_idx] += vector * (morphing_factor - 1.0)
166166

167167
return Structure(lattice=lattice, species=species, coords=coords, coords_are_cartesian=True)
168168

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def make_supergraph(graph, multiplicity, periodicity_vectors):
142142
if isinstance(multiplicity, int) or len(multiplicity) == 1:
143143
mult = multiplicity if isinstance(multiplicity, int) else multiplicity[0]
144144
nodes = graph.nodes(data=True)
145-
inodes = [isite for isite, data in nodes]
146-
indices_nodes = {isite: inodes.index(isite) for isite in inodes}
145+
node_indices = [idx for idx, data in nodes]
146+
indices_nodes = {idx: node_indices.index(idx) for idx in node_indices}
147147
edges = graph.edges(data=True, keys=True)
148148
connecting_edges = []
149149
other_edges = []

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,24 @@ def get_structure_connectivity(self, light_structure_environments):
4646
logging.info("Setup of structure connectivity graph")
4747
structure_connectivity = StructureConnectivity(light_structure_environments)
4848
structure_connectivity.add_sites()
49-
for isite, _site in enumerate(light_structure_environments.structure):
50-
site_neighbors_sets = light_structure_environments.neighbors_sets[isite]
49+
for site_idx, _site in enumerate(light_structure_environments.structure):
50+
site_neighbors_sets = light_structure_environments.neighbors_sets[site_idx]
5151
if site_neighbors_sets is None:
5252
continue
5353
if len(site_neighbors_sets) > 1:
5454
if self.multiple_environments_choice is None:
55-
raise ValueError(f"Local environment of site {isite} is a mix and nothing is asked about it")
55+
raise ValueError(f"Local environment of site {site_idx} is a mix and nothing is asked about it")
5656
if self.multiple_environments_choice == "TAKE_HIGHEST_FRACTION":
57-
imax = np.argmax(
58-
[ee["ce_fraction"] for ee in light_structure_environments.coordination_environments[isite]]
57+
idx_max = np.argmax(
58+
[ee["ce_fraction"] for ee in light_structure_environments.coordination_environments[site_idx]]
5959
)
60-
print(f"IMAX {imax}")
61-
site_neighbors_set = site_neighbors_sets[imax]
60+
print(f"IMAX {idx_max}")
61+
site_neighbors_set = site_neighbors_sets[idx_max]
6262
else:
6363
raise RuntimeError("Should not be here")
6464
else:
6565
site_neighbors_set = site_neighbors_sets[0]
66-
structure_connectivity.add_bonds(isite, site_neighbors_set)
66+
structure_connectivity.add_bonds(site_idx, site_neighbors_set)
6767
return structure_connectivity
6868

6969
def setup_parameters(self, multiple_environments_choice):

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ def add_bonds(self, isite, site_neighbors_set):
114114
exists = True
115115
break
116116
elif isite == nb_index_unitcell:
117-
for isite1, ineighb1, data1 in existing_edges:
118-
if isite1 == ineighb1 and (
117+
for site_idx1, ineighb1, data1 in existing_edges:
118+
if site_idx1 == ineighb1 and (
119119
np.allclose(data1["delta"], nb_image_cell) or np.allclose(data1["delta"], -nb_image_cell)
120120
):
121121
exists = True
@@ -164,7 +164,7 @@ def setup_environment_subgraph(self, environments_symbols, only_atoms=None):
164164
# Initialize graph for a subset of environments
165165
self._environment_subgraph = nx.MultiGraph()
166166
# Add the sites with the required environment(s)
167-
for isite, ce_this_site_all in enumerate(self.light_structure_environments.coordination_environments):
167+
for site_idx, ce_this_site_all in enumerate(self.light_structure_environments.coordination_environments):
168168
if ce_this_site_all is None:
169169
continue
170170
if len(ce_this_site_all) == 0:
@@ -173,30 +173,30 @@ def setup_environment_subgraph(self, environments_symbols, only_atoms=None):
173173
if ce_this_site in environments_symbols:
174174
if only_atoms is None:
175175
env_node = get_environment_node(
176-
self.light_structure_environments.structure[isite],
177-
isite,
176+
self.light_structure_environments.structure[site_idx],
177+
site_idx,
178178
ce_this_site,
179179
)
180180
self._environment_subgraph.add_node(env_node)
181181
elif self.light_structure_environments.structure.is_ordered:
182-
if self.light_structure_environments.structure[isite].specie.symbol in only_atoms:
182+
if self.light_structure_environments.structure[site_idx].specie.symbol in only_atoms:
183183
env_node = get_environment_node(
184-
self.light_structure_environments.structure[isite],
185-
isite,
184+
self.light_structure_environments.structure[site_idx],
185+
site_idx,
186186
ce_this_site,
187187
)
188188
self._environment_subgraph.add_node(env_node)
189189
else:
190190
# TODO add the possibility of a "constraint" on the minimum percentage
191191
# of the atoms on the site
192192
this_site_elements = [
193-
sp.symbol for sp in self.light_structure_environments.structure[isite].species_and_occu
193+
sp.symbol for sp in self.light_structure_environments.structure[site_idx].species_and_occu
194194
]
195195
for elem_symbol in this_site_elements:
196196
if elem_symbol in only_atoms:
197197
env_node = get_environment_node(
198-
self.light_structure_environments.structure[isite],
199-
isite,
198+
self.light_structure_environments.structure[site_idx],
199+
site_idx,
200200
ce_this_site,
201201
)
202202
self._environment_subgraph.add_node(env_node)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ def equivalent_site_index_and_transform(self, psite):
262262
uc_psite = psite.to_unit_cell()
263263
site_idx = self.structure_environments.structure.index(uc_psite)
264264
except ValueError:
265-
for isite2, site2 in enumerate(self.structure_environments.structure):
265+
for site_idx2, site2 in enumerate(self.structure_environments.structure):
266266
if psite.is_periodic_image(site2):
267-
site_idx = isite2
267+
site_idx = site_idx2
268268
break
269269
# Get the translation between psite and its corresponding site in the unit cell (Translation I)
270270
this_site = self.structure_environments.structure[site_idx]

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def compute_structure_environments(
677677
]
678678

679679
if only_indices is not None:
680-
sites_indices = [isite for isite in indices if isite in only_indices]
680+
sites_indices = [*set(indices) & set(only_indices)]
681681

682682
# Get the VoronoiContainer for the sites defined by their indices (sites_indices)
683683
logging.debug("Getting DetailedVoronoiContainer")
@@ -749,22 +749,22 @@ def compute_structure_environments(
749749
self.detailed_voronoi.separations = [None] * len(self.structure)
750750

751751
# Loop on all the sites
752-
for isite, site in enumerate(self.structure):
753-
if isite not in sites_indices:
754-
logging.debug(f" ... in site #{isite}/{len(self.structure)} ({site.species_string}) : skipped")
752+
for site_idx, site in enumerate(self.structure):
753+
if site_idx not in sites_indices:
754+
logging.debug(f" ... in site #{site_idx}/{len(self.structure)} ({site.species_string}) : skipped")
755755
continue
756756
if break_it:
757757
logging.debug(
758-
f" ... in site #{isite}/{len(self.structure)} ({site.species_string}) : skipped (timelimit)"
758+
f" ... in site #{site_idx}/{len(self.structure)} ({site.species_string}) : skipped (timelimit)"
759759
)
760760
continue
761-
logging.debug(f" ... in site #{isite}/{len(self.structure)} ({site.species_string})")
761+
logging.debug(f" ... in site #{site_idx}/{len(self.structure)} ({site.species_string})")
762762
t1 = time.process_time()
763763
if optimization > 0:
764-
self.detailed_voronoi.local_planes[isite] = {}
765-
self.detailed_voronoi.separations[isite] = {}
764+
self.detailed_voronoi.local_planes[site_idx] = {}
765+
self.detailed_voronoi.separations[site_idx] = {}
766766
struct_envs.init_neighbors_sets(
767-
isite=isite,
767+
isite=site_idx,
768768
additional_conditions=additional_conditions,
769769
valences=valences,
770770
)
@@ -773,15 +773,15 @@ def compute_structure_environments(
773773
nb_sets_info = {}
774774
cn = 0
775775

776-
for cn, nb_sets in struct_envs.neighbors_sets[isite].items():
776+
for cn, nb_sets in struct_envs.neighbors_sets[site_idx].items():
777777
if cn not in all_cns:
778778
continue
779779
for inb_set, nb_set in enumerate(nb_sets):
780780
logging.debug(f" ... getting environments for nb_set ({cn}, {inb_set})")
781781
t_nbset1 = time.process_time()
782782
ce = self.update_nb_set_environments(
783783
se=struct_envs,
784-
isite=isite,
784+
isite=site_idx,
785785
cn=cn,
786786
inb_set=inb_set,
787787
nb_set=nb_set,
@@ -809,7 +809,7 @@ def compute_structure_environments(
809809
logging.debug(f" hint # {idx_new}")
810810
new_nb_set = struct_envs.NeighborsSet(
811811
structure=struct_envs.structure,
812-
isite=isite,
812+
isite=site_idx,
813813
detailed_voronoi=struct_envs.voronoi,
814814
site_voronoi_indices=new_nb_set_voronoi_indices,
815815
sources={
@@ -827,14 +827,14 @@ def compute_structure_environments(
827827
continue
828828
if new_nb_set in [ta["new_nb_set"] for ta in to_add_from_hints]:
829829
has_nb_set = True
830-
elif cn_new_nb_set not in struct_envs.neighbors_sets[isite]:
830+
elif cn_new_nb_set not in struct_envs.neighbors_sets[site_idx]:
831831
has_nb_set = False
832832
else:
833-
has_nb_set = new_nb_set in struct_envs.neighbors_sets[isite][cn_new_nb_set]
833+
has_nb_set = new_nb_set in struct_envs.neighbors_sets[site_idx][cn_new_nb_set]
834834
if not has_nb_set:
835835
to_add_from_hints.append(
836836
{
837-
"isite": isite,
837+
"isite": site_idx,
838838
"new_nb_set": new_nb_set,
839839
"cn_new_nb_set": cn_new_nb_set,
840840
}
@@ -844,7 +844,7 @@ def compute_structure_environments(
844844
logging.debug(" => already present")
845845
logging.debug(" ... getting environments for nb_sets added from hints")
846846
for missing_nb_set_to_add in to_add_from_hints:
847-
struct_envs.add_neighbors_set(isite=isite, nb_set=missing_nb_set_to_add["new_nb_set"])
847+
struct_envs.add_neighbors_set(isite=site_idx, nb_set=missing_nb_set_to_add["new_nb_set"])
848848
for missing_nb_set_to_add in to_add_from_hints:
849849
isite_new_nb_set = missing_nb_set_to_add["isite"]
850850
cn_new_nb_set = missing_nb_set_to_add["cn_new_nb_set"]
@@ -865,7 +865,7 @@ def compute_structure_environments(
865865
nb_sets_info[cn] = {}
866866
nb_sets_info[cn][inew_nb_set] = {"time": t_nbset2 - t_nbset1}
867867
t2 = time.process_time()
868-
struct_envs.update_site_info(isite=isite, info_dict={"time": t2 - t1, "nb_sets_info": nb_sets_info})
868+
struct_envs.update_site_info(isite=site_idx, info_dict={"time": t2 - t1, "nb_sets_info": nb_sets_info})
869869
if timelimit is not None:
870870
time_elapsed = t2 - time_init
871871
time_left = timelimit - time_elapsed
@@ -1029,7 +1029,7 @@ def setup_test_perfect_environment(
10291029
# Rotating the test environment
10301030
if random_rotation == "RANDOM":
10311031
uu = rng.random(3) + 0.1
1032-
uu = uu / norm(uu)
1032+
uu /= norm(uu)
10331033
theta = np.pi * rng.random()
10341034
cos_theta = np.cos(theta)
10351035
sin_theta = np.sin(theta)

0 commit comments

Comments
 (0)