Ejemplo n.º 1
0
def test_sections_config(sections_data):
    with pytest.raises(SettingsFileError) as excinfo:
        with temp_config_filename(sections_data) as filename:
            settings.load(filename)
    assert excinfo.match(r"Those sections must be present")
    assert excinfo.match(r"Sections that are needed but not present in the file")
    assert excinfo.type == SettingsFileError
Ejemplo n.º 2
0
def test_not_all_states_decay():
    data = data_abs_ok + '''sensitizer_decay:
# lifetimes in s
    ES: 1e-3

activator_decay:
'''
    with pytest.raises(SettingsValueError) as excinfo: # all states must have a decay rate
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"activator_decay")
    assert excinfo.match(r"does not have the right type")
    assert excinfo.type == SettingsValueError

    data = data_abs_ok + '''sensitizer_decay:
activator_decay:
    3F4: 12e-3
    3H5: 25e-6
    3H4: 2e-3
    3F3: 2e-6
    1G4: 760e-6
    1D2: 67.5e-6
'''
    with pytest.raises(SettingsValueError) as excinfo: # all states must have a decay rate
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"sensitizer_decay")
    assert excinfo.match(r"does not have the right type")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 3
0
def test_version_config():
    with pytest.raises(SettingsValueError) as excinfo:
        with temp_config_filename(data_all_mandatory_ok.replace('version: 1',
                                                                'version: 2')) as filename:
            settings.load(filename)
    assert excinfo.match(r"cannot be larger than 1")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 4
0
def test_empty_states_config():
    data = '''version: 1
lattice:
    name: bNaYF4
    N_uc: 8
    # concentration
    S_conc: 0.3
    A_conc: 0.3
    # unit cell
    # distances in Angstrom
    a: 5.9738
    b: 5.9738
    c: 3.5297
    # angles in degree
    alpha: 90
    beta: 90
    gamma: 120
    # the number is also ok for the spacegroup
    spacegroup: P-6
    # info about sites
    sites_pos: [[0, 0, 0], [2/3, 1/3, 1/2]]
    sites_occ: [1, 1/2]
states: asd
excitations: asd
sensitizer_decay: asd
activator_decay: asd
'''
    with pytest.raises(SettingsValueError) as excinfo:
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r'Error validating section "states"')
    assert excinfo.type == SettingsValueError
Ejemplo n.º 5
0
def test_excitations_config2():
    data = data_states_ok + '''excitations:
    Vis_473:'''
    with pytest.raises(SettingsValueError) as excinfo: # emtpy excitation
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"does not have the right type")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 6
0
def test_pow_dep_config4(): # text instead numbers
    data = data_ET_ok + '''power_dependence: [asd, 1e7, 8]'''

    with pytest.raises(SettingsValueError) as excinfo:
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"does not have the right type")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 7
0
def test_extra_sections_warning_config():
    data = data_all_mandatory_ok+'''extra_unknown_section: dsa'''
    with pytest.warns(SettingsExtraValueWarning) as warnings:
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert len(warnings) == 2 # one warning
    warning = warnings.pop(SettingsExtraValueWarning)
    assert issubclass(warning.category, SettingsExtraValueWarning)
    assert 'Some values or sections should not be present in the file' in str(warning.message)
Ejemplo n.º 8
0
def test_extra_value():
    extra_data = '''version: 1
lattice:
    name: bNaYF4
    N_uc: 8
    # concentration
    S_conc: 0.3
    A_conc: 0.3
    # unit cell
    # distances in Angstrom
    a: 5.9738
    b: 5.9738
    c: 3.5297
    # angles in degree
    alpha: 90
    beta: 90
    gamma: 120
    # the number is also ok for the spacegroup
    spacegroup: P-6
    # info about sites
    sites_pos: [[0, 0, 0], [2/3, 1/3, 1/2]]
    sites_occ: [1, 1/2]
    extra_value: 3
states:
    sensitizer_ion_label: Yb
    sensitizer_states_labels: [GS, ES]
    activator_ion_label: Tm
    activator_states_labels: [3H6, 3F4, 3H5, 3H4, 3F3, 1G4, 1D2]
excitations:
    Vis_473:
        active: True
        power_dens: 1e6 # power density W/cm^2
        t_pulse: 1e-8 # pulse width, seconds
        process: Tm(3H6) -> Tm(1G4) # both ion labels are required
        degeneracy: 13/9
        pump_rate: 9.3e-4 # cm2/J
sensitizer_decay:
# lifetimes in s
    ES: 2.5e-3
activator_decay:
# lifetimes in s
    3F4: 12e-3
    3H5: 25e-6
    3H4: 2e-3
    3F3: 2e-6
    1G4: 760e-6
    1D2: 67.5e-6
sensitizer_branching_ratios:
activator_branching_ratios:
'''
    with pytest.warns(SettingsExtraValueWarning) as warnings: # "extra_value" in lattice section
        with temp_config_filename(extra_data) as filename:
            settings.load(filename)
    assert len(warnings) == 1 # one warning
    warning = warnings.pop(SettingsExtraValueWarning)
    assert issubclass(warning.category, SettingsExtraValueWarning)
    assert 'Some values or sections should not be present in the file' in str(warning.message)
