Skip to content

Commit

Permalink
fix a bug due to wrong scaling factor applied to f_ideal
Browse files Browse the repository at this point in the history
  • Loading branch information
jackey-qiu committed May 20, 2021
1 parent 88f1d3b commit 8c88a69
Show file tree
Hide file tree
Showing 10 changed files with 1,807 additions and 63 deletions.
8 changes: 4 additions & 4 deletions EnginePool/models/setup_domain_hematite_rcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ def setup_raxr_pars_new(NUMBER_SPECTRA,F1F2_FILE):
F1F2=np.loadtxt(os.path.join(F1F2_FILE))
rgh_raxr=UserVars()
for i in range(NUMBER_SPECTRA):
rgh_raxr.new_var('a'+str(i+1),0.0)
rgh_raxr.new_var('b'+str(i+1),0.0)
rgh_raxr.new_var('c'+str(i+1),0.0)
rgh_raxr.new_var('A_'+str(i+1),2.0)
rgh_raxr.new_var('a'+str(i+1),1.0)
rgh_raxr.new_var('b'+str(i+1),1.0)
rgh_raxr.new_var('c'+str(i+1),1.0)
rgh_raxr.new_var('A_'+str(i+1),0.2)
rgh_raxr.new_var('P_'+str(i+1),0.0)
else:
rgh_raxr=None
Expand Down
Binary file not shown.
Binary file not shown.
5 changes: 5 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.scaling_tag_raxs = []
self.data_sequence = []
for i,each in enumerate(self.items):
if hasattr(each,'mask'):
Expand All @@ -572,6 +573,10 @@ def concatenate_all_ctr_datasets(self):
if x[0]>100:#x column is energy for raxs (in ev); but x column is L for CTR (smaller than 10 usually)
data_type_tag = 100+i#datasets with tag>100 are raxs data
self.data_sequence.append(data_type_tag)
if int(h[0])==0 and int(k[0])==0:
self.scaling_tag_raxs.append('specular_rod')
else:
self.scaling_tag_raxs.append('nonspecular_rod')
else:
data_type_tag = 1+i#datasets with tag>1 but <100 are ctr data
self.data_sequence.append(data_type_tag)
Expand Down
Binary file modified examples/hematite_rcut_AD/test.rod
Binary file not shown.
1,772 changes: 1,772 additions & 0 deletions examples/hematite_rcut_AD/test_data.csv

Large diffs are not rendered by default.

Binary file added examples/hematite_rcut_AD/test_data.xlsx
Binary file not shown.
8 changes: 6 additions & 2 deletions projects/superrod/SuPerRod_GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,10 @@ def calc_f_ideal(self):
self.f_ideal = []
for i in range(len(self.model.data)):
each = self.model.data[i]
self.f_ideal.append(self.model.script_module.sample.calc_f_ideal(each.extra_data['h'], each.extra_data['k'], each.x)**2)
if each.x[0]>1000:#indicate energy column
self.f_ideal.append(self.model.script_module.sample.calc_f_ideal(each.extra_data['h'], each.extra_data['k'], each.extra_data['Y'])**2)
else:
self.f_ideal.append(self.model.script_module.sample.calc_f_ideal(each.extra_data['h'], each.extra_data['k'], each.x)**2)

def update_plot_data_view(self):
"""update views of all figures if script is compiled, while only plot data profiles if otherwise"""
Expand Down Expand Up @@ -1128,7 +1131,8 @@ def _get_index(index_in_use):

#plot ideal structure factor
try:
scale_factor = [self.model.script_module.rgh.scale_nonspecular_rods,self.model.script_module.rgh.scale_specular_rod][int("00L" in self.model.data[i].name)]
specular_condition = int(round(self.model.data[_get_index(i+offset)].extra_data['h'][0],0))==0 and int(round(self.model.data[_get_index(i+offset)].extra_data['k'][0],0))==0
scale_factor = [self.model.script_module.rgh.scale_nonspecular_rods,self.model.script_module.rgh.scale_specular_rod][int(specular_condition)]
h_, k_ = int(round(self.model.data[_get_index(i+offset)].extra_data['h'][0],0)),int(round(self.model.data[_get_index(i+offset)].extra_data['k'][0],0))
extra_scale_factor = 'scale_factor_{}{}L'.format(h_,k_)
if hasattr(self.model.script_module.rgh,extra_scale_factor):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import models.setup_domain_hematite_rcut as setup_domain_hematite_rcut
from accessory_functions.data_formating.data_formating import format_hkl
from UtilityFunctions import config_file_parser_bv, update_O_NUMBER
from UtilityFunctions import config_file_parser_bv, update_O_NUMBER, setup_raxr_pars_new
from FitEnginePool import bond_valence_constraint

model_type = 'ctr'
Expand All @@ -23,7 +23,7 @@
F1F2_FILE='As_K_edge_March28_2018.f1f2'
#/raxs/end#
if NUMBER_SPECTRA!=0:
rgh_raxs,F1F2=setup_domain_hematite_rcut.setup_raxr_pars_new(NUMBER_SPECTRA, F1F2_FILE)
rgh_raxs,F1F2 = setup_raxr_pars_new(NUMBER_SPECTRA, F1F2_FILE)
else:
rgh_raxs, F1F2 = None, []

