示例#1
0
文件: max_cell.py 项目: jmp1985/dials
def find_max_cell(
    reflections,
    max_cell_multiplier=1.3,
    step_size=45,
    nearest_neighbor_percentile=None,
    histogram_binning="linear",
    nn_per_bin=5,
    max_height_fraction=0.25,
    filter_ice=True,
    filter_overlaps=True,
    overlaps_border=0,
):
    logger.debug("Finding suitable max_cell based on %i reflections" %
                 len(reflections))
    # Exclude potential ice-ring spots from nearest neighbour analysis if needed
    if filter_ice:

        ice_sel = ice_rings_selection(reflections)
        reflections = reflections.select(~ice_sel)
        logger.debug("Rejecting %i reflections at ice ring resolution" %
                     ice_sel.count(True))

    # need bounding box in reflections to find overlaps; this is not there if
    # spots are from XDS (for example)
    if filter_overlaps and "bbox" in reflections:
        overlap_sel = flex.bool(len(reflections), False)

        overlaps = reflections.find_overlaps(border=overlaps_border)
        for item in overlaps.edges():
            i0 = overlaps.source(item)
            i1 = overlaps.target(item)
            overlap_sel[i0] = True
            overlap_sel[i1] = True
        logger.debug("Rejecting %i overlapping bounding boxes" %
                     overlap_sel.count(True))
        reflections = reflections.select(~overlap_sel)
    logger.debug("%i reflections remain for max_cell identification" %
                 len(reflections))

    if not len(reflections):
        raise DialsIndexError(
            "Too few spots remaining for nearest neighbour analysis (%d)" %
            len(reflections))

    NN = NeighborAnalysis(
        reflections,
        step_size=step_size,
        max_height_fraction=max_height_fraction,
        tolerance=max_cell_multiplier,
        percentile=nearest_neighbor_percentile,
        histogram_binning=histogram_binning,
        nn_per_bin=nn_per_bin,
    )

    return NN
示例#2
0
def test_estimate_resolution(centroid_test_data, tmpdir):
    experiments, reflections = centroid_test_data
    ice_sel = per_image_analysis.ice_rings_selection(reflections, width=0.004)
    assert ice_sel.count(True) == 76
    plot_file = tmpdir.join("i_over_sigi_vs_resolution.png")
    d_min = per_image_analysis.estimate_resolution_limit(
        reflections=reflections, plot_filename=plot_file.strpath)
    assert d_min == pytest.approx(1.446715534174674)
    assert plot_file.check()
    d_min = per_image_analysis.estimate_resolution_limit(
        reflections=reflections, ice_sel=ice_sel)
    assert d_min == pytest.approx(1.446715534174674)
示例#3
0
    def calculate_stats(self, verbose=False):
        # Only accept "good" spots based on specific parameters, if selected

        # 1. No ice
        if self.cfg.getboolean("spf_ice_filter"):
            ice_sel = per_image_analysis.ice_rings_selection(self.refl)
            spots_no_ice = self.refl.select(~ice_sel)
        else:
            spots_no_ice = self.refl

        # 2. Falls between 40 - 4.5A
        if self.cfg.getboolean('spf_good_spots_only'):
            res_lim_sel = self.filter_by_resolution(
                refl=spots_no_ice,
                d_min=self.cfg.getstr('spf_d_min'),
                d_max=self.cfg.getstr('spf_d_max'))
            good_spots = spots_no_ice.select(res_lim_sel)
        else:
            good_spots = spots_no_ice

        # Saturation / distance are already filtered by the spotfinder
        self.n_spots = good_spots.size()

        # Estimate resolution by spots that aren't ice (susceptible to poor ice ring
        # location)
        if self.n_spots > 10:
            self.hres = per_image_analysis.estimate_resolution_limit(spots_no_ice)
        else:
            self.hres = 99.9

        if verbose:
            print('SCORER: no. spots total = ', self.refl.size())
            if self.cfg.getboolean('spf_ice_filter'):
                print('SCORER: no. spots (no ice) = ', spots_no_ice.size())
                no_ice = 'no ice, '
            else:
                no_ice = ''
            if self.cfg.getboolean('spf_good_spots_only'):
                print('SCORER: no. spots ({}w/in res limits) = '.format(no_ice),
                      good_spots.size())