예제 #1
0
def test(dials_regression):
    from iotbx.xds import xparm, integrate_hkl
    from dials.util import ioutil
    from dials.algorithms.spot_prediction import IndexGenerator
    import numpy
    from rstbx.cftbx.coordinate_frame_converter import \
        coordinate_frame_converter
    from scitbx import matrix

    # The XDS files to read from
    integrate_filename = os.path.join(dials_regression, 'data', 'sim_mx',
                                      'INTEGRATE.HKL')
    gxparm_filename = os.path.join(dials_regression, 'data', 'sim_mx',
                                   'GXPARM.XDS')

    # Read the XDS files
    integrate_handle = integrate_hkl.reader()
    integrate_handle.read_file(integrate_filename)
    gxparm_handle = xparm.reader()
    gxparm_handle.read_file(gxparm_filename)

    # Get the parameters we need from the GXPARM file
    d_min = 1.6
    space_group_type = ioutil.get_space_group_type_from_xparm(gxparm_handle)
    cfc = coordinate_frame_converter(gxparm_filename)
    a_vec = cfc.get('real_space_a')
    b_vec = cfc.get('real_space_b')
    c_vec = cfc.get('real_space_c')
    unit_cell = cfc.get_unit_cell()
    UB = matrix.sqr(a_vec + b_vec + c_vec).inverse()
    ub_matrix = UB

    # Generate the indices
    index_generator = IndexGenerator(unit_cell, space_group_type, d_min)
    miller_indices = index_generator.to_array()

    # Get individual generated hkl
    gen_h = [hkl[0] for hkl in miller_indices]
    gen_k = [hkl[1] for hkl in miller_indices]
    gen_l = [hkl[2] for hkl in miller_indices]

    # Get individual xds generated hkl
    xds_h = [hkl[0] for hkl in integrate_handle.hkl]
    xds_k = [hkl[1] for hkl in integrate_handle.hkl]
    xds_l = [hkl[2] for hkl in integrate_handle.hkl]

    # Get min/max generated hkl
    min_gen_h, max_gen_h = numpy.min(gen_h), numpy.max(gen_h)
    min_gen_k, max_gen_k = numpy.min(gen_k), numpy.max(gen_k)
    min_gen_l, max_gen_l = numpy.min(gen_l), numpy.max(gen_l)

    # Get min/max xds generated hkl
    min_xds_h, max_xds_h = numpy.min(xds_h), numpy.max(xds_h)
    min_xds_k, max_xds_k = numpy.min(xds_k), numpy.max(xds_k)
    min_xds_l, max_xds_l = numpy.min(xds_l), numpy.max(xds_l)

    # Ensure we have the whole xds range  in the generated set
    assert min_gen_h <= min_xds_h and max_gen_h >= max_xds_h
    assert min_gen_k <= min_xds_k and max_gen_k >= max_xds_k
    assert min_gen_l <= min_xds_l and max_gen_l >= max_xds_l
