Program: 16521
Project: 16521
Buggy source:
/** 
 * Generates a ProteinSequence corresponding to the sequence of struct, and maintains a mapping from the sequence back to the original groups. Chains are appended to one another. 'X' is used for heteroatoms.
 * @param struct Input structure
 * @param groupIndexPosition An empty map, which will be populated with(residue index in returned ProteinSequence) -> (Group within struct)
 * @return A ProteinSequence with the full sequence of struct. Chains areconcatenated in the same order as the input structures
 * @see {@link SeqRes2AtomAligner#getFullAtomSequence(List,Map)}, which does the heavy lifting.
 */
public static ProteinSequence getProteinSequenceForStructure(Structure struct,Map<Integer,Group> groupIndexPosition){
  if (groupIndexPosition != null) {
    groupIndexPosition.clear();
  }
  StringBuilder seqStr=new StringBuilder();
  for (  Chain chain : struct.getChains()) {
    List<Group> groups=chain.getAtomGroups();
    Map<Integer,Integer> chainIndexPosition=new HashMap<Integer,Integer>();
    int prevLen=seqStr.length();
    String chainSeq=SeqRes2AtomAligner.getFullAtomSequence(groups,chainIndexPosition);
    seqStr.append(chainSeq);
    for (    Integer seqIndex : chainIndexPosition.keySet()) {
      Integer groupIndex=chainIndexPosition.get(seqIndex);
      groupIndexPosition.put(prevLen + seqIndex,groups.get(groupIndex));
    }
  }
  ProteinSequence s=null;
  try {
    s=new ProteinSequence(seqStr.toString());
  }
 catch (  CompoundNotFoundException e) {
    logger.error("String_Node_Str",e.getMessage());
  }
  return s;
}

Fixed version (ground truth):
/** 
 * Generates a ProteinSequence corresponding to the sequence of struct, and maintains a mapping from the sequence back to the original groups. Chains are appended to one another. 'X' is used for heteroatoms.
 * @param struct Input structure
 * @param groupIndexPosition An empty map, which will be populated with(residue index in returned ProteinSequence) -> (Group within struct)
 * @return A ProteinSequence with the full sequence of struct. Chains areconcatenated in the same order as the input structures
 * @see {@link SeqRes2AtomAligner#getFullAtomSequence(List,Map)}, which does the heavy lifting.
 */
public static ProteinSequence getProteinSequenceForStructure(Structure struct,Map<Integer,Group> groupIndexPosition){
  if (groupIndexPosition != null) {
    groupIndexPosition.clear();
  }
  StringBuilder seqStr=new StringBuilder();
  for (  Chain chain : struct.getChains()) {
    List<Group> groups=chain.getAtomGroups();
    Map<Integer,Integer> chainIndexPosition=new HashMap<Integer,Integer>();
    int prevLen=seqStr.length();
    String chainSeq=SeqRes2AtomAligner.getFullAtomSequence(groups,chainIndexPosition,false);
    seqStr.append(chainSeq);
    for (    Integer seqIndex : chainIndexPosition.keySet()) {
      Integer groupIndex=chainIndexPosition.get(seqIndex);
      groupIndexPosition.put(prevLen + seqIndex,groups.get(groupIndex));
    }
  }
  ProteinSequence s=null;
  try {
    s=new ProteinSequence(seqStr.toString());
  }
 catch (  CompoundNotFoundException e) {
    logger.error("String_Node_Str",e.getMessage());
  }
  return s;
}