def test_local_multiple_rotations(dials_data): """Test the fix for https://github.com/dials/dials/issues/1458""" experiments = load.experiment_list( dials_data("insulin_processed").join("indexed.expt"), check_format=False, ) # Override the scan range to ensure we have 4 full rotations experiments[0].scan.set_image_range((1, 1440)) # Generate some predicted reflections reflections = flex.reflection_table.from_predictions(experiments[0], dmin=4) reflections["imageset_id"] = flex.int(len(reflections), 0) reflections["id"] = flex.int(len(reflections), -1) reflections["xyzobs.px.value"] = reflections["xyzcal.px"] reflections["xyzobs.mm.value"] = reflections["xyzcal.mm"] predicted_miller_indices = reflections["miller_index"] # Prepare reflections for indexing reflections.centroid_px_to_mm(experiments) reflections.map_centroids_to_reciprocal_space(experiments) # Reset miller indices to ensure they are reindexed reflections["miller_index"] = flex.miller_index(len(reflections), (0, 0, 0)) # Assign indices with the correct scan oscillation AssignIndicesLocal()(reflections, experiments) # Assert we have correctly indexed all reflections assert (reflections["miller_index"] == (0, 0, 0)).count(True) == 0 assert (reflections["miller_index"] == predicted_miller_indices ).count(False) == 0 # Modify the scan oscillation such that we are out by 1 degree per rotation experiments[0].scan.set_oscillation((0, 1 - 1 / 360), deg=True) # Reset miller indices and re-map to reciprocal space reflections["miller_index"] = flex.miller_index(len(reflections), (0, 0, 0)) reflections["id"] = flex.int(len(reflections), -1) reflections.centroid_px_to_mm(experiments) reflections.map_centroids_to_reciprocal_space(experiments) # Assign indices, this time with the incorrect scan oscillation AssignIndicesLocal()(reflections, experiments) # Assert that most reflections have been indexed indexed_sel = reflections["miller_index"] == (0, 0, 0) assert indexed_sel.count(True) < 10 # Assert that all indexed miller indices are correct assert ((reflections["miller_index"] != predicted_miller_indices) & ~indexed_sel).count(True) == 0
def __init__(self, experiment, reflections, expected_miller_indices): index_reflections_global = AssignIndicesGlobal() index_reflections_local = AssignIndicesLocal() # index reflections using simple "global" method self.reflections_global = copy.deepcopy(reflections) self.reflections_global["id"] = flex.int(len(self.reflections_global), -1) self.reflections_global["imageset_id"] = flex.int( len(self.reflections_global), 0 ) index_reflections_global(self.reflections_global, ExperimentList([experiment])) non_zero_sel = self.reflections_global["miller_index"] != (0, 0, 0) assert self.reflections_global["id"].select(~non_zero_sel).all_eq(-1) self.misindexed_global = ( (expected_miller_indices == self.reflections_global["miller_index"]) .select(non_zero_sel) .count(False) ) self.correct_global = ( expected_miller_indices == self.reflections_global["miller_index"] ).count(True) # index reflections using xds-style "local" method self.reflections_local = copy.deepcopy(reflections) self.reflections_local["id"] = flex.int(len(self.reflections_local), -1) index_reflections_local(self.reflections_local, ExperimentList([experiment])) non_zero_sel = self.reflections_local["miller_index"] != (0, 0, 0) assert self.reflections_local["id"].select(~non_zero_sel).all_eq(-1) self.misindexed_local = ( (expected_miller_indices == self.reflections_local["miller_index"]) .select(non_zero_sel) .count(False) ) self.correct_local = ( expected_miller_indices == self.reflections_local["miller_index"] ).count(True) print( "Global misindexed: %d, correct: %d, total: %d" % ( self.misindexed_global, self.correct_global, len(self.reflections_global), ) ) print( " Local misindexed: %d, correct: %d, total: %d" % (self.misindexed_local, self.correct_local, len(self.reflections_local)) )