## Re: [PyMOL] Algorithm to Rotate One Set of Vectors onto Another

 Re: [PyMOL] Algorithm to Rotate One Set of Vectors onto Another From: Buz Barstow - 2008-01-29 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 open-source 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 > pymol-users-request@... wrote: >> ------------------------------ >> >> Message: 3 >> Date: Sat, 26 Jan 2008 10:04:06 +0100 >> From: "Tsjerk Wassenaar" >> Subject: Re: [PyMOL] Algorithm to Rotate One Set of Vectors onto >> Another >> To: "Buz Barstow" >> Cc: pymol-users@... >> Message-ID: >> <8ff898150801260104k4902e5f0tcb94e8ebbbf1e027@...> >> Content-Type: text/plain; charset=ISO-8859-1 >> >> 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 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/ > _______________________________________________ > PyMOL-users mailing list > PyMOL-users@... > https://lists.sourceforge.net/lists/listinfo/pymol-users ```

 Re: [PyMOL] Algorithm to Rotate One Set of Vectors onto Another From: Jason Vertrees - 2008-01-29 13:30:49 ```Buz, Tsjerk's answer is right on. This has already been implemented for PyMOL a= s a=20 plugin. See Kabsch/optAlign from "cealign," here: =20 http://www.pymolwiki.org/index.php/Kabsch The code is open-source and so can be applied elsewhere. Another simple method is to simply calculate the SVD of the correlation=20 matrix. Then multiply the right and left singular vectors by each other --= =20 that will yield the DxD rotation matrix (where D is the dimension of your=20 vector sets). (This is how Kabsch/optAlign works.) =2D- Jason On Monday 28 January 2008 10:48:29 pm=20 pymol-users-request@... wrote: > ------------------------------ > > Message: 3 > Date: Sat, 26 Jan 2008 10:04:06 +0100 > From: "Tsjerk Wassenaar" > Subject: Re: [PyMOL] Algorithm to Rotate One Set of Vectors onto > =A0=A0=A0=A0=A0=A0=A0=A0Another > To: "Buz Barstow" > Cc: pymol-users@... > Message-ID: > =A0=A0=A0=A0=A0=A0=A0=A0<8ff898150801260104k4902e5f0tcb94e8ebbbf1e027@...= l.gmail.com> > Content-Type: text/plain; charset=3DISO-8859-1 > > 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 =3D 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 =3D RN > > Then > > MN^-1=3DRNN^-1 > > such that > > R =3D 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 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 =2D-=20 Jason Vertrees (javertre@...) Doctoral Candidate Biophysical, Structural & Computational Biology Program University of Texas Medical Branch=20 Galveston, Texas http://www.best.utmb.edu/ http://www.pymolwiki.org/ ```
 Re: [PyMOL] Algorithm to Rotate One Set of Vectors onto Another From: Buz Barstow - 2008-01-29 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 open-source 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 > pymol-users-request@... wrote: >> ------------------------------ >> >> Message: 3 >> Date: Sat, 26 Jan 2008 10:04:06 +0100 >> From: "Tsjerk Wassenaar" >> Subject: Re: [PyMOL] Algorithm to Rotate One Set of Vectors onto >> Another >> To: "Buz Barstow" >> Cc: pymol-users@... >> Message-ID: >> <8ff898150801260104k4902e5f0tcb94e8ebbbf1e027@...> >> Content-Type: text/plain; charset=ISO-8859-1 >> >> 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 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/ > _______________________________________________ > PyMOL-users mailing list > PyMOL-users@... > https://lists.sourceforge.net/lists/listinfo/pymol-users ```