Ejemplo n.º 1
0
def tst_set_mosflm_beam_centre(detector):
    from scitbx import matrix
    from dxtbx.model import Beam
    wavelength = 1
    panel = detector[0]
    detector_normal = matrix.col(panel.get_normal())
    origin = matrix.col(panel.get_origin())
    fast_axis = matrix.col(panel.get_fast_axis())
    slow_axis = matrix.col(panel.get_slow_axis())
    image_size = panel.get_image_size_mm()

    s0 = (1.0 / wavelength) * detector_normal
    beam = Beam(-s0.normalize(), wavelength)

    beam_centre = matrix.col(panel.get_beam_centre(beam.get_s0()))
    origin_shift = matrix.col((1, 0.5))
    new_beam_centre = beam_centre + origin_shift

    new_mosflm_beam_centre = tuple(reversed(new_beam_centre))

    from dxtbx.model.detector_helpers import set_mosflm_beam_centre
    set_mosflm_beam_centre(detector, beam, new_mosflm_beam_centre)

    assert (matrix.col(panel.get_beam_centre(beam.get_s0())) - matrix.col(
        tuple(reversed(new_mosflm_beam_centre)))).length() < 1e-6
Ejemplo n.º 2
0
def test_set_mosflm_beam_centre(detector):
    wavelength = 1.0
    panel = detector[0]
    detector_normal = matrix.col(panel.get_normal())
    _ = matrix.col(panel.get_origin())
    _ = matrix.col(panel.get_fast_axis())
    _ = matrix.col(panel.get_slow_axis())
    _ = panel.get_image_size_mm()

    s0 = (1.0 / wavelength) * detector_normal
    beam = Beam(-s0.normalize(), wavelength)

    beam_centre = matrix.col(panel.get_beam_centre(beam.get_s0()))
    origin_shift = matrix.col((1, 0.5))
    new_beam_centre = beam_centre + origin_shift

    new_mosflm_beam_centre = tuple(reversed(new_beam_centre))

    set_mosflm_beam_centre(detector, beam, new_mosflm_beam_centre)

    assert (
        matrix.col(panel.get_beam_centre(beam.get_s0()))
        - matrix.col(tuple(reversed(new_mosflm_beam_centre)))
    ).length() < 1e-6

    # test resolution methods
    beam = Beam(direction=(0, 0, 1), wavelength=1.0)
    d_min1 = detector.get_max_resolution(beam.get_s0())
    d_min2 = detector.get_max_inscribed_resolution(beam.get_s0())
    assert d_min1 < d_min2
Ejemplo n.º 3
0
def tst_set_direction_wavelength():
    """Test setting direction and wavelength"""
    from scitbx import matrix
    direction = matrix.col((0.013142, 0.002200, 1.450476))
    unit_direction = direction.normalize()
    wavelength = 0.689400

    # Create the beam
    b = Beam(direction, wavelength)

    eps = 1e-7

    # Check direction is a unit vector
    assert (abs(matrix.col(b.get_direction()).length() - 1) <= eps)
    assert (abs(matrix.col(b.get_direction()) - unit_direction) <= eps)

    # Check wavelength is correct
    assert (abs(b.get_wavelength() - wavelength) <= eps)

    # Check s0 is in direction and has length 1/wavelength
    assert (abs(matrix.col(b.get_s0()).length() - 1.0 / wavelength) <= eps)
    assert (abs(-matrix.col(b.get_s0()).normalize() - unit_direction) <= eps)

    # Test passed
    print "OK"
Ejemplo n.º 4
0
def tst_set_mosflm_beam_centre(detector):
  from scitbx import matrix
  from dxtbx.model import Beam
  wavelength = 1
  panel = detector[0]
  detector_normal = matrix.col(panel.get_normal())
  origin = matrix.col(panel.get_origin())
  fast_axis = matrix.col(panel.get_fast_axis())
  slow_axis = matrix.col(panel.get_slow_axis())
  image_size = panel.get_image_size_mm()

  s0 = (1.0/wavelength) * detector_normal
  beam = Beam(-s0.normalize(), wavelength)

  beam_centre = matrix.col(panel.get_beam_centre(beam.get_s0()))
  origin_shift = matrix.col((1, 0.5))
  new_beam_centre = beam_centre + origin_shift

  new_mosflm_beam_centre = tuple(reversed(new_beam_centre))

  from dxtbx.model.detector_helpers import set_mosflm_beam_centre
  set_mosflm_beam_centre(detector, beam, new_mosflm_beam_centre)

  assert (matrix.col(panel.get_beam_centre(beam.get_s0())) -
          matrix.col(tuple(reversed(new_mosflm_beam_centre)))).length() < 1e-6

  print 'OK'
