+ Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap = buildColoursMap(
+ ssm, files, sequence, sr, fr, alignment);
+
+ List<String> colourCommands = buildColourCommands(colourMap);
+
+ StructureMappingcommandSet cs = new StructureMappingcommandSet(
+ ChimeraCommands.class, null,
+ colourCommands.toArray(new String[0]));
+
+ return new StructureMappingcommandSet[]
+ { cs };
+ }
+
+ /**
+ * Traverse the map of colours/models/chains/positions to construct a list of
+ * 'color' commands (one per distinct colour used). The format of each command
+ * is
+ *
+ * <blockquote> color colorname #modelnumber:range.chain e.g. color #00ff00
+ * #0:2.B,4.B,9-12.B|#1:1.A,2-6.A,...
+ *
+ * @see http
+ * ://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/frameatom_spec
+ * .html </pre>
+ *
+ * @param colourMap
+ * @return
+ */
+ protected static List<String> buildColourCommands(
+ Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap)
+ {
+ /*
+ * This version concatenates all commands into a single String (semi-colon
+ * delimited). If length limit issues arise, refactor to return one color
+ * command per colour.
+ */
+ List<String> commands = new ArrayList<String>();
+ StringBuilder sb = new StringBuilder(256);
+ boolean firstColour = true;
+ for (Color colour : colourMap.keySet())
+ {
+ String colourCode = ColorUtils.toTkCode(colour);
+ if (!firstColour)
+ {
+ sb.append("; ");
+ }
+ sb.append("color ").append(colourCode).append(" ");
+ firstColour = false;
+ boolean firstModelForColour = true;
+ final Map<Integer, Map<String, List<int[]>>> colourData = colourMap.get(colour);
+ for (Integer model : colourData.keySet())
+ {
+ boolean firstPositionForModel = true;
+ if (!firstModelForColour)
+ {
+ sb.append("|");
+ }
+ firstModelForColour = false;
+ sb.append("#").append(model).append(":");