def test_limits():
    # Empty Test
    expected = ['main', 'difference']
    expected_type = [LoggedPathDict, LoggedPathDict]

    PathDictDerived(Limits, expected, expected_type)
    lim = Limits()
    expected = ['x_min', 'x_max', 'y_min', 'y_max']
    expected_type = [float] * 4
    PathDictTest(lim['main'], expected, expected_type)
    expected = ['y_min', 'y_max']
    expected_type = [float] * 2
    PathDictTest(lim['difference'], expected, expected_type)
    main = lim['main']
    assert main['x_min'] == 0.0
    assert main['x_max'] == 0.0
    assert main['y_min'] == -np.Inf
    assert main['y_max'] == np.Inf
    difference = lim['difference']
    assert difference['y_min'] == -np.Inf
    assert difference['y_max'] == np.Inf

    # Data Test
    expected = ['main', 'difference']
    expected_type = [LoggedPathDict, LoggedPathDict]

    x = [float(x) for x in range(10)]
    y_obs_lower = [x_ - 0.1 for x_ in x]
    y_obs_upper = [x_ + 0.1 for x_ in x]
    y_diff_upper = [x_ + 0.25 for x_ in x]
    y_diff_lower = [x_ - 0.25 for x_ in x]
    x_calc = x
    y_calc = [x_ * 2 for x_ in x]

    PathDictDerived(Limits, expected, expected_type, y_obs_lower, y_obs_upper,
                    y_diff_upper, y_diff_lower, x_calc, y_calc)
    lim = Limits(y_obs_lower, y_obs_upper, y_diff_upper, y_diff_lower, x_calc,
                 y_calc)
    expected = ['x_min', 'x_max', 'y_min', 'y_max']
    expected_type = [float] * 4
    PathDictTest(lim['main'], expected, expected_type)
    expected = ['y_min', 'y_max']
    expected_type = [float] * 2
    PathDictTest(lim['difference'], expected, expected_type)
    main = lim['main']
    assert main['x_min'] == 0.0
    assert main['x_max'] == 9.0
    assert main['y_min'] == -0.1
    assert main['y_max'] == 18.0
    difference = lim['difference']
    assert difference['y_min'] == -0.25
    assert difference['y_max'] == 9.25
Пример #2
0
def genericTestExperiment(exp_constructor, *args):
    expected = [
        'name', 'wavelength', 'offset', 'magnetic_field', 'phase',
        'background', 'resolution', 'measured_pattern', 'refinement_type',
        'polarization'
    ]

    expected_type = [
        str, Base, Base, Base, ExperimentPhases, Backgrounds, Resolution,
        MeasuredPattern, RefinementType, Polarization
    ]
    PathDictDerived(exp_constructor, expected, expected_type, *args)

    exp = exp_constructor(*args)

    assert exp.getItemByPath(['wavelength', 'header'
                              ]) == EXPERIMENT_DETAILS['wavelength']['header']
    assert exp.getItemByPath(['offset', 'header'
                              ]) == EXPERIMENT_DETAILS['offset']['header']

    assert exp.getItemByPath(['wavelength', 'tooltip'
                              ]) == EXPERIMENT_DETAILS['wavelength']['tooltip']
    assert exp.getItemByPath(['offset', 'tooltip'
                              ]) == EXPERIMENT_DETAILS['offset']['tooltip']

    assert exp.getItemByPath(['wavelength', 'url'
                              ]) == EXPERIMENT_DETAILS['wavelength']['url']
    assert exp.getItemByPath(['offset',
                              'url']) == EXPERIMENT_DETAILS['offset']['url']

    return exp
def test_Info_Default():
    expected = [
        'name', 'phase_ids', 'experiment_ids', 'modified_datetime',
        'refinement_datetime', 'chi_squared', 'n_res'
    ]
    expected_type = [str, list, list, str, str, Base, Base]
    PathDictDerived(Info.default, expected, expected_type)
Пример #4
0
def genericTestPhase(phase_constructor, *args):
    expected = ['phasename', 'spacegroup', 'cell', 'atoms', 'sites']

    expected_type = [str, SpaceGroup, Cell, (Atom, dict, Atoms), dict]
    PathDictDerived(phase_constructor, expected, expected_type, *args)

    return phase_constructor(*args)
