示例#1
0
def run(args,
        log=None,
        ccp4_map=None,
        return_as_miller_arrays=False,
        nohl=False,
        return_f_obs=False,
        space_group_number=None,
        out=sys.stdout):
    if log is None: log = out
    inputs = mmtbx.utils.process_command_line_args(
        args=args, master_params=master_params())
    got_map = False
    if ccp4_map: got_map = True
    broadcast(m="Parameters:", log=log)
    inputs.params.show(prefix="  ", out=out)
    params = inputs.params.extract()
    if (ccp4_map is None and inputs.ccp4_map is not None):
        broadcast(m="Processing input CCP4 map file: %s" %
                  inputs.ccp4_map_file_name,
                  log=log)
        ccp4_map = inputs.ccp4_map
        ccp4_map.show_summary(prefix="  ", out=out)
        got_map = True
    if (not got_map):
        raise Sorry("Map file is needed.")
    #
    m = ccp4_map
    if (m.space_group_number > 1):
        raise Sorry("Input map space group: %d. Must be P1." %
                    m.space_group_number)
    broadcast(m="Input map information:", log=log)
    print("m.all()   :", m.data.all(), file=out)
    print("m.focus() :", m.data.focus(), file=out)
    print("m.origin():", m.data.origin(), file=out)
    print("m.nd()    :", m.data.nd(), file=out)
    print("m.size()  :", m.data.size(), file=out)
    print("m.focus_size_1d():", m.data.focus_size_1d(), file=out)
    print("m.is_0_based()   :", m.data.is_0_based(), file=out)
    print("map: min/max/mean:",
          flex.min(m.data),
          flex.max(m.data),
          flex.mean(m.data),
          file=out)
    print("unit cell:", m.unit_cell_parameters, file=out)
    #
    if not space_group_number:
        space_group_number = 1
    if space_group_number <= 1:
        symmetry_flags = None
    else:
        symmetry_flags = maptbx.use_space_group_symmetry,

    #cs = crystal.symmetry(m.unit_cell_parameters, space_group_number)
    # this will not work if m.unit_cell_grid != m.data.all()

    # Instead use ccp4 map crystal_symmetry and classify according to the case
    cs = m.crystal_symmetry()

    if m.unit_cell_grid == m.data.all():
        print("\nOne unit cell of data is present in map", file=out)
    else:
        if params.keep_origin:
            print("\nNOTE: This map does not have exactly one unit cell of data, so \n"+\
              "keep_origin is not available\n", file=out)
            print(
                "--> Setting keep_origin=False and creating a new cell and gridding.\n",
                file=out)
            params.keep_origin = False
        print("Moving origin of input map to (0,0,0)", file=out)
        print("New cell will be: (%.3f, %.3f, %.3f, %.1f, %.1f, %.1f) A " %
              (cs.unit_cell().parameters()),
              file=out)
        print("New unit cell grid will be: (%s, %s, %s) " % (m.data.all()),
              file=out)

    map_data = m.data

    # Get origin in grid units and new position of origin in grid units
    original_origin = map_data.origin()
    print("\nInput map has origin at grid point (%s,%s,%s)" %
          (tuple(original_origin)),
          file=out)

    if params.output_origin_grid_units is not None:
        params.keep_origin = False
        new_origin = tuple(params.output_origin_grid_units)
        print("User-specified origin at grid point (%s,%s,%s)" %
              (tuple(params.output_origin_grid_units)),
              file=out)
        if tuple(params.output_origin_grid_units) == tuple(original_origin):
            print("This is the same as the input origin. No origin shift.",
                  file=out)
    elif params.keep_origin:
        new_origin = original_origin
        print("Keeping origin at grid point  (%s,%s,%s)" %
              (tuple(original_origin)),
              file=out)
    else:
        new_origin = (
            0,
            0,
            0,
        )
        print("New origin at grid point (%s,%s,%s)" % (tuple((
            0,
            0,
            0,
        ))),
              file=out)

    # shift_cart is shift away from (0,0,0)
    if new_origin != (
            0,
            0,
            0,
    ):
        shift_cart = get_shift_cart(map_data=map_data,
                                    crystal_symmetry=cs,
                                    origin=new_origin)
    else:
        shift_cart = (
            0,
            0,
            0,
        )

    map_data = maptbx.shift_origin_if_needed(map_data=map_data).map_data
    # generate complete set of Miller indices up to given high resolution d_min
    n_real = map_data.focus()
    crystal_gridding = maptbx.crystal_gridding(
        unit_cell=cs.unit_cell(),
        space_group_info=cs.space_group_info(),
        symmetry_flags=symmetry_flags,
        pre_determined_n_real=n_real)
    #
    d_min = params.d_min
    if (d_min is None and not params.box):
        d_min = maptbx.d_min_from_map(
            map_data=map_data,
            unit_cell=cs.unit_cell(),
            resolution_factor=params.resolution_factor)
        print("\nResolution of map coefficients using "+\
           "resolution_factor of %.2f: %.1f A\n" %(params.resolution_factor,d_min), file=out)
    if (d_min is None):
        # box of reflections in |h|<N1/2, |k|<N2/2, 0<=|l|<N3/2
        f_obs_cmpl = miller.structure_factor_box_from_map(
            map=map_data.as_double(), crystal_symmetry=cs, include_000=True)
    else:
        complete_set = miller.build_set(crystal_symmetry=cs,
                                        anomalous_flag=False,
                                        d_min=d_min)
        try:
            f_obs_cmpl = complete_set.structure_factors_from_map(
                map=map_data.as_double(),
                use_scale=True,
                anomalous_flag=False,
                use_sg=False)
        except Exception as e:
            if (str(e) ==
                    "cctbx Error: Miller index not in structure factor map."):
                msg = "Too high resolution requested. Try running with larger d_min."
                raise Sorry(msg)
            else:
                raise Sorry(str(e))

    if params.scale_max is not None:
        f_obs_cmpl = f_obs_cmpl.apply_scaling(target_max=params.scale_max)

    from scitbx.matrix import col
    if col(shift_cart) != col((
            0,
            0,
            0,
    )):
        print("Output origin is at: (%.3f, %.3f, %.3f) A " %
              (tuple(-col(shift_cart))),
              file=out)
        f_obs_cmpl = f_obs_cmpl.translational_shift(
            cs.unit_cell().fractionalize(-col(shift_cart)), deg=False)
    else:
        print("Output origin is at (0.000, 0.000, 0.000) A", file=out)

    if nohl and return_as_miller_arrays and not return_f_obs:
        return f_obs_cmpl

    mtz_dataset = f_obs_cmpl.as_mtz_dataset(column_root_label="F")
    f_obs = abs(f_obs_cmpl)
    f_obs.set_sigmas(sigmas=flex.double(f_obs_cmpl.data().size(), 1))
    if nohl and return_as_miller_arrays and return_f_obs:
        return f_obs
    mtz_dataset.add_miller_array(miller_array=f_obs, column_root_label="F-obs")
    mtz_dataset.add_miller_array(miller_array=f_obs.generate_r_free_flags(),
                                 column_root_label="R-free-flags")
    if not nohl:
        # convert phases into HL coefficeints
        broadcast(m="Convert phases into HL coefficients:", log=log)
        hl = get_hl(f_obs_cmpl=f_obs_cmpl,
                    k_blur=params.k_blur,
                    b_blur=params.b_blur)
        cc = get_cc(f=f_obs_cmpl, hl=hl)
        print("cc:", cc, file=out)
        if (abs(1. - cc) > 1.e-3):
            print(
                "Supplied b_blur is not good. Attempting to find optimal b_blur.",
                file=out)
            cc_best = 999.
            b_blur_best = params.b_blur
            for b_blur in range(1, 100):
                hl = get_hl(f_obs_cmpl=f_obs_cmpl,
                            k_blur=params.k_blur,
                            b_blur=b_blur)
                cc = get_cc(f=f_obs_cmpl, hl=hl)
                if (cc < cc_best):
                    cc_best = cc
                    b_blur_best = b_blur
                if (abs(1. - cc) < 1.e-3):
                    b_blur_best = b_blur
                    break
            hl = get_hl(f_obs_cmpl=f_obs_cmpl,
                        k_blur=params.k_blur,
                        b_blur=b_blur_best)
            print("cc:", get_cc(f=f_obs_cmpl, hl=hl), file=out)
            print("b_blur_best:", b_blur_best, file=out)
        mtz_dataset.add_miller_array(miller_array=hl, column_root_label="HL")
    else:
        hl = None
    if return_as_miller_arrays:
        if return_f_obs:
            return f_obs, hl
        else:
            return f_obs_cmpl, hl
    else:
        # write output MTZ file with all the data
        broadcast(m="Writing output MTZ file:", log=log)
        print("  file name:", params.output_file_name, file=log)
        mtz_object = mtz_dataset.mtz_object()
        mtz_object.write(file_name=params.output_file_name)
