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 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"
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 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)
def _get_beam(self): return BeamFactory.simple_directional((0, 0, 1), WAVELEN_LOW)
params.indexing.two_color.avg_energy = parameters.ENERGY_LOW * .5 + parameters.ENERGY_HIGH * .5 params.indexing.stills.refine_all_candidates = False params.indexing.stills.refine_candidates_with_known_symmetry = False params.indexing.refinement_protocol.mode = "ignore" params.indexing.stills.rmsd_min_px = 20000 params.indexing.stills.candidate_outlier_rejection = False params.indexing.refinement_protocol.n_macro_cycles = 1 params.indexing.multiple_lattice_search.max_lattices = 1 params.indexing.basis_vector_combinations.max_refine = 10000000000 #params.indexing.basis_vector_combinations.max_combinations = 150 params.refinement.reflections.outlier.algorithm = "null" # ==================================================================== BEAM_LOW = BeamFactory.simple_directional((0, 0, 1), parameters.WAVELEN_LOW) BEAM_HIGH = BeamFactory.simple_directional((0, 0, 1), parameters.WAVELEN_HIGH) if __name__ == "__main__": show_hits = False if not HAS_TWO_COLOR: print("Need to install the module cxi_xdr_xes") sys.exit() pickle_fname = sys.argv[1] image_fname = sys.argv[2] print('Loading reflections') with open(pickle_fname, 'r') as f: found_refl = cPickle.load(f) refl_select = spot_utils.ReflectionSelect(found_refl)