from __future__ import division from rstbx.diffraction.fastbragg import detector,standard_camera,crystal_structure from rstbx.simulation.constants import electron_radius from rstbx.simulation import xfel1 from rstbx.simulation.sim_pdf import PDF from rstbx.simulation.sim_utils import generate_random_rotation # Instantiation of the Detector, array size & pixel edge in meters Det = detector(slowpixels=1516,fastpixels=1516,pixel_size=0.00022) Det.show() Cam = standard_camera(detector = Det, mean_xtd_distance_m = 0.150, mean_xray_wavelength_m = 1.24E-10) Cam.show() Pdb = crystal_structure(pdb_code='2alp',standard_camera=Cam) Pdb.show() square_crystal_edge = 5.E-6 # in meters square_focus_edge = 5.E-6 # in meters vol_crystal = square_crystal_edge**3 # volume of the crystal in meters**3 I_beam = 2E12 #number of photons per LCLS pulse I_beam_flux = I_beam/(square_focus_edge**2) darwin_numerator = I_beam_flux * (electron_radius**2) * vol_crystal class Params:pass Sim = Params() Sim.mosaicity = 0.10 #degrees Sim.bandpass = 0.002 Sim.tracing_impacts = 1000
def tst_all(): F = foo() assert F == (1, 2, 3, 4) size = 1516 D = detector(slowpixels=1516, fastpixels=1516, pixel_size=0.00011) D.set_region_of_interest(0, int(0.6 * size), int(0.4 * size), int(0.6 * size)) D.set_oversampling(1) C = camera() C.distance = 0.18166 C.Ybeam = 0.08338 C.Zbeam = 0.08338 C.lambda0 = 6.2E-10 C.dispersion = 0.002 C.dispsteps = 4 C.hdivrange = 0 C.vdivrange = 0 C.hdivstep = 1 C.vdivstep = 1 C.source_distance = 10. C.fluence = 1.E24 Amat = sqr((127.6895065259495, 0.6512077339887, -0.4403031342553, -1.1449112128916, 225.3922539826207, 1.8393136632579, 1.0680694468752, -2.4923062985132, 306.0953037195841)) PSII = amplitudes_from_pdb(8., "fft", True) from cctbx import crystal_orientation X = crystal() X.orientation = crystal_orientation.crystal_orientation( Amat, crystal_orientation.basis_type.direct) X.miller = PSII.indices() X.amplitudes = PSII.data() X.Na = 6 X.Nb = 6 X.Nc = 6 SIM = fast_bragg_simulation() SIM.set_detector(D) SIM.set_camera(C) SIM.set_crystal(X) SIM.sweep_over_detector() data = D.raw scale_factor = 55000. / flex.max(data) #print "scale_factor",scale_factor fileout = "intimage_001.img" SIM.to_smv_format(fileout=fileout, intfile_scale=scale_factor, saturation=40000) import os assert os.path.isfile(fileout) os.remove(fileout) #simulation is complete, now we'll autoindex the image fragment and verify # that the indexed cell is similar to the input cell. if (not libtbx.env.has_module("annlib")): print "Skipping some tests: annlib not available." return # 1. Analysis of the image to identify the Bragg peak centers. # This step uses an inefficient algorithm and implementation and # is most time consuming; but the code is only for testing, not production from rstbx.diffraction.fastbragg.tst_utils_clustering import specific_libann_cluster M = specific_libann_cluster(scale_factor * data, intensity_cutoff=25, distance_cutoff=17) # M is a dictionary of peak intensities indexed by pixel coordinates # 2. Now autoindex the pattern from rstbx.diffraction.fastbragg.tst_utils_clustering import index_wrapper SIM.C = C SIM.D = D ai, ref_uc = index_wrapper(M.keys(), SIM, PSII) tst_uc = ai.getOrientation().unit_cell() #print ref_uc # (127.692, 225.403, 306.106, 90, 90, 90) #print tst_uc # (106.432, 223.983, 303.102, 90.3185, 91.5998, 90.5231) # 3. Final assertion. In the given orientation, # the unit cell A vector is into the beam and is not well sampled, # so tolerances have to be fairly relaxed, 5%. # Labelit does better with the target_cell restraint, but this improved # algorithm is not used here for the test assert ref_uc.is_similar_to(tst_uc, relative_length_tolerance=0.20, absolute_angle_tolerance=2.0)
from __future__ import absolute_import, division, print_function from rstbx.diffraction.fastbragg import detector, standard_camera, crystal_structure from rstbx.simulation.constants import electron_radius from rstbx.simulation import xfel1 from rstbx.simulation.sim_pdf import PDF from rstbx.simulation.sim_utils import generate_random_rotation # Instantiation of the Detector, array size & pixel edge in meters Det = detector(slowpixels=1516, fastpixels=1516, pixel_size=0.00022) Det.show() Cam = standard_camera(detector=Det, mean_xtd_distance_m=0.150, mean_xray_wavelength_m=1.24E-10) Cam.show() Pdb = crystal_structure(pdb_code='2alp', standard_camera=Cam) Pdb.show() square_crystal_edge = 5.E-6 # in meters square_focus_edge = 5.E-6 # in meters vol_crystal = square_crystal_edge**3 # volume of the crystal in meters**3 I_beam = 2E12 #number of photons per LCLS pulse I_beam_flux = I_beam / (square_focus_edge**2) darwin_numerator = I_beam_flux * (electron_radius**2) * vol_crystal class Params: pass
def tst_all(): F = foo() assert F == (1,2,3,4) size=1516 D = detector(slowpixels=1516,fastpixels=1516,pixel_size=0.00011) D.set_region_of_interest(0,int(0.6*size),int(0.4*size),int(0.6*size)) D.set_oversampling(1) C = camera() C.distance = 0.18166 C.Ybeam = 0.08338 C.Zbeam = 0.08338 C.lambda0 = 6.2E-10 C.dispersion = 0.002 C.dispsteps = 4 C.hdivrange = 0 C.vdivrange = 0 C.hdivstep = 1 C.vdivstep = 1 C.source_distance = 10. C.fluence = 1.E24 Amat = sqr((127.6895065259495, 0.6512077339887,-0.4403031342553, -1.1449112128916,225.3922539826207,1.8393136632579, 1.0680694468752,-2.4923062985132,306.0953037195841)) PSII = amplitudes_from_pdb(8.,"fft",True) from cctbx import crystal_orientation X = crystal() X.orientation = crystal_orientation.crystal_orientation( Amat,crystal_orientation.basis_type.direct) X.miller = PSII.indices() X.amplitudes = PSII.data() X.Na = 6; X.Nb = 6; X.Nc = 6 SIM = fast_bragg_simulation() SIM.set_detector(D) SIM.set_camera(C) SIM.set_crystal(X) SIM.sweep_over_detector() data = D.raw scale_factor = 55000./flex.max(data) #print "scale_factor",scale_factor fileout="intimage_001.img" SIM.to_smv_format(fileout=fileout, intfile_scale = scale_factor, saturation=40000) import os assert os.path.isfile(fileout) os.remove(fileout) #simulation is complete, now we'll autoindex the image fragment and verify # that the indexed cell is similar to the input cell. if (not libtbx.env.has_module("annlib")): print "Skipping some tests: annlib not available." return # 1. Analysis of the image to identify the Bragg peak centers. # This step uses an inefficient algorithm and implementation and # is most time consuming; but the code is only for testing, not production from rstbx.diffraction.fastbragg.tst_utils_clustering import specific_libann_cluster M=specific_libann_cluster(scale_factor*data,intensity_cutoff = 25,distance_cutoff=17) # M is a dictionary of peak intensities indexed by pixel coordinates # 2. Now autoindex the pattern from rstbx.diffraction.fastbragg.tst_utils_clustering import index_wrapper SIM.C = C SIM.D = D ai,ref_uc = index_wrapper(M.keys(), SIM, PSII) tst_uc = ai.getOrientation().unit_cell() #print ref_uc # (127.692, 225.403, 306.106, 90, 90, 90) #print tst_uc # (106.432, 223.983, 303.102, 90.3185, 91.5998, 90.5231) # 3. Final assertion. In the given orientation, # the unit cell A vector is into the beam and is not well sampled, # so tolerances have to be fairly relaxed, 5%. # Labelit does better with the target_cell restraint, but this improved # algorithm is not used here for the test assert ref_uc.is_similar_to(tst_uc, relative_length_tolerance=0.20, absolute_angle_tolerance= 2.0)