Пример #5
0
def test_measured_pattern_default():
    expected = [
        'x', 'y_obs', 'sy_obs', 'y_obs_diff', 'sy_obs_diff', 'y_obs_up',
        'sy_obs_up', 'y_obs_down', 'sy_obs_down'
    ]
    expected_type = [*[list] * 3, *[(list, type(None))] * 6]

    PathDictDerived(MeasuredPattern.default, expected, expected_type)
    mp = MeasuredPattern.default()
    assert len(mp['x']) == 0
    assert len(mp['y_obs']) == 0
    assert len(mp['sy_obs']) == 0
    assert mp['y_obs_up'] is None
    assert mp['sy_obs_up'] is None
    assert mp['y_obs_down'] is None
    assert mp['sy_obs_down'] is None

    PathDictDerived(MeasuredPattern.default, expected, expected_type, True)
    mp = MeasuredPattern.default(True)
    assert len(mp['x']) == 0
    assert len(mp['y_obs']) == 0
    assert len(mp['sy_obs']) == 0
    assert len(mp['y_obs_up']) == 0
    assert len(mp['sy_obs_up']) == 0
    assert len(mp['y_obs_down']) == 0
    assert len(mp['sy_obs_down']) == 0

    PathDictDerived(MeasuredPattern.default, expected, expected_type, False)
    mp = MeasuredPattern.default(False)
    assert len(mp['x']) == 0
    assert len(mp['y_obs']) == 0
    assert len(mp['sy_obs']) == 0
    assert mp['y_obs_up'] is None
    assert mp['sy_obs_up'] is None
    assert mp['y_obs_down'] is None
    assert mp['sy_obs_down'] is None
Пример #6
0
def genericTestBackground(bg_constructor, *args):
    expected = ['name', 'ttheta', 'intensity']

    expected_type = [str, float, Base]
    PathDictDerived(bg_constructor, expected, expected_type, *args)

    bg = bg_constructor(*args)

    assert bg.getItemByPath(['intensity', 'header'
                             ]) == INTENSITY_DETAILS['intensity']['header']
    assert bg.getItemByPath(['intensity', 'tooltip'
                             ]) == INTENSITY_DETAILS['intensity']['tooltip']
    assert bg.getItemByPath(['intensity',
                             'url']) == INTENSITY_DETAILS['intensity']['url']

    return bg
Пример #7
0
def test_exp_phase_default():
    expected = ['name', 'scale']
    expected_type = [str, Base]
    name = 'boo'

    PathDictDerived(ExperimentPhase.default, expected, expected_type, name)
    ep = ExperimentPhase.default(name)
    assert ep['name'] == name
    assert ep.getItemByPath(['scale',
                             'header']) == SCALE_DETAILS['scale']['header']
    assert ep.getItemByPath(['scale',
                             'tooltip']) == SCALE_DETAILS['scale']['tooltip']
    assert ep.getItemByPath(['scale', 'url']) == SCALE_DETAILS['scale']['url']
    assert str(
        ep['scale']['store']['unit']) == SCALE_DETAILS['scale']['default'][1]
    assert ep['scale'].value == SCALE_DETAILS['scale']['default'][0]