def run(args,
        log=None,
        ccp4_map=None,
        return_as_miller_arrays=False,
        nohl=False,
        return_f_obs=False,
        space_group_number=None,
        out=sys.stdout):
    if log is None: log = out
    inputs = mmtbx.utils.process_command_line_args(
        args=args, master_params=master_params())
    got_map = False
    if ccp4_map: got_map = True
    broadcast(m="Parameters:", log=log)
    inputs.params.show(prefix="  ", out=out)
    params = inputs.params.extract()
    if (ccp4_map is None and inputs.ccp4_map is not None):
        broadcast(m="Processing input CCP4 map file: %s" %
                  inputs.ccp4_map_file_name,
                  log=log)
        ccp4_map = inputs.ccp4_map
        ccp4_map.show_summary(prefix="  ", out=out)
        got_map = True
    if (not got_map):
        raise Sorry("Map file is needed.")
    #
    m = ccp4_map
    if (m.space_group_number > 1):
        raise Sorry("Input map space group: %d. Must be P1." %
                    m.space_group_number)
    broadcast(m="Input map information:", log=log)
    print >> out, "m.all()   :", m.data.all()
    print >> out, "m.focus() :", m.data.focus()
    print >> out, "m.origin():", m.data.origin()
    print >> out, "m.nd()    :", m.data.nd()
    print >> out, "m.size()  :", m.data.size()
    print >> out, "m.focus_size_1d():", m.data.focus_size_1d()
    print >> out, "m.is_0_based()   :", m.data.is_0_based()
    print >> out, "map: min/max/mean:", flex.min(m.data), flex.max(
        m.data), flex.mean(m.data)
    print >> out, "unit cell:", m.unit_cell_parameters
    #
    if not space_group_number:
        space_group_number = 1
    if space_group_number <= 1:
        symmetry_flags = None
    else:
        symmetry_flags = maptbx.use_space_group_symmetry,

    cs = crystal.symmetry(m.unit_cell_parameters, space_group_number)
    map_data = m.data

    # Get origin in grid units and new position of origin in grid units
    original_origin = map_data.origin()
    print >> out, "Input map has origin at grid point (%s,%s,%s)" % (
        tuple(original_origin))

    if params.output_origin_grid_units is not None:
        params.keep_origin = False
        new_origin = tuple(params.output_origin_grid_units)
        print >> out, "User-specified origin at grid point (%s,%s,%s)" % (
            tuple(params.output_origin_grid_units))
        if tuple(params.output_origin_grid_units) == tuple(original_origin):
            print >> out, "This is the same as the input origin. No origin shift."
    elif params.keep_origin:
        new_origin = original_origin
        print >> out, "Keeping origin at grid point  (%s,%s,%s)" % (
            tuple(original_origin))
    else:
        new_origin = (
            0,
            0,
            0,
        )
        print >> out, "New origin at grid point (%s,%s,%s)" % (tuple((
            0,
            0,
            0,
        )))

    # shift_cart is shift away from (0,0,0)
    if new_origin != (
            0,
            0,
            0,
    ):
        shift_cart = get_shift_cart(map_data=map_data,
                                    crystal_symmetry=cs,
                                    origin=new_origin)
    else:
        shift_cart = (
            0,
            0,
            0,
        )

    map_data = maptbx.shift_origin_if_needed(map_data=map_data).map_data
    # generate complete set of Miller indices up to given high resolution d_min
    n_real = map_data.focus()
    crystal_gridding = maptbx.crystal_gridding(
        unit_cell=cs.unit_cell(),
        space_group_info=cs.space_group_info(),
        symmetry_flags=symmetry_flags,
        pre_determined_n_real=n_real)
    #
    d_min = params.d_min
    if (d_min is None and not params.box):
        d_min = maptbx.d_min_from_map(map_data=map_data,
                                      unit_cell=cs.unit_cell())
    if (d_min is None):
        # box of reflections in |h|<N1/2, |k|<N2/2, 0<=|l|<N3/2
        f_obs_cmpl = miller.structure_factor_box_from_map(
            map=map_data.as_double(), crystal_symmetry=cs, include_000=True)
    else:
        complete_set = miller.build_set(crystal_symmetry=cs,
                                        anomalous_flag=False,
                                        d_min=d_min)
        try:
            f_obs_cmpl = complete_set.structure_factors_from_map(
                map=map_data.as_double(),
                use_scale=True,
                anomalous_flag=False,
                use_sg=False)
        except Exception, e:
            if (str(e) ==
                    "cctbx Error: Miller index not in structure factor map."):
                msg = "Too high resolution requested. Try running with larger d_min."
                raise Sorry(msg)
            else:
                raise Sorry(str(e))
