Exemplo n.º 1
0
def load_cxi_phil(path, args=[]):
    import os
    from labelit.phil_preferences import iotbx_defs, libtbx_defs
    from iotbx import phil
    from libtbx.phil.command_line import argument_interpreter
    from libtbx.utils import Sorry

    exts = ["", ".params", ".phil"]
    foundIt = False
    for ext in exts:
        if os.path.exists(path + ext):
            foundIt = True
            path += ext
            break
    if not foundIt:
        raise Sorry("Target not found: " + path)

    master_phil = phil.parse(input_string=iotbx_defs + libtbx_defs,
                             process_includes=True)

    horizons_phil = master_phil.fetch(
        sources=[phil.parse(file_name=path, process_includes=True)])

    argument_interpreter = argument_interpreter(master_phil=master_phil)
    consume = []
    for arg in args:
        try:
            command_line_params = argument_interpreter.process(arg=arg)
            horizons_phil = horizons_phil.fetch(sources=[
                command_line_params,
            ])
            consume.append(arg)

        except Sorry, e:
            pass
Exemplo n.º 2
0
def process_input(args, phil_args, input_file, mode='auto', now=None):
    """ Read and parse parameter file

      input: input_file_list - PHIL-format files w/ parameters

      output: params - PHIL-formatted parameters
              txt_output - plain text-formatted parameters
  """

    from libtbx.phil.command_line import argument_interpreter
    from libtbx.utils import Sorry

    if mode == 'file':
        user_phil = [ip.parse(open(inp).read()) for inp in [input_file]]
        working_phil = master_phil.fetch(sources=user_phil)
        params = working_phil.extract()
    elif mode == 'auto':
        params = master_phil.extract()
        params.description = 'IOTA parameters auto-generated on {}'.format(now)
        params.input = [input_file]

    final_phil = master_phil.format(python_object=params)

    # Parse in-line params into phil
    argument_interpreter = argument_interpreter(master_phil=master_phil)
    consume = []
    for arg in phil_args:
        try:
            command_line_params = argument_interpreter.process(arg=arg)
            final_phil = final_phil.fetch(sources=[
                command_line_params,
            ])
            consume.append(arg)
        except Sorry, e:
            pass
Exemplo n.º 3
0
def get_input_phil(paramfile=None, phil_args=None, ha14=False, gui=False):
    """Generate PHIL from file, master, and/or command arguments.

    :param args: command line arguments
    :param phil_args: PHIL settings as command line arguments
    :param paramfile: file with input settings in PHIL format
    :return:
    """
    from libtbx.phil.command_line import argument_interpreter
    from libtbx.utils import Sorry

    # Depending on mode, either read input from file, or generate defaults
    if paramfile:
        with open(paramfile, "r") as inpf:
            user_phil = ip.parse(inpf.read())
        phil_fixer = PHILFixer()
        working_phil = phil_fixer.run(old_phil=user_phil, write_file=True)

    else:
        if ha14:
            from iota.etc.iota_cctbx_ha14 import ha14_str

            working_phil = ip.parse(master_phil_str + ha14_str,
                                    process_includes=True)
        else:
            working_phil = master_phil

    if gui:
        from libtbx.phil import find_scope

        if not find_scope(working_phil, "gui"):
            from iota.gui.base import gui_phil

            working_phil.adopt_scope(gui_phil)

    # Parse in-line params into phil
    bad_args = []
    if phil_args:
        argument_interpreter = argument_interpreter(master_phil=working_phil)
        for arg in phil_args:
            try:
                command_line_params = argument_interpreter.process(arg=arg)
                working_phil = working_phil.fetch(
                    sources=[command_line_params])
            except Sorry:
                bad_args.append(arg)

    # Self-fetch to resolve variables
    working_phil = working_phil.fetch(source=working_phil)

    return working_phil, bad_args
Exemplo n.º 4
0
  def merge_command_line(self,args):

    from libtbx.phil.command_line import argument_interpreter

    argument_interpreter = argument_interpreter(
      master_phil=phil_preferences.effective_param_generator.master(),
    )
    consume = []
    for arg in args:

      try:
        command_line_params = argument_interpreter.process(
          arg=arg
        )
        self.phil_scope = self.phil_scope.fetch(sources=[command_line_params,])
        consume.append(arg)

      except Sorry,e:
        pass
