def build_instance(cls,xyzu_oc_m = [0.5, 0.5, 1.5, 0.1, 1, 1], els = ['O','C','C','O'], flat_down_index = [2],anchor_index_list = [1, None, 1, 2 ], lat_pars = [3.615, 3.615, 3.615, 90, 90, 90]): domain = model_2.Slab(T_factor = 'u') ids_all = deepcopy(els) for each in set(els): index_temp_all = list(np.where(np.array(els) == each)[0]) for index_temp in index_temp_all: ids_all[index_temp] = "{}{}".format(ids_all[index_temp], index_temp_all.index(index_temp)+1) for i in range(len(ids_all)): domain.add_atom(ids_all[i],els[i],*xyzu_oc_m) ids = deepcopy(ids_all) del(ids[anchor_index_list.index(None)]) anchor_id = ids_all[anchor_index_list.index(None)] flat_down_index_new = [[i,i-1][int(i>anchor_index_list.index(None))] for i in flat_down_index] r_list_names = [] gamma_list_names = [] delta_list_names = [] for i in range(len(anchor_index_list)): each = anchor_index_list[i] if each != None: #if i not in flat_down_index: delta_list_names.append("delta_{}_{}".format(ids_all[i],ids_all[each])) if each != None: r_list_names.append("r_{}_{}".format(ids_all[i],ids_all[each])) gamma_list_names.append("gamma_{}_{}".format(ids_all[i],ids_all[each])) rgh = UserVars() rgh.new_var('gamma',0) rgh.new_var('rot_ang_x',0) rgh.new_var('rot_ang_y',0) for r in r_list_names: rgh.new_var(r, 1.5) for i in range(len(delta_list_names)): delta = delta_list_names[i] if i in flat_down_index_new: rgh.new_var(delta, 0) else: rgh.new_var(delta, 20) #for gamma in gamma_list_names: # rgh.new_var(gamma, 10) instance = cls(domain, ids, anchor_id, flat_down_index = flat_down_index_new, lat_pars = lat_pars) instance.rgh = rgh instance.r_list_names = r_list_names instance.delta_list_names = delta_list_names instance.gamma_list_names = gamma_list_names instance.gamma_handedness = [1]*anchor_index_list.index(None)+[0]*(len(anchor_index_list)-anchor_index_list.index(None)-1) instance.new_anchor_list = [ids_all[i] for i in anchor_index_list if i!=None] instance.rot_ang_x_list = [0] * len(instance.ids) instance.rot_ang_y_list = [0] * len(instance.ids) return instance
#setup grouping scheme GROUPING_SCHEMES=[[1,0]]#domain tag of first domain is 0 GROUPING_DEPTH=[[0,10]]#means I will group top 10 (range(0,10)) layers of domain1 and domain2 together #setting slabs## wal=0.83345#wavelength of x ray unitcell = model.UnitCell(5.038, 5.434, 7.3707, 90, 90, 90) SURFACE_PARMS={'delta1':0.,'delta2':0.1391}#correction factor in surface unit cell inst = model.Instrument(wavel = wal, alpha = 2.0) bulk = model.Slab(T_factor='B') ref_S_domain1 = model.Slab(c = 1.0,T_factor='B') ref_L_domain1 = model.Slab(c = 1.0,T_factor='B') ref_S_domain2 = model.Slab(c = 1.0,T_factor='B') ref_L_domain2 = model.Slab(c = 1.0,T_factor='B') rgh=UserVars() rgh.new_var('beta', 0.0)#roughness factor rgh.new_var('mu',1)#liquid film thickness scales=['scale_CTR'] for scale in scales: rgh.new_var(scale,1.) #set up experimental constant# re = 2.818e-5#electron radius kvect=2*np.pi/wal#k vector Egam = 6.626*(10**-34)*3*(10**8)/wal*10**10/1.602*10**19#energy in ev LAM=1.5233e-22*Egam**6 - 1.2061e-17*Egam**5 + 2.5484e-13*Egam**4 + 1.6593e-10*Egam**3 + 1.9332e-06*Egam**2 + 1.1043e-02*Egam exp_const = 4*kvect/LAM auc=unitcell.a*unitcell.b*np.sin(unitcell.gamma) #bond valence setup# COVALENT_HYDROGEN_RANDOM=False
#Adding sorbates to domainA and domainB sorbate_methods = {0:"setup_sorbate_OS_new", 1:"setup_sorbate_MD_new", 2:"setup_sorbate_BD_new", 3:"setup_sorbate_TD_new"} for j in range(sum(SORBATE_NUMBER[i])): method_ = getattr(setup_domain_hematite_rcut,sorbate_methods[len(SORBATE_ATTACH_ATOM[i][j])]) return_list = method_(vars(),i,j) vars()['gp_sorbates_set'+str(j+1)+'_D'+str(int(i+1))],vars()['gp_HO_set'+str(j+1)+'_D'+str(int(i+1))]=return_list #setup water layers water_gp_names,water_groups=setup_domain_hematite_rcut.setup_layer_structure(vars(),i) for iii in range(len(water_groups)):vars()[water_gp_names[iii]]=water_groups[iii] #/setup_slabs/end# #/setup_rgh_global/begin# rgh=UserVars() rgh.new_var('beta', 0.0)#roughness factor rgh.new_var('mu',1)#liquid film thickness scales=['scale_CTR'] for scale in scales: rgh.new_var(scale,1.) #/setup_rgh_global/end# #/build_parameter/begin# O_N,binding_mode=setup_domain_hematite_rcut.setup_fit_table(O_NUMBER,DOMAIN_NUMBER,SORBATE_ATTACH_ATOM) make_grid.make_structure(list(map(sum,SORBATE_NUMBER)),O_N,WATER_NUMBER,DOMAIN, Metal=SORBATE,binding_mode=binding_mode,\ long_slab=full_layer_pick,long_slab_HL=half_layer_pick,\ local_structure=LOCAL_STRUCTURE,add_distal_wild=ADD_DISTAL_LIGAND_WILD,\ use_domains=[1]*DOMAIN_NUMBER,N_raxr=NUMBER_SPECTRA,domain_raxr_el=RESONANT_EL_LIST,\ layered_water=layered_water_pars['yes_OR_no'],layered_sorbate=layered_sorbate_pars['yes_OR_no'],\ tab_path=os.path.join(output_file_path,'table.tab'))
vars()['id_match_in_sym_domain'+str(int(i+1))]={'Fe':vars()['sym_file_Fe_domain'+str(int(i+1))],'O':vars()['sym_file_O_domain'+str(int(i+1))],'Pb':vars()['sym_file_Pb_domain'+str(int(i+1))]} #id list according to the order in the reference domain ref_id_list_1=["O1_1_0","O1_2_0","Fe1_2_0","Fe1_3_0","O1_3_0","O1_4_0","Fe1_4_0","Fe1_6_0","O1_5_0","O1_6_0","O1_7_0","O1_8_0","Fe1_8_0","Fe1_9_0","O1_9_0","O1_10_0","Fe1_10_0","Fe1_12_0","O1_11_0","O1_12_0",\ 'O1_1_1','O1_2_1','Fe1_2_1','Fe1_3_1','O1_3_1','O1_4_1','Fe1_4_1','Fe1_6_1','O1_5_1','O1_6_1','O1_7_1','O1_8_1','Fe1_8_1','Fe1_9_1','O1_9_1','O1_10_1','Fe1_10_1','Fe1_12_1','O1_11_1','O1_12_1'] ref_id_list_2=["O1_11_t","O1_12_t","O1_1_0","O1_2_0","Fe1_2_0","Fe1_3_0","O1_3_0","O1_4_0","Fe1_4_0","Fe1_6_0","O1_5_0","O1_6_0","O1_7_0","O1_8_0","Fe1_8_0","Fe1_9_0","O1_9_0","O1_10_0","Fe1_10_0","Fe1_12_0","O1_11_0","O1_12_0",\ 'O1_1_1','O1_2_1','Fe1_2_1','Fe1_3_1','O1_3_1','O1_4_1','Fe1_4_1','Fe1_6_1','O1_5_1','O1_6_1','O1_7_1','O1_8_1','Fe1_8_1','Fe1_9_1','O1_9_1','O1_10_1','Fe1_10_1','Fe1_12_1','O1_11_1','O1_12_1'] ###############################################setting slabs################################################################## unitcell = model.UnitCell(5.038, 5.434, 7.3707, 90, 90, 90) inst = model.Instrument(wavel = .833, alpha = 2.0) bulk = model.Slab(T_factor='B') ref_domain1 = model.Slab(c = 1.0,T_factor='B') ref_domain2 = model.Slab(c = 1.0,T_factor='B') rgh=UserVars() rgh.new_var('beta', 0.0) ################################################build up ref domains############################################ #add atoms for bulk and two ref domains (ref_domain1<half layer> and ref_domain2<full layer>) #In those two reference domains, the atoms are ordered according to first hight (z values), then y values #it is a super surface structure by stacking the surface slab on bulk slab, the repeat vector was counted try: add_atom_in_slab(bulk,batch_path_head+'bulk.str') except: batch_path_head='D:\\Github\\batchfile\\' add_atom_in_slab(bulk,batch_path_head+'bulk.str') add_atom_in_slab(ref_domain1,batch_path_head+'half_layer2.str') add_atom_in_slab(ref_domain2,batch_path_head+'full_layer2.str') #symmetry library, note the Fe output file is the same, but O and Pb output file is different due to different sorbate configuration for i in range(DOMAIN_NUMBER): vars()['sym_file_domain'+str(int(i+1))]={'Fe':batch_path_head+'Fe output file for Genx reading.txt',\ 'O':batch_path_head+'O output file for Genx reading'+str(O_NUMBER[i])+'_'+str(int(DOMAIN[i]))+'.txt',\
#/sorbateproperties/end# #/sorbatestructure/begin# #OCCO # O1 O2 # \ / # C1-C2 #=================== #/sorbatestructure/end# #--set rgh--# #/rgh/begin# #/rgh/global/begin# rgh = UserVars() rgh.new_var('beta', 0.0) #roughness factor rgh.new_var('mu', 1) #liquid film thickness scales = ['scale_nonspecular_rods', 'scale_specular_rod'] for scale in scales: rgh.new_var(scale, 0.0005) #/rgh/global/end# #/rgh/layer_water/begin# rgh_lw = UserVars() pars = ['u0', 'ubar', 'd_w', 'first_layer_height', 'density_w'] rgh_lw.new_var('u0', 2) rgh_lw.new_var('ubar', 2) rgh_lw.new_var('first_layer_height', 2) rgh_lw.new_var('d_w', 2) rgh_lw.new_var('density_w', 0.033) #/rgh/layer_water/end#
0.0,0.0,0.0]) l=np.array([0.345508,0.465508,0.545508,0.685508,0.815508,1.08551,1.38551,1.64551,2.24551 ,2.57551,2.78551,3.14551,3.48551,4.17551,4.48551,5.54551,6.18551,7.24551,9.08551 ,10.2455,11.0855]) zs=np.array([ 2. , 4.8, 7.6, 10.4, 13.2, 16. , 18.8, 21.6, 24.4, 27.2, 30. ]) water_scaling= 0.376587994184 ##cal q list q_list=np.array(create_plots.q_list_func(h,k,l)) ##define fitting parameters rgh_u=UserVars() rgh_oc=UserVars() for i in range(len(zs)): rgh_u.new_var('u'+str(i+1),0.2) rgh_oc.new_var('oc'+str(i+1),1.) def Sim(data): u_list=[] oc_list=[] ##<Extract pars>## for i in range(len(zs)): u_list.append(getattr(rgh_u,'getU'+str(i+1))()) oc_list.append(getattr(rgh_oc,'getOc'+str(i+1))()) ##<calculate e density>## F,fom_scaler=[],[] i=0 for data_set in data: f=np.array([])
#/sorbatestructure/begin# #1 C1 #2 | #3 C2-O1-C3 #4 | #5 C4 # =================== #/sorbatestructure/end# #--set rgh--# #/rgh/begin# #/rgh/global/begin# rgh = UserVars() rgh.new_var('beta', 0.0) #roughness factor rgh.new_var('mu', 1) #liquid film thickness scales = ['scale_nonspecular_rods', 'scale_specular_rod'] for scale in scales: rgh.new_var(scale, 1.) #/rgh/global/end# #/rgh/domain_weight/begin# rgh_wt = UserVars() for i in range(num_surface_slabs): rgh_wt.new_var('wt_domain{}'.format(i + 1), 1) #/rgh/domain_weight/end# #/rgh/end# #/atmgroup/begin# #/substrate/start#
vars()['id_match_in_sym_domain'+str(int(i+1))]={'Fe':vars()['sym_file_Fe_domain'+str(int(i+1))],'O':vars()['sym_file_O_domain'+str(int(i+1))],'Pb':vars()['sym_file_Pb_domain'+str(int(i+1))]} ##id list according to the order in the reference domain (used to set up ref domain) ref_id_list_1=["O1_1_0","O1_2_0","Fe1_2_0","Fe1_3_0","O1_3_0","O1_4_0","Fe1_4_0","Fe1_6_0","O1_5_0","O1_6_0","O1_7_0","O1_8_0","Fe1_8_0","Fe1_9_0","O1_9_0","O1_10_0","Fe1_10_0","Fe1_12_0","O1_11_0","O1_12_0",\ 'O1_1_1','O1_2_1','Fe1_2_1','Fe1_3_1','O1_3_1','O1_4_1','Fe1_4_1','Fe1_6_1','O1_5_1','O1_6_1','O1_7_1','O1_8_1','Fe1_8_1','Fe1_9_1','O1_9_1','O1_10_1','Fe1_10_1','Fe1_12_1','O1_11_1','O1_12_1'] ref_id_list_2=["O1_11_t","O1_12_t","O1_1_0","O1_2_0","Fe1_2_0","Fe1_3_0","O1_3_0","O1_4_0","Fe1_4_0","Fe1_6_0","O1_5_0","O1_6_0","O1_7_0","O1_8_0","Fe1_8_0","Fe1_9_0","O1_9_0","O1_10_0","Fe1_10_0","Fe1_12_0","O1_11_0","O1_12_0",\ 'O1_1_1','O1_2_1','Fe1_2_1','Fe1_3_1','O1_3_1','O1_4_1','Fe1_4_1','Fe1_6_1','O1_5_1','O1_6_1','O1_7_1','O1_8_1','Fe1_8_1','Fe1_9_1','O1_9_1','O1_10_1','Fe1_10_1','Fe1_12_1','O1_11_1','O1_12_1'] ###############################################setting slabs################################################################## unitcell = model.UnitCell(5.038, 5.434, 7.3707, 90, 90, 90) inst = model.Instrument(wavel = .833, alpha = 2.0) bulk = model.Slab(T_factor='B') ref_domain1 = model.Slab(c = 1.0,T_factor='B') ref_domain2 = model.Slab(c = 1.0,T_factor='B') rgh=UserVars() rgh.new_var('beta', 0.0) scales=['scale_CTR','scale_RAXS'] for scale in scales: rgh.new_var(scale,1.) ################################################build up ref domains############################################ #add atoms for bulk and two ref domains (ref_domain1<half layer> and ref_domain2<full layer>) #In those two reference domains, the atoms are ordered according to first hight (z values), then y values #it is a super surface structure by stacking the surface slab on bulk slab, the repeat vector was counted #only two possible path(one for runing in pacman, the other in local laptop) try: add_atom_in_slab(bulk,batch_path_head+'bulk.str') except: batch_path_head='D:\\Github\\batchfile\\' add_atom_in_slab(bulk,batch_path_head+'bulk.str')
else: h=np.array([ 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 ]) k=np.array([ 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 ]) l=np.array([ 0.41,0.53,0.61,0.75,0.88,1.15,1.45,1.71,2.31,2.64,2.85,3.21,3.55,4.24,4.55,5.61,6.25,7.31,9.15,10.31,11.15 ]) zs=np.array([ 1.5,3.65,5.85,7.7,9.7,11.75,17.05,19.1,21.1,23.1,25.25,27.45,29.55,32.0,34.45,36.5,38.6,40.65,42.55,44.65,48.0,49.85 ]) water_scaling= 0.33 ##cal q list q_list=np.array(create_plots.q_list_func(h,k,l)) ##define fitting parameters rgh_u=UserVars() rgh_oc=UserVars() rgh_dz=UserVars() for i in range(len(zs)): rgh_u.new_var('u'+str(i+1),0.2) rgh_oc.new_var('oc'+str(i+1),0.) rgh_dz.new_var('dz'+str(i+1),0.) def Sim(data): u_list=[] oc_list=[] z_list=[] ##<Extract pars>## for i in range(len(zs)): u_list.append(getattr(rgh_u,'getU'+str(0+1))()) oc_list.append(getattr(rgh_oc,'getOc'+str(i+1))()) z_list.append(getattr(rgh_dz,'getDz'+str(i+1))()+zs[i]) ##<calculate e density>## F,fom_scaler=[],[]
c=unitcell.c,domain_tag='_D1',\ shape=gaussian_shape_freeze,\ gaussian_rms = 2,\ freeze_tag=True) for i in range(len(Gaussian_groups_freeze)): vars()[Gaussian_group_names_freeze[i]]=Gaussian_groups_freeze[i] rgh_gaussian_freeze=domain_creator.define_gaussian_vars(rgh=UserVars(),domain=surface_1,shape=gaussian_shape_freeze,freeze_tag=True) #/gaussian_type2/end# #/sorbateproperties/end# #--set rgh--# #/rgh/begin# #/rgh/global/begin# rgh = UserVars() rgh.new_var('wt1', 1.0)#roughness factor rgh.new_var('beta', 0.0)#roughness factor rgh.new_var('ra_conc', 0.0)#resonant el conc in M rgh.new_var('mu',1)#liquid film thickness scales=['scale_nonspecular_rods','scale_specular_rod'] for scale in scales: rgh.new_var(scale,1.) #/rgh/global/end# #/rgh/domain_weight/begin# rgh_wt = UserVars() for i in range(num_surface_slabs): rgh_wt.new_var('wt_domain{}'.format(i+1),1) #/rgh/domain_weight/end# #/rgh/others/begin# rgh_raxs=domain_creator.define_raxs_vars(rgh=UserVars(),number_spectra=number_raxs_spectra,number_domain=1)#RAXR spectra pars