예제 #2
0
def test(dials_regression):
    import numpy as np

    from iotbx.xds import integrate_hkl, xparm
    from rstbx.cftbx.coordinate_frame_converter import coordinate_frame_converter

    from dials.algorithms.spot_prediction import IndexGenerator
    from dials.util import ioutil

    # The XDS files to read from
    integrate_filename = os.path.join(dials_regression, "data", "sim_mx",
                                      "INTEGRATE.HKL")
    gxparm_filename = os.path.join(dials_regression, "data", "sim_mx",
                                   "GXPARM.XDS")

    # Read the XDS files
    integrate_handle = integrate_hkl.reader()
    integrate_handle.read_file(integrate_filename)
    gxparm_handle = xparm.reader()
    gxparm_handle.read_file(gxparm_filename)

    # Get the parameters we need from the GXPARM file
    d_min = 1.6
    space_group_type = ioutil.get_space_group_type_from_xparm(gxparm_handle)
    cfc = coordinate_frame_converter(gxparm_filename)
    unit_cell = cfc.get_unit_cell()

    # Generate the indices
    index_generator = IndexGenerator(unit_cell, space_group_type, d_min)
    miller_indices = index_generator.to_array()

    # Get individual generated hkl
    gen_h = [hkl[0] for hkl in miller_indices]
    gen_k = [hkl[1] for hkl in miller_indices]
    gen_l = [hkl[2] for hkl in miller_indices]

    # Get individual xds generated hkl
    xds_h = [hkl[0] for hkl in integrate_handle.hkl]
    xds_k = [hkl[1] for hkl in integrate_handle.hkl]
    xds_l = [hkl[2] for hkl in integrate_handle.hkl]

    # Get min/max generated hkl
    min_gen_h, max_gen_h = np.min(gen_h), np.max(gen_h)
    min_gen_k, max_gen_k = np.min(gen_k), np.max(gen_k)
    min_gen_l, max_gen_l = np.min(gen_l), np.max(gen_l)

    # Get min/max xds generated hkl
    min_xds_h, max_xds_h = np.min(xds_h), np.max(xds_h)
    min_xds_k, max_xds_k = np.min(xds_k), np.max(xds_k)
    min_xds_l, max_xds_l = np.min(xds_l), np.max(xds_l)

    # Ensure we have the whole xds range  in the generated set
    assert min_gen_h <= min_xds_h and max_gen_h >= max_xds_h
    assert min_gen_k <= min_xds_k and max_gen_k >= max_xds_k
    assert min_gen_l <= min_xds_l and max_gen_l >= max_xds_l
예제 #3
0
def run():
  from iotbx.xds import xparm, integrate_hkl
  from dials.util import ioutil
  from dials.algorithms.spot_prediction import IndexGenerator
  from os.path import realpath, dirname, join
  import numpy
  from rstbx.cftbx.coordinate_frame_converter import \
      coordinate_frame_converter
  from scitbx import matrix

  # The XDS files to read from
  test_path = dirname(dirname(dirname(realpath(__file__))))
  integrate_filename = join(test_path, 'data/sim_mx/INTEGRATE.HKL')
  gxparm_filename = join(test_path, 'data/sim_mx/GXPARM.XDS')

  # Read the XDS files
  integrate_handle = integrate_hkl.reader()
  integrate_handle.read_file(integrate_filename)
  gxparm_handle = xparm.reader()
  gxparm_handle.read_file(gxparm_filename)

  # Get the parameters we need from the GXPARM file
  d_min = 1.6
  space_group_type = ioutil.get_space_group_type_from_xparm(gxparm_handle)
  cfc = coordinate_frame_converter(gxparm_filename)
  a_vec = cfc.get('real_space_a')
  b_vec = cfc.get('real_space_b')
  c_vec = cfc.get('real_space_c')
  unit_cell = cfc.get_unit_cell()
  UB = matrix.sqr(a_vec + b_vec + c_vec).inverse()
  ub_matrix = UB

  # Generate the indices
  index_generator = IndexGenerator(unit_cell, space_group_type, d_min)
  miller_indices = index_generator.to_array()

  # Get individual generated hkl
  gen_h = [hkl[0] for hkl in miller_indices]
  gen_k = [hkl[1] for hkl in miller_indices]
  gen_l = [hkl[2] for hkl in miller_indices]

  # Get individual xds generated hkl
  xds_h = [hkl[0] for hkl in integrate_handle.hkl]
  xds_k = [hkl[0] for hkl in integrate_handle.hkl]
  xds_l = [hkl[0] for hkl in integrate_handle.hkl]

  # Get min/max generated hkl
  min_gen_h, max_gen_h = numpy.min(gen_h), numpy.max(gen_h)
  min_gen_k, max_gen_k = numpy.min(gen_k), numpy.max(gen_k)
  min_gen_l, max_gen_l = numpy.min(gen_l), numpy.max(gen_l)

  # Get min/max xds generated hkl
  min_xds_h, max_xds_h = numpy.min(xds_h), numpy.max(xds_h)
  min_xds_k, max_xds_k = numpy.min(xds_k), numpy.max(xds_k)
  min_xds_l, max_xds_l = numpy.min(xds_l), numpy.max(xds_l)

  # Ensure we have the whole xds range  in the generated set
  assert(min_gen_h <= min_xds_h and max_gen_h >= max_xds_h)
  assert(min_gen_k <= min_xds_k and max_gen_k >= max_xds_k)
  assert(min_gen_l <= min_xds_l and max_gen_l >= max_xds_l)

  # Test Passed
  print "OK"
