Program: 16325
Project: 16325
Buggy source:
/** 
 * Returns a Jmol script that colors subunits to highlight the symmetry within a structure Different subunits should have a consistent color scheme or different shade of the same colors
 * @return Jmol script
 */
@Override public String colorBySymmetry(){
  List<List<Integer>> units=helixAxisAligner.getHelixLayers().getByLargestContacts().getLayerLines();
  units=orientLayerLines(units);
  Subunits subunits=helixAxisAligner.getSubunits();
  List<Integer> modelNumbers=subunits.getModelNumbers();
  List<String> chainIds=subunits.getChainIds();
  List<Integer> clusterIds=subunits.getSequenceClusterIds();
  int clusterCount=Collections.max(clusterIds) + 1;
  Map<Color4f,List<String>> colorMap=new HashMap<Color4f,List<String>>();
  int maxLen=0;
  for (  List<Integer> unit : units) {
    maxLen=Math.max(maxLen,unit.size());
  }
  Color4f[] colors=getSymmetryColors(subunits.getSubunitCount());
  int count=0;
  for (int i=0; i < maxLen; i++) {
    for (int j=0; j < units.size(); j++) {
      int m=units.get(j).size();
      if (i < m) {
        int subunit=units.get(j).get(i);
        int cluster=clusterIds.get(subunit);
        float scale=0.3f + 0.7f * (cluster + 1) / clusterCount;
        Color4f c=new Color4f(colors[count]);
        count++;
        c.scale(scale);
        List<String> ids=colorMap.get(c);
        if (ids == null) {
          ids=new ArrayList<String>();
          colorMap.put(c,ids);
        }
        String id=getChainSpecification(modelNumbers,chainIds,subunit);
        ids.add(id);
      }
    }
  }
  String coloring=defaultColoring + getJmolColorScript(colorMap);
  return coloring;
}

Fixed version (ground truth):
/** 
 * Returns a Jmol script that colors subunits to highlight the symmetry within a structure Different subunits should have a consistent color scheme or different shade of the same colors
 * @return Jmol script
 */
@Override public String colorBySymmetry(){
  List<List<Integer>> units=helixAxisAligner.getHelixLayers().getByLargestContacts().getLayerLines();
  units=orientLayerLines(units);
  QuatSymmetrySubunits subunits=helixAxisAligner.getSubunits();
  List<Integer> modelNumbers=subunits.getModelNumbers();
  List<String> chainIds=subunits.getChainIds();
  List<Integer> clusterIds=subunits.getSequenceClusterIds();
  int clusterCount=Collections.max(clusterIds) + 1;
  Map<Color4f,List<String>> colorMap=new HashMap<Color4f,List<String>>();
  int maxLen=0;
  for (  List<Integer> unit : units) {
    maxLen=Math.max(maxLen,unit.size());
  }
  Color4f[] colors=getSymmetryColors(subunits.getSubunitCount());
  int count=0;
  for (int i=0; i < maxLen; i++) {
    for (int j=0; j < units.size(); j++) {
      int m=units.get(j).size();
      if (i < m) {
        int subunit=units.get(j).get(i);
        int cluster=clusterIds.get(subunit);
        float scale=0.3f + 0.7f * (cluster + 1) / clusterCount;
        Color4f c=new Color4f(colors[count]);
        count++;
        c.scale(scale);
        List<String> ids=colorMap.get(c);
        if (ids == null) {
          ids=new ArrayList<String>();
          colorMap.put(c,ids);
        }
        String id=getChainSpecification(modelNumbers,chainIds,subunit);
        ids.add(id);
      }
    }
  }
  String coloring=defaultColoring + getJmolColorScript(colorMap);
  return coloring;
}