def run(args, log=None, ccp4_map=None, return_as_miller_arrays=False, nohl=False,
    out=sys.stdout):
  if log is None: log=out

  inputs = mmtbx.utils.process_command_line_args(args = args,
    master_params = master_params())
  got_map = False
  if ccp4_map: got_map=True
  broadcast(m="Parameters:", log=log)
  inputs.params.show(prefix="  ",out=out)
  params = inputs.params.extract()
  if(ccp4_map is None and inputs.ccp4_map is not None):
    broadcast(m="Processing input CCP4 map file: %s"%inputs.ccp4_map_file_name,
      log=log)
    ccp4_map = inputs.ccp4_map
    ccp4_map.show_summary(prefix="  ",out=out)
    got_map = True
  if(not got_map):
    raise Sorry("Map file is needed.")
  #
  m = ccp4_map
  broadcast(m="Input map information:", log=log)
  print >>out,"m.all()   :", m.data.all()
  print >>out,"m.focus() :", m.data.focus()
  print >>out,"m.origin():", m.data.origin()
  print >>out,"m.nd()    :", m.data.nd()
  print >>out,"m.size()  :", m.data.size()
  print >>out,"m.focus_size_1d():", m.data.focus_size_1d()
  print >>out,"m.is_0_based()   :", m.data.is_0_based()
  print >>out,"map: min/max/mean:", flex.min(m.data), flex.max(m.data), flex.mean(m.data)
  print >>out,"unit cell:", m.unit_cell_parameters
  #
  map_data=m.data
  shift_needed = not \
     (map_data.focus_size_1d() > 0 and map_data.nd() == 3 and
      map_data.is_0_based())
  if(shift_needed):
    map_data = map_data.shift_origin()

  # generate complete set of Miller indices up to given high resolution d_min
  n_real = map_data.focus()
  cs = crystal.symmetry(m.unit_cell_parameters, 1)
  crystal_gridding = maptbx.crystal_gridding(
    unit_cell         = cs.unit_cell(),
    space_group_info  = cs.space_group_info(),
    #symmetry_flags     = maptbx.use_space_group_symmetry,
    pre_determined_n_real = n_real)
  #
  d_min = params.d_min
  if(d_min is None and not params.box):
    d_min = maptbx.d_min_from_map(
      map_data  = map_data,
      unit_cell = cs.unit_cell())
  if(d_min is None):
    # box of reflections in |h|<N1/2, |k|<N2/2, 0<=|l|<N3/2
    max_index = [(i-1)//2 for i in n_real]
    print >>out,"max_index:", max_index
    complete_set = miller.build_set(
      crystal_symmetry = cs,
      anomalous_flag   = False,
      max_index        = max_index)
    indices = complete_set.indices()
    indices.append((0,0,0))
    complete_set = complete_set.customized_copy(indices = indices)
    #if(not params.box):
    #  # XXX What is sphere resolution corresponding to given box?
    #  uc = complete_set.unit_cell()
    #  d1 = uc.d([0,0,max_index[2]])
    #  d2 = uc.d([0,max_index[1],0])
    #  d3 = uc.d([max_index[0],1,0])
    #  print >>out, d1,d2,d3
    #  complete_set_sp = miller.build_set(
    #    crystal_symmetry = cs,
    #    anomalous_flag   = False,
    #    d_min            = min(d1,d2,d3))
    #  complete_set = complete_set.common_set(complete_set_sp)
  else:
    complete_set = miller.build_set(
      crystal_symmetry = cs,
      anomalous_flag   = False,
      d_min            = d_min)
  broadcast(m="Complete set information:", log=log)
  complete_set.show_comprehensive_summary(prefix="  ",f=out)
  try:
    f_obs_cmpl = complete_set.structure_factors_from_map(
      map            = map_data.as_double(),
      use_scale      = True,
      anomalous_flag = False,
      use_sg         = False)
  except Exception, e:
    if(str(e) == "cctbx Error: Miller index not in structure factor map."):
      msg = "Too high resolution requested. Try running with larger d_min."
      raise Sorry(msg)
    else:
      raise Sorry(str(e))
示例#4
0
def run(args,
        log=None,
        ccp4_map=None,
        return_as_miller_arrays=False,
        nohl=False,
        return_f_obs=False,
        space_group_number=None,
        out=sys.stdout):
    if log is None: log = out
    inputs = mmtbx.utils.process_command_line_args(
        args=args, master_params=master_params())
    got_map = False
    if ccp4_map: got_map = True
    broadcast(m="Parameters:", log=log)
    inputs.params.show(prefix="  ", out=out)
    params = inputs.params.extract()
    if (ccp4_map is None and inputs.ccp4_map is not None):
        broadcast(m="Processing input CCP4 map file: %s" %
                  inputs.ccp4_map_file_name,
                  log=log)
        ccp4_map = inputs.ccp4_map
        ccp4_map.show_summary(prefix="  ", out=out)
        got_map = True
    if (not got_map):
        raise Sorry("Map file is needed.")
    #
    m = ccp4_map
    if (m.unit_cell_crystal_symmetry().space_group_number() > 1):
        raise Sorry("Input map space group: %d. Must be P1." %
                    m.unit_cell_crystal_symmetry().space_group_number())
    broadcast(m="Input map information:", log=log)
    print("m.all()   :", m.map_data().all(), file=out)
    print("m.focus() :", m.map_data().focus(), file=out)
    print("m.origin():", m.map_data().origin(), file=out)
    print("m.nd()    :", m.map_data().nd(), file=out)
    print("m.size()  :", m.map_data().size(), file=out)
    print("m.focus_size_1d():", m.map_data().focus_size_1d(), file=out)
    print("m.is_0_based()   :", m.map_data().is_0_based(), file=out)
    print("map: min/max/mean:",
          flex.min(m.map_data()),
          flex.max(m.map_data()),
          flex.mean(m.map_data()),
          file=out)
    print("unit cell:", m.unit_cell().parameters(), file=out)
    #

    # Instead use ccp4 map crystal_symmetry and classify according to the case
    cs = m.crystal_symmetry()

    if m.unit_cell_grid == m.map_data().all():
        print("\nOne unit cell of data is present in map", file=out)
    else:
        if params.keep_origin:
            print("\nNOTE: This map does not have exactly one unit cell of data, so \n"+\
              "keep_origin is not available\n", file=out)
            print(
                "--> Setting keep_origin=False and creating a new cell and gridding.\n",
                file=out)
            params.keep_origin = False
        print("Moving origin of input map to (0,0,0)", file=out)
        print("New cell will be: (%.3f, %.3f, %.3f, %.1f, %.1f, %.1f) A " %
              (cs.unit_cell().parameters()),
              file=out)
        print("New unit cell grid will be: (%s, %s, %s) " %
              (m.map_data().all()),
              file=out)

    map_data = m.map_data()

    # Get origin in grid units and new position of origin in grid units
    original_origin = map_data.origin()
    print("\nInput map has origin at grid point (%s,%s,%s)" %
          (tuple(original_origin)),
          file=out)

    if params.output_origin_grid_units is not None:
        params.keep_origin = False
        new_origin = tuple(params.output_origin_grid_units)
        print("User-specified origin at grid point (%s,%s,%s)" %
              (tuple(params.output_origin_grid_units)),
              file=out)
        if tuple(params.output_origin_grid_units) == tuple(original_origin):
            print("This is the same as the input origin. No origin shift.",
                  file=out)
    elif params.keep_origin:
        new_origin = original_origin
        print("Keeping origin at grid point  (%s,%s,%s)" %
              (tuple(original_origin)),
              file=out)
    else:
        new_origin = (
            0,
            0,
            0,
        )
        print("New origin at grid point (%s,%s,%s)" % (tuple((
            0,
            0,
            0,
        ))),
              file=out)

    # shift_cart is shift away from (0,0,0)
    if new_origin != (
            0,
            0,
            0,
    ):
        shift_cart = get_shift_cart(map_data=map_data,
                                    crystal_symmetry=cs,
                                    origin=new_origin)
    else:
        shift_cart = (
            0,
            0,
            0,
        )
    d_min = params.d_min
    box = params.box
    resolution_factor = params.resolution_factor

    # Shift the map data if necessary
    map_data = maptbx.shift_origin_if_needed(map_data=map_data).map_data

    f_obs_cmpl = calculate_inverse_fft(
        map_data=map_data,
        crystal_symmetry=cs,
        d_min=params.d_min,
        box=params.box,
        resolution_factor=params.resolution_factor,
        out=out)

    if params.scale_max is not None:
        f_obs_cmpl = f_obs_cmpl.apply_scaling(target_max=params.scale_max)

    from scitbx.matrix import col
    if col(shift_cart) != col((
            0,
            0,
            0,
    )):
        print("Output origin is at: (%.3f, %.3f, %.3f) A " %
              (tuple(-col(shift_cart))),
              file=out)
        f_obs_cmpl = f_obs_cmpl.translational_shift(
            cs.unit_cell().fractionalize(-col(shift_cart)), deg=False)
    else:
        print("Output origin is at (0.000, 0.000, 0.000) A", file=out)

    if nohl and return_as_miller_arrays and not return_f_obs:
        return f_obs_cmpl

    mtz_dataset = f_obs_cmpl.as_mtz_dataset(column_root_label="F")
    f_obs = abs(f_obs_cmpl)
    f_obs.set_sigmas(sigmas=flex.double(f_obs_cmpl.data().size(), 1))
    if nohl and return_as_miller_arrays and return_f_obs:
        return f_obs
    mtz_dataset.add_miller_array(miller_array=f_obs, column_root_label="F-obs")
    mtz_dataset.add_miller_array(miller_array=f_obs.generate_r_free_flags(),
                                 column_root_label="R-free-flags")
    if not nohl and params.k_blur is not None and params.b_blur is None:
        # convert phases into HL coefficeints
        broadcast(m="Convert phases into HL coefficients:", log=log)
        hl = get_hl(f_obs_cmpl=f_obs_cmpl,
                    k_blur=params.k_blur,
                    b_blur=params.b_blur)
        cc = get_cc(f=f_obs_cmpl, hl=hl)
        print("cc:", cc, file=out)
        if (abs(1. - cc) > 1.e-3):
            print(
                "Supplied b_blur is not good. Attempting to find optimal b_blur.",
                file=out)
            cc_best = 999.
            b_blur_best = params.b_blur
            for b_blur in range(1, 100):
                hl = get_hl(f_obs_cmpl=f_obs_cmpl,
                            k_blur=params.k_blur,
                            b_blur=b_blur)
                cc = get_cc(f=f_obs_cmpl, hl=hl)
                if (cc < cc_best):
                    cc_best = cc
                    b_blur_best = b_blur
                if (abs(1. - cc) < 1.e-3):
                    b_blur_best = b_blur
                    break
            hl = get_hl(f_obs_cmpl=f_obs_cmpl,
                        k_blur=params.k_blur,
                        b_blur=b_blur_best)
            print("cc:", get_cc(f=f_obs_cmpl, hl=hl), file=out)
            print("b_blur_best:", b_blur_best, file=out)
        mtz_dataset.add_miller_array(miller_array=hl, column_root_label="HL")
    else:
        hl = None
    if return_as_miller_arrays:
        if return_f_obs:
            return f_obs, hl
        else:
            return f_obs_cmpl, hl
    else:
        # write output MTZ file with all the data
        broadcast(m="Writing output MTZ file:", log=log)
        print("  file name:", params.output_file_name, file=log)
        mtz_object = mtz_dataset.mtz_object()
        mtz_object.write(file_name=params.output_file_name)
示例#5
0
def run(args,
        log=None,
        ccp4_map=None,
        return_as_miller_arrays=False,
        nohl=False,
        space_group_number=None,
        out=sys.stdout):
    if log is None: log = out
    inputs = mmtbx.utils.process_command_line_args(
        args=args, master_params=master_params())
    got_map = False
    if ccp4_map: got_map = True
    broadcast(m="Parameters:", log=log)
    inputs.params.show(prefix="  ", out=out)
    params = inputs.params.extract()
    if (ccp4_map is None and inputs.ccp4_map is not None):
        broadcast(m="Processing input CCP4 map file: %s" %
                  inputs.ccp4_map_file_name,
                  log=log)
        ccp4_map = inputs.ccp4_map
        ccp4_map.show_summary(prefix="  ", out=out)
        got_map = True
    if (not got_map):
        raise Sorry("Map file is needed.")
    #
    m = ccp4_map
    if (m.space_group_number > 1):
        raise Sorry("Input map space group: %d. Must be P1." %
                    m.space_group_number)
    broadcast(m="Input map information:", log=log)
    print >> out, "m.all()   :", m.data.all()
    print >> out, "m.focus() :", m.data.focus()
    print >> out, "m.origin():", m.data.origin()
    print >> out, "m.nd()    :", m.data.nd()
    print >> out, "m.size()  :", m.data.size()
    print >> out, "m.focus_size_1d():", m.data.focus_size_1d()
    print >> out, "m.is_0_based()   :", m.data.is_0_based()
    print >> out, "map: min/max/mean:", flex.min(m.data), flex.max(
        m.data), flex.mean(m.data)
    print >> out, "unit cell:", m.unit_cell_parameters
    #
    map_data = m.data
    shift_needed = not \
       (map_data.focus_size_1d() > 0 and map_data.nd() == 3 and
        map_data.is_0_based())
    if (shift_needed):
        map_data = map_data.shift_origin()

    # generate complete set of Miller indices up to given high resolution d_min
    n_real = map_data.focus()
    if not space_group_number:
        space_group_number = 1
    if space_group_number <= 1:
        symmetry_flags = None
    else:
        symmetry_flags = maptbx.use_space_group_symmetry,

    cs = crystal.symmetry(m.unit_cell_parameters, space_group_number)
    crystal_gridding = maptbx.crystal_gridding(
        unit_cell=cs.unit_cell(),
        space_group_info=cs.space_group_info(),
        symmetry_flags=symmetry_flags,
        pre_determined_n_real=n_real)
    #
    d_min = params.d_min
    if (d_min is None and not params.box):
        d_min = maptbx.d_min_from_map(map_data=map_data,
                                      unit_cell=cs.unit_cell())
    if (d_min is None):
        # box of reflections in |h|<N1/2, |k|<N2/2, 0<=|l|<N3/2
        max_index = [(i - 1) // 2 for i in n_real]
        print >> out, "max_index:", max_index
        complete_set = miller.build_set(crystal_symmetry=cs,
                                        anomalous_flag=False,
                                        max_index=max_index)
        indices = complete_set.indices()
        indices.append((0, 0, 0))
        complete_set = complete_set.customized_copy(indices=indices)
        #if(not params.box):
        #  # XXX What is sphere resolution corresponding to given box?
        #  uc = complete_set.unit_cell()
        #  d1 = uc.d([0,0,max_index[2]])
        #  d2 = uc.d([0,max_index[1],0])
        #  d3 = uc.d([max_index[0],1,0])
        #  print >>out, d1,d2,d3
        #  complete_set_sp = miller.build_set(
        #    crystal_symmetry = cs,
        #    anomalous_flag   = False,
        #    d_min            = min(d1,d2,d3))
        #  complete_set = complete_set.common_set(complete_set_sp)
    else:
        complete_set = miller.build_set(crystal_symmetry=cs,
                                        anomalous_flag=False,
                                        d_min=d_min)
    broadcast(m="Complete set information:", log=log)
    complete_set.show_comprehensive_summary(prefix="  ", f=out)
    try:
        f_obs_cmpl = complete_set.structure_factors_from_map(
            map=map_data.as_double(),
            use_scale=True,
            anomalous_flag=False,
            use_sg=False)
    except Exception, e:
        if (str(e) == "cctbx Error: Miller index not in structure factor map."
            ):
            msg = "Too high resolution requested. Try running with larger d_min."
            raise Sorry(msg)
        else:
            raise Sorry(str(e))