Program: 16377
Project: 16377
Buggy source:
/** 
 * Method that converts a symmetry alignment into an alignment of the repeats 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 repeats in Jmol.
 * @param result CeSymmResult of symmetry
 * @return MultipleAlignment of the repeats
 * @throws StructureException
 */
public static MultipleAlignment toRepeatsAlignment(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.getRepeatsID());
  List<Atom[]> atomArrays=new ArrayList<Atom[]>();
  Structure divided=SymmetryTools.getQuaternaryStructure(result);
  MultipleAlignment repeats=newEnsemble.getMultipleAlignment(0);
  Block block=repeats.getBlock(0);
  for (int i=0; i < result.getMultipleAlignment().size(); i++) {
    Structure newStr=new StructureImpl();
    Chain newCh=divided.getChain(i);
    newStr.addChain(newCh);
    Atom[] repeat=StructureTools.getRepresentativeAtomArray(newCh);
    atomArrays.add(repeat);
  }
  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 repeats;
}

Fixed version (ground truth):
/** 
 * Method that converts a symmetry alignment into an alignment of the repeats 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 repeats in Jmol.
 * @param result CeSymmResult of symmetry
 * @return MultipleAlignment of the repeats
 * @throws StructureException
 */
public static MultipleAlignment toRepeatsAlignment(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();
  List<Atom[]> atomArrays=new ArrayList<Atom[]>();
  Structure divided=SymmetryTools.getQuaternaryStructure(result);
  MultipleAlignment repeats=newEnsemble.getMultipleAlignment(0);
  Block block=repeats.getBlock(0);
  for (int i=0; i < result.getMultipleAlignment().size(); i++) {
    Structure newStr=new StructureImpl();
    Chain newCh=divided.getChain(i);
    newStr.addChain(newCh);
    Atom[] repeat=StructureTools.getRepresentativeAtomArray(newCh);
    atomArrays.add(repeat);
  }
  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 repeats;
}