Skip to content

Commit

Permalink
Merge pull request #767 from hackingmaterials/dict-keys
Browse files Browse the repository at this point in the history
Remove unneeded `dict.keys()`
  • Loading branch information
janosh authored Mar 14, 2023
2 parents a041423 + 993d197 commit 842641d
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 61 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion atomate/qchem/powerups.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def use_fake_qchem(original_wf, ref_dirs, input_file="mol.qin"):
Workflow
"""
for idx_fw, fw in enumerate(original_wf.fws):
for job_type in ref_dirs.keys():
for job_type in ref_dirs:
if job_type == fw.name:
for idx_t, t in enumerate(fw.tasks):
if "RunQChemCustodian" in str(t) or "RunQChemDirect" in str(t):
Expand Down
12 changes: 3 additions & 9 deletions atomate/qchem/tests/test_drones.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,8 @@ def test_assimilate_FF(self):
self.assertIn("last_updated", doc)
self.assertIn("dir_name", doc)
self.assertEqual(len(doc["calcs_reversed"]), 4)
self.assertEqual(
list(doc["calcs_reversed"][0].keys()), list(doc["calcs_reversed"][2].keys())
)
self.assertEqual(
list(doc["calcs_reversed"][1].keys()), list(doc["calcs_reversed"][3].keys())
)
self.assertEqual(list(doc["calcs_reversed"][0]), list(doc["calcs_reversed"][2]))
self.assertEqual(list(doc["calcs_reversed"][1]), list(doc["calcs_reversed"][3]))

def test_assimilate_bad_FF(self):
drone = QChemDrone(
Expand Down Expand Up @@ -327,9 +323,7 @@ def test_assimilate_ffts(self):
self.assertIn("last_updated", doc)
self.assertIn("dir_name", doc)
self.assertEqual(len(doc["calcs_reversed"]), 3)
self.assertEqual(
list(doc["calcs_reversed"][0].keys()), list(doc["calcs_reversed"][2].keys())
)
self.assertEqual(list(doc["calcs_reversed"][0]), list(doc["calcs_reversed"][2]))

def test_assimilate_bad_ffts(self):
drone = QChemDrone(
Expand Down
2 changes: 1 addition & 1 deletion atomate/vasp/builders/tasks_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def run(self):
q = {"state": "successful", "task_label": {"$in": self.supported_task_labels}}

if self.query:
common_keys = [k for k in q.keys() if k in self.query.keys()]
common_keys = [k for k in q if k in self.query]
if common_keys:
raise ValueError(
f"User query parameter cannot contain key(s): {common_keys}"
Expand Down
8 changes: 4 additions & 4 deletions atomate/vasp/firetasks/approx_neb_dynamic_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ def run_task(self, fw_spec):
elif isinstance(structure_paths, (dict)):
relax_image_fws = []
if launch_mode == "all":
for key in structure_paths.keys():
for key in structure_paths:
for path in structure_paths[key]:
relax_image_fws.append(self.get_fw(structure_path=path))
elif launch_mode == "screening":
for key in structure_paths.keys():
for key in structure_paths:
sorted_paths = structure_paths[key]
relax_image_fws.extend(
self.get_screening_fws(sorted_paths=sorted_paths)
)

# place fws in temporary wf in order to use powerup_by_kwargs
# to apply powerups to image fireworks
if "vasp_powerups" in fw_spec.keys():
if "vasp_powerups" in fw_spec:
temp_wf = Workflow(relax_image_fws)
powerup_dicts = fw_spec["vasp_powerups"]
temp_wf = powerup_by_kwargs(temp_wf, powerup_dicts)
Expand Down Expand Up @@ -177,7 +177,7 @@ def get_fw(self, structure_path, parents=None):
add_tags=add_tags,
)
if isinstance(add_tags, list):
if "tags" in fw.spec.keys():
if "tags" in fw.spec:
fw.spec["tags"].extend(add_tags)
else:
fw.spec["tags"] = add_tags
Expand Down
12 changes: 6 additions & 6 deletions atomate/vasp/firetasks/approx_neb_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def run_task(self, fw_spec):
additional_fields = self.get("additional_fields", {})
if isinstance(additional_fields, dict):
for key, value in additional_fields.items():
if key not in approx_neb_doc.keys():
if key not in approx_neb_doc:
approx_neb_doc[key] = value

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

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

# insert site(s) in structure and stores corresponding site index in inserted_site_indexes
Expand Down Expand Up @@ -559,7 +559,7 @@ def run_task(self, fw_spec):
pf_subdoc = mmdb.collection.find_one(
{"wf_uuid": wf_uuid}, {"pathfinder": 1, "_id": 0}
)
if "pathfinder" not in pf_subdoc.keys():
if "pathfinder" not in pf_subdoc:
pf_subdoc = {}
else:
pf_subdoc = pf_subdoc["pathfinder"]
Expand Down Expand Up @@ -655,7 +655,7 @@ def run_task(self, fw_spec):
)

# store images output in approx_neb collection
if "images" not in approx_neb_doc.keys():
if "images" not in approx_neb_doc:
images_subdoc = {}
else:
images_subdoc = approx_neb_doc["images"]
Expand Down Expand Up @@ -738,7 +738,7 @@ def add_fix_two_atom_selective_dynamics(self, structure, fixed_index, fixed_spec

# removes site properties to avoid error
if structure.site_properties != {}:
for p in structure.site_properties.keys():
for p in structure.site_properties:
structure.remove_site_property(p)

sd_structure = structure.copy()
Expand Down
2 changes: 1 addition & 1 deletion atomate/vasp/firetasks/parse_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def run_task(self, fw_spec):
}

# store the displacement & epsilon for each mode in a dictionary
mode_disps = fw_spec["raman_epsilon"].keys()
mode_disps = fw_spec["raman_epsilon"]
modes_eps_dict = defaultdict(list)
for md in mode_disps:
modes_eps_dict[fw_spec["raman_epsilon"][md]["mode"]].append(
Expand Down
14 changes: 7 additions & 7 deletions atomate/vasp/powerups.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def use_no_vasp(original_wf, ref_dirs):
Workflow
"""
for idx_fw, fw in enumerate(original_wf.fws):
for job_type in ref_dirs.keys():
for job_type in ref_dirs:
if job_type in fw.name:
for idx_t, t in enumerate(fw.tasks):
if "RunVasp" in str(t):
Expand Down Expand Up @@ -171,7 +171,7 @@ def use_fake_vasp(
]

