Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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():
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(".")

Expand Down Expand Up @@ -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
Expand Down
48 changes: 34 additions & 14 deletions qe_xml_parser/src/qe_xml_parser/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
Loading