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]) 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()
def test_exercise_accumulators(xia2_regression): from xia2.Modules.PyChef2 import PyChef from xia2.Modules.PyChef2 import ChefStatistics from iotbx.reflection_file_reader import any_reflection_file from cctbx.array_family import flex from libtbx.test_utils import approx_equal import os f = os.path.join(xia2_regression, "test/insulin_dials_scaled_unmerged.mtz") reader = any_reflection_file(f) assert reader.file_type() == 'ccp4_mtz' arrays = reader.as_miller_arrays(merge_equivalents=False) for ma in arrays: if ma.info().labels == ['BATCH']: batches = ma elif ma.info().labels == ['I', 'SIGI']: intensities = ma elif ma.info().labels == ['I(+)', 'SIGI(+)', 'I(-)', 'SIGI(-)']: intensities = ma assert intensities is not None assert batches is not None anomalous_flag = True if anomalous_flag: intensities = intensities.as_anomalous_array() pystats = PyChef.PyStatistics(intensities, batches.data()) miller_indices = batches.indices() sg = batches.space_group() n_steps = pystats.n_steps dose = batches.data() range_width = 1 range_max = flex.max(dose) range_min = flex.min(dose) - range_width dose /= range_width dose -= range_min binner_non_anom = intensities.as_non_anomalous_array().use_binning( pystats.binner) n_complete = flex.size_t(binner_non_anom.counts_complete()[1:-1]) dose = flex.size_t(list(dose)) chef_stats = ChefStatistics(miller_indices, intensities.data(), intensities.sigmas(), intensities.d_star_sq().data(), dose, n_complete, pystats.binner, sg, anomalous_flag, n_steps) # test completeness assert approx_equal(chef_stats.iplus_completeness(), pystats.iplus_comp_overall) assert approx_equal(chef_stats.iminus_completeness(), pystats.iminus_comp_overall) assert approx_equal(chef_stats.ieither_completeness(), pystats.ieither_comp_overall) assert approx_equal(chef_stats.iboth_completeness(), pystats.iboth_comp_overall) # test rcp,scp assert approx_equal(chef_stats.rcp(), pystats.rcp) assert approx_equal(chef_stats.scp(), pystats.scp) # test Rd assert approx_equal(chef_stats.rd(), pystats.rd)
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()
def exercise_accumulators(): from xia2.Modules.PyChef2 import PyChef from xia2.Modules.PyChef2 import ChefStatistics from iotbx.reflection_file_reader import any_reflection_file from cctbx.array_family import flex import libtbx.load_env import os xia2_regression = libtbx.env.find_in_repositories("xia2_regression") if xia2_regression is None: print "Skipping exercise_accumulators(): xia2_regression not available" return f = os.path.join(xia2_regression, "test/insulin_dials_scaled_unmerged.mtz") reader = any_reflection_file(f) assert reader.file_type() == 'ccp4_mtz' arrays = reader.as_miller_arrays(merge_equivalents=False) for ma in arrays: if ma.info().labels == ['BATCH']: batches = ma elif ma.info().labels == ['I', 'SIGI']: intensities = ma elif ma.info().labels == ['I(+)', 'SIGI(+)', 'I(-)', 'SIGI(-)']: intensities = ma assert intensities is not None assert batches is not None anomalous_flag = True if anomalous_flag: intensities = intensities.as_anomalous_array() pystats = PyChef.PyStatistics(intensities, batches.data()) miller_indices = batches.indices() sg = batches.space_group() n_steps = pystats.n_steps dose = batches.data() range_width = 1 range_max = flex.max(dose) range_min = flex.min(dose) - range_width dose /= range_width dose -= range_min binner_non_anom = intensities.as_non_anomalous_array().use_binning( pystats.binner) n_complete = flex.size_t(binner_non_anom.counts_complete()[1:-1]) dose = flex.size_t(list(dose)) chef_stats = ChefStatistics( miller_indices, intensities.data(), intensities.sigmas(), intensities.d_star_sq().data(), dose, n_complete, pystats.binner, sg, anomalous_flag, n_steps) # test completeness assert approx_equal(chef_stats.iplus_completeness(), pystats.iplus_comp_overall) assert approx_equal(chef_stats.iminus_completeness(), pystats.iminus_comp_overall) assert approx_equal(chef_stats.ieither_completeness(), pystats.ieither_comp_overall) assert approx_equal(chef_stats.iboth_completeness(), pystats.iboth_comp_overall) # test rcp,scp assert approx_equal(chef_stats.rcp(), pystats.rcp) assert approx_equal(chef_stats.scp(), pystats.scp) # test Rd assert approx_equal(chef_stats.rd(), pystats.rd) print "OK"