Exemplo n.º 1
0
def exercise_vector_to_vector(angle_exponent_step=10, n_trials=10):
    principal_vectors = [
        matrix.col(v) for v in ((1, 0, 0), (0, 1, 0), (0, 0, 1))
    ]
    for g0 in principal_vectors:
        for t0 in principal_vectors:
            for g in [g0, -g0]:
                for t in [t0, -t0]:
                    check_vector_to_vector(g=g, t=t)
    if (sys.platform.startswith("osf")):
        max_exp = 300
    else:
        max_exp = 340
    for ig, g0 in enumerate(principal_vectors):
        for it, t0 in enumerate(principal_vectors):
            if (ig == it): continue
            axis = g0.cross(t0)
            for e in range(0, max_exp, angle_exponent_step):
                angle = 10**(-e)
                for angle in [angle, -angle]:
                    r = matrix.sqr(
                        scitbx.math.r3_rotation_axis_and_angle_as_matrix(
                            axis=axis, angle=angle))
                    for g in [g0, -g0]:
                        for t in [t0, -t0]:
                            check_vector_to_vector(g, r * t)
                            check_vector_to_vector(r * g, t)
                            check_vector_to_vector(r * g, r * t)
    for i_trial in range(n_trials):
        g = matrix.col(flex.random_double_point_on_sphere())
        check_vector_to_vector(g, g)
        check_vector_to_vector(g, -g)
        t = matrix.col(flex.random_double_point_on_sphere())
        check_vector_to_vector(g, t)
        for e in range(0, max_exp, angle_exponent_step):
            angle = 10**(-e)
            for angle in [angle, -angle]:
                rt = matrix.sqr(
                    scitbx.math.r3_rotation_axis_and_angle_as_matrix(
                        axis=g, angle=angle)) * t
                check_vector_to_vector(rt, t)
                check_vector_to_vector(rt, -t)
    #
    check_vector_to_001((0, 0, 1))
    check_vector_to_001((0, 0, -1))
    for e in range(0, max_exp, angle_exponent_step):
        angle = 10**(-e)
        for angle in [angle, -angle]:
            rg = matrix.sqr(
                scitbx.math.r3_rotation_axis_and_angle_as_matrix(
                    axis=(1, 1, 0), angle=angle)) * matrix.col((0, 0, 1))
            check_vector_to_001(rg)
            check_vector_to_001(-rg)
    for i_trial in range(n_trials):
        g = matrix.col(flex.random_double_point_on_sphere())
        check_vector_to_001(g)
    #
    check_vector_to_010((0, 1, 0))
    check_vector_to_010((0, -1, 0))
    for e in range(0, max_exp, angle_exponent_step):
        angle = 10**(-e)
        for angle in [angle, -angle]:
            rg = matrix.sqr(
                scitbx.math.r3_rotation_axis_and_angle_as_matrix(
                    axis=(1, 0, 1), angle=angle)) * matrix.col((0, 1, 0))
            check_vector_to_010(rg)
            check_vector_to_010(-rg)
    for i_trial in range(n_trials):
        g = matrix.col(flex.random_double_point_on_sphere())
        check_vector_to_010(g)
    #
    check_vector_to_100((1, 0, 0))
    check_vector_to_100((-1, 0, 0))
    for e in range(0, max_exp, angle_exponent_step):
        angle = 10**(-e)
        for angle in [angle, -angle]:
            rg = matrix.sqr(
                scitbx.math.r3_rotation_axis_and_angle_as_matrix(
                    axis=(0, 1, 1), angle=angle)) * matrix.col((1, 0, 0))
            check_vector_to_100(rg)
            check_vector_to_100(-rg)
    for i_trial in range(n_trials):
        g = matrix.col(flex.random_double_point_on_sphere())
        check_vector_to_100(g)
    #
    rvv = vector_to_vector((0, 0, -1), (0, 0, 1))
    rv1 = vector_to_001((0, 0, -1))
    assert approx_equal(rv1, rvv)
    rvv = vector_to_vector((0, -1, 0), (0, 1, 0))
    rv1 = vector_to_010((0, -1, 0))
    assert approx_equal(rv1, rvv)
    rvv = vector_to_vector((-1, 0, 0), (1, 0, 0))
    rv1 = vector_to_100((-1, 0, 0))
    assert approx_equal(rv1, rvv)
