Ejemplo n.º 1
0
def exercise_match_bijvoet_mates():
  h0 = flex.miller_index(((1,2,3), (-1,-2,-3), (2,3,4), (-2,-3,-4), (3,4,5)))
  d0 = flex.double((1,2,3,4,5))
  bm = miller.match_bijvoet_mates(
    sgtbx.space_group_type(),
    h0)
  bm = miller.match_bijvoet_mates(
    sgtbx.reciprocal_space_asu(sgtbx.space_group_type()),
    h0)
  bm = miller.match_bijvoet_mates(
    h0)
  assert tuple(bm.pairs()) == ((0,1), (2,3))
  assert tuple(bm.singles("+")) == (4,)
  assert tuple(bm.singles("-")) == ()
  assert bm.n_singles() != 0
  assert tuple(bm.pairs_hemisphere_selection("+")) == (0, 2)
  assert tuple(bm.pairs_hemisphere_selection("-")) == (1, 3)
  assert tuple(bm.singles_hemisphere_selection("+")) == (4,)
  assert tuple(bm.singles_hemisphere_selection("-")) == ()
  assert tuple(bm.miller_indices_in_hemisphere("+")) == ((1,2,3), (2,3,4))
  assert tuple(bm.miller_indices_in_hemisphere("-")) == ((-1,-2,-3),(-2,-3,-4))
  assert approx_equal(tuple(bm.minus(d0)), (-1, -1))
  assert approx_equal(tuple(bm.additive_sigmas(d0)),
                      [math.sqrt(x*x+y*y) for x,y in ((1,2), (3,4))])
  assert approx_equal(tuple(bm.average(d0)), (3/2., 7/2.))
  h0.append((1,2,3))
  try: miller.match_bijvoet_mates(h0)
  except Exception: pass
  else: raise Exception_expected
Ejemplo n.º 2
0
def exercise_match_bijvoet_mates():
  h0 = flex.miller_index(((1,2,3), (-1,-2,-3), (2,3,4), (-2,-3,-4), (3,4,5)))
  d0 = flex.double((1,2,3,4,5))
  bm = miller.match_bijvoet_mates(
    sgtbx.space_group_type(),
    h0)
  bm = miller.match_bijvoet_mates(
    sgtbx.reciprocal_space_asu(sgtbx.space_group_type()),
    h0)
  bm = miller.match_bijvoet_mates(
    h0)
  assert tuple(bm.pairs()) == ((0,1), (2,3))
  assert tuple(bm.singles("+")) == (4,)
  assert tuple(bm.singles("-")) == ()
  assert bm.n_singles() != 0
  assert tuple(bm.pairs_hemisphere_selection("+")) == (0, 2)
  assert tuple(bm.pairs_hemisphere_selection("-")) == (1, 3)
  assert tuple(bm.singles_hemisphere_selection("+")) == (4,)
  assert tuple(bm.singles_hemisphere_selection("-")) == ()
  assert tuple(bm.miller_indices_in_hemisphere("+")) == ((1,2,3), (2,3,4))
  assert tuple(bm.miller_indices_in_hemisphere("-")) == ((-1,-2,-3),(-2,-3,-4))
  assert approx_equal(tuple(bm.minus(d0)), (-1, -1))
  assert approx_equal(tuple(bm.additive_sigmas(d0)),
                      [math.sqrt(x*x+y*y) for x,y in ((1,2), (3,4))])
  assert approx_equal(tuple(bm.average(d0)), (3/2., 7/2.))
  h0.append((1,2,3))
  try: miller.match_bijvoet_mates(h0)
  except Exception: pass
  else: raise Exception_expected
Ejemplo n.º 3
0
def compare_ccp4_and_sgtbx(syminfo_data):
    for s in sgtbx.space_group_symbol_iterator():
        sg = sgtbx.space_group(s.hall())
        sg_type = sgtbx.space_group_type(sg)
        asu = sgtbx.reciprocal_space_asu(sg_type)
        sgtbx_hklasu = asu.reference_as_string().replace('==', '=')
        ccp4_hklasu = syminfo_data[s.number()]
        assert sgtbx_hklasu == ccp4_hklasu
        assert sgtbx_hklasu in hklasu_strings
