[Chimera-users] Feature Request: Expose rotation to python

Greg Couch gregc at cgl.ucsf.edu
Mon Nov 28 17:18:18 PST 2005


On Mon, 28 Nov 2005, Charlie Moad wrote:

>     The repr of an xform shows the opengl rotation matrix.  I want to
> get this efficiently in python, but I don't believe it is exposed.
> Could a getter please be added returning a 4x4 tuple, so a Numeric
> array can be trivial/efficiently made from it?  If there is a current
> approach please let me know.

The new and improved method is to use the getCoordFrame method :-) and
the coorresponding Xform.coordFrame constructor.  I agree that it would be 
better for Python to have a method that returned a Numeric array.

Example:

 	>>> xf = chimera.Xform.zRotation(30)
 	>>> x, y, z, o = xf.getCoordFrame()
 	>>> print "x: %s, y: %s, z: %s, o: %s" % (x, y, z, o)
 	x: 0.866025 0.5 0, y: -0.5 0.866025 0, z: 0 0 1, o: 0 0 0

Using getCoordFrame would simplify PDBmatrices.matrices.xform_matrix to 
be:

 	rx, ry, rz, t = xform.getCoordFrame()
 	return ((rx[0], ry[0], rz[0], t[0]),
         	(rx[1], ry[1], rz[1], t[1]),
         	(rx[2], ry[2], rz[2], t[2]))

You could do something similar to construct a Numeric array.

Xforms have improved in the latest release.  Now you can easily make 
copies of matrices using the constructor:

 	xformprime = chimera.Xform(xform)

or:

 	import copy
 	xformprime = copy.copy(xform)

Type:

 	help(chimera.Xform)

to see all of the methods and static methods.

 	Hope this helps,

 	Greg Couch
 	UCSF Computer Graphics Lab
 	gregc at cgl.ucsf.edu




More information about the Chimera-users mailing list