def __init__(self, plots = False):

    # Do we make scatterplots?
    self.do_plots = plots

    # Let's say we have a scan of 100 images
    self.image_range = (1, 100)

    # Make a random P1 crystal
    a = random.uniform(10,50) * \
        self.random_direction_close_to(matrix.col((1, 0, 0)))
    b = random.uniform(10,50) * \
        self.random_direction_close_to(matrix.col((0, 1, 0)))
    c = random.uniform(10,50) * \
        self.random_direction_close_to(matrix.col((0, 0, 1)))
    self.xl = crystal_model(a, b, c, space_group_symbol = "P 1")

    # Make a beam with wavelength in the range 0.8--1.2 and s0 direction close
    # to 0,0,1
    s0 = random.uniform(0.8, 1.2) * \
        self.random_direction_close_to(matrix.col((0, 0, 1)))
    self.beam = Beam(s0)

    # Make a standard goniometer model along X
    self.goniometer = Goniometer((1,0,0))

    # Make a simple single panel detector
    d1 = matrix.col((1, 0, 0))
    d2 = matrix.col((0, -1, 0))
    npx_fast = 1475
    npx_slow = 1679
    pix_size_f = pix_size_s = 0.172
    from dxtbx.model.experiment import detector_factory
    self.detector = detector_factory.make_detector("PAD", d1, d2,
      matrix.col((0, 0, -110)), (pix_size_f, pix_size_s),
      (npx_fast, npx_slow), (0, 2e20))
示例#2
0
def test_goniometer():
    '''A test class for the goniometer class.'''

    axis = (1, 0, 0)
    fixed = (1, 0, 0, 0, 1, 0, 0, 0, 1)

    xg = Goniometer(axis, fixed)

    assert (len(xg.get_rotation_axis()) == 3)
    assert (len(xg.get_fixed_rotation()) == 9)

    assert (compare_tuples(xg.get_rotation_axis(), axis))
    assert (compare_tuples(xg.get_fixed_rotation(), fixed))

    single = goniometer_factory.single_axis()

    assert (len(single.get_rotation_axis()) == 3)
    assert (len(single.get_fixed_rotation()) == 9)

    assert (compare_tuples(single.get_rotation_axis(), axis))
    assert (compare_tuples(single.get_fixed_rotation(), fixed))

    kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'omega')

    assert (len(kappa.get_rotation_axis()) == 3)
    assert (len(kappa.get_fixed_rotation()) == 9)
    assert (compare_tuples(kappa.get_rotation_axis(), axis))
    assert (compare_tuples(kappa.get_fixed_rotation(), fixed))

    kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'omega')

    assert (len(kappa.get_rotation_axis()) == 3)
    assert (len(kappa.get_fixed_rotation()) == 9)

    assert (compare_tuples(kappa.get_rotation_axis(), axis))
    assert (compare_tuples(kappa.get_fixed_rotation(), fixed))

    kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'phi')

    assert (len(kappa.get_rotation_axis()) == 3)
    assert (len(kappa.get_fixed_rotation()) == 9)

    assert (compare_tuples(kappa.get_rotation_axis(), axis))
    assert (compare_tuples(kappa.get_fixed_rotation(), fixed))

    kappa = goniometer_factory.kappa(50.0, 0.0, 30.0, 0.0, '-y', 'omega')

    assert (len(kappa.get_rotation_axis()) == 3)
    assert (len(kappa.get_fixed_rotation()) == 9)

    assert (compare_tuples(kappa.get_rotation_axis(), axis))
    assert (not compare_tuples(kappa.get_fixed_rotation(), fixed))

    import libtbx.load_env
    import os

    dxtbx_dir = libtbx.env.dist_path('dxtbx')

    image = os.path.join(dxtbx_dir, 'tests', 'phi_scan_001.cbf')
    cbf = goniometer_factory.imgCIF(image)

    kappa = goniometer_factory.kappa(50.0, -10.0, 30.0, 0.0, '-y', 'phi')

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2

    image = os.path.join(dxtbx_dir, 'tests', 'omega_scan.cbf')
    cbf = goniometer_factory.imgCIF(image)

    kappa = goniometer_factory.kappa(50.0, -10.0, 30.0, 20.0, '-y', 'omega')

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2

    print 'OK'
