Skip to content

Commit 842641d

Browse files
authored
Merge pull request #767 from hackingmaterials/dict-keys
Remove unneeded `dict.keys()`
2 parents a041423 + 993d197 commit 842641d

15 files changed

+55
-61
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
[![Tests](https://github.com/hackingmaterials/atomate/actions/workflows/test.yml/badge.svg)](https://github.com/hackingmaterials/atomate/actions/workflows/test.yml)
44
[![PyPI Downloads](https://img.shields.io/pypi/dm/atomate?label=PyPI%20Downloads)](https://pypi.org/project/atomate)
5-
[![PyPI](https://img.shields.io/pypi/v/atomate?label=PyPI%20Release)](https://pypi.org/project/atomate)
6-
[![Requires Python 3.8+](https://img.shields.io/badge/Python-3.8+-blue.svg?label=Requires%20Python)](https://python.org/downloads)
5+
[![PyPI](https://img.shields.io/pypi/v/atomate?logo=pypi&logoColor=white)](https://pypi.org/project/atomate)
6+
[![Requires Python 3.8+](https://img.shields.io/badge/Python-3.8+-blue.svg?logo=python&logoColor=white)](https://python.org/downloads)
77

88
atomate is a software for computational materials science that contains pre-built workflows to compute and analyze the properties of materials.
99

10-
- **Website (including documentation):** https://hackingmaterials.github.io/atomate/
11-
- **Help/Support:** https://discuss.matsci.org/c/atomate
12-
- **Source:** https://github.com/hackingmaterials/atomate
10+
- **Website (including documentation):** <https://hackingmaterials.github.io/atomate/>
11+
- **Help/Support:** <https://discuss.matsci.org/c/atomate>
12+
- **Source:** <https://github.com/hackingmaterials/atomate>
1313

1414
If you find atomate useful, please encourage its development by citing the following paper in your research output:
1515

atomate/qchem/powerups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def use_fake_qchem(original_wf, ref_dirs, input_file="mol.qin"):
2525
Workflow
2626
"""
2727
for idx_fw, fw in enumerate(original_wf.fws):
28-
for job_type in ref_dirs.keys():
28+
for job_type in ref_dirs:
2929
if job_type == fw.name:
3030
for idx_t, t in enumerate(fw.tasks):
3131
if "RunQChemCustodian" in str(t) or "RunQChemDirect" in str(t):

atomate/qchem/tests/test_drones.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,8 @@ def test_assimilate_FF(self):
213213
self.assertIn("last_updated", doc)
214214
self.assertIn("dir_name", doc)
215215
self.assertEqual(len(doc["calcs_reversed"]), 4)
216-
self.assertEqual(
217-
list(doc["calcs_reversed"][0].keys()), list(doc["calcs_reversed"][2].keys())
218-
)
219-
self.assertEqual(
220-
list(doc["calcs_reversed"][1].keys()), list(doc["calcs_reversed"][3].keys())
221-
)
216+
self.assertEqual(list(doc["calcs_reversed"][0]), list(doc["calcs_reversed"][2]))
217+
self.assertEqual(list(doc["calcs_reversed"][1]), list(doc["calcs_reversed"][3]))
222218

223219
def test_assimilate_bad_FF(self):
224220
drone = QChemDrone(
@@ -327,9 +323,7 @@ def test_assimilate_ffts(self):
327323
self.assertIn("last_updated", doc)
328324
self.assertIn("dir_name", doc)
329325
self.assertEqual(len(doc["calcs_reversed"]), 3)
330-
self.assertEqual(
331-
list(doc["calcs_reversed"][0].keys()), list(doc["calcs_reversed"][2].keys())
332-
)
326+
self.assertEqual(list(doc["calcs_reversed"][0]), list(doc["calcs_reversed"][2]))
333327

334328
def test_assimilate_bad_ffts(self):
335329
drone = QChemDrone(

atomate/vasp/builders/tasks_materials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run(self):
8383
q = {"state": "successful", "task_label": {"$in": self.supported_task_labels}}
8484

8585
if self.query:
86-
common_keys = [k for k in q.keys() if k in self.query.keys()]
86+
common_keys = [k for k in q if k in self.query]
8787
if common_keys:
8888
raise ValueError(
8989
f"User query parameter cannot contain key(s): {common_keys}"

atomate/vasp/firetasks/approx_neb_dynamic_tasks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,19 @@ def run_task(self, fw_spec):
125125
elif isinstance(structure_paths, (dict)):
126126
relax_image_fws = []
127127
if launch_mode == "all":
128-
for key in structure_paths.keys():
128+
for key in structure_paths:
129129
for path in structure_paths[key]:
130130
relax_image_fws.append(self.get_fw(structure_path=path))
131131
elif launch_mode == "screening":
132-
for key in structure_paths.keys():
132+
for key in structure_paths:
133133
sorted_paths = structure_paths[key]
134134
relax_image_fws.extend(
135135
self.get_screening_fws(sorted_paths=sorted_paths)
136136
)
137137

138138
# place fws in temporary wf in order to use powerup_by_kwargs
139139
# to apply powerups to image fireworks
140-
if "vasp_powerups" in fw_spec.keys():
140+
if "vasp_powerups" in fw_spec:
141141
temp_wf = Workflow(relax_image_fws)
142142
powerup_dicts = fw_spec["vasp_powerups"]
143143
temp_wf = powerup_by_kwargs(temp_wf, powerup_dicts)
@@ -177,7 +177,7 @@ def get_fw(self, structure_path, parents=None):
177177
add_tags=add_tags,
178178
)
179179
if isinstance(add_tags, list):
180-
if "tags" in fw.spec.keys():
180+
if "tags" in fw.spec:
181181
fw.spec["tags"].extend(add_tags)
182182
else:
183183
fw.spec["tags"] = add_tags

atomate/vasp/firetasks/approx_neb_tasks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def run_task(self, fw_spec):
9090
additional_fields = self.get("additional_fields", {})
9191
if isinstance(additional_fields, dict):
9292
for key, value in additional_fields.items():
93-
if key not in approx_neb_doc.keys():
93+
if key not in approx_neb_doc:
9494
approx_neb_doc[key] = value
9595

9696
tags = self.get("tags")
@@ -156,7 +156,7 @@ def run_task(self, fw_spec):
156156
# pulls desired fields from approx_neb collection and stores in pulled_fields
157157
pulled_doc = mmdb.collection.find_one({"wf_uuid": wf_uuid})
158158
pulled_fields = dict()
159-
for key in fields_to_pull.keys():
159+
for key in fields_to_pull:
160160
pulled_fields[key] = get(pulled_doc, fields_to_pull[key])
161161

162162
# update fw_spec with pulled fields (labeled according to fields_to_pass)
@@ -230,7 +230,7 @@ def run_task(self, fw_spec):
230230
structure = Structure.from_dict(structure_doc["output"]["structure"])
231231
# removes site properties to avoid error
232232
if structure.site_properties != {}:
233-
for p in structure.site_properties.keys():
233+
for p in structure.site_properties:
234234
structure.remove_site_property(p)
235235

236236
# insert site(s) in structure and stores corresponding site index in inserted_site_indexes
@@ -559,7 +559,7 @@ def run_task(self, fw_spec):
559559
pf_subdoc = mmdb.collection.find_one(
560560
{"wf_uuid": wf_uuid}, {"pathfinder": 1, "_id": 0}
561561
)
562-
if "pathfinder" not in pf_subdoc.keys():
562+
if "pathfinder" not in pf_subdoc:
563563
pf_subdoc = {}
564564
else:
565565
pf_subdoc = pf_subdoc["pathfinder"]
@@ -655,7 +655,7 @@ def run_task(self, fw_spec):
655655
)
656656

657657
# store images output in approx_neb collection
658-
if "images" not in approx_neb_doc.keys():
658+
if "images" not in approx_neb_doc:
659659
images_subdoc = {}
660660
else:
661661
images_subdoc = approx_neb_doc["images"]
@@ -738,7 +738,7 @@ def add_fix_two_atom_selective_dynamics(self, structure, fixed_index, fixed_spec
738738

739739
# removes site properties to avoid error
740740
if structure.site_properties != {}:
741-
for p in structure.site_properties.keys():
741+
for p in structure.site_properties:
742742
structure.remove_site_property(p)
743743

744744
sd_structure = structure.copy()

atomate/vasp/firetasks/parse_outputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def run_task(self, fw_spec):
495495
}
496496

497497
# store the displacement & epsilon for each mode in a dictionary
498-
mode_disps = fw_spec["raman_epsilon"].keys()
498+
mode_disps = fw_spec["raman_epsilon"]
499499
modes_eps_dict = defaultdict(list)
500500
for md in mode_disps:
501501
modes_eps_dict[fw_spec["raman_epsilon"][md]["mode"]].append(

atomate/vasp/powerups.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def use_no_vasp(original_wf, ref_dirs):
114114
Workflow
115115
"""
116116
for idx_fw, fw in enumerate(original_wf.fws):
117-
for job_type in ref_dirs.keys():
117+
for job_type in ref_dirs:
118118
if job_type in fw.name:
119119
for idx_t, t in enumerate(fw.tasks):
120120
if "RunVasp" in str(t):
@@ -171,7 +171,7 @@ def use_fake_vasp(
171171
]
172172

173173
for idx_fw, fw in enumerate(original_wf.fws):
174-
for job_type in ref_dirs.keys():
174+
for job_type in ref_dirs:
175175
if job_type in fw.name:
176176
for idx_t, t in enumerate(fw.tasks):
177177
t_str = str(t)
@@ -384,7 +384,7 @@ def modify_to_soc(
384384
fw_name_constraint=fw_name_constraint,
385385
task_name_constraint="RunBoltztrap",
386386
)
387-
for idx_fw, idx_t in run_boltztrap_list:
387+
for idx_fw, _idx_t in run_boltztrap_list:
388388
original_wf.fws[idx_fw].name += " soc"
389389

390390
return original_wf
@@ -457,7 +457,7 @@ def set_queue_options(
457457
task_name_constraint=task_name_constraint,
458458
)
459459

460-
for idx_fw, idx_t in idx_list:
460+
for idx_fw, _idx_t in idx_list:
461461
original_wf.fws[idx_fw].spec.update({"_queueadapter": qsettings})
462462

463463
return original_wf
@@ -525,7 +525,7 @@ def add_stability_check(
525525
fw_name_constraint=fw_name_constraint,
526526
task_name_constraint="VaspToDb",
527527
)
528-
for idx_fw, idx_t in idx_list:
528+
for idx_fw, _idx_t in idx_list:
529529
original_wf.fws[idx_fw].tasks.append(CheckStability(**check_stability_params))
530530
return original_wf
531531

@@ -551,7 +551,7 @@ def add_bandgap_check(original_wf, check_bandgap_params=None, fw_name_constraint
551551
fw_name_constraint=fw_name_constraint,
552552
task_name_constraint="VaspToDb",
553553
)
554-
for idx_fw, idx_t in idx_list:
554+
for idx_fw, _idx_t in idx_list:
555555
original_wf.fws[idx_fw].tasks.append(CheckBandgap(**check_bandgap_params))
556556
return original_wf
557557

@@ -812,7 +812,7 @@ def use_fake_lobster(original_wf, ref_dirs, params_to_check=None):
812812
if not params_to_check:
813813
params_to_check = ["basisSet", "cohpGenerator", "basisfunctions"]
814814
for idx_fw, fw in enumerate(original_wf.fws):
815-
for job_type in ref_dirs.keys():
815+
for job_type in ref_dirs:
816816
if job_type in fw.name:
817817
for idx_t, t in enumerate(fw.tasks):
818818
if "RunLobster" in str(t):

atomate/vasp/tests/test_drones.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ def test_runs_assimilate(self):
6767
self.assertEqual(doc["formula_pretty"], "Si")
6868
self.assertEqual(doc["formula_anonymous"], "A")
6969
self.assertEqual(
70-
list(doc["calcs_reversed"][0]["input"].keys()),
71-
list(doc["calcs_reversed"][1]["input"].keys()),
70+
list(doc["calcs_reversed"][0]["input"]),
71+
list(doc["calcs_reversed"][1]["input"]),
7272
)
7373
self.assertEqual(
74-
list(doc["calcs_reversed"][0]["output"].keys()),
75-
list(doc["calcs_reversed"][1]["output"].keys()),
74+
list(doc["calcs_reversed"][0]["output"]),
75+
list(doc["calcs_reversed"][1]["output"]),
7676
)
7777
self.assertEqual(
7878
doc["calcs_reversed"][0]["output"]["energy"], doc["output"]["energy"]

atomate/vasp/workflows/base/approx_neb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def get_aneb_wf(
161161
)
162162

163163
# modifies incar settings needed for end point and image structure relaxations
164-
if "user_incar_settings" not in approx_neb_params.keys():
164+
if "user_incar_settings" not in approx_neb_params:
165165
approx_neb_params = {"user_incar_settings": {}}
166166
approx_neb_params["user_incar_settings"]["ISIF"] = 2
167167
approx_neb_params["user_incar_settings"]["ISYM"] = 0

0 commit comments

Comments
 (0)