Esempio n. 1
0
 def __init__(O, type, qE):
   assert type in ["euler_params", "euler_angles_xyz"]
   if (type == "euler_params"):
     if (len(qE.elems) == 3):
       qE = euler_angles_xyz_qE_as_euler_params_qE(qE=qE)
   else:
     if (len(qE.elems) == 4):
       qE = euler_params_qE_as_euler_angles_xyz_qE(qE=qE)
   O.type = type
   O.qE = qE
   O.q_size = len(qE)
   #
   if (type == "euler_params"):
     O.unit_quaternion = qE.normalize() # RBDA, bottom of p. 86
     O.E = RBDA_Eq_4_12(q=O.unit_quaternion)
   else:
     O.E = RBDA_Eq_4_7(q=qE)
   #
   O.Tps = matrix.rt((O.E, (0,0,0)))
   O.Tsp = matrix.rt((O.E.transpose(), (0,0,0)))
   O.Xj = T_as_X(O.Tps)
   O.S = matrix.rec((
     1,0,0,
     0,1,0,
     0,0,1,
     0,0,0,
     0,0,0,
     0,0,0), n=(6,3))
Esempio n. 2
0
 def __init__(O, type, qE, qr, r_is_qr=False):
   assert type in ["euler_params", "euler_angles_xyz"]
   if (type == "euler_params"):
     if (len(qE.elems) == 3):
       qE = euler_angles_xyz_qE_as_euler_params_qE(qE=qE)
   else:
     if (len(qE.elems) == 4):
       qE = euler_params_qE_as_euler_angles_xyz_qE(qE=qE)
   O.type = type
   O.qE = qE
   O.qr = qr
   O.r_is_qr = r_is_qr
   O.q_size = len(qE) + len(qr)
   #
   if (type == "euler_params"):
     O.unit_quaternion = qE.normalize() # RBDA, bottom of p. 86
     O.E = RBDA_Eq_4_12(q=O.unit_quaternion)
   else:
     O.E = RBDA_Eq_4_7(q=qE)
   if (r_is_qr):
     O.r = qr
   else:
     O.r = O.E.transpose() * qr # RBDA Tab. 4.1
   #
   O.Tps = matrix.rt((O.E, -O.E * O.r)) # RBDA Eq. 2.28
   O.Tsp = matrix.rt((O.E.transpose(), O.r))
   O.Xj = T_as_X(O.Tps)
   O.S = None
Esempio n. 3
0
 def __init__(O, type, qE, qr, r_is_qr=False):
     assert type in ["euler_params", "euler_angles_xyz"]
     if (type == "euler_params"):
         if (len(qE.elems) == 3):
             qE = euler_angles_xyz_qE_as_euler_params_qE(qE=qE)
     else:
         if (len(qE.elems) == 4):
             qE = euler_params_qE_as_euler_angles_xyz_qE(qE=qE)
     O.type = type
     O.qE = qE
     O.qr = qr
     O.r_is_qr = r_is_qr
     O.q_size = len(qE) + len(qr)
     #
     if (type == "euler_params"):
         O.unit_quaternion = qE.normalize()  # RBDA, bottom of p. 86
         O.E = RBDA_Eq_4_12(q=O.unit_quaternion)
     else:
         O.E = RBDA_Eq_4_7(q=qE)
     if (r_is_qr):
         O.r = qr
     else:
         O.r = O.E.transpose() * qr  # RBDA Tab. 4.1
     #
     O.Tps = matrix.rt((O.E, -O.E * O.r))  # RBDA Eq. 2.28
     O.Tsp = matrix.rt((O.E.transpose(), O.r))
     O.Xj = T_as_X(O.Tps)
     O.S = None
