Hello all, I have a rotation + translation matrix. Let's say py> mtx array([[ 0.88302225, 0.11697778, 0.45451948, 5. ], [ 0.11697778, 0.88302225, -0.45451948, 10. ], [ -0.45451948, 0.45451948, 0.76604444, 20. ], [ 0. , 0. , 0. , 1. ]]) My usual way of transforming a set of coordinates with a 4x4 matrix is to use numpy: py> xyz_1 array([[ 5., 10., 15., 1.], [ 20., 15., 10., 1.]]) py> numpy.inner(xyz_1, mtx) array([[ 17.40268126, 12.59731919, 33.76326397, 1. ], [ 28.9603065 , 21.03969455, 25.38784698, 1. ]]) What is the equivalent in cctbx? Is there a way to avoid converting coordinates back and fourth between numpy arrays with atoms().extract_xyz() & .set_xyz() (as might be used from a iotbx_pdb_hierarchy_ext.root). Thank you for any help. James
Hi James, a hint: look how rotate/translate is implemented in : in cctbx_project/mmtbx/pdbtools.py look for def _rb_shift(..) and then follow the code. This is just an example of a possible way of doing it. I guess there are many more. Pavel On 3/26/13 10:29 AM, James Stroud wrote:
Hello all,
I have a rotation + translation matrix. Let's say
py> mtx array([[ 0.88302225, 0.11697778, 0.45451948, 5. ], [ 0.11697778, 0.88302225, -0.45451948, 10. ], [ -0.45451948, 0.45451948, 0.76604444, 20. ], [ 0. , 0. , 0. , 1. ]])
My usual way of transforming a set of coordinates with a 4x4 matrix is to use numpy:
py> xyz_1 array([[ 5., 10., 15., 1.], [ 20., 15., 10., 1.]])
py> numpy.inner(xyz_1, mtx) array([[ 17.40268126, 12.59731919, 33.76326397, 1. ], [ 28.9603065 , 21.03969455, 25.38784698, 1. ]])
What is the equivalent in cctbx? Is there a way to avoid converting coordinates back and fourth between numpy arrays with atoms().extract_xyz() & .set_xyz() (as might be used from a iotbx_pdb_hierarchy_ext.root).
Thank you for any help.
James
_______________________________________________ cctbxbb mailing list [email protected] http://phenix-online.org/mailman/listinfo/cctbxbb
On Tue, Mar 26, 2013 at 10:42 AM, Pavel Afonine
a hint: look how rotate/translate is implemented in : ... This is just an example of a possible way of doing it. I guess there are many more.
A more general method (not dependent on xray.structure): from scitbx import matrix rt = matrix.rt(([0.88302225, 0.11697778, 0.45451948, 0.11697778, 0.88302225, -0.45451948, -0.45451948, 0.45451948, 0.76604444], [5,10,20])) sites = atoms.extract_xyz() atoms.set_xyz(rt.r.elems * sites + rt.t.elems) Internally these are simply tuples - so if you multiply a flex.vec3_double array with a 9-element tuple, it is assumed to be a 3x3 rotation matrix, and adding a 3-element tuple to the array is assumed to be a translation. But since these operations are frequently coupled we usually package the two matrices together. -Nat
participants (3)
-
James Stroud
-
Nathaniel Echols
-
Pavel Afonine