def exercise_fast_terms():
  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_terms(
    gridding=(20,20,36),
    anomalous_flag=False,
    miller_indices_p1_f_calc=flex.miller_index(((1,2,3),)),
    p1_f_calc=flex.complex_double((12,)))
  assert f.summation(
    space_group=space_group,
    miller_indices_f_obs=miller_indices_f_obs,
    m=flex.double((1,2)),
    f_part=None,
    squared_flag=False).fft().accu_real_copy().all() == (20,20,36)
def exercise_fast_terms():
    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_terms(
        gridding=(20, 20, 36),
        anomalous_flag=False,
        miller_indices_p1_f_calc=flex.miller_index(((1, 2, 3), )),
        p1_f_calc=flex.complex_double((12, )))
    assert f.summation(space_group=space_group,
                       miller_indices_f_obs=miller_indices_f_obs,
                       m=flex.double((1, 2)),
                       f_part=None,
                       squared_flag=False).fft().accu_real_copy().all() == (20,
                                                                            20,
                                                                            36)
Esempio n. 3
0
def run_fast_terms(structure_fixed, structure_p1,
                   f_obs, f_calc_fixed, f_calc_p1,
                   symmetry_flags, gridding, grid_tags,
                   n_sample_grid_points=10,
                   test_origin=False,
                   verbose=0):
  if (f_calc_fixed is None):
    f_part = flex.complex_double()
  else:
    f_part = f_calc_fixed.data()
  m = flex.double()
  for i in xrange(f_obs.indices().size()):
    m.append(random.random())
  assert f_obs.anomalous_flag() == f_calc_p1.anomalous_flag()
  fast_terms = translation_search.fast_terms(
    gridding=gridding,
    anomalous_flag=f_obs.anomalous_flag(),
    miller_indices_p1_f_calc=f_calc_p1.indices(),
    p1_f_calc=f_calc_p1.data())
  for squared_flag in (False, True):
    map = fast_terms.summation(
      space_group=f_obs.space_group(),
      miller_indices_f_obs=f_obs.indices(),
      m=m,
      f_part=f_part,
      squared_flag=squared_flag).fft().accu_real_copy()
    assert map.all() == gridding
    map_stats = maptbx.statistics(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(map)
    for i_sample in xrange(n_sample_grid_points):
      run_away_counter = 0
      while 1:
        run_away_counter += 1
        assert run_away_counter < 1000
        if (i_sample == 0 and test_origin):
          grid_point = [0,0,0]
        else:
          grid_point = [random.randrange(g) for g in gridding]
        grid_site = [float(x)/g for x,g in zip(grid_point,gridding)]
        structure_shifted = structure_fixed.deep_copy_scatterers()
        assert structure_shifted.special_position_indices().size() == 0
        structure_shifted.add_scatterers(
          scatterers=structure_p1.apply_shift(grid_site).scatterers())
        if (structure_shifted.special_position_indices().size() == 0):
          break
        if (test_origin):
          assert i_sample != 0
      i_grid = flex.norm(f_obs.structure_factors_from_scatterers(
        xray_structure=structure_shifted, algorithm="direct").f_calc().data())
      if (squared_flag): p = 4
      else: p = 2
      map_value = map[grid_point] * f_obs.space_group().n_ltr()**p
      if (not squared_flag):
        sum_m_i_grid = flex.sum(m * i_grid)
      else:
        sum_m_i_grid = flex.sum(m * flex.pow2(i_grid))
      assert "%.6g" % sum_m_i_grid == "%.6g" % map_value, (
        sum_m_i_grid, map_value)