def genericTestSG(sg_constructor, *args):
    expected = [
        'crystal_system', 'space_group_name_HM_ref', 'space_group_IT_number',
        'origin_choice'
    ]

    expected_type = [Base, Base, Base, Base]
    PathDictDerived(sg_constructor, expected, expected_type, *args)

    sg = sg_constructor(*args)

    assert sg.getItemByPath(['crystal_system', 'header'
                             ]) == SG_DETAILS['crystal_system']['header']
    assert sg.getItemByPath(
        ['space_group_name_HM_ref',
         'header']) == SG_DETAILS['space_group_name_HM_ref']['header']
    assert sg.getItemByPath(
        ['space_group_IT_number',
         'header']) == SG_DETAILS['space_group_IT_number']['header']
    assert sg.getItemByPath(['origin_choice', 'header'
                             ]) == SG_DETAILS['origin_choice']['header']

    assert sg.getItemByPath(['crystal_system', 'tooltip'
                             ]) == SG_DETAILS['crystal_system']['tooltip']
    assert sg.getItemByPath(
        ['space_group_name_HM_ref',
         'tooltip']) == SG_DETAILS['space_group_name_HM_ref']['tooltip']
    assert sg.getItemByPath(
        ['space_group_IT_number',
         'tooltip']) == SG_DETAILS['space_group_IT_number']['tooltip']
    assert sg.getItemByPath(['origin_choice', 'tooltip'
                             ]) == SG_DETAILS['origin_choice']['tooltip']

    assert sg.getItemByPath(['crystal_system',
                             'url']) == SG_DETAILS['crystal_system']['url']
    assert sg.getItemByPath(['space_group_name_HM_ref', 'url'
                             ]) == SG_DETAILS['space_group_name_HM_ref']['url']
    assert sg.getItemByPath(['space_group_IT_number', 'url'
                             ]) == SG_DETAILS['space_group_IT_number']['url']
    assert sg.getItemByPath(['origin_choice',
                             'url']) == SG_DETAILS['origin_choice']['url']

    return sg
Пример #9
0
def genericTestResolution(res_constructor, *args):
    expected = ['u', 'v', 'w', 'x', 'y']

    expected_type = [Base, Base, Base, Base, Base]
    PathDictDerived(res_constructor, expected, expected_type, *args)

    res = res_constructor(*args)

    assert res.getItemByPath(['u', 'header'
                              ]) == RESOLUTION_DETAILS['UVWXY']['header']
    assert res.getItemByPath(['v', 'header'
                              ]) == RESOLUTION_DETAILS['UVWXY']['header']
    assert res.getItemByPath(['w', 'header'
                              ]) == RESOLUTION_DETAILS['UVWXY']['header']
    assert res.getItemByPath(['x', 'header'
                              ]) == RESOLUTION_DETAILS['UVWXY']['header']
    assert res.getItemByPath(['y', 'header'
                              ]) == RESOLUTION_DETAILS['UVWXY']['header']

    assert res.getItemByPath(['u', 'tooltip'
                              ]) == RESOLUTION_DETAILS['UVWXY']['tooltip']
    assert res.getItemByPath(['v', 'tooltip'
                              ]) == RESOLUTION_DETAILS['UVWXY']['tooltip']
    assert res.getItemByPath(['w', 'tooltip'
                              ]) == RESOLUTION_DETAILS['UVWXY']['tooltip']
    assert res.getItemByPath(['x', 'tooltip'
                              ]) == RESOLUTION_DETAILS['UVWXY']['tooltip']
    assert res.getItemByPath(['y', 'tooltip'
                              ]) == RESOLUTION_DETAILS['UVWXY']['tooltip']

    assert res.getItemByPath(['u',
                              'url']) == RESOLUTION_DETAILS['UVWXY']['url']
    assert res.getItemByPath(['v',
                              'url']) == RESOLUTION_DETAILS['UVWXY']['url']
    assert res.getItemByPath(['w',
                              'url']) == RESOLUTION_DETAILS['UVWXY']['url']
    assert res.getItemByPath(['x',
                              'url']) == RESOLUTION_DETAILS['UVWXY']['url']
    assert res.getItemByPath(['y',
                              'url']) == RESOLUTION_DETAILS['UVWXY']['url']

    return res
