Example #1
0
  def run(self):

    from iotbx.xds import xds_inp
    import os
    import libtbx.load_env
    iotbx_dir = libtbx.env.dist_path('iotbx')

    filename = os.path.join(iotbx_dir, 'xds', 'tests', 'XDS.INP')
    handle = xds_inp.reader()
    handle.read_file(filename)

    assert handle.detector == 'PILATUS'
    assert handle.minimum_valid_pixel_value == 0
    assert handle.overload == 1048500
    assert handle.corrections == 'ALL'
    assert handle.direction_of_detector_x_axis == [1.0, 0.0, 0.0]
    assert handle.direction_of_detector_y_axis == [0.0, 1.0, 0.0]
    assert handle.trusted_region == [0.0, 1.41]
    assert handle.sensor_thickness == 0.32
    assert handle.untrusted_rectangle == [
      [487, 495, 0, 2528], [981, 989, 0, 2528], [1475, 1483, 0, 2528],
      [1969, 1977, 0, 2528], [0, 2464, 195, 213], [0, 2464, 407, 425],
      [0, 2464, 619, 637], [0, 2464, 831, 849], [0, 2464, 1043, 1061],
      [0, 2464, 1255, 1273], [0, 2464, 1467, 1485], [0, 2464, 1679, 1697],
      [0, 2464, 1891, 1909], [0, 2464, 2103, 2121], [0, 2464, 2315, 2333]]
    assert handle.maximum_number_of_processor == 16
    assert (handle.nx, handle.ny, handle.px, handle.py) == (2463, 2527, 0.172, 0.172)
    assert (handle.orgx, handle.orgy) == (1279.1, 1235.3)
    assert handle.rotation_axis == [1.0, 0.0, 0.0]
    assert handle.detector_distance == 190.18
    assert handle.xray_wavelength == 0.9795
    assert handle.incident_beam_direction == [0.0, 0.0, 1.0]
    assert handle.fraction_of_polarization == 0.99
    assert handle.polarization_plane_normal == [0.0, 1.0, 0.0]
    assert handle.friedels_law
    assert len(handle.name_template_of_data_frames) == 1
    assert handle.name_template_of_data_frames[0].endswith(
      'X4_lots_M1S4_1_????.cbf')
    assert handle.starting_angle == 0
    assert handle.starting_frame == 1
    assert handle.include_resolution_range == [30.0, 1.27]
    assert handle.unit_cell_constants == [42.45, 42.45, 39.8, 90.0, 90.0, 90.0]
    assert handle.space_group_number == 89
    assert handle.max_fac_rmeas == 3.0
    assert handle.data_range == [1,900]

    filename_1 = os.path.join(iotbx_dir, 'xds', 'tests', 'XDS_2.INP')
    tmp_dir = open_tmp_directory()
    filename_2 = os.path.join(tmp_dir, 'XDS.INP')
    with open(filename_2, 'wb') as f:
      print >> f, open(filename_1, 'rb').read()
    handle = xds_inp.reader()
    handle.read_file(filename_2)
    assert handle.corrections is None
    assert handle.incident_beam_direction == [-0.003, 0.001, 1.032]
    assert len(handle.name_template_of_data_frames) == 2
    assert handle.name_template_of_data_frames[0] == '/blah/xtal1_1_????.cbf'
    assert handle.name_template_of_data_frames[1] == 'CBF'

    print 'OK'
