Example #1
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)
Example #2
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
Example #3
0
        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
Example #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)
Example #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)
Example #6
0
        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
Example #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)
Example #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)))
Example #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)))