Пример #10
0
def genericTestMSP(msp_constructor, *args):
    expected = [
        'type', 'chi_11', 'chi_22', 'chi_33', 'chi_12', 'chi_13', 'chi_23'
    ]

    expected_type = [Base, Base, Base, Base, Base, Base, Base]
    PathDictDerived(msp_constructor, expected, expected_type, *args)

    msp = msp_constructor(*args)

    assert msp.getItemByPath(['type', 'header']) == 'Type'
    assert msp.getItemByPath(['chi_11', 'header']) == 'U11'
    assert msp.getItemByPath(['chi_22', 'header']) == 'U22'
    assert msp.getItemByPath(['chi_33', 'header']) == 'U33'
    assert msp.getItemByPath(['chi_12', 'header']) == 'U12'
    assert msp.getItemByPath(['chi_13', 'header']) == 'U13'
    assert msp.getItemByPath(['chi_23', 'header']) == 'U23'

    assert msp.getItemByPath(['type', 'tooltip']) == ''
    assert msp.getItemByPath(['chi_11',
                              'tooltip']) == ATOM_DETAILS['MSP']['tooltip']
    assert msp.getItemByPath(['chi_22',
                              'tooltip']) == ATOM_DETAILS['MSP']['tooltip']
    assert msp.getItemByPath(['chi_33',
                              'tooltip']) == ATOM_DETAILS['MSP']['tooltip']
    assert msp.getItemByPath(['chi_12',
                              'tooltip']) == ATOM_DETAILS['MSP']['tooltip']
    assert msp.getItemByPath(['chi_13',
                              'tooltip']) == ATOM_DETAILS['MSP']['tooltip']
    assert msp.getItemByPath(['chi_23',
                              'tooltip']) == ATOM_DETAILS['MSP']['tooltip']

    assert msp.getItemByPath(['type', 'url']) == ''
    assert msp.getItemByPath(['chi_11', 'url']) == ATOM_DETAILS['MSP']['url']
    assert msp.getItemByPath(['chi_22', 'url']) == ATOM_DETAILS['MSP']['url']
    assert msp.getItemByPath(['chi_33', 'url']) == ATOM_DETAILS['MSP']['url']
    assert msp.getItemByPath(['chi_12', 'url']) == ATOM_DETAILS['MSP']['url']
    assert msp.getItemByPath(['chi_13', 'url']) == ATOM_DETAILS['MSP']['url']
    assert msp.getItemByPath(['chi_23', 'url']) == ATOM_DETAILS['MSP']['url']

    return msp
Пример #11
0
def genericTestADP(adp_constructor, *args):
    expected = ['u_11', 'u_22', 'u_33', 'u_12', 'u_13', 'u_23']

    expected_type = [Base, Base, Base, Base, Base, Base]
    PathDictDerived(adp_constructor, expected, expected_type, *args)

    adp = adp_constructor(*args)

    assert adp.getItemByPath(['u_11', 'header']) == 'U11'
    assert adp.getItemByPath(['u_22', 'header']) == 'U22'
    assert adp.getItemByPath(['u_33', 'header']) == 'U33'
    assert adp.getItemByPath(['u_12', 'header']) == 'U12'
    assert adp.getItemByPath(['u_13', 'header']) == 'U13'
    assert adp.getItemByPath(['u_23', 'header']) == 'U23'

    assert adp.getItemByPath(['u_11',
                              'tooltip']) == ATOM_DETAILS['ADP']['tooltip']
    assert adp.getItemByPath(['u_22',
                              'tooltip']) == ATOM_DETAILS['ADP']['tooltip']
    assert adp.getItemByPath(['u_33',
                              'tooltip']) == ATOM_DETAILS['ADP']['tooltip']
    assert adp.getItemByPath(['u_12',
                              'tooltip']) == ATOM_DETAILS['ADP']['tooltip']
    assert adp.getItemByPath(['u_13',
                              'tooltip']) == ATOM_DETAILS['ADP']['tooltip']
    assert adp.getItemByPath(['u_23',
                              'tooltip']) == ATOM_DETAILS['ADP']['tooltip']

    assert adp.getItemByPath(['u_11', 'url']) == ATOM_DETAILS['ADP']['url']
    assert adp.getItemByPath(['u_22', 'url']) == ATOM_DETAILS['ADP']['url']
    assert adp.getItemByPath(['u_33', 'url']) == ATOM_DETAILS['ADP']['url']
    assert adp.getItemByPath(['u_12', 'url']) == ATOM_DETAILS['ADP']['url']
    assert adp.getItemByPath(['u_13', 'url']) == ATOM_DETAILS['ADP']['url']
    assert adp.getItemByPath(['u_23', 'url']) == ATOM_DETAILS['ADP']['url']

    return adp
