コード例 #1
0
def run(args, out=sys.stdout):
    cmdline = iotbx.phil.process_command_line_with_files(
        args=args,
        master_phil_string=master_phil_str,
        pdb_file_def="model",
        map_file_def="map",
        usage_string="""\
em_rscc.py model.pdb map.ccp4

%s""" % __doc__)
    params = cmdline.work.extract()
    assert (not None in [params.model, params.map])
    pdb_in = cmdline.get_file(params.model).file_object
    m = cmdline.get_file(params.map).file_object
    print >> out, "Input electron density map:"
    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
    symm = crystal.symmetry(space_group_symbol="P1",
                            unit_cell=m.unit_cell_parameters)
    xrs = pdb_in.input.xray_structure_simple(crystal_symmetry=symm)
    print >> out, "Setting up electron scattering table (d_min=%g)" % params.d_min
    xrs.scattering_type_registry(d_min=params.d_min, table="electron")
    fc = xrs.structure_factors(d_min=params.d_min).f_calc()
    cg = maptbx.crystal_gridding(unit_cell=symm.unit_cell(),
                                 space_group_info=symm.space_group_info(),
                                 pre_determined_n_real=m.data.all())
    fc_map = fc.fft_map(
        crystal_gridding=cg).apply_sigma_scaling().real_map_unpadded()
    assert (fc_map.all() == fc_map.focus() == m.data.all())
    em_data = m.data.as_double()
    unit_cell_for_interpolation = m.grid_unit_cell()
    frac_matrix = unit_cell_for_interpolation.fractionalization_matrix()
    sites_cart = xrs.sites_cart()
    sites_frac = xrs.sites_frac()
    print >> out, "PER-RESIDUE CORRELATION:"
    for chain in pdb_in.hierarchy.only_model().chains():
        for residue_group in chain.residue_groups():
            i_seqs = residue_group.atoms().extract_i_seq()
            values_em = flex.double()
            values_fc = flex.double()
            for i_seq in i_seqs:
                rho_em = maptbx.non_crystallographic_eight_point_interpolation(
                    map=em_data,
                    gridding_matrix=frac_matrix,
                    site_cart=sites_cart[i_seq])
                rho_fc = fc_map.eight_point_interpolation(sites_frac[i_seq])
                values_em.append(rho_em)
                values_fc.append(rho_fc)
            cc = flex.linear_correlation(x=values_em,
                                         y=values_fc).coefficient()
            print >> out, residue_group.id_str(), cc
コード例 #2
0
ファイル: map_util.py プロジェクト: fraser-lab/qptm
def get_density_at_position(position, frac_matrix, mapdata):
    """generic function for computing the density at a single point"""
    # raise Sorry if the position doesn't appear to be within the bounds of the map.
    # this may mean the user supplied a model that was not centered in the map.
    try:
        density = non_crystallographic_eight_point_interpolation(
            map=mapdata, gridding_matrix=frac_matrix, site_cart=position)
    except RuntimeError as e:
        raise Sorry("Could not compute map density at the requested position. "+\
          "Please check that model is entirely within map bounds.")
    return density
コード例 #3
0
def sample_angle (
    i_seqs,
    sites_cart,
    map_coeffs,
    real_map,
    sigma,
    angle_start,
    params,
    unit_cell=None) :
  frac_matrix = None
  if (unit_cell is None) :
    assert (map_coeffs is not None)
    unit_cell = map_coeffs.unit_cell()
  frac_matrix = unit_cell.fractionalization_matrix()
  assert (params.sampling_method != "direct") or (map_coeffs is not None)
  from cctbx import maptbx
  from scitbx.matrix import rotate_point_around_axis
  point = rotate_point_around_axis(
    axis_point_1=sites_cart[1],
    axis_point_2=sites_cart[2],
    point=sites_cart[3],
    angle=-angle_start,
    deg=True)
  # TODO: present option to have point (sites_cart[3]) be generated based on idealized geometry.
  n_degrees = 0
  densities = []
  while (n_degrees < 360) :
    point = rotate_point_around_axis(
      axis_point_1=sites_cart[1],
      axis_point_2=sites_cart[2],
      point=point,
      angle=params.sampling_angle,
      deg=True)
    point_frac = unit_cell.fractionalize(site_cart=point)
    if (params.sampling_method == "spline") and (map_coeffs is not None) :
      rho = real_map.tricubic_interpolation(point_frac)
    elif (params.sampling_method == "linear") or (map_coeffs is None) :
      if (map_coeffs is None) :
        rho = maptbx.non_crystallographic_eight_point_interpolation(
          map=real_map,
          gridding_matrix=frac_matrix,
          site_cart=point)
          #allow_out_of_bounds=True)
      else :
        rho = real_map.eight_point_interpolation(point_frac)
    else :
      rho = map_coeffs.direct_summation_at_point(
        site_frac=point_frac,
        sigma=sigma).real
    densities.append(rho)
    n_degrees += params.sampling_angle
  #print densities
  return densities
