def exercise_value(f_c_in_p1, f_o, flags, n_sampled):
  """ where we check against the trusted correlation map implemented
  in cctbx.translation_search """
  crystal_gridding = f_o.crystal_gridding(
    symmetry_flags=translation_search.symmetry_flags(
      is_isotropic_search_model=False,
      have_f_part=False),
    resolution_factor=1/3)
  correlation_map = translation_search.fast_nv1995(
    gridding=crystal_gridding.n_real(),
    space_group=f_o.space_group(),
    anomalous_flag=f_o.anomalous_flag(),
    miller_indices_f_obs=f_o.indices(),
    f_obs=f_o.data(),
    f_part=flex.complex_double(), ## no sub-structure is already fixed
    miller_indices_p1_f_calc=f_c_in_p1.indices(),
    p1_f_calc=f_c_in_p1.data()).target_map()
  nx, ny, nz = n = crystal_gridding.n_real()
  def sampled_indices():
    from random import randrange
    yield (0,0,0)
    for i in xrange(n_sampled - 1):
      yield randrange(0, n[0]), randrange(0, n[1]), randrange(0, n[2])
  f_o_sq = f_o.as_intensity_array()
  for i,j,k in sampled_indices():
    x = (i/nx, j/ny, k/nz)
    if random.random() > 0.5: f_o_or_f_o_sq = f_o
    else: f_o_or_f_o_sq = f_o_sq
    gos = symmetrised_shifted_structure_factors(
      f_o_or_f_o_sq, f_c_in_p1, x).misfit(f_o_or_f_o_sq)
    assert approx_equal(gos.correlation, correlation_map[i,j,k]), (i,j,k)
def exercise_value(f_c_in_p1, f_o, flags, n_sampled):
    """ where we check against the trusted correlation map implemented
  in cctbx.translation_search """
    crystal_gridding = f_o.crystal_gridding(
        symmetry_flags=translation_search.symmetry_flags(
            is_isotropic_search_model=False, have_f_part=False),
        resolution_factor=1 / 3)
    correlation_map = translation_search.fast_nv1995(
        gridding=crystal_gridding.n_real(),
        space_group=f_o.space_group(),
        anomalous_flag=f_o.anomalous_flag(),
        miller_indices_f_obs=f_o.indices(),
        f_obs=f_o.data(),
        f_part=flex.complex_double(),  ## no sub-structure is already fixed
        miller_indices_p1_f_calc=f_c_in_p1.indices(),
        p1_f_calc=f_c_in_p1.data()).target_map()
    nx, ny, nz = n = crystal_gridding.n_real()

    def sampled_indices():
        from random import randrange
        yield (0, 0, 0)
        for i in xrange(n_sampled - 1):
            yield randrange(0, n[0]), randrange(0, n[1]), randrange(0, n[2])

    f_o_sq = f_o.as_intensity_array()
    for i, j, k in sampled_indices():
        x = (i / nx, j / ny, k / nz)
        if random.random() > 0.5: f_o_or_f_o_sq = f_o
        else: f_o_or_f_o_sq = f_o_sq
        gos = symmetrised_shifted_structure_factors(f_o_or_f_o_sq, f_c_in_p1,
                                                    x).misfit(f_o_or_f_o_sq)
        assert approx_equal(gos.correlation, correlation_map[i, j,
                                                             k]), (i, j, k)
