From: Buz Barstow <buzb@ma...>  20080129 14:56:39

Hi Jason, Thanks a lot for this! I was able to code up a very simple solution to my problem using Tsjerk's suggestion. In my problem I have a series of very similar structures, and I wanted to calculate the principal axes of a section of these structures and then align the principal axes of another section of the structure with those principal axes: while i < len(eigVectors0001_1): # the m matrix is a matrix of the principal axes of segment 1 of structure 1 m = array([eigVectors0001_1[1], eigVectors0001_2[1], eigVectors0001_3[1]]) m = transpose(m) # The n matrix is a matrix of the principal axes of segment of structure i n = array([eigVectors0001_1[i], eigVectors0001_2[i], eigVectors0001_3[i]]) n = transpose(n) # r is the rotation matrix to rotate the n axes onto the m axes r = dot(m,inverse(n)) # p is a matrix of the principal axes of segment 2 in structure i p = array([eigVectors0002_1[i], eigVectors0002_2[i], eigVectors0002_3[i]]) p = transpose(p) # q are the rotated principal axes of segment 2 in structure i q = dot(r,p) i+=1 Thanks again! and all the best, Buz On Jan 29, 2008, at 8:31 AM, Jason Vertrees wrote: > Buz, > > Tsjerk's answer is right on. This has already been implemented for > PyMOL as a > plugin. See Kabsch/optAlign from "cealign," here: > http://www.pymolwiki.org/index.php/Kabsch > The code is opensource and so can be applied elsewhere. > > Another simple method is to simply calculate the SVD of the > correlation > matrix. Then multiply the right and left singular vectors by each > other  > that will yield the DxD rotation matrix (where D is the dimension of > your > vector sets). (This is how Kabsch/optAlign works.) > >  Jason > > On Monday 28 January 2008 10:48:29 pm > pymolusersrequest@... wrote: >>  >> >> Message: 3 >> Date: Sat, 26 Jan 2008 10:04:06 +0100 >> From: "Tsjerk Wassenaar" <tsjerkw@...> >> Subject: Re: [PyMOL] Algorithm to Rotate One Set of Vectors onto >> Another >> To: "Buz Barstow" <buzb@...> >> Cc: pymolusers@... >> MessageID: >> <8ff898150801260104k4902e5f0tcb94e8ebbbf1e027@...> >> ContentType: text/plain; charset=ISO88591 >> >> Hi Buz, >> >> To my opinion, this is not the best place for your question. Pymol is >> a molecular viewer... >> But the question itself is basically trivial from the linear algebra >> point of view. >> >> If X is your source set of orthogonal vectors and Y is the target, >> then you should have some sort of matrix R to satisfy >> >> Y = RX >> >> But, since it should only be a rotation, you'll first have to >> transform X and Y to their orthonormal counterparts N and M: >> >> M = RN >> >> Then >> >> MN^1=RNN^1 >> >> such that >> >> R = MN^1 >> >> If both sets are of equal dimensions (and full rank), there's an >> exact >> solution. Otherwise, there's a bit more trouble... >> >> So, taking your favourite language with the proper linear algebra >> package, it comes down to: >> >> normalize X > N >> normalize Y > M >> invert N >> multiply M with the inverse of N >> >> By the way, you're probably dealing with 3x3 matrices here (molecules >> in cartesian space), in which case the routines are simple enough to >> write down yourself (I believe these were even in the array.py I >> posted like two days ago). >> >> Hope it helps, >> >> Tsjerk >> >> On Jan 25, 2008 10:55 PM, Buz Barstow <buzb@...> wrote: >>> Dear All, >>> >>> I'm looking for an algorithm that will allow me to derive a >>> transformation matrix that superimposes one set of orthogonal >>> vectors >>> onto another set of orthogonal vectors, that I can then use to >>> transform another set of orthogonal vectors. >>> >>> Thanks! and all the best, >>> >>> Buz > > > >  > > Jason Vertrees (javertre@...) > Doctoral Candidate > Biophysical, Structural & Computational Biology Program > University of Texas Medical Branch > Galveston, Texas > > http://www.best.utmb.edu/ > http://www.pymolwiki.org/ > >  > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > PyMOLusers mailing list > PyMOLusers@... > https://lists.sourceforge.net/lists/listinfo/pymolusers 