def save_results(data_img, crystal, refl, fcalc_file, Xang, Yang, filename): x = col((1, 0, 0)) y = col((0, 1, 0)) rX = x.axis_and_angle_as_r3_rotation_matrix(Xang, deg=True) rY = y.axis_and_angle_as_r3_rotation_matrix(Yang, deg=True) energies, fcalc_at_en = sim_utils.load_fcalc_file(fcalc_file) Patts = PatternFactory() Patts.adjust_mosaicity(2, 0.05) #flux_per_en = [fracA*Patts.SIM2.flux, fracB*Patts.SIM2.flux] flux_per_en = [fracA * 1e14, fracB * 1e14] sim_patt = Patts.make_pattern2(crystal=deepcopy(crystal), flux_per_en=flux_per_en, energies_eV=energies, fcalcs_at_energies=fcalcs_at_en, mosaic_spread=None, mosaic_domains=None, ret_sum=True, Op=None) sim_patt_R = Patts.make_pattern2(crystal=deepcopy(crystal), flux_per_en=flux_per_en, energies_eV=energies, fcalcs_at_energies=fcalcs_at_en, mosaic_spread=None, mosaic_domains=None, ret_sum=True, Op=rX * rY) refls = [refl] * 3 imgs = [sim_patt, data_img, sim_patt_R] utils.images_and_refls_to_simview(filename, imgs, refls)
def refine_cell(data): spot_mask = spot_utils.strong_spot_mask(data['refl'], (1800, 1800)) Patts = sim_utils.PatternFactory() Patts.adjust_mosaicity(2, 0.5) energy, fcalc = sim_utils.load_fcalc_file(data['fcalc_f']) crystal = data['crystal'] a, b, c, _, _, _ = crystal.get_unit_cell().parameters() optX, optY = data['optX'], data['optY'] optX_fine, optY_fine = data['optX_fine'], data['optY_fine'] Op = optX_fine * optY_fine * optX * optY crystal.set_U(Op) overlaps = [] imgs_all = [] percs = np.arange(-0.005, 0.006, 0.001) crystals = [] for i in percs: for j in percs: crystal2 = deepcopy(crystal) a2 = a + a * i c2 = c + c * j B2 = sqr((a2, 0, 0, 0, a2, 0, 0, 0, c2)).inverse() crystal2.set_B(B2) sim_patt = Patts.make_pattern2( crystal=crystal2, flux_per_en=[data['fracA'] * 1e14, data['fracB'] * 1e14], energies_eV=energy, fcalcs_at_energies=fcalc, mosaic_spread=None, mosaic_domains=None, ret_sum=True, Op=None) sim_sig_mask = sim_patt > 0 overlaps.append(np.sum(sim_sig_mask * spot_mask)) crystals.append(deepcopy(crystal2)) imgs_all.append(sim_patt) refls_all = [data["refl"]] * len(imgs_all) utils.images_and_refls_to_simview("cell_refine", imgs_all, refls_all) return overlaps, crystals
def xyscan_multi(crystal, fcalcs_file, fracA, fracB, strong, rot_series, n_jobs, scan_func=xyscan, use_weights=False, raw_image=None): """ :param crystal_file: :param energies: :param fcalcs_file: :param fracA: :param fracB: :param strong_file: :param rotxy_series: :param n_jobs: :return: """ from joblib import Parallel, delayed nscans = len(rot_series) scan_idx = np.array_split(range(nscans), n_jobs) scan_split = [] for idx in scan_idx: scan_split.append([rot_series[i] for i in idx]) energy, fcalcs = sim_utils.load_fcalc_file(fcalcs_file) results = Parallel(n_jobs=n_jobs)(delayed(scan_func)\ (crystal=crystal, fcalcs_energies=energy, fcalcs = fcalcs, fracA=fracA, fracB=fracB, strong=strong,jid=jid, use_weights=use_weights, raw_image=raw_image, rotxy_series=scan_split[jid]) \ for jid in range(n_jobs)) results = np.concatenate(results) return results
idx = hit_idx[0] iset = loader.get_imageset(img_f)[idx:idx + 1] dblock = DataBlockFactory.from_imageset(iset)[0] refls = info_f[idx]['refl'] fracA = info_f[idx]['fracA'] fracB = info_f[idx]['fracB'] cryst_orig = info_f[idx]['crystals'][0] # load a test crystal #crystal = utils.open_flex( sim_utils.cryst_f ) # fraction of two color energy # simulate the pattern #Patts = sim_utils.PatternFactory() en, fcalc = sim_utils.load_fcalc_file("../sim/fcalc_slim.pkl") flux = [fracA * 1e14, fracB * 1e14] #imgA, imgB = Patts.make_pattern2(crystal, flux, en, fcalc, 20, 0.1, False) # here we can index each 1 color pattern as well as the two color pattern # for fun # ================================== # 2 color indexer of 2 color pattern # ================================== sad_index_params.indexing.multiple_lattice_search.max_lattices = 1 sad_index_params.indexing.stills.refine_all_candidates = True #False sad_index_params.indexing.stills.refine_candidates_with_known_symmetry = True #False sad_index_params.indexing.stills.candidate_outlier_rejection = True # False sad_index_params.indexing.stills.rmsd_min_px = 10 #sad_index_params.indexing.refinement_protocol.mode = "ignore"