for idx_fw, fw in enumerate(original_wf.fws):
for job_type in ref_dirs.keys():
for job_type in ref_dirs:
if job_type in fw.name:
for idx_t, t in enumerate(fw.tasks):
t_str = str(t)
Expand Down Expand Up @@ -384,7 +384,7 @@ def modify_to_soc(
fw_name_constraint=fw_name_constraint,
task_name_constraint="RunBoltztrap",
)
for idx_fw, idx_t in run_boltztrap_list:
for idx_fw, _idx_t in run_boltztrap_list:
original_wf.fws[idx_fw].name += " soc"

return original_wf
Expand Down Expand Up @@ -457,7 +457,7 @@ def set_queue_options(
task_name_constraint=task_name_constraint,
)

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

return original_wf
Expand Down Expand Up @@ -525,7 +525,7 @@ def add_stability_check(
fw_name_constraint=fw_name_constraint,
task_name_constraint="VaspToDb",
)
for idx_fw, idx_t in idx_list:
for idx_fw, _idx_t in idx_list:
original_wf.fws[idx_fw].tasks.append(CheckStability(**check_stability_params))
return original_wf

Expand All @@ -551,7 +551,7 @@ def add_bandgap_check(original_wf, check_bandgap_params=None, fw_name_constraint
fw_name_constraint=fw_name_constraint,
task_name_constraint="VaspToDb",
)
for idx_fw, idx_t in idx_list:
for idx_fw, _idx_t in idx_list:
original_wf.fws[idx_fw].tasks.append(CheckBandgap(**check_bandgap_params))
return original_wf

