Skip to content

Commit 1800b2e

Browse files
authored
Add black formatting (#72)
1 parent d9c919c commit 1800b2e

File tree

4 files changed

+69
-22
lines changed

4 files changed

+69
-22
lines changed

.github/workflows/pipeline.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ on:
66
pull_request:
77

88
jobs:
9+
black:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: psf/black@stable
14+
with:
15+
options: "--check --diff"
16+
src: ./python_workflow_definition/src/python_workflow_definition
17+
- uses: psf/black@stable
18+
with:
19+
options: "--check --diff"
20+
src: ./qe_xml_parser/src/qe_xml_parser
21+
922
nfdi4ing:
1023
runs-on: ubuntu-22.04
1124
steps:

python_workflow_definition/src/python_workflow_definition/jobflow.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def _get_nodes_dict(function_dict: dict):
3333
return nodes_dict, nodes_mapping_dict
3434

3535

36-
def _get_edge_from_dict(target: str, key: str, value_dict: dict, nodes_mapping_dict: dict) -> dict:
36+
def _get_edge_from_dict(
37+
target: str, key: str, value_dict: dict, nodes_mapping_dict: dict
38+
) -> dict:
3739
if len(value_dict["attributes"]) == 1:
3840
return {
3941
TARGET_LABEL: target,
@@ -50,7 +52,9 @@ def _get_edge_from_dict(target: str, key: str, value_dict: dict, nodes_mapping_d
5052
}
5153

5254

53-
def _get_edges_and_extend_nodes(flow_dict: dict, nodes_mapping_dict: dict, nodes_dict: dict):
55+
def _get_edges_and_extend_nodes(
56+
flow_dict: dict, nodes_mapping_dict: dict, nodes_dict: dict
57+
):
5458
edges_lst = []
5559
for job in flow_dict["jobs"]:
5660
for k, v in job["function_kwargs"].items():
@@ -222,7 +226,9 @@ def _get_input_dict(nodes_dict: dict) -> dict:
222226
return {k: v for k, v in nodes_dict.items() if not isfunction(v)}
223227

224228

225-
def _get_workflow(nodes_dict: dict, input_dict: dict, total_dict: dict, source_handles_dict: dict) -> list:
229+
def _get_workflow(
230+
nodes_dict: dict, input_dict: dict, total_dict: dict, source_handles_dict: dict
231+
) -> list:
226232
def get_attr_helper(obj, source_handle):
227233
if source_handle is None:
228234
return getattr(obj, "output")

python_workflow_definition/src/python_workflow_definition/pyiron_base.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def _group_edges(edges_lst: list) -> list:
5353
return total_lst
5454

5555

56-
def _get_source(nodes_dict: dict, delayed_object_dict: dict, source: str, source_handle: str):
56+
def _get_source(
57+
nodes_dict: dict, delayed_object_dict: dict, source: str, source_handle: str
58+
):
5759
if source in delayed_object_dict.keys() and source_handle is not None:
5860
return (
5961
delayed_object_dict[source].__getattr__("output").__getattr__(source_handle)
@@ -64,7 +66,9 @@ def _get_source(nodes_dict: dict, delayed_object_dict: dict, source: str, source
6466
return nodes_dict[source]
6567

6668

67-
def _get_delayed_object_dict(total_lst: list, nodes_dict: dict, source_handle_dict: dict, pyiron_project: Project) -> dict:
69+
def _get_delayed_object_dict(
70+
total_lst: list, nodes_dict: dict, source_handle_dict: dict, pyiron_project: Project
71+
) -> dict:
6872
delayed_object_dict = {}
6973
for item in total_lst:
7074
key, input_dict = item
@@ -175,7 +179,9 @@ def _get_connection_dict(delayed_object_updated_dict: dict, match_dict: dict):
175179
return connection_dict, lookup_dict
176180

177181

178-
def _get_edges_dict(edges_lst: list, nodes_dict: dict, connection_dict: dict, lookup_dict: dict):
182+
def _get_edges_dict(
183+
edges_lst: list, nodes_dict: dict, connection_dict: dict, lookup_dict: dict
184+
):
179185
edges_dict_lst = []
180186
existing_connection_lst = []
181187
for ep in edges_lst:
@@ -217,7 +223,7 @@ def _get_edges_dict(edges_lst: list, nodes_dict: dict, connection_dict: dict, lo
217223
return edges_dict_lst
218224

219225

220-
def load_workflow_json(file_name: str, project: Optional[Project]=None):
226+
def load_workflow_json(file_name: str, project: Optional[Project] = None):
221227
if project is None:
222228
project = Project(".")
223229

@@ -248,7 +254,9 @@ def load_workflow_json(file_name: str, project: Optional[Project]=None):
248254
return list(delayed_object_dict.values())
249255

250256

251-
def write_workflow_json(delayed_object: DelayedObject, file_name: str="workflow.json"):
257+
def write_workflow_json(
258+
delayed_object: DelayedObject, file_name: str = "workflow.json"
259+
):
252260
nodes_dict, edges_lst = delayed_object.get_graph()
253261
nodes_dict, edges_lst = _remove_server_obj(
254262
nodes_dict=nodes_dict, edges_lst=edges_lst

qe_xml_parser/src/qe_xml_parser/parsers.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,34 @@
1212
def parse_pw(xml_file):
1313
"""Parse a Quantum Espresso XML output file."""
1414

15-
xml_dict = XMLSchema(str(files(schemas) / 'qes_230310.xsd')).to_dict(xml_file)
15+
xml_dict = XMLSchema(str(files(schemas) / "qes_230310.xsd")).to_dict(xml_file)
1616

1717
parsed_results = {}
1818

1919
try:
20-
cell = numpy.array(
21-
[ v for v in xml_dict['output']['atomic_structure']['cell'].values()]
22-
) * CONSTANTS.bohr_to_ang
23-
symbols = [el['@name'] for el in xml_dict['output']['atomic_structure']['atomic_positions']['atom']]
24-
positions = numpy.array(
25-
[el['$'] for el in xml_dict['output']['atomic_structure']['atomic_positions']['atom']]
26-
) * CONSTANTS.bohr_to_ang
27-
28-
parsed_results['ase_structure'] = Atoms(
20+
cell = (
21+
numpy.array(
22+
[v for v in xml_dict["output"]["atomic_structure"]["cell"].values()]
23+
)
24+
* CONSTANTS.bohr_to_ang
25+
)
26+
symbols = [
27+
el["@name"]
28+
for el in xml_dict["output"]["atomic_structure"]["atomic_positions"]["atom"]
29+
]
30+
positions = (
31+
numpy.array(
32+
[
33+
el["$"]
34+
for el in xml_dict["output"]["atomic_structure"][
35+
"atomic_positions"
36+
]["atom"]
37+
]
38+
)
39+
* CONSTANTS.bohr_to_ang
40+
)
41+
42+
parsed_results["ase_structure"] = Atoms(
2943
cell=cell,
3044
positions=positions,
3145
symbols=symbols,
@@ -35,14 +49,20 @@ def parse_pw(xml_file):
3549
pass
3650

3751
try:
38-
parsed_results['energy'] = xml_dict['output']['total_energy']['etot'] * CONSTANTS.ry_to_ev
52+
parsed_results["energy"] = (
53+
xml_dict["output"]["total_energy"]["etot"] * CONSTANTS.ry_to_ev
54+
)
3955
except KeyError:
4056
pass
4157

4258
try:
43-
parsed_results['forces'] = (
44-
numpy.array(xml_dict['output']['forces']['$']).reshape(xml_dict['output']['forces']['@dims'])
45-
* 2 * CONSTANTS.ry_to_ev / CONSTANTS.bohr_to_ang
59+
parsed_results["forces"] = (
60+
numpy.array(xml_dict["output"]["forces"]["$"]).reshape(
61+
xml_dict["output"]["forces"]["@dims"]
62+
)
63+
* 2
64+
* CONSTANTS.ry_to_ev
65+
/ CONSTANTS.bohr_to_ang
4666
)
4767
except KeyError:
4868
pass

0 commit comments

Comments
 (0)