def genericTestProjectDict(constructor, *args):
    expected = ['interface', 'calculator', 'app', 'info', 'phases', 'experiments', 'calculations']
    expected_type = [Interface, Calculator, App, Info, Phases, Experiments, Calculations]
    PathDictDerived(constructor, expected, expected_type, *args)
    return constructor(*args)
def genericTestCalculation(cp_constructor, *args):
    expected = ['name', 'bragg_peaks', 'calculated_pattern', 'limits']
    expected_type = [str, BraggPeaks, CalculatedPattern, Limits]
    PathDictDerived(cp_constructor, expected, expected_type, *args)
    return cp_constructor(*args)
Пример #14
0
def genericTestAtom(atom_constructor, *args):
    expected = [
        'atom_site_label', 'type_symbol', 'scat_length_neutron', 'fract_x',
        'fract_y', 'fract_z', 'occupancy', 'adp_type', 'U_iso_or_equiv', 'ADP',
        'MSP'
    ]

    expected_type = [
        str, Base, Base, Base, Base, Base, Base, Base, Base, (ADP, type(None)),
        (MSP, type(None))
    ]
    PathDictDerived(atom_constructor, expected, expected_type, *args)

    atom = atom_constructor(*args)

    assert atom.getItemByPath(['type_symbol', 'header'
                               ]) == ATOM_DETAILS['type_symbol']['header']
    assert atom.getItemByPath(
        ['scat_length_neutron',
         'header']) == ATOM_DETAILS['scat_length_neutron']['header']
    assert atom.getItemByPath(['fract_x', 'header']) == 'x'
    assert atom.getItemByPath(['fract_y', 'header']) == 'y'
    assert atom.getItemByPath(['fract_z', 'header']) == 'z'
    assert atom.getItemByPath(['occupancy', 'header'
                               ]) == ATOM_DETAILS['occupancy']['header']
    assert atom.getItemByPath(['adp_type',
                               'header']) == ATOM_DETAILS['adp_type']['header']
    assert atom.getItemByPath(['U_iso_or_equiv', 'header'
                               ]) == ATOM_DETAILS['U_iso_or_equiv']['header']

    assert atom.getItemByPath(['type_symbol', 'tooltip'
                               ]) == ATOM_DETAILS['type_symbol']['tooltip']
    assert atom.getItemByPath(
        ['scat_length_neutron',
         'tooltip']) == ATOM_DETAILS['scat_length_neutron']['tooltip']
    assert atom.getItemByPath(['fract_x',
                               'tooltip']) == ATOM_DETAILS['fract']['tooltip']
    assert atom.getItemByPath(['fract_y',
                               'tooltip']) == ATOM_DETAILS['fract']['tooltip']
    assert atom.getItemByPath(['fract_z',
                               'tooltip']) == ATOM_DETAILS['fract']['tooltip']
    assert atom.getItemByPath(['occupancy', 'tooltip'
                               ]) == ATOM_DETAILS['occupancy']['tooltip']
    assert atom.getItemByPath(['adp_type', 'tooltip'
                               ]) == ATOM_DETAILS['adp_type']['tooltip']
    assert atom.getItemByPath(['U_iso_or_equiv', 'tooltip'
                               ]) == ATOM_DETAILS['U_iso_or_equiv']['tooltip']

    assert atom.getItemByPath(['type_symbol',
                               'url']) == ATOM_DETAILS['type_symbol']['url']
    assert atom.getItemByPath(['scat_length_neutron', 'url'
                               ]) == ATOM_DETAILS['scat_length_neutron']['url']
    assert atom.getItemByPath(['fract_x',
                               'url']) == ATOM_DETAILS['fract']['url']
    assert atom.getItemByPath(['fract_y',
                               'url']) == ATOM_DETAILS['fract']['url']
    assert atom.getItemByPath(['fract_z',
                               'url']) == ATOM_DETAILS['fract']['url']
    assert atom.getItemByPath(['occupancy',
                               'url']) == ATOM_DETAILS['occupancy']['url']
    assert atom.getItemByPath(['adp_type',
                               'url']) == ATOM_DETAILS['adp_type']['url']
    assert atom.getItemByPath(['U_iso_or_equiv',
                               'url']) == ATOM_DETAILS['U_iso_or_equiv']['url']

    return atom