예제 #4
0
    def __init__(self):
        from dials.algorithms.spot_prediction import IndexGenerator
        from dials.algorithms.spot_prediction import ScanStaticRayPredictor
        from dials.algorithms.spot_prediction import ray_intersection
        from iotbx.xds import xparm, integrate_hkl
        from dials.util import ioutil
        from math import ceil
        import dxtbx
        from rstbx.cftbx.coordinate_frame_converter import \
            coordinate_frame_converter
        from scitbx import matrix

        # The XDS files to read from
        integrate_filename = join(dials_regression,
                                  'data/sim_mx/INTEGRATE.HKL')
        gxparm_filename = join(dials_regression, 'data/sim_mx/GXPARM.XDS')

        # Read the XDS files
        self.integrate_handle = integrate_hkl.reader()
        self.integrate_handle.read_file(integrate_filename)
        self.gxparm_handle = xparm.reader()
        self.gxparm_handle.read_file(gxparm_filename)

        # Get the parameters we need from the GXPARM file
        models = dxtbx.load(gxparm_filename)
        self.beam = models.get_beam()
        self.gonio = models.get_goniometer()
        self.detector = models.get_detector()
        self.scan = models.get_scan()

        assert (len(self.detector) == 1)

        #print self.detector

        # Get crystal parameters
        self.space_group_type = ioutil.get_space_group_type_from_xparm(
            self.gxparm_handle)
        cfc = coordinate_frame_converter(gxparm_filename)
        a_vec = cfc.get('real_space_a')
        b_vec = cfc.get('real_space_b')
        c_vec = cfc.get('real_space_c')
        self.unit_cell = cfc.get_unit_cell()
        self.ub_matrix = matrix.sqr(a_vec + b_vec + c_vec).inverse()

        # Get the minimum resolution in the integrate file
        self.d_min = self.detector[0].get_max_resolution_at_corners(
            self.beam.get_s0())

        # Get the number of frames from the max z value
        xcal, ycal, zcal = zip(*self.integrate_handle.xyzcal)
        self.scan.set_image_range(
            (self.scan.get_image_range()[0],
             self.scan.get_image_range()[0] + int(ceil(max(zcal)))))

        # Create the index generator
        generate_indices = IndexGenerator(self.unit_cell,
                                          self.space_group_type, self.d_min)

        s0 = self.beam.get_s0()
        m2 = self.gonio.get_rotation_axis()
        fixed_rotation = self.gonio.get_fixed_rotation()
        setting_rotation = self.gonio.get_setting_rotation()
        UB = self.ub_matrix
        dphi = self.scan.get_oscillation_range(deg=False)

        # Create the ray predictor
        self.predict_rays = ScanStaticRayPredictor(s0, m2, fixed_rotation,
                                                   setting_rotation, dphi)

        # Predict the spot locations
        self.reflections = self.predict_rays(generate_indices.to_array(), UB)

        # Calculate the intersection of the detector and reflection frames
        success = ray_intersection(self.detector, self.reflections)
        self.reflections.select(success)
