Beispiel #1
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
Beispiel #2
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
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
Beispiel #4
0
# from dials.array_family import flex
import sys
import numpy as np
import cPickle

from dials.algorithms.indexing.indexer import master_phil_scope\
    as indexer_phil_scope

from dials.algorithms.indexing import stills_indexer
from dials.algorithms.indexing.indexer import indexer_base
from cctbx import crystal
import dxtbx
from cxid9114.spots import count_spots
from libtbx.utils import Sorry

params = indexer_phil_scope.extract()
MIN_SPOT_PER_HIT = 3

#   =====================================
#   Parameters
show_hits = False
INDEXER = stills_indexer.stills_indexer
KNOWN_SYMMETRY = crystal.symmetry("79,79,38,90,90,90", "P43212")
params.refinement.parameterisation.beam.fix = "all"
params.refinement.parameterisation.detector.fix = "all"
params.indexing.method = "fft1d"
params.indexing.known_symmetry.space_group = KNOWN_SYMMETRY.space_group_info()
params.refinement.verbosity = 3
# params.indexing.refinement_protocol.d_min_start
params.indexing.known_symmetry.unit_cell = KNOWN_SYMMETRY.unit_cell()
params.indexing.debug = True
    S.Ncells_abc = (10,10,10)
    S.add_nanoBragg_spots()
    return [S.raw_pixels.as_numpy_array() ]

# Here is our dxtbx crystal description
# this will be our ground truth
cryst_descr = {'__id__': 'crystal',
               'real_space_a': (150., 0, 0),
               'real_space_b': (0, 200., 0),
               'real_space_c': (0, 0, 100.),
               'space_group_hall_symbol': '-P 2 2'}
cryst = CrystalFactory.from_dict(cryst_descr)


# Lets define the indexing parameters for when we need them later:
idxpar = indexer_phil_scope.extract()
idxpar.indexing.known_symmetry.space_group = cryst.get_space_group().info()
idxpar.indexing.known_symmetry.unit_cell = cryst.get_unit_cell()
idxpar.indexing.method = "fft1d"
idxpar.indexing.fft1d.characteristic_grid = 0.029
idxpar.indexing.multiple_lattice_search.max_lattices = 1
idxpar.indexing.stills.indexer = 'stills'
idxpar.indexing.stills.refine_all_candidates = True
idxpar.indexing.stills.refine_candidates_with_known_symmetry = True 
idxpar.indexing.stills.candidate_outlier_rejection = False
idxpar.indexing.debug = False
idxpar.refinement.verbosity = 0
#idxpar.indexing.refinement_protocol.mode = "repredict_only"
idxpar.refinement.parameterisation.beam.fix = "all"
idxpar.refinement.parameterisation.detector.fix_list = ["origin"]
idxpar.refinement.parameterisation.crystal.fix = "all"
Beispiel #6
0
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"
Beispiel #7
0
from cxi_xdr_xes.two_color import merge_close_spots
from dxtbx.imageset import ImageSet, ImageSetData
from dxtbx.format.Format import Reader, Masker
from dxtbx.model.beam import BeamFactory as beam_factory
from dials.algorithms.indexing.indexer import master_phil_scope
# from libtbx.phil import command_line
from cctbx import crystal
from scitbx.matrix import col
from dxtbx.model import Crystal
from dxtbx.model.detector import DetectorFactory as detector_factory
from dials.algorithms.indexing.compare_orientation_matrices\
      import difference_rotation_matrix_axis_angle
from cxi_xdr_xes.command_line.two_color_process import two_color_phil_scope

master_phil_scope.adopt_scope(two_color_phil_scope)
master_phil_scope.extract()
'''This program is designed to test that the final indexed image hkl values
for experiment list are unigue. This is done by comparing the list of hkl values
for each associated experiment to the set of unique hkl values; the number of
elements in each list should be the same. This is done for 100 simulated diffraction
images of thermolysin. '''


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"
def run():
    random_seed = 35
    flex.set_random_seed(random_seed)
    random.seed(random_seed)
    data = merge_close_spots.merge_close_spots()
    # unit cell and space group for lysozyme
    known_symmetry = crystal.symmetry("78,78,37,90,90,90", "P43212")

    sim = data.two_color_sim
    merged_spot_info = data.spot_proximity(sim)
    merged_refl = merged_spot_info[0]

    detector = data.detector
    beams = data.beams

    # to make sure input crystal and indexed crystal model are the same
    # orientation before using the refiner
    A = sim['input_orientation']
    A_inv = A.inverse()
    a = A_inv[:3]
    b = A_inv[3:6]
    c = A_inv[6:]
    crystinp = Crystal(a, b, c, space_group=known_symmetry.space_group())
    result = index(merged_refl, detector, known_symmetry, beams)
    print("RESULTS ARE IN")
    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)
    euler_angles = euler.xyz_angles(R)

    print "input crystal: %s" % crystinp
    print "Indexed crystal: %s" % cm
    print "rotation of: %s" % R
    print "euler angles:", euler_angles
    print "change of basis:", change_of_basis.as_hkl()

    # 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

    expts = copy.deepcopy(result.refined_experiments)
    expts.crystals()[0].change_basis(change_of_basis)
    print(expts.crystals()[0])

    refined = refine(params, result.reflections, expts, verbosity=1)
    print(refined[0].get_experiments().crystals()[0])

    # from annlib_ext import AnnAdaptor
    # ann = AnnAdaptor(merged_refl['xyzobs.px.value'].as_double(), dim=3, k=1)
    # ann.query(result.reflections['xyzobs.px.value'].as_double()+1e-6)
    indices_sim = change_of_basis.apply(merged_refl['set_miller_index'])
    id_sim = merged_refl['set_id']
    # only get those that refined:
    idx = align_merged_and_refined_refl(merged_refl,
                                        result.refined_reflections)
    indices_sim = flex.miller_index([indices_sim[i] for i in idx])
    id_sim = flex.int([id_sim[i] for i in idx])
    indices_result = result.refined_reflections['miller_index']
    id_result = result.refined_reflections['id']

    correct_ind = (indices_sim == indices_result)
    wrong_wavelength = (id_sim != id_result) & (id_sim != 2)
    wrong_index = (indices_sim != indices_result)
    correct_wavelength = (id_sim == id_result) | (id_sim == 2)
    correct = correct_ind & correct_wavelength
    print "Correct index and wavelength: %i/%i" % (correct.count(True),
                                                   len(correct))
    print "Correct index but wrong wavelength: %i/%i" % (
        wrong_wavelength.count(True), len(wrong_wavelength))
    print "Wrong index but correct wavelength: %i/%i" % (
        wrong_index.count(True), len(correct_wavelength))