Пример #1
0
        def varience(subr):

            fctr = structure.film_ctr(self.var_list, self.var_table, subr,
                                      slab_index, self.iq, self.h, self.k,
                                      key_list)

            # roughness
            cr = roughness(self.iq)
            # interface roughness
            ir = cr.interface_roughness(self.iroughness)

            f = np.multiply(np.multiply(self.intensity * fctr,
                                        np.mat(r).T),
                            np.mat(ir).T)

            a = s + f

            e = np.sqrt(self.i)

            #            plt.cla()
            #            plt.plot(np.log10(e))
            #            plt.plot(np.log10(abs(a)))

            v = np.sum(
                abs(mask * (np.log10(abs(a) + 1e-6) - np.log10(e + 1e-6))))

            print(v)

            return v
Пример #2
0
    def surface_modulate(self, thrface=0.9, secface=0.9, surface=1.1):

        subr0 = self.var_table['posz_list']
        slab_index = 'posz'

        subr0[-3] = thrface
        subr0[-1] = surface
        subr0[-2] = secface
        key_list = ['pos']

        self.var_table['posz_list'][0] = thrface
        self.var_table['posz_list'][-1] = surface
        self.var_table['posz_list'][1] = secface

        #        print(subr0)

        fctr = structure.film_ctr(self.var_list, self.var_table, subr0,
                                  slab_index, self.iq, self.h, self.k,
                                  key_list)

        # roughness
        cr = roughness(self.iq)
        r = cr.robinson_roughness(self.roughness)
        # interface roughness
        ir = cr.interface_roughness(self.iroughness)

        return np.multiply(np.multiply(self.intensity * fctr,
                                       np.mat(r).T),
                           np.mat(ir).T)
Пример #3
0
    def sub_ctr(self):

        # the used keys
        key_list = ['absorption', 'roughness', 'scale']
        # input substrate ubr and substrate index
        subr, sindex = tc.initialize_contral_vars(self.ubr_index,
                                                  ['substrate'], key_list)

        substrate_ctr = structure.substrate_ctr(self.var_list, self.iq, subr,
                                                sindex, self.absorption,
                                                self.h, self.h, self.scale,
                                                key_list)

        # roughness
        cr = roughness(self.iq)
        r = cr.robinson_roughness(self.roughness)

        return np.multiply(self.intensity * substrate_ctr, np.mat(r).T)
Пример #4
0
    def slab_ctr(self):

        # used keys
        key_list = ['lattice_abc', 'dw']
        # input slab ubr and slab index
        slab_ubr, slab_index = tc.initialize_contral_vars(
            self.ubr_index,
            np.unique(self.var_table['slab_list']).tolist(), key_list)
        fctr = structure.film_ctr(self.var_list, self.var_table, slab_ubr,
                                  slab_index, self.iq, self.h, self.k,
                                  key_list)

        # roughness
        cr = roughness(self.iq)
        r = cr.robinson_roughness(self.roughness)
        # interface roughness
        ir = cr.interface_roughness(self.iroughness)

        return np.multiply(np.multiply(self.intensity * fctr,
                                       np.mat(r).T),
                           np.mat(ir).T)
Пример #5
0
    def pos_modulate(self, bc, sc, cl):

        subr0 = self.var_table['posz_list']
        slab_index = 'posz'

        subr0 = relax.strain_relax(subr0, cl, bc, sc)
        key_list = ['pos']

        print(subr0)

        fctr = structure.film_ctr(self.var_list, self.var_table, subr0,
                                  slab_index, self.iq, self.h, self.k,
                                  key_list)

        # roughness
        cr = roughness(self.iq)
        r = cr.robinson_roughness(self.roughness)
        # interface roughness
        ir = cr.interface_roughness(self.iroughness)

        return np.multiply(np.multiply(self.intensity * fctr,
                                       np.mat(r).T),
                           np.mat(ir).T)
