## jmol-users

 [Jmol-users] Jmol 11.1.15 -- "molecular" math Part I From: Bob Hanson - 2007-02-27 01:20:41 ```INTRODUCTION TO MOLECULAR MATH IN JMOL -- Part I OK, I think you will find that the "molecular math" that you can do in Jmol is quite an advance over 11.0. Basically what you can do is assign variables to all sorts of quantities -- true/false conditions, integer and real numbers, strings, atom sets, bond sets, and points and planes in space. That should cover us! All the standard math is supported, including +-*/() and % (modulus): x = (3.0 * ({oxygen} + {hydrogen}) / 2 z = "the number of oxygen atoms is " + {oxygen}.size isSaturated = ((2.0 * {carbon} + 2 + {nitrogen} - {hydrogen}) == 0) Note that the simple phrasing {...} means two different things in two contexts. In a numeric context, it means the number of atoms. In a string context, it means a listing of the atoms in a special Jmol 11 format: x = "the oxygen atoms are " + {oxygen} gives for caffeine: >>> x = "the oxygen atoms are ({8 10})" This allows saving of variables such as this in the state - they are just strings, but they are special strings. Bonds are saved the same way, but with square brackets instead of parentheses: set bondMode or; x = "the bonds to oxygen are " + {oxygen}.bonds >>> x = "the bonds to oxygen are [{10 13}]" Anything that can be done in a SELECT command can be put between braces and evaluated: y = {oxygen and not atomno < 3} This delivers TWO answers: y_set = "({8 10})" y = 2 You can use both of these in later commands: x = y * 5 xBonds = y_set.bonds and, especially interesting, you can use the "set" version in SELECT commands: select y_set; color red; select xBonds; color bonds green; # yes, this selects just those bonds The following functions are available, shown with examples: Distance(a,b) Angle(a,b,c) Angle(a,b,c,d) ------------ the a-b distance, angle a-b-c or dihedral a-b-c-d, where a, b, c, and d are any combination of expressions that can be evaluated to a point, including atom expressions, xyz coordinates, fractional coordinates, or draw objects. xAB = distance({oxygen}[1],{oxygen}[2]) xAngle = angle({C1},{C2},{C3}) xAngle = angle({C1},{C2},{0 0.5 0.5}) xAngle = angle({carbon}[1],{carbon}[2],{carbon}[3]) draw pt {2 2 2}; xAngle = angle({0 0 0},\$pt,{atomno=3}) Data({atoms},"format") ---------------- The Data() function generates XYZ, MOL, or PDB code for the specified subset of atoms. xyzData = data({selected},"xyz") xyzData = data({not solvent},"pdb") The PDB file format does not include connections at this point. In conjunction with new DATA and WRITE capabilities, the Data() function allows for extracting out specific parts of the model to files using the application: load 1blu.pdb x = data({within(5.0, iron)}, "pdb") write VAR x ironCenter.pdb or, do display but not save, a new option for the DATA command: load 1blu.pdb x = data({within(5.0, iron)}, "pdb") DATA "model @x" Note that @x can be used in just about any command as a variable: xCenter = {0.0 0.0 0.0}; xAtom = {atomno=3}.xyz; draw line1 @xCenter @xAtom Load("filename") ---------------- Variables can be loaded with string data from files. Combined with the DATA command, this allows for a new way to load a model: x = load("caffeine.xyz") DATA "model @x" With the .lines method (given below), this also allows for loading a file and then displaying only certain lines, or loading specific lines: x = load("mydata.dat").lines[1][15] #only the first 15 lines of a file. x = load("caffeine.xyz") y = x.lines[x.lines.size-2][x.lines.size] #only the last three lines Connected(nMin,nMax,"type",{a}) Connected(dMin,dMax,"type",{a},{b}) ----------------------------- As for SELECT, the first of these Connected() function finds all atoms that are connected to atoms of the specified atom set by the specified number and type of bonds. All of the parameters are optional. x = connected(3,"single",{carbon}) xMethylCarbon = connected(3, {hydrogen}) select connected("double",{carbon}) The second is a new function that mirrors what the CONNECT command does. In this case, though, it only selects for the BONDS of the given type (which may be omitted). Note that the return from this function is a set of bonds, not atoms. Thus, we have: select connected(1.2,1.3,{carbon},{oxygen});color bonds green or: x = connected(1.2,1.3,{carbon},{oxygen}) connect @x_set red double Here x_set gets defined as the set of bonds; @x_set is how that is referenced in the connect command. Substructure("smiles-string") ----------------------------- This is the same as in Jmol 10.2. For example: select substructure("[C]=[O]") selects four atoms. So does the following, but we can then use modifiers to get more: x = substructure("[C]=[O]").bonds.label("%-4a1 %-4a2 %6.3LENGTH") reports: O11 C5 1.245 O9 C6 1.251 Within("group|chain|molecule|etc...",a) Within(distance,a) Within("plane",{a b c d}) Within("hkl",{h k l}) Within(distance,plane,{a b c d}) Within(distance,hkl,{h k l}) Within("sequenceData") ------------------------------------- The within() function operates the same as SELECT, delivering an atom set matching the designation. With 11.1.15, the syntax used in SELECT for functions is extended to match the syntax for IF and SET: select within(group, oxygen) # old way, still usable select within("group", {oxygen}) # new way -- matches IF and SET: x = within("group", {oxygen}) This also means that we can use "item selectors" in SELECT: select within("molecule", {oxygen}[2]) Or, for that last molecule: select within("molecule", {*}[{*}]) (This works because [n] selects the nth atom, and {*} evaluates to the number of atoms, so {*}[{*}] evaluates to "the last atom in the model" -- and then we find its molecule.) I'll save the modifier functions .atoms .bonds .distance(a) .find("string") .ident .label("formatString") .length .lines .size .x, .y, .z .xyz and all the atom properties such as .temperature, .phi, .bondcount, etc., for another posting. Bob ```