Exemplo n.º 1
0
class StillsReflectionManager(ReflectionManager):
    """Overloads for a Reflection Manager that does not exclude
    reflections too close to the spindle, and reports only information
    about X, Y, DelPsi residuals"""

    _weighting_strategy = weighting_strategies.StillsWeightingStrategy()
    experiment_type = "stills"

    def _id_refs_to_keep(self, obs_data):
        """Create a selection of observations that pass certain conditions.

        Stills-specific version removes checks relevant only to experiments
        with a rotation axis."""

        # first exclude reflections with miller index set to 0,0,0
        sel1 = obs_data["miller_index"] != (0, 0, 0)

        # exclude reflections with overloads, as these have worse centroids
        sel2 = ~obs_data.get_flags(obs_data.flags.overloaded)

        # combine selections
        sel = sel1 & sel2
        inc = flex.size_t_range(len(obs_data)).select(sel)

        return inc

    def print_stats_on_matches(self):
        """Print some basic statistics on the matches"""

        l = self.get_matches()
        nref = len(l)
        if nref == 0:
            logger.warning(
                "Unable to calculate summary statistics for zero observations"
            )
            return

        from scitbx.math import five_number_summary

        try:
            x_resid = l["x_resid"]
            y_resid = l["y_resid"]
            delpsi = l["delpsical.rad"]
            w_x, w_y, _ = l["xyzobs.mm.weights"].parts()
            w_delpsi = l["delpsical.weights"]
        except KeyError:
            return

        header = ["", "Min", "Q1", "Med", "Q3", "Max"]
        rows = []
        row_data = five_number_summary(x_resid)
        rows.append(["Xc - Xo (mm)"] + ["%.4g" % e for e in row_data])
        row_data = five_number_summary(y_resid)
        rows.append(["Yc - Yo (mm)"] + ["%.4g" % e for e in row_data])
        row_data = five_number_summary(delpsi)
        rows.append(["DeltaPsi (deg)"] + ["%.4g" % (e * RAD2DEG) for e in row_data])
        row_data = five_number_summary(w_x)
        rows.append(["X weights"] + ["%.4g" % e for e in row_data])
        row_data = five_number_summary(w_y)
        rows.append(["Y weights"] + ["%.4g" % e for e in row_data])
        row_data = five_number_summary(w_delpsi)
        rows.append(
            ["DeltaPsi weights"] + ["%.4g" % (e * DEG2RAD ** 2) for e in row_data]
        )

        msg = (
            "\nSummary statistics for {} observations".format(nref)
            + " matched to predictions:"
        )
        logger.info(msg)
        logger.info(dials.util.tabulate(rows, header) + "\n")
Exemplo n.º 2
0
class StillsReflectionManager(ReflectionManager):
    """Overloads for a Reflection Manager that does not exclude
  reflections too close to the spindle, and reports only information
  about X, Y, DelPsi residuals"""

    _weighting_strategy = weighting_strategies.StillsWeightingStrategy()

    def print_stats_on_matches(self):
        """Print some basic statistics on the matches"""

        l = self.get_matches()
        nref = len(l)

        from libtbx.table_utils import simple_table
        from scitbx.math import five_number_summary
        x_resid = l['x_resid']
        y_resid = l['y_resid']
        delpsi = l['delpsical.rad']
        w_x, w_y, _ = l['xyzobs.mm.weights'].parts()
        w_delpsi = l['delpsical.weights']

        msg = "\nSummary statistics for {0} observations".format(nref) +\
              " matched to predictions:"
        header = ["", "Min", "Q1", "Med", "Q3", "Max"]
        rows = []
        try:
            row_data = five_number_summary(x_resid)
            rows.append(["Xc - Xo (mm)"] + ["%.4g" % e for e in row_data])
            row_data = five_number_summary(y_resid)
            rows.append(["Yc - Yo (mm)"] + ["%.4g" % e for e in row_data])
            row_data = five_number_summary(delpsi)
            rows.append(["DeltaPsi (deg)"] +
                        ["%.4g" % (e * RAD2DEG) for e in row_data])
            row_data = five_number_summary(w_x)
            rows.append(["X weights"] + ["%.4g" % e for e in row_data])
            row_data = five_number_summary(w_y)
            rows.append(["Y weights"] + ["%.4g" % e for e in row_data])
            row_data = five_number_summary(w_delpsi)
            rows.append(["DeltaPsi weights"] +
                        ["%.4g" % (e * DEG2RAD**2) for e in row_data])
        except IndexError:
            # zero length reflection list
            logger.warning(
                "Unable to calculate summary statistics for zero observations")
            return
        logger.info(msg)
        st = simple_table(rows, header)
        logger.info(st.format())
        logger.info("")

        # sorting is expensive and the following table is only of interest in
        # special cases, so return now if verbosity is not high
        if self._verbosity < 3: return

        if nref < 20:
            logger.debug("Fewer than 20 reflections matched!")
            return

        sl = self._sort_obs_by_residual(l)
        logger.debug("Reflections with the worst 20 positional residuals:")
        header = [
            'Miller index', 'x_resid', 'y_resid', 'pnl', 'x_obs', 'y_obs',
            'x_obs\nweight', 'y_obs\nweight'
        ]
        rows = []
        for i in xrange(20):
            e = sl[i]
            x_obs, y_obs, _ = e['xyzobs.mm.value']
            rows.append([
                '% 3d, % 3d, % 3d' % e['miller_index'],
                '%5.3f' % e['x_resid'],
                '%5.3f' % e['y_resid'],
                '%d' % e['panel'],
                '%5.3f' % x_obs,
                '%5.3f' % y_obs,
                '%5.3f' % e['xyzobs.mm.weights'][0],
                '%5.3f' % e['xyzobs.mm.weights'][1]
            ])
        logger.debug(simple_table(rows, header).format())
        logger.debug("")

        return