Esempio n. 1
0
def run():
    show_times = libtbx.utils.show_times()
    from scitbx.python_utils import command_line
    flags = command_line.parse_options(sys.argv[1:], [
        "RandomSeed",
        "Verbose",
    ])
    if (not flags.RandomSeed): random.seed(0)
    assert fftpack.adjust_gridding(13, 5) == 15
    assert fftpack.adjust_gridding(13, 5, 6) == 18
    assert fftpack.adjust_gridding_triple((13, 22, 34), 5) == (15, 24, 36)
    assert fftpack.adjust_gridding_triple((13, 22, 34), 5,
                                          (6, 10, 8)) == (18, 30, 40)
    f = fftpack.factorization(30, False)
    assert f.n() == 30
    assert tuple(f.factors()) == (2, 3, 5)
    test_complex_to_complex(flags.Verbose)
    test_real_to_complex(flags.Verbose)
    test_complex_to_complex_2d(flags.Verbose)
    test_complex_to_complex_3d(flags.Verbose)
    test_real_to_complex_3d(flags.Verbose)
    exercise_real_to_complex_padding_area()
    max_transform_size = 300
    test_comprehensive_cc_1d(max_transform_size)
    test_comprehensive_rc_1d(max_transform_size)
    show_times()
Esempio n. 2
0
def run():
  show_times = libtbx.utils.show_times()
  from scitbx.python_utils import command_line
  flags = command_line.parse_options(sys.argv[1:], [
    "RandomSeed",
    "Verbose",
  ])
  if (not flags.RandomSeed): random.seed(0)
  assert fftpack.adjust_gridding(13, 5) == 15
  assert fftpack.adjust_gridding(13, 5, 6) == 18
  assert fftpack.adjust_gridding_triple((13,22,34), 5) == (15,24,36)
  assert fftpack.adjust_gridding_triple((13,22,34), 5, (6,10,8)) == (18,30,40)
  f = fftpack.factorization(30, False)
  assert f.n() == 30
  assert tuple(f.factors()) == (2, 3, 5)
  test_complex_to_complex(flags.Verbose)
  test_real_to_complex(flags.Verbose)
  test_complex_to_complex_2d(flags.Verbose)
  test_complex_to_complex_3d(flags.Verbose)
  test_real_to_complex_3d(flags.Verbose)
  exercise_real_to_complex_padding_area()
  max_transform_size = 300
  test_comprehensive_cc_1d(max_transform_size)
  test_comprehensive_rc_1d(max_transform_size)
  show_times()
Esempio n. 3
0
def region_density_correlation(large_unit_cell, large_d_min, large_density_map,
                               sites_cart, site_radii, work_scatterers):
    sites_frac_large = large_unit_cell.fractionalize(sites_cart)
    large_frac_min = sites_frac_large.min()
    large_frac_max = sites_frac_large.max()
    large_n_real = large_density_map.focus()
    from scitbx import fftpack
    from libtbx.math_utils import ifloor, iceil
    large_ucp = large_unit_cell.parameters()
    small_n_real = [0, 0, 0]
    small_origin_in_large_grid = [0, 0, 0]
    small_abc = [0, 0, 0]
    sites_frac_shift = [0, 0, 0]
    for i in xrange(3):
        grid_step = large_ucp[i] / large_n_real[i]
        buffer = large_d_min / grid_step
        grid_min = ifloor(large_frac_min[i] * large_n_real[i] - buffer)
        grid_max = iceil(large_frac_max[i] * large_n_real[i] + buffer)
        min_grid = grid_max - grid_min + 1
        small_n_real[i] = fftpack.adjust_gridding(min_grid=min_grid,
                                                  max_prime=5)
        if (small_n_real[i] < large_n_real[i]):
            shift_min = (small_n_real[i] - min_grid) // 2
            small_origin_in_large_grid[i] = grid_min - shift_min
            small_abc[i] = small_n_real[i] * grid_step
            sites_frac_shift[
                i] = small_origin_in_large_grid[i] / large_n_real[i]
        else:
            small_n_real[i] = large_n_real[i]
            small_origin_in_large_grid[i] = 0
            small_abc[i] = large_ucp[i]
            sites_frac_shift[i] = 0
    sites_cart_shift = large_unit_cell.orthogonalize(sites_frac_shift)
    sites_cart_small = sites_cart - sites_cart_shift
    from cctbx import xray
    small_xray_structure = xray.structure(crystal_symmetry=crystal.symmetry(
        unit_cell=tuple(small_abc) + large_ucp[3:], space_group_symbol="P1"),
                                          scatterers=work_scatterers)
    small_xray_structure.set_sites_cart(sites_cart=sites_cart_small)
    small_f_calc = small_xray_structure.structure_factors(
        d_min=large_d_min).f_calc()
    small_gridding = crystal_gridding(
        unit_cell=small_f_calc.unit_cell(),
        space_group_info=small_f_calc.space_group_info(),
        pre_determined_n_real=small_n_real)
    from cctbx import miller
    small_fft_map = miller.fft_map(crystal_gridding=small_gridding,
                                   fourier_coefficients=small_f_calc)
    small_fft_map.apply_sigma_scaling()
    small_map = small_fft_map.real_map_unpadded()
    grid_indices = grid_indices_around_sites(
        unit_cell=small_xray_structure.unit_cell(),
        fft_n_real=small_n_real,
        fft_m_real=small_n_real,
        sites_cart=sites_cart_small,
        site_radii=site_radii)
    small_copy_from_large_map = copy(
        map_unit_cell=large_density_map,
        first=small_origin_in_large_grid,
        last=matrix.col(small_origin_in_large_grid) +
        matrix.col(small_n_real) - matrix.col((1, 1, 1)))
    assert small_copy_from_large_map.all() == small_map.all()
    corr = flex.linear_correlation(
        x=small_map.select(grid_indices),
        y=small_copy_from_large_map.select(grid_indices))
    if (not corr.is_well_defined()):
        return None
    return corr.coefficient()
