示例#1
0
def test_multi_axis_goniometer():
  from libtbx.test_utils import approx_equal
  from scitbx.array_family import flex

  alpha = 50
  omega = -10
  kappa = 30
  phi = 20
  direction = '-y'

  from dxtbx.model.goniometer import KappaGoniometer
  kappa_omega_scan = KappaGoniometer(
    alpha, omega, kappa, phi, direction, 'omega')
  axes = (kappa_omega_scan.get_phi_axis(), kappa_omega_scan.get_kappa_axis(),
          kappa_omega_scan.get_omega_axis())
  angles = (kappa_omega_scan.get_phi_angle(), kappa_omega_scan.get_kappa_angle(),
            kappa_omega_scan.get_omega_angle())

  # First test a kappa goniometer with omega as the scan axis
  axes = flex.vec3_double(axes)
  angles = flex.double(angles)
  names = flex.std_string(('phi', 'kappa', 'omega'))
  scan_axis = 2

  multi_axis_omega_scan = goniometer_factory.multi_axis(
    axes, angles, names, scan_axis)
  assert approx_equal(multi_axis_omega_scan.get_fixed_rotation(), kappa_omega_scan.get_fixed_rotation())
  assert approx_equal(multi_axis_omega_scan.get_rotation_axis(), kappa_omega_scan.get_rotation_axis())

  recycle_omega = MultiAxisGoniometer.from_dict(multi_axis_omega_scan.to_dict())
  assert approx_equal(recycle_omega.get_axes(), multi_axis_omega_scan.get_axes())
  assert approx_equal(recycle_omega.get_angles(), multi_axis_omega_scan.get_angles())
  assert recycle_omega.get_scan_axis() == multi_axis_omega_scan.get_scan_axis()

  # Now test a kappa goniometer with phi as the scan axis
  kappa_phi_scan = KappaGoniometer(
    alpha, omega, kappa, phi, direction, 'phi')

  scan_axis = 0
  multi_axis_phi_scan = goniometer_factory.multi_axis(
    axes, angles, names, scan_axis)
  assert approx_equal(multi_axis_phi_scan.get_fixed_rotation(), kappa_phi_scan.get_fixed_rotation())
  from scitbx import matrix
  assert approx_equal(matrix.sqr(multi_axis_phi_scan.get_setting_rotation()) * multi_axis_phi_scan.get_rotation_axis(), kappa_phi_scan.get_rotation_axis())

  recycle_phi = MultiAxisGoniometer.from_dict(multi_axis_phi_scan.to_dict())
  assert approx_equal(recycle_phi.get_axes(), multi_axis_phi_scan.get_axes())
  assert approx_equal(recycle_phi.get_angles(), multi_axis_phi_scan.get_angles())
  assert recycle_phi.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()

  s = easy_pickle.dumps(multi_axis_phi_scan)
  recycle = easy_pickle.loads(s)
  assert recycle == multi_axis_phi_scan

  assert approx_equal(recycle.get_axes(), multi_axis_phi_scan.get_axes())
  assert approx_equal(recycle.get_angles(), multi_axis_phi_scan.get_angles())
  assert recycle.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()
  recycle.set_angles((0,90,180))
  assert approx_equal(recycle.get_angles(), (0, 90, 180))
  new_axes = (0.9, 0.1, 0.0), (0.6427876096865394, -0.766044443118978, 0.0), (1.0, 0.0, 0.0)
  new_axes = flex.vec3_double(
    ((0.99996, -0.00647, -0.00659), (0.91314, 0.27949, -0.29674),
     (1.00000, -0.00013, -0.00064)))
  recycle.set_axes(new_axes)
  assert approx_equal(recycle.get_axes(), new_axes)

  # Check exception is raised if scan axis is out range
  try: goniometer_factory.multi_axis(axes, angles, names, 3)
  except RuntimeError, e: pass
  else: raise Exception_expected

  # Single axis is just a special case of a multi axis goniometer
  single_axis = goniometer_factory.multi_axis(
    flex.vec3_double(((1,0,0),)), flex.double((0,)), flex.std_string(('PHI',)), 0)
  assert single_axis.get_fixed_rotation() == (1,0,0,0,1,0,0,0,1)
  assert single_axis.get_setting_rotation() == (1,0,0,0,1,0,0,0,1)
  assert single_axis.get_rotation_axis() == (1,0,0)

  print 'OK'
