Skip to content

Commit

Permalink
some bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jackey-qiu committed May 11, 2021
1 parent 26e8f44 commit f013e3d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
37 changes: 34 additions & 3 deletions EnginePool/models/structure_tools/sxrd_dafy.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,43 @@ def calc_f_all(self, h, k, l):
return abs(ftot)*self.inst.inten

def calc_f_all_RAXS(self, h, k, l, a,b,c,A_list,P_list, E, E0, f1f2, res_el, mode = 'MD'):
f_ctr = self.calc_f_all(h, k, l)
'''
Calculate the structure factors for the sample
Here the surface structure is diveded into the subtrate itself and the sorbate atoms
The format of domain has a structure like: domain = {'domain1':{'slab':slab,'wt':weight,'sorbate':sorbate}}
'''
#here the chemically equivalent domains will be added up in-coherently always
ftot=0
# key = (h[0],k[0],l[0],l[-1])
# if key in self.fb:
# fb = self.fb[key]
# else:
# fb = self.calc_fb(h, k, l)
# self.fb[key] = fb
fb = self.calc_fb(h, k, l)

if mode == 'MD':
f_raxs, scale = self.calc_fs_sorbate_RAXS_MD(h, k, l,self.domain[key]['sorbate'],self.domain[key]['sorbate_sym'],a,b,c,E,E0,f1f2,res_el)
elif mode == 'MI':
f_raxs, scale = self.calc_fs_sorbate_RAXS_MI(f1f2,E, E0, a, b, c, A_list,P_list)
return scale*(f_ctr + f_raxs)

if self.coherence==True:
for key in self.domain.keys():
f_water = self.calc_f_layered_water_copper(h, k, l, rgh = self.domain[key])
if self.domain[key]['wt']!=0:
if type(self.domain[key]['sorbate'])==type([]):
ftot = ftot+(fb+self.calc_fs(h, k, l,[self.domain[key]['slab']])+self.calc_fs_sorbate(h, k, l,self.domain[key]['sorbate'],self.domain[key]['sorbate_sym'])+f_raxs+f_water)*self.domain[key]['wt']
else:
ftot = ftot+(fb+self.calc_fs(h, k, l,[self.domain[key]['slab']])+self.calc_fs_sorbate(h, k, l,[self.domain[key]['sorbate']],self.domain[key]['sorbate_sym'])+f_raxs+f_water)*self.domain[key]['wt']
else:
for key in self.domain.keys():
f_water = self.calc_f_layered_water_copper(h, k, l, rgh = self.domain[key])
if self.domain[key]['wt']!=0:
if type(self.domain[key]['sorbate'])==type([]):
ftot = ftot+abs(fb+self.calc_fs(h, k, l,[self.domain[key]['slab']])+self.calc_fs_sorbate(h, k, l,self.domain[key]['sorbate'],self.domain[key]['sorbate_sym'])+f_raxs+f_water)*self.domain[key]['wt']
else:
ftot = ftot+abs(fb+self.calc_fs(h, k, l,[self.domain[key]['slab']])+self.calc_fs_sorbate(h, k, l,[self.domain[key]['sorbate']],self.domain[key]['sorbate_sym'])+f_raxs+f_water)*self.domain[key]['wt']
return abs(ftot)*self.inst.inten*scale

def calc_f_ideal(self, h, k, l):
'''
Expand Down Expand Up @@ -2658,7 +2689,7 @@ def _extract_f1f2(f1f2,E):
if len(f1f2)!=len(E):
f1f2=_extract_f1f2(f1f2,E)
scaling_factor = np.exp(-a*(E-E0)**2/E0**2+b*(E-E0)/E0)*c
return (f1f2[:,0]+1.0J*f1f2[:,1])*A_list*np.exp(1.0J*np.pi*2*P_list)),scaling_factor
return (f1f2[:,0]+1.0J*f1f2[:,1])*A_list*np.exp(1.0J*np.pi*2*P_list),scaling_factor

def calc_fs_sorbate_RAXS_MD(self, h, k, l,slabs, sorbate_sym,a,b,c,E,E0,f1f2,res_el='Pb'):
'''Calculate the structure factors from the surface
Expand Down
17 changes: 17 additions & 0 deletions FilterPool/data_superrod.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ def concatenate_all_ctr_datasets(self):
all_ctr_data = []
self.ctr_data_info = {}
self.scaling_tag = []
self.data_type = []
for i,each in enumerate(self.items):
if hasattr(each,'mask'):
h,k,x,y,LB,dL = each.extra_data['h'][each.mask][:,np.newaxis],each.extra_data['k'][each.mask][:,np.newaxis],each.x[each.mask][:,np.newaxis],each.extra_data['Y'][each.mask][:,np.newaxis],each.extra_data['LB'][each.mask][:,np.newaxis],each.extra_data['dL'][each.mask][:,np.newaxis]
Expand All @@ -572,6 +573,10 @@ def concatenate_all_ctr_datasets(self):
self.scaling_tag.append('specular_rod')
else:
self.scaling_tag.append('nonspecular_rod')
if x[0]>100:#x column is energy for raxs (in ev); but x column is L for CTR (smaller than 10 usually)
self.data_type.append('RAXS')
else:
self.data_type.append('CTR')
#mask = np.ones(len(h))[:,np.newaxis]
fbulk = np.zeros(len(h))[:,np.newaxis]
temp_data = np.hstack((h,k,x,y,LB,dL,fbulk))
Expand All @@ -590,6 +595,18 @@ def split_fullset(self,full_set,scale_factors):
sub_sets.append(full_set[cum_sum[i]:cum_sum[i+1]]*scale_factors[i])
return sub_sets

def get_ctr_raxs_data(self, full_set, scale_factors):
sub_sets = self.split_fullset(full_set, scale_factors)
sub_sets_ctr = []
sub_sets_raxs = []
for i in range(len(self.data_type)):
each = self.data_type[i]
if each == 'CTR':
sub_sets_ctr.append(sub_sets[i])
elif each == 'RAXS':
sub_sets_raxs.append(sub_sets[i])
return sub_sets_ctr,sub_sets_raxs

def __getitem__(self,key):
'''__getitem__(self,key) --> DataSet
Expand Down

0 comments on commit f013e3d

Please sign in to comment.