Exemplo n.º 1
0
    def __init__(self,
                 intensities,
                 dose,
                 n_bins=8,
                 range_min=None,
                 range_max=None,
                 range_width=1):

        if isinstance(dose, flex.double):
            sorted_dose = flex.sorted(dose)
            dd = sorted_dose[1:] - sorted_dose[:-1]
            dd = dd.select(dd > 0)
            if len(dd):
                step_size = flex.min(dd)
                dose /= step_size
            dose = dose.iround()
            if flex.min(dose) == 0:
                dose += 1

        # fix for completeness > 1 if screw axes present
        intensities = intensities.customized_copy(
            space_group_info=intensities.space_group().
            build_derived_reflection_intensity_group(
                anomalous_flag=intensities.anomalous_flag()).info(),
            info=intensities.info(),
        )

        self.intensities = intensities
        self.dose = dose
        self.n_bins = n_bins
        self.range_min = range_min
        self.range_max = range_max
        self.range_width = range_width
        assert self.range_width > 0

        if self.range_min is None:
            self.range_min = flex.min(self.dose) - self.range_width
        if self.range_max is None:
            self.range_max = flex.max(self.dose)
        self.n_steps = 2 + int((self.range_max - self.range_min) -
                               self.range_width)

        sel = (self.dose.as_double() <=
               self.range_max) & (self.dose.as_double() >= self.range_min)
        self.dose = self.dose.select(sel)

        self.intensities = self.intensities.select(sel)
        self.d_star_sq = self.intensities.d_star_sq().data()

        self.binner = self.intensities.setup_binner_d_star_sq_step(
            d_star_sq_step=(flex.max(self.d_star_sq) -
                            flex.min(self.d_star_sq) + 1e-8) / self.n_bins)

        # self.dose /= range_width
        self.dose -= int(self.range_min)

        self.dose = flex.size_t(list(self.dose))

        binner_non_anom = intensities.as_non_anomalous_array().use_binning(
            self.binner)
        n_complete = flex.size_t(binner_non_anom.counts_complete()[1:-1])

        chef_stats = ChefStatistics(
            intensities.indices(),
            intensities.data(),
            intensities.sigmas(),
            intensities.d_star_sq().data(),
            self.dose,
            n_complete,
            self.binner,
            intensities.space_group(),
            intensities.anomalous_flag(),
            self.n_steps,
        )

        self.iplus_comp_bins = chef_stats.iplus_completeness_bins()
        self.iminus_comp_bins = chef_stats.iminus_completeness_bins()
        self.ieither_comp_bins = chef_stats.ieither_completeness_bins()
        self.iboth_comp_bins = chef_stats.iboth_completeness_bins()
        self.iplus_comp_overall = chef_stats.iplus_completeness()
        self.iminus_comp_overall = chef_stats.iminus_completeness()
        self.ieither_comp_overall = chef_stats.ieither_completeness()
        self.iboth_comp_overall = chef_stats.iboth_completeness()
        self.rcp_bins = chef_stats.rcp_bins()
        self.rcp = chef_stats.rcp()
        self.scp_bins = chef_stats.scp_bins()
        self.scp = chef_stats.scp()
        self.rd = chef_stats.rd()
Exemplo n.º 2
0
Arquivo: PyChef.py Projeto: xia2/xia2
  def __init__(self, intensities, dose, n_bins=8,
               range_min=None, range_max=None, range_width=1):

    if isinstance(dose, flex.double):
      sorted_dose = flex.sorted(dose)
      dd = sorted_dose[1:] - sorted_dose[:-1]
      step_size = flex.min(dd.select(dd > 0))
      dose /= step_size
      dose = dose.iround()
      if flex.min(dose) == 0:
        dose += 1

    # fix for completeness > 1 if screw axes present
    intensities = intensities.customized_copy(
      space_group_info=intensities.space_group().build_derived_reflection_intensity_group(
        anomalous_flag=intensities.anomalous_flag()).info(),
      info=intensities.info())

    self.intensities = intensities
    self.dose = dose
    self.n_bins = n_bins
    self.range_min = range_min
    self.range_max = range_max
    self.range_width = range_width
    assert self.range_width > 0

    if self.range_min is None:
      self.range_min = flex.min(self.dose) - self.range_width
    if self.range_max is None:
      self.range_max = flex.max(self.dose)
    self.n_steps = 2 + int((self.range_max - self.range_min) - self.range_width)

    sel = (self.dose.as_double() <= self.range_max) & (self.dose.as_double() >= self.range_min)
    self.dose = self.dose.select(sel)

    self.intensities = self.intensities.select(sel)
    self.d_star_sq = self.intensities.d_star_sq().data()

    self.binner = self.intensities.setup_binner_d_star_sq_step(
      d_star_sq_step=(flex.max(self.d_star_sq)-flex.min(self.d_star_sq)+1e-8)/self.n_bins)

    #self.dose /= range_width
    self.dose -= int(self.range_min)

    self.dose = flex.size_t(list(self.dose))

    binner_non_anom = intensities.as_non_anomalous_array().use_binning(
      self.binner)
    n_complete = flex.size_t(binner_non_anom.counts_complete()[1:-1])

    from xia2.Modules.PyChef2 import ChefStatistics
    chef_stats = ChefStatistics(
      intensities.indices(), intensities.data(), intensities.sigmas(),
      intensities.d_star_sq().data(), self.dose, n_complete, self.binner,
      intensities.space_group(), intensities.anomalous_flag(), self.n_steps)

    self.iplus_comp_bins = chef_stats.iplus_completeness_bins()
    self.iminus_comp_bins = chef_stats.iminus_completeness_bins()
    self.ieither_comp_bins = chef_stats.ieither_completeness_bins()
    self.iboth_comp_bins = chef_stats.iboth_completeness_bins()
    self.iplus_comp_overall = chef_stats.iplus_completeness()
    self.iminus_comp_overall = chef_stats.iminus_completeness()
    self.ieither_comp_overall = chef_stats.ieither_completeness()
    self.iboth_comp_overall = chef_stats.iboth_completeness()
    self.rcp_bins = chef_stats.rcp_bins()
    self.rcp = chef_stats.rcp()
    self.scp_bins = chef_stats.scp_bins()
    self.scp = chef_stats.scp()
    self.rd = chef_stats.rd()