コード例 #4
0
def exercise_non_crystallographic_eight_point_interpolation():
  unit_cell=130.45,130.245,288.405,90,90,120
  unit_cell_gridding_n=144,144,360
  grid_cell=uctbx.unit_cell((130.45/144,130.245/144,388.405/360,90,90,120))
  grid_mat = grid_cell.fractionalization_matrix()
  map = test_map.deep_copy()
  map.resize(flex.grid((-1,-2,-1),(3,3,5)))
  for site_cart,expected_result in ([(0.468661,-1.549268,3.352108),-0.333095],
                                    [(0.624992,1.553980,1.205578),-0.187556],
                                    [(0.278175,0.968454,2.578265),-0.375068],
                                    [(0.265198,-1.476055,0.704381),-0.147061],
                                    [(1.296042,0.002101,3.459270),-0.304401],
                                    [(0.296189,-1.346603,2.935777),-0.296395],
                                    [(0.551586,-1.284371,3.202145),-0.363263],
                                    [(0.856542,-0.782700,-0.985020),-0.106925],
                                    [(0.154407,1.078936,-0.917551),-0.151128]):
    assert approx_equal(maptbx.non_crystallographic_eight_point_interpolation(
      map=map,
      gridding_matrix=grid_mat,
      site_cart=site_cart,
      allow_out_of_bounds=False,
      out_of_bounds_substitute_value=0), expected_result)
  for x in range(0,2):
    for y in range(-1,2):
      for z in range(0,4):
        assert approx_equal(
          maptbx.non_crystallographic_eight_point_interpolation(
            map,
            grid_mat,
            grid_cell.orthogonalize((x,y,z))), map[x,y,z])
  try:
    val = maptbx.non_crystallographic_eight_point_interpolation(
      map, grid_mat, (5,5,5))
  except RuntimeError as e:
    assert str(e) == \
      "cctbx Error: non_crystallographic_eight_point_interpolation:" \
      " point required for interpolation is out of bounds."
  else: raise Exception_expected
  assert approx_equal(maptbx.non_crystallographic_eight_point_interpolation(
    map, grid_mat, (5,5,5), True, -123), -123)
