def test_gaussianrs_reference_profile_calculator(data): from dials.algorithms.profile_model.gaussian_rs.algorithm import ( GaussianRSReferenceCalculatorFactory, ) algorithm = GaussianRSReferenceCalculatorFactory.create(data.experiments) reflections = flex.reflection_table_to_list_of_reflections( data.reflections) count = 0 for r in reflections: try: algorithm(r) except Exception: count += 1 assert len(reflections) == 15193 assert count == 0 profiles = algorithm.reference_profiles() count = 0 for i in range(len(profiles)): p = profiles[i].reference() for j in range(len(p)): d = p.data(j) p.mask(j) if len(d) != 0: count += 1 assert count == 9
def test_gaussianrs_detector_space_with_deconvolution_intensity_calculator( data): algorithm = IntensityCalculatorFactory.create(data, detector_space=True, deconvolution=True) reflections = flex.reflection_table_to_list_of_reflections( data.reflections) count = 0 for r in reflections: try: algorithm(r, []) partiality_old = r.get("partiality_old") partiality_new = r.get("partiality") except Exception as e: count += 1 continue assert partiality_old < 1.0 and partiality_old >= 0 assert partiality_new < 1.0 and partiality_new >= 0 assert len(reflections) == 15193 assert count == 4802
def test_gaussianrs_mask_calculator(data): from dials.algorithms.integration.parallel_integrator import MaskCalculatorFactory algorithm = MaskCalculatorFactory.create(data.experiments) reflections = flex.reflection_table_to_list_of_reflections(data.reflections) for r in reflections: algorithm(r, False)
def test_gaussianrs_detector_space_with_deconvolution_intensity_calculator(data): algorithm = IntensityCalculatorFactory.create( data, detector_space=True, deconvolution=True ) reflections = flex.reflection_table_to_list_of_reflections(data.reflections) errors = 0 for r in reflections: try: algorithm(r, []) partiality_old = r.get("partiality_old") partiality_new = r.get("partiality") except Exception as e: if ("Partiality too small to fit" in str(e)) or ( "DIALS_ASSERT(fit.niter() < 100) failure." in str(e) ): errors += 1 continue raise assert partiality_old < 1.0 and partiality_old >= 0 assert partiality_new < 1.0 and partiality_new >= 0 assert len(reflections) == 15193 assert errors == 4802
def test_glm_background_calculator(): from dials.algorithms.background.glm.algorithm import GLMBackgroundCalculatorFactory algorithm = GLMBackgroundCalculatorFactory.create(data.experiments) reflections = flex.reflection_table_to_list_of_reflections(data.reflections) count = 0 for r in reflections: try: algorithm(r) except Exception: count += 1 assert len(reflections) == 15193 assert count == 333
def test_simple_background_calculator(data): from dials.algorithms.background.simple.algorithm import ( SimpleBackgroundCalculatorFactory, ) algorithm = SimpleBackgroundCalculatorFactory.create(data.experiments) reflections = flex.reflection_table_to_list_of_reflections( data.reflections) errors = 0 for r in reflections: try: algorithm(r) except Exception: errors += 1 assert len(reflections) == 15193 assert errors == 333
def test_gaussianrs_reciprocal_space_intensity_calculator(data): algorithm = IntensityCalculatorFactory.create( data, detector_space=False, deconvolution=False ) reflections = flex.reflection_table_to_list_of_reflections(data.reflections) errors = 0 for r in reflections: try: algorithm(r, []) except Exception: errors += 1 assert len(reflections) == 15193 assert errors == 5296
def test_gaussianrs_detector_space_with_deconvolution_intensity_calculator2( data): from scitbx import matrix reflections = flex.reflection_table_to_list_of_reflections( data.reflections) R = None for r in reflections: if r.get("partiality") > 0.9 and r.get("intensity.sum.value") > 100: R = r break assert R is not None px = R.get("xyzcal.px") mm = R.get("xyzcal.mm") px1 = (px[0] - 3, px[1] - 3, px[2]) px2 = (px[0] + 3, px[1] + 3, px[2]) mm1 = (mm[0] - 3 * 0.172, mm[1] - 3 * 0.172, mm[2]) mm2 = (mm[0] + 3 * 0.172, mm[1] + 3 * 0.172, mm[2]) s11 = matrix.col(data.experiments[0].detector[0].get_pixel_lab_coord( px1[0:2])).normalize() s12 = matrix.col(data.experiments[0].detector[0].get_pixel_lab_coord( px2[0:2])).normalize() R1 = R.copy() R2 = R.copy() R1.set_vec3_double("xyzcal.px", px1) R1.set_vec3_double("xyzcal.mm", mm1) R1.set_vec3_double("s1", s11) R2.set_vec3_double("xyzcal.px", px2) R2.set_vec3_double("xyzcal.mm", mm2) R2.set_vec3_double("s1", s12) compute_intensity = IntensityCalculatorFactory.create(data, detector_space=True, deconvolution=False) compute_intensity(R, []) R.set_double("intensity.prf.value.old", R.get("intensity.prf.value")) R.set_double("intensity.prf.variance.old", R.get("intensity.prf.variance")) R_no_deconvolution = R.copy() # print "Partiality", R.get("partiality") # print "Partiality Old", R.get("partiality_old") # print "Intensity", R.get("intensity.prf.value") # print "Intensity Old", R.get("intensity.prf.value.old") from dials.algorithms.integration.parallel_integrator import MaskCalculatorFactory mask_calculator = MaskCalculatorFactory.create(data.experiments) mask_calculator(R1, True) mask_calculator(R2, True) # print R.get("shoebox").mask.as_numpy_array()[0,:,:] compute_intensity = IntensityCalculatorFactory.create(data, detector_space=True, deconvolution=True) compute_intensity(R, [R1, R2]) # compute_intensity(R, [R1, R2]) R_deconvolution = R.copy() partiality1 = R_no_deconvolution.get("partiality") partiality2 = R_deconvolution.get("partiality") intensity = R_deconvolution.get("intensity.prf.value") variance = R_deconvolution.get("intensity.prf.variance") assert partiality1 <= partiality2 assert abs(intensity - 179.05997142249996) < 1e-7 assert abs(variance - 203.56992949599677) < 1e-7