aiidateam / aiida-core

The official repository for the AiiDA code
https://aiida-core.readthedocs.io
Other
413 stars 184 forks source link

Implement _repr_html_ representation for base orm types #6378

Open danielhollas opened 2 months ago

danielhollas commented 2 months ago

Pretty-printing ORM objects in jupyter notebooks

Jupyter notebooks / ipython allow objects to define special methods for rich display, see:

https://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display

Specifically, it would be nice to implement HTML representation (_repr_html_) for a nice printing in HTML notebooks. And we could then reuse this in AiiDAlab (which is where my motivation comes from).

Describe the solution you'd like

Display something nicer than this:

image

Describe alternatives you've considered

We could implement this as viewer widgets in aiidalab-widgets-base (and we already do for some types such as Dict) but I don't see a good reason why not integrate it to aiida-core so it can be easily used elsewhere as well.

mbercx commented 2 months ago

As @superstar54 knows, I'm a big fan of having nicer representations in Jupyter notebooks, visualising the structure when a StructureData is returned (as I think he already implemented: https://github.com/aiidateam/aiida-atomistic/pull/18), or showing a band structure when a BandsData is returned. So big +1 from me.

superstar54 commented 2 months ago

:+1: For Jupyter notebooks, I suggest using _repr_mimebundle_, which provides more format (includes HTML) for complex data nodes, such as structure and bands.

I proposed a similar idea in the AiiDA meeting, that we provide a viewer for the data node, and one step further, also for the AiiDA WorkChain. The viewer for the workchain is similar to the result panel in QEApp. Thus, when the users finish a PwBandsWorkChain or XpsWorkchain, they can visualize the result (bands, spectra) of the WorkChain in the notebook directly by adding the node in the last line of the cell. In such a way, we really combine the power of AiiDAlab with AiiDA and provide user-friendly features.