diff --git a/aiidalab_widgets_base/viewers.py b/aiidalab_widgets_base/viewers.py index 3ed0f6aad..77897bdf0 100644 --- a/aiidalab_widgets_base/viewers.py +++ b/aiidalab_widgets_base/viewers.py @@ -12,6 +12,7 @@ import spglib import traitlets from aiida.cmdline.utils.common import get_workchain_report +from aiida.cmdline.utils.query import formatting from aiida.orm import Node from ase import Atoms, neighborlist from ase.cell import Cell @@ -1164,18 +1165,28 @@ def __init__(self, bands, **kwargs): super().__init__(children, **kwargs) +@register_viewer_widget("process.calculation.calcfunction.CalcFunctionNode.") +@register_viewer_widget("process.calculation.calcjob.CalcJobNode.") +@register_viewer_widget("process.workflow.workfunction.WorkFunctionNode.") @register_viewer_widget("process.workflow.workchain.WorkChainNode.") -class WorkChainNodeViewerWidget(ipw.HTML): - def __init__(self, workchain, **kwargs): - self.workchain = workchain +class ProcessNodeViewerWidget(ipw.HTML): + def __init__(self, process, **kwargs): + self.process = process - # Displaying reports only from the selected workchain, - # NOT from its descendants - report = get_workchain_report(self.workchain, "REPORT", max_depth=1) + # Displaying reports only from the selected process, + # NOT from its descendants. + report = get_workchain_report(self.process, "REPORT", max_depth=1) # Filter out the first column with dates filtered_report = re.sub( r"^[0-9]{4}.*\| ([A-Z]+)\]", r"\1", report, flags=re.MULTILINE ) - self.value = f"
{filtered_report}
" + header = f""" + Process {process.process_label}, + State: {formatting.format_process_state(process.process_state.value)}, + UUID: {process.uuid} (pk: {process.pk})
+ Started {formatting.format_relative_time(process.ctime)}, + Last modified {formatting.format_relative_time(process.mtime)}
+ """ + self.value = f"{header}
{filtered_report}
" super().__init__(**kwargs) diff --git a/notebooks/aiida_datatypes_viewers.ipynb b/notebooks/aiida_datatypes_viewers.ipynb index 570f18e73..902a9d3e7 100644 --- a/notebooks/aiida_datatypes_viewers.ipynb +++ b/notebooks/aiida_datatypes_viewers.ipynb @@ -169,6 +169,44 @@ "vwr = viewer(fd.store(), downloadable=True)\n", "display(vwr)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Workfunctions and Calcfunctions" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from aiida.workflows.arithmetic.add_multiply import add, add_multiply\n", + "from aiida.engine import run_get_node\n", + "from aiida.orm import Int" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "result, workfunction = run_get_node(add_multiply, Int(3), Int(4), Int(5))\n", + "display(viewer(workfunction))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "result, calcfunction = run_get_node(add, Int(3), Int(4))\n", + "display(viewer(calcfunction))" + ] } ], "metadata": { @@ -187,7 +225,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.7.9" } }, "nbformat": 4,