home *** CD-ROM | disk | FTP | other *** search
/ ftptest.leeds.ac.uk / 2015.02.ftptest.leeds.ac.uk.tar / ftptest.leeds.ac.uk / bionet / workshop / animation / workshop.txt < prev   
Text File  |  1994-05-08  |  22KB  |  277 lines

  1. Animation in Toolbook
  2.  
  3. Leader - Jon Maber
  4. Dept. Biochemistry & Molecular Biology
  5. The University of Leeds
  6.  
  7. A reasonable familiarity with Toolbook is assumed but advanced experience of scripting is not necessary.
  8.  
  9. Toolbook is not specifically an animation package but its object oriented graphics and script commands lend itself well to cartoon style animation.  It is possible to get by with only a basic understanding of the scripting language.  There are a number of techniques demonstrated in the Animation Primer which comes with Toolbook.  This workshop concentrates on two techniques.
  10. For this exercise you will animate the mode of action of a typical membrane bound protein which transports a ligand across the membrane.  (The file MEMBRANE.TBK contains  a [nearly] completed version of the animation so you can get a idea of what you are aiming at.)
  11. Plan of Action
  12.     Create a suitable Toolbook background.
  13.     Create five versions of the protein in different conformations.
  14.     Write a script in a button to animate the protein.
  15.     Create a ligand.
  16.     Edit the script to make the ligand follow a path.
  17.     Eliminate 'blinking'.
  18. The Background
  19. It is wise to put the static parts of the animation in the background because it is possible to get Toolbook to store this background and so avoid the need to recreate it as the foreground objects move across it.
  20.     Start a new book (with the default page size).
  21.     Set the background colour to pale blue to represent water. 
  22.     Draw a cross section of a membrane across the middle.  This can be achieved with five rectangles - two for the outer edges (phosphate heads), two in the middle (aliphatic tails) and one thin one in the centre ( a gap to emphasise the bilayer.  
  23.     Put a pale blue rectangle (for water) in the middle of the membrane to make a pore.
  24. The Show/Hide commands
  25. A simple method for animation is to display different images in sequence.  For cartoon style animations this can be done in a small number of steps.  
  26. Switch to foreground.
  27.  
  28.  
  29.     Use ellipses and an irregular polygon to make one side of the protein in its initial position without bound ligand.  The shape should be a rounded off isosceles triangle with one short side vertical.
  30.  
  31.  
  32.     Use copy and paste to make the other side of the protein and flip it over to make a mirror image.  Adjust the position to make a small gap between the two halves.  Use the group command to fix the bits and pieces together.  You now have position one of the protein.
  33.     Copy and paste the whole protein and flip over to make position five of the protein.
  34.     Make position three next (leave position two for the moment).  The protein is a different shape so you will have to start from scratch.  The ligand should be at the centre and the two triangular sides should be rotated around so that the long side is vertical.  The point where the ligand is bound needs to be concave - you will have to carefully sculpture this using the irregular polygon tool.  Remember, you can adjust an irregular polygon after its creation using the Reshape command.  
  35.     Position two is the most difficult.  you are trying to make a structure midway between positions one and three - partly rotated and with a slightly concave binding site offset above the centre line.  Copy, paste and flip over to make position four.
  36.  
  37.     Use the Object Group Properties... command to name each protein starting with "protein_a".
  38.     Now position all of the structures over the pore in the membrane.
  39.     You are now in a position to animate the structures.  Create a grey button at the bottom of the page and edit the script.  The script is quite simple;
  40.  
  41. to handle buttonup
  42.     show group protein_a
  43.     hide group protein_b
  44.     hide group protein_c
  45.     hide group protein_d
  46.     hide group protein_e
  47.  
  48.     pause 1 seconds
  49.  
  50.     hide group protein_a
  51.     show group protein_b
  52.  
  53.     pause 1 seconds
  54.  
  55.     hide group protein_b
  56.     show group protein_c
  57.  
  58.     pause 1 seconds
  59.  
  60.     hide group protein_c
  61.     show group protein_d
  62.  
  63.     pause 1 seconds
  64.  
  65.     hide group protein_d
  66.     show group protein_e
  67.  
  68.     pause 1 seconds
  69.  
  70.     hide group protein_e
  71.     show group protein_d
  72.  
  73.     pause 1 seconds
  74.  
  75.     hide group protein_d
  76.     show group protein_c
  77.  
  78.     pause 1 seconds
  79.  
  80.     hide group protein_c
  81.     show group protein_b
  82.  
  83.     pause 1 seconds
  84.  
  85.     hide group protein_b
  86.     show group protein_a
  87. end
  88.  
  89. Test the animation by clicking on the button in reader mode.  If you need to edit any of the objects use the toolbook command window to enter the command; "show objects of this page".
  90. The Move Command
  91. Any object can be moved on the page using the move command.  The form of the command is;
  92. move object to x, y
  93. It would be tedious in the extreme to move the ligand across the page by scripting hundreds of move commands.  A neater method is to use an angled line drawn with the mouse as the path which the ligand will follow.  This requires a subroutine which will find the position of each point on a named angled line and move the object over them one by one.
  94.     Add the following to the book script;
  95. to handle startPath o, p
  96.     local i, v, s
  97.  
  98.     set item 1 of s to (item 3 of bounds of o)-(item 1 of bounds of o)
  99.     set item 2 of s to (item 4 of bounds of o)-(item 2 of bounds of o)
  100.     set item 1 of s to item 1 of s/2
  101.     set item 2 of s to item 2 of s/2
  102.     set item 1 of v to (item 1 of vertices of p)-(item 1 of s)
  103.     set item 2 of v to (item 2 of vertices of p)-(item 2 of s)
  104.     set position of o to v
  105. end
  106.  
  107. to handle followPath o, p
  108.     local i, v, s
  109.  
  110.     set item 1 of s to (item 3 of bounds of o)-(item 1 of bounds of o)
  111.     set item 2 of s to (item 4 of bounds of o)-(item 2 of bounds of o)
  112.     set item 1 of s to item 1 of s/2
  113.     set item 2 of s to item 2 of s/2
  114.     step i from 1 to itemcount( vertices of p ) by 2
  115.         set item 1 of v to (item i of vertices of p)-(item 1 of s)
  116.         set item 2 of v to (item i+1 of vertices of p)-(item 2 of s)
  117.         set position of o to v
  118.     end step
  119. end
  120.     Draw a free ligand (just a circle) and name it "ligand".
  121.     Draw an angled line from the top left hand corner to the binding site on the protein using twenty or thirty points.  (More points make slower motion.) Name it "path_a".  If you stretch the path after you have drawn it you can get it to start from off the page.
  122.     Edit the top of the buttonup handler of the button script to read;  (The send command sends a message to the book script which activates the routines you put in there.)
  123.  
  124.     show group protein_a
  125.     hide group protein_b
  126.     hide group protein_c
  127.     hide group protein_d
  128.     hide group protein_e
  129.     send startpath ellipse ligand, angledline path_a
  130.     show ellipse ligand
  131.  
  132.     send followpath ellipse "ligand", angledline path_a
  133.  
  134.     pause 1 seconds
  135.  
  136.     To complete the animation you need three more paths; ligand leaving bottom of protein, ligand coming back to bottom of protein and ligand leaving top of protein.  Add the appropriate lines to the button script.
  137. Test and adjust as necessary.  The Reshape command can be used to alter the paths.
  138. The angled lines don't need to be visible to work.  In the command window type 'hide angledline path_a' to make the first line invisible.  Do the same for the others.
  139. Eliminate Blinking
  140. When you hide one object and show another there is an irritating blink between the two events.  This is because Toolbook redraws the screen immediately after each command.  You can prevent this.  The system variable sysLockScreen is set to true or false to switch on and off screen updates.  E.g.
  141. to handle buttonup
  142.     .
  143.     .
  144.     .
  145.     set sysLockScreen to true
  146.     hide group "protein_a"
  147.     show group "protein_b"
  148.     set sysLockScreen to false
  149.     .
  150.     .
  151.     .
  152. While sysLockScreen is true the screen is frozen and when it is made true the screen is redrawn to show all the changes that were made in one go.
  153.     Edit in the appropriate statements to eliminate blinking during hide/show phases.  Make sure you haven't enclosed any of the followpath statements.
  154. A big problem with Toolbook animations is that the performance of the animation depends on the computer used.  The pause command should give a consistent delay but redrawing and moving objects may be dramatically faster or slower.  One way round this is to generate bitmap images and Video for Windows to make an AVI file of the animation.  This is not part of this workshop but I can provide you with Toolbook scripts if you want to experiment.
  155.  
  156. Molecular Animations (Small molecules)
  157.  
  158. Leader - Jon Maber
  159. Dept. Biochemistry & Molecular Biology
  160. The University of Leeds
  161.  
  162. A reasonable familiarity with MS Windows applications is assumed.
  163. Plan of Action
  164.     Obtain structure in common file format.
  165.     Use molecular graphics package to generate set of images.
  166.     Use MS Video for Windows ViEdit to make AVI file from bitmaps.
  167.     Incorporate into courseware.
  168.  
  169. Simple Rotations
  170. The three dimensional structure of a molecule is often crucial to the understanding of it's properties and function.  A static two dimensional image of the molecule on a v.d.u. may be inadequate but when the molecule is rotated the brain easily reconstructs the structure in three dimensions.
  171. Part 1
  172.     Run Molecular Viewpoint.
  173.     Open the file ASPIRIN.CSV.  
  174.     Select File Target Bitmap command.
  175.  
  176.  
  177.  
  178.  
  179.  
  180.     Select File Bitmap Setup... command and adjust the bitmap width and height.  Bear in mind that performance of Video for Windows drops as the bitmap size increases also the bitmaps need to be stored on disc temporarily.
  181.  
  182.     Use View Background Colour... and View Zoom... commands to get desired appearance.
  183.  
  184.  
  185.  
  186.  
  187.  
  188.     Choose the Frame Duplicate Frames... command and enter the number of frames for the animation.  If you want to do a simple rotation about a single axis then 36 frames will give you 10░ increments.  It is desirable to minimise the number of frames but to maintain the illusion of smooth movement you must ensure that from one frame to the next each atom moves a small distance relative to it's diameter.  (Incidentally, if a frame is very similar to  a previous frame the compression will be better later on so the final file size will not be directly proportional to the number of frames chosen now.)
  189.     Select the Transform Copy to All command so that when you alter the view in frame zero the same view is copied to all frames.
  190.     Use mouse to rotate the molecule to the desired initial orientation.  Clicking on different regions of the graphic display will rotate around any of the three axes by a few degrees per click.
  191.     Now select the Frame Special Effects... command and choose a transform from the list.
  192.     Preview the animation using the Frame Play command.  Because the program is generating images in real time the performance may not be as good as you wish but this will be sorted out later.
  193.  
  194.     If you are happy with the animation you are ready to generate bitmaps.  Select the File Save Image As... command.  In the Save As dialogue box use the Save File as Type control to select Bitmap Series and type the file name for the first bitmap in the File Name edit box.  The file name must have numeral at the end - for example aspri000.dib.  The program will create files with incrementing file names for each of the frames in the animation.
  195. Part 2
  196.     Exit from Molecular Viewpoint and run VidEdit.
  197.     Choose File Open... command and list files of type DIB Sequence.  Open the first bitmap in the series - the entire set of bitmaps will be loaded into VidEdit.  You could play back the animation but the performance is likely to be poor - this will improve when the images are compressed.
  198.     Choose the Save As... command, enter a filename (ASPIRIN.AVI will do) and select the compression options button.  Microsoft RLE will give an accurate representation but Microsoft Video 1 will give the best compression.  It is possible to adjust the balance between compression and quality and you may like to use the preview button to experiment with this.
  199.     The default playback rate is probably far too fast - computer generated animations often are acceptable at very low frame rates.  Do NOT use the Convert Frame Rate command  as this maintains the playback duration by duplicating or deleting frames instead us the Synchronise command.  Experiment with frame rates - somewhere under 10 frames per second will give you reasonable playback performance on low end computers.  Save the file when you are satisfied.
  200.     Delete the bitmaps in File Manager.  They take up a lot of disc space.  (In normal practice you may wish to archive the bitmaps in some way before you delete them.)
  201. Part 3
  202.     The AVI file can now be incorporated into multimedia aware applications.  For example, pasted into a Windows Write document via the  Media Player.
  203.     Run Media Player and use the File Open... command to load your animation.
  204.     Use the Edit Options... command to control playback.  (E.g. Auto Repeat).
  205.     Put the animation on the clipboard by selecting the Edit Copy Object command.
  206.     Run Write and choose the Edit Paste command. 
  207.     You can type in a title and a paragraph of explanation and then save the document.  The reader can double click on the graphic to see the animation.
  208.     Of course the animation can be incorporated into many other applications such as Toolbook..
  209. Animating Conformational Changes and Reaction Mechanisms
  210. For this you need co-ordinates for the start and finish structures and create in between structures.  Interpolation of co-ordinates can be done in two ways - interpolation of co-ordinates or interpolation of geometry (bond lengths, angles and torsion angles.).  The first of these is straightforward whereas the second requires specially written software.
  211. For this exercise I've set up some co-ordinates.  The animation will show a nucleophylic reaction mechanism.  A hydroxide ion will displace the hydroxyl group from methanol.  The carbon atom goes from tetrahedral through trigonal planar and back to tetrahedral.
  212.     Run Molecular Viewpoint and open the file METHANOL.CSV.  The file contains thirty frames.  
  213.     Repeat steps from the previous exercise to create a set of bitmap files and import into Video for Windows as before.
  214. Molecular Mechanics
  215. Students raised on chemical formulae may forget the dynamic nature of molecules so in some cases molecular dynamics can be used to show thermal motion.  I've used a molecular dynamics run to produce the file aleua.csv.  This is short run of the tripeptide alanine-leucine-alanine at 300K.  Each step is 10 fs in duration (decimated from 1fs iterations).
  216.     Produce an AVI file as for the previous exercises.
  217.  
  218. Animation In Action!
  219.  
  220. Leader - Jon Maber
  221. Dept. Biochemistry & Molecular Biology
  222. The University of Leeds
  223.  
  224. A reasonable familiarity with MS Windows graphics applications (e.g. MS Draw or Corel Draw) is assumed.
  225. Action is aimed at business presentations.  It isn't designed for sophisticated scientific material but is cheap and simple with a freely distributable playback program.  A key advantage is that all events follow a strict time line and if a slow computer is used the frame rate is adjusted down to maintain time accuracy.  So a fast computer makes the action smoother but not faster.
  226. For this exercise you will animate the paths of different sized proteins through a gel filtration bead.   (A completed version of the animation is in the file GELFILT.ACT for guidance.)
  227. Plan of Action
  228.     Create graphic objects.
  229.     Edit start points and durations of objects.
  230.     Create a path for each protein molecule.
  231.     Make an AVI file for playback (optional).
  232. In Detail
  233.     Run Action!
  234.     To create a new file first choose the Edit Preferences... command and set the stage size to 640 by 480.  The lowest resolution screen which will be used for playback is likely to be VGA so the stage size will fill the screen.  On higher resolution screens a grey border will surround the animation.  (If your final target will be an AVI file a smaller size would be sensible.)  Now select the File New command.
  235.  
  236.     Set the background colour with the Scene Set Background... command.  Select 'Pattern' in the drop down selection box and choose a pattern and colours by clicking on the colour controls.  (This colour represent the water surrounding the bead.)
  237.  
  238.  
  239.     Select the ellipse tool and draw three concentric circles (starting with the big one) to represent the gel bead (which gets denser in the middle).  It isn't  necessary to be accurate at this stage.
  240.     Use the colour selector on the tool box to choose the colours of the circles.  They should be graded to give the appearance of increasing density.  Chose a colour for the centre and then find colours intermediate to this and the background blue for the other circles.  Remove the surrounding black lines using the line style control on the tool box.
  241.     Set the sizes of the circles accurately.  Double click on a circle to obtain the object properties dialogue box.  The properties are divided into groups using a drop down selector.  Choose the Content group.  You can now use the 'Extent' controls to edit the size of the circle accurately.  Set the diameters of the circles to 100, 200 & 300.
  242.     To properly centre the circles select them all and choose the Object Align Objects... command.  One of the alignment types shown in the dialogue box will centre all the selected object.
  243.  
  244.  
  245.  
  246.     Now group the circles to make a single object.  Use Object Group command.  Drag the group to the centre of the screen.
  247.  
  248.  
  249.  
  250.  
  251.     You now need four protein molecules of different sizes.  To keep things simple use circles (if you want some realism overlap several circles to make an irregular blob and group).  Rough sizes ought to be 10, 20, 30 and 40 pixels wide.  Choose distinctive colours.
  252.     Drag the proteins to a tightly spaced row just off stage centre top.
  253. Motion
  254. Action objects have three phases of existence on the stage - enter, hold and exit.  Each can have its own duration and the enter and exit phases can have motion applied in a variety of ways.  Because your protein molecules will be in constant motion you only really need one phase but to make things simple you can use the hold phase to keep the proteins off stage before they are needed.  This won't affect the appearance but make it easier to click on them for selection while you are editing.  The Exit phase will be used to bring the proteins down past the bottom of the stage.  (No enter phase will be used.)
  255.  
  256.     Double click on the biggest protein.  Go to the hold group of properties and change the duration to three seconds.  This will give you a three second pause at the start of the animation.  Now go to the exit group of properties (don't set the duration this will happen automatically).   Choose the motion type Path Editor.  You now enter the path editor mode.  You must define positions for the protein at times in the exit phase.  The speed of the motion depends on the distance moved in a period of time
  257.  
  258.  
  259.     The protein will take one second to drop to the bead.  Use the time control to move to one second into the exit phase.  Now drag the protein down to the point where it touches the bead.  
  260.     The protein is too big to penetrate the bead so will travel around the outside of the bead at a constant speed.  Change the time to 2 seconds and drag the protein round to the '11 o'clock' position.  Change the time to 3 seconds and drag the protein round to the '10 o'clock' position.  Change the time to 4 seconds and drag the protein round to the '9 o'clock' position.  
  261.     The last part of the movement can be done in one step.  Change the time to 8 seconds and drag the protein down off the bottom of the stage.  You have completed the movement so click on the done button of the time control.  Dismiss the properties dialogue box.
  262.  
  263.  
  264.  
  265.     You can preview the animation by clicking on the play button in the time control box.  You should see the big protein moving in an appropriate way but the bead disappears ten seconds into the animation.  This is because the default duration for an object is ten seconds.  Double click on the bead and changes the duration of its hold phase to one minute.  Play again.  (Remember to rewind.)
  266. The next smaller protein will penetrate into the outermost shell of the bead before travelling around and out.  This can be done in pretty much the same way as before but to get slower motion inside the gel use two second steps while the protein is in the bead.  The final result should be that the two proteins drop simultaneously but the smaller protein takes longer to pass through the bead.  (It will travel at the same speed after it leaves the bead.)  Each subsequent protein penetrates into another shell of the bead and travels more slowly.
  267.     Plan the durations and paths of the remaining proteins and implement using the hold and exit property groups in the object properties dialogue box.  It's best to do this on paper.
  268. Optional Extra
  269. If you wish to avoid using Action! for playback you can make a series of bitmap images from the animation and load these into MS Video for Windows VidEdit.  This is possible but problematic because of the way Action! names files.  Action! always starts with 1 (appended to the file name you provide) and doesn't pad with zeros.  VidEdit expects units, tens etc. to stay in the same character position, i.e. padded with zeros.  The way round this is to make sure the first part of the animation is unwanted and discard the first 99 frames that Action! creates.
  270.     Edit the duration of the proteins so they stay off stage for 15 seconds.
  271.     Choose the File Export command - set Start Time to 00:00.0 the End Time appropriate to your animation and Every: to 00:00.1 to give you a frame rate of 10 per sec.
  272.     Delete the unwanted files.
  273.     Load into VidEdit (See molecular movies exercise for instrcutions).  Voila!
  274. BioNet Workshop '94        JRM
  275.  
  276.  
  277.