示例#2
0
def test_multi_axis_goniometer():
    from libtbx.test_utils import approx_equal
    from scitbx.array_family import flex

    alpha = 50
    omega = -10
    kappa = 30
    phi = 20
    direction = '-y'

    from dxtbx.model.goniometer import KappaGoniometer
    kappa_omega_scan = KappaGoniometer(alpha, omega, kappa, phi, direction,
                                       'omega')
    axes = (kappa_omega_scan.get_phi_axis(), kappa_omega_scan.get_kappa_axis(),
            kappa_omega_scan.get_omega_axis())
    angles = (kappa_omega_scan.get_phi_angle(),
              kappa_omega_scan.get_kappa_angle(),
              kappa_omega_scan.get_omega_angle())

    # First test a kappa goniometer with omega as the scan axis
    axes = flex.vec3_double(axes)
    angles = flex.double(angles)
    names = flex.std_string(('phi', 'kappa', 'omega'))
    scan_axis = 2

    multi_axis_omega_scan = goniometer_factory.multi_axis(
        axes, angles, names, scan_axis)
    assert approx_equal(multi_axis_omega_scan.get_fixed_rotation(),
                        kappa_omega_scan.get_fixed_rotation())
    assert approx_equal(multi_axis_omega_scan.get_rotation_axis(),
                        kappa_omega_scan.get_rotation_axis())

    recycle_omega = MultiAxisGoniometer.from_dict(
        multi_axis_omega_scan.to_dict())
    assert approx_equal(recycle_omega.get_axes(),
                        multi_axis_omega_scan.get_axes())
    assert approx_equal(recycle_omega.get_angles(),
                        multi_axis_omega_scan.get_angles())
    assert recycle_omega.get_scan_axis(
    ) == multi_axis_omega_scan.get_scan_axis()

    # Now test a kappa goniometer with phi as the scan axis
    kappa_phi_scan = KappaGoniometer(alpha, omega, kappa, phi, direction,
                                     'phi')

    scan_axis = 0
    multi_axis_phi_scan = goniometer_factory.multi_axis(
        axes, angles, names, scan_axis)
    assert approx_equal(multi_axis_phi_scan.get_fixed_rotation(),
                        kappa_phi_scan.get_fixed_rotation())
    from scitbx import matrix
    assert approx_equal(
        matrix.sqr(multi_axis_phi_scan.get_setting_rotation()) *
        multi_axis_phi_scan.get_rotation_axis_datum(),
        kappa_phi_scan.get_rotation_axis())
    assert approx_equal(multi_axis_phi_scan.get_rotation_axis(),
                        kappa_phi_scan.get_rotation_axis())

    recycle_phi = MultiAxisGoniometer.from_dict(multi_axis_phi_scan.to_dict())
    assert approx_equal(recycle_phi.get_axes(), multi_axis_phi_scan.get_axes())
    assert approx_equal(recycle_phi.get_angles(),
                        multi_axis_phi_scan.get_angles())
    assert recycle_phi.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()

    s = easy_pickle.dumps(multi_axis_phi_scan)
    recycle = easy_pickle.loads(s)
    assert recycle == multi_axis_phi_scan

    assert approx_equal(recycle.get_axes(), multi_axis_phi_scan.get_axes())
    assert approx_equal(recycle.get_angles(), multi_axis_phi_scan.get_angles())
    assert recycle.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()
    recycle.set_angles((0, 90, 180))
    assert approx_equal(recycle.get_angles(), (0, 90, 180))
    new_axes = (0.9, 0.1, 0.0), (0.6427876096865394, -0.766044443118978,
                                 0.0), (1.0, 0.0, 0.0)
    new_axes = flex.vec3_double(
        ((0.99996, -0.00647, -0.00659), (0.91314, 0.27949, -0.29674),
         (1.00000, -0.00013, -0.00064)))
    recycle.set_axes(new_axes)
    assert approx_equal(recycle.get_axes(), new_axes)

    # Check exception is raised if scan axis is out range
    try:
        goniometer_factory.multi_axis(axes, angles, names, 3)
    except RuntimeError, e:
        pass