示例#3
0
def test_goniometer():
  '''A test class for the goniometer class.'''


  axis = (1, 0, 0)
  fixed = (1, 0, 0, 0, 1, 0, 0, 0, 1)

  xg = Goniometer(axis, fixed)

  assert(len(xg.get_rotation_axis()) == 3)
  assert(len(xg.get_fixed_rotation()) == 9)

  assert(compare_tuples(xg.get_rotation_axis(), axis))
  assert(compare_tuples(xg.get_fixed_rotation(), fixed))

  single = goniometer_factory.single_axis()

  assert(len(single.get_rotation_axis()) == 3)
  assert(len(single.get_fixed_rotation()) == 9)

  assert(compare_tuples(single.get_rotation_axis(), axis))
  assert(compare_tuples(single.get_fixed_rotation(), fixed))

  kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'omega')

  assert(len(kappa.get_rotation_axis()) == 3)
  assert(len(kappa.get_fixed_rotation()) == 9)
  assert(compare_tuples(kappa.get_rotation_axis(), axis))
  assert(compare_tuples(kappa.get_fixed_rotation(), fixed))

  kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'omega')

  assert(len(kappa.get_rotation_axis()) == 3)
  assert(len(kappa.get_fixed_rotation()) == 9)

  assert(compare_tuples(kappa.get_rotation_axis(), axis))
  assert(compare_tuples(kappa.get_fixed_rotation(), fixed))

  kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'phi')

  assert(len(kappa.get_rotation_axis()) == 3)
  assert(len(kappa.get_fixed_rotation()) == 9)

  assert(compare_tuples(kappa.get_rotation_axis(), axis))
  assert(compare_tuples(kappa.get_fixed_rotation(), fixed))

  kappa = goniometer_factory.kappa(50.0, 0.0, 30.0, 0.0, '-y', 'omega')

  assert(len(kappa.get_rotation_axis()) == 3)
  assert(len(kappa.get_fixed_rotation()) == 9)

  assert(compare_tuples(kappa.get_rotation_axis(), axis))
  assert(not compare_tuples(kappa.get_fixed_rotation(), fixed))

  import libtbx.load_env
  import os

  dxtbx_dir = libtbx.env.dist_path('dxtbx')

  image = os.path.join(dxtbx_dir, 'tests', 'phi_scan_001.cbf')
  cbf = goniometer_factory.imgCIF(image)

  kappa = goniometer_factory.kappa(50.0, -10.0, 30.0, 0.0, '-y', 'phi')

  s = easy_pickle.dumps(kappa)
  kappa2 = easy_pickle.loads(s)
  assert kappa == kappa2

  image = os.path.join(dxtbx_dir, 'tests', 'omega_scan.cbf')
  cbf = goniometer_factory.imgCIF(image)

  kappa = goniometer_factory.kappa(50.0, -10.0, 30.0, 20.0, '-y', 'omega')

  s = easy_pickle.dumps(kappa)
  kappa2 = easy_pickle.loads(s)
  assert kappa == kappa2

  print 'OK'
示例#4
0
def test_comparison():
    # Setting rotation for small random offset
    offset_ax = matrix.col.random(3, -1.0, 1.0).normalize()
    S = offset_ax.axis_and_angle_as_r3_rotation_matrix(angle=0.01, deg=True)

    # Equal goniometers with scan-points set
    g1 = Goniometer((1, 0, 0))
    g1.set_setting_rotation(S)
    g1.set_setting_rotation_at_scan_points([S] * 5)
    g2 = Goniometer((1, 0, 0))
    g2.set_setting_rotation(S)
    g2.set_setting_rotation_at_scan_points([S] * 5)

    assert g1 == g2
    assert g1.is_similar_to(g2)

    # Different setting matrix
    g3 = Goniometer((1, 0, 0))
    invS = S.inverse()
    g3.set_setting_rotation(invS)
    g3.set_setting_rotation_at_scan_points([invS] * 5)

    assert g1 != g3
    assert not g1.is_similar_to(g3)
