Skip to content

Commit 0b29cdf

Browse files
committed
Merge branch 'main' of https://www.github.com/hackingmaterials/atomate into main
2 parents d90e96d + a9cedff commit 0b29cdf

File tree

214 files changed

+2250463
-4289
lines changed

Some content is hidden

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

214 files changed

+2250463
-4289
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
repos:
2-
- repo: git@github.com:humitos/mirrors-autoflake.git
3-
rev: v1.1
2+
- repo: https://github.com/myint/autoflake
3+
rev: v1.4
44
hooks:
55
- id: autoflake
6-
args: [ '--in-place', '--remove-all-unused-imports', '--remove-unused-variable' ]
7-
- repo: https://github.com/ambv/black
8-
rev: stable
6+
args: [--in-place, --remove-all-unused-imports, --remove-unused-variable, --ignore-init-module-imports]
7+
- repo: https://github.com/psf/black
8+
rev: 21.4b2
99
hooks:
1010
- id: black
11-
language_version: python3
11+
- repo: https://gitlab.com/pycqa/flake8
12+
rev: 3.8.4
13+
hooks:
14+
- id: flake8
15+
args: [--max-line-length=125]
1216
- repo: https://github.com/pre-commit/pre-commit-hooks
13-
rev: v2.3.0
17+
rev: v3.4.0
1418
hooks:
1519
- id: check-yaml
1620
- id: end-of-file-fixer
1721
- id: trailing-whitespace
18-
- id: flake8
19-
args: ["--max-line-length=125"]

CONTRIBUTING.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# Contributing to atomate
2+
23
We love your input! We want to make contributing to atomate as easy and transparent as possible, whether it's:
4+
35
* Reporting a bug
46
* Discussing the current state of the code
57
* Submitting a fix
68
* Proposing or implementing new features
79
* Becoming a maintainer
810

