def gen_fmodel_adapt(self): direct_algo_res_limit = 1.7 self.GF = gen_fmodel(resolution=direct_algo_res_limit,pdb_text=data( ).get("pdb_lines"),algorithm="fft",wavelength=7122) self.CB_OP_C_P = self.GF.xray_structure.change_of_basis_op_to_primitive_setting() # from C to P, for ersatz model self.GF.set_k_sol(0.435) self.GF.make_P1_primitive() self.sfall_main = self.GF.get_amplitudes()
def channel_pixels(ROI,wavelength_A,flux,N,UMAT_nm,Amatrix_rot,fmodel_generator,output): local_data = data() energy_dependent_fmodel=False if energy_dependent_fmodel: fmodel_generator.reset_wavelength(wavelength_A) fmodel_generator.reset_specific_at_wavelength( label_has="FE1",tables=local_data.get("Fe_oxidized_model"),newvalue=wavelength_A) fmodel_generator.reset_specific_at_wavelength( label_has="FE2",tables=local_data.get("Fe_reduced_model"),newvalue=wavelength_A) print("USING scatterer-specific energy-dependent scattering factors") sfall_channel = fmodel_generator.get_amplitudes() else: sfall_channel = sfall_P1_7122_amplitudes SIM = nanoBragg(detpixels_slowfast=(3000,3000),pixel_size_mm=0.11,Ncells_abc=(N,N,N), wavelength_A=wavelength_A,verbose=0) SIM.adc_offset_adu = 10 # Do not offset by 40 SIM.region_of_interest = ROI SIM.mosaic_spread_deg = 0.05 # interpreted by UMAT_nm as a half-width stddev SIM.mosaic_domains = 200 # 77 seconds. With 100 energy points, 7700 seconds (2 hours) per image SIM.distance_mm=141.7 SIM.set_mosaic_blocks(UMAT_nm) #SIM.detector_thick_mm = 0.5 # = 0 for Rayonix #SIM.detector_thicksteps = 1 # should default to 1 for Rayonix, but set to 5 for CSPAD #SIM.detector_attenuation_length_mm = default is silicon # get same noise each time this test is run SIM.seed = 1 SIM.oversample=1 SIM.wavelength_A = wavelength_A SIM.polarization=1 SIM.default_F=0 SIM.Fhkl=sfall_channel SIM.Amatrix_RUB = Amatrix_rot SIM.xtal_shape=shapetype.Gauss # both crystal & RLP are Gaussian SIM.progress_meter=False # flux is always in photons/s SIM.flux=flux SIM.exposure_s=1.0 # so total fluence is e12 # assumes round beam SIM.beamsize_mm=0.003 #cannot make this 3 microns; spots are too intense temp=SIM.Ncells_abc print("Ncells_abc=",SIM.Ncells_abc) SIM.Ncells_abc=temp from libtbx.development.timers import Profiler P = Profiler("nanoBragg") SIM.printout=True fast = ROI[1][0] + (ROI[1][1]-ROI[1][0])//2 slow = ROI[0][0] + (ROI[0][1]-ROI[0][0])//2 SIM.printout_pixel_fastslow=(slow,fast) from boost.python import streambuf # will deposit printout into output as side effect SIM.add_nanoBragg_spots_nks(streambuf(output)) del P print(("SIM count > 0",(SIM.raw_pixels>0).count(True))) return SIM
def __init__(self, mosaic_domains=25, mosaic_spread_deg=0.05): local_data = data() direct_algo_res_limit = 1.7 wavelength_A = 1.3 # Angstroms, dummy value GF = gen_fmodel(resolution=direct_algo_res_limit, pdb_text=local_data.get("pdb_lines"), algorithm="fft", wavelength=wavelength_A) GF.set_k_sol(0.435) GF.make_P1_primitive() self.sfall_main = GF.get_amplitudes() SIM = nanoBragg( detpixels_slowfast=(3000, 3000), pixel_size_mm=0.11, Ncells_abc=(10, 10, 10), # workaround for problem with wavelength array, specify it separately in constructor. wavelength_A=wavelength_A, verbose=0) SIM.mosaic_spread_deg = mosaic_spread_deg # interpreted by UMAT_nm as a half-width stddev SIM.mosaic_domains = mosaic_domains # mosaic_domains setter must come after mosaic_spread_deg setter UMAT_nm = flex.mat3_double() mersenne_twister = flex.mersenne_twister(seed=0) scitbx.random.set_random_seed(1234) rand_norm = scitbx.random.normal_distribution( mean=0, sigma=SIM.mosaic_spread_deg * math.pi / 180.) g = scitbx.random.variate(rand_norm) mosaic_rotation = g(SIM.mosaic_domains) for m in mosaic_rotation: site = col(mersenne_twister.random_double_point_on_sphere()) UMAT_nm.append( site.axis_and_angle_as_r3_rotation_matrix(m, deg=False)) SIM.set_mosaic_blocks(UMAT_nm) self.SIM = SIM
def run_sim2smv(prefix, crystal, spectra, rotation, rank, quick=False): local_data = data() smv_fileout = prefix + ".img" if quick is not True: if not write_safe(smv_fileout): print("File %s already exists, skipping in rank %d" % (smv_fileout, rank)) return direct_algo_res_limit = 1.7 wavlen, flux, wavelength_A = next( spectra) # list of lambdas, list of fluxes, average wavelength if quick: wavlen = flex.double([wavelength_A]) flux = flex.double([flex.sum(flux)]) print("Quick sim, lambda=%f, flux=%f" % (wavelength_A, flux[0])) GF = gen_fmodel(resolution=direct_algo_res_limit, pdb_text=local_data.get("pdb_lines"), algorithm="fft", wavelength=wavelength_A) GF.set_k_sol(0.435) GF.make_P1_primitive() sfall_main = GF.get_amplitudes() # use crystal structure to initialize Fhkl array sfall_main.show_summary(prefix="Amplitudes used ") N = crystal.number_of_cells(sfall_main.unit_cell()) #SIM = nanoBragg(detpixels_slowfast=(2000,2000),pixel_size_mm=0.11,Ncells_abc=(5,5,5),verbose=0) SIM = nanoBragg( detpixels_slowfast=(3000, 3000), pixel_size_mm=0.11, Ncells_abc=(N, N, N), # workaround for problem with wavelength array, specify it separately in constructor. wavelength_A=wavelength_A, verbose=0) SIM.adc_offset_adu = 0 # Do not offset by 40 SIM.adc_offset_adu = 10 # Do not offset by 40 import sys if len(sys.argv) > 2: SIM.seed = -int(sys.argv[2]) print("GOTHERE seed=", SIM.seed) if len(sys.argv) > 1: if sys.argv[1] == "random": SIM.randomize_orientation() SIM.mosaic_spread_deg = 0.05 # interpreted by UMAT_nm as a half-width stddev SIM.mosaic_domains = n_mosaic_domains # 77 seconds. With 100 energy points, 7700 seconds (2 hours) per image # 3000000 images would be 100000 hours on a 60-core machine (dials), or 11.4 years # using 2 nodes, 5.7 years. Do this at SLAC? NERSC? combination of all? # SLAC downtimes: Tues Dec 5 (24 hrs), Mon Dec 11 (72 hrs), Mon Dec 18 light use, 24 days # mosaic_domains setter must come after mosaic_spread_deg setter SIM.distance_mm = 141.7 UMAT_nm = flex.mat3_double() mersenne_twister = flex.mersenne_twister(seed=0) scitbx.random.set_random_seed(1234) rand_norm = scitbx.random.normal_distribution(mean=0, sigma=SIM.mosaic_spread_deg * math.pi / 180.) g = scitbx.random.variate(rand_norm) mosaic_rotation = g(SIM.mosaic_domains) for m in mosaic_rotation: site = col(mersenne_twister.random_double_point_on_sphere()) UMAT_nm.append(site.axis_and_angle_as_r3_rotation_matrix(m, deg=False)) SIM.set_mosaic_blocks(UMAT_nm) #SIM.detector_thick_mm = 0.5 # = 0 for Rayonix #SIM.detector_thicksteps = 1 # should default to 1 for Rayonix, but set to 5 for CSPAD #SIM.detector_attenuation_length_mm = default is silicon # get same noise each time this test is run SIM.seed = 1 SIM.oversample = 1 SIM.wavelength_A = wavelength_A SIM.polarization = 1 # this will become F000, marking the beam center SIM.default_F = 0 #SIM.missets_deg= (10,20,30) print("mosaic_seed=", SIM.mosaic_seed) print("seed=", SIM.seed) print("calib_seed=", SIM.calib_seed) print("missets_deg =", SIM.missets_deg) SIM.Fhkl = sfall_main print("Determinant", rotation.determinant()) Amatrix_rot = ( rotation * sqr(sfall_main.unit_cell().orthogonalization_matrix())).transpose() print("RAND_ORI", prefix, end=' ') for i in Amatrix_rot: print(i, end=' ') print() SIM.Amatrix_RUB = Amatrix_rot #workaround for failing init_cell, use custom written Amatrix setter print("unit_cell_Adeg=", SIM.unit_cell_Adeg) print("unit_cell_tuple=", SIM.unit_cell_tuple) Amat = sqr(SIM.Amatrix).transpose() # recovered Amatrix from SIM from cctbx import crystal_orientation Ori = crystal_orientation.crystal_orientation( Amat, crystal_orientation.basis_type.reciprocal) print("Python unit cell from SIM state", Ori.unit_cell()) # fastest option, least realistic #SIM.xtal_shape=shapetype.Tophat # RLP = hard sphere #SIM.xtal_shape=shapetype.Square # gives fringes SIM.xtal_shape = shapetype.Gauss # both crystal & RLP are Gaussian #SIM.xtal_shape=shapetype.Round # Crystal is a hard sphere # only really useful for long runs SIM.progress_meter = False # prints out value of one pixel only. will not render full image! #SIM.printout_pixel_fastslow=(500,500) #SIM.printout=True SIM.show_params() # flux is always in photons/s SIM.flux = 1e12 SIM.exposure_s = 1.0 # so total fluence is e12 # assumes round beam SIM.beamsize_mm = 0.003 #cannot make this 3 microns; spots are too intense temp = SIM.Ncells_abc print("Ncells_abc=", SIM.Ncells_abc) SIM.Ncells_abc = temp print("Ncells_abc=", SIM.Ncells_abc) print("xtal_size_mm=", SIM.xtal_size_mm) print("unit_cell_Adeg=", SIM.unit_cell_Adeg) print("unit_cell_tuple=", SIM.unit_cell_tuple) print("missets_deg=", SIM.missets_deg) print("Amatrix=", SIM.Amatrix) print("beam_center_mm=", SIM.beam_center_mm) print("XDS_ORGXY=", SIM.XDS_ORGXY) print("detector_pivot=", SIM.detector_pivot) print("xtal_shape=", SIM.xtal_shape) print("beamcenter_convention=", SIM.beamcenter_convention) print("fdet_vector=", SIM.fdet_vector) print("sdet_vector=", SIM.sdet_vector) print("odet_vector=", SIM.odet_vector) print("beam_vector=", SIM.beam_vector) print("polar_vector=", SIM.polar_vector) print("spindle_axis=", SIM.spindle_axis) print("twotheta_axis=", SIM.twotheta_axis) print("distance_meters=", SIM.distance_meters) print("distance_mm=", SIM.distance_mm) print("close_distance_mm=", SIM.close_distance_mm) print("detector_twotheta_deg=", SIM.detector_twotheta_deg) print("detsize_fastslow_mm=", SIM.detsize_fastslow_mm) print("detpixels_fastslow=", SIM.detpixels_fastslow) print("detector_rot_deg=", SIM.detector_rot_deg) print("curved_detector=", SIM.curved_detector) print("pixel_size_mm=", SIM.pixel_size_mm) print("point_pixel=", SIM.point_pixel) print("polarization=", SIM.polarization) print("nopolar=", SIM.nopolar) print("oversample=", SIM.oversample) print("region_of_interest=", SIM.region_of_interest) print("wavelength_A=", SIM.wavelength_A) print("energy_eV=", SIM.energy_eV) print("fluence=", SIM.fluence) print("flux=", SIM.flux) print("exposure_s=", SIM.exposure_s) print("beamsize_mm=", SIM.beamsize_mm) print("dispersion_pct=", SIM.dispersion_pct) print("dispsteps=", SIM.dispsteps) print("divergence_hv_mrad=", SIM.divergence_hv_mrad) print("divsteps_hv=", SIM.divsteps_hv) print("divstep_hv_mrad=", SIM.divstep_hv_mrad) print("round_div=", SIM.round_div) print("phi_deg=", SIM.phi_deg) print("osc_deg=", SIM.osc_deg) print("phisteps=", SIM.phisteps) print("phistep_deg=", SIM.phistep_deg) print("detector_thick_mm=", SIM.detector_thick_mm) print("detector_thicksteps=", SIM.detector_thicksteps) print("detector_thickstep_mm=", SIM.detector_thickstep_mm) print("***mosaic_spread_deg=", SIM.mosaic_spread_deg) print("***mosaic_domains=", SIM.mosaic_domains) print("indices=", SIM.indices) print("amplitudes=", SIM.amplitudes) print("Fhkl_tuple=", SIM.Fhkl_tuple) print("default_F=", SIM.default_F) print("interpolate=", SIM.interpolate) print("integral_form=", SIM.integral_form) from libtbx.development.timers import Profiler P = Profiler("nanoBragg") # now actually burn up some CPU #SIM.add_nanoBragg_spots() del P # simulated crystal is only 125 unit cells (25 nm wide) # amplify spot signal to simulate physical crystal of 4000x larger: 100 um (64e9 x the volume) print(crystal.domains_per_crystal) SIM.raw_pixels *= crystal.domains_per_crystal # must calculate the correct scale! # Use single wavelength for all energy channels for the purpose of Fcalc wavelength_hi_remote = wavlen[-1] GF.reset_wavelength(wavelength_hi_remote) GF.reset_specific_at_wavelength(label_has="FE1", tables=local_data.get("Fe_oxidized_model"), newvalue=wavelength_hi_remote) GF.reset_specific_at_wavelength(label_has="FE2", tables=local_data.get("Fe_reduced_model"), newvalue=wavelength_hi_remote) sfall_channel = GF.get_amplitudes() # sources channel_source_XYZ = flex.vec3_double(len(flux), SIM.xray_source_XYZ[0]) CP = channel_pixels( wavlen, flux, channel_source_XYZ) # class interface for multi-wavelength print("+++++++++++++++++++++++++++++++++++++++ Multiwavelength call") CH = CP(N=N, UMAT_nm=UMAT_nm, Amatrix_rot=Amatrix_rot, sfall_channel=sfall_channel) SIM.raw_pixels += CH.raw_pixels * crystal.domains_per_crystal CH.free_all() if quick: SIM.to_smv_format(fileout=prefix + "_intimage_001.img") # rough approximation to water: interpolation points for sin(theta/lambda) vs structure factor bg = flex.vec2_double([(0, 2.57), (0.0365, 2.58), (0.07, 2.8), (0.12, 5), (0.162, 8), (0.2, 6.75), (0.18, 7.32), (0.216, 6.75), (0.236, 6.5), (0.28, 4.5), (0.3, 4.3), (0.345, 4.36), (0.436, 3.77), (0.5, 3.17)]) SIM.Fbg_vs_stol = bg SIM.amorphous_sample_thick_mm = 0.1 SIM.amorphous_density_gcm3 = 1 SIM.amorphous_molecular_weight_Da = 18 SIM.flux = 1e12 SIM.beamsize_mm = 0.003 # square (not user specified) SIM.exposure_s = 1.0 # multiplies flux x exposure SIM.add_background() if quick: SIM.to_smv_format(fileout=prefix + "_intimage_002.img") # rough approximation to air bg = flex.vec2_double([(0, 14.1), (0.045, 13.5), (0.174, 8.35), (0.35, 4.78), (0.5, 4.22)]) SIM.Fbg_vs_stol = bg #SIM.amorphous_sample_thick_mm = 35 # between beamstop and collimator SIM.amorphous_sample_thick_mm = 10 # between beamstop and collimator SIM.amorphous_density_gcm3 = 1.2e-3 SIM.amorphous_sample_molecular_weight_Da = 28 # nitrogen = N2 print("amorphous_sample_size_mm=", SIM.amorphous_sample_size_mm) print("amorphous_sample_thick_mm=", SIM.amorphous_sample_thick_mm) print("amorphous_density_gcm3=", SIM.amorphous_density_gcm3) print("amorphous_molecular_weight_Da=", SIM.amorphous_molecular_weight_Da) SIM.add_background() #apply beamstop mask here # set this to 0 or -1 to trigger automatic radius. could be very slow with bright images # settings for CCD SIM.detector_psf_kernel_radius_pixels = 5 #SIM.detector_psf_fwhm_mm=0.08; #SIM.detector_psf_type=shapetype.Fiber # rayonix=Fiber, CSPAD=None (or small Gaussian) SIM.detector_psf_type = shapetype.Unknown # for CSPAD SIM.detector_psf_fwhm_mm = 0 #SIM.apply_psf() print("One pixel-->", SIM.raw_pixels[500000]) # at this point we scale the raw pixels so that the output array is on an scale from 0 to 50000. # that is the default behavior (intfile_scale<=0), otherwise it applies intfile_scale as a multiplier on an abs scale. if quick: SIM.to_smv_format(fileout=prefix + "_intimage_003.img") print("quantum_gain=", SIM.quantum_gain) #defaults to 1. converts photons to ADU print("adc_offset_adu=", SIM.adc_offset_adu) print("detector_calibration_noise_pct=", SIM.detector_calibration_noise_pct) print("flicker_noise_pct=", SIM.flicker_noise_pct) print("readout_noise_adu=", SIM.readout_noise_adu ) # gaussian random number to add to every pixel (0 for PAD) # apply Poissonion correction, then scale to ADU, then adc_offset. # should be 10 for most Rayonix, Pilatus should be 0, CSPAD should be 0. print("detector_psf_type=", SIM.detector_psf_type) print("detector_psf_fwhm_mm=", SIM.detector_psf_fwhm_mm) print("detector_psf_kernel_radius_pixels=", SIM.detector_psf_kernel_radius_pixels) SIM.add_noise() #converts phtons to ADU. print("raw_pixels=", SIM.raw_pixels) extra = "PREFIX=%s;\nRANK=%d;\n" % (prefix, rank) SIM.to_smv_format_py(fileout=smv_fileout, intfile_scale=1, rotmat=True, extra=extra, gz=True) # try to write as CBF if False: import dxtbx from dxtbx.format.FormatCBFMiniPilatus import FormatCBFMiniPilatus img = dxtbx.load(prefix + ".img") print(img) FormatCBFMiniPilatus.as_file(detector=img.get_detector(), beam=img.get_beam(), gonio=img.get_goniometer(), scan=img.get_scan(), data=img.get_raw_data(), path=prefix + ".cbf") SIM.free_all()
from LS49.work2_for_aca_lsq.abc_background import fit_roi_multichannel # implicit import # multichannel needed for unpickling # %%% boilerplate specialize to packaged big data %%% import os from LS49.sim import step5_pad from LS49.sim import step4_pad from LS49.spectra import generate_spectra ls49_big_data = os.environ[ "LS49_BIG_DATA"] # get absolute path from environment step5_pad.big_data = ls49_big_data step4_pad.big_data = ls49_big_data generate_spectra.big_data = ls49_big_data # %%%%%% from LS49.sim.step5_pad import data local_data = data() Fe_oxidized_model = local_data.get("Fe_oxidized_model") Fe_reduced_model = local_data.get("Fe_reduced_model") Fe_metallic_model = local_data.get("Fe_metallic_model") abc_dir = [ "/net/dials/raid1/sauter/abc_coverage_allrestr", #"/net/dials/raid1/sauter/paper1/abc_coverage_superpower_postrefine", "/net/dials/raid1/sauter/paper1/abc_coverage_dials_refine", "/net/dials/raid1/sauter/paper1/abc_coverage_coarse_ground_truth" ] def get_item(key, trial=0): with open("%s/abcX%06d.pickle" % (abc_dir[trial], key), "rb") as F: T = pickle.load(F)
if __name__ == "__main__": # %%% boilerplate specialize to packaged big data %%% from LS49.sim import step5_pad from LS49.sim import step4_pad from LS49.spectra import generate_spectra from LS49 import ls49_big_data step5_pad.big_data = ls49_big_data step4_pad.big_data = ls49_big_data generate_spectra.big_data = ls49_big_data # %%%%%% from LS49.sim.util_fmodel import gen_fmodel from LS49.sim.step5_pad import data pdb_lines = data().get("pdb_lines") Fe_oxidized_model = data().get("Fe_oxidized_model") Fe_reduced_model = data().get("Fe_reduced_model") W2 = 12398.425 / 7122. GF = gen_fmodel(resolution=1.7, pdb_text=pdb_lines, algorithm="fft", wavelength=W2) GF.set_k_sol(0.435) GF.params2.fmodel.b_sol = 46. GF.params2.structure_factors_accuracy.grid_resolution_factor = 1 / 5. GF.params2.mask.grid_step_factor = 10. GF.reset_wavelength(W2) GF.reset_specific_at_wavelength(label_has="FE1",
def run_sim2smv(ROI, prefix, crystal, spectra, rotation, rank, tophat_spectrum=True, quick=False): smv_fileout = prefix + ".img" direct_algo_res_limit = 1.7 wavlen, flux, wavelength_A = next( spectra) # list of lambdas, list of fluxes, average wavelength if tophat_spectrum: sum_flux = flex.sum(flux) #from IPython import embed; embed() ave_flux = sum_flux / 60. # 60 energy channels for ix in range(len(wavlen)): energy = 12398.425 / wavlen[ix] if energy >= 7090 and energy <= 7150: flux[ix] = ave_flux else: flux[ix] = 0. if quick: wavlen = flex.double([wavelength_A]) flux = flex.double([flex.sum(flux)]) print("Quick sim, lambda=%f, flux=%f" % (wavelength_A, flux[0])) #from matplotlib import pyplot as plt #plt.plot(flux,"r-") #plt.title(smv_fileout) #plt.show() GF = gen_fmodel(resolution=direct_algo_res_limit, pdb_text=data().get("pdb_lines"), algorithm="fft", wavelength=wavelength_A) CB_OP_C_P = GF.xray_structure.change_of_basis_op_to_primitive_setting( ) # from C to P, used for ersatz model GF.set_k_sol(0.435) GF.make_P1_primitive() sfall_main = GF.get_amplitudes() # use crystal structure to initialize Fhkl array sfall_main.show_summary(prefix="Amplitudes used ") N = crystal.number_of_cells(sfall_main.unit_cell()) #SIM = nanoBragg(detpixels_slowfast=(2000,2000),pixel_size_mm=0.11,Ncells_abc=(5,5,5),verbose=0) SIM = nanoBragg( detpixels_slowfast=(3000, 3000), pixel_size_mm=0.11, Ncells_abc=(N, N, N), # workaround for problem with wavelength array, specify it separately in constructor. wavelength_A=wavelength_A, verbose=0) SIM.adc_offset_adu = 0 # Do not offset by 40 SIM.adc_offset_adu = 10 # Do not offset by 40 #import sys #if len(sys.argv)>2: # SIM.seed = -int(sys.argv[2]) # print("GOTHERE seed=",SIM.seed) #if len(sys.argv)>1: # if sys.argv[1]=="random" : SIM.randomize_orientation() SIM.mosaic_spread_deg = 0.05 # interpreted by UMAT_nm as a half-width stddev SIM.mosaic_domains = 200 # 77 seconds. With 100 energy points, 7700 seconds (2 hours) per image # 3000000 images would be 100000 hours on a 60-core machine (dials), or 11.4 years # using 2 nodes, 5.7 years. Do this at SLAC? NERSC? combination of all? # SLAC downtimes: Tues Dec 5 (24 hrs), Mon Dec 11 (72 hrs), Mon Dec 18 light use, 24 days # mosaic_domains setter must come after mosaic_spread_deg setter SIM.distance_mm = 141.7 UMAT_nm = flex.mat3_double() mersenne_twister = flex.mersenne_twister(seed=0) scitbx.random.set_random_seed(1234) rand_norm = scitbx.random.normal_distribution(mean=0, sigma=SIM.mosaic_spread_deg * math.pi / 180.) g = scitbx.random.variate(rand_norm) mosaic_rotation = g(SIM.mosaic_domains) for m in mosaic_rotation: site = col(mersenne_twister.random_double_point_on_sphere()) UMAT_nm.append(site.axis_and_angle_as_r3_rotation_matrix(m, deg=False)) SIM.set_mosaic_blocks(UMAT_nm) #SIM.detector_thick_mm = 0.5 # = 0 for Rayonix #SIM.detector_thicksteps = 1 # should default to 1 for Rayonix, but set to 5 for CSPAD #SIM.detector_attenuation_length_mm = default is silicon # get same noise each time this test is run SIM.seed = 1 SIM.oversample = 1 SIM.wavelength_A = wavelength_A SIM.polarization = 1 # this will become F000, marking the beam center SIM.default_F = 0 #SIM.missets_deg= (10,20,30) print("mosaic_seed=", SIM.mosaic_seed) print("seed=", SIM.seed) print("calib_seed=", SIM.calib_seed) print("missets_deg =", SIM.missets_deg) SIM.Fhkl = sfall_main print("Determinant", rotation.determinant()) Amatrix_rot = ( rotation * sqr(sfall_main.unit_cell().orthogonalization_matrix())).transpose() print("RAND_ORI", prefix, end=' ') for i in Amatrix_rot: print(i, end=' ') print() ##### ersatz inserted code (3 lines) for modeling profiles from refined geometry ### key = int(prefix.split("_")[-1]) different_models = superpower_postrefine(key, CB_OP_C_P, old_Amat=Amatrix_rot) for key in different_models: print(key, sqr(different_models[key]).elems) new_Amat = sqr(different_models[model_mode]) Amatrix_rot = new_Amat # insert the chosen-model Amatrix print("&&& chosen", new_Amat.elems) SIM.Amatrix_RUB = Amatrix_rot #workaround for failing init_cell, use custom written Amatrix setter print("unit_cell_Adeg=", SIM.unit_cell_Adeg) print("unit_cell_tuple=", SIM.unit_cell_tuple) Amat = sqr(SIM.Amatrix).transpose() # recovered Amatrix from SIM Ori = crystal_orientation.crystal_orientation( Amat, crystal_orientation.basis_type.reciprocal) print("Python unit cell from SIM state", Ori.unit_cell()) # fastest option, least realistic #SIM.xtal_shape=shapetype.Tophat # RLP = hard sphere #SIM.xtal_shape=shapetype.Square # gives fringes SIM.xtal_shape = shapetype.Gauss # both crystal & RLP are Gaussian #SIM.xtal_shape=shapetype.Round # Crystal is a hard sphere # only really useful for long runs SIM.progress_meter = False # prints out value of one pixel only. will not render full image! #SIM.printout_pixel_fastslow=(500,500) #SIM.printout=True SIM.show_params() # flux is always in photons/s SIM.flux = 1e12 SIM.exposure_s = 1.0 # so total fluence is e12 # assumes round beam SIM.beamsize_mm = 0.003 #cannot make this 3 microns; spots are too intense temp = SIM.Ncells_abc print("Ncells_abc=", SIM.Ncells_abc) SIM.Ncells_abc = temp print("Ncells_abc=", SIM.Ncells_abc) print("xtal_size_mm=", SIM.xtal_size_mm) print("unit_cell_Adeg=", SIM.unit_cell_Adeg) print("unit_cell_tuple=", SIM.unit_cell_tuple) print("missets_deg=", SIM.missets_deg) print("Amatrix=", SIM.Amatrix) print("beam_center_mm=", SIM.beam_center_mm) print("XDS_ORGXY=", SIM.XDS_ORGXY) print("detector_pivot=", SIM.detector_pivot) print("xtal_shape=", SIM.xtal_shape) print("beamcenter_convention=", SIM.beamcenter_convention) print("fdet_vector=", SIM.fdet_vector) print("sdet_vector=", SIM.sdet_vector) print("odet_vector=", SIM.odet_vector) print("beam_vector=", SIM.beam_vector) print("polar_vector=", SIM.polar_vector) print("spindle_axis=", SIM.spindle_axis) print("twotheta_axis=", SIM.twotheta_axis) print("distance_meters=", SIM.distance_meters) print("distance_mm=", SIM.distance_mm) print("close_distance_mm=", SIM.close_distance_mm) print("detector_twotheta_deg=", SIM.detector_twotheta_deg) print("detsize_fastslow_mm=", SIM.detsize_fastslow_mm) print("detpixels_fastslow=", SIM.detpixels_fastslow) print("detector_rot_deg=", SIM.detector_rot_deg) print("curved_detector=", SIM.curved_detector) print("pixel_size_mm=", SIM.pixel_size_mm) print("point_pixel=", SIM.point_pixel) print("polarization=", SIM.polarization) print("nopolar=", SIM.nopolar) print("oversample=", SIM.oversample) print("region_of_interest=", SIM.region_of_interest) print("wavelength_A=", SIM.wavelength_A) print("energy_eV=", SIM.energy_eV) print("fluence=", SIM.fluence) print("flux=", SIM.flux) print("exposure_s=", SIM.exposure_s) print("beamsize_mm=", SIM.beamsize_mm) print("dispersion_pct=", SIM.dispersion_pct) print("dispsteps=", SIM.dispsteps) print("divergence_hv_mrad=", SIM.divergence_hv_mrad) print("divsteps_hv=", SIM.divsteps_hv) print("divstep_hv_mrad=", SIM.divstep_hv_mrad) print("round_div=", SIM.round_div) print("phi_deg=", SIM.phi_deg) print("osc_deg=", SIM.osc_deg) print("phisteps=", SIM.phisteps) print("phistep_deg=", SIM.phistep_deg) print("detector_thick_mm=", SIM.detector_thick_mm) print("detector_thicksteps=", SIM.detector_thicksteps) print("detector_thickstep_mm=", SIM.detector_thickstep_mm) print("***mosaic_spread_deg=", SIM.mosaic_spread_deg) print("***mosaic_domains=", SIM.mosaic_domains) print("indices=", SIM.indices) print("amplitudes=", SIM.amplitudes) print("Fhkl_tuple=", SIM.Fhkl_tuple) print("default_F=", SIM.default_F) print("interpolate=", SIM.interpolate) print("integral_form=", SIM.integral_form) from libtbx.development.timers import Profiler P = Profiler("nanoBragg") # now actually burn up some CPU #SIM.add_nanoBragg_spots() del P # simulated crystal is only 125 unit cells (25 nm wide) # amplify spot signal to simulate physical crystal of 4000x larger: 100 um (64e9 x the volume) print(crystal.domains_per_crystal) SIM.raw_pixels *= crystal.domains_per_crystal # must calculate the correct scale! output = StringIO() # open("myfile","w") make_response_plot = response_plot(False, title=prefix) for x in range(0, 100, 2): #len(flux)): if flux[x] == 0.0: continue print("+++++++++++++++++++++++++++++++++++++++ Wavelength", x) CH = channel_pixels(ROI, wavlen[x], flux[x], N, UMAT_nm, Amatrix_rot, GF, output) incremental_signal = CH.raw_pixels * crystal.domains_per_crystal make_response_plot.append_channel(x, ROI, incremental_signal) if x in [26, 40, 54, 68]: # subsample 7096, 7110, 7124, 7138 eV print("----------------------> subsample", x) make_response_plot.incr_subsample(x, ROI, incremental_signal) make_response_plot.increment(x, ROI, incremental_signal) SIM.raw_pixels += incremental_signal CH.free_all() message = output.getvalue().split() miller = (int(message[4]), int(message[5]), int(message[6])) intensity = float(message[9]) #SIM.to_smv_format(fileout=prefix + "_intimage_001.img") pixels = SIM.raw_pixels roi_pixels = pixels[ROI[1][0]:ROI[1][1], ROI[0][0]:ROI[0][1]] print("Reducing full shape of", pixels.focus(), "to ROI of", roi_pixels.focus()) SIM.free_all() make_response_plot.plot(roi_pixels, miller) return dict(roi_pixels=roi_pixels, miller=miller, intensity=intensity, channels=make_response_plot.channels)
if rank == 0 and size == 1: # special case of testing it import sys try: rank = int(sys.argv[1]) size = 1024 usingMPI = False except Exception: pass print("MPI rank %d of %d" % (rank, size)) N_stride = int(math.ceil(N_total / size)) # total number of tasks per rank print("hello from rank %d of %d with stride %d" % (rank, size, N_stride)) if (not usingMPI) or rank == 0: print("set up in rank 0") from LS49.sim.step5_pad import data pdb_lines = data().get("pdb_lines") from LS49.sim.util_fmodel import gen_fmodel GF = gen_fmodel(resolution=10.0, pdb_text=pdb_lines, algorithm="fft", wavelength=1.7) A = GF.get_amplitudes() from LS49.spectra.generate_spectra import spectra_simulation SS = spectra_simulation() from LS49 import legacy_random_orientations random_orientations = legacy_random_orientations(N_total) transmitted_info = dict(