def rt_from_string(string, default_r_identity=False, r_den=12**2, t_den=12**3):
    from cctbx import sgtbx
    from scitbx import matrix
    result = None
    s = string.strip()
    if (len(s) == 0):
        s = "a,b,c"
    try:
        cb_op = sgtbx.change_of_basis_op(symbol=s,
                                         stop_chars="",
                                         r_den=r_den,
                                         t_den=t_den)
    except ValueError as e:
        pass
    except RuntimeError as e:
        pass
    else:
        return cb_op.c_inv().as_rational()
    nums = nums_from_string(s)
    if (nums is not None):
        if (len(nums) == 12):
            if (string.find("|") < 0):
                result = matrix.rt((nums[:9], nums[9:]))
            else:
                result = matrix.rt((nums[:3] + nums[4:7] + nums[8:11],
                                    (nums[3], nums[7], nums[11])))
        elif (len(nums) == 9):
            result = matrix.rt((nums[:9], (0, 0, 0)))
        elif (len(nums) == 3):
            if (default_r_identity):
                r = (1, 0, 0, 0, 1, 0, 0, 0, 1)
            else:
                r = (0, 0, 0, 0, 0, 0, 0, 0, 0)
            result = matrix.rt((r, nums))
    return result
 def __init__(O, qE, qr):
   O.qE = qE
   O.qr = qr
   #
   O.E = RBDA_Eq_4_12(qE)
   O.r = O.E.transpose() * qr # RBDA Tab. 4.1
   #
   O.Tps = matrix.rt((O.E, -O.E * O.r)) # RBDA Eq. 2.28
   O.Tsp = matrix.rt((O.E.transpose(), O.r))
Esempio n. 6
0
 def __init__(O, qE, qr):
     O.qE = qE
     O.qr = qr
     #
     O.E = RBDA_Eq_4_12(qE)
     O.r = O.E.transpose() * qr  # RBDA Tab. 4.1
     #
     O.Tps = matrix.rt((O.E, -O.E * O.r))  # RBDA Eq. 2.28
     O.Tsp = matrix.rt((O.E.transpose(), O.r))
Esempio n. 7
0
 def __init__(O, qE):
     O.qE = qE
     O.q_size = len(qE)
     #
     c, s = math.cos(qE[0]), math.sin(qE[0])
     O.E = matrix.sqr((c, s, 0, -s, c, 0, 0, 0, 1))  # RBDA Tab. 2.2
     O.r = matrix.col((0, 0, 0))
     #
     O.Tps = matrix.rt((O.E, (0, 0, 0)))
     O.Tsp = matrix.rt((O.E.transpose(), (0, 0, 0)))
     O.Xj = T_as_X(O.Tps)
     O.S = matrix.col((0, 0, 1, 0, 0, 0))
Esempio n. 8
0
 def __init__(O, qE):
   O.qE = qE
   O.q_size = len(qE)
   #
   c, s = math.cos(qE[0]), math.sin(qE[0])
   O.E = matrix.sqr((c, s, 0, -s, c, 0, 0, 0, 1)) # RBDA Tab. 2.2
   O.r = matrix.col((0,0,0))
   #
   O.Tps = matrix.rt((O.E, (0,0,0)))
   O.Tsp = matrix.rt((O.E.transpose(), (0,0,0)))
   O.Xj = T_as_X(O.Tps)
   O.S = matrix.col((0,0,1,0,0,0))
Esempio n. 9
0
def exercise_joint_lib_six_dof_aja_simplified():
  tc = test_cases_tardy_pdb.test_cases[9]
  tt = tc.tardy_tree_construct()
  masses = [1.0]*len(tc.sites)
  # arbitrary transformation so that the center of mass is not at the origin
  rt_arbitrary = matrix.col((-0.21,-0.51,0.64)) \
    .rt_for_rotation_around_axis_through(
      point=matrix.col((-0.80, 0.28, -0.89)), angle=-37, deg=True)
  sites = [rt_arbitrary * site for site in tc.sites]
  tm = scitbx.rigid_body.essence.tardy.model(
    labels=tc.labels,
    sites=sites,
    masses=masses,
    tardy_tree=tt,
    potential_obj=None)
  assert len(tm.bodies) == 1
  assert tm.q_packed_size == 7
  mt = flex.mersenne_twister(seed=0)
  for i_trial in xrange(3):
    q = mt.random_double(size=tm.q_packed_size)*2-1
    tm.unpack_q(q_packed=q)
    sm = tm.sites_moved()
    aja = matrix.rt(scitbx.rigid_body.joint_lib_six_dof_aja_simplified(
      center_of_mass=tuple(flex.vec3_double(sites).mean()),
      q=q))
    sm2 = [aja * site for site in sites]
    assert approx_equal(sm2, sm)