Ejemplo n.º 9
0
def test_conc_dep_config4(): # negative number
    data = data_ET_ok + '''concentration_dependence:
    concentrations: [[0, 1, 2], [-0.01, 0.1, 0.2, 0.3, 0.4, 0.5]]'''

    with pytest.raises(SettingsValueError) as excinfo:
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"cannot be smaller than 0")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 10
0
def test_pow_dep_config3(): # empty
    data = data_ET_ok + '''power_dependence: []'''

    with pytest.raises(SettingsValueError) as excinfo:
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"Length of power_dependence")
    assert excinfo.match(r"cannot be smaller than 3")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 11
0
def test_ET_coop_ok(): # ok
    data = data_branch_ok + '''energy_transfer:
    CR50:
        process: Yb(ES) + Yb(ES) + Tm(3H6) -> Yb(GS) + Yb(GS) + Tm(1G4)
        multipolarity: 6
        strength: 1e3
'''
    with temp_config_filename(data) as filename:
            settings.load(filename)
Ejemplo n.º 12
0
def test_ET_config_missing_ETlabel():
    data = data_branch_ok + '''energy_transfer:
        process: Tm(1G4) + Tm(3H6) -> Tm(3H4) + Tm(3H5)
        multipolarity: 6
'''
    with pytest.raises(SettingsValueError) as excinfo: # label missing
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"does not have the right type")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 13
0
def test_optim_wrong_excitations(): # ok
    data = data_ET_ok + '''optimization:
        excitations: [Vis_473, wrong_label]'''

    with pytest.raises(settings.LabelError) as excinfo:
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"in optimization: excitations")
    assert excinfo.match(r"not found in excitations section above!")
    assert excinfo.type == settings.LabelError
Ejemplo n.º 14
0
def test_optim_wrong_B_proc_label():
    '''Wrong branching ration optimization process'''
    data = data_ET_ok + '''optimization:
        processes: [3H145->3F4]
'''
    with pytest.raises(settings.LabelError) as excinfo: # wrong ET process label
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"Wrong labels in optimization: processes")
    assert excinfo.type == settings.LabelError
Ejemplo n.º 15
0
def test_optim_wrong_proc_2():
    '''Wrong ET optimization process'''
    data = data_ET_ok + '''optimization:
        processes: [ETU53, ETU_does_no_exist]
'''
    with pytest.raises(settings.LabelError) as excinfo: # wrong ET process label
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"Wrong labels in optimization: processes")
    assert excinfo.type == settings.LabelError
Ejemplo n.º 16
0
def test_ET_ok(): # ok
    data = data_branch_ok + '''energy_transfer:
    CR50:
        process: Tm(1G4) + Tm(3H6) -> Tm(3H4) + Tm(3H5)
        multipolarity: 6
        strength: 1e3
        strength_avg: 1e1
'''
    with temp_config_filename(data) as filename:
            settings.load(filename)
Ejemplo n.º 17
0
def test_conc_dep_config3(): # ok, but empty
    data = data_ET_ok + '''concentration_dependence:
    concentrations: []'''

    with pytest.raises(SettingsValueError) as excinfo:
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"Length of concentrations")
    assert excinfo.match(r"cannot be smaller than 2")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 18
0
def test_states_empty_list():  # empty list for S states
    data = data_lattice_ok + '''states:
    sensitizer_ion_label: Yb
    sensitizer_states_labels: [GS, ES]
    activator_ion_label: Tm
    activator_states_labels: []'''
    with pytest.raises(SettingsValueError) as excinfo: # empty S labels list
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r'Length of activator_states_labels \(0\) cannot be smaller than 1.')
    assert excinfo.type == SettingsValueError
Ejemplo n.º 19
0
def test_states_no_states_labels():
    data = data_lattice_ok + '''states:
        sensitizer_states_labels: [GS, ES]
        activator_ion_label: Tm
        activator_states_labels: [3H6, 3F4, 3H5, 3H4, 3F3, 1G4, 1D2]'''
    with pytest.raises(SettingsValueError) as excinfo: # missing key
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r'Error validating section "states"')
    assert excinfo.match(r'"sensitizer_ion_label" not in dictionary')
    assert excinfo.type == SettingsValueError
Ejemplo n.º 20
0
def test_ET_config_missing_strength():
    data = data_branch_ok + '''energy_transfer:
    CR50:
        process: Tm(1G4) + Tm(3H6) -> Tm(3H4) + Tm(3H5)
        multipolarity: 6
'''
    with pytest.raises(SettingsValueError) as excinfo: # strength missing
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match('"strength" not in dictionary')
    assert excinfo.type == SettingsValueError
Ejemplo n.º 21
0
def test_ET_config_wrong_initial_final_ion_label():
    data = data_branch_ok + '''energy_transfer:
    CR50:
        process: Tm(1G4) + Tm(3H6) -> Yb(3H4) + Tm(3H5)
        multipolarity: 6
        strength: 8.87920884e+08
'''
    with pytest.raises(settings.LabelError) as excinfo: # initial ion label should be the same
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"is not a valid state label")
    assert excinfo.type == settings.LabelError