예제 #5
0
    def __init__(self, dials_regression):
        import dxtbx
        from iotbx.xds import integrate_hkl, xparm
        from rstbx.cftbx.coordinate_frame_converter import coordinate_frame_converter

        from dials.algorithms.spot_prediction import (
            IndexGenerator,
            ScanStaticRayPredictor,
        )
        from dials.util import ioutil

        # The XDS files to read from
        integrate_filename = os.path.join(dials_regression, "data", "sim_mx",
                                          "INTEGRATE.HKL")
        gxparm_filename = os.path.join(dials_regression, "data", "sim_mx",
                                       "GXPARM.XDS")

        # Read the XDS files
        self.integrate_handle = integrate_hkl.reader()
        self.integrate_handle.read_file(integrate_filename)
        self.gxparm_handle = xparm.reader()
        self.gxparm_handle.read_file(gxparm_filename)

        # Get the parameters we need from the GXPARM file
        models = dxtbx.load(gxparm_filename)
        self.beam = models.get_beam()
        self.gonio = models.get_goniometer()
        self.detector = models.get_detector()
        self.scan = models.get_scan()

        # Get crystal parameters
        self.space_group_type = ioutil.get_space_group_type_from_xparm(
            self.gxparm_handle)
        cfc = coordinate_frame_converter(gxparm_filename)
        a_vec = cfc.get("real_space_a")
        b_vec = cfc.get("real_space_b")
        c_vec = cfc.get("real_space_c")
        self.unit_cell = cfc.get_unit_cell()
        self.ub_matrix = matrix.sqr(a_vec + b_vec + c_vec).inverse()

        # Get the minimum resolution in the integrate file
        d = [self.unit_cell.d(h) for h in self.integrate_handle.hkl]
        self.d_min = min(d)
        # extend the resolution shell by epsilon>0
        # to account for rounding artifacts on 32-bit platforms
        self.d_min = self.d_min - 1e-15

        # Get the number of frames from the max z value
        xcal, ycal, zcal = zip(*self.integrate_handle.xyzcal)
        self.scan.set_image_range((
            self.scan.get_image_range()[0],
            self.scan.get_image_range()[0] + int(math.ceil(max(zcal))),
        ))

        # Print stuff
        #        print self.beam
        #        print self.gonio
        #        print self.detector
        #        print self.scan

        # Create the index generator
        self.generate_indices = IndexGenerator(self.unit_cell,
                                               self.space_group_type,
                                               self.d_min)

        s0 = self.beam.get_s0()
        m2 = self.gonio.get_rotation_axis()
        fixed_rotation = self.gonio.get_fixed_rotation()
        setting_rotation = self.gonio.get_setting_rotation()
        UB = self.ub_matrix
        dphi = self.scan.get_oscillation_range(deg=False)

        # Create the ray predictor
        self.predict_rays = ScanStaticRayPredictor(s0, m2, fixed_rotation,
                                                   setting_rotation, dphi)

        # Predict the spot locations
        self.reflections = self.predict_rays(self.generate_indices.to_array(),
                                             UB)
예제 #6
0
  def __init__(self):
    from dials.algorithms.spot_prediction import IndexGenerator
    from dials.algorithms.spot_prediction import ScanStaticRayPredictor
    from iotbx.xds import xparm, integrate_hkl
    from dials.util import ioutil
    from math import ceil
    import dxtbx
    from rstbx.cftbx.coordinate_frame_converter import \
        coordinate_frame_converter
    from scitbx import matrix

    # The XDS files to read from
    integrate_filename = join(dials_regression, 'data/sim_mx/INTEGRATE.HKL')
    gxparm_filename = join(dials_regression, 'data/sim_mx/GXPARM.XDS')

    # Read the XDS files
    self.integrate_handle = integrate_hkl.reader()
    self.integrate_handle.read_file(integrate_filename)
    self.gxparm_handle = xparm.reader()
    self.gxparm_handle.read_file(gxparm_filename)

    # Get the parameters we need from the GXPARM file
    models = dxtbx.load(gxparm_filename)
    self.beam = models.get_beam()
    self.gonio = models.get_goniometer()
    self.detector = models.get_detector()
    self.scan = models.get_scan()

    # Get crystal parameters
    self.space_group_type = ioutil.get_space_group_type_from_xparm(
        self.gxparm_handle)
    cfc = coordinate_frame_converter(gxparm_filename)
    a_vec = cfc.get('real_space_a')
    b_vec = cfc.get('real_space_b')
    c_vec = cfc.get('real_space_c')
    self.unit_cell = cfc.get_unit_cell()
    self.ub_matrix = matrix.sqr(a_vec + b_vec + c_vec).inverse()

    # Get the minimum resolution in the integrate file
    d = [self.unit_cell.d(h) for h in self.integrate_handle.hkl]
    self.d_min = min(d)
    # extend the resolution shell by epsilon>0
    # to account for rounding artifacts on 32-bit platforms
    self.d_min = self.d_min - 1e-15

    # Get the number of frames from the max z value
    xcal, ycal, zcal = zip(*self.integrate_handle.xyzcal)
    self.scan.set_image_range((self.scan.get_image_range()[0],
                             self.scan.get_image_range()[0] +
                                int(ceil(max(zcal)))))

    # Print stuff