Esempio n. 10
0
def exercise_joint_lib_six_dof_aja_simplified():
    tc = test_cases_tardy_pdb.test_cases[9]
    tt = tc.tardy_tree_construct()
    masses = [1.0] * len(tc.sites)
    # arbitrary transformation so that the center of mass is not at the origin
    rt_arbitrary = matrix.col((-0.21,-0.51,0.64)) \
      .rt_for_rotation_around_axis_through(
        point=matrix.col((-0.80, 0.28, -0.89)), angle=-37, deg=True)
    sites = [rt_arbitrary * site for site in tc.sites]
    tm = scitbx.rigid_body.essence.tardy.model(labels=tc.labels,
                                               sites=sites,
                                               masses=masses,
                                               tardy_tree=tt,
                                               potential_obj=None)
    assert len(tm.bodies) == 1
    assert tm.q_packed_size == 7
    mt = flex.mersenne_twister(seed=0)
    for i_trial in xrange(3):
        q = mt.random_double(size=tm.q_packed_size) * 2 - 1
        tm.unpack_q(q_packed=q)
        sm = tm.sites_moved()
        aja = matrix.rt(
            scitbx.rigid_body.joint_lib_six_dof_aja_simplified(
                center_of_mass=tuple(flex.vec3_double(sites).mean()), q=q))
        sm2 = [aja * site for site in sites]
        assert approx_equal(sm2, sm)
Esempio n. 11
0
 def compute_operators(self, sites_cart):
     for pair in self.selection_pairs:
         superposition = superpose.least_squares_fit(
             reference_sites=sites_cart.select(pair[0]),
             other_sites=sites_cart.select(pair[1]))
         rtmx = matrix.rt((superposition.r, superposition.t))
         self.matrices.append(rtmx)
         x = sites_cart.select(pair[0])
         y = rtmx * sites_cart.select(pair[1])
         d_sq = (x - y).dot()
         self.rms.append(flex.mean(d_sq)**0.5)
Esempio n. 12
0
def exercise_T_as_X(mersenne_twister):
    for i_trial in xrange(10):
        T1 = matrix.rt((mersenne_twister.random_double_r3_rotation_matrix(),
                        mersenne_twister.random_double(size=3) - 0.5))
        T2 = matrix.rt((mersenne_twister.random_double_r3_rotation_matrix(),
                        mersenne_twister.random_double(size=3) - 0.5))
        T12 = T1 * T2
        T21 = T2 * T1
        T1i = T1.inverse_assuming_orthogonal_r()
        T2i = T2.inverse_assuming_orthogonal_r()
        X1 = T_as_X(T1)
        X2 = T_as_X(T2)
        X12 = T_as_X(T12)
        X21 = T_as_X(T21)
        X1i = T_as_X(T1i)
        X2i = T_as_X(T2i)
        assert approx_equal(X1 * X2, X12)
        assert approx_equal(X2 * X1, X21)
        assert approx_equal(X1.inverse(), X1i)
        assert approx_equal(X2.inverse(), X2i)
def exercise_T_as_X(mersenne_twister):
  for i_trial in xrange(10):
    T1 = matrix.rt((
      mersenne_twister.random_double_r3_rotation_matrix(),
      mersenne_twister.random_double(size=3)-0.5))
    T2 = matrix.rt((
      mersenne_twister.random_double_r3_rotation_matrix(),
      mersenne_twister.random_double(size=3)-0.5))
    T12 = T1 * T2
    T21 = T2 * T1
    T1i = T1.inverse_assuming_orthogonal_r()
    T2i = T2.inverse_assuming_orthogonal_r()
    X1 = T_as_X(T1)
    X2 = T_as_X(T2)
    X12 = T_as_X(T12)
    X21 = T_as_X(T21)
    X1i = T_as_X(T1i)
    X2i = T_as_X(T2i)
    assert approx_equal(X1*X2, X12)
    assert approx_equal(X2*X1, X21)
    assert approx_equal(X1.inverse(), X1i)
    assert approx_equal(X2.inverse(), X2i)
Esempio n. 14
0
 def __init__(self, group, sites_cart):
     self.group = group
     self.matrices = []
     self.rms = []
     for pair in self.group.selection_pairs:
         superposition = superpose.least_squares_fit(
             reference_sites=sites_cart.select(pair[0]),
             other_sites=sites_cart.select(pair[1]))
         rtmx = matrix.rt((superposition.r, superposition.t))
         self.matrices.append(rtmx)
         x = sites_cart.select(pair[0])
         y = rtmx * sites_cart.select(pair[1])
         d_sq = (x - y).dot()
         self.rms.append(flex.mean(d_sq)**0.5)