示例#3
0
def test_multi_axis_goniometer():
    from libtbx.test_utils import approx_equal
    from scitbx.array_family import flex

    alpha = 50
    omega = -10
    kappa = 30
    phi = 20
    direction = "-y"

    from dxtbx.model.goniometer import KappaGoniometer

    kappa_omega_scan = KappaGoniometer(alpha, omega, kappa, phi, direction,
                                       "omega")
    axes = (
        kappa_omega_scan.get_phi_axis(),
        kappa_omega_scan.get_kappa_axis(),
        kappa_omega_scan.get_omega_axis(),
    )
    angles = (
        kappa_omega_scan.get_phi_angle(),
        kappa_omega_scan.get_kappa_angle(),
        kappa_omega_scan.get_omega_angle(),
    )

    # First test a kappa goniometer with omega as the scan axis
    axes = flex.vec3_double(axes)
    angles = flex.double(angles)
    names = flex.std_string(("phi", "kappa", "omega"))
    scan_axis = 2

    multi_axis_omega_scan = GoniometerFactory.multi_axis(
        axes, angles, names, scan_axis)
    assert approx_equal(
        multi_axis_omega_scan.get_fixed_rotation(),
        kappa_omega_scan.get_fixed_rotation(),
    )
    assert approx_equal(multi_axis_omega_scan.get_rotation_axis(),
                        kappa_omega_scan.get_rotation_axis())

    recycle_omega = MultiAxisGoniometer.from_dict(
        multi_axis_omega_scan.to_dict())
    assert approx_equal(recycle_omega.get_axes(),
                        multi_axis_omega_scan.get_axes())
    assert approx_equal(recycle_omega.get_angles(),
                        multi_axis_omega_scan.get_angles())
    assert recycle_omega.get_scan_axis(
    ) == multi_axis_omega_scan.get_scan_axis()

    # Now test a kappa goniometer with phi as the scan axis
    kappa_phi_scan = KappaGoniometer(alpha, omega, kappa, phi, direction,
                                     "phi")

    scan_axis = 0
    multi_axis_phi_scan = GoniometerFactory.multi_axis(axes, angles, names,
                                                       scan_axis)
    assert approx_equal(multi_axis_phi_scan.get_fixed_rotation(),
                        kappa_phi_scan.get_fixed_rotation())
    assert approx_equal(
        matrix.sqr(multi_axis_phi_scan.get_setting_rotation()) *
        multi_axis_phi_scan.get_rotation_axis_datum(),
        kappa_phi_scan.get_rotation_axis(),
    )
    assert approx_equal(multi_axis_phi_scan.get_rotation_axis(),
                        kappa_phi_scan.get_rotation_axis())

    recycle_phi = MultiAxisGoniometer.from_dict(multi_axis_phi_scan.to_dict())
    assert approx_equal(recycle_phi.get_axes(), multi_axis_phi_scan.get_axes())
    assert approx_equal(recycle_phi.get_angles(),
                        multi_axis_phi_scan.get_angles())
    assert recycle_phi.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()

    s = easy_pickle.dumps(multi_axis_phi_scan)
    recycle = easy_pickle.loads(s)
    assert recycle == multi_axis_phi_scan

    assert approx_equal(recycle.get_axes(), multi_axis_phi_scan.get_axes())
    assert approx_equal(recycle.get_angles(), multi_axis_phi_scan.get_angles())
    assert recycle.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()
    recycle.set_angles((0, 90, 180))
    assert approx_equal(recycle.get_angles(), (0, 90, 180))
    new_axes = flex.vec3_double((
        (0.99996, -0.00647, -0.00659),
        (0.91314, 0.27949, -0.29674),
        (1.00000, -0.00013, -0.00064),
    ))
    recycle.set_axes(new_axes)
    assert approx_equal(recycle.get_axes(), new_axes)

    # Check exception is raised if scan axis is out range
    try:
        GoniometerFactory.multi_axis(axes, angles, names, 3)
    except RuntimeError:
        pass
    else:
        raise Exception_expected

    # Single axis is just a special case of a multi axis goniometer
    single_axis = GoniometerFactory.multi_axis(flex.vec3_double(((1, 0, 0), )),
                                               flex.double((0, )),
                                               flex.std_string(("PHI", )), 0)
    assert single_axis.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert single_axis.get_setting_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert single_axis.get_rotation_axis() == (1, 0, 0)