From 3fb7c28902c8d817ae5981b54722c18731c0ba6a Mon Sep 17 00:00:00 2001 From: liamhuber Date: Sun, 19 Nov 2023 13:41:57 -0800 Subject: [PATCH 1/3] Make macros with a meta node --- .../atomistics_library/macronodes.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pyiron_workflow/atomistics_library/macronodes.py b/pyiron_workflow/atomistics_library/macronodes.py index 58698caa..eac0572b 100644 --- a/pyiron_workflow/atomistics_library/macronodes.py +++ b/pyiron_workflow/atomistics_library/macronodes.py @@ -10,6 +10,40 @@ ) +def atomistics_meta_macro(task_generator_node_class, macro_name) -> type[Macro]: + + def generic_macro(wf: Macro) -> None: + wf.tasks = task_generator_node_class() + wf.structures = generate_structures(instance=wf.tasks) + wf.calc = calc_with_calculator(task_dict=wf.structures) + wf.fit = analyse_structures(instance=wf.tasks, output_dict=wf.calc) + inputs_map = { + # Dynamically expose _all_ task generator input directly on the macro + "tasks__" + s: s for s in wf.tasks.inputs.labels + } + inputs_map["calc__calculator"] = "calculator" + wf.inputs_map = inputs_map + wf.outputs_map = {"fit__result_dict": "result_dict"} + generic_macro.__name__ = macro_name + + return macro_node()(generic_macro) + + +elastic_matrix = atomistics_meta_macro( + get_elastic_matrix_task_generator, "elastic_matrix" +) + + +energy_volume_curve = atomistics_meta_macro( + get_evcurve_task_generator, "energy_volume_curve", +) + +phonons = atomistics_meta_macro(get_phonons_task_generator, "phonons") + + + + + @single_value_node("instance") def get_instance(instance): return instance @@ -80,7 +114,11 @@ def get_phonons(wf: Macro) -> None: nodes = [ + elastic_matrix, + energy_volume_curve, + phonons, get_energy_volume_curve, get_elastic_matrix, get_phonons, + ] From dcd948b012dd15eb03cebc8a02b2f9e6d426dc7d Mon Sep 17 00:00:00 2001 From: liamhuber Date: Sun, 19 Nov 2023 13:42:38 -0800 Subject: [PATCH 2/3] Remove the old versions --- .../atomistics_library/macronodes.py | 77 ------------------- 1 file changed, 77 deletions(-) diff --git a/pyiron_workflow/atomistics_library/macronodes.py b/pyiron_workflow/atomistics_library/macronodes.py index eac0572b..c612bc62 100644 --- a/pyiron_workflow/atomistics_library/macronodes.py +++ b/pyiron_workflow/atomistics_library/macronodes.py @@ -1,5 +1,4 @@ from pyiron_workflow.macro import Macro, macro_node -from pyiron_workflow.function import single_value_node from pyiron_workflow.atomistics_library.calculatornodes import calc_with_calculator from pyiron_workflow.atomistics_library.tasknodes import ( get_elastic_matrix_task_generator, @@ -41,84 +40,8 @@ def generic_macro(wf: Macro) -> None: phonons = atomistics_meta_macro(get_phonons_task_generator, "phonons") - - - -@single_value_node("instance") -def get_instance(instance): - return instance - - -@macro_node() -def internal_macro(wf: Macro) -> None: - wf.get_instance = get_instance() - wf.generate_structures = generate_structures(instance=wf.get_instance) - wf.calc_with_calculator = calc_with_calculator(task_dict=wf.generate_structures) - wf.fit = analyse_structures( - instance=wf.get_instance, output_dict=wf.calc_with_calculator - ) - wf.inputs_map = { - "get_instance__instance": "instance", - "calc_with_calculator__calculator": "calculator", - } - wf.outputs_map = {"fit__fit_dict": "fit_dict"} - - -@macro_node() -def get_energy_volume_curve(wf: Macro) -> None: - wf.get_task_generator = get_evcurve_task_generator() - wf.internal = internal_macro(instance=wf.get_task_generator) - wf.inputs_map = { - "get_task_generator__structure": "structure", - "get_task_generator__num_points": "num_points", - "get_task_generator__fit_type": "fit_type", - "get_task_generator__fit_order": "fit_order", - "get_task_generator__vol_range": "vol_range", - "get_task_generator__axes": "axes", - "get_task_generator__strains": "strains", - "internal__calculator": "calculator", - } - wf.outputs_map = {"internal__fit_dict": "fit_dict"} - - -@macro_node() -def get_elastic_matrix(wf: Macro) -> None: - wf.get_task_generator = get_elastic_matrix_task_generator() - wf.internal = internal_macro(instance=wf.get_task_generator) - wf.inputs_map = { - "get_task_generator__structure": "structure", - "get_task_generator__num_of_point": "num_of_point", - "get_task_generator__eps_range": "eps_range", - "get_task_generator__sqrt_eta": "sqrt_eta", - "get_task_generator__fit_order": "fit_order", - "internal__calculator": "calculator", - } - wf.outputs_map = {"internal__fit_dict": "fit_dict"} - - -@macro_node() -def get_phonons(wf: Macro) -> None: - wf.get_task_generator = get_phonons_task_generator() - wf.internal = internal_macro(instance=wf.get_task_generator) - wf.inputs_map = { - "get_task_generator__structure": "structure", - "get_task_generator__interaction_range": "interaction_range", - "get_task_generator__factor": "factor", - "get_task_generator__displacement": "displacement", - "get_task_generator__dos_mesh": "dos_mesh", - "get_task_generator__primitive_matrix": "primitive_matrix", - "get_task_generator__number_of_snapshots": "number_of_snapshots", - "internal__calculator": "calculator", - } - wf.outputs_map = {"internal__fit_dict": "fit_dict"} - - nodes = [ elastic_matrix, energy_volume_curve, phonons, - get_energy_volume_curve, - get_elastic_matrix, - get_phonons, - ] From d39289072c32b125e65b291c0482d6317994e30c Mon Sep 17 00:00:00 2001 From: pyiron-runner Date: Mon, 20 Nov 2023 04:14:43 +0000 Subject: [PATCH 3/3] Format black --- pyiron_workflow/atomistics_library/macronodes.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyiron_workflow/atomistics_library/macronodes.py b/pyiron_workflow/atomistics_library/macronodes.py index c612bc62..f65b8789 100644 --- a/pyiron_workflow/atomistics_library/macronodes.py +++ b/pyiron_workflow/atomistics_library/macronodes.py @@ -10,7 +10,6 @@ def atomistics_meta_macro(task_generator_node_class, macro_name) -> type[Macro]: - def generic_macro(wf: Macro) -> None: wf.tasks = task_generator_node_class() wf.structures = generate_structures(instance=wf.tasks) @@ -18,11 +17,13 @@ def generic_macro(wf: Macro) -> None: wf.fit = analyse_structures(instance=wf.tasks, output_dict=wf.calc) inputs_map = { # Dynamically expose _all_ task generator input directly on the macro - "tasks__" + s: s for s in wf.tasks.inputs.labels + "tasks__" + s: s + for s in wf.tasks.inputs.labels } inputs_map["calc__calculator"] = "calculator" wf.inputs_map = inputs_map wf.outputs_map = {"fit__result_dict": "result_dict"} + generic_macro.__name__ = macro_name return macro_node()(generic_macro) @@ -34,7 +35,8 @@ def generic_macro(wf: Macro) -> None: energy_volume_curve = atomistics_meta_macro( - get_evcurve_task_generator, "energy_volume_curve", + get_evcurve_task_generator, + "energy_volume_curve", ) phonons = atomistics_meta_macro(get_phonons_task_generator, "phonons")