def dump_subvol(self,picking_result): from aitom.classify.deep.unsupervised.autoencoder.autoencoder_util import peaks_to_subvolumes subvols_loc = os.path.join(self.dump_path,"demo_single_particle_subvolumes.pickle") a = io_file.read_mrc_data(self.path) d = peaks_to_subvolumes(im_vol_util.cub_img(a)['vt'], picking_result, 32) io_file.pickle_dump(d, subvols_loc) print("Save subvolumes .pickle file to:", subvols_loc)
def particle_picking(mrc_header): sigma1 = max(int(7 / voxel_spacing_in_nm), 2) # In general, 7 is optimal sigma1 val in nm according to the paper and sigma1 should at least be 2 print('sigma1=%d' % sigma1) # For particular tomogram, larger sigma1 value may have better results. Use IMOD to display selected peaks and determine best sigma1. # For 'aitom_demo_cellular_tomogram.mrc', sigma1 is 5 rather than 3 for better performance(in this tomogram, 7nm corresponds to 3.84 pixels) # print(mrc_header['MRC']['xlen'], mrc_header['MRC']['nx'], voxel_spacing_in_nm, sigma1) partition_op = {'nonoverlap_width': sigma1 * 20, 'overlap_width': sigma1 * 10, 'save_vg': False} result = picking(path, s1=sigma1, s2=sigma1 * 1.1, t=3, find_maxima=False, partition_op=partition_op, multiprocessing_process_num=10, pick_num=1000) print("DoG done, %d particles picked" % len(result)) pprint(result[:5]) # (Optional) Save subvolumes of peaks for autoencoder input dump_subvols = True if dump_subvols: # use later for autoencoder subvols_loc = "demo_single_particle_subvolumes.pickle" from aitom.classify.deep.unsupervised.autoencoder.autoencoder_util import peaks_to_subvolumes a = io_file.read_mrc_data(path) d = peaks_to_subvolumes(im_vol_util.cub_img(a)['vt'], result, 32) io_file.pickle_dump(d, subvols_loc) print("Save subvolumes .pickle file to:", subvols_loc)
def main(): # Download from: https://cmu.box.com/s/9hn3qqtqmivauus3kgtasg5uzlj53wxp path = '/ldap_shared/home/v_zhenxi_zhu/data/aitom_demo_single_particle_tomogram.mrc' # Also, we can crop and only use part of the mrc image instead of binning for tasks requiring higher resolution # crop_path = 'cropped.mrc' # crop_mrc(path, crop_path) mrc_header = io_file.read_mrc_header(path) voxel_spacing_in_nm = mrc_header['MRC']['xlen'] / mrc_header['MRC'][ 'nx'] / 10 sigma1 = max( int(7 / voxel_spacing_in_nm), 2 ) # In general, 7 is optimal sigma1 val in nm according to the paper and sigma1 should at least be 2 print('sigma1=%d' % sigma1) # For particular tomogram, larger sigma1 value may have better results. Use IMOD to display selected peaks and determine best sigma1. # For 'aitom_demo_cellular_tomogram.mrc', sigma1 is 5 rather than 3 for better performance(in this tomogram, 7nm corresponds to 3.84 pixels) # print(mrc_header['MRC']['xlen'], mrc_header['MRC']['nx'], voxel_spacing_in_nm, sigma1) partition_op = { 'nonoverlap_width': sigma1 * 20, 'overlap_width': sigma1 * 10, 'save_vg': False } result = picking(path, s1=sigma1, s2=sigma1 * 1.1, t=3, find_maxima=False, partition_op=partition_op, multiprocessing_process_num=10, pick_num=1000) print("DoG done, %d particles picked" % len(result)) pprint(result[:5]) # (Optional) Save subvolumes of peaks for autoencoder input dump_subvols = True if dump_subvols: # use later for autoencoder subvols_loc = "demo_single_particle_subvolumes.pickle" from aitom.classify.deep.unsupervised.autoencoder.autoencoder_util import peaks_to_subvolumes a = io_file.read_mrc_data(path) d = peaks_to_subvolumes(im_vol_util.cub_img(a)['vt'], result, 32) io_file.pickle_dump(d, subvols_loc) print("Save subvolumes .pickle file to:", subvols_loc) # Display selected peaks using imod/3dmod (http://bio3d.colorado.edu/imod/) ''' #Optional: smooth original image a = io_file.read_mrc_data(path) path =path[:-5]+'_smoothed'+path[-4:] temp = im_vol_util.cub_img(a) s1 = sigma1 s2=sigma1*1.1 vg = dog_smooth(temp['vt'], s1,s2) #vg = smooth(temp['vt'], s1) TIM.write_data(vg,path) ''' json_data = [] # generate file for 3dmod for i in range(len(result)): loc_np = result[i]['x'] loc = [] for j in range(len(loc_np)): loc.append(loc_np[j].tolist()) json_data.append({'peak': {'loc': loc}}) with open('data_json_file.json', 'w') as f: json.dump(json_data, f) dj = json_data x = N.zeros((len(dj), 3)) for i, d in enumerate(dj): x[i, :] = N.array(d['peak']['loc']) l = generate_lines(x_full=x, rad=sigma1) display_map_with_lines(l=l, map_file=path)