Ejemplo n.º 1
0
def nist_names():
    '''
    Get a list of registered compound names understood by nist
    '''
    import xraylib

    return xraylib.GetCompoundDataNISTList()
Ejemplo n.º 2
0
    def test_good(self):
        list = xraylib.GetCompoundDataNISTList()
        self.assertEqual(len(list), 180)
        for i, v in enumerate(list):
            cdn = xraylib.GetCompoundDataNISTByIndex(i)
            self.assertEqual(cdn['name'], v)
            cdn = xraylib.GetCompoundDataNISTByName(v)
            self.assertEqual(cdn['name'], v)

        cdn = xraylib.GetCompoundDataNISTByIndex(5)
        self.assertEqual(cdn['nElements'], 4)
        self.assertEqual(cdn['density'], 0.001205)
        self.assertEqual(cdn['Elements'], [6, 7, 8, 18])
        self.assertAlmostEqual(cdn['massFractions'],
                               [0.000124, 0.755267, 0.231781, 0.012827])
        self.assertEqual(cdn['name'], 'Air, Dry (near sea level)')

        cdn = xraylib.GetCompoundDataNISTByName('Air, Dry (near sea level)')
        self.assertEqual(cdn['nElements'], 4)
        self.assertEqual(cdn['density'], 0.001205)
        self.assertEqual(cdn['Elements'], [6, 7, 8, 18])
        self.assertAlmostEqual(cdn['massFractions'],
                               [0.000124, 0.755267, 0.231781, 0.012827])
        self.assertEqual(cdn['name'], 'Air, Dry (near sea level)')
