def map_calculate_rings(mp): # set up parameters mp.structure_generator.random.setstate(mp.random_state) es = ewald_sphere() es.set_wavelength(mp.beam_properties.wavelength) es.set_distance(mp.detector_properties.distance) ic = image_composer() ic.set_detector_size(mp.detector_properties.detector_size) ic.set_beam_center(mp.detector_properties.beam_center) ic.set_pixel_size(mp.detector_properties.pixel_size) ic.set_ewald_sphere(es) im = image_simulator() im.structures = mp.structure_generator im.image_composer = ic im.cached_h = mp.h # calculate structure factors for i in xrange(mp.n_images): im.structures.randomize() im.sum_structure_factors() # copy intensities to full image sf = im.structure_factors all_sf = flex.complex_double((mp.detector_properties.detector_size[0]+1)*\ (mp.detector_properties.detector_size[1]+1),\ complex(0.0,0.0)) k = 0 for j in xrange(len(mp.use_index)): if (mp.use_index[j]): all_sf[j] = sf[k] k += 1 im.structure_factors = all_sf image_data = im.build_image(n_photons=bp.flux*bp.t) if (True): for q_i in [0.01, 0.1, 0.2]: print q_i, I_q(ic.get_q(),image_data,q_i,mp.dq) write_image(file_name='ring.png', detector_size=mp.detector_properties.detector_size, image_data=image_data) if (False): file_name = './test_rings/' + str(os.getpid()) + '_' + str(i) f = open(file_name,'wb') pickle.dump(image_data,f,2) f.close() return mp.n_images
def map_model_I_q(mp): # set up parameters mp.structure_generator.random.setstate(mp.random_state) es = ewald_sphere() es.set_wavelength(mp.beam_properties.wavelength) es.set_distance(mp.detector_properties.distance) ic = image_composer() ic.set_detector_size(mp.detector_properties.detector_size) ic.set_beam_center(mp.detector_properties.beam_center) ic.set_pixel_size(mp.detector_properties.pixel_size) ic.set_ewald_sphere(es) # initialize image simulator im = image_simulator() im.structures = mp.structure_generator im.image_composer = ic # make images sums = flex.vec2_double(mp.n_bins) for i in xrange(mp.n_images): im.structures.randomize() im.sum_structure_factors_gpu(gpu=mp.gpu) image_data = im.build_image(n_photons=(mp.beam_properties.flux * mp.beam_properties.t)) if (False): for q_i in [0.01, 0.1, 0.2]: print q_i, I_q(im.cached_q, image_data, q_i, mp.dq) write_image(detector_size=mp.detector_properties.detector_size, image_data=image_data) if (True): file_name = '/scratch/home/bkpoon/images/' + str( os.getpid()) + '_' + str(i) f = open(file_name, 'wb') pickle.dump(im.structure_factors, f, 2) f.close() # convert image data to I(q) mv = mean_and_variance_by_q(mp.q_min, mp.q_max, mp.dq, mp.n_bins, im.cached_q, image_data) sums += mv return sums
def map_random_image(p=None): result = [None for i in xrange(p.n_images)] # set random state for current thread p.structure_generator.random.setstate(p.random_state) es = ewald_sphere() es.set_wavelength(p.beam_properties.wavelength) es.set_distance(p.detector_properties.distance) ic = image_composer() ic.set_detector_size(p.detector_properties.detector_size) ic.set_beam_center(p.detector_properties.beam_center) ic.set_pixel_size(p.detector_properties.pixel_size) ic.set_ewald_sphere(es) im = image_simulator() im.structures = p.structure_generator im.image_composer = ic h = ic.cache_h() sf_length = (p.detector_properties.detector_size[0] + 1) *\ (p.detector_properties.detector_size[1] + 1) n_photons = p.beam_properties.flux * p.beam_properties.t for i in xrange(p.n_images): sf = flex.complex_double(sf_length, 0.0) im.structures.species[0].n_copies = p.n_particles[i] im.structures.randomize() for j in xrange(p.n_particles[i]): image_name = p.base_image_directory + im.structures.random.choice( image_list) t = im.structures.translations[0][j] f = open(image_name, 'rb') sf_tmp = pickle.load(f) f.close() sf_tmp = apply_translation(sf_tmp, h, t) sf += sf_tmp im.structure_factors = sf image_data = im.build_image(n_photons=n_photons) result[i] = image_data.deep_copy() return result
mp.n_bins = 100 mp.q_min = 0.005 mp.q_max = 0.45 mp.dq = (mp.q_max - mp.q_min)/mp.n_bins s = structure_generator() s.add_species(pdb_input=pdb.input('6LYZ.pdb'),n_copies=2) mp.structure_generator = s rings = [0.01, 0.1, 0.2] es = ewald_sphere() es.set_wavelength(bp.wavelength) es.set_distance(dp.distance) ic = image_composer() ic.set_detector_size(dp.detector_size) ic.set_beam_center(dp.beam_center) ic.set_pixel_size(dp.pixel_size) ic.set_ewald_sphere(es) q = ic.get_q() # flag pixel corners for each ring pixel_xy = list() all_h = ic.cache_h() use_index = flex.bool(len(all_h),False) use_index[dp.beam_center[1]*dp.detector_size[0] + dp.beam_center[0]] = True n_x = dp.detector_size[0] + 1 for x in xrange(dp.detector_size[0]): for y in xrange(dp.detector_size[1]):