#        print self.beam
#        print self.gonio
#        print self.detector
#        print self.scan

    # Create the index generator
    self.generate_indices = IndexGenerator(self.unit_cell,
        self.space_group_type, self.d_min)

    s0 = self.beam.get_s0()
    m2 = self.gonio.get_rotation_axis()
    fixed_rotation = self.gonio.get_fixed_rotation()
    setting_rotation = self.gonio.get_setting_rotation()
    UB = self.ub_matrix
    dphi = self.scan.get_oscillation_range(deg=False)

    # Create the ray predictor
    self.predict_rays = ScanStaticRayPredictor(s0, m2, fixed_rotation,
                                               setting_rotation, dphi)

    # Predict the spot locations
    self.reflections = self.predict_rays(
                            self.generate_indices.to_array(), UB)
예제 #7
0
def run():
  if not have_dials_regression:
    print "Skipping test: dials_regression not available."
    return

  from scitbx import matrix
  from iotbx.xds import xparm, integrate_hkl
  from dials.util import ioutil
  from math import ceil
  from dials.algorithms.spot_prediction import RotationAngles
  import dxtbx
  from rstbx.cftbx.coordinate_frame_converter import \
      coordinate_frame_converter

  # The XDS files to read from
  integrate_filename = join(dials_regression, 'data/sim_mx/INTEGRATE.HKL')
  gxparm_filename = join(dials_regression, 'data/sim_mx/GXPARM.XDS')

  # Read the XDS files
  integrate_handle = integrate_hkl.reader()
  integrate_handle.read_file(integrate_filename)
  gxparm_handle = xparm.reader()
  gxparm_handle.read_file(gxparm_filename)

  # Get the parameters we need from the GXPARM file
  models = dxtbx.load(gxparm_filename)
  beam = models.get_beam()
  gonio = models.get_goniometer()
  detector = models.get_detector()
  scan = models.get_scan()

  # Get the crystal parameters
  space_group_type = ioutil.get_space_group_type_from_xparm(gxparm_handle)
  cfc = coordinate_frame_converter(gxparm_filename)
  a_vec = cfc.get('real_space_a')
  b_vec = cfc.get('real_space_b')
  c_vec = cfc.get('real_space_c')
  unit_cell = cfc.get_unit_cell()
  UB = matrix.sqr(a_vec + b_vec + c_vec).inverse()
  ub_matrix = UB

  # Get the minimum resolution in the integrate file
  d = [unit_cell.d(h) for h in integrate_handle.hkl]
  d_min = min(d)

  # Get the number of frames from the max z value
  xcal, ycal, zcal = zip(*integrate_handle.xyzcal)
  num_frames = int(ceil(max(zcal)))
  scan.set_image_range((scan.get_image_range()[0],
                      scan.get_image_range()[0] + num_frames - 1))

  # Create the rotation angle object
  ra = RotationAngles(beam.get_s0(), gonio.get_rotation_axis())

  # Setup the matrices
  ub = matrix.sqr(ub_matrix)
  s0 = matrix.col(beam.get_s0())
  m2 = matrix.col(gonio.get_rotation_axis())

  # For all the miller indices
  for h in integrate_handle.hkl:
    h = matrix.col(h)

    # Calculate the angles
    angles = ra(h, ub)

    # For all the angles
    for phi in angles:
      r = m2.axis_and_angle_as_r3_rotation_matrix(angle=phi)
      pstar = r * ub * h
      s1 = s0 + pstar
      assert(abs(s1.length() - s0.length()) < 1e-7)

  print "OK"

  # Create a dict of lists of xy for each hkl
  gen_phi = {}
  for h in integrate_handle.hkl:

    # Calculate the angles
    angles = ra(h, ub)
    gen_phi[h] = angles
