public void jmolColorByChain ( ) { String script = "function color_by_chain(objtype, color_list) {" + String . format ( "%n" ) + "" + String . format ( "%n" ) + " if (color_list) {" + String . format ( "%n" ) + " if (color_list.type == \"string\") {" + String . format ( "%n" ) + " color_list = color_list.split(\",\").trim();" + String . format ( "%n" ) + " }" + String . format ( "%n" ) + " } else {" + String . format ( "%n" ) + " color_list = [\"104BA9\",\"AA00A2\",\"C9F600\",\"FFA200\",\"284A7E\",\"7F207B\",\"9FB82E\",\"BF8B30\",\"052D6E\",\"6E0069\",\"83A000\",\"A66A00\",\"447BD4\",\"D435CD\",\"D8FA3F\",\"FFBA40\",\"6A93D4\",\"D460CF\",\"E1FA71\",\"FFCC73\"];" + String . format ( "%n" ) + " }" + String . format ( "%n" ) + " var cmd2 = \"\";" + String . format ( "%n" ) + " if (!objtype) {" + String . format ( "%n" ) + " var type_list = [ \"backbone\",\"cartoon\",\"dots\",\"halo\",\"label\",\"meshribbon\",\"polyhedra\",\"rocket\",\"star\",\"strand\",\"strut\",\"trace\"];" + String . format ( "%n" ) + " cmd2 = \"color \" + type_list.join(\" none; color \") + \" none;\";" + String . format ( "%n" ) + " objtype = \"atoms\";" + String . format ( "%n" ) + " }" + String . format ( "%n" ) + " var chain_list = script(\"show chain\").trim().lines;" + String . format ( "%n" ) + " var chain_count = chain_list.length;" + String . format ( "%n" ) + " var color_count = color_list.length;" + String . format ( "%n" ) + " var sel = {selected};" + String . format ( "%n" ) + " var cmds = \"\";" + String . format ( "%n" ) + " for (var chain_number=1; chain_number<=chain_count; chain_number++) {" + String . format ( "%n" ) + " // remember, Jmol arrays start with 1, but % can return 0" + String . format ( "%n" ) + " cmds += \"select sel and :\" + chain_list[chain_number] + \";color \" + objtype + \" [x\" + color_list[(chain_number-1) % color_count + 1] + \"];\" + cmd2;" + String . format ( "%n" ) + " }" + String . format ( "%n" ) + " script INLINE @{cmds + \"select sel\"}" + String . format ( "%n" ) + "}" ; executeCmd ( script ) ; }
assign a custom color to the Jmol chains command .