Skip to content

Commit

Permalink
Structure Viewer: add pk to the file name when downloading structure. (
Browse files Browse the repository at this point in the history
…#246)

The PK number is added only when dealing with a stored AiiDA node.

Co-authored-by: Carl Simon Adorf <simon.adorf@epfl.ch>
  • Loading branch information
yakutovicha and csadorf authored Sep 30, 2021
1 parent f25b855 commit 13e93ce
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion aiidalab_widgets_base/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,10 @@ def apply_selection(self, _=None):

def download(self, change=None): # pylint: disable=unused-argument
"""Prepare a structure for downloading."""
suffix = f"-pk-{self.pk}" if self.pk else ""
self._download(
payload=self._prepare_payload(),
filename="structure." + self.file_format.value,
filename=f"structure{suffix}.{self.file_format.value}",
)

@staticmethod
Expand Down Expand Up @@ -602,6 +603,7 @@ class StructureDataViewer(_StructureDataBaseViewer):

structure = Union([Instance(Atoms), Instance(Node)], allow_none=True)
displayed_structure = Instance(Atoms, allow_none=True, read_only=True)
pk = Int(allow_none=True)

def __init__(self, structure=None, **kwargs):
super().__init__(**kwargs)
Expand All @@ -622,8 +624,10 @@ def _valid_structure(self, change): # pylint: disable=no-self-use
return None # if no structure provided, the rest of the code can be skipped

if isinstance(structure, Atoms):
self.pk = None
return structure
if isinstance(structure, Node):
self.pk = structure.pk
return structure.get_ase()
raise ValueError(
"Unsupported type {}, structure must be one of the following types: "
Expand Down

0 comments on commit 13e93ce

Please sign in to comment.