#        for phi in angles:
#            try:
#                a = gen_phi[h]
#                a.append(phi)
#                gen_phi[h] = a
#            except KeyError:
#                gen_phi[h] = [phi]

  # For each hkl in the xds file
  for hkl, xyz in zip(integrate_handle.hkl,
                      integrate_handle.xyzcal):

    # Calculate the XDS phi value
    xds_phi = scan.get_oscillation(deg=False)[0] + \
              xyz[2]*scan.get_oscillation(deg=False)[1]

    # Select the nearest xy to use if there are 2
    my_phi = gen_phi[hkl]
    if len(my_phi) == 2:
      my_phi0 = my_phi[0]
      my_phi1 = my_phi[1]
      diff0 = abs(xds_phi - my_phi0)
      diff1 = abs(xds_phi - my_phi1)
      if diff0 < diff1:
        my_phi = my_phi0
      else:
        my_phi = my_phi1
    else:
      my_phi = my_phi[0]

    # Check the Phi values are the same
    assert(abs(xds_phi - my_phi) < 0.1)

  # Test Passed
  print "OK"
예제 #8
0
def run():
  if not have_dials_regression:
    print "Skipping test: dials_regression not available."
    return

  from scitbx import matrix
  from iotbx.xds import xparm, integrate_hkl
  from dials.util import ioutil
  from math import ceil
  from dials.algorithms.spot_prediction import RotationAngles
  import dxtbx
  from rstbx.cftbx.coordinate_frame_converter import \
      coordinate_frame_converter

  # The XDS files to read from
  integrate_filename = join(dials_regression, 'data/sim_mx/INTEGRATE.HKL')
  gxparm_filename = join(dials_regression, 'data/sim_mx/GXPARM.XDS')

  # Read the XDS files
  integrate_handle = integrate_hkl.reader()
  integrate_handle.read_file(integrate_filename)
  gxparm_handle = xparm.reader()
  gxparm_handle.read_file(gxparm_filename)

  # Get the parameters we need from the GXPARM file
  models = dxtbx.load(gxparm_filename)
  beam = models.get_beam()
  gonio = models.get_goniometer()
  detector = models.get_detector()
  scan = models.get_scan()

  # Get the crystal parameters
  space_group_type = ioutil.get_space_group_type_from_xparm(gxparm_handle)
  cfc = coordinate_frame_converter(gxparm_filename)
  a_vec = cfc.get('real_space_a')
  b_vec = cfc.get('real_space_b')
  c_vec = cfc.get('real_space_c')
  unit_cell = cfc.get_unit_cell()
  UB = matrix.sqr(a_vec + b_vec + c_vec).inverse()
  ub_matrix = UB

  # Get the minimum resolution in the integrate file
  d = [unit_cell.d(h) for h in integrate_handle.hkl]
  d_min = min(d)

  # Get the number of frames from the max z value
  xcal, ycal, zcal = zip(*integrate_handle.xyzcal)
  num_frames = int(ceil(max(zcal)))
  scan.set_image_range((scan.get_image_range()[0],
                      scan.get_image_range()[0] + num_frames - 1))

  # Create the rotation angle object
  ra = RotationAngles(beam.get_s0(), gonio.get_rotation_axis())

  # Setup the matrices
  ub = matrix.sqr(ub_matrix)
  s0 = matrix.col(beam.get_s0())
  m2 = matrix.col(gonio.get_rotation_axis())

  # For all the miller indices
  for h in integrate_handle.hkl:
    h = matrix.col(h)

    # Calculate the angles
    angles = ra(h, ub)

    # For all the angles
    for phi in angles:
      r = m2.axis_and_angle_as_r3_rotation_matrix(angle=phi)
      pstar = r * ub * h
      s1 = s0 + pstar
      assert(abs(s1.length() - s0.length()) < 1e-7)

  print "OK"

  # Create a dict of lists of xy for each hkl
  gen_phi = {}
  for h in integrate_handle.hkl:

    # Calculate the angles
    angles = ra(h, ub)
    gen_phi[h] = angles