Exemplo n.º 3
0
def run_fast_nv1995(f_obs, f_calc_fixed, f_calc_p1,
                    symmetry_flags, gridding, grid_tags, verbose):
  if (f_calc_fixed is None):
    f_part = flex.complex_double()
  else:
    f_part = f_calc_fixed.data()
  assert f_obs.anomalous_flag() == f_calc_p1.anomalous_flag()
  fast_nv1995 = translation_search.fast_nv1995(
    gridding=gridding,
    space_group=f_obs.space_group(),
    anomalous_flag=f_obs.anomalous_flag(),
    miller_indices_f_obs=f_obs.indices(),
    f_obs=f_obs.data(),
    f_part=f_part,
    miller_indices_p1_f_calc=f_calc_p1.indices(),
    p1_f_calc=f_calc_p1.data())
  assert fast_nv1995.target_map().all() == gridding
  map_stats = maptbx.statistics(fast_nv1995.target_map())
  if (0 or verbose):
    map_stats.show_summary()
  grid_tags.build(f_obs.space_group_info().type(), symmetry_flags)
  assert grid_tags.n_grid_misses() == 0
  assert grid_tags.verify(fast_nv1995.target_map())
  peak_list = maptbx.peak_list(
    data=fast_nv1995.target_map(),
    tags=grid_tags.tag_array(),
    peak_search_level=1,
    max_peaks=10,
    interpolate=True)
  if (0 or verbose):
    print "gridding:", gridding
    for i,site in enumerate(peak_list.sites()):
      print "(%.4f,%.4f,%.4f)" % site, "%.6g" % peak_list.heights()[i]
  assert approx_equal(map_stats.max(), flex.max(peak_list.grid_heights()))
  return peak_list
Exemplo n.º 4
0
def run():
  target_structure = random_structure.xray_structure(
    space_group_info=sgtbx.space_group_info("I432"),
    elements=['C']*6+['O'],
    use_u_iso=False,
    use_u_aniso=True,
  )
  shift = tuple(flex.random_double(3))
  print "shift to be found: (%.3f, %.3f, %.3f)" % shift
  target_structure_in_p1 = target_structure.expand_to_p1().apply_shift(shift)
  miller_indices = miller.build_set(
    crystal_symmetry=target_structure,
    anomalous_flag=True,
    d_min=0.8)
  f_obs = miller_indices.structure_factors_from_scatterers(
    xray_structure=target_structure,
    algorithm="direct").f_calc().amplitudes()
  miller_indices_in_p1 = miller.build_set(
    crystal_symmetry=target_structure_in_p1,
    anomalous_flag=True,
    d_min=0.8)
  f_calc = miller_indices_in_p1.structure_factors_from_scatterers(
      xray_structure=target_structure_in_p1,
      algorithm="direct").f_calc()
  crystal_gridding = f_calc.crystal_gridding(
    symmetry_flags=translation_search.symmetry_flags(
      is_isotropic_search_model=False,
      have_f_part=False),
    resolution_factor=1/2
  )
  omptbx.env.num_threads = 1
  t_fast_tf = show_times()
  fast_tf_map = translation_search.fast_nv1995(
    gridding=crystal_gridding.n_real(),
    space_group=f_obs.space_group(),
    anomalous_flag=f_obs.anomalous_flag(),
    miller_indices_f_obs=f_obs.indices(),
    f_obs=f_obs.data(),
    f_part=flex.complex_double(), ## no sub-structure is already fixed
    miller_indices_p1_f_calc=f_calc.indices(),
    p1_f_calc=f_calc.data()).target_map()
  print
  print "Fast translation function"
  t_fast_tf()
  t_cross_corr = show_times()
  for op in target_structure.space_group():
    f, op_times_f = f_calc.original_and_transformed(op)
    cross_corr_map = miller.fft_map(crystal_gridding,
                                    f * op_times_f.conjugate().data())
  print
  print "Traditional cross-correlation"
  t_cross_corr()
def exercise_fast_nv1995():
    space_group = sgtbx.space_group_info("P 21 21 21").group()
    miller_indices_f_obs = flex.miller_index(((3, 4, 5), (4, 5, 6)))
    f = translation_search.fast_nv1995(
        gridding=(20, 20, 36),
        space_group=space_group,
        anomalous_flag=False,
        miller_indices_f_obs=miller_indices_f_obs,
        f_obs=flex.double((1, 2)),
        f_part=flex.complex_double(),
        miller_indices_p1_f_calc=flex.miller_index(((1, 2, 3), )),
        p1_f_calc=flex.complex_double((12, )))
    assert f.target_map().all() == (20, 20, 36)
def exercise_fast_nv1995():
  space_group = sgtbx.space_group_info("P 21 21 21").group()
  miller_indices_f_obs = flex.miller_index(((3,4,5),(4,5,6)))
  f = translation_search.fast_nv1995(
    gridding=(20,20,36),
    space_group=space_group,
    anomalous_flag=False,
    miller_indices_f_obs=miller_indices_f_obs,
    f_obs=flex.double((1,2)),
    f_part=flex.complex_double(),
    miller_indices_p1_f_calc=flex.miller_index(((1,2,3),)),
    p1_f_calc=flex.complex_double((12,)))
  assert f.target_map().all() == (20,20,36)
Exemplo n.º 7
0
def f_calc_symmetrisations(f_obs, f_calc_in_p1, min_cc_peak_height):
  # The fast correlation map as per cctbx.translation_search.fast_nv1995
  # is computed and its peaks studied.
  # Inspiration from phenix.substructure.hyss for the parameters tuning.
  if 0: # Display f_calc_in_p1
    from crys3d.qttbx import map_viewer
    map_viewer.display(window_title="f_calc in P1 before fast CC",
                       fft_map=f_calc_in_p1.fft_map(),
                       iso_level_positive_range_fraction=0.8)

  crystal_gridding = f_obs.crystal_gridding(
    symmetry_flags=translation_search.symmetry_flags(
      is_isotropic_search_model=False,
      have_f_part=False),
    resolution_factor=1/3
  )
  correlation_map = translation_search.fast_nv1995(
    gridding=crystal_gridding.n_real(),
    space_group=f_obs.space_group(),
    anomalous_flag=f_obs.anomalous_flag(),
    miller_indices_f_obs=f_obs.indices(),
    f_obs=f_obs.data(),
    f_part=flex.complex_double(), ## no sub-structure is already fixed
    miller_indices_p1_f_calc=f_calc_in_p1.indices(),
    p1_f_calc=f_calc_in_p1.data()).target_map()

  if 0: # Display correlation_map
    from crys3d.qttbx import map_viewer
    map_viewer.display(window_title="Fast CC map",
                       raw_map=correlation_map,
                       unit_cell=f_calc_in_p1.unit_cell(),
                       positive_iso_level=0.8)

  search_parameters = maptbx.peak_search_parameters(
    peak_search_level=1,
    peak_cutoff=0.5,
    interpolate=True,
    min_distance_sym_equiv=1e-6,
    general_positions_only=False,
    min_cross_distance=f_obs.d_min()/2)
  ## The correlation map is not a miller.fft_map, just a 3D flex.double
  correlation_map_peaks = crystal_gridding.tags().peak_search(
    map=correlation_map,
    parameters=search_parameters)
  # iterate over the strong peak; for each, shift and symmetrised f_calc
  for peak in correlation_map_peaks:
    if peak.height < min_cc_peak_height: break
    sr = symmetry_search.shift_refinement(
      f_obs, f_calc_in_p1, peak.site)
    yield sr.symmetrised_shifted_sf.f_x, sr.shift, sr.goos.correlation
