rif.legacy package

Submodules

rif.legacy.xyzMath module

Easy 3D Linear Algebra, like xyz* in rosetta

class rif.legacy.xyzMath.Mat(xx=None, xy=None, xz=None, yx=None, yy=None, yz=None, zx=None, zy=None, zz=None)[source]

docstring for Mat

>>> m = Mat(2,0,0,0,1,0,0,0,1)
>>> print(m)
Mat[ (2.000000,0.000000,0.000000), (0.000000,1.000000,0.000000), (0.000000,0.000000,1.000000) ]
>>> print(m*m)
Mat[ (4.000000,0.000000,0.000000), (0.000000,1.000000,0.000000), (0.000000,0.000000,1.000000) ]
>>> print(Mat(*list(range(1,10))) * Mat(*list(range(10,19))))
Mat[ (84.000000,90.000000,96.000000), (201.000000,216.000000,231.000000), (318.000000,342.000000,366.000000) ]
>>> assert Mat(0.0,1.0,2.0,3,4,5,6,7,8) == Mat(-0,1,2,3,4,5.0,6.0,7.0,8.0)
>>> print(Mat(100,2,3,4,5,6,7,8,9).det())
-297.0
>>> m = Mat(100,2,3,4,5,6,7,8,9)
>>> assert m * ~m == Imat
rotation_axis(R)[source]
>>> axis ,ang  = randnorm(),uniform(-pi,pi)
>>> axis2,ang2 = rotation_matrix(axis,ang).rotation_axis()
>>> assert abs( abs(ang) - abs(ang2) ) < EPS
>>> assert axis == axis2 * copysign(1,ang*ang2)
class rif.legacy.xyzMath.Vec(x=0.0, y=None, z=None)[source]

a Vector like xyzVector<Real> in rosetta

>>> v = Vec(1,2,3)
>>> print(v, 10*v)
(1.000000,2.000000,3.000000) (10.000000,20.000000,30.000000)

multiplication is a dot prod at the moment >>> v*v 14.0 >>> assert Vec(1,0,-0) == Vec(1,-0,0)

class rif.legacy.xyzMath.Xform(R=None, t=None)[source]

Coordinate frame like rosetta Xform, behaves also as a rosetta Stub

>>> x = Xform(R=Imat,t=Uz)
>>> print(x)
Xform( Mat[ (1.000000,0.000000,0.000000), (0.000000,1.000000,0.000000), (0.000000,0.000000,1.000000) ], (0.000000,0.000000,1.000000) )
>>> assert (x*x) == Xform(R=Imat,t=2*Uz)
>>> x = Xform(R=rotation_matrix_degrees(Vec(1,0,0),90.0),t=Vec(0,0,0))
>>> print(x)
Xform( Mat[ (1.000000,0.000000,0.000000), (0.000000,0.000000,-1.000000), (0.000000,1.000000,0.000000) ], (0.000000,0.000000,0.000000) )
>>> assert x*x*x*x == Ixform
>>> x.t = Ux
>>> assert x*x*x*x == Xform(R=Imat,t=4*Ux)
>>> x.t = Uz
>>> print(x)
Xform( Mat[ (1.000000,0.000000,0.000000), (0.000000,0.000000,-1.000000), (0.000000,1.000000,0.000000) ], (0.000000,0.000000,1.000000) )
>>> assert x               == Xform(R=rotation_matrix_degrees(Ux, 90.0),t=Vec(0, 0,1))
>>> assert x*x             == Xform(R=rotation_matrix_degrees(Ux,180.0),t=Vec(0,-1,1))
>>> assert x*x*x           == Xform(R=rotation_matrix_degrees(Ux,270.0),t=Vec(0,-1,0))
>>> assert x*x*x*x         == Xform(R=rotation_matrix_degrees(Ux,  0.0),t=Vec(0, 0,0))
>>> assert x*x*x*x*x       == Xform(R=rotation_matrix_degrees(Ux, 90.0),t=Vec(0, 0,1))
>>> assert x*x*x*x*x*x     == Xform(R=rotation_matrix_degrees(Ux,180.0),t=Vec(0,-1,1))
>>> assert x*x*x*x*x*x*x   == Xform(R=rotation_matrix_degrees(Ux,270.0),t=Vec(0,-1,0))
>>> assert x*x*x*x*x*x*x*x == Xform(R=rotation_matrix_degrees(Ux,  0.0),t=Vec(0, 0,0))
>>> x = Xform(rotation_matrix_degrees(Vec(1,2,3),123),Vec(5,7,9))
>>> assert ~x *  x == Ixform
>>> assert  x * ~x == Ixform