Exemplo n.º 5
0
def process_input(args,
                  phil_args,
                  input_file,
                  mode='auto',
                  now=None):
  """ Read and parse parameter file

      input: input_file_list - PHIL-format files w/ parameters

      output: params - PHIL-formatted parameters
              txt_output - plain text-formatted parameters
  """

  from libtbx.phil.command_line import argument_interpreter
  from libtbx.utils import Sorry

  if mode == 'file':
    user_phil = [ip.parse(open(inp).read()) for inp in [input_file]]
    working_phil = master_phil.fetch(sources=user_phil)
    params = working_phil.extract()
  elif mode == 'auto':
    params = master_phil.extract()
    params.description = 'IOTA parameters auto-generated on {}'.format(now)
    params.input = [input_file]
    if params.advanced.integrate_with == 'dials':
      params.dials.target = 'dials.phil'
    elif params.advanced.integrate_with == 'cctbx':
      params.cctbx.target = 'cctbx.phil'

  final_phil = master_phil.format(python_object=params)

  # Parse in-line params into phil
  argument_interpreter = argument_interpreter(master_phil=master_phil)
  consume = []
  for arg in phil_args:
    try:
      command_line_params = argument_interpreter.process(arg=arg)
      final_phil = final_phil.fetch(sources=[command_line_params,])
      consume.append(arg)
    except Sorry,e:
      pass
Exemplo n.º 6
0
    def merge_command_line(self, args):

        from libtbx.phil.command_line import argument_interpreter

        argument_interpreter = argument_interpreter(
            master_phil=phil_preferences.effective_param_generator.master(), )
        consume = []
        for arg in args:

            try:
                command_line_params = argument_interpreter.process(arg=arg)
                self.phil_scope = self.phil_scope.fetch(sources=[
                    command_line_params,
                ])
                consume.append(arg)

            except Sorry as e:
                pass

        for item in consume:
            args.remove(item)

        self.new_scope_extract()
Exemplo n.º 7
0
def load_cxi_phil(path, args=[]):
  import os
  from labelit.phil_preferences import iotbx_defs, libtbx_defs
  from iotbx import phil
  from libtbx.phil.command_line import argument_interpreter
  from libtbx.utils import Sorry

  exts = ["", ".params", ".phil"]
  foundIt = False
  for ext in exts:
    if os.path.exists(path + ext):
      foundIt = True
      path += ext
      break
  if not foundIt:
    raise Sorry("Target not found: " + path)

  master_phil = phil.parse(input_string=iotbx_defs + libtbx_defs,
                           process_includes=True)

  horizons_phil = master_phil.fetch(
    sources=[phil.parse(file_name=path, process_includes=True)])

  argument_interpreter = argument_interpreter(
    master_phil=master_phil
  )
  consume = []
  for arg in args:
    try:
      command_line_params = argument_interpreter.process(
        arg=arg
      )
      horizons_phil = horizons_phil.fetch(sources=[command_line_params,])
      consume.append(arg)

    except Sorry,e:
      pass
Exemplo n.º 8
0
def process_input(args,
                  phil_args,
                  input_file,
                  mode='auto',
                  now=None):
  """ Read and parse parameter file and/or command-line args; if none found,
  create a default parameter object

  :param args: command-line arguments upon launch
  :param phil_args: command-line arguments pertaining to IOTA parameters
  :param input_file: text file with IOTA parameters
  :param mode: Mode of XtermIOTA run. See the InitAll base class
  :param now: date / time stamp
  :return: PHIL-formatted parameters
  """

  from libtbx.phil.command_line import argument_interpreter
  from libtbx.utils import Sorry

  # Depending on mode, either read input from file, or generate defaults
  if mode == 'file':
    user_phil = [ip.parse(open(inp).read()) for inp in [input_file]]
    working_phil = master_phil.fetch(sources=user_phil)
  else:
    working_phil = master_phil

  # Parse in-line params into phil
  argument_interpreter = argument_interpreter(master_phil=master_phil)
  consume = []
  for arg in phil_args:
    try:
      command_line_params = argument_interpreter.process(arg=arg)
      working_phil = working_phil.fetch(sources=[command_line_params,])
      consume.append(arg)
    except Sorry,e:
      pass