示例#5
0
def test_scan_varying():
    axis = (1, 0, 0)
    g = Goniometer(axis)

    assert g.get_num_scan_points() == 0
    assert g.get_setting_rotation_at_scan_points().size() == 0
    with pytest.raises(RuntimeError):
        g.get_setting_rotation_at_scan_point(0)

    # set varying beam
    num_scan_points = 11
    S_static = matrix.sqr(g.get_setting_rotation())
    S_as_scan_points = [S_static]
    axis = matrix.col.random(3, -1.0, 1.0).normalize()
    R = axis.axis_and_angle_as_r3_rotation_matrix(angle=0.01, deg=True)
    for i in range(num_scan_points - 1):
        S_as_scan_points.append(R * S_as_scan_points[-1])
    g.set_setting_rotation_at_scan_points(S_as_scan_points)
    assert g.get_num_scan_points() == 11
    assert g.get_setting_rotation_at_scan_points().size() == 11

    for t in range(num_scan_points):
        S_t = matrix.sqr(g.get_setting_rotation_at_scan_point(t))
        assert S_t == S_as_scan_points[t]

    # also test setting as tuple
    g.set_setting_rotation_at_scan_points(tuple(S_as_scan_points))
    assert g.get_num_scan_points() == 11
    assert g.get_setting_rotation_at_scan_points().size() == 11

    # test resetting
    g.reset_scan_points()
    assert g.get_num_scan_points() == 0
    assert g.get_setting_rotation_at_scan_points().size() == 0
示例#6
0
def test_goniometer():
    """A test class for the goniometer class."""

    axis = (1, 0, 0)
    fixed = (1, 0, 0, 0, 1, 0, 0, 0, 1)

    xg = Goniometer(axis, fixed)

    assert len(xg.get_rotation_axis()) == 3
    assert len(xg.get_fixed_rotation()) == 9

    _compare_tuples(xg.get_rotation_axis(), axis)
    _compare_tuples(xg.get_fixed_rotation(), fixed)

    single = GoniometerFactory.single_axis()

    assert len(single.get_rotation_axis()) == 3
    assert len(single.get_fixed_rotation()) == 9

    _compare_tuples(single.get_rotation_axis(), axis)
    _compare_tuples(single.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9
    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "phi")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 30.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    with pytest.raises(AssertionError):
        _compare_tuples(kappa.get_fixed_rotation(), fixed)

    import libtbx.load_env

    dxtbx_dir = libtbx.env.dist_path("dxtbx")

    image = os.path.join(dxtbx_dir, "tests", "phi_scan_001.cbf")
    assert GoniometerFactory.imgCIF(image)

    kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 0.0, "-y", "phi")

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2

    image = os.path.join(dxtbx_dir, "tests", "omega_scan.cbf")
    assert GoniometerFactory.imgCIF(image)

    kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 20.0, "-y", "omega")

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2
示例#7
0
def test_goniometer():
    """A test class for the goniometer class."""

    axis = (1, 0, 0)
    fixed = (1, 0, 0, 0, 1, 0, 0, 0, 1)

    xg = Goniometer(axis, fixed)

    assert len(xg.get_rotation_axis()) == 3
    assert len(xg.get_fixed_rotation()) == 9

    _compare_tuples(xg.get_rotation_axis(), axis)
    _compare_tuples(xg.get_fixed_rotation(), fixed)

    single = GoniometerFactory.single_axis()

    assert len(single.get_rotation_axis()) == 3
    assert len(single.get_fixed_rotation()) == 9

    _compare_tuples(single.get_rotation_axis(), axis)
    _compare_tuples(single.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9
    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "phi")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 30.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    with pytest.raises(AssertionError):
        _compare_tuples(kappa.get_fixed_rotation(), fixed)

    image = Path(__file__).parent / "phi_scan_001.cbf"
    assert GoniometerFactory.imgCIF(str(image))

    kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 0.0, "-y", "phi")

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2

    image = Path(__file__).parent / "omega_scan.cbf"
    assert GoniometerFactory.imgCIF(str(image))

    kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 20.0, "-y", "omega")

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2