Frames / RTs are interchangable:

>>> fr = Xform(rotation_matrix_degrees(Vec(1,2,3), 65.64),t=Vec(3,2,1))
>>> to = Xform(rotation_matrix_degrees(Vec(7,5,3),105.44),t=Vec(10,9,8))
>>> x = to/fr
>>> assert to/Ixform ==  to
>>> assert Ixform/fr == ~fr
>>> assert (to * ~fr) * fr == to
>>> assert x * fr == to
>>> a1 = randnorm()
>>> b1 = randnorm()
>>> ang = uniform(0,1)*360.0-180.0
>>> a2 = rotation_matrix_degrees(a1.cross(randnorm()),ang) * a1
>>> b2 = rotation_matrix_degrees(b1.cross(randnorm()),ang) * b1
>>> assert abs(angle(a1,a2) - angle(b1,b2)) < EPS
>>> xa = Xform().from_two_vecs(a1,a2)
>>> xb = Xform().from_two_vecs(b1,b2)
>>> assert xa.tolocal(a1) == xb.tolocal(b1)
>>> assert xa.tolocal(a2) == xb.tolocal(b2)
>>> assert ~xa*a1 == ~xb*b1
>>> assert ~xa*a2 == ~xb*b2
>>> assert xb/xa*a1 == b1
>>> assert xb/xa*a2 == b2

add/sub with Vecs:

>>> X = randxform()
>>> u,v = randvec(2)
>>> assert isxform(u+X) and isxform(X+u) and isxform(u-X) and isxform(X-u)
>>> assert X*v+u == (u+X)*v
>>> assert X*(v+u) == (X+u)*v
>>> assert Xform(u)*X*v == (u+X)*v
>>> assert X*Xform(u)*v == (X+u)*v
>>> assert X*v-u == (u-X)*v
>>> assert X*(v-u) == (X-u)*v

mul,div with Mats:

>>> R = randrot()
>>> assert isxform(R*X) and isxform(X*R)
>>> assert R*X*u == (R*X)*u == R*(X*u)
>>> assert X*R*u == (X*R)*u == X*(R*u)
>>> assert Xform(R)*X*u == Xform(R)*(X*u)
>>> assert X*Xform(R)*u == X*(Xform(R,V0)*u)
>>> assert X/X*v == v

mul/div Xforms:

>>> Y = randxform()
>>> assert isxform(X/Y) and isxform(X*Y)
>>> assert X/Y*v == X*~Y*v

these don’t work yet:

>>> axis,ang,cen = randnorm(),uniform(-pi,pi),randvec()      
>>> X = rotation_around(axis,ang,cen)                        
>>> axis2,ang2,cen2 = X.rotation_center()                    
>>> assert abs( abs(ang) - abs(ang2) ) < EPS                 
>>> assert axis == axis2 * copysign(1,ang*ang2)              
>>> print(cen)                                                
>>> print(cen2)                                               
>>> x =                Xform( Mat( Vec( 0.816587, -0.306018, 0.489427 ), Vec( 0.245040, 0.951487, 0.186086 ), Vec( -0.522629, -0.032026, 0.851959 ) ), Vec( 1.689794, 1.535762, -0.964428 ) )
>>> assert repr(x) == "Xform( Mat( Vec( 0.816587, -0.306018, 0.489427 ), Vec( 0.245040, 0.951487, 0.186086 ), Vec( -0.522629, -0.032026, 0.851959 ) ), Vec( 1.689794, 1.535762, -0.964428 ) )"
rif.legacy.xyzMath.align_skew_line_pairs(aa1, ac1, aa2, ac2, ba1, bc1, ba2, bc2)[source]
>>> aa1 = Ux
>>> ac1 = V0
>>> aa2 = Uy
>>> ac2 = V0
>>> ba1 = Ux
>>> bc1 = V0
>>> ba2 = Uy
>>> bc2 = V0
>>> print(align_skew_line_pairs(aa1,ac1,aa2,ac2,ba1,bc1,ba2,bc2))
Xform( Mat[ (1.000000,-0.000000,-0.000000), (-0.000000,1.000000,0.000000), (0.000000,-0.000000,1.000000) ], (0.000000,0.000000,0.000000) )
>>> aa1 = Uy
>>> ac1 = V0
>>> aa2 = Uz
>>> ac2 = V0
>>> ba1 = Ux
>>> bc1 = Uz
>>> ba2 = Uy
>>> bc2 = Uz
>>> print(align_skew_line_pairs(aa1,ac1,aa2,ac2,ba1,bc1,ba2,bc2))
Xform( Mat[ (0.000000,1.000000,0.000000), (0.000000,0.000000,1.000000), (1.000000,0.000000,0.000000) ], (0.000000,0.000000,1.000000) )
rif.legacy.xyzMath.alignaroundaxis(axis, u, v)[source]
>>> axis = randnorm()
>>> u = randvec()
>>> ang = uniform(-pi,pi)
>>> v = rotation_matrix(axis,ang)*u
>>> uprime = alignaroundaxis(axis,u,v)*u
>>> assert v.angle(uprime) < EPS
>>> v = randvec()
>>> uprime = alignaroundaxis(axis,u,v)*u
>>> assert coplanar(V0,axis,v,uprime)
rif.legacy.xyzMath.alignvector(a, b)[source]
>>> u = randvec()
>>> v = randvec()
>>> assert v.angle(alignvector(u,v)*u) < EPS
rif.legacy.xyzMath.alignvectors(a1, a2, b1, b2)[source]

same as alignvectors_minangle

rif.legacy.xyzMath.alignvectors_minangle(a1, a2, b1, b2)[source]

exact alignment:

>>> for i in range(10):
...         angdeg = uniform(-180,180)
...         a1 = randvec()
...         b1 = randnorm()*a1.length()
...         l2 = gauss(0,1)
...         a2 = rotation_matrix_degrees(a1.cross(randnorm()),angdeg) * a1 * l2
...         b2 = rotation_matrix_degrees(b1.cross(randnorm()),angdeg) * b1 * l2
...         assert abs(angle(a1,a2) - angle(b1,b2)) < EPS
...         Xa2b = alignvectors_minangle(a1,a2,b1,b2)
...         assert Xa2b.t.length() < EPS
...         assert (Xa2b*a1).distance(b1) < EPS
...         assert (Xa2b*a2).distance(b2) < EPS

if angle(a1,a2) != angle(b1,2b), minimize deviation

>>> a1,a2,b1,b2 = randvec(4)
>>> Xa2b = alignvectors_minangle(a1,a2,b1,b2)
>>> assert coplanar(b1,b2,Xa2b*a1,Xa2b*a2)
>>> assert (b1.angle(a1)+b2.angle(a2)) > (b1.angle(Xa2b*a1)+b2.angle(Xa2b*a2))

# >>> tgt1 = -Vec(0.816497,0.000000,0.577350) # >>> tgt2 = Vec(0.000000,0.000000,1.000000) # >>> orig1 = Vec(0.000000,0.000000,1.000000) # >>> orig2 = Vec(-0.723746,0.377967,-0.577350) # >>> print orig1.angle_degrees(orig2) # >>> print tgt1.angle_degrees(tgt2) # >>> x = alignvectors_minangle(orig1,orig2,tgt1,tgt2) # >>> print tgt1,x*orig1 # >>> print tgt2,x*orig2