Expand Down Expand Up @@ -235,8 +235,8 @@ def Sim(data,VARS=vars()):
sub_sets, data_info = data.split_used_dataset(F_, data_type = 'RAXS')
F_ = data.insert_datasets(full_set = F_all, sub_sets = sub_sets, data_info = data_info, data_type = 'RAXS')
#you need to edit the list of extra scaling factor accordingly
#scaling_factors = [[rgh.scale_nonspecular_rods, rgh.scale_specular_rod][int(each=='specular_rod')] for each in data.scaling_tag]
F_raxs = data.split_fullset(F_,scale_factors=1, data_type = 'RAXS')
scaling_factors = [[rgh.scale_nonspecular_rods, rgh.scale_specular_rod][int(each=='specular_rod')] for each in data.scaling_tag_raxs]
F_raxs = data.split_fullset(F_,scale_factors=scaling_factors, data_type = 'RAXS')
else:
F_raxs=data.split_fullset(data.ctr_data_all[condition_raxs][:,0]*0,scale_factors=1, data_type = 'RAXS')

Expand All @@ -251,56 +251,3 @@ def Sim(data,VARS=vars()):
bv += VARS['bv_constraint_domain{}'.format(i+1)].cal_distance()

return F,1+bv,fom_scaler
'''
def Sim(data,VARS=vars()):
F =[]
fom_scaler=[]
beta=rgh.beta
#/update_sorbate/begin#
for i in range(num_sorbate_slabs):
VARS['{}{}'.format(VARS['sorbate_instance_head'],i+1)].set_coordinate_all_rgh()
#/update_sorbate/end#
#normalize the domain weight to make total = 1
wt_list = [getattr(rgh_wt, 'wt_domain{}'.format(i+1)) for i in range(num_surface_slabs)]
total_wt = sum(wt_list)
for i in range(num_surface_slabs):
sample.domain['domain{}'.format(i+1)]['wt']=wt_list[i]/total_wt
#faster solution(a factor of two faster than using loop)
#ctr datasets
condition_ctr = data.ctr_data_all[:,-1]<100
h_, k_, x_,LB_,dL_ = data.ctr_data_all[condition_ctr][:,0], data.ctr_data_all[condition_ctr][:,1], data.ctr_data_all[condition_ctr][:,2],data.ctr_data_all[condition_ctr][:,4],data.ctr_data_all[condition_ctr][:,5]
rough_ = (1-beta)/((1-beta)**2 + 4*beta*np.sin(np.pi*(x_-LB_)/dL_)**2)**0.5
f_ = rough_*sample.calc_f_all(h_, k_, x_)
F_ = abs(f_*f_)
#you need to edit the list of extra scaling factor accordingly
scaling_factors = [[rgh.scale_nonspecular_rods, rgh.scale_specular_rod][int(each=='specular_rod')] for each in data.scaling_tag]
F_ctr = data.split_fullset(F_,scaling_factors)
#raxs datasets
condition_raxs = data.ctr_data_all[:,-1]>=100
if True in list(condition_raxs):
h_, k_, E_, l_, LB_,dL_ = data.ctr_data_all[condition_raxs][:,0], data.ctr_data_all[condition_raxs][:,1], data.ctr_data_all[condition_raxs][:,2],data.ctr_data_all[condition_raxs][:,3], data.ctr_data_all[condition_raxs][:,4],data.ctr_data_all[condition_raxs][:,5]
rough_ = (1-beta)/((1-beta)**2 + 4*beta*np.sin(np.pi*(l_-LB_)/dL_)**2)**0.5
f_ = rough_*sample.calc_f_all_RAXS(h_, k_, l_, E_)
F_ = abs(f_*f_)
#you need to edit the list of extra scaling factor accordingly
#scaling_factors = [[rgh.scale_nonspecular_rods, rgh.scale_specular_rod][int(each=='specular_rod')] for each in data.scaling_tag]
F_raxs = data.split_fullset(F_,scale_factors=1, data_type = 'RAXS')
else:
F_raxs = []
#Now merge both datasets together
F = data.merge_datasets(ctr_datasets = F_ctr, raxs_datasets = F_raxs)
fom_scaler = [1]*len(F)
#calculate bv panelty factor
bv = 0
if USE_BV:
for i in range(num_surface_slabs):
bv += VARS['bv_constraint_domain{}'.format(i+1)].cal_distance()
return F,1+bv,fom_scaler
'''
16 changes: 16 additions & 0 deletions util/UtilityFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,28 @@
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
DaFy_Path = os.path.dirname(currentdir)
sys.path.append(os.path.join(DaFy_Path,'EnginePool'))
from models.utils import UserVars
import FitEnginePool
import matplotlib.pyplot as pyplot
#make compatibility of py 2 and py 3#
if (sys.version_info > (3, 0)):
raw_input = input

def setup_raxr_pars_new(NUMBER_SPECTRA,F1F2_FILE):
if NUMBER_SPECTRA!=0:
F1F2=np.loadtxt(os.path.join(F1F2_FILE))
rgh_raxr=UserVars()
for i in range(NUMBER_SPECTRA):
rgh_raxr.new_var('a'+str(i+1),1.0)
rgh_raxr.new_var('b'+str(i+1),1.0)
rgh_raxr.new_var('c'+str(i+1),1.0)
rgh_raxr.new_var('A_'+str(i+1),0.2)
rgh_raxr.new_var('P_'+str(i+1),0.0)
else:
rgh_raxr=None
F1F2=None
return rgh_raxr,F1F2

def config_file_parser_bv(config_file):
return_lib = {}
config = configparser.RawConfigParser()
Expand Down

0 comments on commit 8c88a69

Please sign in to comment.