def plot_kde(): # Load files print('Loading DIALS files') expt_file = "dials_temp_files/mega_ultra_refined.expt" refl_file = "dials_temp_files/mega_ultra_refined.refl" elist = ExperimentListFactory.from_json_file(expt_file, check_format=False) refls = reflection_table.from_file(refl_file) # Remove outliers print('Removing outliers') idx = refls.get_flags(refls.flags.used_in_refinement).as_numpy_array() idy = np.arange(len(elist))[idx].tolist() elist = ExperimentList([elist[i] for i in idy]) refls = refls.select(flex.bool(idx)) # Generate KDE normalized_resolution, lams, kde = gen_kde(elist, refls) # Make a mesh print('Making a meshgrid') N = 50 x = np.linspace(min(normalized_resolution), max(normalized_resolution), N) y = np.linspace(min(lams), max(lams), N) z = np.zeros(shape=(len(x), len(y))) zeros = np.zeros(len(x)) # Evaluate PDF on mesh for x0, y0 in it.product(x, y): i = np.where(x == x0)[0][0] j = np.where(y == y0)[0][0] z[i, j] = kde.pdf([x0, y0]) # Plot a wireframe print('Plotting') norm = plt.Normalize(z.min(), z.max()) colors = cm.viridis(norm(z)) rcount, ccount, _ = colors.shape fig = plt.figure() ax = fig.add_subplot(projection='3d') surface = ax.plot_surface(x[:, None] + zeros, y[None, :] + zeros, z, rcount=rcount, ccount=ccount, facecolors=colors, shade=False) surface.set_facecolor((0, 0, 0, 0)) plt.xlabel('$1/d^2$ (A$^{-2}$)') plt.ylabel('$\lambda$ (A)') plt.title('PDF of Reflections') plt.show()
macro_cycles = 3 lam_min = 0.95 lam_max = 1.15 d_min = 1.4 rlp_radius = 0.002 n_steps = 10 new_expt_filename = 'dials_temp_files/optimized.expt' new_refl_filename = 'dials_temp_files/optimized.refl' # Load DIALS files print('Loading DIALS files') expt_file = "dials_temp_files/stills_no_sb.expt" refl_file = "dials_temp_files/stills_no_sb.refl" elist = ExperimentListFactory.from_json_file(expt_file, check_format=False) refls = reflection_table.from_file(refl_file) # This will populate refls['s1'] & refls['rlp'] refls.centroid_px_to_mm(elist) refls.map_centroids_to_reciprocal_space(elist) s0 = np.array(elist[0].beam.get_s0()) # Write to reflection file refls['Wavelength'] = flex.double(len(refls)) refls['miller_index'] = flex.miller_index(len(refls)) # Loop over images and index by frame print('Reindexing images') for i in trange(len(elist.imagesets())): # Get experiment data from experiment objects
expt_file1 = "dials_temp_files/optimized.expt" refl_file1 = "dials_temp_files/optimized.refl" expt_file2 = "dials_temp_files/ultra_refined.expt" refl_file2 = "dials_temp_files/ultra_refined.refl" #centroid distance cutoff in pixels centroid_max_distance = 10. print('reading DIALS files') from dxtbx.model.experiment_list import ExperimentListFactory from dials.array_family.flex import reflection_table elist1 = ExperimentListFactory.from_json_file(expt_file1) cryst1 = elist1.crystals()[0] unit_cell1 = cryst1.get_unit_cell() refls1 = reflection_table.from_file(refl_file1) elist2 = ExperimentListFactory.from_json_file(expt_file2) cryst2 = elist2.crystals()[0] unit_cell2 = cryst2.get_unit_cell() refls2 = reflection_table.from_file(refl_file2) # Remove reflections not used in refinement refls2 = refls2.select(refls2.get_flags(refls2.flags.used_in_refinement)) print('generating DIALS dataframes') dials_df1 = rs.DataSet( { 'X': refls1['xyzobs.px.value'].parts()[0].as_numpy_array(), 'Y': refls1['xyzobs.px.value'].parts()[1].as_numpy_array(), 'Wavelength': refls1['Wavelength'].as_numpy_array(), 'BATCH': refls1['imageset_id'].as_numpy_array(),