rif.legacy.xyzMath.coplanar(x1, x2, x3, x4)[source]
>>> u,v,w = randvec(3)
>>> a,b,c = (gauss(0,10) for i in range(3))
>>> assert     coplanar(u, v, w, u + a*(u-v) + b*(v-w) + c*(w-u) )
>>> assert not coplanar(u, v, w, u + a*(u-v) + b*(v-w) + c*(w-u) + randvec().cross(u-v) )
rif.legacy.xyzMath.dihedral(p1, p2, p3, p4)[source]
>>> dihedral_degrees(Ux,Uy,V0,Uz)
90.0
>>> dihedral_degrees(Ux,V0,Uy,Uz)
-90.0
rif.legacy.xyzMath.expand_xforms(G, N=3, c=Vec( 1.000000, 3.000000, 10.000000 ), maxrad=9000000000.0)[source]
>>> G = get_test_generators1()
>>> for x in expand_xforms(G): print(x*Ux)
(-1.000000,0.000000,0.000000)
(1.000000,0.000000,0.000000)
(1.000000,-0.000000,0.000000)
(-1.000000,0.000000,0.000000)
(1.000000,-2.000000,0.000000)
(1.000000,0.000000,0.000000)
(-1.000000,2.000000,0.000000)
(-1.000000,0.000000,0.000000)
(1.000000,-2.000000,0.000000)
(1.000000,-0.000000,-2.000000)
rif.legacy.xyzMath.find_identities(G, n=6, c=Vec( 1.000000, 3.000000, 10.000000 ))[source]
>>> G = get_test_generators1()
>>> for I in find_identities(G): print(I.t)
(0.000000,0.000000,0.000000)
(-2.000000,2.000000,2.000000)
(2.000000,-2.000000,2.000000)
rif.legacy.xyzMath.get_cell_bounds_orthogonal_only(G, n=6, c=Vec( 1.000000, 3.000000, 10.000000 ))[source]

very slow… need to speed up

>>> G = get_test_generators1()                  
>>> get_cell_bounds_orthogonal_only(G[:2],12)   
(4.0, 4.0, 4.0)
rif.legacy.xyzMath.line_line_closest_points(A1, C1, A2, C2)[source]
>>> print(line_line_closest_points(Ux,Ux,Uy,Uy))
(Vec( 0.000000, 0.000000, 0.000000 ), Vec( 0.000000, 0.000000, 0.000000 ))
>>> print(line_line_closest_points(Ux,Uy,Uy,Uz))
(Vec( 0.000000, 1.000000, 0.000000 ), Vec( 0.000000, 1.000000, 1.000000 ))
rif.legacy.xyzMath.line_line_distance(a1, c1, a2, c2)[source]
>>> line_line_distance(Ux,V0,Uy,V0)
0.0
>>> round(line_line_distance(Ux,Vec(0,1,2),Ux,Vec(3,2,1)) , 8)
1.41421356
>>> line_line_distance(Ux,10*Uy,Uz,99.0*Ux)
10.0
>>> X = randxform()
>>> round(line_line_distance(X.R*Ux,X*Vec(0,1,2),X.R*Ux,X*Vec(3,2,1)) , 8)
1.41421356
rif.legacy.xyzMath.line_plane_intersection(l, l0, n, p0)[source]
>>> l  = Ux
>>> l0 = randvec()
>>> n  = Ux
>>> p0 = V0
>>> assert line_plane_intersection(l,l0,n,p0)[1] == Vec(0,l0.y,l0.z)
>>> n = randnorm()
>>> p0 = randvec().cross(n)
>>> l = randvec()
>>> l0 = p0+l*gauss(0,10)
>>> assert line_plane_intersection(l,l0,n,p0)[1] == p0
rif.legacy.xyzMath.point_line_distance(p, a, c)[source]
>>> point_line_distance(V0,Uy,V0)
0.0
>>> round(point_line_distance(V0,Uy,Ux+Uz),8)
1.41421356
>>> round(point_line_distance(Ux,Ux,Vec(3,2,1)) , 8)
2.23606798
rif.legacy.xyzMath.proj(u, v)[source]
>>> u = Vec(1,0,0); v = Vec(1,1,1)
>>> proj(u,v)
Vec( 1.000000, 0.000000, 0.000000 )
rif.legacy.xyzMath.projperp(u, v)[source]
>>> u = Vec(1,0,0); v = Vec(1,1,1)
>>> projperp(u,v)
Vec( 0.000000, 1.000000, 1.000000 )
rif.legacy.xyzMath.randnorm(n=None)[source]
>>> assert abs(randnorm().length()-1.0) < 0.0000001
rif.legacy.xyzMath.ray_sphere_intersection(lin, l0in, cen, r)[source]
>>> v = randnorm()
>>> v = Ux
>>> assert v.distance( ray_sphere_intersection(v,V0,V0,1) ) < 0.00001
>>> assert not ray_sphere_intersection(v,V0,-2*v,1.0)
rif.legacy.xyzMath.rmsd(l, m)[source]
>>> l,m = randvec(6),randvec(6)
>>> rmsd(l,l)
0.0
rif.legacy.xyzMath.rotation_around(axs, ang, cen=None)[source]
>>> x = rotation_around(Ux,1,Uy)
>>> x * Uy
Vec( 0.000000, 1.000000, 0.000000 )
rif.legacy.xyzMath.rotation_around_dof_to_set_vec_vec_angle(dofaxis, tgt0, v1, v2)[source]
>>> from random import random
>>> for i in range(10):
...         dof = randnorm()
...         tgt = random()*180
...         v1 = randnorm()
...         v2 = randnorm()
...         ANGs = rotation_around_dof_to_set_vec_vec_angle(dof,tgt,v1,v2)
...         for a in ANGs:
...                 R = rotation_around_degrees(dof,a,Vec(0,0,0))
...                 act = line_line_angle_degrees(v1,R*v2)
...                 if 0.000001 < min(abs(act-tgt),abs(act-180+tgt)):
...                         print(a,tgt,act)
>>> print("if no other output, correct")
if no other output, correct
rif.legacy.xyzMath.rotation_matrix_degrees(axis, angle)[source]