Пример #6
0
def substrate_ctr(var_list,
                  iq,
                  sub_ubr,
                  sub_index,
                  beta=0,
                  u=0,
                  v=0,
                  scale=1e-4,
                  key_list=['absorption', 'pos', 'roughness', 'dw', 'scale']):
    """
       calculate the ctr rods of substrate
    """

    square_q = iq**2
    # sn for sampling number
    sn = len(iq)

    atoms = var_list['substrate']['pos']
    ions = (np.array(var_list['substrate']['ions']).tolist())[0]

    p = atoms.as_matrix()
    # thermal vibration distance
    dw = var_list['substrate']['dw']

    # r-- crystal surface roughness
    r = np.mat(np.ones([sn, 1]))

    "---------------------------------------------------------"

    # introduce the contral variable list
    # indicator to indicate the variable postion in ubr list

    for key in key_list:

        if key == 'absorption':
            # aor-- absorption indicator
            aor = tc.indicator_contral_vars(sub_ubr, sub_index, 'substrate',
                                            'absorption')
            beta = beta + (1 - sub_ubr[aor[0]:aor[1]][0])

        elif key == 'roughness':
            # ror--roughness indicator
            ror = tc.indicator_contral_vars(sub_ubr, sub_index, 'substrate',
                                            'roughness')
            # beta_r- roughness beta distinguish with absorption beta
            beta_r = sub_ubr[ror[0]:ror[1]][0] - 1
            cr = roughness(iq)
            r = np.mat(cr.robinson_roughness(beta_r)).T

        elif key == 'scale':
            # sor-- scale indicator
            sor = tc.indicator_contral_vars(sub_ubr, sub_index, 'substrate',
                                            'scale')
            scale = scale + sub_ubr[sor[0]:sor[1]][0]

        elif key == 'pos':
            # por-- pos indicator
            por = tc.indicator_contral_vars(sub_ubr, sub_index, 'substrate',
                                            'pos')
            # get pos ubr and reshape it into 3x5 matrix p.shape
            p_ubr = np.reshape(np.array(sub_ubr[por[0]:por[1]]), p.shape)
            p = np.multiply(p, p_ubr)

        elif key == 'dw':
            # dor-- debye waller factor indicator
            dor = tc.indicator_contral_vars(sub_ubr, sub_index, 'substrate',
                                            'dw')
            d_ubr = np.reshape(np.array(sub_ubr[dor[0]:dor[1]]), dw.shape)
            dw = np.multiply(dw, d_ubr)

    "---------------------------------------------------------"

    # a--atomic form factor
    a = atomic_form_factor(ions, square_q)

    # d--debye waller factor
    d = debye_waller_factor(dw, iq, u, v)

    # q--construct 3d qs space
    q = np.mat(np.zeros([sn, 3]))

    q[:, 0] = np.mat(np.ones([sn, 1])) * u  # qx
    q[:, 1] = np.mat(np.ones([sn, 1])) * v  # qy
    q[:, 2] = np.mat(iq).T

    # f--structure form factor
    f = np.multiply(np.multiply(a, d), np.exp(1j * 2 * np.pi * (np.dot(q, p))))

    # s--shape function
    s = 1/(1 - np.exp(-1*1j*2*np.pi*np.dot(q,np.mat([0,0,1]).T))*\
                                                    np.exp(-beta) +\
                                                    scale)

    #sctr--structure form factor for crystal turncation rod
    sctr = np.multiply(f, s)

    return np.multiply(np.sum(sctr, 1), r)
