Jmol/Quaternions

From Proteopedia

(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
<StructureSection load='' size='340' side='right' caption='' scene='43/433638/Fullview_cartoon/20'>
<StructureSection load='' size='340' side='right' caption='' scene='43/433638/Fullview_cartoon/20'>
-
==Examples==
+
==Examples of how quaterions are used==
-
http://proteopedia.org/wiki/images/7/76/Wobble.spt
 
-
{{Image:Wobble.spt}}
 
<jmol><jmolButton><script>script "http://proteopedia.org/wiki/images/7/76/Wobble.spt"</script>
<jmol><jmolButton><script>script "http://proteopedia.org/wiki/images/7/76/Wobble.spt"</script>
<text>wobble</text></jmolButton></jmol>
<text>wobble</text></jmolButton></jmol>
 +
 +
http://proteopedia.org/wiki/images/7/76/Wobble.spt
 +
{{Image:Wobble.spt}}
Line 38: Line 39:
<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>
 +
Relevant Jmol command examples:
 +
q = quaternion() # store current orientation
 +
moveto 0 quaternion @q # go back to stored orientation instantly
 +
moveto 1 quaternion @q # go back to stored orientation gradually
 +
==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.
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''.
+
In order to achieve this effect, we have to apply a rotation ''r'' on the starting orientation ''s''. 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'' * ''s''.
 +
 
 +
Relevant Jmol command examples:
 +
r = quaternion({@x @y @z},@tilt) # rotation about an axis in direction xyz by tilt degrees
 +
tilted = r * s # apply the rotation to the starting orientation to get the tilted orientation
 +
moveto @time quaternion @tilted # tilt the view, taking some time to do so.
==Interpolating between orientations==
==Interpolating between orientations==
Line 52: Line 63:
<jmol><jmolButton><script>moveto 0 quaternion @q0</script><text>back to last orientation</text></jmolButton></jmol>
<jmol><jmolButton><script>moveto 0 quaternion @q0</script><text>back to last orientation</text></jmolButton></jmol>
-
<jmol><jmolButton><script>q10 = @qr / 10; rotate quaternion @q10</script><text>rotate one tenth</text></jmolButton></jmol>
+
<jmol><jmolButton><script>q10 = @qr / 10; rotate @q10</script><text>rotate one tenth</text></jmolButton></jmol>
 +
Relevant Jmol command examples:
 +
qr = quaternion({1 1 0}, 90) #define the overall rotation
 +
q10 = @qr / 10 #q10 is rotating only one tenth of the way
 +
rotate @q10 # rotate the view by the given amount
==Interpreting a rotation==
==Interpreting a rotation==
 +
For the second example script, I wanted to rotate the view back to the initial orientation. For small adjustments, I wanted it to take a small time, while for larger adjustment, I wanted to spend enough time that you can easily follow. The Jmol moveto command takes a duration for the entire rotation as a parameter. If I set this to a fixed value, it would be too slow for small adjustments or too fast for large rotations. So I had to figure out by how many degrees I would rotate first, and then decide on the timing accordingly.
 +
 +
Here are the relevant Jmol commands:
 +
q0 = quaternion
 +
angle = rotation%"theta" #Extract the rotation angle from the quaternion
 +
angle = 2 * acos(rotation.w) #Alternative way to get the angle, avoids percent sign that gave me trouble
 +
duration = angle/45 + 0.1 #take one second per 45 degrees rotation, plus 0.1 sec
 +
qnew = rotation * q0 #figure out the new orientation
 +
moveto @duration quaternion @qnew # reorient the view to qnew in duration seconds
 +
</StructureSection>
</StructureSection>
==Resources==
==Resources==
http://sacredsoftware.net/tutorials/quaternion.html
http://sacredsoftware.net/tutorials/quaternion.html

Revision as of 15:59, 25 July 2019

Drag the structure with the mouse to rotate

Resources

http://sacredsoftware.net/tutorials/quaternion.html

Proteopedia Page Contributors and Editors (what is this?)

Karsten Theis

Personal tools