Exemplo n.º 1
0
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
Exemplo n.º 2
0
def entry_point():
    from iota.components.iota_init import initialize_interface, initialize_new_run

    args, phil_args = parse_command_args().parse_known_args()

    if args.run_path:
        from iota.components.iota_base import ProcInfo

        info = ProcInfo.from_folder(args.run_path[0])
        proc = Process.for_existing_run(info=info, out_type=args.out_type[0])
    else:
        if args.out_type == "progress":
            print(logo)

        if not args.path:
            parse_command_args().print_help()  # Print usage
            if args.default:  # Write out default params and exit
                from iota.components.iota_input import print_params

                help_out, txt_out = print_params()
                print("\n{:-^70}\n".format("IOTA Parameters"))
                print(help_out)
                iota_exit()

        with prog_message("Interpreting input", prog="UI INIT", out_type=args.out_type):
            input_dict, phil, msg = initialize_interface(args, phil_args)
            if not (input_dict or phil):
                iota_exit(silent=(args.out_type == "silent"), msg=msg)

        with prog_message(
            "Initializing run parameters", prog="PARAM INIT", out_type=args.out_type
        ):
            init_ok, info, msg = initialize_new_run(phil=phil, input_dict=input_dict)
            if not init_ok:
                iota_exit(silent=False, msg=msg)

        proc = Process.for_new_run(
            paramfile=info.paramfile, run_no=info.run_number, out_type=args.out_type
        )

    proc.run()
Exemplo n.º 3
0
                    print('\n'.join(self.info.summary))
                else:
                    print('\n **** NO IMAGES INTEGRATED! ****')


