## [Jmol-users] a treat for you -- Jmol in motion

 [Jmol-users] a treat for you -- Jmol in motion From: Bob Hanson - 2007-02-28 08:57:57 Hot off the press -- Q: What do you get when you combine the following? wide-ranging variable capability, including arrayed variables program flow control with if/else/endif and message/loop relative motion Take a look at http://www.stolaf.edu/people/hansonr/molecules.htm in particular the link "Water Liquid" followed by "Jmol 11.2 motion ON" This is not a movie. This is not a set of frames. It's just a file full of water molecules. Then look at the script that drives the animation: http://www.stolaf.edu/people/hansonr/water.spt This script runs through the molecules, setting them moving in independent directions. It tracks what direction they are going and how many atoms are within 1.6 angstroms of a given molecule. When nearby atoms are found, the program reverses a molecule's direction, but if a molecule wander too far afield, we can spot that and turn it around again. The code that controls this neighbor-sensing and reversal is just a few lines long: tooclose = not {mol_set} and within(1.6, {mol_set}) if (tooclose > 0) set @vm = mxyz - {tooclose_set}.xyz else if (centerpt.distance(mxyz) > maxradius) set @vm = {0 0 0} - @vm endif endif motion = @vm / @vm * rate select {mol_set} translateSelected @motion Pretty straightforward! The setup is interesting as well: centerpt = {*}.xyz nMolecules = {*}[{*}].molecule message _start # this is the loop start m = m + 1 if (m > nMolecules) m = 1 endif mol = {molecule=m} mxyz = {mol_set}.xyz vm = "v"+m # this is the "array" - v1, v2, v3, etc. set @vm mxyz # this sets the appropriate variable, v1, v2, etc. Fun, eh? -Bob