Esempio n. 4
0
def region_density_correlation(
      large_unit_cell,
      large_d_min,
      large_density_map,
      sites_cart,
      site_radii,
      work_scatterers):
  sites_frac_large = large_unit_cell.fractionalize(sites_cart)
  large_frac_min = sites_frac_large.min()
  large_frac_max = sites_frac_large.max()
  large_n_real = large_density_map.focus()
  from scitbx import fftpack
  from libtbx.math_utils import ifloor, iceil
  large_ucp = large_unit_cell.parameters()
  small_n_real = [0,0,0]
  small_origin_in_large_grid = [0,0,0]
  small_abc = [0,0,0]
  sites_frac_shift = [0,0,0]
  for i in xrange(3):
    grid_step = large_ucp[i] / large_n_real[i]
    buffer = large_d_min / grid_step
    grid_min = ifloor(large_frac_min[i] * large_n_real[i] - buffer)
    grid_max = iceil(large_frac_max[i] * large_n_real[i] + buffer)
    min_grid = grid_max - grid_min + 1
    small_n_real[i] = fftpack.adjust_gridding(min_grid=min_grid, max_prime=5)
    if (small_n_real[i] < large_n_real[i]):
      shift_min = (small_n_real[i] - min_grid) // 2
      small_origin_in_large_grid[i] = grid_min - shift_min
      small_abc[i] = small_n_real[i] * grid_step
      sites_frac_shift[i] = small_origin_in_large_grid[i] / large_n_real[i]
    else:
      small_n_real[i] = large_n_real[i]
      small_origin_in_large_grid[i] = 0
      small_abc[i] = large_ucp[i]
      sites_frac_shift[i] = 0
  sites_cart_shift = large_unit_cell.orthogonalize(sites_frac_shift)
  sites_cart_small = sites_cart - sites_cart_shift
  from cctbx import xray
  small_xray_structure = xray.structure(
    crystal_symmetry=crystal.symmetry(
      unit_cell=tuple(small_abc)+large_ucp[3:],
      space_group_symbol="P1"),
    scatterers=work_scatterers)
  small_xray_structure.set_sites_cart(sites_cart=sites_cart_small)
  small_f_calc = small_xray_structure.structure_factors(
    d_min=large_d_min).f_calc()
  small_gridding = crystal_gridding(
    unit_cell=small_f_calc.unit_cell(),
    space_group_info=small_f_calc.space_group_info(),
    pre_determined_n_real=small_n_real)
  from cctbx import miller
  small_fft_map = miller.fft_map(
    crystal_gridding=small_gridding,
    fourier_coefficients=small_f_calc)
  small_fft_map.apply_sigma_scaling()
  small_map = small_fft_map.real_map_unpadded()
  grid_indices = grid_indices_around_sites(
    unit_cell=small_xray_structure.unit_cell(),
    fft_n_real=small_n_real,
    fft_m_real=small_n_real,
    sites_cart=sites_cart_small,
    site_radii=site_radii)
  small_copy_from_large_map = copy(
    map_unit_cell=large_density_map,
    first=small_origin_in_large_grid,
    last=matrix.col(small_origin_in_large_grid)
       + matrix.col(small_n_real)
       - matrix.col((1,1,1)))
  assert small_copy_from_large_map.all() == small_map.all()
  corr = flex.linear_correlation(
    x=small_map.select(grid_indices),
    y=small_copy_from_large_map.select(grid_indices))
  if (not corr.is_well_defined()):
    return None
  return corr.coefficient()