Ejemplo n.º 4
0
def exercise_asu():
    sg_type = sgtbx.space_group_type("P 41")
    asu = sgtbx.reciprocal_space_asu(sg_type)
    miller_indices = flex.miller_index(((1, 2, 3), (3, 5, 0)))
    for h in miller_indices:
        h_eq = miller.sym_equiv_indices(sg_type.group(), h)
        for i_eq in xrange(h_eq.multiplicity(False)):
            h_i = h_eq(i_eq)
            for anomalous_flag in (False, True):
                a = miller.asym_index(sg_type.group(), asu, h_i.h())
                assert a.h() == h
                o = a.one_column(anomalous_flag)
                assert o.i_column() == 0
                t = a.two_column(anomalous_flag)
                assert t.h() == h
                assert (o.h() != h) == (t.i_column() == 1)
                assert not anomalous_flag or (t.i_column() !=
                                              0) == h_i.friedel_flag()
                assert anomalous_flag or t.i_column() == 0
    miller.map_to_asu(sg_type, False, miller_indices)
    data = flex.double((0, 0))
    miller.map_to_asu(sg_type, False, miller_indices, data)
    miller.map_to_asu(sg_type, False, miller_indices, data, False)
    miller.map_to_asu(sg_type, False, miller_indices, data, True)
    data = flex.complex_double((0, 0))
    miller.map_to_asu(sg_type, False, miller_indices, data)
    data = flex.hendrickson_lattman(((1, 2, 3, 4), (2, 3, 4, 5)))
    miller.map_to_asu(sg_type, False, miller_indices, data)
    for sg_symbol in ("P 41", "P 31 1 2"):
        exercise_map_to_asu(sg_symbol)
    #
    sg_type = sgtbx.space_group_type("P 2")
    miller_indices = flex.miller_index(((1, 2, 3), (-1, -2, -3)))
    assert not miller.is_unique_set_under_symmetry(
        space_group_type=sg_type,
        anomalous_flag=False,
        miller_indices=miller_indices)
    assert miller.is_unique_set_under_symmetry(space_group_type=sg_type,
                                               anomalous_flag=True,
                                               miller_indices=miller_indices)
    assert list(
        miller.unique_under_symmetry_selection(
            space_group_type=sg_type,
            anomalous_flag=False,
            miller_indices=miller_indices)) == [0]
    assert list(
        miller.unique_under_symmetry_selection(
            space_group_type=sg_type,
            anomalous_flag=True,
            miller_indices=miller_indices)) == [0, 1]
