Пример #1
0
 def get_dens(self):
     """Gets estimated layer density from user.
     Could make this a calc from xtal struct in future...
     """
     user_alert('Layer Density:\nUsed solely to convert thicknesses in '
                'ug/cm^2 to Angstroms; has no effect on the results.')
     rho = get_nums('Approximate density (g/cm^3):', 25, 0)
     return rho
Пример #2
0
 def get_volts(self):
     """Get accelerating voltages"""
     volts = []
     while True:
         volts.append(get_nums('Accelerating Voltage [KeV]?:', 60, 0))
         reply = yes_no('Add another voltage?(Y/N):')
         if reply is False:
             break
     return volts
Пример #3
0
    def fixlayer(self):
        """Get fixed values for  thickness and composition"""
        # Get Thickness (layers not sub - sub has "infinite" thickness)
        if not self.fix:
            self.thick = 0.0
            return False
        self.units = get_options('+Enter fixed thicknesses in Angstroms (a)'
                                 'or ug/cm**2 (u), (def=a):', ('A', 'U'), 'A')
        if self.units == 'A':
            label = 'Angstroms'
        if self.units == 'U':
            label = 'ug/cm**2'
        self.thick = get_nums('Fixed thickness [%s]:' % label,
                              10e5, 0, 0)
        self.thick = self.thick/1.0e6   # g/cm**2
        if self.units == 'A':
                self.thick = self.thick*self.rho/100.  # cm

        # Get Composition
        if len(self.els) == 1:
            # fraction in layer is one if only 1 element
            self.els[0] = 1.0
        else:
            reply = get_options('Enter the fixed composition %s by '
                                'weight fractions (w) or by atomic '
                                'formula (def=a) :', ('W', 'A'), 'A')

            for i in range(0, len(self.els)):
                if reply == 'W':
                    for j in range(0, self.els):
                        self.els[j].wtfrac = get_nums(
                                'Weight fraction concentration'
                                'of element %s:' % self.els[j], 1.0, 0.0,
                                default=1, zeroval=1.0e-9)
                elif reply == 'A':
                        self.els[j].atform = get_nums(
                                'Atomic Formula of element %s '
                                '(i.e 1 for Si in SiO2):' % self.els[j], 100)

            if reply == 'A':
                wtfracs = wtfract([el.name for el in self.els],
                                  [el.atform for el in self.els])
                for x, _ in enumerate(wtfracs):
                    self.els[x].wtfrac = wtfracs[x]
Пример #4
0
    def new_std(self):
        how = get_options('Input %s standard composition in wt. %% (w) '
                          'or atomic formula(a) (def=a):' % self.name,
                          ('W', 'A'), 'A')
        while True:
            count = 0
            while True:
                count += 1
                print "Element %d in %s" % (count, self.name)
                name = get_options('Element Symbol:', 'els')
                line = get_options('Lowest Excited X-Ray Line:', 'lines')
                self.els.append(AtomicElement(name, line))
                if how.upper() == 'W':
                    self.els[-1].wtfract = get_nums('Weight Fraction:', 1)
                else:
                    self.els[-1].atform = get_nums('Atomic Formula:', 100)
                print ("Entered so far: %s"
                       % ' '.join([el.name for el in self.els]))
                if not yes_no("Add another element? (Y/N)"):
                    break
            if how.upper() == 'A':
                wtfracs = wtfract(self.els, [el.atform for el in self.els])
                for x, _ in enumerate(wtfracs):
                    self.els[x].wtfrac = wtfracs[x]
                print ('%s compound standard: els, weight fractions:'
                       % self.name)
            print "\t".join([self.els[x].name for x
                             in range(0, len(self.els))])
            print "\t".join([str(round(el.wtfrac, 5)) for el in self.els])

            if yes_no("Is this correct?\n(restarts if no)(Y/N):", False):
                break
        data = ""
        for i in range(0, len(self.els)):
            data += "\t%s\t%s\t%s" % (self.els[i].name,
                                      self.els[i].line,
                                      self.els[i].wtfrac)
        towrite = "%s%s\n" % (self.name, data)
        with open('empastds.txt', 'a') as myfile:
            myfile.write(towrite)
Пример #5
0
    def user_input(self, volt):

        z, name = get_options('Please enter Element Symbol:',
                              'els', count=True)
        # make sure the selected line is valid
        while True:
            line = get_options('Please enter Element X-Ray Line '
                               '(Ka, Lg2, etc.):', 'lines')
            xray = get_data(z, line)
            if xray > 0:
                break
            user_alert('Invalid line for this element; try again:')
        opt = self.get_opt()
        if volt is None:
            volt = get_nums('Accelerating voltage for this element?:',
                            50, 0)
        return name, line, z, volt, opt
