Jmol/Quaternions
From Proteopedia
(Difference between revisions)
Line 1: | Line 1: | ||
==Examples== | ==Examples== | ||
- | <StructureSection load=' | + | <StructureSection load='' size='340' side='right' caption='' scene='43/433638/Fullview_cartoon/20'> |
http://proteopedia.org/wiki/images/7/76/Wobble.spt | http://proteopedia.org/wiki/images/7/76/Wobble.spt | ||
Line 13: | Line 13: | ||
==Preliminaries== | ==Preliminaries== | ||
- | A quaternion is an mathematical object (like a matrix or a complex number) with four parameters x y z w. It is useful to express orientations and rotations, and to do calculations (combining, interpolating, dissecting) on them. | + | A quaternion ''q'' is an mathematical object (like a matrix or a complex number) with four parameters ''x y z w''. It is useful to express orientations and rotations, and to do calculations (combining, interpolating, dissecting) on them. |
- | Jmol shows structures (e.g. | + | Orientation refers to from which side we are looking at an object (or how we a orienting the object in front of the camera or viewport). Rotation refers to changing either the orientation, or turning a selected object while keeping the view. |
+ | |||
+ | ==Coordinate systems== | ||
+ | |||
+ | Jmol shows structures (e.g. atomic positions) on a display and allows the view to be rotated and individual atomic positions to be manipulated. The display has Cartesion coordinates (the x-axis goes right, the y-axis goes up, and the z-axis points at the viewer). The atoms have Cartesian coordinates x, y, z. The meaning of the axes is sometimes arbitrary (NMR structures) or along certain crystallographic directions (X-ray structures). When you rotate the model, the coordinate system of the model is rotated (same coordinates x, y, z, but axes of coordinate system point in different directions) with respect to the display coordinate system. | ||
<jmol><jmolButton><script>axes on</script><text>show axes</text></jmolButton></jmol> | <jmol><jmolButton><script>axes on</script><text>show axes</text></jmolButton></jmol> | ||
- | When a new structure is loaded, the axes point left, up, and out of the screen. The Jmol command "reset" puts | + | When a new structure is loaded, the model axes point left, up, and out of the screen. The Jmol command "reset" puts that coordinate system back into that initial orientation. |
<jmol><jmolButton><script>reset</script><text>reset to initial orientation</text></jmolButton></jmol> | <jmol><jmolButton><script>reset</script><text>reset to initial orientation</text></jmolButton></jmol> | ||
+ | |||
+ | ==Changing orientations using quaternions== | ||
The Jmol command "q = quaternion()" assigns the current orientation to q. | The Jmol command "q = quaternion()" assigns the current orientation to q. | ||
Line 27: | Line 33: | ||
<jmol><jmolButton><script>q = quaternion()</script><text>save orientation</text></jmolButton></jmol> | <jmol><jmolButton><script>q = quaternion()</script><text>save orientation</text></jmolButton></jmol> | ||
- | + | So, again, how is an orientation different from a rotation? An orientation is the rotation necessary to get the coordinate system from the "reset" orientation to the current orientation. The quaternion ''q0'' for the initial orientation corresponds to no rotation, i.e. {0 0 1 0}. To get back to an orientation ''q'' after rotating, use "moveto 0 quaternion q". After you saved an orientation, click the reset button above and then go back to the saved orientation with the button below. | |
<jmol><jmolButton><script>moveto 0 quaternion @q</script><text>go to saved orientation</text></jmolButton></jmol> | <jmol><jmolButton><script>moveto 0 quaternion @q</script><text>go to saved orientation</text></jmolButton></jmol> | ||
- | |||
==Combining two rotations== | ==Combining two rotations== | ||
+ | For the wobble script, I want to change the orientation a little bit, rotating about an axis in the plane of the display. The effect is that parts of the structure the the center foreground move around in a circle, tilting the view a bit in different directions. Distinct from the spin command, the view does not change much. Distinct from a rocking motion, the structure gets tilted over time in all directions, giving a better spatial view. | ||
+ | |||
+ | In order to achieve this effect, we have to apply a rotation ''r'' on the orientation ''o''. This is done by quaternion multiplication. The order matters: the right-most rotation is applied first. Here, we first want to rotate the structure from the initial orientation to the current orientation, and then apply the tilting rotation, so the overall orientation becomes ''r'' * ''o''. | ||
==Interpolating between orientations== | ==Interpolating between orientations== |
Revision as of 14:31, 25 July 2019
Examples
|