From 7737e8b497890ccbafc2e13d84f03096f355423f Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Fri, 8 Sep 2023 13:38:11 +0000 Subject: [PATCH 01/12] Start writing documentation for viewers widgets --- docs/source/widget-list/aiida_viewers.rst | 26 ++++++++++++++++ docs/source/widget-list/index.rst | 1 + notebooks/aiida_datatypes_viewers.ipynb | 36 +++++++++++++++-------- 3 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 docs/source/widget-list/aiida_viewers.rst diff --git a/docs/source/widget-list/aiida_viewers.rst b/docs/source/widget-list/aiida_viewers.rst new file mode 100644 index 000000000..362e5fb84 --- /dev/null +++ b/docs/source/widget-list/aiida_viewers.rst @@ -0,0 +1,26 @@ +.. _widget-list:aiida_viewers: + +************* +AiiDA Viewers +************* + +This module contains the viewers, which are used to visualize AiiDA objects. + +**How to visualize an AiiDA object** +.. _widget-list:aiida_viewers:how-to-visualize-an-aiida-object: + +The simples way is to import the :py:meth:`~aiidalab_widgets_base.viewer` function and call it with the object: + +.. code-block:: python + + from aiida import orm + from aiidalab_widgets_base import viewer + + p = Dict(dict={ + 'parameter 1' : 'some string', + 'parameter 2' : 2, + 'parameter 3' : 3.0, + 'parameter 4' : [1, 2, 3], + }) + vwr = viewer(p.store(), downloadable=True) + display(vwr) diff --git a/docs/source/widget-list/index.rst b/docs/source/widget-list/index.rst index 71ca43782..6f27da588 100644 --- a/docs/source/widget-list/index.rst +++ b/docs/source/widget-list/index.rst @@ -11,6 +11,7 @@ See also the `corresponding git repository Date: Fri, 8 Sep 2023 23:31:17 +0200 Subject: [PATCH 02/12] Move the content of aiida_viwers into aiida_datatypes_viewers.ipynb --- docs/source/widget-list/aiida_viewers.rst | 26 ----- docs/source/widget-list/index.rst | 1 - notebooks/aiida_datatypes_viewers.ipynb | 128 ++++++++++++++++++---- 3 files changed, 109 insertions(+), 46 deletions(-) delete mode 100644 docs/source/widget-list/aiida_viewers.rst diff --git a/docs/source/widget-list/aiida_viewers.rst b/docs/source/widget-list/aiida_viewers.rst deleted file mode 100644 index 362e5fb84..000000000 --- a/docs/source/widget-list/aiida_viewers.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. _widget-list:aiida_viewers: - -************* -AiiDA Viewers -************* - -This module contains the viewers, which are used to visualize AiiDA objects. - -**How to visualize an AiiDA object** -.. _widget-list:aiida_viewers:how-to-visualize-an-aiida-object: - -The simples way is to import the :py:meth:`~aiidalab_widgets_base.viewer` function and call it with the object: - -.. code-block:: python - - from aiida import orm - from aiidalab_widgets_base import viewer - - p = Dict(dict={ - 'parameter 1' : 'some string', - 'parameter 2' : 2, - 'parameter 3' : 3.0, - 'parameter 4' : [1, 2, 3], - }) - vwr = viewer(p.store(), downloadable=True) - display(vwr) diff --git a/docs/source/widget-list/index.rst b/docs/source/widget-list/index.rst index 6f27da588..71ca43782 100644 --- a/docs/source/widget-list/index.rst +++ b/docs/source/widget-list/index.rst @@ -11,7 +11,6 @@ See also the `corresponding git repository Date: Fri, 8 Sep 2023 23:39:26 +0200 Subject: [PATCH 03/12] fix a bunch of typos --- notebooks/aiida_datatypes_viewers.ipynb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/notebooks/aiida_datatypes_viewers.ipynb b/notebooks/aiida_datatypes_viewers.ipynb index 6d07c8e2a..866ec7287 100644 --- a/notebooks/aiida_datatypes_viewers.ipynb +++ b/notebooks/aiida_datatypes_viewers.ipynb @@ -15,7 +15,7 @@ "source": [ "## How to visualize an AiiDA object\n", "\n", - "The simples way is to import the {py:meth}`~aiidalab_widgets_base.viewer` function and call it with the object:\n" + "The simplest way is to import the {py:meth}`~aiidalab_widgets_base.viewer` function and call it with the object:\n" ] }, { @@ -44,7 +44,7 @@ "source": [ "The function takes two inputs: the object to show and an optional flag for displaying the download button.\n", "The function gives back a viewer object for notebook display.\n", - "If the viwer for the object is not available, the object itself is returned, allowing for a very basic representation of it.\n", + "If the viewer for the object is not available, the object itself is returned, allowing for a very basic representation of it.\n", "\n", "An alternative way is to use the {py:class}`~aiidalab_widgets_base.AiidaNodeViewWidget` class directly:\n" ] @@ -108,7 +108,7 @@ "The viewers for several AiiDA objects are available:\n", "\n", "* {py:class}`~aiidalab_widgets_base.viewers.DictViewer` for the `orm.Dict` object representation.\n", - "* {py:class}~aiidalab_widgets_base.viewers.StructureDataViewer` for the `orm.StructureData` and `orm.CifData` object representation.\n", + "* {py:class}`~aiidalab_widgets_base.viewers.StructureDataViewer` for the `orm.StructureData` and `orm.CifData` object representation.\n", "* {py:class}`~aiidalab_widgets_base.viewers.FolderDataViewer` for the `orm.FolderDataViewer` object representation.\n", "* and others...\n", "\n", @@ -119,7 +119,10 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Create a custom viewer" + "## Create a custom viewer\n", + "\n", + "\n", + "To create a custom viewer ..." ] }, { From 543a7f59f9789aaaf3382965aed6d8c55a869bcd Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Fri, 8 Sep 2023 21:43:30 +0000 Subject: [PATCH 04/12] Simplify notebook. --- notebooks/aiida_datatypes_viewers.ipynb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/notebooks/aiida_datatypes_viewers.ipynb b/notebooks/aiida_datatypes_viewers.ipynb index 866ec7287..6b0970b82 100644 --- a/notebooks/aiida_datatypes_viewers.ipynb +++ b/notebooks/aiida_datatypes_viewers.ipynb @@ -157,11 +157,6 @@ "metadata": {}, "outputs": [], "source": [ - "# create molecule\n", - "from ase.build import molecule, bulk\n", - "m = molecule('H2O')\n", - "m.center(vacuum=2.0)\n", - "#\n", "# create bulk Pt\n", "pt = bulk('Pt', cubic = True)" ] @@ -321,13 +316,6 @@ "result, calcfunction = run_get_node(add, Int(3), Int(4))\n", "display(viewer(calcfunction))" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From 14d73b13580a986b6cb1e5f1918e3196dcbe8251 Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Fri, 8 Sep 2023 23:50:29 +0200 Subject: [PATCH 05/12] Further improve the viewer notebook. --- notebooks/aiida_datatypes_viewers.ipynb | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/notebooks/aiida_datatypes_viewers.ipynb b/notebooks/aiida_datatypes_viewers.ipynb index 6b0970b82..8a0fd801d 100644 --- a/notebooks/aiida_datatypes_viewers.ipynb +++ b/notebooks/aiida_datatypes_viewers.ipynb @@ -125,6 +125,13 @@ "To create a custom viewer ..." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## List of build-in viewers" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -151,16 +158,6 @@ "display(vwr)" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# create bulk Pt\n", - "pt = bulk('Pt', cubic = True)" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -176,6 +173,9 @@ "metadata": {}, "outputs": [], "source": [ + "# create bulk Pt\n", + "pt = bulk('Pt', cubic = True)\n", + "\n", "CifData = plugins.DataFactory('core.cif')\n", "s = CifData(ase=pt)\n", "vwr = viewer(s.store(), configuration_tabs=['Selection', 'Appearance', 'Cell', 'Download'])\n", @@ -186,7 +186,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## StructureData" + "### StructureData" ] }, { @@ -205,7 +205,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## BandsData" + "### BandsData" ] }, { @@ -258,7 +258,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## FolderData" + "### FolderData" ] }, { @@ -283,7 +283,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Workfunctions and Calcfunctions" + "### Workfunctions and Calcfunctions" ] }, { From f71ff3f623cb0b6d475f3dd7fc803e06b30ce137 Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Fri, 8 Sep 2023 23:51:07 +0200 Subject: [PATCH 06/12] Rename aiida_datatypes_viewers.ipynb tp viewers.ipynb --- notebooks/{aiida_datatypes_viewers.ipynb => viewers.ipynb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename notebooks/{aiida_datatypes_viewers.ipynb => viewers.ipynb} (100%) diff --git a/notebooks/aiida_datatypes_viewers.ipynb b/notebooks/viewers.ipynb similarity index 100% rename from notebooks/aiida_datatypes_viewers.ipynb rename to notebooks/viewers.ipynb From fb7f17d050330378fc3f2a3b6d6634586108cd5c Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Wed, 4 Oct 2023 19:33:14 +0200 Subject: [PATCH 07/12] small changes. --- docs/source/widget-list/index.rst | 2 +- notebooks/viewers.ipynb | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/source/widget-list/index.rst b/docs/source/widget-list/index.rst index 71ca43782..d967edbf6 100644 --- a/docs/source/widget-list/index.rst +++ b/docs/source/widget-list/index.rst @@ -11,7 +11,7 @@ See also the `corresponding git repository Date: Fri, 3 Nov 2023 10:59:15 +0100 Subject: [PATCH 08/12] Complete the viewer documentation notebook. --- notebooks/viewers.ipynb | 138 +++++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 53 deletions(-) diff --git a/notebooks/viewers.ipynb b/notebooks/viewers.ipynb index ee64e98e5..09bf7e3b4 100644 --- a/notebooks/viewers.ipynb +++ b/notebooks/viewers.ipynb @@ -15,8 +15,7 @@ "metadata": {}, "source": [ "## How to visualize an AiiDA object\n", - ".. \\_widget-list:viewers:how-to-visualize-an-aiida-object:\n", - "\n", + "(widget:viwers:how-to-visualize-an-aiida-object)=\n", "\n", "The simplest way is to import the {py:meth}`~aiidalab_widgets_base.viewer` function and call it with the object:\n" ] @@ -49,7 +48,7 @@ "The function gives back a viewer object for notebook display.\n", "If the viewer for the object is not available, the object itself is returned, allowing for a very basic representation of it.\n", "\n", - "An alternative way is to use the {py:class}`~aiidalab_widgets_base.AiidaNodeViewWidget` class directly:\n" + "An alternative way is to use the {py:class}`~aiidalab_widgets_base.AiidaNodeViewWidget` class:\n" ] }, { @@ -58,6 +57,7 @@ "metadata": {}, "outputs": [], "source": [ + "from aiida import orm\n", "from aiidalab_widgets_base import AiidaNodeViewWidget\n", "\n", "p = orm.Dict(dict={\n", @@ -85,8 +85,8 @@ "outputs": [], "source": [ "from aiida import plugins\n", - "\n", "from ase.build import molecule\n", + "\n", "m = molecule('H2O')\n", "m.center(vacuum=2.0)\n", "\n", @@ -108,35 +108,26 @@ "metadata": {}, "source": [ "## Build-in viewers\n", - ".. \\_widget-list:viewers:build-in-viewers:\n", + "(widget-list:viewers:build-in-viewers)=\n", "\n", "The viewers for several AiiDA objects are available:\n", "\n", "* {py:class}`~aiidalab_widgets_base.viewers.DictViewer` for the `orm.Dict` object representation.\n", "* {py:class}`~aiidalab_widgets_base.viewers.StructureDataViewer` for the `orm.StructureData` and `orm.CifData` object representation.\n", "* {py:class}`~aiidalab_widgets_base.viewers.FolderDataViewer` for the `orm.FolderDataViewer` object representation.\n", + "* {py:class}`~aiidalab_widgets_base.viewers.BandsDataViewer` for the `orm.BandsData` object representation.\n", + "* {py:class}`~aiidalab_widgets_base.viewers.ProcessNodeViewerWidget` for the `orm.ProcessNode` (and its children such as `orm.CalcJobNode` or `orm.WorkChainNode`) object representation.\n", "* and others...\n", "\n", "To see the full list of available viewers, visit the module API documentation." ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create a custom viewer\n", - ".. \\_widget-list:viewers:create-a-custom-viewer:\n", - "\n", - "\n", - "To create a custom viewer ..." - ] - }, { "cell_type": "markdown", "metadata": {}, "source": [ "## List of build-in viewers\n", - ".. \\_widget-list:viewers:list-of-build-in-viewers:\n", + "(widget-list:viewers:list-of-build-in-viewers)=\n", "\n", "\n", "In this section, we list the build-in viewers and show how to use them." @@ -147,6 +138,7 @@ "metadata": {}, "source": [ "### Dict viewer\n", + "(widget-list:viewers:list-of-build-in-viewers:dict-viewer)=\n", "\n", "The {py:class}`~aiidalab_widgets_base.viewers.DictViewer` is used to visualize dictionaries." ] @@ -157,14 +149,17 @@ "metadata": {}, "outputs": [], "source": [ + "from aiidalab_widgets_base.viewers import DictViewer\n", + "from aiida import plugins\n", + "\n", "Dict = plugins.DataFactory('core.dict')\n", "p = Dict(dict={\n", - " 'Parameter' :'super long string '*4,\n", + " 'Parameter' :'super long string '*4,\n", " 'parameter 2' :'value 2',\n", " 'parameter 3' : 1,\n", " 'parameter 4' : 2,\n", "})\n", - "vwr = viewer(p.store(), downloadable=True)\n", + "vwr = DictViewer(p.store(), downloadable=True)\n", "display(vwr)" ] }, @@ -172,9 +167,10 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### CifData\n", + "### CifData and StructureData viewer\n", + "(widget-list:viewers:list-of-build-in-viewers:cif-and-strucutre-data-viewer)=\n", "\n", - "The {py:class}`~aiidalab_widgets_base.viewers.CifDataViewer` is used to visualize CifData objects." + "The {py:class}`~aiidalab_widgets_base.viewers.StructureDataViewer` is used to visualize both `CifData`` and `StructureData`` objects." ] }, { @@ -183,39 +179,37 @@ "metadata": {}, "outputs": [], "source": [ + "from ase.build import molecule, bulk\n", + "from aiidalab_widgets_base.viewers import StructureDataViewer\n", + "\n", + "\n", "# create bulk Pt\n", "pt = bulk('Pt', cubic = True)\n", "\n", + "# Cif data.\n", "CifData = plugins.DataFactory('core.cif')\n", "s = CifData(ase=pt)\n", - "vwr = viewer(s.store(), configuration_tabs=['Selection', 'Appearance', 'Cell', 'Download'])\n", - "display(vwr)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### StructureData" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ + "vwr_cif = StructureDataViewer(s.store())\n", + "display(vwr_cif)\n", + "\n", + "# Structure data.\n", + "m = molecule('H2O')\n", + "m.center(vacuum=2.0)\n", + "\n", "StructureData = plugins.DataFactory('core.structure')\n", "s = StructureData(ase=m)\n", - "vwr = viewer(s.store())\n", - "display(vwr)" + "vwr_structure = StructureDataViewer(s.store())\n", + "display(vwr_structure)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### BandsData" + "### BandsData viewer\n", + "(widget-list:viewers:list-of-build-in-viewers:bands-data-viewer)=\n", + "\n", + "The {py:class}`~aiidalab_widgets_base.viewers.BandsDataViewer` is used to visualize `BandsData` objects." ] }, { @@ -225,6 +219,9 @@ "outputs": [], "source": [ "import numpy as np\n", + "from aiida import plugins\n", + "from aiidalab_widgets_base.viewers import BandsDataViewer\n", + "\n", "BandsData = plugins.DataFactory('core.array.bands')\n", "bs = BandsData()\n", "kpoints = np.array([[0. , 0. , 0. ], # array shape is 12 * 3\n", @@ -260,7 +257,9 @@ " (6, u'Z'),\n", " (11, u'U')]\n", "bs.labels = labels\n", - "vwr = viewer(bs.store(), downloadable=True)\n", + "\n", + "\n", + "vwr = BandsDataViewer(bs.store(), downloadable=True)\n", "display(vwr)" ] }, @@ -268,7 +267,10 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### FolderData" + "### FolderData viewer\n", + "(widget-list:viewers:list-of-build-in-viewers:folder-data-viewer)=\n", + "\n", + "The {py:class}`~aiidalab_widgets_base.viewers.FolderDataViewer` is used to visualize `FolderData` objects." ] }, { @@ -277,6 +279,10 @@ "metadata": {}, "outputs": [], "source": [ + "import io\n", + "from aiida import plugins\n", + "from aiidalab_widgets_base.viewers import FolderDataViewer\n", + "\n", "FolderData = plugins.DataFactory('core.folder')\n", "fd = FolderData()\n", "with io.StringIO('content of test1 filelike') as fobj:\n", @@ -293,7 +299,10 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Workfunctions and Calcfunctions" + "### ProcessNode viewer\n", + "(widget-list:viewers:list-of-build-in-viewers:workfunctions-and-calcfunctions)=\n", + "\n", + "The {py:class}`~aiidalab_widgets_base.viewers.ProcessNodeViewerWidget` is used to visualize `CalcFunctionNode` and `WorkFunctionNode` objects." ] }, { @@ -303,18 +312,30 @@ "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" + "from aiida import engine, orm\n", + "from aiidalab_widgets_base import ProcessNodeViewerWidget\n", + "result, workfunction = engine.run_get_node(add_multiply, orm.Int(3), orm.Int(4), orm.Int(5))\n", + "vwr_workfunction = ProcessNodeViewerWidget(workfunction)\n", + "display(vwr_workfunction)\n", + "\n", + "result, calcfunction = engine.run_get_node(add, int.Int(3), int.Int(4))\n", + "vwr_calcfunction = ProcessNodeViewerWidget(calcfunction)\n", + "display(vwr_calcfunction)" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "result, workfunction = run_get_node(add_multiply, Int(3), Int(4), Int(5))\n", - "display(viewer(workfunction))" + "## Create a custom viewer\n", + "(widget-list:viewers:create-a-custom-viewer)=\n", + "\n", + "To create a custom viewer one usually inherits from an existing ipywidgets widget and implements the logic for displaying the object.\n", + "The only requirement is that the first argument of the constructor is the object to visualize.\n", + "\n", + "Also to make the new class recognizable by the {py:meth}`~aiidalab_widgets_base.viewer` function, the class should be decorated with the {py:func}`~aiidalab_widgets_base.register_viewer_widget` decorator.\n", + "\n", + "To demonstrate how this works we create a simple viewer for the `orm.Int` object:" ] }, { @@ -323,8 +344,19 @@ "metadata": {}, "outputs": [], "source": [ - "result, calcfunction = run_get_node(add, Int(3), Int(4))\n", - "display(viewer(calcfunction))" + "\n", + "from aiidalab_widgets_base import register_viewer_widget\n", + "import ipywidgets as ipw\n", + "from aiida import orm\n", + "\n", + "@register_viewer_widget(orm.Int)\n", + "class IntViewerWidget(ipw.HTML):\n", + " def __init__(self, node, **kwargs):\n", + " super().__init__(**kwargs)\n", + " self.value = f'Int object:

{node.value}

'\n", + "\n", + "vwr = viewer(orm.Int(3).store())\n", + "display(vwr)" ] } ], From f0e86f20e1bf4a2aecd86b603d2f9040480c0786 Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Fri, 3 Nov 2023 11:16:04 +0000 Subject: [PATCH 09/12] Small update. --- notebooks/viewers.ipynb | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/notebooks/viewers.ipynb b/notebooks/viewers.ipynb index 09bf7e3b4..7b017001b 100644 --- a/notebooks/viewers.ipynb +++ b/notebooks/viewers.ipynb @@ -285,9 +285,9 @@ "\n", "FolderData = plugins.DataFactory('core.folder')\n", "fd = FolderData()\n", - "with io.StringIO('content of test1 filelike') as fobj:\n", + "with io.StringIO('content of test1 file') as fobj:\n", " fd.put_object_from_filelike(fobj, path='test1.txt')\n", - "with io.StringIO('content of test2 filelike') as fobj:\n", + "with io.StringIO('content of test2 file') as fobj:\n", " fd.put_object_from_filelike(fobj, path='test2.txt')\n", "with io.StringIO(u'content of test_long file'*1000) as fobj:\n", " fd.put_object_from_filelike(fobj, path='test_long.txt')\n", @@ -313,12 +313,12 @@ "source": [ "from aiida.workflows.arithmetic.add_multiply import add, add_multiply\n", "from aiida import engine, orm\n", - "from aiidalab_widgets_base import ProcessNodeViewerWidget\n", + "from aiidalab_widgets_base.viewers import ProcessNodeViewerWidget\n", "result, workfunction = engine.run_get_node(add_multiply, orm.Int(3), orm.Int(4), orm.Int(5))\n", "vwr_workfunction = ProcessNodeViewerWidget(workfunction)\n", "display(vwr_workfunction)\n", "\n", - "result, calcfunction = engine.run_get_node(add, int.Int(3), int.Int(4))\n", + "result, calcfunction = engine.run_get_node(add, orm.Int(3), orm.Int(4))\n", "vwr_calcfunction = ProcessNodeViewerWidget(calcfunction)\n", "display(vwr_calcfunction)" ] @@ -335,6 +335,7 @@ "\n", "Also to make the new class recognizable by the {py:meth}`~aiidalab_widgets_base.viewer` function, the class should be decorated with the {py:func}`~aiidalab_widgets_base.register_viewer_widget` decorator.\n", "\n", + "\n", "To demonstrate how this works we create a simple viewer for the `orm.Int` object:" ] }, @@ -344,20 +345,36 @@ "metadata": {}, "outputs": [], "source": [ - "\n", "from aiidalab_widgets_base import register_viewer_widget\n", "import ipywidgets as ipw\n", - "from aiida import orm\n", + "from aiida.orm import Int\n", "\n", - "@register_viewer_widget(orm.Int)\n", + "@register_viewer_widget('data.core.int.Int.')\n", "class IntViewerWidget(ipw.HTML):\n", " def __init__(self, node, **kwargs):\n", " super().__init__(**kwargs)\n", - " self.value = f'Int object:

{node.value}

'\n", + " self.value = f'Int object: {node.value}'\n", "\n", "vwr = viewer(orm.Int(3).store())\n", "display(vwr)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The string to be put as an argument of the `register_viewer_widget` decorator can be obtained from the `node_type` property of an object." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "i_node = orm.Int(1)\n", + "print(i_node.node_type)" + ] } ], "metadata": { From 44696b06d31e04093bb90f737dd345a9659864b9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Fri, 3 Nov 2023 15:03:39 +0100 Subject: [PATCH 10/12] Try to fix the notebook test. --- tests_notebooks/test_notebooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests_notebooks/test_notebooks.py b/tests_notebooks/test_notebooks.py index 2cec668c6..66da4d812 100644 --- a/tests_notebooks/test_notebooks.py +++ b/tests_notebooks/test_notebooks.py @@ -17,7 +17,7 @@ def test_process_list(selenium_driver, final_screenshot): def test_aiida_datatypes_viewers(selenium_driver, final_screenshot): - driver = selenium_driver("notebooks/aiida_datatypes_viewers.ipynb") + driver = selenium_driver("notebooks/viewers.ipynb") driver.set_window_size(1000, 2000) driver.find_element(By.CLASS_NAME, "widget-label") driver.find_element(By.XPATH, '//button[text()="Clear selection"]') From 48efea4ccc5733b6eb420dd9712b3c009404e4b9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Fri, 3 Nov 2023 15:14:26 +0100 Subject: [PATCH 11/12] Remove unnecessary check. --- tests_notebooks/test_notebooks.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests_notebooks/test_notebooks.py b/tests_notebooks/test_notebooks.py index 66da4d812..0207d8820 100644 --- a/tests_notebooks/test_notebooks.py +++ b/tests_notebooks/test_notebooks.py @@ -21,7 +21,6 @@ def test_aiida_datatypes_viewers(selenium_driver, final_screenshot): driver.set_window_size(1000, 2000) driver.find_element(By.CLASS_NAME, "widget-label") driver.find_element(By.XPATH, '//button[text()="Clear selection"]') - driver.find_element(By.XPATH, '//p[text()="Warning:"]') time.sleep(5) From 3147c2338c88b75b859c3d0d479b2b48bbd64147 Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Fri, 3 Nov 2023 15:25:30 +0100 Subject: [PATCH 12/12] review --- notebooks/viewers.ipynb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/notebooks/viewers.ipynb b/notebooks/viewers.ipynb index 7b017001b..2d93bdb0b 100644 --- a/notebooks/viewers.ipynb +++ b/notebooks/viewers.ipynb @@ -1,5 +1,16 @@ { "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Load the default AiiDA profile.\n", + "from aiida import orm, load_profile\n", + "load_profile();" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -26,8 +37,6 @@ "metadata": {}, "outputs": [], "source": [ - "from aiida import orm, load_profile\n", - "load_profile()\n", "from aiidalab_widgets_base import viewer\n", "\n", "p = orm.Dict(dict={\n",