Exemplo n.º 9
0
def process_input(args,
                  phil_args,
                  input_file,
                  mode='auto',
                  now=None):
  """ Read and parse parameter file

      input: input_file_list - PHIL-format files w/ parameters

      output: params - PHIL-formatted parameters
              txt_output - plain text-formatted parameters
  """

  from libtbx.phil.command_line import argument_interpreter
  from libtbx.utils import Sorry

  if mode == 'file':
    user_phil = [ip.parse(open(inp).read()) for inp in [input_file]]
    working_phil = master_phil.fetch(sources=user_phil)
    params = working_phil.extract()
  elif mode == 'auto':
    params = master_phil.extract()
    params.description = 'IOTA parameters auto-generated on {}'.format(now)
    params.input = [input_file]

  final_phil = master_phil.format(python_object=params)

  # Parse in-line params into phil
  argument_interpreter = argument_interpreter(master_phil=master_phil)
  consume = []
  for arg in phil_args:
    try:
      command_line_params = argument_interpreter.process(arg=arg)
      final_phil = final_phil.fetch(sources=[command_line_params,])
      consume.append(arg)
    except Sorry as e:
      pass
  for item in consume:
    phil_args.remove(item)
  if len(phil_args) > 0:
    raise Sorry("Not all arguments processed, remaining: {}".format(phil_args))

  # Perform command line check and modify params accordingly
  params = final_phil.extract()

  if mode == 'auto':
    output_dir = os.path.abspath(os.curdir)
    if params.advanced.integrate_with == 'dials':
      params.dials.target = os.path.join(output_dir, 'dials.phil')
    elif params.advanced.integrate_with == 'cctbx':
      params.cctbx.target = os.path.join(output_dir, 'cctbx.phil')

  # Check for -r option and set random subset parameter
  if args.random > 0:
    params.advanced.random_sample.flag_on = True
    params.advanced.random_sample.number = args.random[0]

  # Check for -n option and set number of processors override
  # (for parallel map only, for now)
  if args.nproc > 0:
    params.n_processors = args.nproc[0]

  # Check for -c option and set flags to exit IOTA after raw image conversion
  if args.convert:
    params.image_conversion.convert_only = True

  # Check -p option to see if converted file prefix is supplied; will run
  # conversion automatically if prefix is supplied
  if str(args.prefix).lower() != "auto":
    params.image_conversion.convert_images = True
    params.image_conversion.rename_pickle_prefix = args.prefix

  #Check -s option to bypass grid search and run selection/integration only
  if args.select:
    params.cctbx.selection.select_only.flag_on = True

  # Check if grid search is turned off; if so, set everything to zero
  if str(params.cctbx.grid_search.type).lower() == 'none':
    params.cctbx.grid_search.area_range = 0
    params.cctbx.grid_search.height_range = 0
    params.cctbx.grid_search.sig_height_search = False

  final_phil = master_phil.format(python_object=params)

  temp_phil = [final_phil]
  #diff_phil = master_phil.fetch_diff(sources=temp_phil)
  diff_phil = master_phil.fetch(sources=temp_phil)

  with Capturing() as output:
    diff_phil.show()
  diff_out = ''
  for one_output in output:
    diff_out += one_output + '\n'

  if mode == 'auto':
    with Capturing() as diff_output:
      final_phil.show()
    txt_out = ''
    for one_output in diff_output:
      txt_out += one_output + '\n'
    write_defaults(os.path.abspath(os.curdir), txt_out, params.advanced.integrate_with)

  return params, diff_out
Exemplo n.º 10
0
def load_cxi_phil(path, args=[]):
    import os
    from labelit.phil_preferences import iotbx_defs, libtbx_defs
    from iotbx import phil
    from libtbx.phil.command_line import argument_interpreter
    from libtbx.utils import Sorry

    exts = ["", ".params", ".phil"]
    foundIt = False
    for ext in exts:
        if os.path.exists(path + ext):
            foundIt = True
            path += ext
            break
    if not foundIt:
        raise Sorry("Target not found: " + path)

    master_phil = phil.parse(input_string=iotbx_defs + libtbx_defs,
                             process_includes=True)

    horizons_phil = master_phil.fetch(
        sources=[phil.parse(file_name=path, process_includes=True)])

    argument_interpreter = argument_interpreter(master_phil=master_phil)
    consume = []
    for arg in args:
        try:
            command_line_params = argument_interpreter.process(arg=arg)
            horizons_phil = horizons_phil.fetch(sources=[
                command_line_params,
            ])
            consume.append(arg)

        except Sorry as e:
            pass

    for item in consume:
        args.remove(item)

    if len(args) > 0:
        raise Sorry("Not all arguments processed")

    params = horizons_phil.extract()
    if params.distl.tile_translations is not None and params.distl.quad_translations is not None:
        return params

    from spotfinder.applications.xfel.cxi_phil import cxi_versioned_extract
    args = [
        "distl.detector_format_version=%s" %
        params.distl.detector_format_version
    ]

    versioned_extract = cxi_versioned_extract(args).persist.commands

    if params.distl.quad_translations is None:
        params.distl.quad_translations = versioned_extract.distl.quad_translations

    if params.distl.tile_translations is None:
        params.distl.tile_translations = versioned_extract.distl.tile_translations

    return params