def make_images(data, tag): pixel_size = 0.1 # mm/pixel detector = DetectorFactory.simple( 'PAD', 100, (pixel_size * data.focus()[1] / 2, pixel_size * data.focus()[2] / 2), '+x', '-y', (pixel_size, pixel_size), (data.focus()[2], data.focus()[1]), (-1, 1e6 - 1), [], None) beam = BeamFactory.simple(1.0) sf = ScanFactory() scan = sf.make_scan(image_range=(1, 180), exposure_times=0.1, oscillation=(0, 1.0), epochs=range(180), deg=True) # write images in each of three directions for slice_id in [0, 1, 2]: for idx in xrange(data.focus()[slice_id]): if slice_id == 0: # slow data_slice = data[idx:idx + 1, :, :] data_slice.reshape(flex.grid(data.focus()[1], data.focus()[2])) filename = "fft_frame_%s_mf_%04d.cbf" % (tag, idx) elif slice_id == 1: # med data_slice = data[:, idx:idx + 1, :] data_slice.reshape(flex.grid(data.focus()[0], data.focus()[2])) filename = "fft_frame_%s_sf_%04d.cbf" % (tag, idx) elif slice_id == 2: # fast data_slice = data[:, :, idx:idx + 1] data_slice.reshape(flex.grid(data.focus()[0], data.focus()[1])) filename = "fft_frame_%s_sm_%04d.cbf" % (tag, idx) print['slow', 'med', 'fast'][slice_id], idx FormatCBFMini.as_file(detector, beam, None, scan, data_slice, filename)
def get_values(invert_y): beam = BeamFactory.simple(wavelength=1) if invert_y: y_direction = "-y" else: y_direction = "+y" detector = DetectorFactory.simple( sensor=DetectorFactory.sensor("PAD"), distance=100, beam_centre=[50, 50], fast_direction="+x", slow_direction=y_direction, pixel_size=[0.1, 0.1], image_size=[1000, 1000], )[0] wavelength = beam.get_wavelength() thickness = 0.5 table = attenuation_coefficient.get_table("Si") mu = table.mu_at_angstrom(wavelength) / 10.0 t0 = thickness for panel in detector: panel.set_px_mm_strategy(ParallaxCorrectedPxMmStrategy(mu, t0)) v1 = detector.pixel_to_millimeter((0, 0)) v2 = detector.pixel_to_millimeter((1000, 1000)) return v1, v2
def make_images(data, tag): pixel_size = 0.1 detector = DetectorFactory.simple( 'PAD', 100, (pixel_size * data.focus()[1] / 2, pixel_size * data.focus()[2] / 2), '+x', '-y', (pixel_size, pixel_size), (data.focus()[2], data.focus()[1]), (-1, 1e6 - 1), [], None) beam = BeamFactory.simple(1.0) for slice_id in [0, 1, 2]: for idx in xrange(data.focus()[slice_id]): if slice_id == 0: # slow data_slice = data[idx:idx + 1, :, :] data_slice.reshape(flex.grid(data.focus()[1], data.focus()[2])) filename = "fft_frame_%s_mf_%04d.cbf" % (tag, idx) elif slice_id == 1: # med data_slice = data[:, idx:idx + 1, :] data_slice.reshape(flex.grid(data.focus()[0], data.focus()[2])) filename = "fft_frame_%s_sf_%04d.cbf" % (tag, idx) elif slice_id == 2: # fast data_slice = data[:, :, idx:idx + 1] data_slice.reshape(flex.grid(data.focus()[0], data.focus()[1])) filename = "fft_frame_%s_sm_%04d.cbf" % (tag, idx) print['slow', 'med', 'fast'][slice_id], idx FormatCBFMini.as_file(detector, beam, None, None, data_slice, filename)
def __init__(self): #unit cell and space group for lysozyme known_symmetry = crystal.symmetry("78,78,37,90,90,90", "P43212") data = two_color_still_sim.two_color_still_sim(symm=known_symmetry, rot=None) self.data = data wavelength1 = 12398 / 7400 #wavelength for 2 color experiment in Angstroms wavelength2 = 12398 / 7500 #wavelength for 2 color experiment in Angstroms #get detector with a single panel detector = detector_factory.simple('SENSOR_UNKNOWN', 125, (97.075, 97.075), '+x', '-y', (0.11, 0.11), (1765, 1765)) self.detector = detector beam1 = beam_factory.simple_directional((0, 0, 1), wavelength1) beam2 = beam_factory.simple_directional((0, 0, 1), wavelength2) beams = [beam1, beam2] self.beams = beams hkl_list = data.hkl_list self.hkl_list = hkl_list A = data.A self.A = A two_color_sim = data.ewald_proximity_test(beams, hkl_list, A, detector) self.two_color_sim = two_color_sim
def test_unique_hkl(): '''tests the uniqueness of hkl values associated with each experiment for 100 simulated randomly oriented thermolysin diffraction images prior to indexing.''' flex.set_random_seed(42) # the meaning of life known_symmetry = crystal.symmetry("78,78,37,90,90,90", "P43212") detector = detector_factory.simple('SENSOR_UNKNOWN', 125, (97.075, 97.075), '+x', '-y', (0.11, 0.11), (1765, 1765)) wavelength1 = 12398 / 7400 #wavelength for 2 color experiment in Angstroms wavelength2 = 12398 / 7500 #wavelength for 2 color experiment in Angstroms beam1 = beam_factory.simple_directional((0, 0, 1), wavelength1) beam2 = beam_factory.simple_directional((0, 0, 1), wavelength2) beams = [beam1, beam2] for i in range(100): data = two_color_still_sim.two_color_still_sim(known_symmetry, rot=None) hkl_list = data.hkl_list A = data.A sim_data = data.ewald_proximity_test(beams, hkl_list, A, detector) refl = sim_data.get('reflection_table') refl1 = refl.select(refl['set_id'] == 0) refl2 = refl.select(refl['set_id'] == 1) # unit test to make sure all miller indices are unique for each experiment id assert len(refl1['miller_index']) == len(set(refl1['miller_index'])) assert len(refl2['miller_index']) == len(set(refl2['miller_index'])) print "ok"
def test_detector(): """A test class for the detector class.""" assert DetectorFactory.simple( "CCD", 100.0, (45.0, 52.0), "+x", "-y", (0.172, 0.172), (516, 590), (0, 1024), [], ) assert DetectorFactory.two_theta( "CCD", 60.0, (35.0, 34.0), "+x", "+y", "+x", 30, (0.07, 0.07), (1042, 1042), (0, 1024), [], ) image = Path(__file__).parent / "phi_scan_001.cbf" assert DetectorFactory.imgCIF(str(image), "CCD")
def test_detector(): """A test class for the detector class.""" assert DetectorFactory.simple( "CCD", 100.0, (45.0, 52.0), "+x", "-y", (0.172, 0.172), (516, 590), (0, 1024), [], ) assert DetectorFactory.two_theta( "CCD", 60.0, (35.0, 34.0), "+x", "+y", "+x", 30, (0.07, 0.07), (1042, 1042), (0, 1024), [], ) dxtbx_dir = libtbx.env.dist_path("dxtbx") image = os.path.join(dxtbx_dir, "tests", "phi_scan_001.cbf") # xparm = os.path.join(dxtbx_dir, "tests", "example-xparm.xds") assert DetectorFactory.imgCIF(image, "CCD")
def _construct_detector(distance): return DetectorFactory.simple( sensor="PAD", distance=distance, beam_centre=(216.87, 211.32), fast_direction="+x", slow_direction="-y", pixel_size=(0.172, 0.172), image_size=(2463, 2527), trusted_range=(-1, 1e8), )
def _construct_detector(distance): return DetectorFactory.simple( sensor="PAD", distance=distance, beam_centre=(41.20, 51.69), fast_direction="+x", slow_direction="-y", pixel_size=(0.172, 0.172), image_size=(487, 619), trusted_range=(-1, 1e8), )
def test_detector(): '''A test class for the detector class.''' d = DetectorFactory.simple('CCD', 100.0, (45.0, 52.0), '+x', '-y', (0.172, 0.172), (516, 590), (0, 1024), []) t = DetectorFactory.two_theta( 'CCD', 60.0, (35.0, 34.0), '+x', '+y', '+x', 30, (0.07, 0.07), (1042, 1042), (0, 1024), []) import libtbx.load_env import os dxtbx_dir = libtbx.env.dist_path('dxtbx') image = os.path.join(dxtbx_dir, 'tests', 'phi_scan_001.cbf') xparm = os.path.join(dxtbx_dir, 'tests', 'example-xparm.xds') c = DetectorFactory.imgCIF(image, 'CCD')
def get_basis(): '''gets the input basis vectors of 100 simulated diffraction images''' flex.set_random_seed(42) known_symmetry = crystal.symmetry("78,78,37,90,90,90", "P43212") detector = detector_factory.simple('SENSOR_UNKNOWN', 125, (97.075, 97.075), '+x', '-y', (0.11, 0.11), (1765, 1765)) wavelength1 = 12398 / 7400 #wavelength for 2 color experiment in Angstroms wavelength2 = 12398 / 7500 #wavelength for 2 color experiment in Angstroms beam1 = beam_factory.simple_directional((0, 0, 1), wavelength1) beam2 = beam_factory.simple_directional((0, 0, 1), wavelength2) a_basis = [] b_basis = [] c_basis = [] unique_vectors = [] # refiner resets random number seed so in order to get the same 100 images #generated each time the random seed is set # the implementation is as follows sims = [merge_close_spots.merge_close_spots() for i in range(2)] for data in sims: A = data.A A_inv = A.inverse() a = col(A_inv[:3]) b = col(A_inv[3:6]) c = col(A_inv[6:]) a_basis.append(a) b_basis.append(b) c_basis.append(c) res = data.two_color_sim info = data.spot_proximity(res) refl = info[0] candidate_basis_vectors = index(refl, detector, known_symmetry, [beam1, beam2]) unique_vectors.append(candidate_basis_vectors) return a_basis, b_basis, c_basis, unique_vectors
def test_indexed_hkl(): '''tests the uniqueness of hkl values associated with each experiment for 100 simulated randomly oriented thermolysin diffraction images indexed using two color indexer''' flex.set_random_seed(42) known_symmetry = crystal.symmetry("78,78,37,90,90,90", "P43212") detector = detector_factory.simple('SENSOR_UNKNOWN', 125, (97.075, 97.075), '+x', '-y', (0.11, 0.11), (1765, 1765)) wavelength1 = 12398 / 7400 #wavelength for 2 color experiment in Angstroms wavelength2 = 12398 / 7500 #wavelength for 2 color experiment in Angstroms beam1 = beam_factory.simple_directional((0, 0, 1), wavelength1) beam2 = beam_factory.simple_directional((0, 0, 1), wavelength2) a_basis = [] b_basis = [] c_basis = [] # refiner resets random number seed so in order to get the same 100 images #generated each time the random seed is set # the implementation is as follows # gets simulated images sims = [merge_close_spots.merge_close_spots() for i in range(2)] for data in sims: A = data.A A_inv = A.inverse() a = col(A_inv[:3]) b = col(A_inv[3:6]) c = col(A_inv[6:]) crystinp = Crystal(a, b, c, space_group=known_symmetry.space_group()) a_basis.append(a) b_basis.append(b) c_basis.append(c) res = data.two_color_sim info = data.spot_proximity(res) refl = info[0] result = index(refl, detector, known_symmetry, [beam1, beam2]) cm = result.refined_experiments.crystals()[0] R, best_axis, best_angle, change_of_basis = difference_rotation_matrix_axis_angle( crystal_a=cm, crystal_b=crystinp) # cmd_line = command_line.argument_interpreter(master_params=master_phil_scope) # working_phil = cmd_line.process_and_fetch(args=[]) params = master_phil_scope.extract() params.refinement.parameterisation.beam.fix = "all" params.refinement.parameterisation.detector.fix = "all" params.indexing.known_symmetry.space_group = known_symmetry.space_group_info( ) params.refinement.verbosity = 3 params.indexing.refinement_protocol.d_min_start = 3 params.indexing.refinement_protocol.n_macro_cycles = 1 params.indexing.known_symmetry.unit_cell = known_symmetry.unit_cell() params.indexing.multiple_lattice_search.max_lattices = 1 params.indexing.debug = True params.indexing.known_symmetry.absolute_angle_tolerance = 5.0 params.indexing.known_symmetry.relative_length_tolerance = 0.3 params.indexing.stills.rmsd_min_px = 3.5 expts = copy.deepcopy(result.refined_experiments) expts.crystals()[0].change_basis(change_of_basis) reflections_exp0 = result.refined_reflections.select( result.refined_reflections['id'] == 0) reflections_exp1 = result.refined_reflections.select( result.refined_reflections['id'] == 1) assert len(reflections_exp0['miller_index']) == len( set(reflections_exp0['miller_index'])) assert len(reflections_exp1['miller_index']) == len( set(reflections_exp1['miller_index'])) print "OK"
'reflection_table': refl, 'all_spots': spots, 'wavelength_1_spots': spots1, 'wavelength_2_spots': spots2, 'input_orientation': A } return sim_res if __name__ == "__main__": wavelength1 = 12398 / 7400 #wavelength for 2 color experiment in Angstroms wavelength2 = 12398 / 7500 #wavelength for 2 color experiment in Angstroms #get detector with a single panel detector = detector_factory.simple('SENSOR_UNKNOWN', 125, (97.075, 97.075), '+x', '-y', (0.11, 0.11), (1765, 1765)) #unit cell and space group for lysozyme known_symmetry = crystal.symmetry("78,78,37,90,90,90", "P43212") beam1 = beam_factory.simple_directional((0, 0, 1), wavelength1) beam2 = beam_factory.simple_directional((0, 0, 1), wavelength2) beams = [beam1, beam2] flex.set_random_seed(42) for i in range(5): data = two_color_still_sim(known_symmetry, rot=None) hkl_list = data.hkl_list A = data.A
from math import sqrt side_length = sqrt(diagonal.length()**2 / 2) npx = int(round(side_length / pixel_size[0])) beam_centre = [npx / 2 * pixel_size[0]] * 2 distance = detector[0].get_distance() # Create a new single panel detector orthogonal to the beam, which intersects # at the centre from dxtbx.model.detector import DetectorFactory detector2 = DetectorFactory.simple( sensor="PAD", distance=distance, beam_centre=beam_centre, fast_direction="+x", slow_direction="-y", pixel_size=pixel_size, image_size=(npx, npx), ) exp.detector = detector2 # Make the scan a full turn to ensure no reflections get thrown out during # refinement for being outside the scan range image_width_deg = scan.get_oscillation(deg=True)[1] nimages = int(round(360.0 / image_width_deg)) image_width_deg = 360.0 / nimages image_range = 1, nimages epochs = [0] * nimages exposure_times = 0.0 oscillation = (0, image_width_deg)