Molecule Tutorials - Herong's Tutorial Examples - v1.21, by Dr. Herong Yang
Camera-to-Model Space Coordinates Mapping
This section provides a tutorial on how to map camera space coordinates to model space coodinates manually using the reverse of the rotation matrix in PyMol.
In the last tutorial, we have used the following mapping relation to map a point in model space to camera space, which is very easy.
Assuming: [Ax, Ay, Az]: a point in model space [Bx, By, Bz]: model rotation center [M11, ..., M33]: the rotation matrix [Cx, Cy, Cz]: same point in camera space [Dx, Dy, Dz]: camera rotation center We have the following mapping relation: |Cx-Dx| |M11 M12 M13| |Ax-Bx| |Cy-Dx| = |M21 M22 M23| * |Ay-By| |Cz-Dx| |M31 M32 M33| |Az-Bz|
But what about mapping a point in the camera space to the model space? It is also easy to do, if you know how to reverse the rotation matrix, using the "numpy" Python module.
1. Load the methane molecule structure to PyMol again. And convert viewing parameters into 'numpy' matrix and vectors:
PyMOL>delete all PyMOL>load Molecule-Methane.sdf CmdLoad: loaded as "Molecule-Methane". PyMOL>view = cmd.get_view() PyMOL>M1 = [view[i] for i in range(0,3)] PyMOL>M2 = [view[i] for i in range(3,6)] PyMOL>M3 = [view[i] for i in range(6,9)] PyMOL>M = numpy.matrix([M1, M2, M3]) PyMOL>D = numpy.matrix([[view],[view],[view]]) PyMOL>B = numpy.matrix([[view],[view],[view]])
2. Get the reverse of the rotation matrix and call it R:
PyMOL>R = M.I
3. We are ready to convert any point in the model space, A, to the camera space, C:
C = M*(A-B) + D A = R*(C-D) + B
You can verify this with some examples.
Table of Contents