Example #2
0
def to_imageset(input_filename, extra_filename=None):
  '''Get an image set from the xds input filename plus an extra filename

  Params:
      input_filename The XDS.INP file
      extra_filename A (G)XPARM.XDS, INTGRATE.HKL or XDS_ASCII.HKL file

  Returns:
      The imageset

  '''
  from iotbx.xds import xds_inp
  from dxtbx.imageset import ImageSetFactory
  import dxtbx

  # Read the input filename
  handle = xds_inp.reader()
  handle.read_file(input_filename)

  # Get the template
  template = handle.name_template_of_data_frames[0].replace('?', '#')
  image_range = handle.data_range
  detector_name = handle.detector

  if extra_filename is not None:
    # we can get all the extra dxtbx models from extra_filename
    check_format = False
  else:
    # we need the image files present to get the dxtbx models
    check_format = True

  # Create the imageset
  imageset = ImageSetFactory.from_template(
    template, image_range=image_range, check_format=False)[0]

  # If an extra filename has been specified, try to load models
  if extra_filename:
    models = dxtbx.load(extra_filename)
    detector = models.get_detector()
    if detector_name.strip() == 'PILATUS':
      from dxtbx.model import ParallaxCorrectedPxMmStrategy
      from cctbx.eltbx import attenuation_coefficient
      table = attenuation_coefficient.get_table("Si")
      wavelength = models.get_beam().get_wavelength()
      mu = table.mu_at_angstrom(wavelength) / 10.0
      t0 = handle.sensor_thickness
      for panel in detector:
        panel.set_px_mm_strategy(ParallaxCorrectedPxMmStrategy(mu, t0))
        panel.set_trusted_range(
          (handle.minimum_valid_pixel_value, handle.overload))
    imageset.set_beam(models.get_beam())
    imageset.set_detector(detector)
    imageset.set_goniometer(models.get_goniometer())
    # take the image range from XDS.INP
    scan = models.get_scan()
    scan.set_image_range(image_range)
    imageset.set_scan(scan)

  # Return the imageset
  return imageset
def import_xds_inp(xds_inp_file):
    '''Read an XDS XPARM file, transform the parameters contained therein
    into the standard coordinate frame, record this as a dictionary.'''
    from iotbx.xds import xds_inp

    handle = xds_inp.reader()
    handle.read_file(xds_inp_file)

    # first determine the rotation R from the XDS coordinate frame used in
    # the processing to the central (i.e. imgCIF) coordinate frame. N.B.
    # if the scan was e.g. a PHI scan the resulting frame could well come out
    # a little odd...

    axis = handle.rotation_axis
    beam = handle.incident_beam_direction
    x, y = handle.direction_of_detector_x_axis, handle.direction_of_detector_y_axis

    # XDS defines the beam vector as s0 rather than from sample -> source.

    B = - matrix.col(beam).normalize()
    A = matrix.col(axis).normalize()

    X = matrix.col(x).normalize()
    Y = matrix.col(y).normalize()
    N = X.cross(Y)

    _X = matrix.col([1, 0, 0])
    _Y = matrix.col([0, 1, 0])
    _Z = matrix.col([0, 0, 1])

    R = align_reference_frame(A, _X, B, _Z)

    # now transform contents of the XPARM file to the form which we want to
    # return...

    nx, ny = handle.nx, handle.ny
    px, py = handle.px, handle.py

    distance = handle.detector_distance
    ox, oy = handle.orgx, handle.orgy

    # Need to subtract 0.5 because XDS seems to do centroids in fortran coords
    ox = ox - 0.5
    oy = oy - 0.5

    detector_origin = R * (distance * N - ox * px * X - oy * py * Y)
    detector_fast = R * X
    detector_slow = R * Y
    rotation_axis = R * A
    sample_to_source = R * B
    wavelength = handle.xray_wavelength
    real_space_a, real_space_b, real_space_c = None, None, None
    space_group_number = handle.space_group_number
    starting_angle = handle.starting_angle
    oscillation_range = handle.oscillation_range
    starting_frame = handle.starting_frame
    data_range = handle.data_range

    panel_offset = None
    panel_size = None
    panel_origins = None
    panel_fast_axes = None
    panel_slow_axes = None

    if handle.num_segments > 1:
        # Now, for each detector segment the following two lines of information
        # are provided.

        # The 5 numbers of this line, iseg x1 x2 y1 y2, define the pixel numbers
        # IX,IY belonging to segment #iseg as x1<=IX<=x2, y1<=IY<=y2.
        # The 9 numbers of this line, ORGXS ORGYS FS EDS(:,1) EDS(:,2), describe
        # origin and orientation of segment #iseg with respect to the detector
        # coordinate system.

        panel_offset = []
        panel_size = []
        panel_origins = []
        panel_fast_axes = []
        panel_slow_axes = []
        for i in range(handle.num_segments):
            x1, x2, y1, y2 = handle.segment[i]
            # XDS panel limits inclusive range
            panel_offset.append((x1-1, y1-1))
            panel_size.append((x2-x1+1, y2-y1+1))
            panel_fast = matrix.col(handle.direction_of_segment_x_axis[i])
            panel_slow = matrix.col(handle.direction_of_segment_y_axis[i])
            # local basis vectors
            fl = matrix.col(panel_fast)
            sl = matrix.col(panel_slow)
            nl = fl.cross(sl)

            orgxs = handle.segment_orgx[i]
            orgys = handle.segment_orgy[i]
            fs = handle.segment_distance[i]
            panel_origin = R * (- (orgxs - x1 + 1) * px * fl \
                                - (orgys - y1 + 1) * py * sl \
                                + fs * nl ) \
                + detector_origin

            # detector to laboratory transformation
            ED = matrix.sqr(list(X) + list(Y) + list(N))

            panel_normal = (R * panel_fast).cross(R * panel_slow)
            panel_origins.append(panel_origin)
            panel_fast_axes.append(R * ED * panel_fast)
            panel_slow_axes.append(R * ED * panel_slow)

    return coordinate_frame_information(
        detector_origin, detector_fast, detector_slow, (nx, ny), (px, py),
        rotation_axis, sample_to_source, wavelength,
        real_space_a, real_space_b, real_space_c, space_group_number,
        None, None, starting_angle, oscillation_range, starting_frame,
        original_rotation=R,
        data_range=data_range,
        panel_offset=panel_offset,
        panel_size=panel_size,
        panel_origin=panel_origins,
        panel_fast=panel_fast_axes,
        panel_slow=panel_slow_axes)
