Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def tst_index_spots():
    assert (REFLS)

    global CRYSTALS
    global RMSD
    from cxi_xdr_xes.two_color.two_color_indexer import indexer_two_color
    from cxid9114.spots import spot_utils
    from libtbx.utils import Sorry

    for i in [2, 5]:  # NOTE: these are the experiments that should index
        refls_strong = REFLS[i]
        try:
            orientAB = indexer_two_color(
                reflections=spot_utils.as_single_shot_reflections(
                    refls_strong, inplace=False),
                experiments=EXP_LIST[i:i + 1],
                params=mad_index_params)
            orientAB.index()
        except (Sorry, RuntimeError) as error:
            print("Failed to index experiment %d:" % i)
            print(error)
            continue
        RMSD.append(orientAB.best_Amat_rmsd)
        CRYSTALS.append(orientAB.refined_experiments.crystals()[0])

    assert (len(RMSD) == 2)
    assert (all([r < 3.75 for r in RMSD]))
Exemplo n.º 4
0
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
Exemplo n.º 5
0
    def index(self, datablock, reflections):
        from time import time
        from logging import info
        import copy
        st = time()

        info('*' * 80)
        info('Indexing Strong Spots')
        info('*' * 80)

        imagesets = datablock.extract_imagesets()

        params = copy.deepcopy(self.params)
        # don't do scan-varying refinement during indexing
        params.refinement.parameterisation.crystal.scan_varying = False
        from cxi_xdr_xes.two_color.two_color_indexer import indexer_two_color
        idxr = indexer_two_color(reflections, imagesets, params=params)
        indexed = idxr.refined_reflections
        experiments = idxr.refined_experiments

        if self.params.output.indexed_filename:
            self.save_reflections(indexed, self.params.output.indexed_filename)

        info('')
        info('Time Taken = %f seconds' % (time() - st))
        return experiments, indexed
Exemplo n.º 6
0
    #            imagesets=[isetB],
    #            params=sad_index_params)
    #        orientB.index()
    #        crystalB = orientB.refined_experiments.crystals()[0]
    #        outB = sim_utils.sim_twocolors(crystalB, mos_dom=20, mos_spread=0.1, fracA=fracA, fracB=fracB, plot=False)
    #        B_results.append(outB)
    #    except:
    #        B_results.append(None)

    # ==================================
    # 2 color indexer of 2 color pattern
    # ==================================
    try:
        orientAB = indexer_two_color(
            reflections=spot_utils.as_single_shot_reflections(refls_strong,
                                                              inplace=False),
            imagesets=[iset],
            params=mad_index_params)
        orientAB.index()
    except (Sorry, RuntimeError):
        print("####\nIndexingFailed  T_T \n####")
        failed_shots.append(idx)
        try:
            np.savetxt(failed_idx_f, failed_shots, fmt="%d")
        except:
            pass
        continue
    n_idx += 1
    #if not orientAB.refined_experiments.crystals():  # this would probably never happen...
    #    continue
    print("####\n *_* IndexingWORKED *_* \n####")
Exemplo n.º 7
0
from cxid9114 import utils
import glob
from scitbx.matrix import sqr
from cxi_xdr_xes.two_color.two_color_indexer import indexer_two_color

fnames = glob.glob("results/good_hit_*_10_crys.pkl")
for fname in fnames:
    data = utils.open_flex(fname)

    crystal = data['crystal']
    xrot = data['optX']
    yrot = data['optY']
    new_A = xrot * yrot * sqr(crystal.get_U()) * sqr(crystal.get_B())
    crystal.set_A(new_A)

    orient = indexer_two_color(reflections=refl,
                               imagesets=[hit_imgset],
                               params=params)

    # h5_name = fname.replace(".pkl", ".h5")
Exemplo n.º 8
0
img_data = utils.open_flex('some_imgs.pkl')

dblock = utils.datablock_from_numpyarrays(
    [i.as_numpy_array() for i in img_data["img%d" % shot_idx]],
    detector=D,
    beam=BeamA,
    mask=mask)
dump = utils.open_flex("dump_%d.pkl" % shot_idx)
refls = dump['refls_strong']
spot_utils.as_single_shot_reflections(refls)

iset = dblock.extract_imagesets()[0]

if index:
    orientAB = indexer_two_color(reflections=refls,
                                 imagesets=[iset],
                                 params=mad_index_params)
    orientAB.index()

    C = orientAB.refined_experiments.crystals()[0]
    utils.save_flex({"C": C}, "C%d.pkl" % shot_idx)
    from dxtbx.model.experiment_list import Experiment, ExperimentList
    e = Experiment()
    e.detector = D
    e.beam = B
    e.crystal = C
    e.imageset = iset
    el = ExperimentList()
    el.append(e)
    orientAB.export_as_json(el, "exp%d.json" % shot_idx)
Exemplo n.º 9
0
isetB.set_beam(BeamB)

# index two color pattern using fft1d
orientA = indexer_base.from_parameters(
    reflections=count_spots.as_single_shot_reflections(refls, inplace=False),
    imagesets=[isetA],
    params=sad_index_params)
orientA.index()
crystalA = orientA.refined_experiments.crystals()[0]

# try with other color
orientB = indexer_base.from_parameters(
    reflections=count_spots.as_single_shot_reflections(refls, inplace=False),
    imagesets=[isetB],
    params=sad_index_params)
orientB.index()
crystalB = orientB.refined_experiments.crystals()[0]

# ==================================
# 2 color indexer of 2 color pattern
# ==================================
orientAB = indexer_two_color(
    reflections=count_spots.as_single_shot_reflections(refls, inplace=False),
    imagesets=[iset],
    params=mad_index_params)
orientAB.index()
crystalAB = orientAB.refined_experiments.crystals()[0]

from IPython import embed
embed()
Exemplo n.º 10
0
    loader = dxtbx.load(image_fname)
    img = loader.get_raw_data(idx).as_numpy_array()

    iset = loader.get_imageset(loader.get_image_file())
    dblock = DataBlockFactory.from_imageset(iset[idx:idx+1])[0]
    refl = flex.reflection_table.from_observations(dblock, find_spot_params)

    imgs.append(img)
    refls.append( refl)

    info_fname = image_fname.replace(".h5", ".pkl")
    sim_data = utils.open_flex(info_fname)

    orient = indexer_two_color(
        reflections=spot_utils.as_single_shot_reflections(refl, inplace=False),
        imagesets=[iset],
        params=indexing_params)

    try:
        orient.index()
        crystals = [o.crystal for o in orient.refined_experiments]
        rmsd =  orient.best_rmsd
        sim_data["sim_indexed_rmsd"] = rmsd
        sim_data["sim_indexed_crystals"] = crystals
        sim_data["sim_indexed_refls"] = refl
    except:
        print("FAILED!")


    utils.save_flex( sim_data, info_fname+out_tag)