Ejemplo n.º 5
0
def exercise_asu():
  sg_type = sgtbx.space_group_type("P 41")
  asu = sgtbx.reciprocal_space_asu(sg_type)
  miller_indices = flex.miller_index(((1,2,3), (3,5,0)))
  for h in miller_indices:
    h_eq = miller.sym_equiv_indices(sg_type.group(), h)
    for i_eq in xrange(h_eq.multiplicity(False)):
      h_i = h_eq(i_eq)
      for anomalous_flag in (False,True):
        a = miller.asym_index(sg_type.group(), asu, h_i.h())
        assert a.h() == h
        o = a.one_column(anomalous_flag)
        assert o.i_column() == 0
        t = a.two_column(anomalous_flag)
        assert t.h() == h
        assert (o.h() != h) == (t.i_column() == 1)
        assert not anomalous_flag or (t.i_column() != 0) == h_i.friedel_flag()
        assert anomalous_flag or t.i_column() == 0
  miller.map_to_asu(sg_type, False, miller_indices)
  data = flex.double((0,0))
  miller.map_to_asu(sg_type, False, miller_indices, data)
  miller.map_to_asu(sg_type, False, miller_indices, data, False)
  miller.map_to_asu(sg_type, False, miller_indices, data, True)
  data = flex.complex_double((0,0))
  miller.map_to_asu(sg_type, False, miller_indices, data)
  data = flex.hendrickson_lattman(((1,2,3,4),(2,3,4,5)))
  miller.map_to_asu(sg_type, False, miller_indices, data)
  for sg_symbol in ("P 41", "P 31 1 2"):
    exercise_map_to_asu(sg_symbol)
  #
  sg_type = sgtbx.space_group_type("P 2")
  miller_indices = flex.miller_index(((1,2,3), (-1,-2,-3)))
  assert not miller.is_unique_set_under_symmetry(
    space_group_type=sg_type,
    anomalous_flag=False,
    miller_indices=miller_indices)
  assert miller.is_unique_set_under_symmetry(
    space_group_type=sg_type,
    anomalous_flag=True,
    miller_indices=miller_indices)
  assert list(miller.unique_under_symmetry_selection(
    space_group_type=sg_type,
    anomalous_flag=False,
    miller_indices=miller_indices)) == [0]
  assert list(miller.unique_under_symmetry_selection(
    space_group_type=sg_type,
    anomalous_flag=True,
    miller_indices=miller_indices)) == [0,1]
Ejemplo n.º 6
0
  def __init__(self, unmerged_intensities):
    self._intensities_original_index = unmerged_intensities

    self._observations = {}
    from cctbx import miller, sgtbx
    sg = self._intensities_original_index.space_group()
    sg_type = sg.type()
    asu = sgtbx.reciprocal_space_asu(sg_type)
    anomalous_flag = self._intensities_original_index.anomalous_flag()

    ma = self._intensities_original_index
    original_indices = ma.indices()
    unique_indices = original_indices.deep_copy()
    isym = flex.int(unique_indices.size())

    miller.map_to_asu_isym(sg_type, anomalous_flag, unique_indices, isym)

    n_plus, n_minus = 0, 0

    for iref in range(len(original_indices)):
      h_orig = original_indices[iref]
      h_uniq = unique_indices[iref]
      h_isym = isym[iref]

      h_eq = miller.sym_equiv_indices(sg, h_uniq)
      if h_eq.is_centric():
        flag = observation_group.CENTRIC
      else:
        asu_which = asu.which(h_uniq)
        assert asu_which != 0
        if asu_which == 1:
          flag = observation_group.PLUS
        else:
          flag = observation_group.MINUS
          h_uniq = tuple(-1*h for h in h_uniq)

      group = self._observations.get(h_uniq)
      if group is None:
        group = observation_group(
          h_uniq, is_centric=(flag == observation_group.CENTRIC))
        self._observations[h_uniq] = group
      if flag == observation_group.MINUS:
        n_minus += 1
        group.add_iminus(iref)
      else:
        n_plus += 1
        group.add_iplus(iref)
Ejemplo n.º 7
0
Archivo: PyChef.py Proyecto: xia2/xia2
  def __init__(self, unmerged_intensities):
    self._intensities_original_index = unmerged_intensities

    self._observations = {}
    from cctbx import miller, sgtbx
    sg = self._intensities_original_index.space_group()
    sg_type = sg.type()
    asu = sgtbx.reciprocal_space_asu(sg_type)
    anomalous_flag = self._intensities_original_index.anomalous_flag()

    ma = self._intensities_original_index
    original_indices = ma.indices()
    unique_indices = original_indices.deep_copy()
    isym = flex.int(unique_indices.size())

    miller.map_to_asu_isym(sg_type, anomalous_flag, unique_indices, isym)

    n_plus, n_minus = 0, 0

    for iref in range(len(original_indices)):
      h_orig = original_indices[iref]
      h_uniq = unique_indices[iref]
      h_isym = isym[iref]

      h_eq = miller.sym_equiv_indices(sg, h_uniq)
      if h_eq.is_centric():
        flag = observation_group.CENTRIC
      else:
        asu_which = asu.which(h_uniq)
        assert asu_which != 0
        if asu_which == 1:
          flag = observation_group.PLUS
        else:
          flag = observation_group.MINUS
          h_uniq = tuple(-1*h for h in h_uniq)

      group = self._observations.get(h_uniq)
      if group is None:
        group = observation_group(
          h_uniq, is_centric=(flag == observation_group.CENTRIC))
        self._observations[h_uniq] = group
      if flag == observation_group.MINUS:
        n_minus += 1
        group.add_iminus(iref)
      else:
        n_plus += 1
        group.add_iplus(iref)