911
## Reporting bugs, getting help, and discussion
12+
1013
At any time, feel free to start a thread on our [Discourse forum](https://discuss.matsci.org/c/atomate).
1114

1215
If you are making a bug report, incorporate as many elements of the following as possible to ensure a timely response and avoid the need for followups:
16+
1317
* A quick summary and/or background
1418
* Steps to reproduce - be specific! **Provide sample code.**
1519
* What you expected would happen, compared to what actually happens
@@ -19,16 +23,19 @@ If you are making a bug report, incorporate as many elements of the following as
1923
We love thorough bug reports as this means the development team can make quick and meaningful fixes. When we confirm your bug report, we'll move it to the GitHub issues where its progress can be further tracked.
2024

2125
## Contributing code modifications or additions through Github
22-
We use github to host code, to track issues and feature requests, as well as accept pull requests. We maintain a list of all contributors to atomate [here.](https://atomate.org/contributors.html)
26+
27+
We use github to host code, to track issues and feature requests, as well as accept pull requests. We maintain a list of all contributors to atomate [here](https://atomate.org/contributors.html).
2328

2429
Pull requests are the best way to propose changes to the codebase. Follow the [Github flow](https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow) for more information on this procedure.
2530

2631
The basic procedure for making a PR is:
32+
2733
* Fork the repo and create your branch from main.
2834
* Commit your improvements to your branch and push to your Github fork (repo).
2935
* When you're finished, go to your fork and make a Pull Request. It will automatically update if you need to make further changes.
3036

3137
### How to Make a **Great** Pull Request
38+
3239
We have a few tips for writing good PRs that are accepted into the main repo:
3340

3441
* Use the Google Code style for all of your code. Find an example [here.](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html)
@@ -41,4 +48,5 @@ When you submit your PR, our CI service will automatically run your tests.
4148
We welcome good discussion on the best ways to write your code, and the comments on your PR are an excellent area for discussion.
4249

4350
#### References
51+
4452
This document was adapted from the open-source contribution guidelines for Facebook's Draft, as well as briandk's [contribution template](https://gist.github.com/briandk/3d2e8b3ec8daf5a27a62).

atomate/common/firetasks/glue_tasks.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# coding: utf-8
2-
3-
41
import os
52
import monty
63
import shutil
@@ -72,7 +69,7 @@ def get_calc_loc(target_name, calc_locs):
7269
for doc in reversed(calc_locs):
7370
if doc["name"] == target_name:
7471
return doc
75-
raise ValueError("Could not find the target_name: {}".format(target_name))
72+
raise ValueError(f"Could not find the target_name: {target_name}")
7673
else:
7774
return calc_locs[-1]
7875

atomate/common/firetasks/parse_outputs.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# coding: utf-8
2-
3-
41
import json
52
import os
63

@@ -10,7 +7,7 @@
107
from atomate.utils.utils import env_chk, get_logger, load_class
118
from atomate.common.firetasks.glue_tasks import get_calc_loc
129

13-
__author__ = 'Shyam Dwaraknath <[email protected]>, Anubhav Jain <[email protected]>'
10+
__author__ = "Shyam Dwaraknath <[email protected]>, Anubhav Jain <[email protected]>"
1411

1512
logger = get_logger(__name__)
1613

@@ -37,7 +34,14 @@ class ToDbTask(FiretaskBase):
3734
"""
3835

3936
required_params = ["drone"]
40-
optional_params = ["mmdb", "db_file", "calc_dir", "calc_loc", "additional_fields", "options"]
37+
optional_params = [
38+
"mmdb",
39+
"db_file",
40+
"calc_dir",
41+
"calc_loc",
42+
"additional_fields",
43+
"options",
44+
]
4145

4246
def run_task(self, fw_spec):
4347
# get the directory that contains the dir to parse
@@ -48,12 +52,15 @@ def run_task(self, fw_spec):
4852
calc_dir = get_calc_loc(self["calc_loc"], fw_spec["calc_locs"])["path"]
4953

5054
# parse the calc directory
51-
logger.info("PARSING DIRECTORY: {} USING DRONE: {}".format(
52-
calc_dir, self['drone'].__class__.__name__))
55+
logger.info(
56+
"PARSING DIRECTORY: {} USING DRONE: {}".format(
57+
calc_dir, self["drone"].__class__.__name__
58+
)
59+
)
5360
# get the database connection
54-
db_file = env_chk(self.get('db_file'), fw_spec)
61+
db_file = env_chk(self.get("db_file"), fw_spec)
5562

56-
drone = self['drone'].__class__()
63+
drone = self["drone"].__class__()
5764
task_doc = drone.assimilate(calc_dir)
5865
if not db_file:
5966
with open("task.json", "w") as f:
@@ -66,7 +73,9 @@ def run_task(self, fw_spec):
6673

6774
# insert the task document
6875
t_id = db.insert(task_doc)
69-
logger.info("Finished parsing with task_id: {}".format(t_id))
76+
logger.info(f"Finished parsing with task_id: {t_id}")
7077

71-
return FWAction(stored_data={"task_id": task_doc.get("task_id", None)},
72-
defuse_children=(task_doc["state"] != "successful"))
78+
return FWAction(
79+
stored_data={"task_id": task_doc.get("task_id", None)},
80+
defuse_children=(task_doc["state"] != "successful"),
81+
)

atomate/common/firetasks/run_calc.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# coding: utf-8
2-
3-
41
import os
52
import subprocess
63

@@ -10,7 +7,7 @@
107

118
from atomate.utils.utils import env_chk, get_logger
129

13-
__author__ = 'Anubhav Jain <[email protected]>'
10+
__author__ = "Anubhav Jain <[email protected]>"
1411

1512
logger = get_logger(__name__)
1613

@@ -34,9 +31,9 @@ def run_task(self, fw_spec):
3431
if self.get("expand_vars", False):
3532
cmd = os.path.expandvars(cmd)
3633

37-
logger.info("Running command: {}".format(cmd))
34+
logger.info(f"Running command: {cmd}")
3835
return_code = subprocess.call(cmd, shell=True)
39-
logger.info("Command {} finished running with returncode: {}".format(cmd, return_code))
36+
logger.info(f"Command {cmd} finished running with returncode: {return_code}")
4037

4138

4239
@explicit_serialize
@@ -58,6 +55,10 @@ class RunCustodianFromObjects(FiretaskBase):
5855
optional_params = ["validators", "custodian_params"]
5956

6057
def run_task(self, fw_spec):
61-
c = Custodian(self["handlers"], self["jobs"], self.get("validators"),
62-
**self.get("custodian_params", {}))
58+
c = Custodian(
59+
self["handlers"],
60+
self["jobs"],
61+
self.get("validators"),
62+
**self.get("custodian_params", {}),
63+
)
6364
c.run()
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1-
2-
31
import os
42
import unittest
5-
import shutil
63

7-
from fireworks import LaunchPad, Firework, Workflow
4+
from fireworks import Firework, Workflow
85
from fireworks.core.rocket_launcher import rapidfire
96

107
from pymatgen.apps.borg.hive import AbstractDrone
118

129
from atomate.common.firetasks.parse_outputs import ToDbTask
1310
from atomate.utils.testing import AtomateTest
1411

15-
__author__ = 'Shyam Dwaraknath <[email protected]>'
12+
__author__ = "Shyam Dwaraknath <[email protected]>"
1613

1714
module_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
1815
db_dir = os.path.join(module_dir, "..", "..", "test_files")
1916

2017

2118
class TestDrone(AbstractDrone):
22-
2319
def __init__(self):
2420
pass
2521

2622
def assimilate(self, path):
27-
return {"drone": "Test Drone",
28-
"dir_name": "/test",
29-
'state': "successful"}
23+
return {"drone": "Test Drone", "dir_name": "/test", "state": "successful"}
3024

3125
def get_valid_paths(self, path):
3226
return path
3327

3428

3529
class TestToDbTask(AtomateTest):
36-
3730
def test_ToDbTask(self):
3831
d = TestDrone()
3932

40-
fw1 = Firework([ToDbTask(drone=d,
41-
mmdb="atomate.vasp.database.VaspCalcDb",
42-
db_file=os.path.join(db_dir, "db.json"),
43-
calc_dir=db_dir)], name="fw1")
33+
fw1 = Firework(
34+
[
35+
ToDbTask(
36+
drone=d,
37+
mmdb="atomate.vasp.database.VaspCalcDb",
38+
db_file=os.path.join(db_dir, "db.json"),
39+
calc_dir=db_dir,
40+
)
41+
],
42+
name="fw1",
43+
)
4444

4545
wf = Workflow([fw1])
4646
self.lp.add_wf(wf)
4747
rapidfire(self.lp)
4848

49-
task1 = self.lp.db.tasks.find_one({"task_id":1})
50-
self.assertEqual(task1['task_id'],1)
51-
self.assertEqual(task1['dir_name'],"/test" )
52-
self.assertEqual(task1['drone'],'Test Drone')
49+
task1 = self.lp.db.tasks.find_one({"task_id": 1})
50+
self.assertEqual(task1["task_id"], 1)
51+
self.assertEqual(task1["dir_name"], "/test")
52+
self.assertEqual(task1["drone"], "Test Drone")
53+
5354

5455
if __name__ == "__main__":
5556
unittest.main()

atomate/common/powerups.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# coding: utf-8
2-
31
"""
42
This module defines general powerups that can be used for all workflows
53
"""
@@ -102,7 +100,7 @@ def add_namefile(original_wf, use_slug=True):
102100
Workflow
103101
"""
104102
for idx, fw in enumerate(original_wf.fws):
105-
fname = "FW--{}".format(fw.name)
103+
fname = f"FW--{fw.name}"
106104
if use_slug:
107105
fname = get_slug(fname)
108106

@@ -132,6 +130,34 @@ def add_additional_fields_to_taskdocs(
132130
return original_wf
133131

134132

133+
def add_metadata(wf, meta_dict, fw_name_constraint=None):
134+
"""
135+
Add a metadata dictionary to a Workflow and all its Fireworks. The dictionary
136+
is merged into the "metadata" key of the Workflow and into the "_spec" key of
137+
each Firework in the workflow.
138+
139+
Can be used in combination with add_additional_fields_to_taskdocs to add the
140+
same set of key-value pairs to Workflows, Fireworks and Tasks collections.
141+
142+
Args:
143+
wf (Workflow)
144+
meta_dict: dictionary of custom metadata
145+
146+
Returns:
147+
Workflow
148+
"""
149+
150+
# add metadata to Workflow metadata
151+
wf.metadata.update(meta_dict)
152+
153+
# add metadata to Firework metadata
154+
for fw in wf.fws:
155+
if fw_name_constraint is None or fw_name_constraint in fw.name:
156+
fw.spec.update(meta_dict)
157+
158+
return wf
159+
160+
135161
def preserve_fworker(original_wf, fw_name_constraint=None):
136162
"""
137163
set _preserve_fworker spec of Fireworker(s) of a Workflow. Can be used to
@@ -275,5 +301,5 @@ def powerup_by_kwargs(
275301
except Exception:
276302
pass
277303
if not found:
278-
raise RuntimeError("Could not find powerup {}.".format(name))
304+
raise RuntimeError(f"Could not find powerup {name}.")
279305
return original_wf

atomate/common/tests/test_powerups.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
22

3+
from atomate.utils.utils import get_fws_and_tasks
34
from atomate.vasp.workflows.base.core import get_wf
45

56
from pymatgen.io.vasp.sets import MPRelaxSet
@@ -10,6 +11,8 @@
1011
add_priority,
1112
add_tags,
1213
powerup_by_kwargs,
14+
add_additional_fields_to_taskdocs,
15+
add_metadata,
1316
)
1417
from fireworks import Firework, ScriptTask, Workflow
1518

@@ -137,6 +140,36 @@ def test_set_queue_adapter(self):
137140
)
138141
self.assertDictEqual(wf.id_fw[-3].spec, {})
139142

143+
def test_add_additional_fields_to_taskdocs(self):
144+
145+
my_wf = copy_wf(self.bsboltz_wf)
146+
meta_dict = {"foo": "bar", "baz": 42}
147+
my_wf = add_additional_fields_to_taskdocs(my_wf, meta_dict)
148+
149+
found = 0
150+
151+
for fw in my_wf.fws:
152+
for task in fw.tasks:
153+
if "ToDb" in str(task):
154+
for key, val in meta_dict.items():
155+
self.assertEqual(task["additional_fields"][key], val)
156+
157+
found += 1
158+
159+
self.assertEqual(found, 5)
160+
161+
def test_add_metadata(self):
162+
my_wf = copy_wf(self.bs_wf)
163+
my_wf.metadata = {"what": "ever"}
164+
meta_dict = {"foo": "bar", "baz": 42}
165+
my_wf = add_metadata(my_wf, meta_dict, fw_name_constraint="NonSCFFW")
166+
167+
self.assertEqual(my_wf.metadata, {"what": "ever", "foo": "bar", "baz": 42})
168+
169+
for [fw, _] in get_fws_and_tasks(my_wf, fw_name_constraint="NonSCFFW"):
170+
for key, val in meta_dict.items():
171+
self.assertEqual(fw.spec[key], val)
172+
140173

141174
def copy_wf(wf):
142175
return Workflow.from_dict(wf.to_dict())

0 commit comments

Comments
 (0)