def test_minimum_multiplicity_selection():

    # some groups of indices with increasing multiplicity
    hkl = flex.miller_index([(0, 0, 1), (0, 0, 2), (0, 0, 2), (0, 0, 3),
                             (0, 0, 3), (0, 0, 3), (0, 0, 4), (0, 0, 4),
                             (0, 0, 4), (0, 0, 4), (0, 0, 5), (0, 0, 5),
                             (0, 0, 5), (0, 0, 5), (0, 0, 5)])

    # test the various possible selections with multiplicity from 1 to 6
    sel = minimum_multiplicity_selection(hkl, 1)
    assert sel.count(True) == len(hkl)

    sel = minimum_multiplicity_selection(hkl, 2)
    assert (sel == flex.bool([
        False,
    ] + [True] * 14)).all_eq(True)

    sel = minimum_multiplicity_selection(hkl, 3)
    assert (sel == flex.bool([False] * 3 + [True] * 12)).all_eq(True)

    sel = minimum_multiplicity_selection(hkl, 4)
    assert (sel == flex.bool([False] * 6 + [True] * 9)).all_eq(True)

    sel = minimum_multiplicity_selection(hkl, 5)
    assert (sel == flex.bool([False] * 10 + [True] * 5)).all_eq(True)

    sel = minimum_multiplicity_selection(hkl, 6)
    assert sel.count(False) == len(hkl)

    print "OK"
def test_minimum_multiplicity_selection():

  # some groups of indices with increasing multiplicity
  hkl = flex.miller_index(
        [(0,0,1),
         (0,0,2), (0,0,2),
         (0,0,3), (0,0,3), (0,0,3),
         (0,0,4), (0,0,4), (0,0,4), (0,0,4),
         (0,0,5), (0,0,5), (0,0,5), (0,0,5), (0,0,5)])

  # test the various possible selections with multiplicity from 1 to 6
  sel = minimum_multiplicity_selection(hkl, 1)
  assert sel.count(True) == len(hkl)

  sel = minimum_multiplicity_selection(hkl, 2)
  assert (sel == flex.bool([False,] + [True] * 14)).all_eq(True)

  sel = minimum_multiplicity_selection(hkl, 3)
  assert (sel == flex.bool([False] * 3 + [True] * 12)).all_eq(True)

  sel = minimum_multiplicity_selection(hkl, 4)
  assert (sel == flex.bool([False] * 6 + [True] * 9)).all_eq(True)

  sel = minimum_multiplicity_selection(hkl, 5)
  assert (sel == flex.bool([False] * 10 + [True] * 5)).all_eq(True)

  sel = minimum_multiplicity_selection(hkl, 6)
  assert sel.count(False) == len(hkl)

  print "OK"
    def __init__(self, reflections, experiment, params=None):

        if params is None:
            params = om_scope.extract()

        # initial filter
        reflections = reflections.select(
            reflections.get_flags(reflections.flags.integrated)
        )

        # create new column containing the reduced Miller index
        xl = experiment.crystal
        symm = cctbx.crystal.symmetry(
            xl.get_unit_cell(), space_group=xl.get_space_group()
        )
        hkl_set = cctbx.miller.set(symm, reflections["miller_index"])
        asu_set = hkl_set.map_to_asu()
        reflections["asu_miller_index"] = asu_set.indices()

        # sort table by reduced hkl
        reflections.sort("asu_miller_index")

        if params.observations.integration_type == "mix":
            raise Sorry("integration_type=mix is not supported yet")
        else:
            ikey = "intensity." + params.observations.integration_type + ".value"
            vkey = "intensity." + params.observations.integration_type + ".variance"

        # filters
        sel = reflections[vkey] > 0
        reflections = reflections.select(sel)
        if params.observations.i_over_sigma_cutoff > 0:
            ios = reflections[ikey] / flex.sqrt(reflections[vkey])
            sel = ios >= params.observations.i_over_sigma_cutoff
            reflections = reflections.select(sel)
        if params.observations.min_multiplicity > 0:
            sel = minimum_multiplicity_selection(
                reflections["asu_miller_index"], params.observations.min_multiplicity
            )
            reflections = reflections.select(sel)

        # extract columns of interest
        gp_idx = reflections["asu_miller_index"]
        intensity = reflections[ikey]
        weight = 1.0 / reflections[vkey]
        phi = reflections["xyzcal.mm"].parts()[2]
        scale = flex.double(len(reflections), 1.0)

        # set up reflection grouping object
        self._go = GroupedObservations(gp_idx, intensity, weight, phi, scale)

        return
Exemple #4
0
  def __init__(self, reflections, experiment, params=None):

    if params is None: params = om_scope.extract()

    # initial filter
    reflections = reflections.select(reflections.get_flags(
      reflections.flags.integrated))

    # create new column containing the reduced Miller index
    xl = experiment.crystal
    symm = cctbx.crystal.symmetry(xl.get_unit_cell(),
                                  space_group=xl.get_space_group())
    hkl_set = cctbx.miller.set(symm, reflections['miller_index'])
    asu_set = hkl_set.map_to_asu()
    reflections['asu_miller_index'] = asu_set.indices()

    # sort table by reduced hkl
    reflections.sort('asu_miller_index')

    if params.observations.integration_type == 'mix':
      raise Sorry('integration_type=mix is not supported yet')
    else:
      ikey = 'intensity.' + params.observations.integration_type + '.value'
      vkey = 'intensity.' + params.observations.integration_type + '.variance'

    # filters
    sel = reflections[vkey] > 0
    reflections = reflections.select(sel)
    if params.observations.i_over_sigma_cutoff > 0:
      ios = reflections[ikey] / flex.sqrt(reflections[vkey])
      sel = ios >= params.observations.i_over_sigma_cutoff
      reflections = reflections.select(sel)
    if params.observations.min_multiplicity > 0:
      sel = minimum_multiplicity_selection(reflections['asu_miller_index'],
        params.observations.min_multiplicity)
      reflections = reflections.select(sel)

    # extract columns of interest
    gp_idx = reflections['asu_miller_index']
    intensity = reflections[ikey]
    weight = 1. / reflections[vkey]
    phi = reflections['xyzcal.mm'].parts()[2]
    scale = flex.double(len(reflections), 1.0)

    # set up reflection grouping object
    self._go = GroupedObservations(gp_idx, intensity, weight, phi, scale)

    return