def get_structure_factor(cif_file, dfout=0, **sf_args): '''computes structure factor 3D - sf_args : see (structure_factor3D) returns : - (qx,qy,qz),Fhkl ''' crys = import_crys(cif_file) pattern = np.array([ np.hstack([a.coords_fractional, a.atomic_number]) for a in crys.atoms ]) lat_vec = np.array(crys.reciprocal_vectors) (h, k, l), Fhkl = structure_factor3D(pattern, lat_vec, **sf_args) qx = h / crys.lattice_parameters[0] qy = k / crys.lattice_parameters[1] qz = l / crys.lattice_parameters[2] if dfout: data = [ h.flatten(), k.flatten(), l.flatten(), qx.flatten(), qy.flatten(), qz.flatten(), Fhkl.flatten() ] d = dict(zip(['h', 'k', 'l', 'qx', 'qy', 'qz', 'Fhkl'], data)) return pd.DataFrame.from_dict(d) else: return (qx, qy, qz), Fhkl
def update_Nmax(self, Nmax): '''Update resolution/max order. (Updates lattice and Fhkl) Nmax : maximum h,k,l order ''' if isinstance(Nmax, int): if not Nmax == self.Nmax: self.Nmax = Nmax (h, k, l), (qx, qy, qz) = mut.get_lattice(self.lat_vec, self.Nmax) self.lattice = [(h, k, l), (qx, qy, qz)] self.hklF, self.Fhkl = sf.structure_factor3D( self.pattern, 2 * np.pi * self.lat_vec, hklMax=2 * self.Nmax)
def get_pattern(name, N=1, opt='', **kwargs): # crys = Crystal.from_database(name) # lat_vec = crys.reciprocal_vectors # pattern = np.array([list(a.coords_fractional)+[a.atomic_number] for a in crys.atoms]) pptype, ax, by, cz, angle = 'p1', 2, 2, 2, 90 pattern = np.array([[1, 1, 1, 1]]) lat_vec = 2 * np.pi * np.diag([1 / ax, 1 / by, 1 / cz]) hkl, Fhkl = sf.structure_factor3D(pattern, lat_vec, hklMax=2 * N, sym=1) if opt: sFact.plot_structure3D(hkl, Fhkl, opt=opt, **kwargs) a, b, c = lat_vec hkl = np.array( [i[N:3 * N + 1, N:3 * N + 1, N:3 * N + 1].flatten() for i in hkl]) #hkl = hkl[0].flatten(),hkl[1].flatten(),hkl[2].flatten()]) h, k, l = hkl kx = a[0] * h + b[0] * k + c[0] * l ky = a[1] * h + b[1] * k + c[1] * l kz = a[2] * h + b[2] * k + c[2] * l Gs = np.array([kx, ky, kz]).T / (2 * np.pi) Vg = Fhkl #.flatten() return hkl.T, Gs, Vg / (ax * by * cz)
if 'B' in opts: df = pd.read_pickle(path+'df0.pkl') p1 = pp.load_multi_obj(path+'biotin_m0_autoslic.pkl') p1.datpath = p1.datpath.replace('ronan','tarik') p1.get_beams(bOpt='na') #plot iBs = ['(64,0)','(0,32)','(0,64)','(32,32)','(64,64)'] fig,ax = p1.beam_vs_thickness(iBs=iBs,cm='jet', fonts=fs,opt='ps',name=figpath+'biotin_m0_beams.png') if 'F' in opts: # structure factor lat_vec = crys.reciprocal_vectors pattern = np.array([ np.hstack([a.coords_cartesian,a.atomic_number]) for a in crys.atoms]) hkl,F3d = structure_factor3D(pattern,lat_vec,hkl=None,hklMax=3,sym=0) #excitation error K = 1/cst.keV2lam(200) k = [2/a1,2/a2, b12, 2*b12] ti = np.arcsin(k/K) xi = K*(1-np.cos(ti)) z = np.linspace(0,2000,2000) Fibs = F3d[[2,0,0,1,2],[0,1,2,1,2],0] Fi = [Fibs[i]*np.sin(np.pi*z*zeta_i)/(np.pi*zeta_i) for i,zeta_i in enumerate(xi)] Ii = np.abs(Fi)**2 #plot kinematic cs = dsp.getCs('jet',len(iBs)) plts = [[z,I/1e8,[cs[i],'--'],''] for i,I in enumerate(Ii)] dsp.pltPlots(ax,plts,2) fig.show()
import importlib as imp from utils import * from crystals import Crystal from scattering import structure_factor as sf imp.reload(sf) crys = Crystal.from_database('Si') pattern = np.array([ np.hstack([a.coords_fractional, 0 * a.atomic_number]) for a in crys.atoms ]) lat_vec = np.array(crys.reciprocal_vectors) hkl, Fhkl = sf.structure_factor3D(pattern, lat_vec, hkl=None, hklMax=2, sym=0, v='') h, k, l = hkl I = np.abs(Fhkl)**2 id0 = ~((h % 2 == 0) & (k % 2 == 0) & (l % 2 == 0)) & ~((h % 2 == 1) & (k % 2 == 1) & (l % 2 == 1)) print(np.abs(I[id0])) #should be 0 print(np.abs(I[~id0 & ((h + k + l) % 4 == 0)])) #should be 64 print(np.abs(I[~id0 & ((h + k + l) % 2 == 1)])) #should be 32 print(np.abs(I[~id0 & ((h + k + l) % 4 == 2)])) #should be 0