Program: 16556
Project: 16556
Buggy source:
/** 
 * Method that converts a symmetry alignment into an alignment of the subunits only, as new independent structures. <p> This method changes the structure identifiers, the Atom arrays and re-scles the aligned residues in the Blocks corresponding to those changes. <p> Application: display superimposed subunits in Jmol.
 * @param result CeSymmResult of symmetry
 * @return MultipleAlignment of the subunits
 * @throws StructureException
 */
public static MultipleAlignment toSubunitAlignment(CeSymmResult result) throws StructureException {
  if (!result.isRefined())   throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str");
  MultipleAlignment msa=result.getMultipleAlignment();
  MultipleAlignmentEnsemble newEnsemble=msa.getEnsemble().clone();
  newEnsemble.setStructureIdentifiers(result.getProtodomains());
  List<Atom[]> atomArrays=new ArrayList<Atom[]>();
  Structure divided=SymmetryTools.getQuaternaryStructure(result);
  MultipleAlignment subunits=newEnsemble.getMultipleAlignment(0);
  Block block=subunits.getBlock(0);
  for (int i=0; i < result.getMultipleAlignment().size(); i++) {
    Structure newStr=new StructureImpl();
    Chain newCh=divided.getChain(i);
    newStr.addChain(newCh);
    Atom[] subunit=StructureTools.getRepresentativeAtomArray(newCh);
    atomArrays.add(subunit);
  }
  newEnsemble.setAtomArrays(atomArrays);
  for (int su=0; su < block.size(); su++) {
    int count=0;
    Integer start=null;
    while (start == null && count < block.length()) {
      start=block.getAlignRes().get(su).get(0 + count);
      count++;
    }
    for (int res=0; res < block.length(); res++) {
      Integer residue=block.getAlignRes().get(su).get(res);
      if (residue != null)       residue-=start;
      block.getAlignRes().get(su).set(res,residue);
    }
  }
  return subunits;
}

Fixed version (ground truth):
/** 
 * Method that converts a symmetry alignment into an alignment of the subunits only, as new independent structures. <p> This method changes the structure identifiers, the Atom arrays and re-scles the aligned residues in the Blocks corresponding to those changes. <p> Application: display superimposed subunits in Jmol.
 * @param result CeSymmResult of symmetry
 * @return MultipleAlignment of the subunits
 * @throws StructureException
 */
public static MultipleAlignment toSubunitAlignment(CeSymmResult result) throws StructureException {
  if (!result.isRefined())   throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str");
  MultipleAlignment msa=result.getMultipleAlignment();
  MultipleAlignmentEnsemble newEnsemble=msa.getEnsemble().clone();
  newEnsemble.setStructureIdentifiers(result.getProtodomains());
  List<Atom[]> atomArrays=new ArrayList<Atom[]>();
  Structure divided=SymmetryTools.getQuaternaryStructure(result);
  MultipleAlignment subunits=newEnsemble.getMultipleAlignment(0);
  Block block=subunits.getBlock(0);
  for (int i=0; i < result.getMultipleAlignment().size(); i++) {
    Structure newStr=new StructureImpl();
    Chain newCh=divided.getChain(i);
    newStr.addChain(newCh);
    Atom[] subunit=StructureTools.getRepresentativeAtomArray(newCh);
    atomArrays.add(subunit);
  }
  newEnsemble.setAtomArrays(atomArrays);
  for (int su=0; su < block.size(); su++) {
    Integer start=block.getStartResidue(su);
    for (int res=0; res < block.length(); res++) {
      Integer residue=block.getAlignRes().get(su).get(res);
      if (residue != null)       residue-=start;
      block.getAlignRes().get(su).set(res,residue);
    }
  }
  return subunits;
}