Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add electronic_structure plugin #522

Merged
merged 10 commits into from
Oct 29, 2023
Merged

Conversation

superstar54
Copy link
Member

@superstar54 superstar54 commented Oct 21, 2023

This PR supports

  • showing the result from multiple plugins.
  • only shows the result panel when it is available.

One can use the workchain_labels to specify which plugins (outputs) are needed for this result panel. For example, the electronic_structure result panel needs pdos and bands.

class Result(ResultPanel):
    title = "Electronic Structure"
    workchain_labels = ["bands", "pdos"]

@codecov
Copy link

codecov bot commented Oct 21, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (b731978) 78.92% compared to head (5b486fd) 79.07%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #522      +/-   ##
==========================================
+ Coverage   78.92%   79.07%   +0.14%     
==========================================
  Files          45       47       +2     
  Lines        3213     3211       -2     
==========================================
+ Hits         2536     2539       +3     
+ Misses        677      672       -5     
Flag Coverage Δ
python-3.10 79.07% <94.64%> (+0.14%) ⬆️
python-3.8 79.11% <94.64%> (+0.14%) ⬆️
python-3.9 79.11% <94.64%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/aiidalab_qe/common/panel.py 86.95% <100.00%> (+0.28%) ⬆️
src/aiidalab_qe/plugins/bands/result.py 94.73% <100.00%> (+0.29%) ⬆️
...idalab_qe/plugins/electronic_structure/__init__.py 100.00% <100.00%> (ø)
src/aiidalab_qe/plugins/pdos/result.py 92.95% <100.00%> (+0.10%) ⬆️
tests/test_plugins_bands.py 100.00% <ø> (ø)
tests/test_plugins_electronic_structure.py 100.00% <100.00%> (ø)
tests/test_plugins_pdos.py 100.00% <ø> (ø)
tests/test_result.py 100.00% <ø> (ø)
...aiidalab_qe/plugins/electronic_structure/result.py 79.26% <94.44%> (ø)
src/aiidalab_qe/app/result/workchain_viewer.py 57.40% <88.88%> (-2.06%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@superstar54 superstar54 requested a review from unkcpz October 21, 2023 06:48
@superstar54 superstar54 added the enhancement New feature or request label Oct 21, 2023
Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @superstar54, I have two things ask to change, please have a look.

wcv = WorkChainViewer(wkchain.node)
assert (
"DOS grouped by:"
== wcv.result_tabs.children[2].children[0].children[0].children[0].value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea of all these children are, a detailed comment will be very useful.
Since now things are implemented as "Panel", is some of these children are panel? If so, I think Panel can have some way to associate children with name to make it easy to access.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test here is too detailed, and not necessary, so I removed it. A new test that checks the length of the panel children is added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that is better!

Comment on lines 210 to 224
children=[
ipw.HBox(
children=[
ipw.Label(
"DOS grouped by:",
layout=ipw.Layout(
justify_content="flex-start", width="120px"
),
),
group_dos_by,
]
),
],
layout={"margin": "0 0 30px 30px"},
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid a deep nest of widgets, if there are many, define it outside with a comment on what the box is for and where it is displayed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the code. Now, it's become more simple and clear.

@unkcpz
Copy link
Member

unkcpz commented Oct 23, 2023

BTW, there is no need to always merge the branch, if I find time to review I'll merge the main before I review. Usually, this happens before the final merge if there is no conflict.

@superstar54
Copy link
Member Author

@unkcpz I refactored the code and added detailed comments. It's ready for review.

Please focus on the plugin part, which is the primary purpose of this PR.

The part of plotting the electronic structure is simply copied and pasted from the previous code, with few updates. If the code needs polished, it is better to open another PR.

Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @superstar54, thanks a lot for refactoring, very beautiful! Just some minor questions.

bands=bands_data,
dos=dos_data,
)
if False not in results_ready:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if False not in results_ready:
if all(results_ready):

# add this plugin result panel
self.result_tabs.children += (result,)
self.result_tabs.set_title(
len(self.result_tabs.children) - 1, result.title
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess len(self.result_tabs.children) - 1 is the idx of the tab. Please have a variable for it with comment.

@@ -29,14 +29,15 @@ class Result(ResultPanel):
"""Result panel for the bands calculation."""

title = "Bands"
workchain_labels = ["bands"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this labels for? If there are more than one where will those shown?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One can use the workchain_labels to specify which plugins (outputs) are needed for this result panel. For example, the electronic_structure result panel needs pdos and bands.

workchain_labels = ["bands", "pdos"]

To make this clear, I added a comment in the ResultPanel.

wcv = WorkChainViewer(wkchain.node)
assert (
"DOS grouped by:"
== wcv.result_tabs.children[2].children[0].children[0].children[0].value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that is better!

tab = [
tab
for tab in wcv.result_tabs.children
if getattr(tab, "identifier", "") == "electronic_structure"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume identifier is a mendatory attribute of panel, so get this be:

Suggested change
if getattr(tab, "identifier", "") == "electronic_structure"
if tab.identifier == "electronic_structure"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at the comment above the code.

    # the built-in summary and structure tabs is not a plugin panel,
    # thus don't have identifiers
    ```

@superstar54
Copy link
Member Author

@unkcpz I updated the code based on your suggestions. It's ready for another review.

@superstar54 superstar54 requested a review from unkcpz October 27, 2023 20:30
Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @superstar54 ! All good for me. Ready to 🚢

@superstar54 superstar54 merged commit 8a550c8 into main Oct 29, 2023
15 of 17 checks passed
@superstar54 superstar54 deleted the feature/result_multiple_plugins branch October 29, 2023 06:05
@unkcpz unkcpz restored the feature/result_multiple_plugins branch November 2, 2023 15:56
unkcpz pushed a commit that referenced this pull request Nov 2, 2023
…` plugin (#522)

This PR supports:
- showing the result from multiple plugins.
- only shows the result panel when it is available.
- use `electronic_structure` plugin as an example, in which the result panel needs both `pdos` and `bands` plugin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants