Exemplo n.º 1
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.º 2
0
def calculate_exp_i_two_phi_peaks(xray_structure, d_min,
                                  min_peak_distance,
                                  max_reduced_peaks):
  f_h = xray_structure.structure_factors(
    anomalous_flag=False,
    d_min=d_min).f_calc()
  two_i_phi_h = miller.array(
    miller_set=f_h,
    data=flex.polar(1, flex.arg(f_h.data())*2))
  fft_map = two_i_phi_h.fft_map(
    d_min=d_min,
    symmetry_flags=maptbx.use_space_group_symmetry)
  real_map = fft_map.real_map()
  real_map = maptbx.copy(real_map, flex.grid(real_map.focus()))
  stats = maptbx.statistics(real_map)
  if (stats.max() != 0):
    real_map /= abs(stats.max())
  grid_tags = maptbx.grid_tags(real_map.focus())
  grid_tags.build(fft_map.space_group_info().type(), fft_map.symmetry_flags())
  grid_tags.verify(real_map)
  peak_list = maptbx.peak_list(
    data=real_map,
    tags=grid_tags.tag_array(),
    max_peaks=10*max_reduced_peaks,
    interpolate=True)
  reduced_peaks = peak_cluster_reduction(
    crystal_symmetry=xray_structure,
    peak_list=peak_list,
    min_peak_distance=min_peak_distance,
    max_reduced_peaks=max_reduced_peaks)
  return reduced_peaks
Exemplo n.º 3
0
def exercise_peak_search():
  t = flex.long(flex.grid((3,4,5)))
  for flex_type in flex_types():
    d = flex_type(flex.grid((3,4,5)))
    l = maptbx.peak_list(d, t, peak_search_level=0, interpolate=False)
    assert l.gridding() == d.focus()
    assert l.grid_indices(0) == (0,0,0)
    assert list(l.grid_heights()) == [0]
    assert list(l.sites()) == [(0,0,0)]
    assert list(l.heights()) == [0]
    l = maptbx.peak_list(
      d, t, peak_search_level=0,peak_cutoff=-1, interpolate=False)
    assert l.gridding() == d.focus()
    assert l.grid_indices(0) == (0,0,0)
    assert list(l.grid_heights()) == [0]
    assert list(l.sites()) == [(0,0,0)]
    assert list(l.heights()) == [0]
Exemplo n.º 4
0
def run_test(space_group_info, n_elements=5, d_min=1.5,
             grid_resolution_factor=1./3, max_prime=5, verbose=0):
  structure = random_structure.xray_structure(
    space_group_info,
    elements=["Si"]*n_elements,
    volume_per_atom=200,
    min_distance=3.,
    general_positions_only=False)
  miller_set_f_obs = miller.build_set(
    crystal_symmetry=structure,
    anomalous_flag=(random.random()>0.5),
    d_min=d_min)
  f_obs = miller_set_f_obs.structure_factors_from_scatterers(
    xray_structure=structure,
    algorithm="direct").f_calc()
  structure_factor_utils.check_phase_restrictions(f_obs, verbose=verbose)
  if (0 or verbose):
    f_obs.show_summary()
  if (0 or verbose):
    f_obs.show_array()
  fft_map = f_obs.fft_map(
    resolution_factor=grid_resolution_factor,
    symmetry_flags=maptbx.use_space_group_symmetry)
  p = pickle.dumps(fft_map)
  l = pickle.loads(p)
  s1 = StringIO()
  fft_map.statistics().show_summary(f=s1)
  s2 = StringIO()
  l.statistics().show_summary(f=s2)
  assert not show_diff(s2.getvalue(), s1.getvalue())
  #
  if (not f_obs.anomalous_flag()):
    maptbx_fft_map = maptbx.fft_to_real_map_unpadded(
      space_group=fft_map.space_group(),
      n_real=fft_map.n_real(),
      miller_indices=f_obs.indices(),
      data=f_obs.data())
    fft_map_unpadded = fft_map.real_map_unpadded(in_place=False)
    assert approx_equal(
      flex.linear_correlation(
        fft_map_unpadded.as_1d(), maptbx_fft_map.as_1d()).coefficient(), 1)
    assert approx_equal(
      flex.max(flex.abs(maptbx_fft_map - fft_map_unpadded)), 0)
  #
  fft_map.apply_sigma_scaling()
  real_map = maptbx.copy(
    fft_map.real_map(),
    flex.grid(fft_map.real_map().focus()))
  grid_tags = maptbx.grid_tags(real_map.focus())
  grid_tags.build(
    fft_map.space_group_info().type(),
    fft_map.symmetry_flags())
  assert grid_tags.n_grid_misses() == 0
  assert grid_tags.verify(real_map)
  rms = []
  for interpolate in (False,True):
    peak_list = maptbx.peak_list(
      data=real_map,
      tags=grid_tags.tag_array(),
      peak_search_level=1,
      max_peaks=2*n_elements,
      interpolate=interpolate)
    assert peak_list.gridding() == real_map.focus()
    check_peaks(structure, peak_list.sites(), d_min * grid_resolution_factor)
    crystal_gridding_tags = fft_map.tags()
    cluster_analysis = maptbx.peak_cluster_analysis(
      peak_list=peak_list,
      special_position_settings=structure,
      general_positions_only=False,
      effective_resolution=d_min,
      min_cross_distance=2,
      max_clusters=n_elements).all()
    check_peaks(
      structure,
      cluster_analysis.sites(),
      cluster_analysis.min_cross_distance() + d_min * grid_resolution_factor)
    structure_from_peaks = xray.structure(structure)
    for site in cluster_analysis.sites():
      structure_from_peaks.add_scatterer(
        xray.scatterer(label="site", scattering_type="", site=site))
    emma_matches = emma.model_matches(
      structure.as_emma_model(),
      structure_from_peaks.as_emma_model(),
      tolerance=d_min*2)
    rms.append(emma_matches.refined_matches[0].rms)
    assert len(emma_matches.refined_matches[0].pairs) == n_elements
  # exercise interpolation vs. summation
  map_coeffs = f_obs.expand_to_p1()
  fft_map = f_obs.fft_map(
    resolution_factor=grid_resolution_factor,
    symmetry_flags=maptbx.use_space_group_symmetry)
  fft_map.apply_volume_scaling()
  real_map = fft_map.real_map_unpadded()
  sum1 = sum2 = 0
  for scatterer in structure.scatterers() :
    v1 = real_map.eight_point_interpolation(scatterer.site)
    v2 = real_map.tricubic_interpolation(scatterer.site)
    v3 = map_coeffs.direct_summation_at_point(scatterer.site)
    sum1 += abs(v1 - v3.real)
    sum2 += abs(v2 - v3.real)
  mean_delta_linear = sum1 / n_elements
  mean_delta_cubic = sum2 / n_elements
  assert (mean_delta_cubic < mean_delta_linear)
  if (0 or verbose):
    print "emma rms grid, interpolated: %.2f %.2f" % tuple(rms)
  assert rms[0] >= rms[1]
  map_1 = fft_map.real_map_unpadded(in_place=False)
  map_2 = fft_map.real_map_unpadded(in_place=True)
  assert (map_1.all_eq(map_2))