get a rotation matrix

>>> rx180 = rotation_matrix_degrees(Vec(1,0,0),180.0)
>>> rx90  = rotation_matrix_degrees(Vec(1,0,0),90.0)
>>> print(rx90*rx90 == rx180)
True
>>> r = rotation_matrix_degrees(Vec(1,0,0),45.0)
>>> print(r)
Mat[ (1.000000,0.000000,0.000000), (0.000000,0.707107,-0.707107), (0.000000,0.707107,0.707107) ]
>>> assert r*r == rx90
>>> assert r*r*r*r == rx180
>>> assert r*r*r*r*r*r*r*r == Imat
>>> assert ~r == r.transposed()
>>> ang = uniform(0,1)*360.0-180.0
>>> v = randvec()
>>> axs = randnorm()
>>> while(abs(v.dot(axs))>0.9): axs = randnorm()
>>> u = rotation_matrix_degrees(projperp(v,axs),ang)*v
>>> assert abs(u.angle_degrees(v)-abs(ang)) < 10*SQRTEPS
rif.legacy.xyzMath.skew_lines_center(A1, C1, A2, C2)[source]
>>> skew_lines_center(Ux,V0,Uy,V0)
Vec( 0.000000, 0.000000, 0.000000 )
>>> skew_lines_center(Ux,Uy,Uy,Ux)
Vec( 1.000000, 1.000000, 0.000000 )
>>> skew_lines_center(10*Ux,10*Uy,10*Uy,10*Uz)
Vec( 0.000000, 10.000000, 5.000000 )

# >>> skew_lines_center(Ux,Uy,Uz,Ux)

rif.legacy.xyzMath.slide_to_make_lines_intersect(dof, l, l0, m, m0)[source]
>>> v = randvec()
>>> assert abs(slide_to_make_lines_intersect(Ux,Uy,v,Uz,V0) + v.x ) < EPS
>>> dof,l,l0,m,m0 = randvec(5)
>>> d = slide_to_make_lines_intersect(dof,l,l0,m,m0)
>>> l0 = l0 + d*dof
>>> assert abs(line_line_distance(l,l0,m,m0)) < EPS
rif.legacy.xyzMath.symmetrize_xform(anchor, x, nf=None)[source]

# >>> x = rotation_around_degrees(Uz,180,V0) # >>> assert symmetrize_xform(Ux,x,2) == x #>>> x = rotation_around_degrees(Vec(0,0,1),121,Vec(1,1,1)) #>>> x,c = symmetrize_xform(Ux,x,3); print x.pretty(); print c # >>> print x.pretty()

rif.legacy.xyzMath_test module

Module contents

docstring for rif.legacy