Beispiel #1
0
def get_hkl_offset_correlation_coefficients(
    dials_reflections,
    dials_crystal,
    map_to_asu=False,
    grid_h=0,
    grid_k=0,
    grid_l=0,
    reference=None,
):

    # N.B. deliberately ignoring d_min, d_max as these are inconsistent with
    # changing the miller indices

    from cctbx import sgtbx
    from cctbx.miller import set as miller_set

    from dials.array_family import flex

    cs = cctbx_crystal_from_dials(dials_crystal)
    ms = cctbx_i_over_sigi_ms_from_dials_data(dials_reflections, cs)

    if reference:
        reference_ms = cctbx_i_over_sigi_ms_from_dials_data(reference, cs)
    else:
        reference_ms = None

    ccs = flex.double()
    offsets = flex.vec3_int()
    nref = flex.size_t()

    if reference:
        cb_op = sgtbx.change_of_basis_op("x,y,z")
    else:
        cb_op = sgtbx.change_of_basis_op("-x,-y,-z")

    hkl_test = [
        (h, k, l)
        for h in range(-grid_h, grid_h + 1)
        for k in range(-grid_k, grid_k + 1)
        for l in range(-grid_l, grid_l + 1)
    ]

    for hkl in hkl_test:
        indices = offset_miller_indices(ms.indices(), hkl)
        reindexed_indices = cb_op.apply(indices)
        rms = miller_set(cs, reindexed_indices).array(ms.data())
        if reference_ms:
            _ms = reference_ms
        else:
            _ms = miller_set(cs, indices).array(ms.data())
        n, cc = compute_miller_set_correlation(_ms, rms, map_to_asu=map_to_asu)
        ccs.append(cc)
        offsets.append(hkl)
        nref.append(n)

    return offsets, ccs, nref
Beispiel #2
0
def get_hkl_offset_correlation_coefficients(
  dials_reflections, dials_crystal, map_to_asu=False,
  grid_h=0, grid_k=0, grid_l=0, reference=None):

  # N.B. deliberately ignoring d_min, d_max as these are inconsistent with
  # changing the miller indices

  from dials.array_family import flex
  from cctbx.miller import set as miller_set
  from cctbx import sgtbx

  cs = cctbx_crystal_from_dials(dials_crystal)
  ms = cctbx_i_over_sigi_ms_from_dials_data(dials_reflections, cs)

  if reference:
    reference_ms = cctbx_i_over_sigi_ms_from_dials_data(reference, cs)
  else:
    reference_ms = None

  ccs = flex.double()
  offsets = flex.vec3_int()
  nref = flex.size_t()

  if reference:
    cb_op = sgtbx.change_of_basis_op('x,y,z')
  else:
    cb_op = sgtbx.change_of_basis_op('-x,-y,-z')

  hkl_test = [(h, k, l) for h in range(-grid_h, grid_h + 1) \
                        for k in range(-grid_k, grid_k + 1) \
                        for l in range(-grid_l, grid_l + 1)]

  for hkl in hkl_test:
    indices = offset_miller_indices(ms.indices(), hkl)
    reindexed_indices = cb_op.apply(indices)
    rms = miller_set(cs, reindexed_indices).array(ms.data())
    if reference_ms:
      _ms = reference_ms
    else:
      _ms = miller_set(cs, indices).array(ms.data())
    n, cc = compute_miller_set_correlation(_ms, rms, map_to_asu=map_to_asu)
    ccs.append(cc)
    offsets.append(hkl)
    nref.append(n)

  return offsets, ccs, nref
Beispiel #3
0
def refls_to_hkl(refls,
                 detector,
                 beam,
                 crystal,
                 update_table=False,
                 returnQ=False):
    """
    convert pixel panel reflections to miller index data

    :param refls:  reflecton table for a panel or a tuple of (x,y)
    :param detector:  dxtbx detector model
    :param beam:  dxtbx beam model
    :param crystal: dxtbx crystal model
    :param update_table: whether to update the refltable
    :param returnQ: whether to return intermediately computed q vectors
    :return: if as_numpy two Nx3 numpy arrays are returned
        (one for fractional and one for whole HKL)
        else dictionary of hkl_i (nearest) and hkl (fractional)
    """
    if 'rlp' not in list(refls.keys()):
        q_vecs = refls_to_q(refls, detector, beam, update_table=update_table)
    else:
        q_vecs = np.vstack([r['rlp'] for r in refls])
    Ai = sqr(crystal.get_A()).inverse()
    Ai = Ai.as_numpy_array()
    HKL = np.dot(Ai, q_vecs.T)
    HKLi = map(lambda h: np.ceil(h - 0.5).astype(int), HKL)
    if update_table:
        refls['miller_index'] = flex.miller_index(len(refls), (0, 0, 0))
        mil_idx = flex.vec3_int(tuple(map(tuple, np.vstack(HKLi).T)))
        for i in range(len(refls)):
            refls['miller_index'][i] = mil_idx[i]
    if returnQ:
        return np.vstack(HKL).T, np.vstack(HKLi).T, q_vecs
    else:
        return np.vstack(HKL).T, np.vstack(HKLi).T