-
Notifications
You must be signed in to change notification settings - Fork 15
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 from_nodes
class method to instantiate a BandsPdosModel
from AiiDA nodes
#1037
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
import base64 | ||
import json | ||
|
||
|
@@ -6,6 +8,7 @@ | |
import traitlets as tl | ||
from IPython.display import display | ||
|
||
from aiida import orm | ||
from aiida.common.extendeddicts import AttributeDict | ||
from aiidalab_qe.common.bands_pdos.utils import ( | ||
HTML_TAGS, | ||
|
@@ -79,6 +82,37 @@ def __init__(self, *args, **kwargs): | |
lambda _: self._has_pdos or self.needs_projections_controls, | ||
) | ||
|
||
@classmethod | ||
def from_nodes( | ||
cls, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should include some doc string here, to explain why these decisions, and that the bands conditionals is to guarantee backwards compatibility There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Once the design is settled, docstrings 👍 |
||
bands_node: orm.WorkChainNode | None = None, | ||
pdos_node: orm.WorkChainNode | None = None, | ||
): | ||
if not (bands_node or pdos_node): | ||
raise ValueError("At least one of the nodes must be provided") | ||
|
||
if bands_node and bands_node.is_finished_ok: | ||
bands = ( | ||
bands_node.outputs.bands | ||
if "bands" in bands_node.outputs | ||
else bands_node.outputs.bands_projwfc | ||
if "bands_projwfc" in bands_node.outputs | ||
else None | ||
) | ||
else: | ||
bands = None | ||
|
||
if pdos_node and pdos_node.is_finished_ok: | ||
items = {key: getattr(pdos_node.outputs, key) for key in pdos_node.outputs} | ||
pdos = AttributeDict(items) | ||
else: | ||
pdos = None | ||
|
||
if bands or pdos: | ||
return cls(bands=bands, pdos=pdos) | ||
|
||
raise ValueError("Failed to parse at least one node") | ||
|
||
def fetch_data(self): | ||
"""Fetch the data from the nodes.""" | ||
if self.bands: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are removing mos of the Docstring, add it where it should be , so is easy for someone in the future to do changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but later, once we understand the design better 👍 This is not done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for tests. No need to comment on them not passing. I'll adjust w.r.t the final design.