コード例 #5
0
def sample_angle(i_seqs,
                 sites_cart,
                 map_coeffs,
                 real_map,
                 difference_map,
                 sigma,
                 angle_start,
                 params,
                 sampling_method="linear",
                 unit_cell=None):
    """
  Given a set of four sites defining a rotatable dihedral angle, sample the
  density at the fourth site in small angular increments.

  returns: a tuple of lists containing the sampled density values (floats) for
           the primary map and optional difference map.
  """
    frac_matrix = None
    if (unit_cell is None):
        assert (map_coeffs is not None)
        unit_cell = map_coeffs.unit_cell()
    frac_matrix = unit_cell.fractionalization_matrix()
    assert (sampling_method != "direct") or (map_coeffs is not None)
    from cctbx import maptbx
    from scitbx.matrix import rotate_point_around_axis
    point = rotate_point_around_axis(axis_point_1=sites_cart[1],
                                     axis_point_2=sites_cart[2],
                                     point=sites_cart[3],
                                     angle=-angle_start,
                                     deg=True)
    # TODO: present option to have point (sites_cart[3]) be generated based on
    # idealized geometry.
    n_degrees = 0
    densities = []
    difference_densities = []
    while (n_degrees < 360):
        point = rotate_point_around_axis(axis_point_1=sites_cart[1],
                                         axis_point_2=sites_cart[2],
                                         point=point,
                                         angle=params.sampling_angle,
                                         deg=True)
        point_frac = unit_cell.fractionalize(site_cart=point)
        rho = rho_fofc = None
        if (sampling_method == "spline") and (map_coeffs is not None):
            rho = real_map.tricubic_interpolation(point_frac)
            if (difference_map is not None):
                rho_fofc = difference_map.tricubic_interpolation(point_frac)
        elif (sampling_method == "linear") or (map_coeffs is None):
            if (map_coeffs is None):
                rho = maptbx.non_crystallographic_eight_point_interpolation(
                    map=real_map, gridding_matrix=frac_matrix, site_cart=point)
                #allow_out_of_bounds=True)
            else:
                rho = real_map.eight_point_interpolation(point_frac)
                if (difference_map is not None):
                    rho_fofc = difference_map.eight_point_interpolation(
                        point_frac)
        else:
            rho = map_coeffs.direct_summation_at_point(site_frac=point_frac,
                                                       sigma=sigma).real
        densities.append(rho)
        if (rho_fofc is not None):
            difference_densities.append(rho_fofc)
        n_degrees += params.sampling_angle
    #print densities
    return densities, difference_densities
コード例 #6
0
ファイル: __init__.py プロジェクト: cctbx/cctbx-playground
def sample_angle (
    i_seqs,
    sites_cart,
    map_coeffs,
    real_map,
    difference_map,
    sigma,
    angle_start,
    params,
    sampling_method="linear",
    unit_cell=None) :
  """
  Given a set of four sites defining a rotatable dihedral angle, sample the
  density at the fourth site in small angular increments.

  returns: a tuple of lists containing the sampled density values (floats) for
           the primary map and optional difference map.
  """
  frac_matrix = None
  if (unit_cell is None) :
    assert (map_coeffs is not None)
    unit_cell = map_coeffs.unit_cell()
  frac_matrix = unit_cell.fractionalization_matrix()
  assert (sampling_method != "direct") or (map_coeffs is not None)
  from cctbx import maptbx
  from scitbx.matrix import rotate_point_around_axis
  point = rotate_point_around_axis(
    axis_point_1=sites_cart[1],
    axis_point_2=sites_cart[2],
    point=sites_cart[3],
    angle=-angle_start,
    deg=True)
  # TODO: present option to have point (sites_cart[3]) be generated based on
  # idealized geometry.
  n_degrees = 0
  densities = []
  difference_densities = []
  while (n_degrees < 360) :
    point = rotate_point_around_axis(
      axis_point_1=sites_cart[1],
      axis_point_2=sites_cart[2],
      point=point,
      angle=params.sampling_angle,
      deg=True)
    point_frac = unit_cell.fractionalize(site_cart=point)
    rho = rho_fofc = None
    if (sampling_method == "spline") and (map_coeffs is not None) :
      rho = real_map.tricubic_interpolation(point_frac)
      if (difference_map is not None) :
        rho_fofc = difference_map.tricubic_interpolation(point_frac)
    elif (sampling_method == "linear") or (map_coeffs is None) :
      if (map_coeffs is None) :
        rho = maptbx.non_crystallographic_eight_point_interpolation(
          map=real_map,
          gridding_matrix=frac_matrix,
          site_cart=point)
          #allow_out_of_bounds=True)
      else :
        rho = real_map.eight_point_interpolation(point_frac)
        if (difference_map is not None) :
          rho_fofc = difference_map.eight_point_interpolation(point_frac)
    else :
      rho = map_coeffs.direct_summation_at_point(
        site_frac=point_frac,
        sigma=sigma).real
    densities.append(rho)
    if (rho_fofc is not None) :
      difference_densities.append(rho_fofc)
    n_degrees += params.sampling_angle
  #print densities
  return densities, difference_densities
