Why the change to the modulus? If you have simply i % colors.size, if size is 3 for example you get
i = 1 -> modulus is 1 i = 2 -> modulus is 2 i = 3 -> modulus is 0 (which selects the last array member, according to the documentation) i = 4 -> modulus is 1 ..etc. I didn't know I couldn't put expressions in math, thanks for pointing that out; saves some future headaches! Dave 2009/6/16 Robert Hanson <[email protected]>: > A few corrections there: > > the colors need quotes > the */i won't work -- can't mix math and select expressions that way -- > should be model=i > the color line needs @{ } surrounding the math so the processor knows to > treat it as a math expression. > Also, since the array is numbered 1 - 3 you would want, while modulus would > go 0 to 2. I would suggest: > > > var mycolors = ["red", "orange", "green"]; > var ncolors = mycolors.size > var m = n; // 'n' is your model count here > for (var i = 1; i <= m; i = i + 1) > { > select model=i > color atoms @{mycolors[1 + (i - 1)% ncolors]}; > } > > Ah, but the problem is "model" refers to the number the author has assigned > -- usually just "1" for a model in a file. If there are multiple files, then > each model is still probably just "model=1" -- at least if they are PDB > files. A better solution would be if we could just say: > > color atoms property modelindex > > > See Jmol 11.7.42 > http://chemapps.stolaf.edu/jmol/docs/examples-11/Jmol-11.zip > and http://chemapps.stolaf.edu/jmol/docs/examples-11/new.htm > > ;) > > > Bob > > On Tue, Jun 16, 2009 at 12:46 PM, N David Brown <[email protected]> > wrote: >> >> I haven't tried after writing it, but this should work: >> >> var mycolors = [red, orange, green]; >> var m = n + 1; // 'n' is your model count here >> for (var i = 1; i < m; i = i + 1) >> { >> select */i; >> color atoms mycolors[i % mycolors.size]; >> } >> >> The 'i % mycolors.size' means that if you get to the end of your >> colors list, it'll start reusing them from the beginning. >> >> Note that you can specify colors in the form [r, g, b] as well, where >> 'r', 'g' and 'b' are values from 0 - 255. >> >> Best, >> >> Dave >> >> >> 2009/6/16 Marie-Christine Vallet <[email protected]>: >> > Hi, >> > I have a jmol window with n number of models and would like to color >> > each of my models with a different color without having to select each >> > model manually. I would like a script to do this automatically, is it >> > possible? Did I miss something in the mailing list that would answer >> > that question. >> > Thanks, >> > Marie >> > >> > >> > ------------------------------------------------------------------------------ >> > 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 >> > >> >> >> >> -- >> >> - N David Brown >> >> >> ------------------------------------------------------------------------------ >> 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 > > > > -- > 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 > -- - N David Brown ------------------------------------------------------------------------------ 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