Exemplo n.º 5
0
def run_test(space_group_info,
             n_elements=5,
             d_min=1.5,
             grid_resolution_factor=1. / 3,
             max_prime=5,
             verbose=0):
    structure = random_structure.xray_structure(space_group_info,
                                                elements=["Si"] * n_elements,
                                                volume_per_atom=200,
                                                min_distance=3.,
                                                general_positions_only=False)
    miller_set_f_obs = miller.build_set(crystal_symmetry=structure,
                                        anomalous_flag=(random.random() > 0.5),
                                        d_min=d_min)
    f_obs = miller_set_f_obs.structure_factors_from_scatterers(
        xray_structure=structure, algorithm="direct").f_calc()
    structure_factor_utils.check_phase_restrictions(f_obs, verbose=verbose)
    if (0 or verbose):
        f_obs.show_summary()
    if (0 or verbose):
        f_obs.show_array()
    fft_map = f_obs.fft_map(resolution_factor=grid_resolution_factor,
                            symmetry_flags=maptbx.use_space_group_symmetry)
    p = pickle.dumps(fft_map)
    l = pickle.loads(p)
    s1 = StringIO()
    fft_map.statistics().show_summary(f=s1)
    s2 = StringIO()
    l.statistics().show_summary(f=s2)
    assert not show_diff(s2.getvalue(), s1.getvalue())
    #
    if (not f_obs.anomalous_flag()):
        maptbx_fft_map = maptbx.fft_to_real_map_unpadded(
            space_group=fft_map.space_group(),
            n_real=fft_map.n_real(),
            miller_indices=f_obs.indices(),
            data=f_obs.data())
        fft_map_unpadded = fft_map.real_map_unpadded(in_place=False)
        assert approx_equal(
            flex.linear_correlation(fft_map_unpadded.as_1d(),
                                    maptbx_fft_map.as_1d()).coefficient(), 1)
        assert approx_equal(
            flex.max(flex.abs(maptbx_fft_map - fft_map_unpadded)), 0)
    #
    fft_map.apply_sigma_scaling()
    real_map = maptbx.copy(fft_map.real_map(),
                           flex.grid(fft_map.real_map().focus()))
    grid_tags = maptbx.grid_tags(real_map.focus())
    grid_tags.build(fft_map.space_group_info().type(),
                    fft_map.symmetry_flags())
    assert grid_tags.n_grid_misses() == 0
    assert grid_tags.verify(real_map)
    rms = []
    for interpolate in (False, True):
        peak_list = maptbx.peak_list(data=real_map,
                                     tags=grid_tags.tag_array(),
                                     peak_search_level=1,
                                     max_peaks=2 * n_elements,
                                     interpolate=interpolate)
        assert peak_list.gridding() == real_map.focus()
        check_peaks(structure, peak_list.sites(),
                    d_min * grid_resolution_factor)
        crystal_gridding_tags = fft_map.tags()
        cluster_analysis = maptbx.peak_cluster_analysis(
            peak_list=peak_list,
            special_position_settings=structure,
            general_positions_only=False,
            effective_resolution=d_min,
            min_cross_distance=2,
            max_clusters=n_elements).all()
        check_peaks(
            structure, cluster_analysis.sites(),
            cluster_analysis.min_cross_distance() +
            d_min * grid_resolution_factor)
        structure_from_peaks = xray.structure(structure)
        for site in cluster_analysis.sites():
            structure_from_peaks.add_scatterer(
                xray.scatterer(label="site", scattering_type="", site=site))
        emma_matches = emma.model_matches(structure.as_emma_model(),
                                          structure_from_peaks.as_emma_model(),
                                          tolerance=d_min * 2)
        rms.append(emma_matches.refined_matches[0].rms)
        assert len(emma_matches.refined_matches[0].pairs) == n_elements
    # exercise interpolation vs. summation
    map_coeffs = f_obs.expand_to_p1()
    fft_map = f_obs.fft_map(resolution_factor=grid_resolution_factor,
                            symmetry_flags=maptbx.use_space_group_symmetry)
    fft_map.apply_volume_scaling()
    real_map = fft_map.real_map_unpadded()
    sum1 = sum2 = 0
    for scatterer in structure.scatterers():
        v1 = real_map.eight_point_interpolation(scatterer.site)
        v2 = real_map.tricubic_interpolation(scatterer.site)
        v3 = map_coeffs.direct_summation_at_point(scatterer.site)
        sum1 += abs(v1 - v3.real)
        sum2 += abs(v2 - v3.real)
    mean_delta_linear = sum1 / n_elements
    mean_delta_cubic = sum2 / n_elements
    assert (mean_delta_cubic < mean_delta_linear)
    if (0 or verbose):
        print("emma rms grid, interpolated: %.2f %.2f" % tuple(rms))
    assert rms[0] >= rms[1]
    map_1 = fft_map.real_map_unpadded(in_place=False)
    map_2 = fft_map.real_map_unpadded(in_place=True)
    assert (map_1.all_eq(map_2))