def initialize_single_image(img, paramfile, output_file=None, output_dir=None, min_bragg=10): phil, _ = inp.get_input_phil(paramfile=paramfile) params = phil.extract() params.input = [img] params.mp.n_processors = 1 params.data_selection.image_triage.minimum_Bragg_peaks = min_bragg info = ProcInfo.from_args(iota_phil=phil.as_str(), paramfile=paramfile) # Initialize output if output_file is not None: if output_dir is not None: output = os.path.join(os.path.abspath(output_dir), output_file) else: output = os.path.abspath(output_file) else: output = None info.obj_list_file = output info.generate_input_list(params=params) info = generate_stat_containers(info=info, params=params) return info, params
def initialize_new_run(phil, input_dict=None, target_phil=None): ''' Create base integration folder; safe phil, input, and info to file ''' try: params = phil.extract() int_base, run_no = util.set_base_dir(dirname='integration', out_dir=params.output, get_run_no=True) if not os.path.isdir(int_base): os.makedirs(int_base) # Create input list file and populate param input line if input_dict: if len(input_dict['imagepaths']) >= 10: input_list_file = os.path.join(int_base, 'input.lst') with open(input_list_file, 'w') as lf: for f in input_dict['imagefiles']: lf.write('{}\n'.format(f)) params.input = [input_list_file] else: input_list_file = None params.input = input_dict['imagepaths'] else: input_list_file = None # Generate default backend PHIL, write to file, and update params target_fp = os.path.join(int_base,'target.phil') if target_phil: target_phil = inp.write_phil(phil_str=target_phil, dest_file=target_fp, write_target_file=True) else: if params.cctbx_xfel.target: target_phil = inp.write_phil(phil_file=params.cctbx_xfel.target, dest_file=target_fp, write_target_file=True) else: method = params.advanced.processing_backend target_phil, _ = inp.write_defaults(method=method, write_param_file=False, filepath=target_fp) params.cctbx_xfel.target = target_fp # Save PHIL for this run in base integration folder paramfile = os.path.join(int_base, 'iota_r{}.param'.format(run_no)) phil = phil.format(python_object=params) with open(paramfile, 'w') as philf: philf.write(phil.as_str()) # Initialize main log logfile = os.path.abspath(os.path.join(int_base, 'iota.log')) # Initialize proc.info object and save to file info = ProcInfo.from_args( iota_phil=phil.as_str(), target_phil=target_phil.as_str(), int_base=int_base, input_list_file=input_list_file, info_file=os.path.join(int_base, 'proc.info'), cluster_info_file=os.path.join(int_base, 'cluster.info'), paramfile=paramfile, logfile=logfile, run_number=run_no, description=params.description, status='initialized', have_results=False, errors=[], init_proc=False) info.export_json() return True, info, 'IOTA_XTERM_INIT: Initialization complete!' except Exception as e: import traceback traceback.print_exc() msg = 'IOTA_INIT_ERROR: Could not initialize run! {}'.format(e) return False, None, msg
def initialize_new_run(phil, input_dict=None, target_phil=None): ''' Create base integration folder; safe phil, input, and info to file ''' try: params = phil.extract() int_base, run_no = util.set_base_dir(dirname='integration', out_dir=params.output, get_run_no=True) if not os.path.isdir(int_base): os.makedirs(int_base) # Create input list file and populate param input line if input_dict: if len(input_dict['imagepaths']) >= 25: input_list_file = os.path.join(int_base, 'input.lst') with open(input_list_file, 'w') as lf: for f in input_dict['imagefiles']: lf.write('{}\n'.format(f)) params.input = [input_list_file] else: # If there are too many imagefiles, re-constitute the "glob" format # by matching filepaths and replacing non-matching characters with # asterisks if len(input_dict['imagefiles']) >= 25: input_paths = [] for path in input_dict['imagepaths']: fileset = [ os.path.basename(i) for i in input_dict['imagefiles'] if path in i ] zips = [list(set(i)) for i in zip(*fileset)] chars = [i[0] if len(i) == 1 else '*' for i in zips] fname = ''.join(chars) while "*" * 2 in fname: fname = fname.replace("*" * 2, "*") input_paths.append(os.path.join(path, fname)) params.input = input_paths else: params.input = input_dict['imagefiles'] input_list_file = None else: input_list_file = None # Generate default backend PHIL, write to file, and update params target_fp = os.path.join(int_base, 'target.phil') if target_phil: target_phil = inp.write_phil(phil_str=target_phil, dest_file=target_fp, write_target_file=True) else: if params.cctbx_xfel.target: target_phil = inp.write_phil( phil_file=params.cctbx_xfel.target, dest_file=target_fp, write_target_file=True) else: method = params.advanced.processing_backend target_phil, _ = inp.write_defaults(method=method, write_param_file=False, filepath=target_fp) params.cctbx_xfel.target = target_fp # Save PHIL for this run in base integration folder paramfile = os.path.join(int_base, 'iota_r{}.param'.format(run_no)) phil = phil.format(python_object=params) with open(paramfile, 'w') as philf: philf.write(phil.as_str()) # Initialize main log logfile = os.path.abspath(os.path.join(int_base, 'iota.log')) # Initialize proc.info object and save to file info = ProcInfo.from_args( iota_phil=phil.as_str(), target_phil=target_phil.as_str(), int_base=int_base, input_list_file=input_list_file, info_file=os.path.join(int_base, 'proc.info'), cluster_info_file=os.path.join(int_base, 'cluster.info'), paramfile=paramfile, logfile=logfile, run_number=run_no, description=params.description, status='initialized', have_results=False, errors=[], init_proc=False) info.export_json() return True, info, 'IOTA_XTERM_INIT: Initialization complete!' except Exception as e: msg = 'IOTA_INIT_ERROR: Could not initialize run! {}'.format(e) return False, None, msg