Пример #7
0
    def pos_refine(self):

        # the used keys
        sub_key_list = ['absorption', 'roughness', 'scale']
        # input substrate ubr and substrate index
        sub_ubr, sub_index = tc.initialize_contral_vars(
            self.ubr_index, ['substrate'], sub_key_list)

        substrate_ctr = structure.substrate_ctr(self.var_list, self.iq,
                                                sub_ubr, sub_index,
                                                self.absorption, self.h,
                                                self.h, self.scale,
                                                sub_key_list)

        # roughness
        cr = roughness(self.iq)
        r = cr.robinson_roughness(self.roughness)

        s = np.multiply(self.intensity * substrate_ctr, np.mat(r).T)

        subr0 = self.var_table['posz_list']
        slab_index = 'posz'
        key_list = ['pos']

        mask = tc.bragg_mask(self.iq, 3, 1, mode='yin', limit=24)

        #        fig, ax = plt.subplots()

        def varience(subr):

            fctr = structure.film_ctr(self.var_list, self.var_table, subr,
                                      slab_index, self.iq, self.h, self.k,
                                      key_list)

            # roughness
            cr = roughness(self.iq)
            # interface roughness
            ir = cr.interface_roughness(self.iroughness)

            f = np.multiply(np.multiply(self.intensity * fctr,
                                        np.mat(r).T),
                            np.mat(ir).T)

            a = s + f

            e = np.sqrt(self.i)

            #            plt.cla()
            #            plt.plot(np.log10(e))
            #            plt.plot(np.log10(abs(a)))

            v = np.sum(
                abs(mask * (np.log10(abs(a) + 1e-6) - np.log10(e + 1e-6))))

            print(v)

            return v

        re = so.minimize(varience,
                         subr0,
                         method='Nelder-Mead',
                         options={'maxiter': 50})
        subr1 = re.x

        fctr1 = structure.film_ctr(self.var_list, self.var_table, subr1,
                                   slab_index, self.iq, self.h, self.k,
                                   key_list)

        # roughness
        cr = roughness(self.iq)
        # interface roughness
        ir = cr.interface_roughness(self.iroughness)

        return np.multiply(np.multiply(self.intensity * fctr1,
                                       np.mat(r).T),
                           np.mat(ir).T)
Пример #8
0
    def dw_refine(self, p_mask=13, n_mask=3, weight=1, key_list=['dw']):

        # Prepare the data mask
        # yin mask to mask the bragg peaks
        bn_mask = np.mat(tc.bragg_mask(self.iq, n_mask, 1, mode='yin'))
        # yang mask to refine the signal around bragg peaks only
        bp_mask = np.mat(tc.bragg_mask(self.iq, p_mask, 1, mode='yang'))
        bgm = np.asarray(np.multiply(bn_mask, bp_mask).T).reshape(-1) * weight

        # calculate ss tot.For only seveal signal points are calculate
        # mean value is np.sum(abs(i)*bgm)/np.sum(bgm)
        ss_tot = np.sum(
            (abs(self.i) * bgm - np.sum(abs(self.i) * bgm) / np.sum(bgm))**2)

        # initialize the variable about the lattice
        slab_list = np.unique(self.var_table['slab_list']).tolist()
        ubr_index = tc.contral_vars(self.var_list)
        subr, sindex = tc.initialize_contral_vars(ubr_index, slab_list, ['dw'])

        # roughness
        cr = roughness(self.iq)
        r = cr.robinson_roughness(self.roughness)

        # substrate ctr
        # the used keys
        key_list = ['absorption', 'roughness', 'scale']
        # input substrate ubr and substrate index
        sub_ubr, sub_index = tc.initialize_contral_vars(
            self.ubr_index, ['substrate'], key_list)

        substrate_ctr = structure.substrate_ctr(self.var_list, self.iq,
                                                sub_ubr, sub_index,
                                                self.absorption, self.h,
                                                self.h, self.scale, key_list)

        def d_refine(d_var):

            fctr = structure.film_ctr(self.var_list, self.var_table, d_var,
                                      sindex, self.iq, self.h, self.k, ['dw'])

            ss = np.multiply(np.mat(fctr) + substrate_ctr,
                             np.mat(r).T) * self.intensity
            # calculate r square
            sa = np.asarray(ss).reshape(-1)
            ss_res = np.sum((abs(self.i) * bgm - abs(sa) * bgm)**2)
            varience = ss_res / ss_tot

            print(int(varience * 1e4) / 1e4)

            return varience

        d0 = subr
        re = so.minimize(d_refine, d0, method='Nelder-Mead', tol=1)

        self.ubr_index = tc.refresh_index(self.ubr_index, re.x, sindex)

        # plot the refined result

        fctr = structure.film_ctr(self.var_list, self.var_table, re.x, sindex,
                                  self.iq, self.h, self.k, ['dw'])

        ss = np.multiply(np.mat(fctr) + substrate_ctr, np.mat(r).T)
        plt.plot(self.iq, np.log(abs(ss * self.intensity)))
        plt.plot(self.iq, np.log(np.sqrt(self.i)))