Esempio n. 15
0
 def __init__(self, group, sites_cart):
   self.group = group
   self.matrices = []
   self.rms = []
   for pair in self.group.selection_pairs:
     superposition = superpose.least_squares_fit(
       reference_sites=sites_cart.select(pair[0]),
       other_sites=sites_cart.select(pair[1]))
     rtmx = matrix.rt((superposition.r, superposition.t))
     self.matrices.append(rtmx)
     x = sites_cart.select(pair[0])
     y = rtmx * sites_cart.select(pair[1])
     d_sq = (x-y).dot()
     self.rms.append(flex.mean(d_sq)**0.5)
Esempio n. 16
0
 def __init__(O, type, qE):
     assert type in ["euler_params", "euler_angles_xyz"]
     if (type == "euler_params"):
         if (len(qE.elems) == 3):
             qE = euler_angles_xyz_qE_as_euler_params_qE(qE=qE)
     else:
         if (len(qE.elems) == 4):
             qE = euler_params_qE_as_euler_angles_xyz_qE(qE=qE)
     O.type = type
     O.qE = qE
     O.q_size = len(qE)
     #
     if (type == "euler_params"):
         O.unit_quaternion = qE.normalize()  # RBDA, bottom of p. 86
         O.E = RBDA_Eq_4_12(q=O.unit_quaternion)
     else:
         O.E = RBDA_Eq_4_7(q=qE)
     #
     O.Tps = matrix.rt((O.E, (0, 0, 0)))
     O.Tsp = matrix.rt((O.E.transpose(), (0, 0, 0)))
     O.Xj = T_as_X(O.Tps)
     O.S = matrix.rec(
         (1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0), n=(6, 3))
Esempio n. 17
0
 def get(i, delta):
   fs = []
   for signed_delta in [delta, -delta]:
     q_delta[i] = q[i] + signed_delta
     aja = matrix.rt(scitbx.rigid_body.joint_lib_six_dof_aja_simplified(
       center_of_mass=center_of_mass,
       q=q_delta))
     sites_cart_delta = aja * sites_cart_0
     rs_f = maptbx.real_space_target_simple(
       unit_cell=unit_cell,
       density_map=density_map,
       sites_cart=sites_cart_delta,
       selection=flex.bool(sites_cart_delta.size(),True))
     fs.append(rs_f)
   result.append((fs[0]-fs[1])/(2*delta))
Esempio n. 18
0
 def get(i, delta):
   fs = []
   for signed_delta in [delta, -delta]:
     q_delta[i] = q[i] + signed_delta
     aja = matrix.rt(scitbx.rigid_body.joint_lib_six_dof_aja_simplified(
       center_of_mass=center_of_mass,
       q=q_delta))
     sites_cart_delta = aja * sites_cart_0
     rs_f = maptbx.real_space_target_simple(
       unit_cell=unit_cell,
       density_map=density_map,
       sites_cart=sites_cart_delta,
       selection=flex.bool(sites_cart_delta.size(),True))
     fs.append(rs_f)
   result.append((fs[0]-fs[1])/(2*delta))
