def process(self, single_image=False): """ Image processing; selects method, runs requisite modules """ if self.status != 'bypass grid search': self.status = 'processing' #for CCTBX indexing / integration if self.params.advanced.integrate_with == 'cctbx': terminate = False prev_status = self.status prev_fail = 'first cycle' prev_final = self.final prev_epv = 9999 while not terminate: if os.path.isfile(self.abort_file): self.fail = 'aborted' return self # Run grid search if haven't already if self.fail == None and 'grid search' not in self.status: self.integrate_cctbx('grid search', single_image=single_image) # Run selection if haven't already if self.fail == None and self.status != 'selection': self.select_cctbx() # If smart grid search is active run multiple rounds until convergence if self.params.cctbx.grid_search.type == 'smart': if self.fail == None and self.final['epv'] < prev_epv: prev_epv = self.final['epv'] prev_final = self.final prev_status = self.status prev_fail = self.fail self.hmed = self.final['sph'] self.amed = self.final['spa'] self.generate_grid() self.final['final'] = self.fin_file if len(self.grid) == 0: self.final = prev_final self.status = prev_status self.fail = prev_fail terminate = True continue if self.verbose: log_entry = '\nNew starting point: H = {}, A = {}\n'\ ''.format(self.hmed, self.amed) self.log_info.append(log_entry) else: if prev_fail != 'first cycle': self.final = prev_final self.status = prev_status self.fail = prev_fail if self.verbose: log_entry = '\nFinal set of parameters: H = {}, A = {}'\ ''.format(self.final['sph'], self.final['spa']) self.log_info.append(log_entry) terminate = True # If brute force grid search is selected run one round else: terminate = True # Run final integration if haven't already if self.fail == None and self.status != 'final': self.integrate_cctbx('integrate', single_image=single_image) # If verbose output selected (default), write to main log if self.verbose: log_entry = "\n".join(self.log_info) misc.main_log(self.main_log, log_entry) misc.main_log(self.main_log, '\n\n') # Make a temporary process log into a final process log if os.path.isfile(self.int_log): final_int_log = os.path.join( self.log_path, os.path.basename(self.int_log).split('.')[0] + '.log') os.rename(self.int_log, final_int_log) # For DIALS integration (WORK IN PROGRESS) elif self.params.advanced.integrate_with == 'dials': if os.path.isfile(self.abort_file): self.fail = 'aborted' return self if self.fail is not None: self.status = 'final' ep.dump(self.obj_file, self) return self else: # Create DIALS integrator object from iota.components.iota_dials import Integrator integrator = Integrator(source_image=self.conv_img, object_folder=self.obj_path, int_folder=self.int_base, final_filename=self.fin_file, final=self.final, logfile=self.int_log, gain=self.gain, center_intensity=self.center_int, params=self.params) # Run DIALS self.fail, self.final, int_log = integrator.run() if self.fail != None: self.status = 'final' self.log_info.append(int_log) log_entry = "\n".join(self.log_info) misc.main_log(self.main_log, log_entry) misc.main_log(self.main_log, '\n{:-^100}\n'.format('')) # Make a temporary process log into a final process log final_int_log = self.int_log.split('.')[0] + ".log" os.rename(self.int_log, final_int_log) self.status = 'final' ep.dump(self.obj_file, self)
def process(self, single_image=False): """ Image processing; selects method, runs requisite modules """ if self.status != 'bypass grid search': self.status = 'processing' #for CCTBX indexing / integration if self.params.advanced.integrate_with == 'cctbx': terminate = False prev_status = self.status prev_fail = 'first cycle' prev_final = self.final prev_epv = 9999 while not terminate: if os.path.isfile(self.abort_file): self.fail = 'aborted' return self # Run grid search if haven't already if self.fail == None and 'grid search' not in self.status: self.integrate_cctbx('grid search', single_image=single_image) # Run selection if haven't already if self.fail == None and self.status != 'selection': self.select_cctbx() # If smart grid search is active run multiple rounds until convergence if self.params.cctbx.grid_search.type == 'smart': if self.fail == None and self.final['epv'] < prev_epv: prev_epv = self.final['epv'] prev_final = self.final prev_status = self.status prev_fail = self.fail self.hmed = self.final['sph'] self.amed = self.final['spa'] self.generate_grid() self.final['final'] = self.fin_file if len(self.grid) == 0: self.final = prev_final self.status = prev_status self.fail = prev_fail terminate = True continue if self.verbose: log_entry = '\nNew starting point: H = {}, A = {}\n'\ ''.format(self.hmed, self.amed) self.log_info.append(log_entry) else: if prev_fail != 'first cycle': self.final = prev_final self.status = prev_status self.fail = prev_fail if self.verbose: log_entry = '\nFinal set of parameters: H = {}, A = {}'\ ''.format(self.final['sph'], self.final['spa']) self.log_info.append(log_entry) terminate = True # If brute force grid search is selected run one round else: terminate = True # Run final integration if haven't already if self.fail == None and self.status != 'final': self.integrate_cctbx('integrate', single_image=single_image) # If verbose output selected (default), write to main log if self.verbose: log_entry = "\n".join(self.log_info) misc.main_log(self.main_log, log_entry) misc.main_log(self.main_log, '\n\n') # Make a temporary process log into a final process log if os.path.isfile(self.int_log): final_int_log = os.path.join(self.fin_path, os.path.basename(self.int_log).split('.')[0] + '.log') os.rename(self.int_log, final_int_log) # For DIALS integration (WORK IN PROGRESS) elif self.params.advanced.integrate_with == 'dials': if os.path.isfile(self.abort_file): self.fail = 'aborted' return self # Create DIALS integrator object from iota.components.iota_dials import Integrator integrator = Integrator(self.conv_img, self.obj_base, self.fin_base, self.fin_file, self.final, self.int_log, self.gain, self.params) # Run DIALS self.fail, self.final, int_log = integrator.run() if self.fail != None: self.status = 'final' self.log_info.append(int_log) log_entry = "\n".join(self.log_info) misc.main_log(self.main_log, log_entry) misc.main_log(self.main_log, '\n{:-^100}\n'.format('')) # Make a temporary process log into a final process log final_int_log = self.int_log.split('.')[0] + ".log" os.rename(self.int_log, final_int_log) self.status = 'final' ep.dump(self.obj_file, self)
def integrate_cctbx(self, tag, grid_point=0, single_image=False): """ Runs integration using the Integrator class """ # Check to see if the image is suitable for grid search / integration if self.fail != None: self.grid = [] self.final['final'] = None else: from iota.components.iota_cctbx import Integrator integrator = Integrator(params=self.params, source_image=self.conv_img, output_image=self.fin_file, viz=self.viz_path, log=self.int_log, tag=tag, tmp_base=self.tmp_base, gain=self.gain, single_image=single_image) if tag == 'grid search': self.log_info.append('\nCCTBX grid search:') for i in range(len(self.grid)): # If aborted from GUI if os.path.isfile(self.abort_file): self.fail = 'aborted' return self int_results = integrator.integrate(self.grid[i]) self.grid[i].update(int_results) img_filename = os.path.basename(self.conv_img) log_entry ='{:<{width}}: S = {:<3} H = {:<3} ' \ 'A = {:<3} ---> {}'.format(img_filename, self.grid[i]['sih'], self.grid[i]['sph'], self.grid[i]['spa'], self.grid[i]['info'], width = len(img_filename) + 2) self.log_info.append(log_entry) self.gs_results.append(log_entry) # Throw out grid search results that yielded no integration self.grid = [i for i in self.grid if "not integrated" not in i['info'] and\ "no data recorded" not in i['info']] self.status = 'grid search' elif tag == 'split grid': if os.path.isfile(self.abort_file): self.fail = 'aborted' return self self.log_info.append('\nCCTBX INTEGRATION grid search:') int_results = integrator.integrate(self.grid[grid_point]) self.grid[grid_point].update(int_results) img_filename = os.path.basename(self.conv_img) log_entry ='{:<{width}}: S = {:<3} H = {:<3} ' \ 'A = {:<3} ---> {}'.format(img_filename, self.grid[grid_point]['sih'], self.grid[grid_point]['sph'], self.grid[grid_point]['spa'], self.grid[grid_point]['info'], width = len(img_filename) + 2) self.log_info.append(log_entry) self.gs_results.append(log_entry) elif tag == 'integrate': if os.path.isfile(self.abort_file): self.fail = 'aborted' return self self.log_info.append('\nCCTBX final integration:') final_results = integrator.integrate(self.final) self.final.update(final_results) self.status = 'final' img_filename = os.path.basename(self.conv_img) log_entry ='{:<{width}}: S = {:<3} H = {:<3} ' \ 'A = {:<3} ---> {}'.format(img_filename, self.final['sih'], self.final['sph'], self.final['spa'], self.final['info'], width = len(img_filename) + 2) self.log_info.append(log_entry) if self.params.analysis.viz == 'integration': viz.make_png(self.final['img'], self.final['final'], self.viz_file) elif self.params.analysis.viz == 'cv_vectors': viz.cv_png(self.final['img'], self.final['final'], self.viz_file) # Save image object to file ep.dump(self.obj_file, self) return self
def integrate_cctbx(self, tag, grid_point=0, single_image=False): """ Runs integration using the Integrator class """ # Check to see if the image is suitable for grid search / integration if self.fail != None: self.grid = [] self.final['final'] = None else: from iota.components.iota_cctbx import Integrator integrator = Integrator(self.conv_img, self.fin_file, self.params.cctbx.selection.min_sigma, self.params.cctbx.target, self.params.analysis.charts, self.viz_path, self.int_log, tag, self.tmp_base, self.gain, self.params.mp_method, self.params.mp_queue, single_image) if tag == 'grid search': self.log_info.append('\nCCTBX grid search:') for i in range(len(self.grid)): # If aborted from GUI if os.path.isfile(self.abort_file): self.fail = 'aborted' return self int_results = integrator.integrate(self.grid[i]) self.grid[i].update(int_results) img_filename = os.path.basename(self.conv_img) log_entry ='{:<{width}}: S = {:<3} H = {:<3} ' \ 'A = {:<3} ---> {}'.format(img_filename, self.grid[i]['sih'], self.grid[i]['sph'], self.grid[i]['spa'], self.grid[i]['info'], width = len(img_filename) + 2) self.log_info.append(log_entry) self.gs_results.append(log_entry) # Throw out grid search results that yielded no integration self.grid = [i for i in self.grid if "not integrated" not in i['info'] and\ "no data recorded" not in i['info']] self.status = 'grid search' elif tag == 'split grid': if os.path.isfile(self.abort_file): self.fail = 'aborted' return self self.log_info.append('\nCCTBX INTEGRATION grid search:') int_results = integrator.integrate(self.grid[grid_point]) self.grid[grid_point].update(int_results) img_filename = os.path.basename(self.conv_img) log_entry ='{:<{width}}: S = {:<3} H = {:<3} ' \ 'A = {:<3} ---> {}'.format(img_filename, self.grid[grid_point]['sih'], self.grid[grid_point]['sph'], self.grid[grid_point]['spa'], self.grid[grid_point]['info'], width = len(img_filename) + 2) self.log_info.append(log_entry) self.gs_results.append(log_entry) elif tag == 'integrate': if os.path.isfile(self.abort_file): self.fail = 'aborted' return self self.log_info.append('\nCCTBX final integration:') final_results = integrator.integrate(self.final) self.final.update(final_results) self.status = 'final' img_filename = os.path.basename(self.conv_img) log_entry ='{:<{width}}: S = {:<3} H = {:<3} ' \ 'A = {:<3} ---> {}'.format(img_filename, self.final['sih'], self.final['sph'], self.final['spa'], self.final['info'], width = len(img_filename) + 2) self.log_info.append(log_entry) if self.params.analysis.viz == 'integration': viz.make_png(self.final['img'], self.final['final'], self.viz_file) elif self.params.analysis.viz == 'cv_vectors': viz.cv_png(self.final['img'], self.final['final'], self.viz_file) # Save image object to file ep.dump(self.obj_file, self) return self