Exemplo n.º 8
0
def run():
    target_structure = random_structure.xray_structure(
        space_group_info=sgtbx.space_group_info("I432"),
        elements=['C'] * 6 + ['O'],
        use_u_iso=False,
        use_u_aniso=True,
    )
    shift = tuple(flex.random_double(3))
    print "shift to be found: (%.3f, %.3f, %.3f)" % shift
    target_structure_in_p1 = target_structure.expand_to_p1().apply_shift(shift)
    miller_indices = miller.build_set(crystal_symmetry=target_structure,
                                      anomalous_flag=True,
                                      d_min=0.8)
    f_obs = miller_indices.structure_factors_from_scatterers(
        xray_structure=target_structure,
        algorithm="direct").f_calc().amplitudes()
    miller_indices_in_p1 = miller.build_set(
        crystal_symmetry=target_structure_in_p1,
        anomalous_flag=True,
        d_min=0.8)
    f_calc = miller_indices_in_p1.structure_factors_from_scatterers(
        xray_structure=target_structure_in_p1, algorithm="direct").f_calc()
    crystal_gridding = f_calc.crystal_gridding(
        symmetry_flags=translation_search.symmetry_flags(
            is_isotropic_search_model=False, have_f_part=False),
        resolution_factor=1 / 2)
    omptbx.env.num_threads = 1
    t_fast_tf = show_times()
    fast_tf_map = translation_search.fast_nv1995(
        gridding=crystal_gridding.n_real(),
        space_group=f_obs.space_group(),
        anomalous_flag=f_obs.anomalous_flag(),
        miller_indices_f_obs=f_obs.indices(),
        f_obs=f_obs.data(),
        f_part=flex.complex_double(),  ## no sub-structure is already fixed
        miller_indices_p1_f_calc=f_calc.indices(),
        p1_f_calc=f_calc.data()).target_map()
    print
    print "Fast translation function"
    t_fast_tf()
    t_cross_corr = show_times()
    for op in target_structure.space_group():
        f, op_times_f = f_calc.original_and_transformed(op)
        cross_corr_map = miller.fft_map(crystal_gridding,
                                        f * op_times_f.conjugate().data())
    print
    print "Traditional cross-correlation"
    t_cross_corr()
Exemplo n.º 9
0
def f_calc_symmetrisations(f_obs, f_calc_in_p1, min_cc_peak_height):
    # The fast correlation map as per cctbx.translation_search.fast_nv1995
    # is computed and its peaks studied.
    # Inspiration from phenix.substructure.hyss for the parameters tuning.
    if 0:  # Display f_calc_in_p1
        from crys3d.qttbx import map_viewer
        map_viewer.display(window_title="f_calc in P1 before fast CC",
                           fft_map=f_calc_in_p1.fft_map(),
                           iso_level_positive_range_fraction=0.8)

    crystal_gridding = f_obs.crystal_gridding(
        symmetry_flags=translation_search.symmetry_flags(
            is_isotropic_search_model=False, have_f_part=False),
        resolution_factor=1 / 3)
    correlation_map = translation_search.fast_nv1995(
        gridding=crystal_gridding.n_real(),
        space_group=f_obs.space_group(),
        anomalous_flag=f_obs.anomalous_flag(),
        miller_indices_f_obs=f_obs.indices(),
        f_obs=f_obs.data(),
        f_part=flex.complex_double(),  ## no sub-structure is already fixed
        miller_indices_p1_f_calc=f_calc_in_p1.indices(),
        p1_f_calc=f_calc_in_p1.data()).target_map()

    if 0:  # Display correlation_map
        from crys3d.qttbx import map_viewer
        map_viewer.display(window_title="Fast CC map",
                           raw_map=correlation_map,
                           unit_cell=f_calc_in_p1.unit_cell(),
                           positive_iso_level=0.8)

    search_parameters = maptbx.peak_search_parameters(
        peak_search_level=1,
        peak_cutoff=0.5,
        interpolate=True,
        min_distance_sym_equiv=1e-6,
        general_positions_only=False,
        min_cross_distance=f_obs.d_min() / 2)
    ## The correlation map is not a miller.fft_map, just a 3D flex.double
    correlation_map_peaks = crystal_gridding.tags().peak_search(
        map=correlation_map, parameters=search_parameters)
    # iterate over the strong peak; for each, shift and symmetrised f_calc
    for peak in correlation_map_peaks:
        if peak.height < min_cc_peak_height: break
        sr = symmetry_search.shift_refinement(f_obs, f_calc_in_p1, peak.site)
        yield sr.symmetrised_shifted_sf.f_x, sr.shift, sr.goos.correlation