Ejemplo n.º 3
0
    def build_gui(self):

        box = oasysgui.widgetBox(self.controlArea,
                                 self.name + " Input Parameters",
                                 orientation="vertical",
                                 width=self.CONTROL_AREA_WIDTH - 5)

        idx = -1

        #widget index 1
        idx += 1
        box1 = gui.widgetBox(box)
        gui.comboBox(
            box1,
            self,
            "MAT_FLAG",
            label=self.unitLabels()[idx],
            addSpace=False,
            items=['Element(formula)', 'Mixture(formula)', 'Mixture(table)'],
            valueType=int,
            orientation="horizontal",
            labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 2
        idx += 1
        box1 = gui.widgetBox(box)
        items = xraylib.GetCompoundDataNISTList()
        gui.comboBox(box1,
                     self,
                     "MAT_LIST",
                     label=self.unitLabels()[idx],
                     addSpace=False,
                     items=items,
                     valueType=int,
                     orientation="horizontal",
                     labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 3
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "DESCRIPTOR",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          orientation="horizontal")
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 4
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "DENSITY",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 5
        idx += 1
        box1 = gui.widgetBox(box)
        gui.comboBox(box1,
                     self,
                     "CALCULATE",
                     label=self.unitLabels()[idx],
                     addSpace=False,
                     items=[
                         'Total', 'PhotoElectric', 'Rayleigh', 'Compton',
                         'Total-Rayleigh'
                     ],
                     valueType=int,
                     orientation="horizontal",
                     labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 6
        idx += 1
        box1 = gui.widgetBox(box)
        gui.comboBox(box1,
                     self,
                     "GRID",
                     label=self.unitLabels()[idx],
                     addSpace=False,
                     items=['Standard', 'User defined', 'Single Value'],
                     valueType=int,
                     orientation="horizontal",
                     labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 7
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "GRIDSTART",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 8
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "GRIDEND",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=float,
                          validator=QDoubleValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 9
        idx += 1
        box1 = gui.widgetBox(box)
        oasysgui.lineEdit(box1,
                          self,
                          "GRIDN",
                          label=self.unitLabels()[idx],
                          addSpace=False,
                          valueType=int,
                          validator=QIntValidator(),
                          orientation="horizontal",
                          labelWidth=250)
        self.show_at(self.unitFlags()[idx], box1)

        #widget index 10
        idx += 1
        box1 = gui.widgetBox(box)
        gui.comboBox(box1,
                     self,
                     "UNIT",
                     label=self.unitLabels()[idx],
                     addSpace=False,
                     items=[
                         'barn/atom [Cross Section] *see help*',
                         'cm^2 [Cross Section] *see help*',
                         'cm^2/g [Mass abs coef]', 'cm^-1 [Linear abs coef]'
                     ],
                     valueType=int,
                     orientation="horizontal",
                     labelWidth=130)
        self.show_at(self.unitFlags()[idx], box1)

        # widget index 11
        idx += 1
        box1 = gui.widgetBox(box)
        gui.comboBox(box1,
                     self,
                     "DUMP_TO_FILE",
                     label=self.unitLabels()[idx],
                     addSpace=True,
                     items=["No", "Yes"],
                     orientation="horizontal")
        self.show_at(self.unitFlags()[idx], box1)

        # widget index 12
        idx += 1
        box1 = gui.widgetBox(box)
        gui.lineEdit(box1,
                     self,
                     "FILE_NAME",
                     label=self.unitLabels()[idx],
                     addSpace=True)
        self.show_at(self.unitFlags()[idx], box1)

        gui.rubber(self.controlArea)
Ejemplo n.º 4
0
 def getnames():
     return list(xraylib.GetCompoundDataNISTList())
Ejemplo n.º 5
0
print("Uranium Monocarbide")
print("  Name: {}".format(cdn['name']))
print("  Density: {}".format(cdn['density']))
for i in range(cdn['nElements']):
    print("  Element {}: {} %%".format(cdn['Elements'][i],
                                       cdn['massFractions'][i] * 100.0))

cdn = xraylib.GetCompoundDataNISTByIndex(xraylib.NIST_COMPOUND_BRAIN_ICRP)
print("NIST_COMPOUND_BRAIN_ICRP")
print("  Name: {}".format(cdn['name']))
print("  Density: {}".format(cdn['density']))
for i in range(cdn['nElements']):
    print("  Element {}: {} %%".format(cdn['Elements'][i],
                                       cdn['massFractions'][i] * 100.0))

nistCompounds = xraylib.GetCompoundDataNISTList()
print("List of available NIST compounds:")
for i in range(len(nistCompounds)):
    print("  Compound {}: {}".format(i, nistCompounds[i]))

print("")

# radioNuclideData tests
rnd = xraylib.GetRadioNuclideDataByName("109Cd")
print("109Cd")
print("  Name: {}".format(rnd['name']))
print("  Z: {}".format(rnd['Z']))
print("  A: {}".format(rnd['A']))
print("  N: {}".format(rnd['N']))
print("  Z_xray: {}".format(rnd['Z_xray']))
print("  X-rays:")
Ejemplo n.º 6
0
 def list_names():
     return xraylib.GetCompoundDataNISTList()
Ejemplo n.º 7
0
def index():
    form = Xraylib_Request()
    version = xraylib.__version__

    # Populates select fields
    form.function.choices = form.function.choices + cs_tup + dcs_tup
    form.transition.siegbahn.choices = trans_S_tup
    form.shell.choices = shell_tup
    form.nistcomp.choices = nist_tup
    form.rad_nuc.choices = rad_name_tup

    if request.method == 'POST':
        # Get user input
        select_input = request.form.get('function')
        examples = request.form.get('examples')

        notation = request.form.get('transition-notation')
        siegbahn = request.form.get('transition-siegbahn')
        iupac1 = request.form.get('transition-iupac1')
        iupac2 = request.form.get('transition-iupac2')

        ex_shell = request.form.get('augtrans-ex_shell')
        trans_shell = request.form.get('augtrans-trans_shell')
        aug_shell = request.form.get('augtrans-aug_shell')

        cktrans = request.form.get('cktrans')
        nistcomp = request.form.get('nistcomp')
        rad_nuc = request.form.get('rad_nuc')
        shell = request.form.get('shell')

        int_z = request.form['int_z']
        float_q = request.form['float_q']
        comp = request.form['comp']
        int_z_or_comp = request.form['int_z_or_comp']
        energy = request.form['energy']
        theta = request.form['theta']
        phi = request.form['phi']
        density = request.form['density']
        pz = request.form['pz']

        # Turns user input => valid args for calc_output
        trans = iupac1 + iupac2 + '_LINE'
        augtrans = ex_shell + '_' + trans_shell + aug_shell + '_AUGER'

        if select_input == 'AtomicWeight' or select_input == 'ElementDensity':
            if validate_int(int_z) or validate_str(int_z):
                examples = code_example(form.examples.choices, select_input,
                                        int_z)
                output = calc_output(select_input, int_z)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       units=getattr(Request_Units,
                                                     select_input + '_u'),
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'FF_Rayl' or select_input == 'SF_Compt':
            if validate_int(
                    int_z) or validate_str(int_z) and validate_float(float_q):
                examples = code_example(form.examples.choices, select_input,
                                        int_z, float_q)
                output = calc_output(select_input, int_z, float_q)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'AugerRate':
            if validate_int(int_z) or validate_str(int_z):
                examples = code_example(form.examples.choices, select_input,
                                        int_z, augtrans)
                output = calc_output(select_input, int_z, augtrans)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'LineEnergy' or select_input == 'RadRate':
            if notation == 'IUPAC':
                if validate_int(int_z) or validate_str(int_z):
                    examples = code_example(form.examples.choices,
                                            select_input, int_z, trans)
                    output = calc_output(select_input, int_z, trans)

                    if select_input == 'LineEnergy':
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               output=output,
                                               units=Request_Units.Energy_u,
                                               code_examples=examples)
                    else:
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               output=output,
                                               code_examples=examples)
                else:
                    return render_template('index.html',
                                           form=form,
                                           version=version,
                                           error=Request_Error.error)

            elif notation == 'Siegbahn':
                if validate_int(int_z) or validate_str(int_z):
                    examples = code_example(form.examples.choices,
                                            select_input, int_z, siegbahn)
                    output = calc_output(select_input, int_z, siegbahn)
                    print(output)

                    if select_input == 'LineEnergy':
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               output=output,
                                               units=Request_Units.Energy_u,
                                               code_examples=examples)
                    else:
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               output=output,
                                               code_examples=examples)

                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

            elif notation == 'All':
                if validate_int(int_z) or validate_str(int_z):
                    output = all_trans(trans_I_tup, select_input, int_z)

                    if select_input == 'LineEnergy':
                        #needs units
                        #output = dict(out, Line = 'Energies')
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               output=output,
                                               units=Request_Units.Energy_u)
                    else:
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               output=output)
                else:
                    return render_template('index.html',
                                           form=form,
                                           version=version,
                                           error=Request_Error.error)
            else:
                return render_template('index.html', error=Request_Error.error)

        elif (select_input == 'EdgeEnergy' or select_input == 'JumpFactor'
              or select_input == 'FluorYield' or select_input == 'AugerYield'
              or select_input == 'AtomicLevelWidth'
              or select_input == 'ElectronConfig'):
            if validate_int(int_z) or validate_str(int_z):
                examples = code_example(form.examples.choices, select_input,
                                        int_z, shell)
                output = calc_output(select_input, int_z, shell)
                if select_input == 'EdgeEnergy' or select_input == 'AtomicLevelWidth':
                    return render_template('index.html',
                                           form=form,
                                           version=version,
                                           output=output,
                                           units=Request_Units.Energy_u,
                                           code_examples=examples)
                elif select_input == 'ElectronConfig':
                    return render_template(
                        'index.html',
                        form=form,
                        version=version,
                        output=output,
                        units=Request_Units.ElectronConfig_u,
                        code_examples=examples)
                else:
                    return render_template('index.html',
                                           form=form,
                                           version=version,
                                           output=output,
                                           code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'CS_Photo_Partial':
            if validate_int(
                    int_z) or validate_str(int_z) and validate_float(energy):
                output = calc_output(select_input, int_z, shell, energy)
                examples = code_example(form.examples.choices, select_input,
                                        int_z, shell, energy)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       units=Request_Units.CS_u,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'CS_KN':
            if validate_float(energy) and energy != '0':
                output = calc_output(select_input, energy)
                examples = code_example(form.examples.choices, select_input,
                                        energy)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       units=Request_Units.CS_u,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input.startswith('CS_FluorLine'):
            if validate_float(energy):
                if notation == 'IUPAC':
                    if validate_int(int_z) or validate_str(int_z):
                        examples = code_example(form.examples.choices,
                                                select_input, int_z, trans,
                                                energy)
                        output = calc_output(select_input, int_z, trans,
                                             energy)
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               output=output,
                                               units=Request_Units.CS_u,
                                               code_examples=examples)
                    else:
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               error=Request_Error.error)
                elif notation == 'Siegbahn':
                    if validate_int(int_z) or validate_str(int_z):
                        examples = code_example(form.examples.choices,
                                                select_input, int_z, siegbahn,
                                                energy)
                        output = calc_output(select_input, int_z, siegbahn,
                                             energy)
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               output=output,
                                               units=Request_Units.CS_u,
                                               code_examples=examples)
                    else:
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               error=Request_Error.error)
                elif notation == 'All':
                    if validate_int(int_z) or validate_str(int_z):
                        output = all_trans_xrf(form.transition.iupac.choices,
                                               select_input, int_z, energy)
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               output=output,
                                               units=Request_Units.CS_u)
                    else:
                        return render_template('index.html',
                                               form=form,
                                               version=version,
                                               error=Request_Error.error)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input.startswith('CS_'):
            if validate_float(energy) and validate_int(
                    int_z_or_comp) or validate_str(int_z_or_comp):
                examples = code_example(form.examples.choices, select_input,
                                        int_z_or_comp, energy)
                output = calc_output(select_input, int_z_or_comp, energy)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       units=Request_Units.CS_u,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'DCS_Thoms':
            if validate_float(theta):
                output = calc_output(select_input, theta)
                examples = code_example(form.examples.choices, select_input,
                                        theta)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       units=Request_Units.DCS_u,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'DCS_KN' or select_input == 'ComptonEnergy':
            if validate_float(energy, theta):
                output = calc_output(select_input, energy, theta)
                examples = code_example(form.examples.choices, select_input,
                                        energy, theta)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       units=Request_Units.DCS_u,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input.startswith('DCS_'):
            if validate_float(energy, theta) and validate_int(
                    int_z_or_comp) or validate_str(int_z_or_comp):
                output = calc_output(select_input, int_z_or_comp, energy,
                                     theta)
                examples = code_example(form.examples.choices, select_input,
                                        int_z_or_comp, energy, theta)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       units=Request_Units.DCS_u,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'DCSP_KN':
            if validate_float(energy, theta, phi):
                output = calc_output(select_input, energy, theta, phi)
                examples = code_example(form.examples.choices, select_input,
                                        energy, theta, phi)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       units=Request_Units.DCS_u,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'DCSP_Thoms':
            if validate_float(theta, phi):
                output = calc_output(select_input, theta, phi)
                examples = code_example(form.examples.choices, select_input,
                                        theta, phi)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       units=Request_Units.DCS_u,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input.startswith('DCSP_'):
            if validate_float(energy, theta, phi) and validate_int(
                    int_z_or_comp) or validate_str(int_z_or_comp):
                output = calc_output(select_input, int_z_or_comp, energy,
                                     theta, phi)
                examples = code_example(form.examples.choices, select_input,
                                        int_z_or_comp, energy, theta, phi)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       units=Request_Units.DCS_u,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input.startswith('Fi'):
            if validate_int(
                    int_z) or validate_str(int_z) and validate_float(energy):
                output = calc_output(select_input, int_z, energy)
                examples = code_example(form.examples.choices, select_input,
                                        int_z, energy)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'CosKronTransProb':
            if validate_int(int_z) or validate_str(int_z):
                output = calc_output(select_input, int_z, cktrans)
                examples = code_example(form.examples.choices, select_input,
                                        int_z, cktrans)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'ComptonProfile':
            if validate_float(pz) and validate_int(int_z) or validate_str(
                    int_z):

                output = calc_output(select_input, int_z, pz)
                examples = code_example(form.examples.choices, select_input,
                                        int_z, pz)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'ComptonProfile_Partial':
            if validate_float(pz) and validate_int(int_z) or validate_str(
                    int_z):
                output = calc_output(select_input, int_z, shell, pz)
                examples = code_example(form.examples.choices, select_input,
                                        int_z, shell, pz)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'MomentTransf':
            if validate_float(energy, theta) == True:
                output = calc_output(select_input, energy, theta)
                examples = code_example(form.examples.choices, select_input,
                                        energy, theta)
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       output=output,
                                       code_examples=examples)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'Refractive_Index':

            # Special Case: Refractive_Index input needs to be const char compound
            if validate_float(energy, density) and validate_int(
                    int_z_or_comp) or validate_str(int_z_or_comp):
                try:
                    output = xraylib.Refractive_Index(
                        xraylib.AtomicNumberToSymbol(int(int_z_or_comp),
                                                     float(energy),
                                                     float(density)))
                    examples = code_example(form.examples.choices,
                                            select_input, int_z_or_comp,
                                            energy, density)
                    return render_template('index.html',
                                           form=form,
                                           version=version,
                                           output=output,
                                           code_examples=examples)
                except:
                    output = xraylib.Refractive_Index(int_z_or_comp,
                                                      float(energy),
                                                      float(density))
                    examples = code_example(form.examples.choices,
                                            select_input, int_z_or_comp,
                                            energy, density)
                    return render_template('index.html',
                                           form=form,
                                           version=version,
                                           output=output,
                                           code_examples=examples)
                else:
                    return render_template('index.html',
                                           form=form,
                                           version=version,
                                           error=Request_Error.error)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'CompoundParser':
            # Special Case: CompoundParser input needs to be const char compound
            if validate_str(comp):
                try:
                    out = xraylib.CompoundParser(str(comp))

                    # Format output
                    w_fracts = out['massFractions']
                    w_pers = [str(round(i * 100, 2)) + ' %' for i in w_fracts]
                    z = out['Elements']
                    sym = [
                        '<sub>' + str(i) + '</sub>' +
                        str(xraylib.AtomicNumberToSymbol(i)) for i in z
                    ]
                    mmass = str(out['molarMass']) + ' g mol<sup>-1</sup>'

                    output = {
                        'Elements': sym,
                        'Weight Fraction': w_pers,
                        'Number of Atoms': out['nAtoms'],
                        ' Molar Mass': mmass
                    }
                    examples = code_example(form.examples.choices,
                                            select_input, comp)
                    return render_template('index.html',
                                           form=form,
                                           version=version,
                                           output=output,
                                           code_examples=examples,
                                           units=Request_Units.per_u)
                except:
                    return render_template('index.html',
                                           form=form,
                                           version=version,
                                           error=Request_Error.error)
            else:
                return render_template('index.html',
                                       form=form,
                                       version=version,
                                       error=Request_Error.error)

        elif select_input == 'GetRadioNuclideDataList':
            output = xraylib.GetRadioNuclideDataList()
            output.insert(0, '<b> Radionuclides: </b>')
            output = '<br/>'.join(output)
            examples = code_example(form.examples.choices, select_input)
            return render_template('index.html',
                                   form=form,
                                   version=version,
                                   output=output,
                                   code_examples=examples)

        elif select_input == 'GetRadioNuclideDataByIndex':
            out = calc_output(select_input, rad_nuc)
            print(out)
            # Format output
            line_nos = out['XrayLines']
            x_energy = [xraylib.LineEnergy(out['Z_xray'], i) for i in line_nos]

            output = {
                'X-ray Energies': x_energy,
                'Disintegrations s<sup>-1</sup>': out['XrayIntensities'],
                'Gamma-ray Energy': out['GammaEnergies'],
                'Disintegrations s<sup>-1</sup> ': out['GammaIntensities']
            }
            examples = code_example(form.examples.choices,
                                    'GetRadioNuclideDataByName', rad_nuc)

            return render_template('index.html',
                                   form=form,
                                   version=version,
                                   output=output,
                                   code_examples=examples)

        elif select_input == 'GetCompoundDataNISTList':
            output = xraylib.GetCompoundDataNISTList()
            output.insert(0, '<b> NIST Compounds: </b>')
            output = '<br/>'.join(output)
            examples = code_example(form.examples.choices, select_input)
            return render_template('index.html',
                                   form=form,
                                   version=version,
                                   output=output,
                                   code_examples=examples)

        elif select_input == 'GetCompoundDataNISTByIndex':
            out = calc_output(select_input, nistcomp)

            # Format output
            w_fracts = out['massFractions']
            w_pers = [str(round(i * 100, 2)) + ' %' for i in w_fracts]
            z = out['Elements']
            sym = [
                '<sub>' + str(i) + '</sub>' +
                str(xraylib.AtomicNumberToSymbol(i)) for i in z
            ]
            density = str(out['density']) + ' g cm<sup>-3</sup>'

            output = {
                'Elements': sym,
                'Weight Fraction': w_pers,
                ' Density': density
            }
            examples = code_example(form.examples.choices,
                                    'GetCompoundDataNISTByName', nistcomp)
            return render_template('index.html',
                                   form=form,
                                   version=version,
                                   output=output,
                                   code_examples=examples)

    return render_template('index.html', form=form, version=version)