Ejemplo n.º 22
0
def test_abs_config8(): # ok, ESA on different ions
    data = data_states_ok + '''excitations:
    NIR_800:
        active: True
        power_dens: 1e7 # power density W/cm^2
        t_pulse: 1e-8 # pulse width, seconds
        process: [Tm(3H6)->Tm(3H4), Yb(GS)->Yb(ES)]
        degeneracy: [13/9, 11/9]
        pump_rate: [4.4e-3, 2e-3] # cm2/J
'''
    with temp_config_filename(data) as filename:
        settings.load(filename)
Ejemplo n.º 23
0
def test_ET_config_wrong_multipolarity():
    data = data_branch_ok + '''energy_transfer:
    CR50:
        process: Tm(1G4) + Tm(3H6) -> Tm(3H4) + Tm(3H5)
        multipolarity: fds
        strength: 8.87920884e+08
'''
    with pytest.raises(SettingsValueError) as excinfo: # wrong multipolarity
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"does not have the right type")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 24
0
def test_states_no_list():
    data = data_lattice_ok + '''states:
        sensitizer_ion_label: Yb
        sensitizer_states_labels:
        activator_ion_label: Tm
        activator_states_labels: [3H6, 3F4, 3H5, 3H4, 3F3, 1G4, 1D2]'''
    with pytest.raises(SettingsValueError) as excinfo: # empty S labels
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"sensitizer_states_labels")
    assert excinfo.match(r"does not have the right type")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 25
0
def test_abs_config_ok(): # good test
    data = data_states_ok + '''excitations:
    NIR_980:
        active: True
        power_dens: 1e7 # power density W/cm^2
        t_pulse: 1e-8 # pulse width, seconds
        process: Yb(GS)->Yb(ES)
        degeneracy: 4/3
        pump_rate: 4.4e-3 # cm2/J
'''
    with temp_config_filename(data) as filename:
        settings.load(filename)
Ejemplo n.º 26
0
def test_states_fractions():  # fractions in the state labels
    data = data_lattice_ok + '''states:
    sensitizer_ion_label: Yb
    sensitizer_states_labels: [2F7/2, 2F5/2]
    activator_ion_label: Tm
    activator_states_labels: [3H6, 3F4, 3H5, 3H4, 3F3, 1G4, 1D2]'''
    with pytest.raises(SettingsValueError) as excinfo: # it should fail in the excitations section
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r'Setting "excitations"')
    assert excinfo.match(r'does not have the right type')
    assert excinfo.type == SettingsValueError
Ejemplo n.º 27
0
def test_excitations_config7():
    data = data_states_ok + '''excitations:
    Vis_473:
        active: True
        t_pulse: 1e-8 # pulse width, seconds
        process: Tm(3H6) -> Tm(1G4) # both ion labels are required
        degeneracy: 13/9
        pump_rate: 9.3e-4 # cm2/J
'''
    with pytest.raises(SettingsValueError) as excinfo: # missing power_dens
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match('power_dens')
    assert excinfo.type == SettingsValueError
Ejemplo n.º 28
0
def test_excitations_config5():
    data = data_states_ok + '''excitations:
        active: True
        power_dens: 1e6 # power density W/cm^2
        t_pulse: 1e-8 # pulse width, seconds
        process: Tm(3H6) -> Tm(1G4) # both ion labels are required
        degeneracy: 13/9
        pump_rate: 9.3e-4 # cm2/J
'''
    with pytest.raises(SettingsValueError) as excinfo: # label missing
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match(r"does not have the right type")
    assert excinfo.type == SettingsValueError
Ejemplo n.º 29
0
def test_branch_config_ok(): # all ok
    data = data_decay_ok + '''sensitizer_branching_ratios:
    ES->GS: 1.0
activator_branching_ratios:
    3H5->3F4: 0.4
    3H4->3F4: 0.3
    3F3->3H4: 0.999
    1G4->3F4: 0.15
    1G4->3H5: 0.16
    1G4->3H4: 0.04
    1G4->3F3: 0.00
    1D2->3F4: 0.43
'''
    with temp_config_filename(data) as filename:
        settings.load(filename)
Ejemplo n.º 30
0
def test_abs_config7():
    data = data_states_ok + '''excitations:
    NIR_800:
        active: True
        power_dens: 1e7 # power density W/cm^2
        t_pulse: 1e-8 # pulse width, seconds
        process: [Tm(3H6)->Tm(3H4), Tm(3H5)->Tm(1G4)]
        degeneracy: [13/9, 11/9]
        pump_rate: [4.4e-3, -2e-3] # cm2/J
'''
    with pytest.raises(SettingsValueError) as excinfo:  # pump rate must be positive
        with temp_config_filename(data) as filename:
            settings.load(filename)
    assert excinfo.match("cannot be smaller than 0.")
    assert excinfo.type == SettingsValueError