Esempio n. 19
0
 def rotate_about_2ptaxis(self, pdb_hier, coor1, coor2, rot):
     # function that rotates a set of coordinates around an arbitrary
     # axis defined by two points by a rotation in degrees
     #coor1 is the center of rotation origin (input as 3tuple)
     #coor2 gives the vector which forms the rotation axis
     #a new copy of coords are returned as hierarchy
     new_hier = pdb_hier.deep_copy()
     x1, y1, z1 = coor1
     x2, y2, z2 = coor2
     rad = 2 * np.pi * rot / 360.0
     (u, v, w) = (x2 - x1, y2 - y1, z2 - z1)
     L = u**2 + v**2 + w**2
     rt = matrix.rt(
         ([(u**2 + (v**2 + w**2) * math.cos(rad)) / L,
           (u * v *
            (1 - math.cos(rad)) - w * math.sqrt(L) * math.sin(rad)) / L,
           (u * w *
            (1 - math.cos(rad)) + v * math.sqrt(L) * math.sin(rad)) / L,
           (u * v *
            (1 - math.cos(rad)) + w * math.sqrt(L) * math.sin(rad)) / L,
           (v**2 + (u**2 + w**2) * math.cos(rad)) / L,
           (v * w *
            (1 - math.cos(rad)) - u * math.sqrt(L) * math.sin(rad)) / L,
           (u * w *
            (1 - math.cos(rad)) - v * math.sqrt(L) * math.sin(rad)) / L,
           (v * w *
            (1 - math.cos(rad)) + u * math.sqrt(L) * math.sin(rad)) / L,
           (w**2 + (u**2 + v**2) * math.cos(rad)) / L], [
               ((x1 * (v**2 + w**2) - u *
                 (y1 * v + z1 * w)) * (1 - math.cos(rad)) +
                (y1 * w - z1 * v) * math.sqrt(L) * math.sin(rad)) / L,
               ((y1 * (u**2 + w**2) - v *
                 (x1 * u + z1 * w)) * (1 - math.cos(rad)) +
                (z1 * u - x1 * w) * math.sqrt(L) * math.sin(rad)) / L,
               ((z1 * (u**2 + v**2) - w *
                 (x1 * u + y1 * v)) * (1 - math.cos(rad)) +
                (x1 * v - y1 * u) * math.sqrt(L) * math.sin(rad)) / L,
           ]))
     atoms = new_hier.atoms()
     sites = atoms.extract_xyz()
     atoms.set_xyz(rt.r.elems * sites + rt.t.elems)
     return new_hier
Esempio n. 20
0
def axis_rt(axis, setting=None):
    if axis.type == b"rotation":
        if setting:
            a = setting.angle_start_range_incr[0]
        else:
            a = 0.0
        v = matrix.col(axis.vector)
        r = v.axis_and_angle_as_r3_rotation_matrix(a, deg=True)
        t = matrix.col(axis.offset)
    elif axis.type == b"translation":
        if setting:
            t = setting.displacement_start_range_incr[0]
        else:
            t = 0.0
        v = matrix.col(axis.vector)
        r = matrix.sqr((1, 0, 0, 0, 1, 0, 0, 0, 1))
        o = matrix.col(axis.offset)
        t = v * t + o

    rt = matrix.rt((r, t))
    return rt
Esempio n. 21
0
def run():
    osType = sys.platform
    if osType.startswith('win'):
        directory_path = 'c:\Phenix\Dev\Work\work'
    else:
        directory_path = '/net/cci-filer2/raid1/home/youval/Work/work'
    print os.getcwd()
    os.chdir(directory_path)
    f = open('mtrix_not_included_in_pdb.txt','w')
    good_MTRIX_pdb_files = pickle.load(open('dict_good_MTRIX_pdb_files','r'))
    MTRIX_with_Straucture_Factor = pickle.load(open('MTRIX_with_Straucture_Factor_file_list','r'))
    results = []
    n = len(MTRIX_with_Straucture_Factor)
    for file_name in MTRIX_with_Straucture_Factor:
        pdb_inp = pdb.input(file_name=good_MTRIX_pdb_files[file_name])          # read the pdb file data
        TRASFORM_info = pdb_inp.process_mtrix_records(error_handle=False,eps=1e-2)
        TRASFORM_info = [matrix.rt(x.values) for x in TRASFORM_info if not x.coordinates_present]
        if TRASFORM_info != []:
            f.write(file_name + '\n')
            print '*'*60
            results.append(file_name)
    f.close()
    print 'files with MTRIX records that are not already include in pdb file: {}'.format(len(results))
    print 'Total files with mtrix records: {}'.format(n)
Esempio n. 22
0
 def __init__(O, sites):
   O.pivot = center_of_mass_from_sites(sites=sites)
   O.normal = None
   O.T0b = matrix.rt(((1,0,0,0,1,0,0,0,1), -O.pivot))
   O.Tb0 = matrix.rt(((1,0,0,0,1,0,0,0,1), O.pivot))
  def rt(self):

    return matrix.rt( ( self.r, self.t ) )
def sgtbx_rt_mx_as_matrix_rt(s):
    return matrix.rt((s.r().as_double(), s.t().as_double()))
 def setT(O):
   O.Tps = matrix.rt((O.E, (0,0,0)))
   O.Tsp = matrix.rt((O.E.transpose(), (0,0,0)))