#        for phi in angles:
#            try:
#                a = gen_phi[h]
#                a.append(phi)
#                gen_phi[h] = a
#            except KeyError:
#                gen_phi[h] = [phi]

  # For each hkl in the xds file
  for hkl, xyz in zip(integrate_handle.hkl,
                      integrate_handle.xyzcal):

    # Calculate the XDS phi value
    xds_phi = scan.get_oscillation(deg=False)[0] + \
              xyz[2]*scan.get_oscillation(deg=False)[1]

    # Select the nearest xy to use if there are 2
    my_phi = gen_phi[hkl]
    if len(my_phi) == 2:
      my_phi0 = my_phi[0]
      my_phi1 = my_phi[1]
      diff0 = abs(xds_phi - my_phi0)
      diff1 = abs(xds_phi - my_phi1)
      if diff0 < diff1:
        my_phi = my_phi0
      else:
        my_phi = my_phi1
    else:
      my_phi = my_phi[0]

    # Check the Phi values are the same
    assert(abs(xds_phi - my_phi) < 0.1)

  # Test Passed
  print "OK"
예제 #9
0
  def __init__(self):
    from dials.algorithms.spot_prediction import IndexGenerator
    from dials.algorithms.spot_prediction import ScanStaticRayPredictor
    from dials.algorithms.spot_prediction import ray_intersection
    from iotbx.xds import xparm, integrate_hkl
    from dials.util import ioutil
    from math import ceil
    from os.path import realpath, dirname, join
    import dxtbx
    from rstbx.cftbx.coordinate_frame_converter import \
        coordinate_frame_converter
    from scitbx import matrix

    # The XDS files to read from
    test_path = dirname(dirname(dirname(realpath(__file__))))
    integrate_filename = join(test_path, 'data/sim_mx/INTEGRATE.HKL')
    gxparm_filename = join(test_path, 'data/sim_mx/GXPARM.XDS')

    # Read the XDS files
    self.integrate_handle = integrate_hkl.reader()
    self.integrate_handle.read_file(integrate_filename)
    self.gxparm_handle = xparm.reader()
    self.gxparm_handle.read_file(gxparm_filename)

    # Get the parameters we need from the GXPARM file
    models = dxtbx.load(gxparm_filename)
    self.beam = models.get_beam()
    self.gonio = models.get_goniometer()
    self.detector = models.get_detector()
    self.scan = models.get_scan()

    assert(len(self.detector) == 1)

    #print self.detector

    # Get crystal parameters
    self.space_group_type = ioutil.get_space_group_type_from_xparm(
        self.gxparm_handle)
    cfc = coordinate_frame_converter(gxparm_filename)
    a_vec = cfc.get('real_space_a')
    b_vec = cfc.get('real_space_b')
    c_vec = cfc.get('real_space_c')
    self.unit_cell = cfc.get_unit_cell()
    self.ub_matrix = matrix.sqr(a_vec + b_vec + c_vec).inverse()

    # Get the minimum resolution in the integrate file
    self.d_min = self.detector[0].get_max_resolution_at_corners(
        self.beam.get_s0())

    # Get the number of frames from the max z value
    xcal, ycal, zcal = zip(*self.integrate_handle.xyzcal)
    self.scan.set_image_range((self.scan.get_image_range()[0],
                               self.scan.get_image_range()[0] +
                                int(ceil(max(zcal)))))

    # Create the index generator
    generate_indices = IndexGenerator(self.unit_cell, self.space_group_type,
                                      self.d_min)

    s0 = self.beam.get_s0()
    m2 = self.gonio.get_rotation_axis()
    fixed_rotation = self.gonio.get_fixed_rotation()
    UB = self.ub_matrix
    dphi = self.scan.get_oscillation_range(deg=False)

    # Create the ray predictor
    self.predict_rays = ScanStaticRayPredictor(s0, m2, fixed_rotation, dphi)

    # Predict the spot locations
    self.reflections = self.predict_rays(
                                    generate_indices.to_array(), UB)

    # Calculate the intersection of the detector and reflection frames
    success = ray_intersection(self.detector, self.reflections)
    self.reflections.select(success)