OK, so in this spirit, can we make it even more efficient? Also, a slight
correction there regarding modulus, and this allows for a color_list that is
already an array. I note a bug that doesn't allow you to assign variable
name "type" and also use ".type" -- easy fix....
function color_by_chain(objtype, color_list) {
if (color_list) {
if (color_list.type == "string") {
color_list = color_list.split(",").trim();
}
} else {
color_list =
["104BA9","AA00A2","C9F600","FFA200","284A7E","7F207B","9FB82E","BF8B30","052D6E","6E0069","83A000
","A66A00","447BD4","D435CD","D8FA3F","FFBA40","6A93D4","D460CF","E1FA71","FFCC73"];
}
var cmd2 = ""
if (!objtype) {
var type_list = [
"backbone","cartoon","dots","halo","label","meshribbon","polyhedra","rocket","star","strand","stru
t","trace"];
cmd2 = "color " + type_list.join(" none; color ") + " none;";
objtype = "atoms"
}
var chain_list = script("show chain").trim().lines;
var chain_count = chain_list.length;
var color_count = color_list.length;
var sel = {selected};
var cmds = ""
for (var chain_number=1; chain_number<=chain_count; chain_number++) {
// remember, Jmol arrays start with 1, but % can return 0
cmds += "select sel and :" + chain_list[chain_number] + ";color " +
objtype + " [x" +
color_list[(chain_number-1) % color_count + 1] + "];" + cmd2;
}
script INLINE @{cmds + "select sel"}
}
--
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
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users