- try
- {
- lastColour = buildColourCommands(cset, colranges,
- fos, setAttributes);
- } catch (IOException e)
- {
- e.printStackTrace();
- }
-
- try
- {
- fos.close();
- } catch (IOException e)
- {
- e.printStackTrace();
- }
-
- /*
- * Send a rangeColor command, preceded by either defattr or setattr,
- * whichever we end up preferring!
- *
- * rangecolor requires a minimum of two attribute values to operate on
- */
- StringBuilder rangeColor = new StringBuilder(256);
- rangeColor.append("rangecolor jalviewclr");
- int colourId = 0;
- for (String colour : colranges.keySet())
- {
- colourId++;
- rangeColor.append(" " + colourId + " " + colour);
- }
- String rangeColorCommand = rangeColor.toString();
- if (rangeColorCommand.split(" ").length < 5)
- {
- rangeColorCommand += " max " + lastColour;
- }
- final String defAttrCommand = "defattr " + defAttrPath
- + " raiseTool false";
- final String setAttrCommand = setAttributes.toString();
- final String attrCommand = false ? defAttrCommand : setAttrCommand;
- cset.add(new StructureMappingcommandSet(ChimeraCommands.class, null,
- new String[]
- { attrCommand /* , rangeColorCommand */}));
-
- return cset.toArray(new StructureMappingcommandSet[cset.size()]);
- }
-
- /**
- * Get the residue colour at the given sequence position - as determined by
- * the sequence group colour (if any), else the colour scheme, possibly
- * overridden by a feature colour.
- *
- * @param seq
- * @param position
- * @param sr
- * @param fr
- * @return
- */
- protected static Color getResidueColour(final SequenceI seq,
- int position, SequenceRenderer sr, FeatureRenderer fr)
- {
- Color col = sr.getResidueBoxColour(seq, position);
-
- if (fr != null)
- {
- col = fr.findFeatureColour(col, seq, position);
- }
- return col;
- }
-
- /**
- * Helper method to build the colour commands for one PDBfile.
- *
- * @param cset
- * the list of commands to be added to
- * @param colranges
- * the map of colours to residue positions already determined
- * @param fos
- * file to write 'defattr' commands to
- * @param setAttributes
- * @throws IOException
- */
- protected static String buildColourCommands(
- List<StructureMappingcommandSet> cset,
- Map<String, StringBuilder> colranges,
- FileOutputStream fos, StringBuilder setAttributes)
- throws IOException
- {
- int colourId = 0;
- String lastColour = null;
- for (String colour : colranges.keySet())
- {
- lastColour = colour;
- colourId++;
- /*
- * Using color command directly is slow for larger structures.
- * setAttributes.append("color #" + colour + " " + colranges.get(colour)+
- * ";");
- */
- setAttributes.append("color " + colour + " " + colranges.get(colour)
- + ";");
- final String atomSpec = new String(colranges.get(colour));
- // setAttributes.append("setattr r jalviewclr " + colourId + " "
- // + atomSpec + ";");
- fos.write(("\t" + atomSpec + "\t" + colourId + "\n").getBytes());
- }
- return lastColour;