Пример #6
0
 def macstd(self, el1, el2, macchang, caller):
     """controls calculation of mass absorption coefficients
     for compound standards."""
     xmu = mac(el1, el2)
     if macchang == 'Y':
         mess = ('+MAC for %s %s in %s is %.4g\nChange to:(def.=current)'
                 % (el1.name, el1.line, el2.name, xmu))
         if caller == 'B':
             mess = mess + 'XRF, Compd. Stnd.:'
         if caller == 'C':
             mess = mess + 'Compound Standard:'
         if caller == 'P':
             mess = mess + 'Pure Element Stnd:'
         if caller == 'F':
             mess = mess + 'Addl. XRF, Sample:'
         xmu = get_nums(mess, 10e10, 0, xmu)
         print '+Changed to %.4g' % xmu
     return xmu
Пример #7
0
 def get_valences(self):
     """input of valences when one element is analyzed by stoichiometry
     May want to make this a selection in gui version...
     """
     for lar, el in self:
         if el.opt == 'S':
             lar.stoich = el
         else:
             lar.stoich = 0
     for lar, el in self:
         i = self.layers.index(lar)
         if lar.fix:
             continue
         if lar.stoich == 0:
             continue
         if el.valence == -1:
             el.valence = get_nums('Enter valence for layer %d element %s:'
                               % (i, el.name), 20, 0)
Пример #8
0
def Mac(el1, el2):
    """Calculation of Mass the Absorption Coefficient of an impinging X-Ray
    from el1 on el2.
    This calc needs to be checked.  See above refs"""

    if  el1.z == 5 and el2.z == 40:
        """ B xray interacting with Zr ???  weird"""
        xmu = 8270.0
        iflag = 2
    ie = ""
    cutoff = 0
    xray = el1.xray
    z = el2.z
    mass = el2.mass
    # calculate 'c' parameter
    if xray > get_data(z, 'K'):
        if z < 6:
            c = -2.87536e-4 + 1.808599e-3 * z
        else:
            c = (5.253e-3 +
                 1.33257e-3 * z +
                 -7.5937e-5 * z**2 +
                 1.69357e-6 * z**3 +
                 -1.3975e-8 * z**4)
    elif xray < get_data(z, 'L3'):
        c = (-9.24e-5 +
             1.41478e-4 * z +
             -5.24999e-6 * z**2 +
             9.85296e-8 * z**3 +
             -9.07306e-10 * z**4 +
             3.19254e-12 * z**5)
        if xray > get_data(z, 'L1'):
            c = c
        elif xray > get_data(z, 'L2'):
            c = c * 0.858
        else:
            c = c*(0.8933 - z*8.29e-3 + z**2*6.38e-5)
    elif xray > get_data(z, 'M1'):
        if z < 30:
            c = (1.889757e-2 +
                 -1.8517159e-3 * z +
                 6.9602789e-5 * z**2 +
                 -1.1641145e-6 * z**3 +
                 7.2773258e-9 * z**4)
        else:
            c = (3.0039e-3 +
                 -1.73663566e-4 * z +
                 4.0424792e-6 * z**2 +
                 -4.0585911e-8 * z**3 +
                 1.497763e-10 * z**4)
    elif xray > get_data(z, 'M5'):
        c1 = (7.7708e-5 +
              -7.83544e-6 * z +
              2.209365e-7 * z**2 +
              -1.29086e-9 * z**3)
        c2 = (1.406 +
              0.0162 * z +
              -6.561e-4 * z**2 +
              4.865e-6 * z**3)
        c3 = (0.584 +
              0.01955 * z +
              -1.285e-4 * z**2)
        c4 = (1.082 +
              1.366e-3 * z)
        c5 = (1.6442 +
              -0.0480 * z +
              4.0664e-4 * z**2)
        if xray > get_data(z, 'M2'):
            c = c1*c2*c3
        elif xray > get_data(z, 'M3'):
            c = c1*c2*c4
        elif xray > get_data(z, 'M4'):
            c = c1*c2*0.95
        else:  # M5
            ie = 'M5'
            c = c1*c2*c5
    else:
        c = 1.08*(4.3156e-3 +
                  -1.4653e-4 * z +
                  1.707073e-6 * z**2 +
                  -6.69827e-9 * z**3)
        if xray < get_data(z, 'N1'):
            cutoff = ((0.252*z - 31.1812)*z + 1042.)/1000.0
            ie = 'N1'

