コード例 #1
0
def get_map_and_model(params=None,
    map_data=None,
    crystal_symmetry=None,
    pdb_inp=None,
    ncs_obj=None,
    half_map_data_list=None,
    map_coords_inside_cell=True,
    get_map_labels=None,
    out=sys.stdout):

  acc=None # accessor used to shift map back to original location if desired
  origin_frac=(0,0,0)
  map_labels=None
  if map_data and crystal_symmetry:
    original_crystal_symmetry=crystal_symmetry
    original_unit_cell_grid=None
    acc=map_data.accessor()
    shift_needed = not \
       (map_data.focus_size_1d() > 0 and map_data.nd() == 3 and
        map_data.is_0_based())
    if(shift_needed):
      origin_shift=(
        map_data.origin()[0]/map_data.all()[0],
        map_data.origin()[1]/map_data.all()[1],
        map_data.origin()[2]/map_data.all()[2])
      origin_frac=origin_shift  # NOTE: fraction of NEW cell
      map_data = map_data.shift_origin()
    else:
      origin_frac=(0.,0.,0.)

  elif params.input_files.map_file:
    print >>out,"\nReading map from %s\n" %( params.input_files.map_file)
    from cctbx.maptbx.segment_and_split_map import get_map_object
    map_data,space_group,unit_cell,crystal_symmetry,origin_frac,acc,\
        original_crystal_symmetry,original_unit_cell_grid,map_labels=\
      get_map_object(file_name=params.input_files.map_file,
      must_allow_sharpening=(not params.control.ignore_map_limitations),
      get_map_labels=True,out=out)
    map_data=map_data.as_double()
    if origin_frac != (0,0,0) and acc is None:
      print >>out,"\nWARNING: Unable to place output map at position of "+\
        "input map though input map has non-zero origin at %s\n" %(
        str(origin_frac))

  elif params.input_files.map_coeffs_file:
    map_coeffs=get_map_coeffs_from_file(
      map_coeffs_file=params.input_files.map_coeffs_file,
      map_coeffs_labels=params.input_files.map_coeffs_labels)

    if not map_coeffs:
      raise Sorry("Could not get map coeffs from %s with labels %s" %(
        params.input_files.map_coeffs_file,params.input_files.map_coeffs_labels))
    print >>out,"Map coefficients read from %s with labels %s" %(
         params.input_files.map_coeffs_file,
         str(params.input_files.map_coeffs_labels))
    crystal_symmetry=map_coeffs.crystal_symmetry()
    from cctbx.maptbx.segment_and_split_map import get_map_from_map_coeffs
    map_data=get_map_from_map_coeffs(
      map_coeffs=map_coeffs,crystal_symmetry=crystal_symmetry)
    acc=map_data.accessor()
    original_crystal_symmetry=crystal_symmetry
    original_unit_cell_grid=None
    if not params.crystal_info.resolution:
      params.crystal_info.resolution=map_coeffs.d_min()
      print >>out,"Resolution from map_coeffs is %7.2f A" %(
          params.crystal_info.resolution)
  else:
    raise Sorry("Need ccp4 map or map_coeffs")

  if params.input_files.half_map_file:
    if len(params.input_files.half_map_file) != 2:
      raise Sorry("Please supply zero or two half_map files")
    half_map_data_list=[]
    from cctbx.maptbx.segment_and_split_map import get_map_object
    for file_name in params.input_files.half_map_file:
      print >>out,"\nReading half-map from %s\n" %(file_name)
      half_map_data,half_map_space_group,half_map_unit_cell,\
        half_map_crystal_symmetry,half_map_origin_frac,half_map_acc,\
         half_map_original_crystal_symmetry,half_map_original_unit_cell_grid=\
        get_map_object(file_name=file_name,out=out)
      half_map_data=half_map_data.as_double()
      assert half_map_crystal_symmetry.is_similar_symmetry(crystal_symmetry)

      half_map_data_list.append(half_map_data)

  if params.crystal_info.resolution is None:
    raise Sorry("Need resolution if map is supplied")

  if params.crystal_info.resolution >= 10:
    print >>out,"\n** WARNING: auto_sharpen is designed for maps at a "+\
      "resolution of about 4.5 A\nor better.  Sharpening may be"+\
      "poor at %7.0f A" %(params.crystal_info.resolution)


  if params.input_files.pdb_file and not pdb_inp: # get model
    model_file=params.input_files.pdb_file
    if not os.path.isfile(model_file):
      raise Sorry("Missing the model file: %s" %(model_file))
    pdb_inp=iotbx.pdb.input(file_name=model_file)
  if pdb_inp: # XXX added 2019-05-05
    if origin_frac != (0,0,0):
      print >>out,"Shifting model by %s" %(str(origin_frac))
      from cctbx.maptbx.segment_and_split_map import \
         apply_shift_to_pdb_hierarchy
      origin_shift=crystal_symmetry.unit_cell().orthogonalize(
         (-origin_frac[0],-origin_frac[1],-origin_frac[2]))
      pdb_inp=apply_shift_to_pdb_hierarchy(
       origin_shift=origin_shift,
       crystal_symmetry=crystal_symmetry,
       pdb_hierarchy=pdb_inp.construct_hierarchy(),
       out=out).as_pdb_input()
    if map_coords_inside_cell:
      # put inside (0,1)
      pdb_inp=map_inside_cell(pdb_inp,crystal_symmetry=crystal_symmetry)

  if params.input_files.ncs_file and not ncs_obj: # NCS
    from cctbx.maptbx.segment_and_split_map import get_ncs
    ncs_obj,dummy_tracking_data=get_ncs(params,out=out)
    if origin_frac != (0,0,0):
      origin_shift=crystal_symmetry.unit_cell().orthogonalize(
         (-origin_frac[0],-origin_frac[1],-origin_frac[2]))
      print >>out,"Shifting NCS by (%7.2f,%7.2f,%7.2f) " %((origin_shift))
      from scitbx.math import  matrix
      ncs_obj=ncs_obj.coordinate_offset(
       coordinate_offset=matrix.col(origin_shift))

  if get_map_labels:
    return pdb_inp,map_data,half_map_data_list,ncs_obj,crystal_symmetry,acc,\
       original_crystal_symmetry,original_unit_cell_grid,map_labels
  else:
    return pdb_inp,map_data,half_map_data_list,ncs_obj,crystal_symmetry,acc,\
       original_crystal_symmetry,original_unit_cell_grid