Esempio n. 26
0
def run(server_info, inp, status):
    print "<pre>"
    from scitbx import matrix
    p = p_from_string(string=inp.cb_expr)
    assert inp.p_or_q in ["P", "Q"]
    if (inp.p_or_q == "Q"):
        p = p.inverse()
    assert inp.p_transpose in ["off", "on"]
    if (inp.p_transpose == "on"):
        p = matrix.rt((p.r.transpose(), p.t))
    print "P:"
    display_rt(p)
    print
    q = p.inverse()
    print "Q:"
    display_rt(q)
    print
    if (len(inp.obj_expr.strip()) != 0):
        if (inp.obj_type in ["xyz", "hkl"]):
            triple = xyz_from_string(string=inp.obj_expr)
            if (inp.obj_type == "xyz"):
                print "Transformation law: (Q,q) xyz"
                print
                print "  xyz:", triple
                print
                print "  xyz':", (q.r * matrix.col(triple) + q.t).elems
                print
            else:
                print "Transformation law: hkl P"
                print
                print "  hkl:", triple
                print
                print "  hkl':", (matrix.row(triple) * p.r).elems
                print
        elif (inp.obj_type == "unit_cell"):
            from cctbx import uctbx
            uc = uctbx.unit_cell(inp.obj_expr)
            print "Transformation law: Pt G P"
            print
            print "unit cell:", uc
            print
            g = matrix.sym(sym_mat3=uc.metrical_matrix())
            print "metrical matrix:"
            display_r(g)
            print
            gp = p.r.transpose() * g * p.r
            print "metrical matrix':"
            display_r(gp)
            print
            ucp = uctbx.unit_cell(metrical_matrix=gp.as_sym_mat3())
            print "unit cell':", ucp
            print
        elif (inp.obj_type == "Ww"):
            w = w_from_string(string=inp.obj_expr)
            print "Transformation law: (Q,q) (W,w) (P,p)"
            print
            print "(W, w):"
            display_rt(w)
            print
            wp = q * w * p
            print "(W, w)':"
            display_rt(wp)
            print
        else:
            raise RuntimeError("Unknown obj_type: %s" % inp.obj_type)
    print "</pre>"
Esempio n. 27
0
 def as_rational(self):
   return matrix.rt((self.r().as_rational(), self.t().as_rational()))
Esempio n. 28
0
  if (len(s) == 0):
    s = "a,b,c"
  try:
    cb_op = sgtbx.change_of_basis_op(
      symbol=s, stop_chars="", r_den=r_den, t_den=t_den)
  except ValueError, e:
    pass
  except RuntimeError, e :
    pass
  else:
    return cb_op.c_inv().as_rational()
  nums = nums_from_string(s)
  if (nums is not None):
    if (len(nums) == 12):
      if (string.find("|") < 0):
        result = matrix.rt((nums[:9], nums[9:]))
      else:
        result = matrix.rt(
          (nums[:3]+nums[4:7]+nums[8:11],
          (nums[3], nums[7], nums[11])))
    elif (len(nums) == 9):
      result = matrix.rt((nums[:9], (0,0,0)))
    elif (len(nums) == 3):
      if (default_r_identity):
        r = (1,0,0,0,1,0,0,0,1)
      else:
        r = (0,0,0,0,0,0,0,0,0)
      result = matrix.rt((r, nums))
  return result