コード例 #7
0
    for y in range(-1,2):
      for z in range(0,4):
        assert approx_equal(
          maptbx.non_crystallographic_eight_point_interpolation(
            map,
            grid_mat,
            grid_cell.orthogonalize((x,y,z))), map[x,y,z])
  try:
    val = maptbx.non_crystallographic_eight_point_interpolation(
      map, grid_mat, (5,5,5))
  except RuntimeError, e:
    assert str(e) == \
      "cctbx Error: non_crystallographic_eight_point_interpolation:" \
      " point required for interpolation is out of bounds."
  else: raise Exception_expected
  assert approx_equal(maptbx.non_crystallographic_eight_point_interpolation(
    map, grid_mat, (5,5,5), True, -123), -123)

def exercise_average_density():
  map = test_map.deep_copy()
  map.resize(flex.grid(4,5,6))
  sites_frac = flex.vec3_double([
    (-0.8492400683111605, 0.49159543530354166, 0.55624239788303198),
    (0.10631567870879444, -0.38726326483005269, -0.13581656178827783),
    (0.1895918946688977, -0.25027164520003642, -0.61981792226895172),
    (-0.88980846616667897, -0.79492758628794169, 0.015347308715653485)])
  unit_cell = uctbx.unit_cell((130,130,288,90,90,120))
  densities = maptbx.average_densities(
    unit_cell=unit_cell,
    data=map,
    sites_frac=sites_frac,
    radius=5)
コード例 #8
0
ファイル: em_rscc.py プロジェクト: cctbx/cctbx-playground
def run (args, out=sys.stdout) :
  cmdline = iotbx.phil.process_command_line_with_files(
    args=args,
    master_phil_string=master_phil_str,
    pdb_file_def="model",
    map_file_def="map",
    usage_string="""\
em_rscc.py model.pdb map.ccp4

%s""" % __doc__)
  params = cmdline.work.extract()
  assert (not None in [params.model, params.map])
  pdb_in = cmdline.get_file(params.model).file_object
  m = cmdline.get_file(params.map).file_object
  print >> out, "Input electron density map:"
  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
  symm = crystal.symmetry(
    space_group_symbol="P1",
    unit_cell=m.unit_cell_parameters)
  xrs = pdb_in.input.xray_structure_simple(crystal_symmetry=symm)
  print >> out, "Setting up electron scattering table (d_min=%g)" % params.d_min
  xrs.scattering_type_registry(
    d_min=params.d_min,
    table="electron")
  fc = xrs.structure_factors(d_min=params.d_min).f_calc()
  cg = maptbx.crystal_gridding(
    unit_cell=symm.unit_cell(),
    space_group_info=symm.space_group_info(),
    pre_determined_n_real=m.data.all())
  fc_map = fc.fft_map(
    crystal_gridding=cg).apply_sigma_scaling().real_map_unpadded()
  assert (fc_map.all() == fc_map.focus() == m.data.all())
  em_data = m.data.as_double()
  unit_cell_for_interpolation = m.grid_unit_cell()
  frac_matrix = unit_cell_for_interpolation.fractionalization_matrix()
  sites_cart = xrs.sites_cart()
  sites_frac = xrs.sites_frac()
  print >> out, "PER-RESIDUE CORRELATION:"
  for chain in pdb_in.hierarchy.only_model().chains() :
    for residue_group in chain.residue_groups() :
      i_seqs = residue_group.atoms().extract_i_seq()
      values_em = flex.double()
      values_fc = flex.double()
      for i_seq in i_seqs :
        rho_em = maptbx.non_crystallographic_eight_point_interpolation(
          map=em_data,
          gridding_matrix=frac_matrix,
          site_cart=sites_cart[i_seq])
        rho_fc = fc_map.eight_point_interpolation(sites_frac[i_seq])
        values_em.append(rho_em)
        values_fc.append(rho_fc)
      cc = flex.linear_correlation(x=values_em, y=values_fc).coefficient()
      print >> out, residue_group.id_str(), cc