def index(reflections, detector, known_symmetry, beams): '''calls the two color indexer class after setting up the phil parameters and returns a class object''' # 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 params.indexing.refinement_protocol.n_macro_cycles = 1 params.indexing.known_symmetry.unit_cell = known_symmetry.unit_cell() 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 filenames = [""] reader = Reader(filenames) masker = Masker(filenames) imgsetdata = ImageSetData(reader, masker) imgset = ImageSet(imgsetdata) imgset.set_beam(beams[0]) imgset.set_detector(detector) imagesets = [imgset] orient = indexer_two_color(reflections, imagesets, params) orient.index() return orient
def index(reflections, detector, known_symmetry, beams): 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 params.indexing.refinement_protocol.n_macro_cycles = 1 params.indexing.known_symmetry.unit_cell = known_symmetry.unit_cell() params.indexing.debug = True params.indexing.known_symmetry.absolute_angle_tolerance = 5.0 params.indexing.known_symmetry.relative_length_tolerance = 0.3 filenames = [""] reader = Reader(filenames) masker = Masker(filenames) iset_data = ImageSetData(reader, masker) imgset = ImageSet(iset_data) imgset.set_beam(beams[0]) imgset.set_detector(detector) imagesets = [imgset] # dermen: # modified rmsd_min_px this so test will pass, was originally set # to 2 and the stills indexer's best.rmsd was of order ~2.8ish # I dont know enough about the code itself to make the call on # whether this is legit or not or whether 2.8 best.rmsd is # something we should focus on improving... params.indexing.stills.rmsd_min_px = 3.5 orient = indexer_two_color(reflections, imagesets, params) orient.index() return orient
def index(reflections, detector, known_symmetry, beams): '''sets up two color indexer parameters and calls the indexer; returns the candidate basis vectors from the 2-D grid search in two color indexer''' # 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 params.indexing.refinement_protocol.n_macro_cycles = 1 # 5 params.indexing.known_symmetry.unit_cell = known_symmetry.unit_cell() 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 filenames = [""] reader = Reader(filenames) masker = Masker(filenames) iset_data = ImageSetData(reader, masker) imgset = ImageSet(iset_data) imgset.set_beam(beams[0]) imgset.set_detector(detector) imagesets = [imgset] orient = indexer_two_color(reflections, imagesets, params) #, beams=beams) orient.index() cvecs = orient.candidate_basis_vectors return cvecs
def generate_spots(crystal_model, detector, beam, goniometer=None, scan=None, sel_fraction=1.0): experiment = Experiment(beam=beam, detector=detector, goniometer=goniometer, scan=scan, crystal=crystal_model) # if we don't set the imageset then from_predictions uses the StillsReflectionPredictor :-( filenames = [""] * len(scan) reader = Reader(filenames) masker = Masker(filenames) data = ImageSetData(reader, masker) imageset = ImageSweep(data, beam, detector, goniometer, scan) experiment.imageset = imageset predicted = flex.reflection_table.from_predictions(experiment) sel = flex.random_selection(len(predicted), int(math.floor(sel_fraction * len(predicted)))) predicted = predicted.select(sel) predicted['imageset_id'] = flex.size_t(len(predicted), 0) predicted['xyzobs.px.value'] = predicted['xyzcal.px'] predicted['xyzobs.px.variance'] = flex.vec3_double(len(predicted), (0.5, 0.5, 0.5)) return predicted
def test_elliptical_distortion(run_in_tmpdir): """Create distortion maps for elliptical distortion using a dummy experiments with a small detector, for speed. Check those maps seem sensible""" # Make a detector model d = make_detector() # The beam is also essential for a experiments to be serialisable b = Beam((0, 0, 1), 1.0) # Create and write out a experiments imageset = ImageSet(ImageSetData(Reader(None, ["non-existent.cbf"]), None)) imageset.set_detector(d) imageset.set_beam(b) experiments = ExperimentListFactory.from_imageset_and_crystal( imageset, None) experiments.as_json("dummy.expt") # Centre of distortion will be the far corner from the origin of the first # panel centre_xy = d[0].get_image_size_mm() # Generate distortion maps cmd = ("dials.generate_distortion_maps dummy.expt " "mode=ellipse centre_xy={},{} " "phi=0 l1=1.0 l2=0.95").format(*centre_xy) easy_run.fully_buffered(command=cmd).raise_if_errors() # Load the maps with open("dx.pickle", "rb") as f: dx = pickle.load(f) with open("dy.pickle", "rb") as f: dy = pickle.load(f) # Check there are 4 maps each assert len(dx) == len(dy) == 4 # Ellipse has phi=0, so all correction is in the dy map for arr in dx: assert min(arr) == max(arr) == 0.0 # The ellipse correction is centred at the middle of the detector and all in # the Y direction. Therefore we expect a few things from the dy maps: # # (1) Within each panel the columns of the array are identical. # (2) The two upper panels should be the same # (3) The two lower panels should be the same. # (4) One column from an upper panel is a negated, reversed column from a # lower panel. # # All together expect the 4 dy maps to look something like this: # # /-----------\ /-----------\ # |-3 -3 -3 -3| |-3 -3 -3 -3| # |-2 -2 -2 -2| |-2 -2 -2 -2| # |-1 -1 -1 -1| |-1 -1 -1 -1| # | 0 0 0 0| | 0 0 0 0| # \-----------/ \-----------/ # /-----------\ /-----------\ # | 0 0 0 0| | 0 0 0 0| # | 1 1 1 1| | 1 1 1 1| # | 2 2 2 2| | 2 2 2 2| # | 3 3 3 3| | 3 3 3 3| # \-----------/ \-----------/ # So the fundamental data is all in the first column of first panel's map col0 = dy[0].matrix_copy_column(0) # The correction should be 5% of the distance from the ellipse centre to a # corrected pixel (l2 = 0.95 above) along the slow axis. Check that is the # case (for the first pixel at least) vec_centre_to_first_px = matrix.col(d[0].get_pixel_lab_coord( (0.5, 0.5))) - matrix.col(d[0].get_lab_coord(centre_xy)) dist_centre_to_first_px = vec_centre_to_first_px.dot( matrix.col(d[0].get_slow_axis())) corr_mm = dist_centre_to_first_px * 0.05 corr_px = corr_mm / d[0].get_pixel_size()[1] assert col0[0] == pytest.approx(corr_px) # Test (1) from above list for panel 0 for i in range(1, 50): assert (col0 == dy[0].matrix_copy_column(i)).all_eq(True) # Test (2) assert (dy[0] == dy[1]).all_eq(True) # Test (3) assert (dy[2] == dy[3]).all_eq(True) # Test (4) assert col0 == pytest.approx(-1.0 * dy[2].matrix_copy_column(0).reversed()) # Test (1) for panel 2 as well, which then covers everything needed col0 = dy[2].matrix_copy_column(0) for i in range(1, 50): assert (col0 == dy[2].matrix_copy_column(i)).all_eq(True)