def sim_spots(F): a_real = (79, 0, 0) b_real = (0, 79, 0) c_real = (0, 0, 38) C = Crystal(a_real, b_real, c_real, 'P43212') nbcryst = NBcrystal(init_defaults=True) nbcryst.dxtbx_crystal = C # simulate ground truth nbcryst.thick_mm = 0.1 nbcryst.Ncells_abc = 10, 10, 10 nbcryst.miller_array = F print("Ground truth ncells = %f" % (nbcryst.Ncells_abc[0])) # ground truth detector from simtbx.nanoBragg.sim_data import SimData DET_gt = SimData.simple_detector(150, 0.177, (600, 600)) # initialize the simulator SIM = SimData(use_default_crystal=True) SIM.detector = DET_gt SIM.crystal = nbcryst SIM.instantiate_diffBragg(oversample=0) SIM.D.default_F = 0 SIM.D.progress_meter = False SIM.D.add_diffBragg_spots() SIM.D.F000 = 0 SPOTS = SIM.D.raw_pixels.as_numpy_array() SIM.D.free_all() SIM.D.free_Fhkl2() return SPOTS
ETA_ABC_GT = args.eta nbcryst.anisotropic_mos_spread_deg = ETA_ABC_GT NCELLS_GT = 12, 12, 11 else: NCELLS_GT = 12, 12, 11 nbcryst.Ncells_abc = NCELLS_GT SIM = SimData(use_default_crystal=True) #SIM.detector = SimData.simple_detector(150, 0.1, (513, 512)) if "eta" in args.perturb: shape = 513 * 3, 512 * 3 #detdist = 70 else: shape = 513, 512 detdist = 150 SIM.detector = SimData.simple_detector(detdist, 0.1, shape) SIM.crystal = nbcryst SIM.instantiate_diffBragg(oversample=0, auto_set_spotscale=True) SIM.D.default_F = 0 SIM.D.F000 = 0 SIM.D.progress_meter = False SIM.water_path_mm = 0.005 SIM.air_path_mm = 0.1 SIM.add_air = True SIM.add_Water = True SIM.include_noise = True SIM.D.verbose = 2 SIM.D.add_diffBragg_spots() SIM.D.verbose = 0 spots = SIM.D.raw_pixels.as_numpy_array() SIM._add_background()
a_real, b_real, c_real = sqr( uctbx.unit_cell( ucell).orthogonalization_matrix()).transpose().as_list_of_lists() C = Crystal(a_real, b_real, c_real, symbol) # make a nanoBragg crystal to pass to diffBragg nbcryst = NBcrystal() nbcryst.dxtbx_crystal = C nbcryst.n_mos_domains = 1 nbcryst.thick_mm = 0.01 nbcryst.Ncells_abc = (7, 7, 7) # make an instance of diffBRagg, use the simData wrapper SIM = SimData(use_default_crystal=True) # overwrite the default detector with a smaller pixels one SIM.detector = SimData.simple_detector(220, 0.1, (1000, 1000)) SIM.crystal = nbcryst SIM.instantiate_diffBragg(oversample=0, verbose=0, interpolate=0, default_F=1e3, auto_set_spotscale=True) # D is an instance of diffBragg with reasonable parameters # and our dxtbx crystal created above D = SIM.D if args.curvatures: D.compute_curvatures = True # STEP 1: simulate the un-perturbed image: D.refine(rot_idx)
nbcryst.dxtbx_crystal = C # simulate ground truth nbcryst.thick_mm = 0.1 nbcryst.Ncells_abc = Ncells_gt # ground truth Ncells nbcryst.mos_spread_deg = MOS_SPREAD if args.aniso is not None: nbcryst.anisotropic_mos_spread_deg = ANISO_MOS_SPREAD assert nbcryst.has_anisotropic_mosaicity else: assert not nbcryst.has_anisotropic_mosaicity nbcryst.n_mos_domains = N_MOS_DOMAINS nbcryst.miller_array = miller_array_GT print("Ground truth ncells = %f" % (nbcryst.Ncells_abc[0])) # ground truth detector DET_gt = SimData.simple_detector(150, 0.177, (600, 600)) # initialize the simulator SIM = SimData() if args.aniso is None: SIM.Umats_method = 2 else: SIM.Umats_method = 3 SIM.detector = DET_gt SIM.crystal = nbcryst SIM.instantiate_diffBragg(oversample=1, verbose=0) SIM.D.refine(eta_diffBragg_id) SIM.D.initialize_managers() SIM.D.spot_scale = 100000 SIM.D.default_F = 0 SIM.D.progress_meter = False
n_ucell_params = len(UcellMan.variables) assert np.allclose(UcellMan.B_recipspace, C.get_B()) # STEP4: # make a nanoBragg crystal to pass to diffBragg nbcryst = NBcrystal(init_defaults=True) nbcryst.dxtbx_crystal = C nbcryst.n_mos_domains = 1 nbcryst.thick_mm = 0.01 nbcryst.Ncells_abc = (7, 7, 7) # STEP5: make an instance of diffBRagg, use the simData wrapper SIM = SimData() # overwrite the default detector to use smaller pixels img_sh = 700, 700 SIM.detector = SimData.simple_detector(300, 0.1, img_sh) SIM.crystal = nbcryst SIM.instantiate_diffBragg(oversample=0, verbose=0, auto_set_spotscale=True) # D is an instance of diffBragg with sensible parameters # and our dxtbx crystal created above D = SIM.D D.progress_meter = True # STEP6: # initialize the derivative managers for the unit cell parameters for i_param in range(n_ucell_params): D.refine(UCELL_ID_OFFSET + i_param) for i in range(n_ucell_params): D.set_ucell_derivative_matrix(UCELL_ID_OFFSET + i, UcellMan.derivative_matrices[i]) if args.curvatures:
C2.rotate_around_origin(rot_axis, rot_ang) assert np.allclose(C2.get_U(), C.get_U()) C2.rotate_around_origin(col(perturb_rot_axis), perturb_rot_ang) # Setup the simulation and create a realistic image # with background and noise # <><><><><><><><><><><><><><><><><><><><><><><><><> nbcryst = NBcrystal() nbcryst.dxtbx_crystal = C # simulate ground truth nbcryst.thick_mm = 0.1 nbcryst.Ncells_abc = 12, 12, 11 nbcryst.isotropic_ncells = False SIM = SimData(use_default_crystal=True) #SIM.detector = SimData.simple_detector(150, 0.1, (513, 512)) SIM.detector = SimData.simple_detector(150, 0.1, (513, 512)) SIM.crystal = nbcryst SIM.instantiate_diffBragg(oversample=0, auto_set_spotscale=True) SIM.D.default_F = 0 SIM.D.F000 = 0 SIM.D.progress_meter = False SIM.water_path_mm = 0.005 SIM.air_path_mm = 0.1 SIM.add_air = True SIM.add_Water = True SIM.include_noise = True SIM.D.add_diffBragg_spots() spots = SIM.D.raw_pixels.as_numpy_array() SIM._add_background() SIM.D.readout_noise_adu = args.readout
rotation = Rotation.random(num=1, random_state=101)[0] Q = rec(rotation.as_quat(), n=(4, 1)) rot_ang, rot_axis = Q.unit_quaternion_as_axis_and_angle() C.rotate_around_origin(rot_axis, rot_ang) # make a nanoBragg crystal to pass to diffBragg nbcryst = NBcrystal(init_defaults=True) nbcryst.dxtbx_crystal = C nbcryst.n_mos_domains = 1 nbcryst.thick_mm = 0.01 nbcryst.Ncells_abc = (7, 7, 7) # make an instance of diffBRagg, use the simData wrapper SIM = SimData(use_default_crystal=True) # overwrite the default detector with a smaller pixels one SIM.detector = SimData.simple_detector(300, 0.1, (700, 700)) SIM.crystal = nbcryst Fcell = 1e6 SIM.instantiate_diffBragg(oversample=0, verbose=0, interpolate=0, default_F=Fcell) # D is an instance of diffBragg with reasonable parameters # and our dxtbx crystal created above D = SIM.D D.progress_meter = True # initialize the derivative manager for Fcell fcell = 11 # internal index of fcell manager within diffBragg D.refine(fcell)