Skip to content

Commit

Permalink
Merge pull request #64 from aiidalab/release_1.0.0b3
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha authored Mar 18, 2020
2 parents 36f9eaf + 6e15475 commit e9b11c5
Show file tree
Hide file tree
Showing 8 changed files with 362 additions and 302 deletions.
2 changes: 1 addition & 1 deletion aiidalab_widgets_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
from .structures_multi import MultiStructureUploadWidget # noqa
from .viewers import viewer # noqa

__version__ = "1.0.0b2"
__version__ = "1.0.0b3"
23 changes: 10 additions & 13 deletions aiidalab_widgets_base/databases.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
"""Widgets that allow to query online databases."""
import ipywidgets as ipw
from traitlets import Instance, default
from ase import Atoms

from aiida.tools.dbimporters.plugins.cod import CodDbImporter


class CodQueryWidget(ipw.VBox):
'''Query structures in Crystallography Open Database (COD)
Useful class members:
:ivar has_structure: link to a method to be overloaded. It is called evey time when `self.drop_structure`
widget has changed its name
:vartype has_structure: function
'''
:ivar structure(Atoms): trait that contains the selected structure, None if structure is not selected.'''

structure = Instance(Atoms, allow_none=True)

def __init__(self, **kwargs):
description = ipw.HTML("""<h3>Get crystal structures from
Expand Down Expand Up @@ -47,8 +48,6 @@ def __init__(self, **kwargs):
style=style,
layout=layout)
self.link = ipw.HTML("Link to the web-page will appear here")
self.structure_ase = None

self.btn_query.on_click(self._on_click_query)
self.drop_structure.observe(self._on_select_structure, names=['value'])

Expand Down Expand Up @@ -101,14 +100,12 @@ def _on_select_structure(self, change):
"""When a structure was selected."""
selected = change['new']
if selected['status'] is False:
self.structure_ase = None
self.structure = None
return
self.structure_ase = selected['cif'].get_ase()
formula = self.structure_ase.get_chemical_formula()
self.structure = selected['cif'].get_ase()
struct_url = selected['url'].split('.cif')[0] + '.html'
self.link.value = '<a href="{}" target="_blank">COD entry {}</a>'.format(struct_url, selected['id'])
if self.on_structure_selection is not None:
self.on_structure_selection(structure_ase=self.structure_ase, name=formula)

def on_structure_selection(self, structure_ase, name):
pass
@default('structure')
def _default_structure(self): # pylint: disable=no-self-use
return None
51 changes: 31 additions & 20 deletions aiidalab_widgets_base/process.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
"""Widgets to work with processes."""

import os
from ipywidgets import Textarea, VBox
from ipywidgets import Button, HTML, IntProgress, Layout, Textarea, VBox

# AiiDA imports
from aiida.engine import submit
from aiida.orm import CalcJobNode, ProcessNode, WorkChainNode


def get_running_calcs(process):
"""Takes a process and returns a list of running calculations. The running calculations
can be either the process itself or its running children."""

from aiida.orm import CalcJobNode, ProcessNode, WorkChainNode

# If a process is a running calculation - returning it
if issubclass(type(process), CalcJobNode) and not process.is_sealed:
return [process]
Expand All @@ -28,19 +30,20 @@ def get_running_calcs(process):
class SubmitButtonWidget(VBox):
"""Submit button class that creates submit button jupyter widget."""

def __init__(self, process, widgets_values):
def __init__(self, process, input_dictionary_function, description="Submit"):
"""Submit Button
:process: work chain to run
:param_funtion: the function that generates input parameters dictionary
"""
from ipywidgets import Button, Output

self.process = None
self._process_class = process
self.widgets_values = widgets_values
self.btn_submit = Button(description="Submit", disabled=False)
self._run_after_submitted = []

self.input_dictionary_function = input_dictionary_function
self.btn_submit = Button(description=description, disabled=False)
self.btn_submit.on_click(self.on_btn_submit_press)
self.submit_out = Output()
self.submit_out = HTML('')
children = [
self.btn_submit,
self.submit_out,
Expand All @@ -50,30 +53,33 @@ def __init__(self, process, widgets_values):
def on_click(self, function):
self.btn_submit.on_click(function)

def on_btn_submit_press(self, _):
def on_btn_submit_press(self, _=None):
"""When submit button is pressed."""
from IPython.display import clear_output
from aiida.engine import submit

with self.submit_out:
clear_output()
self.submit_out.value = ''
input_dict = self.input_dictionary_function()
if input_dict is None:
self.submit_out.value = "SubmitButtonWidget: did not recieve input dictionary."
else:
self.btn_submit.disabled = True
input_dict = self.widgets_values()
self.process = submit(self._process_class, **input_dict)
print("Submitted process {}".format(self.process))
return
self.submit_out.value = "Submitted process {}".format(self.process)
for func in self._run_after_submitted:
func(self.process)

def on_submitted(self, function):
"""Run functions after a process has been submitted sucesfully."""
self._run_after_submitted.append(function)


class ProcessFollowerWidget(VBox):
"""A Widget that follows a process until finished."""

def __init__(self, process, followers=None, update_interval=0.1, **kwargs):
"""Initiate all the followers."""
from aiida.orm import ProcessNode

if not isinstance(process, ProcessNode):
raise TypeError("Expecting an object of type {}, got {}".format(ProcessNode, type(process)))
self.process = process
self._run_after_completed = []
self.update_interval = update_interval
self.followers = []
if followers is not None:
Expand Down Expand Up @@ -102,13 +108,18 @@ def follow(self, detach=False):
update_state.start()
else:
self._follow()
for func in self._run_after_completed:
func(self.process)

def on_completed(self, function):
"""Run functions after a process has been completed."""
self._run_after_completed.append(function)


class ProgressBarWidget(VBox):
"""A bar showing the proggress of a process."""

def __init__(self, process, **kwargs):
from ipywidgets import HTML, IntProgress, Layout

self.process = process
self.correspondance = {
Expand Down
Loading

0 comments on commit e9b11c5

Please sign in to comment.