Example #4
0
File: xds.py Project: hbrunie/dxtbx
def to_imageset(input_filename, extra_filename=None):
    """Get an image set from the xds input filename plus an extra filename

    Params:
        input_filename The XDS.INP file
        extra_filename A (G)XPARM.XDS, INTGRATE.HKL or XDS_ASCII.HKL file

    Returns:
        The imageset

    """
    from iotbx.xds import xds_inp
    from dxtbx.imageset import ImageSetFactory
    import dxtbx

    # Read the input filename
    handle = xds_inp.reader()
    handle.read_file(input_filename)

    # Get the template
    template = handle.name_template_of_data_frames[0].replace("?", "#")
    if template.endswith("h5"):
        template = template.replace("######", "master")
    image_range = handle.data_range
    detector_name = handle.detector

    if extra_filename is not None:
        # we can get all the extra dxtbx models from extra_filename
        check_format = False
    else:
        # we need the image files present to get the dxtbx models
        check_format = True

    # If an extra filename has been specified, try to load models
    if extra_filename:
        models = dxtbx.load(extra_filename)
        detector = models.get_detector()
        if detector_name.strip() in ("PILATUS",
                                     "EIGER") or handle.silicon is not None:
            from dxtbx.model import ParallaxCorrectedPxMmStrategy
            from cctbx.eltbx import attenuation_coefficient

            if handle.silicon is None:
                table = attenuation_coefficient.get_table("Si")
                wavelength = models.get_beam().get_wavelength()
                mu = table.mu_at_angstrom(wavelength) / 10.0
            else:
                mu = handle.silicon
            t0 = handle.sensor_thickness
            for panel in detector:
                panel.set_px_mm_strategy(ParallaxCorrectedPxMmStrategy(mu, t0))
                panel.set_trusted_range(
                    (handle.minimum_valid_pixel_value, handle.overload))
        beam = models.get_beam()
        detector = models.get_detector()
        goniometer = models.get_goniometer()
        scan = models.get_scan()
        scan.set_image_range(image_range)
    else:
        beam = None
        detector = None
        goniometer = None
        scan = None

    # Create the imageset
    imageset = ImageSetFactory.from_template(
        template,
        image_range=image_range,
        check_format=check_format,
        beam=beam,
        detector=detector,
        goniometer=goniometer,
        scan=scan,
    )[0]

    # Return the imageset
    return imageset