Exemplo n.º 2
0
def exercise_vector_to_vector(angle_exponent_step=10, n_trials=10):
  principal_vectors = [matrix.col(v) for v in (1,0,0), (0,1,0), (0,0,1)]
  for g0 in principal_vectors:
    for t0 in principal_vectors:
      for g in [g0, -g0]:
        for t in [t0, -t0]:
          check_vector_to_vector(g=g, t=t)
  if (sys.platform.startswith("osf")):
    max_exp = 300
  else:
    max_exp = 340
  for ig,g0 in enumerate(principal_vectors):
    for it,t0 in enumerate(principal_vectors):
      if (ig == it): continue
      axis = g0.cross(t0)
      for e in xrange(0, max_exp, angle_exponent_step):
        angle = 10**(-e)
        for angle in [angle, -angle]:
          r = matrix.sqr(scitbx.math.r3_rotation_axis_and_angle_as_matrix(
            axis=axis,
            angle=angle))
          for g in [g0, -g0]:
            for t in [t0, -t0]:
              check_vector_to_vector(g, r*t)
              check_vector_to_vector(r*g, t)
              check_vector_to_vector(r*g, r*t)
  for i_trial in xrange(n_trials):
    g = matrix.col(flex.random_double_point_on_sphere())
    check_vector_to_vector(g, g)
    check_vector_to_vector(g, -g)
    t = matrix.col(flex.random_double_point_on_sphere())
    check_vector_to_vector(g, t)
    for e in xrange(0, max_exp, angle_exponent_step):
      angle = 10**(-e)
      for angle in [angle, -angle]:
        rt = matrix.sqr(scitbx.math.r3_rotation_axis_and_angle_as_matrix(
          axis=g,
          angle=angle)) * t
        check_vector_to_vector(rt, t)
        check_vector_to_vector(rt, -t)
  #
  check_vector_to_001((0,0,1))
  check_vector_to_001((0,0,-1))
  for e in xrange(0, max_exp, angle_exponent_step):
    angle = 10**(-e)
    for angle in [angle, -angle]:
      rg = matrix.sqr(scitbx.math.r3_rotation_axis_and_angle_as_matrix(
        axis=(1,1,0),
        angle=angle)) * matrix.col((0,0,1))
      check_vector_to_001(rg)
      check_vector_to_001(-rg)
  for i_trial in xrange(n_trials):
    g = matrix.col(flex.random_double_point_on_sphere())
    check_vector_to_001(g)
  #
  check_vector_to_010((0,1,0))
  check_vector_to_010((0,-1,0))
  for e in xrange(0, max_exp, angle_exponent_step):
    angle = 10**(-e)
    for angle in [angle, -angle]:
      rg = matrix.sqr(scitbx.math.r3_rotation_axis_and_angle_as_matrix(
        axis=(1,0,1),
        angle=angle)) * matrix.col((0,1,0))
      check_vector_to_010(rg)
      check_vector_to_010(-rg)
  for i_trial in xrange(n_trials):
    g = matrix.col(flex.random_double_point_on_sphere())
    check_vector_to_010(g)
  #
  check_vector_to_100((1,0,0))
  check_vector_to_100((-1,0,0))
  for e in xrange(0, max_exp, angle_exponent_step):
    angle = 10**(-e)
    for angle in [angle, -angle]:
      rg = matrix.sqr(scitbx.math.r3_rotation_axis_and_angle_as_matrix(
        axis=(0,1,1),
        angle=angle)) * matrix.col((1,0,0))
      check_vector_to_100(rg)
      check_vector_to_100(-rg)
  for i_trial in xrange(n_trials):
    g = matrix.col(flex.random_double_point_on_sphere())
    check_vector_to_100(g)
  #
  rvv = vector_to_vector((0,0,-1), (0,0,1))
  rv1 = vector_to_001((0,0,-1))
  assert approx_equal(rv1, rvv)
  rvv = vector_to_vector((0,-1,0), (0,1,0))
  rv1 = vector_to_010((0,-1,0))
  assert approx_equal(rv1, rvv)
  rvv = vector_to_vector((-1,0,0), (1,0,0))
  rv1 = vector_to_100((-1,0,0))
  assert approx_equal(rv1, rvv)
Exemplo n.º 3
0
def check_vector_to_010(g):
    assert approx_equal(abs(matrix.col(g)), 1)
    r = matrix.sqr(vector_to_010(given_unit_vector=g))
    assert approx_equal(r * matrix.col(g), (0, 1, 0))
    assert approx_equal(r.determinant(), 1)
Exemplo n.º 4
0
def check_vector_to_010(g):
  assert approx_equal(abs(matrix.col(g)), 1)
  r = matrix.sqr(vector_to_010(given_unit_vector=g))
  assert approx_equal(r * matrix.col(g), (0,1,0))
  assert approx_equal(r.determinant(), 1)