#      calculate 'n' parameter
    if xray > get_data(z, 'K'):
        if z < 6:
            n = (3.34745 +
                 0.02652873 * z +
                 -0.01273815 * z**2)
        else:
            n = (3.112 +
                 -0.0121 * z)
    elif xray > get_data(z, 'L3'):
        n = (2.7575 +
             1.889e-3 * z +
             -4.982e-5 * z**2)
    elif xray > get_data(z, 'M1'):
        n = (0.5385 +
             0.084597 * z +
             -1.08246e-3 * z**2 +
             4.4509e-6 * z**3)
    elif xray > get_data(z, 'M5'):
        n = 3.0 - 0.004*z
    else:
        n = 0.3736 + 0.02401*z

#      calculate 'a' parameter
    if xray > get_data(z, 'K'):
        if z < 6:
            a = (24.4545 +
                 155.6055 * z +
                 -14.15422 * z**2)
        else:
            a = (47.0 * z +
                 6.52 * z**2 +
                 -0.152624 * z**3)
    elif xray > get_data(z, 'L3'):
        a = (17.8096 * z +
             0.067429 * z**2 +
             0.01253775 * z**3 +
             -1.16286e-4 * z**4)
    elif xray > get_data(z, 'M1'):
        a = (10.2575657 * z +
             -0.822863477 * z**2 +
             2.63199611e-2 * z**3 +
             -1.8641019e-4 * z**4)
    elif xray > get_data(z, 'M5'):
        a = (4.62 * z +
             -0.04 * z**2)
    else:
        a = (19.64 * z +
             -0.61239 * z**2 +
             5.39309e-3 * z**3)

#      calculate 'b' parameter
    if xray > get_data(z, 'K'):
        if z < 6:
            b = -103. + 18.2*z
        else:
            b = 0.
    elif xray > get_data(z, 'L3'):
        b = 0.
    elif xray > get_data(z, 'M1'):
        if z < 61:
            b = (5.654 * z +
                 -0.536839169 * z**2 +
                 0.018972278 * z**3 +
                 -1.683474e-4 * z**4)
        else:
            b = (-1232.4022 * z +
                 51.114164 * z**2 +
                 -0.699473097 * z**3 +
                 3.1779619e-3 * z**4)
    elif xray > get_data(z, 'M5'):
        b = (2.51 +
             (-0.052) * z +
             3.78e-4 * z**2) * get_data(z, 'M4') * 1000.
    else:
        b = -113. + 4.5*z

    if xray > get_data(z, 'N1'):
        qq = (-xray*1000.+b)/a
        if qq > 88.:
            qq = 88.
        elif qq < -88.:
            qq = -88.

        xmu = c * z**4 / mass * ((12.397 / xray)**n) * (1. - np.exp(qq))
        if xmu < 0.0:
            mess = '!!!   negative  mac    !!!'
    else:
        xmu = (((12.397 / xray)**n) * c * z**4 / mass * (xray - cutoff) /
               (1.08 * get_data(z, 'N1')))
    if xray < 1.1 * cutoff:
        mess = '!!!  Ec<1.1xcutoff     !!!'
    elif xray - cutoff < 0.02 and xray - cutoff > -0.005:
        mess = '!!!  close to edge     !!!'
    else:
        mess = 'Good!!'
    if ie == 'M5':
        mess += '!!!M4>Ec>M5 edge & Zab<70!!!'
        if el2.mass >= 70:
            mess = 'Good!!'
    if ie == 'N1':
        mess += '!!!  Ec below M5 edge  !!!'
    if xmu < 0.0 and ie == 'N1':
        mess = '!!!neg. mac & Ec<M5edge!!!'
    user_alert(mess + '\nemiter=%s %s; absorber=%s; mu=%.4g'
               % (el1.name, el1.line, el2.name, xmu))

    if xmu <= 0.0:
        xmu1 = xmu
        xmu = get_nums('MAC is negative; Enter a value for this MAC :')
        user_alert('emiter=%s %s; absorber=%s;'
                   'mu changed from %.4g to %.4g'
                   % (el1.name, el1.line, el2.name, xmu1, xmu))
    return xmu
Пример #9
0
 def get_toa(self):
     """get take-off angle from user"""
     return get_nums('Enter take-off angle (default=40 degrees):',
                     90, 0, 40)