def import_xds_as_still(xdsinp, xparm_in):
    #from dxtbx.serialize import xds
    from dxtbx.datablock import DataBlockFactory

    # Get the sweep from the XDS files
    #sweep = xds.to_imageset(xds_inp, xds_other)

    from iotbx.xds import xds_inp
    from dxtbx.imageset import ImageSetFactory
    import dxtbx

    # Read the input filename
    handle = xds_inp.reader()
    handle.read_file(xdsinp)

    # Get the template
    template = handle.name_template_of_data_frames[0]
    image_range = handle.data_range
    detector_name = handle.detector

    #assert image_range[0] == image_range[1]
    im_nr = int((image_range[1] - image_range[0] + 1) / 2)

    from yamtbx.dataproc.dataset import template_to_filenames

    # Create the imageset
    #imageset = ImageSetFactory.from_template(template, image_range=image_range, check_format=False)[0]
    imageset = ImageSetFactory.make_imageset(
        [os.path.realpath(template_to_filenames(template, im_nr, im_nr)[0])])

    models = dxtbx.load(xparm_in)
    detector = models.get_detector()
    if detector_name.strip() in ('PILATUS',
                                 'EIGER') or handle.silicon is not None:
        from dxtbx.model import ParallaxCorrectedPxMmStrategy
        from cctbx.eltbx import attenuation_coefficient
        if handle.silicon is None:
            table = attenuation_coefficient.get_table("Si")
            wavelength = models.get_beam().get_wavelength()
            mu = table.mu_at_angstrom(wavelength) / 10.0
        else:
            mu = handle.silicon
        t0 = handle.sensor_thickness
        for panel in detector:
            panel.set_px_mm_strategy(ParallaxCorrectedPxMmStrategy(mu, t0))
            panel.set_trusted_range(
                (handle.minimum_valid_pixel_value, handle.overload))

    imageset.set_beam(models.get_beam())
    imageset.set_detector(detector)
    imageset.set_goniometer(None)
    imageset.set_scan(None)
    #imageset.set_goniometer(models.get_goniometer())
    # take the image range from XDS.INP
    #scan = models.get_scan()
    #scan.set_image_range(image_range)
    #imageset.set_scan(scan)

    from dxtbx.serialize import xds

    # Get the crystal from the XDS files
    crystal = xds.to_crystal(xparm_in)

    # Create the experiment list
    experiments = ExperimentListFactory.from_imageset_and_crystal(
        imageset, crystal)

    # Set the crystal in the experiment list
    assert (len(experiments) == 1)

    # Return the experiment list
    return experiments
Example #6
0
def to_imageset(input_filename, extra_filename=None):
    '''Get an image set from the xds input filename plus an extra filename

  Params:
      input_filename The XDS.INP file
      extra_filename A (G)XPARM.XDS, INTGRATE.HKL or XDS_ASCII.HKL file

  Returns:
      The imageset

  '''
    from iotbx.xds import xds_inp
    from dxtbx.imageset import ImageSetFactory
    import dxtbx

    # Read the input filename
    handle = xds_inp.reader()
    handle.read_file(input_filename)

    # Get the template
    template = handle.name_template_of_data_frames[0].replace('?', '#')
    image_range = handle.data_range
    detector_name = handle.detector

    if extra_filename is not None:
        # we can get all the extra dxtbx models from extra_filename
        check_format = False
    else:
        # we need the image files present to get the dxtbx models
        check_format = True

    # Create the imageset
    imageset = ImageSetFactory.from_template(template,
                                             image_range=image_range,
                                             check_format=False)[0]

    # If an extra filename has been specified, try to load models
    if extra_filename:
        models = dxtbx.load(extra_filename)
        detector = models.get_detector()
        if detector_name.strip() == 'PILATUS':
            from dxtbx.model import ParallaxCorrectedPxMmStrategy
            from cctbx.eltbx import attenuation_coefficient
            table = attenuation_coefficient.get_table("Si")
            wavelength = models.get_beam().get_wavelength()
            mu = table.mu_at_angstrom(wavelength) / 10.0
            t0 = handle.sensor_thickness
            for panel in detector:
                panel.set_px_mm_strategy(ParallaxCorrectedPxMmStrategy(mu, t0))
                panel.set_trusted_range(
                    (handle.minimum_valid_pixel_value, handle.overload))
        imageset.set_beam(models.get_beam())
        imageset.set_detector(detector)
        imageset.set_goniometer(models.get_goniometer())
        # take the image range from XDS.INP
        scan = models.get_scan()
        scan.set_image_range(image_range)
        imageset.set_scan(scan)

    # Return the imageset
    return imageset