Thanks, Nico, for releasing Jmol 11.7.41. This is a major advance for Jmol,
probably associated with a few backsteps, we'll see. If you are doing any
script writing, please take a look at this version. The primary changes here
are internal, so we are finding a few odd bugs. The main improvement is in
the way functions, if, while, and for work. Now you have quite a variety of
options, including the sort of brace syntax used in JavaScript. If you are
using Jmol 11.7, please try 11.7.41 (not 11.7.40, by the way).

function myfunc(x) {
   background @x
   spin @{!_spinning}
}

myfunc("blue")

If you code in JavaScript, it will look VERY familiar. (Though it is not
exactly JavaScript -- see below.)

function resetAngle(ang) {
  var currentAngle = getproperty("measurementInfo", 1,"value");
  rot(ang-currentAngle)
}

function rot(n) {
  select hydrogen and connected(c10);rotateselected {c10} {n4} @n;refresh
  var ang = angle({c5}, {n4},{c10},{h15})
  minimization energy;
  var s = "angle = " + ("   "+ang%0)%-5 + " Energy = " + ("
"+(_minimizationEnergy-e0)%2)%-8 + " kJ/mol"
  set echo top left; echo @s
}

function doRotateMethyl() {
  reset;
  center {-0.23140144 0.61279976 0.071704745};
  rotate z -103.09; rotate y 100.92; rotate z 90.44;
  set useMinimizationThread false
  minimize energy
  e0 = _minimizationEnergy
  print "the e0 energy is " + e0

  draw delete
  cmd = ""
  for (var i =0; i < 36; i++) {
      rot(10);
      var x0 = -3
      var z0 = -4
      var s = "draw_"+(i*10)+"_"
      var x=i/10.0 + x0
      var y=0
      var z=0 + z0
      var x1=i/10.0 + x0
      var z1=(_minimizationEnergy-e0)/5.0 + z0
      var y1=0
      cmd += "draw " + s + " " + point(x,y,z) + " " + point(x1,y1,z1) + ";"
  }
  script inline @cmd
}

load caffeine.xyz
doRotateMethyl()

# Similarities to JavaScript:
#
# --Jmol scripting now supports ++, --, +=, -=, *=, /=, \=, |=, &=
# --The if, for, while, and function constructs are all about the same,
using braces.
#   for example:
#
#     for (i = 1; i <= 10; i++) {print {*}[i].radius}
#     for (i = 0; ++i <= 10;) {print {*}[i].temperature}
#     if (var i < 10) {{*}[i].radius *= 2} else {spacefill off;wireframe}
#     i = 0; while (++i < 10) {select {*}[i * 2]; color red }
#     for (i = 0; i < 10;i++){ rotate x 10; delay 0.1 }
#     for (i = 0; i < 10;i++)rotate x 10; delay 0.1  // brackets not
required when commands are all on the same line
#     if ({atomno=3}.radius < 0.35){ print "it is smaller"} else {print "it
is larger"}
#     if ({{*}[3][10]}.radius < 0.35) print "they are smaller on average"
else print "they are larger on avarage"
#     i = 0; while (++i < 10){spin @{!_spinning}; delay 1}
#    calculate straightness;print {helix}.straightness
#
# --Arrays expressed as  a = [3,4,5,"green"]
# --A relatively free typing of variables. Jmol is going to save variables
as strings
#   in terms of the Jmol "state" but in this version I introduce the
Variable class that
#   subclasses Token and allows for a more organized approach to variables
and sets the
#   stage for future improvements.
# --Commands separated by semicolons or line breaks
# --Object-like methods and fields such as {*}.xyz.all.join(" ") and
{atomno=3}.radius
# --On-the-fly compilation.
#
# Differences include:
#
# --A broarder range of variable types, including boolean, integer, decimal,

#   string, point, axis-angle/plane/quaternion, atom bitset, bond bitset,
#   and one-dimensional array.
# --No case-sensitivity for variable names.
# --Double quotes, not single- or double-quotes
# --No "new" keyword -- Array(), not "new Array()"
# --Two-dimensional arrays are not supported (yet):  a =
[3,4,5,"green",["green", "blue", "red"]]
# --1-based rather than 0-based arrays. (ONLY because that's the way models
are numbered.)
# --Array indexing from the back to the front using n <= 0: A[0] A[-1]
A[-2].
# --Array ranges [n][m], for example A[-3][0]
# --Core commands do not use commas or parentheses.
# --Visual-Basic-like IF / ELSEIF /END IF, FOR/END FOR, WHILE /END WHILE,
and GOTO options.
# --A broad range of mathematical operations
# --Of course, a whole suite of methods that relate to molecular structure.
#

There are, of course lots more differences -- I'm not trying to recreate
JavaScript in Jmol. But these are some aspect that come to mind.

Bob




-- 
Robert M. Hanson
Professor of Chemistry
St. Olaf College
1520 St. Olaf Ave.
Northfield, MN 55057
http://www.stolaf.edu/people/hansonr
phone: 507-786-3107


If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to