Ejemplo n.º 8
0
    def __init__(self, parent=None, name=""):
        super(MaterialTabWidget, self).__init__()

        self.parent = parent
        self.name = name  # tag
        self.mat = {}  # materials for target, detector, etc
        self.rad = {}  # radionuclide sources
        self.bem = {}  # beam
        # the following table was used for debug...
        self.mat_table = QTableWidget()
        self.mat_table.setRowCount(2)
        self.mat_table.setColumnCount(2)
        mat_header = self.mat_table.horizontalHeader()
        mat_header.setSectionResizeMode(0, QHeaderView.ResizeToContents)
        mat_header.setSectionResizeMode(1, QHeaderView.ResizeToContents)

        # default values
        saddbutton = ""
        sremovebutton = "Remove"
        sresetbutton = "Reset"
        if self.name == 'det' or self.name == 'rad' or self.name == 'bet':
            saddbutton = "Add"
        elif self.name == 'tgt' or self.name == "bem":
            saddbutton = "Set"

        self.TARGET_STR = "Target"
        self.DETECTOR_STR = "Detector"
        self.FILTER_STR = "Filter"
        self.RADIONUCL_STR = "RadioNucl"

        # main layout
        main_layout = QVBoxLayout()

        # add (set), remove, reset
        self.addButton = QPushButton(saddbutton)
        if self.name == 'rad':
            self.addButton.clicked.connect(self.add_radionuclide)
        elif self.name == 'bem':
            self.addButton.clicked.connect(self.add_beam)
        else:
            self.addButton.clicked.connect(self.add_material)
        self.resetButton = QPushButton(sresetbutton)
        self.resetButton.clicked.connect(self.reset_material)
        self.removeButton = QPushButton(sremovebutton)
        self.removeButton.clicked.connect(self.remove_material)
        ly1 = QHBoxLayout()
        ly1.addWidget(self.addButton)
        if self.name == 'bet' or self.name == 'det' or self.name == 'rad':
            ly1.addWidget(self.removeButton)
        ly1.addWidget(self.resetButton)

        # thickness & density
        self.mat_thick_le = QLineEdit()
        self.mat_thick_le.setValidator(QDoubleValidator(0, 1e11, 999))
        self.mat_thick_le.returnPressed.connect(self.apply_mat_thickness)
        self.mat_dens_le = QLineEdit()
        self.mat_dens_le.setValidator(QDoubleValidator(0, 1e11, 999))
        self.mat_dens_le.returnPressed.connect(self.apply_mat_density)
        ly2 = QHBoxLayout()
        ly2.addWidget(QLabel("Thickness (cm)"))
        ly2.addWidget(QLabel("Density (g/cm3)"))
        ly3 = QHBoxLayout()
        ly3.addWidget(self.mat_thick_le)
        ly3.addWidget(self.mat_dens_le)
        # Element
        el_list = [
            "%d: %s" % (i, xrl.AtomicNumberToSymbol(z))
            for i, z in enumerate(np.arange(1, 108, 1, dtype=int))
        ]
        self.el_cb = QComboBox()
        self.el_cb.addItem("None")
        self.el_cb.addItems(el_list)
        self.el_cb.currentIndexChanged.connect(self.el_select)
        # CP
        self.cp_le = QLineEdit()
        self.cp_le.returnPressed.connect(self.apply_mat_cp)
        # NIST CP
        nistcp_list = [
            "%d: %s" % (i, cp)
            for i, cp in enumerate(xrl.GetCompoundDataNISTList())
        ]
        self.nist_cb = QComboBox()
        self.nist_cb.addItem("None")
        self.nist_cb.addItems(nistcp_list)
        self.nist_cb.currentIndexChanged.connect(self.nistcp_select)

        self.bem_beamene_le = QLineEdit()
        self.bem_beamene_le.setValidator(QDoubleValidator(0, 1e11, 999))
        self.bem_beamene_le.returnPressed.connect(self.apply_beamene)
        self.bem_beamene_le.setText("15.")
        self.bem_beamalpha_le = QLineEdit()
        self.bem_beamalpha_le.setValidator(QDoubleValidator(0, 90., 999))
        self.bem_beamalpha_le.returnPressed.connect(self.apply_beamalpha)
        self.bem_beamalpha_le.setText("45.")
        self.bem_beambeta_le = QLineEdit()
        self.bem_beambeta_le.setValidator(QDoubleValidator(0, 90., 999))
        self.bem_beambeta_le.returnPressed.connect(self.apply_beambeta)
        self.bem_beambeta_le.setText("45.")
        self.bem_beamflux_le = QLineEdit()
        self.bem_beamflux_le.setValidator(QDoubleValidator(0, 1e20, 999))
        self.bem_beamflux_le.returnPressed.connect(self.apply_beamflux)
        self.bem_beamflux_le.setText("1e6")  # 1 M/sec
        self.bem_time_le = QLineEdit()  # duration
        self.bem_time_le.setValidator(QDoubleValidator(0, 1e30, 999))
        self.bem_time_le.setText("7200.")  # 2 hours
        self.bem_time_le.returnPressed.connect(self.apply_beam_time)

        self.ra_cb = QComboBox()
        self.ra_cb.addItem("None")
        self.ra_cb.addItems(self.parent.RDNLIST)
        self.ra_cb.currentIndexChanged.connect(self.ra_select)
        self.rad_act_le = QLineEdit()
        self.rad_date_le = QLineEdit()
        self.rad_date_m_le = QLineEdit()
        self.rad_act_m_le = QLineEdit()
        self.rad_act_m_le.setReadOnly(True)
        self.rad_today_le = QLineEdit()
        self.rad_today_le.setReadOnly(True)
        self.rad_hl_le = QLineEdit()
        self.rad_hl_le.setReadOnly(True)
        self.rad_time_le = QLineEdit()  # duration
        self.rad_act_le.setValidator(QDoubleValidator(0, 1e30, 999))
        self.rad_date_le.setValidator(QIntValidator(19000101, 99991231))
        self.rad_date_m_le.setValidator(QIntValidator(19000101, 99991231))
        self.rad_time_le.setValidator(QDoubleValidator(0, 1e30, 999))
        self.rad_act_le.setText("1e6")
        self.rad_date_le.setText("20110311")
        self.rad_date_m_le.setText("20200311")
        self.rad_time_le.setText("3600.")
        self.rad_act_le.returnPressed.connect(self.apply_rad_act)
        self.rad_date_le.returnPressed.connect(self.apply_rad_date)
        self.rad_date_m_le.returnPressed.connect(self.apply_rad_date_measure)
        self.rad_time_le.returnPressed.connect(self.apply_rad_time)

        if self.name == "bem":
            beamw = QWidget()
            #beamw.setObjectName('beamw')
            #beamw_style='QWidget#beamw{border: 1px solid lightgray; border-radius: 2px;}'
            #beamw.setStyleSheet(beamw_style)
            beambox = QVBoxLayout(beamw)
            beambox.setSpacing(0)
            beamew = QWidget()
            ly4 = QHBoxLayout(beamew)
            ly4.addWidget(QLabel("Incident energy (keV):   "))
            ly4.addWidget(self.bem_beamene_le)
            beamfw = QWidget()
            ly7 = QHBoxLayout(beamfw)
            ly7.addWidget(QLabel("Beam flux (photons): "))
            ly7.addWidget(self.bem_beamflux_le)
            beamaw = QWidget()
            ly5 = QHBoxLayout(beamaw)
            ly5.addWidget(QLabel("Incident angle (degree):"))
            ly5.addWidget(self.bem_beamalpha_le)
            beambw = QWidget()
            ly6 = QHBoxLayout(beambw)
            ly6.addWidget(QLabel("Outgoing angle (degree):"))
            ly6.addWidget(self.bem_beambeta_le)
            beambox.addWidget(beamew)
            beambox.addWidget(beamfw)
            beambox.addWidget(beamaw)
            beambox.addWidget(beambw)
            #detiw=QWidget()
            #detiw.setObjectName('detiw')
            #detiw_style='QWidget#detiw{border: 1px solid lightgray; border-radius: 2px;}'
            #detiw.setStyleSheet(detiw_style)
            #detil=QVBoxLayout(detiw)
            btimew = QWidget()
            btimel = QHBoxLayout(btimew)
            btimel.addWidget(QLabel("Beam time (sec):"))
            btimel.addWidget(self.bem_time_le)
            #detil.addWidget(btimew)
            beambox.addWidget(btimew)
            main_layout.addLayout(ly1)
            main_layout.addWidget(beamw)
            #main_layout.addWidget(detiw)

        # RadioNuclide
        elif self.name == "rad":
            # calibrated radioactivity
            radactw = QWidget()
            radactl = QHBoxLayout(radactw)
            radactl.addWidget(QLabel("Activity calib (Bq):"))
            radactl.addWidget(self.rad_act_le)
            # date of calibration
            raddatew = QWidget()
            raddatel = QHBoxLayout(raddatew)
            raddatel.addWidget(QLabel("Date calib (e.g., 20110311): "))
            raddatel.addWidget(self.rad_date_le)
            # half life
            radhlw = QWidget()
            radhll = QHBoxLayout(radhlw)
            radhll.addWidget(QLabel("Half life (days): "))
            radhll.addWidget(self.rad_hl_le)
            # date of measurement
            raddatemw = QWidget()
            raddateml = QHBoxLayout(raddatemw)
            raddateml.addWidget(QLabel("Date measure (e.g., 20200311): "))
            raddateml.addWidget(self.rad_date_m_le)
            #
            radtodayw = QWidget()
            radtodayl = QHBoxLayout(radtodayw)
            radtodayl.addWidget(QLabel("Activity today (Bq): "))
            radtodayl.addWidget(self.rad_today_le)
            # duration time
            radtimew = QWidget()
            radtimel = QHBoxLayout(radtimew)
            radtimel.addWidget(QLabel("Duration time (sec): "))
            radtimel.addWidget(self.rad_time_le)
            main_layout.addLayout(ly1)
            main_layout.addWidget(QLabel("Radionuclide source"))
            main_layout.addWidget(self.ra_cb)
            main_layout.addWidget(radactw)
            main_layout.addWidget(raddatew)
            main_layout.addWidget(radhlw)
            main_layout.addWidget(radtodayw)
            #radiw=QWidget()
            #radiw.setObjectName('radiw')
            #radiw_style='QWidget#radiw{border: 1px solid lightgray; border-radius: 2px;}'
            #radiw.setStyleSheet(radiw_style)
            #radil=QVBoxLayout(radiw)
            #radil.addWidget(radtimew)
            main_layout.addWidget(radtimew)
            #main_layout.addWidget(radiw)

        elif self.name == "bet":  # between materials = filter
            main_layout.addLayout(ly1)
            main_layout.addLayout(ly2)
            main_layout.addLayout(ly3)
            main_layout.addWidget(QLabel("Element"))
            main_layout.addWidget(self.el_cb)
            main_layout.addWidget(QLabel("NIST compound"))
            main_layout.addWidget(self.nist_cb)
            main_layout.addWidget(
                QLabel("Compound parser (e.g., CdTe) press return"))
            main_layout.addWidget(self.cp_le)
            self.chkbox_luxelht = QCheckBox("add LUXEL HT window")
            self.chkbox_luxelht.stateChanged.connect(
                self.chkbox_luxelht_action)
            self.chkbox_luxelht.setChecked(False)
            main_layout.addWidget(self.chkbox_luxelht)

        else:
            main_layout.addLayout(ly1)
            main_layout.addLayout(ly2)
            main_layout.addLayout(ly3)
            main_layout.addWidget(QLabel("Element"))
            main_layout.addWidget(self.el_cb)
            main_layout.addWidget(QLabel("NIST compound"))
            main_layout.addWidget(self.nist_cb)
            main_layout.addWidget(
                QLabel("Compound parser (e.g., CdTe) press return"))
            main_layout.addWidget(self.cp_le)
            #main_layout.addWidget(self.mat_table)

        self.setLayout(main_layout)