Пример #9
0
    def lattice_refine(self, p_mask=13, n_mask=3, weight=1):

        # Prepare the data mask
        # yin mask to mask the bragg peaks
        bn_mask = np.mat(tc.bragg_mask(self.iq, n_mask, 1, mode='yin'))
        # yang mask to refine the signal around bragg peaks only
        bp_mask = np.mat(tc.bragg_mask(self.iq, p_mask, 1, mode='yang'))
        bgm = np.asarray(np.multiply(bn_mask, bp_mask).T).reshape(-1) * weight

        # calculate ss tot.For only seveal signal points are calculate
        # mean value is np.sum(abs(i)*bgm)/np.sum(bgm)
        ss_tot = np.sum((abs(self.i)*bgm - \
                         np.sum(abs(self.i)*bgm)/np.sum(bgm))**2)

        # initialize the variable about the lattice
        slab_list = np.unique(self.var_table['slab_list']).tolist()
        subr, sindex = tc.initialize_contral_vars(self.ubr_index, slab_list,
                                                  ['lattice_abc'])
        # substrate ctr
        # the used keys
        key_list = ['absorption', 'roughness', 'scale']
        # input substrate ubr and substrate index
        sub_ubr, sub_index = tc.initialize_contral_vars(
            self.ubr_index, ['substrate'], key_list)

        substrate_ctr = structure.substrate_ctr(self.var_list, self.iq,
                                                sub_ubr, sub_index,
                                                self.absorption, self.h,
                                                self.h, self.scale, key_list)

        # roughness
        cr = roughness(self.iq)
        r = cr.robinson_roughness(self.roughness)

        def c_refine(c_var):

            # input lattice c variable into subr
            if len(slab_list) == 1:
                subr[2] = c_var
            elif len(slab_list) >= 2:
                for slabi in range(len(slab_list)):
                    subr[slabi * 3 - 1] = c_var[slabi]

            fctr = structure.film_ctr(self.var_list, self.var_table, subr,
                                      sindex, self.iq, self.h, self.k,
                                      ['lattice_abc'])

            ss = np.multiply(np.mat(fctr) + substrate_ctr,
                             np.mat(r).T) * self.intensity
            # calculate r square
            sa = np.asarray(ss).reshape(-1)
            ss_res = np.sum((abs(self.i) * bgm - abs(sa) * bgm)**2)
            varience = ss_res / ss_tot

            print(int(varience * 1e4) / 1e4)

            return varience

        # select properity optimized method for lattice_c optimize

        # if there are only one or two variables, step_brute method is a direct method
        if len(slab_list) == 1:
            print('lattice c optimising....\nOPT_STEP_BRUTE method is used')
            rec = tt.opt_step_brute(c_refine, [[0.8, 1.2]], grid_size=20)
        elif len(slab_list) == 2:
            print('lattice c optimising....\nOPT_STEP_BRUTE method is used')
            rec = tt.opt_step_brute(c_refine, [[0.8, 1.2], [0.8, 1.2]],
                                    grid_size=10)

        # for larger variable number, Nelder-Mead method is more comparable
        elif len(slab_list) >= 3:
            print('lattice c optimising....\nNELDER_MEAD method is used')
            c0 = np.ones(len(slab_list)).tolist()
            resc = so.minimize(c_refine, c0, method='Nelder-Mead', tol=10)
            rec = resc.x

        # update subr
        if len(slab_list) == 1:
            subr[2] = rec
        elif len(slab_list) >= 2:
            for slabi in range(len(slab_list)):
                subr[slabi * 3 - 1] = rec[0][slabi]

        # update ubr_index
        self.ubr_index = tc.refresh_index(self.ubr_index, subr, sindex)

        # plot the refined result

        fctr = structure.film_ctr(self.var_list, self.var_table, subr, sindex,
                                  self.iq, self.h, self.k, ['lattice_abc'])

        ss = np.multiply(np.mat(fctr) + substrate_ctr, np.mat(r).T)
        plt.plot(self.iq, np.log(abs(ss * self.intensity)))
        plt.plot(self.iq, np.log(np.sqrt(self.i)))