コード例 #2
0
def get_map_and_model(params=None,
                      map_data=None,
                      crystal_symmetry=None,
                      pdb_inp=None,
                      ncs_obj=None,
                      half_map_data_list=None,
                      out=sys.stdout):

    acc = None  # accessor used to shift map back to original location if desired
    origin_frac = (0, 0, 0)
    acc = None
    if map_data and crystal_symmetry:
        pass  # we are set

    elif params.input_files.map_file:
        print >> out, "\nReading map from %s\n" % (params.input_files.map_file)
        from cctbx.maptbx.segment_and_split_map import get_map_object
        map_data,space_group,unit_cell,crystal_symmetry,origin_frac,acc=\
          get_map_object(file_name=params.input_files.map_file,out=out)
        map_data = map_data.as_double()
        if origin_frac != (0, 0, 0) and acc is None:
            print >>out,"\nWARNING: Unable to place output map at position of "+\
              "input map though input map has non-zero origin at %s\n" %(
              str(origin_frac))

    elif params.input_files.map_coeffs_file:
        map_coeffs = get_map_coeffs_from_file(
            map_coeffs_file=params.input_files.map_coeffs_file,
            map_coeffs_labels=params.input_files.map_coeffs_labels)

        if not map_coeffs:
            raise Sorry("Could not get map coeffs from %s with labels %s" %
                        (params.input_files.map_coeffs_file,
                         params.input_files.map_coeffs_labels))
        print >> out, "Map coefficients read from %s with labels %s" % (
            params.input_files.map_coeffs_file,
            str(params.input_files.map_coeffs_labels))
        crystal_symmetry = map_coeffs.crystal_symmetry()
        from cctbx.maptbx.segment_and_split_map import get_map_from_map_coeffs
        map_data = get_map_from_map_coeffs(map_coeffs=map_coeffs,
                                           crystal_symmetry=crystal_symmetry)
        acc = map_data.accessor()
        if not params.crystal_info.resolution:
            params.crystal_info.resolution = map_coeffs.d_min()
            print >> out, "Resolution from map_coeffs is %7.2f A" % (
                params.crystal_info.resolution)
    else:
        raise Sorry("Need ccp4 map or map_coeffs")

    if params.input_files.half_map_file:
        if len(params.input_files.half_map_file) != 2:
            raise Sorry("Please supply zero or two half_map files")
        half_map_data_list = []
        from cctbx.maptbx.segment_and_split_map import get_map_object
        for file_name in params.input_files.half_map_file:
            print >> out, "\nReading half-map from %s\n" % (file_name)
            half_map_data,half_map_space_group,half_map_unit_cell,\
              half_map_crystal_symmetry,half_map_origin_frac,half_map_acc=\
              get_map_object(file_name=file_name,out=out)
            half_map_data = half_map_data.as_double()
            assert half_map_crystal_symmetry.is_similar_symmetry(
                crystal_symmetry)

            half_map_data_list.append(half_map_data)

    if params.crystal_info.resolution is None:
        raise Sorry("Need resolution if map is supplied")

    if params.input_files.pdb_file and not pdb_inp:  # get model
        model_file = params.input_files.pdb_file
        if not os.path.isfile(model_file):
            raise Sorry("Missing the model file: %s" % (model_file))
        pdb_inp = iotbx.pdb.input(file_name=model_file)
        if origin_frac != (0, 0, 0):
            print >> out, "Shifting model by %s" % (str(origin_frac))
            from cctbx.maptbx.segment_and_split_map import \
               apply_shift_to_pdb_hierarchy
            origin_shift = crystal_symmetry.unit_cell().orthogonalize(
                (-origin_frac[0], -origin_frac[1], -origin_frac[2]))
            pdb_inp = apply_shift_to_pdb_hierarchy(
                origin_shift=origin_shift,
                crystal_symmetry=crystal_symmetry,
                pdb_hierarchy=pdb_inp.construct_hierarchy(),
                out=out).as_pdb_input()

    if params.input_files.ncs_file and not ncs_obj:  # NCS
        from cctbx.maptbx.segment_and_split_map import get_ncs
        ncs_obj, dummy_tracking_data = get_ncs(params, out=out)
        if origin_frac != (0, 0, 0):
            origin_shift = crystal_symmetry.unit_cell().orthogonalize(
                (-origin_frac[0], -origin_frac[1], -origin_frac[2]))
            print >> out, "Shifting NCS by (%7.2f,%7.2f,%7.2f) " % (
                (origin_shift))
            from scitbx.math import matrix
            ncs_obj = ncs_obj.coordinate_offset(
                coordinate_offset=matrix.col(origin_shift))

    return pdb_inp, map_data, half_map_data_list, ncs_obj, crystal_symmetry, acc