Exemple #1
0
    def test_val_unitless(self):
        # Number without units
        x = ui.Number(name='XX',
                      desc='Mystery Parameter',
                      min=0,
                      max=10,
                      value=5)
        assert x.value == 5
        assert x.str == '5'

        # simulate pressing enter
        x.cb('')
        assert x.value == 5
        assert x.str == '5'

        x.value = 4.4
        assert x.value == 4.4
        assert x.str == '4.4'

        x.cb('')
        assert x.value == 4.4
        assert x.str == '4.4'

        # try some bad values
        with pytest.raises(ValueError):
            x.value = '4 m'
        with pytest.raises(ValueError):
            x.value = 'foo'
        with pytest.raises(ValueError):
            x.value = None
Exemple #2
0
    def test_val_convert(self):
        x = ui.Number(name='XX',
                      desc='Mystery Parameter',
                      units='m',
                      min=0,
                      max=10,
                      value='5 m')

        x.value = '10 cm'
        assert x.value == 0.1
        assert x.str == '0.1 m'
Exemple #3
0
    def test_disable(self):
        x = ui.Number(name='XX',
                      desc='Mystery Parameter',
                      units='m',
                      min=5,
                      max=10,
                      value=8)

        assert x.disabled is False
        x.disabled = True
        assert x.disabled is True
        x.disabled = False
        assert x.disabled is False
Exemple #4
0
    def test_change_minmax(self):
        x = ui.Number(name='XX',
                      desc='Mystery Parameter',
                      units='m',
                      min=5,
                      max=10,
                      value=8)

        assert x.min == 5
        assert x.max == 10

        x.min = 1
        assert x.min == 1

        x.max = 100
        assert x.max == 100
Exemple #5
0
    def test_val(self):
        x = ui.Number(name='XX',
                      desc='Mystery Parameter',
                      units='m',
                      min=0,
                      max=10,
                      value='5 m')
        assert x.value == 5
        assert x.str == '5 m'

        x.value = '7.1 m'
        assert x.value == 7.1
        assert x.str == '7.1 m'

        x.value = 0.2
        assert x.value == 0.2
        assert x.str == '0.2 m'
Exemple #6
0
    def test_val_no_minmax(self):
        # Number without units
        x = ui.Number(name='XX', desc='Mystery Parameter', value=5)
        x.value = 50000
        assert x.value == 50000
        assert x.str == '50000'

        x.value = -400000
        assert x.value == -400000
        assert x.str == '-400000'

        # try some bad values
        with pytest.raises(ValueError):
            x.value = '4 m'
        with pytest.raises(ValueError):
            x.value = 'foo'
        with pytest.raises(ValueError):
            x.value = None
Exemple #7
0
    def test_val2(self):
        # initial value has no units
        x = ui.Number(name='XX',
                      desc='Mystery Parameter',
                      units='m',
                      min=0,
                      max=10,
                      value=5)
        assert x.value == 5
        assert x.str == '5 m'

        x.value = '7.1 m'
        assert x.value == 7.1
        assert x.str == '7.1 m'

        x.value = '0.2'
        assert x.value == 0.2
        assert x.str == '0.2 m'
Exemple #8
0
    def test_val_max(self):
        x = ui.Number(name='XX',
                      desc='Mystery Parameter',
                      units='m',
                      min=5,
                      max=10,
                      value=8)

        with pytest.raises(ValueError):
            x.value = 10.001

        with pytest.raises(ValueError):
            x.value = '11 m'

        # 1000 cm = 10 m, so OK
        x.value = '1000 cm'
        assert x.value == 10

        # 1001 cm NOT OK
        with pytest.raises(ValueError):
            x.value = '1001 cm'
Exemple #9
0
    def test_val_min(self):
        x = ui.Number(name='XX',
                      desc='Mystery Parameter',
                      units='m',
                      min=5,
                      max=10,
                      value=8)

        with pytest.raises(ValueError):
            x.value = 1

        with pytest.raises(ValueError):
            x.value = '1 m'

        # 500 cm = 5 m, so OK
        x.value = '500 cm'
        assert x.value == 5

        # 499 cm NOT OK
        with pytest.raises(ValueError):
            x.value = '499 cm'
Exemple #10
0
import hublib.ui as ui


"""
A limitation of the current widget set is that we cannot
do labels with tooltips and Math (Latex).  This should
be fixed soon.
"""

e1 = ui.Number(
        name='E1',
        description="Longitudinal Young's Modulus",
        units='GPa',
        min='0 GPa',
        max='500 GPa',
        value='138 GPa'
    )

e2 = ui.Number(
        name='E2',
        description="Transverse Young's Modulus In-Plane",
        units='GPa',
        min='0 GPa',
        max='500 GPa',
        value='14.5 GPa'
    )

nu12 = ui.Number(
        name='nu12',
        description="Major In-Plane Poisson's Ratio",
        min=-1.0,
Exemple #11
0
PARADIM_UI['s1']['display'] = ui.Tab([s1_tab0, s1_tab1, s1_tab2, s1_tab3])
UpdateStep1({'type': 'change', 'name': 'value', 'new': 'new'})

##################################################
# Second
##################################################

PARADIM_UI['s2'] = {}

PARADIM_UI['s2']['button'] = Button(description='Calculate Formation Energy')
PARADIM_UI['s2']['button'].layout = Layout(width='99%')
PARADIM_UI['s2']['button'].w = Box([PARADIM_UI['s2']['button']])
PARADIM_UI['s2']['action'] = Myaction()
PARADIM_UI['s2']['LaNiO3'] = ui.Number(description="LaNiO3",
                                       name="LaNiO3 ~ -325.81",
                                       value=0,
                                       units="Ry",
                                       step=0.1)
PARADIM_UI['s2']['La2O3'] = ui.Number(description="La2O3",
                                      name="La2O3 ~ -350.69",
                                      value=0,
                                      units="Ry",
                                      step=0.1)
PARADIM_UI['s2']['NiO'] = ui.Number(description="NiO",
                                    name="NiO ~-133.62",
                                    value=0,
                                    units="Ry",
                                    step=0.1)
PARADIM_UI['s2']['O2'] = ui.Number(description="O2",
                                   name="O2 ~ -66.67",
                                   value=0,
Exemple #12
0
                                     value=inputs.chiriality.value,
                                     options=inputs.chiriality.options)
PXTAL_UI["chiriality"].dd.observe(
    lambda obj: UI_SET_VALUE(inputs.chiriality, obj.new), names="value")

PXTAL_UI["defect_checkbox"] = ui.Checkbox(
    name="Include Connectivity Defects",
    description=
    "Include head-to-head & tail-to-tail connectivity defects in crystals",
    value=True,
)

PXTAL_UI["connectivity"] = ui.Number(
    name="Defect Ratio",
    description="Defect Ratio for head-to-head & tail-to-tail connections",
    value=inputs.head_tail_defect_ratio.value,
    min=inputs.head_tail_defect_ratio.min,
    max=inputs.head_tail_defect_ratio.max,
)
PXTAL_UI["connectivity"].dd.observe(
    lambda obj: UI_SET_VALUE(inputs.head_tail_defect_ratio, obj.new),
    names="value")
PXTAL_UI["configs"] = ui.Integer(
    name="Configs",
    description=
    "Number of attempts to find a configuration that does not violate excluded region",
    value=inputs.configs.value,
    min=inputs.configs.min,
    max=inputs.configs.max,
)
PXTAL_UI["configs"].dd.observe(