Ejemplo n.º 8
0
def reference_map(sg, mi):
    from cctbx import sgtbx
    asu = sgtbx.reciprocal_space_asu(sg.type())
    isym_ = []
    mi_ = []

    for hkl in mi:
        found = False
        for i_inv in range(sg.f_inv()):
            for i_smx in range(sg.n_smx()):
                rt_mx = sg(0, i_inv, i_smx)
                hkl_ = intify(hkl * rt_mx.r())
                if asu.is_inside(hkl_):
                    mi_.append(hkl_)
                    if i_inv:
                        isym_.append(-i_smx)
                    else:
                        isym_.append(i_smx)
                    found = True
                    break

        if found:
            continue
        else:
            assert (not sg.is_centric())

        for i_inv in range(sg.f_inv()):
            for i_smx in range(sg.n_smx()):
                rt_mx = sg(0, i_inv, i_smx)
                _hkl = [-h for h in hkl]
                mhkl_ = intify(_hkl * rt_mx.r())
                if asu.is_inside(mhkl_):
                    mi_.append(mhkl_)
                    isym_.append(-i_smx)
                    found = True
                    break

    return mi_, isym_
Ejemplo n.º 9
0
def reference_map(sg, mi):
  from cctbx import sgtbx
  asu = sgtbx.reciprocal_space_asu(sg.type())
  isym_ = []
  mi_ = []

  for hkl in mi:
    found = False
    for i_inv in range(sg.f_inv()):
      for i_smx in range(sg.n_smx()):
        rt_mx = sg(0, i_inv, i_smx)
        hkl_ = intify(hkl * rt_mx.r())
        if asu.is_inside(hkl_):
          mi_.append(hkl_)
          if i_inv:
            isym_.append(- i_smx)
          else:
            isym_.append(i_smx)
          found = True
          break

    if found:
      continue
    else:
      assert(not sg.is_centric())

    for i_inv in range(sg.f_inv()):
      for i_smx in range(sg.n_smx()):
        rt_mx = sg(0, i_inv, i_smx)
        _hkl = [-h for h in hkl]
        mhkl_ = intify(_hkl * rt_mx.r())
        if asu.is_inside(mhkl_):
          mi_.append(mhkl_)
          isym_.append(- i_smx)
          found = True
          break

  return mi_, isym_
Ejemplo n.º 10
0
    spacegroup_number = -1

    for arg in sys.argv:
        if arg[-4:] == '.XDS':
            data = map(float, open(arg, 'r').read().split())
            spacegroup_number = int(data[26])

    if spacegroup_number == -1:
        raise RuntimeError, 'spacegroup number not found'

    # now generate a space group from this, via hall symbol, then
    # calculate the corresponding reciprocal space asymmetric unit
    
    spacegroup = sgtbx.space_group_symbols(spacegroup_number).hall()
    sg = sgtbx.space_group(spacegroup)
    asu = sgtbx.reciprocal_space_asu(sg.type())

    # and get the list of symmetry operations: these will be needed to
    # reduce the unmerged miller index to the asymmetric unit, as I've
    # not found a better way...

    for hkl_file in hkl_files:

        reflections = []
        
        fileno =int(hkl_file.replace('.hkl', '').split('-')[-1])
        dat_file = '%s.dat' % hkl_file[:-4]
        
        hkls = read_hkl(hkl_file)
        dats = read_dat(dat_file)
        hits = sorted_hits[fileno]