diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 307ace9..7ea3390 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -6,6 +6,19 @@ on: pull_request: jobs: + black: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: psf/black@stable + with: + options: "--check --diff" + src: ./python_workflow_definition/src/python_workflow_definition + - uses: psf/black@stable + with: + options: "--check --diff" + src: ./qe_xml_parser/src/qe_xml_parser + nfdi4ing: runs-on: ubuntu-22.04 steps: diff --git a/python_workflow_definition/src/python_workflow_definition/jobflow.py b/python_workflow_definition/src/python_workflow_definition/jobflow.py index 3daee26..0fed5b6 100644 --- a/python_workflow_definition/src/python_workflow_definition/jobflow.py +++ b/python_workflow_definition/src/python_workflow_definition/jobflow.py @@ -33,7 +33,9 @@ def _get_nodes_dict(function_dict: dict): return nodes_dict, nodes_mapping_dict -def _get_edge_from_dict(target: str, key: str, value_dict: dict, nodes_mapping_dict: dict) -> dict: +def _get_edge_from_dict( + target: str, key: str, value_dict: dict, nodes_mapping_dict: dict +) -> dict: if len(value_dict["attributes"]) == 1: return { TARGET_LABEL: target, @@ -50,7 +52,9 @@ def _get_edge_from_dict(target: str, key: str, value_dict: dict, nodes_mapping_d } -def _get_edges_and_extend_nodes(flow_dict: dict, nodes_mapping_dict: dict, nodes_dict: dict): +def _get_edges_and_extend_nodes( + flow_dict: dict, nodes_mapping_dict: dict, nodes_dict: dict +): edges_lst = [] for job in flow_dict["jobs"]: for k, v in job["function_kwargs"].items(): @@ -222,7 +226,9 @@ def _get_input_dict(nodes_dict: dict) -> dict: return {k: v for k, v in nodes_dict.items() if not isfunction(v)} -def _get_workflow(nodes_dict: dict, input_dict: dict, total_dict: dict, source_handles_dict: dict) -> list: +def _get_workflow( + nodes_dict: dict, input_dict: dict, total_dict: dict, source_handles_dict: dict +) -> list: def get_attr_helper(obj, source_handle): if source_handle is None: return getattr(obj, "output") diff --git a/python_workflow_definition/src/python_workflow_definition/pyiron_base.py b/python_workflow_definition/src/python_workflow_definition/pyiron_base.py index f3f826c..bbca726 100644 --- a/python_workflow_definition/src/python_workflow_definition/pyiron_base.py +++ b/python_workflow_definition/src/python_workflow_definition/pyiron_base.py @@ -53,7 +53,9 @@ def _group_edges(edges_lst: list) -> list: return total_lst -def _get_source(nodes_dict: dict, delayed_object_dict: dict, source: str, source_handle: str): +def _get_source( + nodes_dict: dict, delayed_object_dict: dict, source: str, source_handle: str +): if source in delayed_object_dict.keys() and source_handle is not None: return ( 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 return nodes_dict[source] -def _get_delayed_object_dict(total_lst: list, nodes_dict: dict, source_handle_dict: dict, pyiron_project: Project) -> dict: +def _get_delayed_object_dict( + total_lst: list, nodes_dict: dict, source_handle_dict: dict, pyiron_project: Project +) -> dict: delayed_object_dict = {} for item in total_lst: key, input_dict = item @@ -175,7 +179,9 @@ def _get_connection_dict(delayed_object_updated_dict: dict, match_dict: dict): return connection_dict, lookup_dict -def _get_edges_dict(edges_lst: list, nodes_dict: dict, connection_dict: dict, lookup_dict: dict): +def _get_edges_dict( + edges_lst: list, nodes_dict: dict, connection_dict: dict, lookup_dict: dict +): edges_dict_lst = [] existing_connection_lst = [] for ep in edges_lst: @@ -217,7 +223,7 @@ def _get_edges_dict(edges_lst: list, nodes_dict: dict, connection_dict: dict, lo return edges_dict_lst -def load_workflow_json(file_name: str, project: Optional[Project]=None): +def load_workflow_json(file_name: str, project: Optional[Project] = None): if project is None: project = Project(".") @@ -248,7 +254,9 @@ def load_workflow_json(file_name: str, project: Optional[Project]=None): return list(delayed_object_dict.values()) -def write_workflow_json(delayed_object: DelayedObject, file_name: str="workflow.json"): +def write_workflow_json( + delayed_object: DelayedObject, file_name: str = "workflow.json" +): nodes_dict, edges_lst = delayed_object.get_graph() nodes_dict, edges_lst = _remove_server_obj( nodes_dict=nodes_dict, edges_lst=edges_lst diff --git a/qe_xml_parser/src/qe_xml_parser/parsers.py b/qe_xml_parser/src/qe_xml_parser/parsers.py index 1b066bd..ab9395b 100644 --- a/qe_xml_parser/src/qe_xml_parser/parsers.py +++ b/qe_xml_parser/src/qe_xml_parser/parsers.py @@ -12,20 +12,34 @@ def parse_pw(xml_file): """Parse a Quantum Espresso XML output file.""" - xml_dict = XMLSchema(str(files(schemas) / 'qes_230310.xsd')).to_dict(xml_file) + xml_dict = XMLSchema(str(files(schemas) / "qes_230310.xsd")).to_dict(xml_file) parsed_results = {} try: - cell = numpy.array( - [ v for v in xml_dict['output']['atomic_structure']['cell'].values()] - ) * CONSTANTS.bohr_to_ang - symbols = [el['@name'] for el in xml_dict['output']['atomic_structure']['atomic_positions']['atom']] - positions = numpy.array( - [el['$'] for el in xml_dict['output']['atomic_structure']['atomic_positions']['atom']] - ) * CONSTANTS.bohr_to_ang - - parsed_results['ase_structure'] = Atoms( + cell = ( + numpy.array( + [v for v in xml_dict["output"]["atomic_structure"]["cell"].values()] + ) + * CONSTANTS.bohr_to_ang + ) + symbols = [ + el["@name"] + for el in xml_dict["output"]["atomic_structure"]["atomic_positions"]["atom"] + ] + positions = ( + numpy.array( + [ + el["$"] + for el in xml_dict["output"]["atomic_structure"][ + "atomic_positions" + ]["atom"] + ] + ) + * CONSTANTS.bohr_to_ang + ) + + parsed_results["ase_structure"] = Atoms( cell=cell, positions=positions, symbols=symbols, @@ -35,14 +49,20 @@ def parse_pw(xml_file): pass try: - parsed_results['energy'] = xml_dict['output']['total_energy']['etot'] * CONSTANTS.ry_to_ev + parsed_results["energy"] = ( + xml_dict["output"]["total_energy"]["etot"] * CONSTANTS.ry_to_ev + ) except KeyError: pass try: - parsed_results['forces'] = ( - numpy.array(xml_dict['output']['forces']['$']).reshape(xml_dict['output']['forces']['@dims']) - * 2 * CONSTANTS.ry_to_ev / CONSTANTS.bohr_to_ang + parsed_results["forces"] = ( + numpy.array(xml_dict["output"]["forces"]["$"]).reshape( + xml_dict["output"]["forces"]["@dims"] + ) + * 2 + * CONSTANTS.ry_to_ev + / CONSTANTS.bohr_to_ang ) except KeyError: pass