def test_for_reflection_table(data): from dials.algorithms.spot_prediction import ( ScanStaticReflectionPredictor, ScanVaryingReflectionPredictor, ) from dials.array_family import flex predict = ScanStaticReflectionPredictor(data.experiments[0]) preds = predict.for_ub(data.experiments[0].crystal.get_A()) preds["ub_matrix"] = flex.mat3_double(len(preds), data.experiments[0].crystal.get_A()) preds["s0"] = flex.vec3_double(len(preds), data.experiments[0].beam.get_s0()) preds["d_matrix"] = flex.mat3_double(len(preds)) preds["S_matrix"] = flex.mat3_double( len(preds), data.experiments[0].goniometer.get_setting_rotation()) for ipanel, panel in enumerate(data.experiments[0].detector): sel = preds["panel"] == ipanel D = panel.get_d_matrix() preds["d_matrix"].set_selected(sel, D) predict = ScanVaryingReflectionPredictor(data.experiments[0]) old_preds = copy.deepcopy(preds) predict.for_reflection_table(preds, preds["ub_matrix"], preds["s0"], preds["d_matrix"], preds["S_matrix"]) # Because UB, s0, d and S values are the same for all reflections, the new # reflections should be approx equal to those produced by the scan static # predictor old_x, old_y, old_z = old_preds["xyzcal.px"].parts() new_x, new_y, new_z = preds["xyzcal.px"].parts() assert old_x.all_approx_equal(new_x) assert old_y.all_approx_equal(new_y) assert old_z.all_approx_equal(new_z)
def test_with_old_index_generator(data): from dials.algorithms.spot_prediction import ScanStaticReflectionPredictor from dials.array_family import flex predict = ScanStaticReflectionPredictor(data.experiments[0]) r_old = predict.for_ub_old_index_generator( data.experiments[0].crystal.get_A()) r_new = predict.for_ub(data.experiments[0].crystal.get_A()) index1 = flex.size_t( sorted(range(len(r_old)), key=lambda x: r_old["miller_index"][x])) index2 = flex.size_t( sorted(range(len(r_new)), key=lambda x: r_new["miller_index"][x])) r_old = r_old.select(index1) r_new = r_new.select(index2) assert len(r_old) == len(r_new) for r1, r2 in zip(r_old.rows(), r_new.rows()): assert r1["miller_index"] == r2["miller_index"] assert r1["panel"] == r2["panel"] assert r1["entering"] == r2["entering"] assert all(a == pytest.approx(b, abs=1e-7) for a, b in zip(r1["s1"], r2["s1"])) assert all(a == pytest.approx(b, abs=1e-7) for a, b in zip(r1["xyzcal.px"], r2["xyzcal.px"])) assert all(a == pytest.approx(b, abs=1e-7) for a, b in zip(r1["xyzcal.mm"], r2["xyzcal.mm"]))
def tst_with_old_index_generator(self): from dials.algorithms.spot_prediction import ScanStaticReflectionPredictor from dials.array_family import flex predict = ScanStaticReflectionPredictor(self.experiments[0]) r_old = predict.for_ub_old_index_generator( self.experiments[0].crystal.get_A()) r_new = predict.for_ub(self.experiments[0].crystal.get_A()) index1 = flex.size_t( sorted(range(len(r_old)), key=lambda x: r_old['miller_index'][x])) index2 = flex.size_t( sorted(range(len(r_new)), key=lambda x: r_new['miller_index'][x])) r_old = r_old.select(index1) r_new = r_new.select(index2) assert (len(r_old) == len(r_new)) eps = 1e-7 for r1, r2 in zip(r_old.rows(), r_new.rows()): assert (r1['miller_index'] == r2['miller_index']) assert (r1['panel'] == r2['panel']) assert (r1['entering'] == r2['entering']) assert (all(abs(a - b) < eps for a, b in zip(r1['s1'], r2['s1']))) assert (all( abs(a - b) < eps for a, b in zip(r1['xyzcal.px'], r2['xyzcal.px']))) assert (all( abs(a - b) < eps for a, b in zip(r1['xyzcal.mm'], r2['xyzcal.mm']))) print 'OK'
def predict_new(self, experiment=None, hkl=None, panel=None): from dials.algorithms.spot_prediction import ScanStaticReflectionPredictor if experiment is None: experiment = self.experiments[0] predict = ScanStaticReflectionPredictor(experiment) if hkl is None: return predict.for_ub(experiment.crystal.get_A()) else: if panel is None: return predict(hkl) else: return predict(hkl, panel)
def predict_new(self, experiment=None, hkl=None, panel=None): from dials.algorithms.spot_prediction import ScanStaticReflectionPredictor if experiment is None: experiment=self.experiments[0] predict = ScanStaticReflectionPredictor(experiment) if hkl is None: return predict.for_ub(experiment.crystal.get_A()) else: if panel is None: return predict(hkl) else: return predict(hkl, panel)
def test_connected_components_centred_cell(dials_data): experiment = ExperimentList.from_file( dials_data("insulin_processed").join("scaled.expt").strpath, check_format=False )[0] experiment.scan.set_image_range((1, 10)) predict = ScanStaticReflectionPredictor(experiment, dmin=3, margin=1) refl = predict.for_ub(experiment.crystal.get_A()) miller_set = miller.set( experiment.crystal.get_crystal_symmetry(), refl["miller_index"], anomalous_flag=False, ) miller_array = miller_set.d_spacings().resolution_filter(d_min=3) complete_set, unique_ms = missing_reflections.connected_components(miller_array) assert [ms.size() for ms in unique_ms] == [581, 32, 29, 6, 3, 3, 3, 2] # Verify that all the indices reported missing are actually missing from the input for ms in unique_ms: assert ms.common_set(miller_array.map_to_asu()).size() == 0 assert complete_set.completeness() == 1
def tst_for_reflection_table(self): from libtbx.test_utils import approx_equal from dials.algorithms.spot_prediction import \ ScanVaryingReflectionPredictor, ScanStaticReflectionPredictor from dials.array_family import flex predict = ScanStaticReflectionPredictor(self.experiments[0]) preds = predict.for_ub(self.experiments[0].crystal.get_A()) preds['ub_matrix'] = flex.mat3_double(len(preds), self.experiments[0].crystal.get_A()) preds['s0'] = flex.vec3_double(len(preds), self.experiments[0].beam.get_s0()) preds['d_matrix'] = flex.mat3_double(len(preds)) preds['S_matrix'] = flex.mat3_double(len(preds), self.experiments[0].goniometer.get_setting_rotation()) for ipanel, panel in enumerate(self.experiments[0].detector): sel = preds['panel'] == ipanel D = panel.get_d_matrix() preds['d_matrix'].set_selected(sel, D) predict = ScanVaryingReflectionPredictor(self.experiments[0]) from copy import deepcopy old_preds = deepcopy(preds) predict.for_reflection_table(preds, preds['ub_matrix'], preds['s0'], preds['d_matrix'], preds['S_matrix']) # Because UB, s0, d and S values are the same for all reflections, the new # reflections should be approx equal to those produced by the scan static # predictor old_x, old_y, old_z = old_preds['xyzcal.px'].parts() new_x, new_y, new_z = preds['xyzcal.px'].parts() assert old_x.all_approx_equal(new_x) assert old_y.all_approx_equal(new_y) assert old_z.all_approx_equal(new_z) print "OK" return
def test_connected_components(dials_data): experiment = ExperimentList.from_file( dials_data("centroid_test_data").join("experiments.json").strpath )[0] image_ranges = [(1, 9), (1, 100), (1, 1000)] expected_ms_sizes = [[755], [242, 14, 10, 5, 2, 2, 2], []] for image_range, expected_sizes in zip(image_ranges, expected_ms_sizes): experiment.scan.set_image_range(image_range) predict = ScanStaticReflectionPredictor(experiment, dmin=3, margin=1) refl = predict.for_ub(experiment.crystal.get_A()) miller_set = miller.set( experiment.crystal.get_crystal_symmetry(), refl["miller_index"], anomalous_flag=False, ) miller_array = miller_set.d_spacings().resolution_filter(d_min=3) complete_set, unique_ms = missing_reflections.connected_components(miller_array) assert len(unique_ms) == len(expected_sizes) assert [ms.size() for ms in unique_ms] == expected_sizes # Verify that all the indices reported missing are actually missing from the input for ms in unique_ms: assert ms.common_set(miller_array.map_to_asu()).size() == 0 assert complete_set.completeness() == 1
def tst_for_reflection_table(self): from libtbx.test_utils import approx_equal from dials.algorithms.spot_prediction import \ ScanVaryingReflectionPredictor, ScanStaticReflectionPredictor from dials.array_family import flex predict = ScanStaticReflectionPredictor(self.experiments[0]) preds = predict.for_ub(self.experiments[0].crystal.get_A()) preds['ub_matrix'] = flex.mat3_double(len(preds), self.experiments[0].crystal.get_A()) preds['s0'] = flex.vec3_double(len(preds), self.experiments[0].beam.get_s0()) preds['d_matrix'] = flex.mat3_double(len(preds)) for ipanel, panel in enumerate(self.experiments[0].detector): sel = preds['panel'] == ipanel D = panel.get_d_matrix() preds['d_matrix'].set_selected(sel, D) predict = ScanVaryingReflectionPredictor(self.experiments[0]) from copy import deepcopy old_preds = deepcopy(preds) predict.for_reflection_table(preds, preds['ub_matrix'], preds['s0'], preds['d_matrix']) # Because UB, s0 and d values are the same for all reflections, the new # reflections should be approx equal to those produced by the scan static # predictor old_x, old_y, old_z = old_preds['xyzcal.px'].parts() new_x, new_y, new_z = preds['xyzcal.px'].parts() assert old_x.all_approx_equal(new_x) assert old_y.all_approx_equal(new_y) assert old_z.all_approx_equal(new_z) print "OK" return