def raise_uninterpretable(what, expression):
Esempio n. 29
0
def run(server_info, inp, status):
  print "<pre>"
  from scitbx import matrix
  p = p_from_string(string=inp.cb_expr)
  assert inp.p_or_q in ["P", "Q"]
  if (inp.p_or_q == "Q"):
    p = p.inverse()
  assert inp.p_transpose in ["off", "on"]
  if (inp.p_transpose == "on"):
    p = matrix.rt((p.r.transpose(), p.t))
  print "P:"
  display_rt(p)
  print
  q = p.inverse()
  print "Q:"
  display_rt(q)
  print
  if (len(inp.obj_expr.strip()) != 0):
    if (inp.obj_type in ["xyz", "hkl"]):
      triple = xyz_from_string(string=inp.obj_expr)
      if (inp.obj_type == "xyz"):
        print "Transformation law: (Q,q) xyz"
        print
        print "  xyz:", triple
        print
        print "  xyz':", (
          q.r * matrix.col(triple) + q.t).elems
        print
      else:
        print "Transformation law: hkl P"
        print
        print "  hkl:", triple
        print
        print "  hkl':", (matrix.row(triple) * p.r).elems
        print
    elif (inp.obj_type == "unit_cell"):
      from cctbx import uctbx
      uc = uctbx.unit_cell(inp.obj_expr)
      print "Transformation law: Pt G P"
      print
      print "unit cell:", uc
      print
      g = matrix.sym(sym_mat3=uc.metrical_matrix())
      print "metrical matrix:"
      display_r(g)
      print
      gp = p.r.transpose() * g * p.r
      print "metrical matrix':"
      display_r(gp)
      print
      ucp = uctbx.unit_cell(metrical_matrix=gp.as_sym_mat3())
      print "unit cell':", ucp
      print
    elif (inp.obj_type == "Ww"):
      w = w_from_string(string=inp.obj_expr)
      print "Transformation law: (Q,q) (W,w) (P,p)"
      print
      print "(W, w):"
      display_rt(w)
      print
      wp = q * w * p
      print "(W, w)':"
      display_rt(wp)
      print
    else:
      raise RuntimeError("Unknown obj_type: %s" % inp.obj_type)
  print "</pre>"
Esempio n. 30
0
    try:
        cb_op = sgtbx.change_of_basis_op(symbol=s,
                                         stop_chars="",
                                         r_den=r_den,
                                         t_den=t_den)
    except ValueError, e:
        pass
    except RuntimeError, e:
        pass
    else:
        return cb_op.c_inv().as_rational()
    nums = nums_from_string(s)
    if (nums is not None):
        if (len(nums) == 12):
            if (string.find("|") < 0):
                result = matrix.rt((nums[:9], nums[9:]))
            else:
                result = matrix.rt((nums[:3] + nums[4:7] + nums[8:11],
                                    (nums[3], nums[7], nums[11])))
        elif (len(nums) == 9):
            result = matrix.rt((nums[:9], (0, 0, 0)))
        elif (len(nums) == 3):
            if (default_r_identity):
                r = (1, 0, 0, 0, 1, 0, 0, 0, 1)
            else:
                r = (0, 0, 0, 0, 0, 0, 0, 0, 0)
            result = matrix.rt((r, nums))
    return result


def raise_uninterpretable(what, expression):
Esempio n. 31
0
 def GetMatrix (self) :
   from scitbx import matrix
   r = [ c.GetPhilValue() for c in self._r_ctrls ]
   t = [ c.GetPhilValue() for c in self._t_ctrls ]
   return matrix.rt((r,t))
 def setT(O):
     O.Tps = matrix.rt((O.E, (0, 0, 0)))
     O.Tsp = matrix.rt((O.E.transpose(), (0, 0, 0)))
Esempio n. 33
0
 def __init__(O, sites):
     O.pivot = center_of_mass_from_sites(sites=sites)
     O.normal = None
     O.T0b = matrix.rt(((1, 0, 0, 0, 1, 0, 0, 0, 1), -O.pivot))
     O.Tb0 = matrix.rt(((1, 0, 0, 0, 1, 0, 0, 0, 1), O.pivot))
Esempio n. 34
0
 def rt(self):
   return matrix.rt(tuple_r_t=(self.r, self.t))
Esempio n. 35
0
 def __init__(O, pivot, normal):
   O.pivot = pivot
   O.normal = normal
   r = normal.vector_to_001_rotation()
   O.T0b = matrix.rt((r, -r * pivot))
   O.Tb0 = matrix.rt((r.transpose(), pivot))
def sgtbx_rt_mx_as_matrix_rt(s):
  return matrix.rt((s.r().as_double(), s.t().as_double()))
Esempio n. 37
0
 def __init__(O, pivot, normal):
     O.pivot = pivot
     O.normal = normal
     r = normal.vector_to_001_rotation()
     O.T0b = matrix.rt((r, -r * pivot))
     O.Tb0 = matrix.rt((r.transpose(), pivot))
Esempio n. 38
0
 def as_rational(self):
     return matrix.rt((self.r().as_rational(), self.t().as_rational()))
Esempio n. 39
0
 def GetMatrix(self):
     from scitbx import matrix
     r = [c.GetPhilValue() for c in self._r_ctrls]
     t = [c.GetPhilValue() for c in self._t_ctrls]
     return matrix.rt((r, t))