# ============================================================================ #
if __name__ == "__main__":

    from iota import logo
    from iota.components import iota_init

    args, phil_args = parse_command_args().parse_known_args()

    if args.run_path:
        from iota.components.iota_base import ProcInfo
        info = ProcInfo.from_folder(args.run_path[0])
        proc = Process.for_existing_run(info=info, out_type=args.out_type[0])
    else:
        if args.out_type == 'progress':
            print(logo)

        if not args.path:
            parse_command_args().print_help()  # Print usage
            if args.default:  # Write out default params and exit
                from iota.components.iota_input import print_params
                help_out, txt_out = print_params()
                print('\n{:-^70}\n'.format('IOTA Parameters'))
                print(help_out)

        with prog_message('Interpreting input',
                          prog='UI INIT',
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def initialize_processing(paramfile, run_no):
  ''' Initialize processing for a set of images
  :param paramfile: text file with IOTA parameters
  :param run_no: number of the processing run
  :return: info: INFO object
           params: IOTA params
  '''
  try:
    phil, _ = inp.get_input_phil(paramfile=paramfile)
  except Exception as e:
    msg = 'IOTA_PROC_ERROR: Cannot import IOTA parameters! {}'.format(e)
    return False, msg
  else:
    params = phil.extract()

  # Reconstruct integration base path and get info object
  int_base = os.path.join(params.output, 'integration/{:03d}'.format(run_no))
  try:
    info_file = os.path.join(int_base, 'proc.info')
    info = ProcInfo.from_json(filepath=info_file)
  except Exception as e:
    msg = 'IOTA_PROC_ERROR: Cannot import INFO object! {}'.format(e)
    return False, msg

  # Generate input list and input base
  if not hasattr(info, 'input_list'):
    info.generate_input_list(params=params)
  common_pfx = os.path.abspath(
    os.path.dirname(os.path.commonprefix(info.input_list)))

  input_base = common_pfx
  if os.path.isdir(os.path.abspath(params.input[0])):
    new_common_pfx = os.path.commonprefix([os.path.abspath(params.input[0]), common_pfx])
    if new_common_pfx not in ('', '.'):
      input_base = new_common_pfx

  # Generate subfolder paths
  paths = dict(obj_base=os.path.join(int_base, 'image_objects'),
               fin_base=os.path.join(int_base, 'final'),
               log_base=os.path.join(int_base, 'logs'),
               viz_base=os.path.join(int_base, 'visualization'),
               tmp_base=os.path.join(int_base, 'tmp'),
               input_base=input_base)
  # FIXME: ordering of items in dictionaries changes depending on python version
  for bkey, bvalue in paths.items():
    if bkey == "input_base":  # I think this is what the original code wanted to do
      continue
    if not os.path.isdir(bvalue):
      os.makedirs(bvalue)
  info.update(paths)

  # Generate filepaths for various info files
  info_files = dict(
    obj_list_file=os.path.join(info.tmp_base, 'finished_objects.lst'),
    idx_file=os.path.join(info.int_base, 'observations.pickle')
  )
  info.update(info_files)

  # Initialize stat containers
  info = generate_stat_containers(info=info, params=params)

    # Initialize main log
  util.main_log(info.logfile, '{:*^80} \n'.format(' IOTA MAIN LOG '))
  util.main_log(info.logfile, '{:-^80} \n'.format(' SETTINGS FOR THIS RUN '))
  util.main_log(info.logfile, info.iota_phil)
  util.main_log(info.logfile, '{:-^80} \n'.format('BACKEND SETTINGS'))
  util.main_log(info.logfile, info.target_phil)

  info.export_json()

  return info, params
Exemplo n.º 6
0
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
Exemplo n.º 7
0
def initialize_processing(paramfile, run_no):
    """Initialize processing for a set of images.

    :param paramfile: text file with IOTA parameters
    :param run_no: number of the processing run
    :return: info: INFO object
             params: IOTA params
    """
    try:
        phil, _ = inp.get_input_phil(paramfile=paramfile)
    except Exception as e:
        msg = "IOTA_PROC_ERROR: Cannot import IOTA parameters! {}".format(e)
        return False, msg
    else:
        params = phil.extract()

    # Reconstruct integration base path and get info object
    int_base = os.path.join(params.output, "integration/{:03d}".format(run_no))
    try:
        info_file = os.path.join(int_base, "proc.info")
        info = ProcInfo.from_json(filepath=info_file)
    except Exception as e:
        msg = "IOTA_PROC_ERROR: Cannot import INFO object! {}".format(e)
        return False, msg

    # Generate input list and input base
    if not hasattr(info, "input_list"):
        info.generate_input_list(params=params)
    filepath_list = []
    for item in info.input_list:
        if isinstance(item, list) or isinstance(item, tuple):
            fp = [i for i in item if os.path.exists(str(i))]
            if fp and len(fp) == 1:
                filepath_list.append(fp[0])
        else:
            if os.path.exists(item):
                filepath_list.append(item)
    common_pfx = os.path.abspath(
        os.path.dirname(os.path.commonprefix(filepath_list)))

    input_base = common_pfx
    if os.path.isdir(os.path.abspath(params.input[0])):
        new_common_pfx = os.path.commonprefix(
            [os.path.abspath(params.input[0]), common_pfx])
        if new_common_pfx not in ("", "."):
            input_base = new_common_pfx

    # Generate subfolder paths
    paths = dict(
        obj_base=os.path.join(int_base, "image_objects"),
        fin_base=os.path.join(int_base, "final"),
        log_base=os.path.join(int_base, "logs"),
        dials_log_base=os.path.join(int_base, "logs/dials_logs"),
        viz_base=os.path.join(int_base, "visualization"),
        tmp_base=os.path.join(int_base, "tmp"),
        input_base=input_base,
    )
    for bkey, bvalue in paths.items():
        if bkey == "input_base":
            continue
        if not os.path.isdir(bvalue):
            os.makedirs(bvalue)
    info.update(paths)

    # Generate filepaths for various info files
    info_files = dict(
        obj_list_file=os.path.join(info.tmp_base, "finished_objects.lst"),
        idx_file=os.path.join(info.int_base, "observations.pickle"),
    )
    info.update(info_files)

    # Initialize stat containers
    info = generate_stat_containers(info=info, params=params)

    # Initialize main log
    util.main_log(info.logfile, "{:*^80} \n".format(" IOTA MAIN LOG "))
    util.main_log(info.logfile, "{:-^80} \n".format(" SETTINGS FOR THIS RUN "))
    util.main_log(info.logfile, info.iota_phil)
    util.main_log(info.logfile, "{:-^80} \n".format("BACKEND SETTINGS"))
    util.main_log(info.logfile, info.target_phil)

    info.export_json()

    return info, params