def test_stats_per_image(centroid_test_data): experiments, reflections = centroid_test_data stats = per_image_analysis.stats_per_image(experiments[0], reflections) result = stats._asdict() for v in result.values(): assert len(v) == len(experiments[0].scan) assert stats.n_spots_total == [90, 100, 67, 49, 54, 62, 68, 83, 81] t = stats.as_table() assert len(t) == len(experiments[0].scan) + 1 assert t[0] == [ "image", "#spots", "#spots_no_ice", "total_intensity", "d_min", "d_min (distl method 1)", "d_min (distl method 2)", ] assert t[1] == ["1", "90", "77", "28214", "1.56", "2.08 (0.09)", "1.59 (0.27)"] # Test n_rows option t = stats.as_table(n_rows=3) assert len(t) == 4 # Test perm option perm = flex.random_permutation(len(experiments[0].scan)) t = stats.as_table(perm=perm) assert [tt[0] for tt in t[1:]] == [str(i + 1) for i in perm]
def setup(request): space_group_symbol = request.param sgi = sgtbx.space_group_info(space_group_symbol) cs = sgi.any_compatible_crystal_symmetry(volume=random.randint(1e4, 1e6)) ms = cs.build_miller_set(anomalous_flag=True, d_min=3).expand_to_p1() # the reciprocal matrix B = scitbx.matrix.sqr(cs.unit_cell().fractionalization_matrix()).transpose() # randomly select 25% of reflections ms = ms.select(flex.random_permutation(ms.size())[: int(0.25 * ms.size())]) refl = flex.reflection_table() refl["rlp"] = B.elems * ms.indices().as_vec3_double() refl["imageset_id"] = flex.int(len(refl)) refl["xyzobs.mm.value"] = flex.vec3_double(len(refl)) d = {} d["crystal_symmetry"] = cs d["reflections"] = refl return d
def split_reflections(experiments, reflections, params): """Split reflections into equal sized groups, ensuring that each unique Miller index is split proportionately""" # Check the space group is the same for all experiments sg = experiments[0].crystal.get_space_group() if not all((e.crystal.get_space_group() == sg for e in experiments)): raise RuntimeError("Not all space groups are equal") # create new column containing the reduced Miller index xl = experiments[0].crystal symm = cctbx.crystal.symmetry(xl.get_unit_cell(), space_group=sg) hkl_set = cctbx.miller.set(symm, reflections["miller_index"]) asu_set = hkl_set.map_to_asu() reflections["asu_miller_index"] = asu_set.indices() # Set up a cycle through sets and a column to store values cyc = cycle(range(params.N)) reflections["disjoint_set"] = flex.size_t(len(reflections)) # Loop over unique Miller indices and split matching reflections into sets for uniq in set(asu_set.indices()): sel = (reflections["miller_index"] == uniq).iselection() vals = flex.size_t(next(cyc) for i in sel) vals = vals.select(flex.random_permutation(len(vals))) reflections["disjoint_set"].set_selected(sel, vals) # Now split the table splits = [] for i in range(params.N): subset = reflections.select(reflections["disjoint_set"] == i) del subset["disjoint_set"] splits.append(subset) # Write out the splits for i, refls in enumerate(splits): fname = (params.output.reflections_prefix + "_{:d}_of_{:d}".format(i + 1, len(splits)) + ".refl") logger.info("Writing {:d} reflections to {}".format(len(refls), fname)) refls.as_file(fname)
def run(args): user_phil = [] for arg in args: if os.path.isfile(arg): filename = arg else: try: user_phil.append(parse(arg)) except Exception as e: raise Sorry("Unrecognized argument: %s" % arg) params = phil_scope.fetch(sources=user_phil).extract() name = os.path.basename(filename) base, ext = os.path.splitext(name) filea = base + "_a" + ext fileb = base + "_b" + ext data = easy_pickle.load(filename) if params.use_selection is None: sel = flex.random_permutation(len(data)) else: sel = easy_pickle.load(params.use_selection) assert len(sel) == len( data), "Length of selection doesn't match length of input" data_a = data.select(sel[:len(data) // 2]) data_b = data.select(sel[len(data) // 2:]) data_a = data_a.select(flex.sort_permutation(data_a["id"])) data_b = data_b.select(flex.sort_permutation(data_b["id"])) assert len(data_a) + len(data_b) == len(data) easy_pickle.dump(filea, data_a) easy_pickle.dump(fileb, data_b) if params.output_selection is not None: easy_pickle.dump(params.output_selection, sel)
def update_minimum_covering_sphere(self): n_points = min(1000, self.points.size()) isel = flex.random_permutation(self.points.size())[:n_points] self.minimum_covering_sphere = minimum_covering_sphere( self.points.select(isel))