Ejemplo n.º 5
0
def tst_set_direction_wavelength():
  """Test setting direction and wavelength"""
  from scitbx import matrix
  direction = matrix.col((0.013142, 0.002200, 1.450476))
  unit_direction = direction.normalize()
  wavelength = 0.689400

  # Create the beam
  b = Beam(direction, wavelength)

  eps = 1e-7

  # Check direction is a unit vector
  assert(abs(matrix.col(b.get_direction()).length() - 1) <= eps)
  assert(abs(matrix.col(b.get_direction()) - unit_direction) <= eps)

  # Check wavelength is correct
  assert(abs(b.get_wavelength() - wavelength) <= eps)

  # Check s0 is in direction and has length 1/wavelength
  assert(abs(matrix.col(b.get_s0()).length() - 1.0 / wavelength) <= eps)
  assert(abs(-matrix.col(b.get_s0()).normalize() - unit_direction) <= eps)

  # Test passed
  print "OK"
Ejemplo n.º 6
0
def tst_resolution(detector):
    from dxtbx.model import Beam

    beam = Beam(direction=(0, 0, 1), wavelength=1.0)
    d_min1 = detector.get_max_resolution(beam.get_s0())
    d_min2 = detector.get_max_inscribed_resolution(beam.get_s0())
    assert d_min1 < d_min2
Ejemplo n.º 7
0
def tst_resolution(detector):

  from dxtbx.model import Beam
  beam = Beam(direction=(0,0,1), wavelength=1.0)
  d_min1 = detector.get_max_resolution(beam.get_s0())
  d_min2 = detector.get_max_inscribed_resolution(beam.get_s0())
  assert d_min1 < d_min2
  print 'OK'
Ejemplo n.º 8
0
def test_setting_direction_and_wavelength():
    direction = matrix.col((0.013142, 0.002200, 1.450476))
    unit_direction = direction.normalize()
    wavelength = 0.689400

    # Create the beam
    b = Beam(direction, wavelength)

    eps = 1e-7

    # Check direction is a unit vector
    assert matrix.col(b.get_direction()).length() == pytest.approx(1)
    assert abs(matrix.col(b.get_direction()) - unit_direction) <= eps

    # Check wavelength is correct
    assert b.get_wavelength() == pytest.approx(wavelength)

    # Check s0 is in direction and has length 1/wavelength
    assert matrix.col(b.get_s0()).length() == pytest.approx(1.0 / wavelength)
    assert abs(-matrix.col(b.get_s0()).normalize() - unit_direction) <= eps
Ejemplo n.º 9
0
def test_beam_with_scan_points():
    b1 = Beam((1, 0, 0), 2, 0.1, 0.1)

    s0_static = matrix.col(b1.get_s0())
    b1.set_s0_at_scan_points([s0_static] * 5)
    d = b1.to_dict()
    b2 = BeamFactory.from_dict(d)

    for s0comp in d["s0_at_scan_points"]:
        assert matrix.col(s0comp) == s0_static

    for s0comp in b2.get_s0_at_scan_points():
        assert matrix.col(s0comp) == s0_static

    assert b1 == b2
Ejemplo n.º 10
0
def test_beam_with_scan_points():
    from dxtbx.model import Beam, BeamFactory
    b1 = Beam((1, 0, 0), 2, 0.1, 0.1)
    from scitbx import matrix
    s0_static = matrix.col(b1.get_s0())
    b1.set_s0_at_scan_points([s0_static] * 5)
    d = b1.to_dict()
    b2 = BeamFactory.from_dict(d)

    for s0comp in d['s0_at_scan_points']:
        assert matrix.col(s0comp) == s0_static

    for s0comp in b2.get_s0_at_scan_points():
        assert matrix.col(s0comp) == s0_static

    assert b1 == b2
Ejemplo n.º 11
0
def tst_scan_varying():

    from scitbx import matrix
    direction = matrix.col((0.013142, 0.002200, 1.450476))
    unit_direction = direction.normalize()
    wavelength = 0.689400
    s0 = -unit_direction * 1.0 / wavelength

    # Create the beam
    b = Beam(s0)

    assert b.get_num_scan_points() == 0
    assert b.get_s0_at_scan_points().size() == 0
    try:
        b.get_s0_at_scan_point(0)  # should raise RuntimeError
    except RuntimeError:
        pass

    # set varying beam
    num_scan_points = 11
    s0_static = matrix.col(b.get_s0())
    s0_as_scan_points = [s0_static]
    axis = matrix.col.random(3, -1., 1.).normalize()
    for i in range(num_scan_points - 1):
        s0_as_scan_points.append(s0_as_scan_points[-1].rotate_around_origin(
            axis, angle=0.01, deg=True))
    b.set_s0_at_scan_points(s0_as_scan_points)
    assert b.get_num_scan_points() == 11
    assert b.get_s0_at_scan_points().size() == 11

    for t in range(num_scan_points):
        s0_t = matrix.col(b.get_s0_at_scan_point(t))
        assert s0_t == s0_as_scan_points[t]

    # also test setting as tuple
    b.set_s0_at_scan_points(tuple(s0_as_scan_points))
    assert b.get_num_scan_points() == 11
    assert b.get_s0_at_scan_points().size() == 11

    # test resetting
    b.reset_scan_points()
    assert b.get_num_scan_points() == 0
    assert b.get_s0_at_scan_points().size() == 0

    print 'OK'