Expand Down Expand Up @@ -812,7 +812,7 @@ def use_fake_lobster(original_wf, ref_dirs, params_to_check=None):
if not params_to_check:
params_to_check = ["basisSet", "cohpGenerator", "basisfunctions"]
for idx_fw, fw in enumerate(original_wf.fws):
for job_type in ref_dirs.keys():
for job_type in ref_dirs:
if job_type in fw.name:
for idx_t, t in enumerate(fw.tasks):
if "RunLobster" in str(t):
Expand Down
8 changes: 4 additions & 4 deletions atomate/vasp/tests/test_drones.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def test_runs_assimilate(self):
self.assertEqual(doc["formula_pretty"], "Si")
self.assertEqual(doc["formula_anonymous"], "A")
self.assertEqual(
list(doc["calcs_reversed"][0]["input"].keys()),
list(doc["calcs_reversed"][1]["input"].keys()),
list(doc["calcs_reversed"][0]["input"]),
list(doc["calcs_reversed"][1]["input"]),
)
self.assertEqual(
list(doc["calcs_reversed"][0]["output"].keys()),
list(doc["calcs_reversed"][1]["output"].keys()),
list(doc["calcs_reversed"][0]["output"]),
list(doc["calcs_reversed"][1]["output"]),
)
self.assertEqual(
doc["calcs_reversed"][0]["output"]["energy"], doc["output"]["energy"]
Expand Down
2 changes: 1 addition & 1 deletion atomate/vasp/workflows/base/approx_neb.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def get_aneb_wf(
)

# modifies incar settings needed for end point and image structure relaxations
if "user_incar_settings" not in approx_neb_params.keys():
if "user_incar_settings" not in approx_neb_params:
approx_neb_params = {"user_incar_settings": {}}
approx_neb_params["user_incar_settings"]["ISIF"] = 2
approx_neb_params["user_incar_settings"]["ISYM"] = 0
Expand Down
18 changes: 9 additions & 9 deletions atomate/vasp/workflows/base/hubbard_hund_linresp.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def get_wf_hubbard_hund_linresp(

# generate list of applied on-site potentials in linear response
applied_potential_value_list = []
for counter_perturb in range(num_perturb):
for _ in range(num_perturb):
applied_potential_values = np.linspace(
applied_potential_range[0], applied_potential_range[1], num_evals
)
Expand Down Expand Up @@ -264,11 +264,11 @@ def find_closest_sites(struct, species_perturb):
n_species = {}
for site in struct:
k = str(site.specie)
if k not in n_species.keys():
if k not in n_species:
n_species.update({k: 0})
n_species[k] += 1

n_s = len(n_species.keys())
n_s = len(n_species)
n_config = 1
for k in n_species:
n_config *= n_species[k]
Expand All @@ -278,10 +278,10 @@ def find_closest_sites(struct, species_perturb):
for k in range(n_config):
denom = 1
for j in range(n_s):
n = n_species[list(n_species.keys())[j]]
n = n_species[list(n_species)[j]]
indices[j] = np.mod(k // denom, n)
denom *= n
nn_s = [n_species[list(n_species.keys())[j]] for j in range(n_s)]
nn_s = [n_species[list(n_species)[j]] for j in range(n_s)]
iindxs = [indices[j] + int(np.sum(nn_s[0:j])) for j in range(n_s)]
indxs = []
for j, jk in enumerate(n_species):
Expand Down Expand Up @@ -309,7 +309,7 @@ def init_linresp_input_sets(
"""

# set LMAXMIX in user_incar_settings
if "LMAXMIX" not in user_incar_settings.keys():
if "LMAXMIX" not in user_incar_settings:
lmaxmix_dict = {"p": 2, "d": 4, "f": 6}
lmm = "p"
for site in structure:
Expand Down Expand Up @@ -679,9 +679,9 @@ def incar(self):
incar.update({"LDAUU": self.kwargs.get("user_incar_settings")["LDAUU"]})
incar.update({"LDAUJ": self.kwargs.get("user_incar_settings")["LDAUJ"]})

incar["LDAUL"] = [incar["LDAUL"][key] for key in incar["LDAUL"].keys()]
incar["LDAUU"] = [incar["LDAUU"][key] for key in incar["LDAUU"].keys()]
incar["LDAUJ"] = [incar["LDAUJ"][key] for key in incar["LDAUJ"].keys()]
incar["LDAUL"] = [incar["LDAUL"][key] for key in incar["LDAUL"]]
incar["LDAUU"] = [incar["LDAUU"][key] for key in incar["LDAUU"]]
incar["LDAUJ"] = [incar["LDAUJ"][key] for key in incar["LDAUJ"]]

incar["LDAU"] = self.kwargs.get("user_incar_settings")["LDAU"]
incar["LDAUTYPE"] = self.kwargs.get("user_incar_settings")["LDAUTYPE"]
Expand Down
2 changes: 1 addition & 1 deletion atomate/vasp/workflows/tests/test_approx_neb_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_wf(self):
self.assertEqual(len(aneb_doc["end_points"]), 2)
for e in aneb_doc["end_points"]:
self.assertIn("output", e)
self.assertEqual(len(aneb_doc["pathfinder"].keys()), 1)
self.assertEqual(len(aneb_doc["pathfinder"]), 1)
self.assertIn("0+1", aneb_doc["pathfinder"])
self.assertIn("0+1", aneb_doc["images"])
self.assertEqual(len(aneb_doc["images"]["0+1"]), 3)
Expand Down
Loading

0 comments on commit 842641d

Please sign in to comment.