def build_beamline(nrays=raycing.nrays): fixedExit = 15. beamLine = raycing.BeamLine(azimuth=0, height=0) rs.GeometricSource( beamLine, 'GeometricSource', (0, 0, -fixedExit), nrays=nrays, dx=5., dy=0, dz=5., dxprime=0., dzprime=0., distE='flat', energies=eLimits, polarization='horizontal') p = 20000. si111 = rm.CrystalSi(hkl=(1, 1, 1), tK=-171+273.15) beamLine.dcm = roe.DCM( beamLine, 'DCM', (0, p - 2000, -fixedExit), surface=('Si111',), material=(si111,)) beamLine.dcm.bragg = math.asin(rm.ch / (2 * si111.d * E0)) beamLine.dcm.cryst2perpTransl = fixedExit/2./math.cos(beamLine.dcm.bragg) beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', (0, p - 1000, 0)) crystalDiamond = rm.CrystalDiamond( (1, 1, 1), 2.0592872, elements='C', geom='Laue reflected', t=0.05) beamLine.qwp = roe.LauePlate( beamLine, 'QWP', (0, p, 0), material=(crystalDiamond,)) theta0 = math.asin(rm.ch / (2 * crystalDiamond.d * (E0+1.2))) beamLine.qwp.pitch = theta0 + math.pi/2 q = 100. beamLine.fsm2 = rsc.Screen(beamLine, 'FSM2', (0, p + q, 0)) return beamLine
import xrt.backends.raycing.apertures as ra import xrt.backends.raycing.oes as roe import xrt.backends.raycing.run as rr import xrt.backends.raycing.materials as rm import xrt.backends.raycing.screens as rsc import xrt.plotter as xrtp import xrt.runner as xrtr showIn3D = False E0 = 9000. eLimits = E0, E0+2.5 prefix = '07_conv_LT_slit' crystalDiamond = rm.CrystalDiamond((1, 1, 1), 2.0592872, elements='C', geom='Laue transmitted', t=0.05) #crystalDiamond = rm.CrystalDiamond( # (3, 1, 1), 2.0592872*(3./11)**0.5, elements='C', # geom='Laue transmitted', t=0.05) theta0 = math.asin(rm.ch / (2 * crystalDiamond.d * (E0+1.2))) def build_beamline(nrays=raycing.nrays): fixedExit = 15. beamLine = raycing.BeamLine(azimuth=0, height=0) hDiv = 1.5e-3 vDiv = 2.5e-4 rs.GeometricSource( beamLine, 'GeometricSource', (0, 0, 0), nrays=nrays, dx=0.1, dy=0, dz=2., dxprime=hDiv/2, dzprime=0,
import xrt.backends.raycing.screens as rsc import xrt.plotter as xrtp import xrt.runner as xrtr showIn3D = False crystalMaterial = 'Si' if crystalMaterial == 'Si': d111 = 3.1354161 # Si elif crystalMaterial == 'Ge': d111 = 3.2662725 # Ge else: raise orders = (1, 4, 8, 12) crystals = [rm.CrystalDiamond((i, i, i), d111 / i) for i in orders] crystalsMask = (0, 1, 0, 0) # 0=don't execute; 1=execute #numiters = [24, 360, 1280, 5120] # @crysals numiters = [24, 24, 48, 120] # @crysals R = 500. # mm isDiced = True isJohansson = True if isJohansson: Rm = R else: Rm = 2. * R beamV = 0.07 / 2.35, beamH = 0.2 / 2.35
name=r"alphaQuartz", hkl=[1, 0, 2], a=4.91304, c=5.40463, gamma=120, atoms=[14, 14, 14, 8, 8, 8, 8, 8, 8], atomsXYZ=[[0.4697, 0.0, 0.0], [-0.4697, -0.4697, 0.3333333333333333], [0.0, 0.4697, 0.6666666666666666], [0.4125, 0.2662, 0.1188], [-0.1463, -0.4125, 0.4521], [-0.2662, 0.1463, -0.2145], [0.1463, -0.2662, -0.1188], [-0.4125, -0.1463, 0.2145], [0.2662, 0.4125, 0.5479]], tK=300.0, table=r"Chantler") C111_300K = rmats.CrystalDiamond(d=2.0595, elements=r"C", rho=3.51, name=r"Diamond") C333_300K = rmats.CrystalDiamond(d=2.0595 / 3, elements=r"C", rho=3.51, name=r"Diamond") Si844_125K = rmats.CrystalSi(tK=125.0, hkl=[8, 4, 4], name=None) Si753_125K = rmats.CrystalSi(tK=125.0, hkl=[7, 5, 3], name=None) Si220_300K = rmats.CrystalSi(tK=300, hkl=[2, 2, 0], name=None) Si220_125K = rmats.CrystalSi(tK=125, hkl=[2, 2, 0], name=None)
import xrt.backends.raycing.screens as rsc import xrt.plotter as xrtp import xrt.runner as xrtr showIn3D = False crystalMaterial = 'Si' if crystalMaterial == 'Si': d111 = 3.1354161 elif crystalMaterial == 'Ge': d111 = 3.2662725 else: raise crystal = rm.CrystalDiamond((4, 4, 4), d111 / 4, elements=crystalMaterial) #numiter = 16000 numiter = 60 Rm = 1e9 # meridional radius, mm #Rs = 1000 # tmp sagittal radius, mm Rs = 250 # tmp sagittal radius, mm dphi = 0 beamV = 0.1 / 2.35 # vertical beam size beamH = 0.1 / 2.35 # horizontal beam size yAxesLim = 20 dxCrystal = 100. dyCrystal = 100.
import xrt.plotter as xrtp import xrt.runner as xrtr showIn3D = False crystalMaterial = 'Si' if crystalMaterial == 'Si': d111 = 3.1354161 # Si elif crystalMaterial == 'Ge': d111 = 3.2662725 # Ge else: raise orders = (1, 4, 8, 12) crystals = [ rm.CrystalDiamond((i, i, i), d111 / i, geom='Laue', elements=crystalMaterial) for i in orders ] crystalsMask = (1, 0, 0, 0) #numiters = [40, 360, 1280, 5120] # @crysals numiters = [40, 40, 80, 120] # @crysals R = 500. # mm isGroundBent = True if isGroundBent: Rm = R else: Rm = 2. * R beamV = 0.07 / 2.35, beamH = 0.2 / 2.35
import xrt.plotter as xrtp import xrt.runner as xrtr showIn3D = False crystalMaterial = 'Si' if crystalMaterial == 'Si': d111 = 3.1354161 # Si elif crystalMaterial == 'Ge': d111 = 3.2662725 # Ge else: raise orders = (1, 4, 8, 12) crystals = [ rm.CrystalDiamond((i, i, i), d111 / i, elements=crystalMaterial) for i in orders ] crystalsMask = (0, 1, 0, 0) #numiters = [40, 2560, 1280, 5120] # @crysals numiters = [40, 40, 80, 120] # @crysals R = 500. # mm isJohansson = True if isJohansson: Rm = R else: Rm = 2. * R beamV = 0.1 / 2.35,
def compare_Bragg_Laue(hkl, beamPath, factDW=1.): """A comparison subroutine used in the module test suit.""" def for_one_alpha(alphaDeg, hkl): alpha = math.radians(alphaDeg) s0 = (np.zeros_like(theta), np.cos(theta+alpha), -np.sin(theta+alpha)) sh = (np.zeros_like(theta), np.cos(theta-alpha), np.sin(theta-alpha)) #'Bragg': n = (0, 0, 1) # outward surface normal hn = (0, math.sin(alpha), math.cos(alpha)) # outward Bragg normal gamma0 = sum(i*j for i, j in zip(n, s0)) gammah = sum(i*j for i, j in zip(n, sh)) hns0 = sum(i*j for i, j in zip(hn, s0)) braggS, braggP = siBraggCrystal.get_amplitude(E, gamma0, gammah, hns0) #'Laue': n = (0, -1, 0) # outward surface normal hn = (0, math.sin(alpha), math.cos(alpha)) # outward Bragg normal gamma0 = sum(i*j for i, j in zip(n, s0)) gammah = sum(i*j for i, j in zip(n, sh)) hns0 = sum(i*j for i, j in zip(hn, s0)) laueS, laueP = siLaueCrystal.get_amplitude(E, gamma0, gammah, hns0) fig = plt.figure(figsize=(8, 6), dpi=100) ax = fig.add_subplot(111) # phases: ax2 = ax.twinx() ax2.set_ylabel(r'$\phi_s - \phi_p$', color='c') phi = np.unwrap(np.angle(braggS * braggP.conj())) p5, = ax2.plot((theta-thetaCenter) * convFactor, phi, '-c', lw=1, yunits=math.pi, zorder=0) phi = np.unwrap(np.angle(laueS * laueP.conj())) p6, = ax2.plot((theta-thetaCenter) * convFactor, phi, '-c.', lw=1, yunits=math.pi, zorder=0) formatter = mpl.ticker.FormatStrFormatter('%g' + r'$ \pi$') ax2.yaxis.set_major_formatter(formatter) for tl in ax2.get_yticklabels(): tl.set_color('c') fig.suptitle(r'Comparison of Bragg and Laue transmittivity for Si{0}'. format(hkl), fontsize=16) p1, = ax.plot((theta-thetaCenter) * convFactor, abs(braggS)**2, '-r') p2, = ax.plot((theta-thetaCenter) * convFactor, abs(braggP)**2, '-b') p3, = ax.plot((theta-thetaCenter) * convFactor, abs(laueS)**2, '-r.') p4, = ax.plot((theta-thetaCenter) * convFactor, abs(laueP)**2, '-b.') ax.set_xlabel(r'$\theta-\theta_B$ (arcsec)') ax.set_ylabel('transmittivity') #upper right 1 #upper left 2 #lower left 3 #lower right 4 #right 5 #center left 6 #center right 7 #lower center 8 #upper center 9 #center 10 l1 = ax.legend([p1, p2], ['s', 'p'], loc=3) ax.legend([p1, p3], [u'Bragg t={0:.1f} µm'.format( siBraggCrystal.t * 1e3), u'Laue t={0:.1f} µm'.format( siLaueCrystal.t * 1e3)], loc=2) ax.add_artist(l1) ax.set_xlim([dtheta[0] * convFactor, dtheta[-1] * convFactor]) fname = r'BraggLaueTrSi{0}'.format(hkl) fig.savefig(fname + '.png') E0 = 10000. convFactor = 180 / math.pi * 3600. # arcsec if hkl == '111': # Si111 dtheta = np.linspace(-100, 100, 400) * 1e-6 dSpacing = 3.13562 hklInd = 1, 1, 1 elif hkl == '333': # Si333 dtheta = np.linspace(-30, 30, 400) * 1e-6 dSpacing = 3.13562 / 3 hklInd = 3, 3, 3 thetaCenter = math.asin(rm.ch / (2*dSpacing*E0)) t = beamPath * math.sin(thetaCenter) siBraggCrystal = rm.CrystalDiamond(hklInd, dSpacing, t=t, geom='Bragg transmitted', factDW=factDW) t = beamPath * math.cos(thetaCenter) siLaueCrystal = rm.CrystalDiamond(hklInd, dSpacing, t=t, geom='Laue transmitted', factDW=factDW) E = np.ones_like(dtheta) * E0 theta = dtheta + thetaCenter for_one_alpha(0., hkl)
def compare_rocking_curves_bent(hkl, t=None, geom='Laue reflected', factDW=1., legendPos1=4, legendPos2=1, Rcurvmm=None, alphas=[0]): try: import pyopencl as cl os.environ['PYOPENCL_COMPILER_OUTPUT'] = '1' isOpenCL = True except ImportError: isOpenCL = False if isOpenCL: import xrt.backends.raycing.myopencl as mcl matCL = mcl.XRT_CL(r'materials.cl', # targetOpenCL='CPU' ) else: matCL = None """A comparison subroutine used in the module test suit.""" def for_one_alpha(crystal, alphaDeg, hkl): xcb_tt = True xcb_pp = False Rcurv=np.inf if Rcurvmm is None else Rcurvmm if Rcurv==0: Rcurv=np.inf alpha = np.radians(alphaDeg) s0 = (np.zeros_like(theta), np.cos(theta+alpha), -np.sin(theta+alpha)) sh = (np.zeros_like(theta), np.cos(theta-alpha), np.sin(theta-alpha)) if geom.startswith('Bragg'): n = (0, 0, 1) # outward surface normal else: n = (0, -1, 0) # outward surface normal hn = (0, np.sin(alpha), np.cos(alpha)) # outward Bragg normal gamma0 = sum(i*j for i, j in zip(n, s0)) gammah = sum(i*j for i, j in zip(n, sh)) hns0 = sum(i*j for i, j in zip(hn, s0)) fig = plt.figure(figsize=(8, 6), dpi=100) fig.subplots_adjust(right=0.88) ax = fig.add_subplot(111) curS, curP = crystal.get_amplitude(E, gamma0, gammah, hns0) curSD, curPD = crystal.get_amplitude_TT(E, gamma0, gammah, hns0, ucl=matCL, alphaAsym=alpha, Rcurvmm=Rcurv) # phases: # ax2 = ax.twinx() # ax2.set_ylabel(r'$\phi_s - \phi_p$', color='c') # phi = np.unwrap(np.angle(curS * curP.conj())) # phiD = np.unwrap(np.angle(curSD * curPD.conj())) # p9, = ax2.plot((theta-thetaCenter) * convFactor, phi, 'c', lw=1, # yunits=math.pi, zorder=0) # p10, = ax2.plot((theta-thetaCenter) * convFactor, -phiD, 'm', lw=1, # yunits=math.pi, zorder=0) # formatter = mpl.ticker.FormatStrFormatter('%g' + r'$ \pi$') # ax2.yaxis.set_major_formatter(formatter) # for tl in ax2.get_yticklabels(): # tl.set_color('c') if t is not None: tt = u', t={0:.0f}µm'.format(t * 1e3) tname = '{0:03d}mkm'.format(int(t * 1e3)) else: tt = ' thick' tname = 'thick' if geom.startswith('Bragg'): geomPrefix = 'b' else: geomPrefix = 'l' if geom.endswith('transmitted'): geomPrefix += 't' if np.isinf(Rcurv): fig.suptitle(r'{0} Si{1}, $\alpha={2:.1f}^\circ$, bending R=$\infty$, E={3:.0f}keV'.format(geom, # analysis:ignore hkl, alphaDeg, E0/1e3), fontsize=16) else: fig.suptitle(r'{0} Si{1}, $\alpha={2:.1f}^\circ$, bending R={3:.1f}m, E={4:.0f}keV'.format(geom, # analysis:ignore hkl, alphaDeg, Rcurv/1e3, E0/1e3), fontsize=16) path = os.path.join('', 'XOP-RockingCurves-Bent') + os.sep if np.isinf(Rcurv) or alphaDeg == 0: x, R2p, R2s = np.loadtxt( "{0}{1}Si{2}_E{3:-.0f}keV_t{4}_R{5:-.0f}m_a{6:-.0f}deg.xc.gz".format( # analysis:ignore path, geomPrefix, hkl, E0/1e3, tname, Rcurv/1e3, alphaDeg), unpack=True, usecols=(0, 2, 3)) p1, = ax.plot(x, R2s, '-k', label='s XCrystal', linewidth=2) # p2, = ax.plot(x, R2p, '--k', label='p XCrystal') if xcb_tt: x, R2s = np.loadtxt( "{0}{1}Si{2}_E{3:-.0f}keV_t{4}_R{5:-.0f}m_a{6:-.0f}deg_tt_sigma.xcb.gz".format( # analysis:ignore path, geomPrefix, hkl, E0/1e3, tname, Rcurv/1e3, alphaDeg), unpack=True, usecols=(0, 3)) p3t, = ax.plot(x*1e3, R2s, '-b', label='s XCrystal_Bent TT') x, R2p = np.loadtxt( "{0}{1}Si{2}_E{3:-.0f}keV_t{4}_R{5:-.0f}m_a{6:-.0f}deg_tt_pi.xcb.gz".format( # analysis:ignore path, geomPrefix, hkl, E0/1e3, tname, Rcurv/1e3, alphaDeg), unpack=True, usecols=(0, 3)) # p4, = ax.plot(x*1e3, R2p, '--b', label='p XCrystal_Bent TT') if xcb_pp: x, R2s = np.loadtxt( "{0}{1}Si{2}_E{3:-.0f}keV_t{4}_R{5:-.0f}m_a{6:-.0f}deg_pp_sigma.xcb.gz".format( # analysis:ignore path, geomPrefix, hkl, E0/1e3, tname, Rcurv/1e3, alphaDeg), unpack=True, usecols=(0, 7)) p3p, = ax.plot(x*1e3, R2s, '-c', label='s XCrystal_Bent PP') x, R2p = np.loadtxt( "{0}{1}Si{2}_E{3:-.0f}keV_t{4}_R{5:-.0f}m_a{6:-.0f}deg_pp_pi.xcb.gz".format( # analysis:ignore path, geomPrefix, hkl, E0/1e3, tname, Rcurv/1e3, alphaDeg), unpack=True, usecols=(0, 7)) # p4, = ax.plot(x*1e3, R2p, '--b', label='p XCrystal_Bent TT') # if np.isinf(Rcurv) or alphaDeg == 0: p7, = ax.plot((theta - thetaCenter) * convFactor, abs(curS)**2, '-r', linewidth=2) # p8, = ax.plot((theta - thetaCenter) * convFactor, # abs(curP)**2, '-c', linewidth=2) p11, = ax.plot((theta - thetaCenter) * convFactor, abs(curSD)**2, '--g', linewidth=2) # p12, = ax.plot((theta - thetaCenter) * convFactor, # abs(curPD)**2, '--r') ax.set_xlabel(r'$\theta-\theta_B$ ($\mu$rad)') if geom.endswith('transmitted'): ax.set_ylabel('transmittivity') else: ax.set_ylabel('reflectivity') ax.set_xlim([dtheta[0] * convFactor, dtheta[-1] * convFactor]) plotList = [p7, p11] curveList = ['xrt perfect', 'xrt TT'] if np.isinf(Rcurv) or alphaDeg == 0: plotList.append(p1) curveList.append('XCrystal') if xcb_tt: plotList.append(p3t) curveList.append('XCrystal_Bent TT') if xcb_pp: plotList.append(p3p) curveList.append('XCrystal_Bent PP') legendPostmp = legendPos2 if alphaDeg > 0 else legendPos2+1 ax.legend(plotList, curveList, loc=legendPostmp) # ax2.add_artist(l1) fname = '{0}Si{1}_{2}_a{3:-.0f}_{4:-.2f}'.format( geomPrefix, hkl, tname, alphaDeg, Rcurv/1e3) fig.savefig(fname + '.png') E0 = 50000. # convFactor = 180 / np.pi * 3600. # arcsec convFactor = 1e6 for alpha in alphas: if hkl == '111': # Si111 if geom.startswith('Bragg'): dtheta = np.linspace(0, 100, 400) * 1e-6 else: dtheta = np.linspace(-5-np.abs(alpha)*2*50e3/Rcurvmm, 5+np.abs(alpha)*2*50e3/Rcurvmm, 1000) * 1e-6 dSpacing = 3.13562 hklInd = 1, 1, 1 elif hkl == '333': # Si333 if geom.startswith('Bragg'): dtheta = np.linspace(-25, 75, 400) * 1e-6 else: dtheta = np.linspace(-2-np.abs(alpha)**1.2*50e3/Rcurvmm, 2+np.abs(alpha)**1.2*50e3/Rcurvmm, 1000) * 1e-6 dSpacing = 3.13562 / 3. hklInd = 3, 3, 3 siCrystal = rm.CrystalDiamond(hklInd, dSpacing, t=t, geom=geom, factDW=factDW) thetaCenter = math.asin(rm.ch / (2*siCrystal.d*E0)) E = np.ones_like(dtheta) * E0 theta = dtheta + thetaCenter for_one_alpha(siCrystal, alpha, hkl)
def compare_rocking_curves(hkl, t=None, geom='Bragg reflected', factDW=1., legendPos1=4, legendPos2=1): """A comparison subroutine used in the module test suit.""" def for_one_alpha(crystal, alphaDeg, hkl): alpha = math.radians(alphaDeg) s0 = (np.zeros_like(theta), np.cos(theta+alpha), -np.sin(theta+alpha)) sh = (np.zeros_like(theta), np.cos(theta-alpha), np.sin(theta-alpha)) if geom.startswith('Bragg'): n = (0, 0, 1) # outward surface normal else: n = (0, -1, 0) # outward surface normal hn = (0, math.sin(alpha), math.cos(alpha)) # outward Bragg normal gamma0 = sum(i*j for i, j in zip(n, s0)) gammah = sum(i*j for i, j in zip(n, sh)) hns0 = sum(i*j for i, j in zip(hn, s0)) fig = plt.figure(figsize=(8, 6), dpi=100) fig.subplots_adjust(right=0.88) ax = fig.add_subplot(111) # curS, curP = crystal.get_amplitude_Authie(E, gamma0, gammah, hns0) # p5, = ax.plot((theta - thetaCenter) * convFactor, abs(curS)**2, '-g') # p6, = ax.plot((theta - thetaCenter) * convFactor, abs(curP)**2, '--g') curS, curP = crystal.get_amplitude(E, gamma0, gammah, hns0) # phases: ax2 = ax.twinx() ax2.set_ylabel(r'$\phi_s - \phi_p$', color='c') phi = np.unwrap(np.angle(curS * curP.conj())) p9, = ax2.plot((theta-thetaCenter) * convFactor, phi, 'c', lw=1, yunits=math.pi, zorder=0) formatter = mpl.ticker.FormatStrFormatter('%g' + r'$ \pi$') ax2.yaxis.set_major_formatter(formatter) for tl in ax2.get_yticklabels(): tl.set_color('c') if t is not None: tt = u', t={0:.0f}µm'.format(t * 1e3) tname = '{0:03d}mum'.format(int(t * 1e3)) else: tt = ' thick' tname = 'thick' if geom.startswith('Bragg'): geomPrefix = 'b' else: geomPrefix = 'l' if geom.endswith('transmitted'): geomPrefix += 't' fig.suptitle(r'{0} Si{1}, $\alpha={2:.1f}^\circ${3}'.format(geom, hkl, alphaDeg, tt), fontsize=16) path = os.path.join('', 'XOP-RockingCurves') + os.sep x, R2s = np.loadtxt("{0}{1}Si{2}_{3}_{4:-.0f}_s.xc.gz".format(path, geomPrefix, hkl, tname, alphaDeg), unpack=True) p1, = ax.plot(x, R2s, '-k', label='s XCrystal') x, R2p = np.loadtxt("{0}{1}Si{2}_{3}_{4:-.0f}_p.xc.gz".format(path, geomPrefix, hkl, tname, alphaDeg), unpack=True) p2, = ax.plot(x, R2p, '--k', label='p XCrystal') x, R2s = np.loadtxt("{0}{1}Si{2}_{3}_{4:-.0f}_s.xin.gz".format(path, geomPrefix, hkl, tname, alphaDeg), unpack=True) p3, = ax.plot(x, R2s, '-b', label='s XInpro') x, R2p = np.loadtxt("{0}{1}Si{2}_{3}_{4:-.0f}_p.xin.gz".format(path, geomPrefix, hkl, tname, alphaDeg), unpack=True) p4, = ax.plot(x, R2p, '--b', label='p XInpro') p7, = ax.plot((theta - thetaCenter) * convFactor, abs(curS)**2, '-r') p8, = ax.plot((theta - thetaCenter) * convFactor, abs(curP)**2, '--r') ax.set_xlabel(r'$\theta-\theta_B$ (arcsec)') if geom.endswith('transmitted'): ax.set_ylabel('transmittivity') else: ax.set_ylabel('reflectivity') ax.set_xlim([dtheta[0] * convFactor, dtheta[-1] * convFactor]) #upper right 1 #upper left 2 #lower left 3 #lower right 4 #right 5 #center left 6 #center right 7 #lower center 8 #upper center 9 #center 10 l1 = ax2.legend([p1, p2], ['s', 'p'], loc=legendPos1) # ax.legend([p1, p3, p5, p7], ['XCrystal/XOP', 'XInpro/XOP', # 'pxrt-Authier', 'pxrt-Bel&Dm'], loc=1) ax2.legend([p1, p3, p7], ['XCrystal/XOP', 'XInpro/XOP', 'xrt'], loc=legendPos2) ax2.add_artist(l1) fname = '{0}Si{1}_{2}_{3:-.0f}'.format( geomPrefix, hkl, tname, alphaDeg) fig.savefig(fname + '.png') E0 = 10000. convFactor = 180 / math.pi * 3600. # arcsec if hkl == '111': # Si111 if geom.startswith('Bragg'): dtheta = np.linspace(0, 100, 400) * 1e-6 else: dtheta = np.linspace(-50, 50, 400) * 1e-6 dSpacing = 3.13562 hklInd = 1, 1, 1 elif hkl == '333': # Si333 if geom.startswith('Bragg'): dtheta = np.linspace(0, 30, 400) * 1e-6 else: dtheta = np.linspace(-15, 15, 400) * 1e-6 dSpacing = 3.13562 / 3 hklInd = 3, 3, 3 siCrystal = rm.CrystalDiamond(hklInd, dSpacing, t=t, geom=geom, factDW=factDW) thetaCenter = math.asin(rm.ch / (2*siCrystal.d*E0)) E = np.ones_like(dtheta) * E0 theta = dtheta + thetaCenter for_one_alpha(siCrystal, 0., hkl) for_one_alpha(siCrystal, -5., hkl) for_one_alpha(siCrystal, 5., hkl)
def run_tests(): """The body of the module test suit. Uncomment the tests you want.""" #Compare the calculated rocking curves of Si crystals with those calculated by #XCrystal and XInpro (parts of XOP): compare_rocking_curves('111') # compare_rocking_curves('333') # compare_rocking_curves('111', t=0.007) # t is thickness in mm # compare_rocking_curves('333', t=0.007) # compare_rocking_curves('111', t=0.100) # compare_rocking_curves('333', t=0.100) compare_rocking_curves('111', t=0.007, geom='Bragg transmitted') # compare_rocking_curves('333', t=0.007, geom='Bragg transmitted') # compare_rocking_curves('111', t=0.100, geom='Bragg transmitted') # compare_rocking_curves('333', t=0.100, geom='Bragg transmitted') # compare_rocking_curves('111', t=0.007, geom='Laue reflected') # compare_rocking_curves('333', t=0.007, geom='Laue reflected') # compare_rocking_curves('111', t=0.100, geom='Laue reflected') # compare_rocking_curves('333', t=0.100, geom='Laue reflected') # compare_rocking_curves('111', t=0.007, geom='Laue transmitted') # compare_rocking_curves('333', t=0.007, geom='Laue transmitted') # compare_rocking_curves('111', t=0.100, geom='Laue transmitted') # compare_rocking_curves('333', t=0.100, geom='Laue transmitted') # Compare rocking curves for bent Si crystals with those calculated by #XCrystal_Bent (Takagi-Taupin): compare_rocking_curves_bent('111', t=1.0, geom='Laue reflected', Rcurvmm=np.inf, alphas=[30]) # compare_rocking_curves_bent('333', t=1.0, geom='Laue reflected', # Rcurvmm=np.inf, alphas=[30]) # compare_rocking_curves_bent('111', t=1.0, geom='Laue reflected', # Rcurvmm=50*1e3, # alphas=[-60, -45, -30, -15, 0, 15, 30, 45, 60]) # compare_rocking_curves_bent('333', t=1.0, geom='Laue reflected', # Rcurvmm=50*1e3, # alphas=[-60, -45, -30, -15, 0, 15, 30, 45, 60]) #check that Bragg transmitted and Laue transmitted give the same results if the #beam path is equal: beamPath = 0.1 # mm compare_Bragg_Laue('111', beamPath=beamPath) compare_Bragg_Laue('333', beamPath=beamPath) #Compare the calculated reflectivities of Si, Pt, SiO_2 with those by Xf1f2 #(part of XOP): compare_reflectivity() compare_reflectivity_coated() #Compare the calculated reflectivities of W slab with those by Mlayer #(part of XOP): compare_reflectivity_slab() #Compare the calculated reflectivities of W slab with those by Mlayer #(part of XOP): # compare_reflectivity_multilayer() compare_reflectivity_multilayer_interdiffusion() # compare_dTheta() #Compare the calculated absorption coefficient with that by XCrossSec #(part of XOP): compare_absorption_coeff() #Compare the calculated transmittivity with that by XPower #(part of XOP): compare_transmittivity() #Play with Si crystal: crystalSi = rm.CrystalSi(hkl=(1, 1, 1), tK=100.) print(2 * crystalSi.get_a()/math.sqrt(3.)) # 2dSi111 print('Si111 d-spacing = {0:.6f}'.format(crystalSi.d)) print(crystalSi.get_Bragg_offset(8600, 8979)) crystalDiamond = rm.CrystalDiamond((1, 1, 1), 2.0592872, elements='C') E = 9000. print(u'Darwin width at E={0:.0f} eV is {1:.5f} µrad for s-polarization'. format(E, crystalDiamond.get_Darwin_width(E) * 1e6)) print(u'Darwin width at E={0:.0f} eV is {1:.5f} µrad for p-polarization'. format(E, crystalDiamond.get_Darwin_width(E, polarization='p')*1e6)) plt.show() print("finished")
else: n = (0, -1, 0) # outward surface normal hn = (0, np.sin(alpha), np.cos(alpha)) # outward Bragg normal gamma0 = sum(i*j for i, j in zip(n, s0)) gammah = sum(i*j for i, j in zip(n, sh)) hns0 = sum(i*j for i, j in zip(hn, s0)) return gamma0, gammah, hns0 #crystalType = 'Si' crystalType = 'Ge' hkl = (1, 1, 1) if crystalType == 'Si': crystal = rm.CrystalSi(hkl=hkl) elif crystalType == 'Ge': crystal = rm.CrystalDiamond(hkl=hkl, d=5.657, elements='Ge') E = 8900 dtheta = np.linspace(-20, 80, 501) #dtheta = np.linspace(-100, 300, 501) theta = crystal.get_Bragg_angle(E) + dtheta*1e-6 asymmDeg = 0. # Degrees g0, gh, hs0 = calc_vectors(theta, asymmDeg, 'Bragg') curS, curP = crystal.get_amplitude(E, g0, gh, hs0) #curS, curP = crystal.get_amplitude(E, np.sin(theta)) #print(crystal.get_a()) print(crystal.get_F_chi(E, 0.5/crystal.d)) print(u'Darwin width at E={0:.0f} eV is {1:.5f} µrad for s-polarization'. format(E, crystal.get_Darwin_width(E) * 1e6))