Program: 16353
Project: 16353
Buggy source:
/** 
 * identify additional groups that are not directly attached to amino acids.
 * @param mc {@link ModifiedCompound}.
 * @param chain a {@link Chain}.
 * @return a list of added groups.
 */
private void identifyAdditionalAttachments(ModifiedCompound mc,List<Group> ligands,Map<String,Chain> mapChainIdChain){
  if (ligands.isEmpty()) {
    return;
  }
  List<Group> identifiedGroups=new ArrayList<Group>();
  for (  StructureGroup num : mc.getGroups(false)) {
    Group group;
    try {
      ResidueNumber resNum=new ResidueNumber();
      resNum.setChainId(num.getChainId());
      resNum.setSeqNum(num.getResidueNumber());
      resNum.setInsCode(num.getInsCode());
      group=mapChainIdChain.get(num.getChainId()).getGroupByPDB(resNum);
    }
 catch (    StructureException e) {
      logger.error("String_Node_Str",e);
      continue;
    }
    identifiedGroups.add(group);
  }
  int start=0;
  int n=identifiedGroups.size();
  while (n > start) {
    for (    Group group1 : ligands) {
      for (int i=start; i < n; i++) {
        Group group2=identifiedGroups.get(i);
        if (!identifiedGroups.contains(group1)) {
          List<Atom[]> linkedAtoms=StructureUtil.findAtomLinkages(group1,group2,false,bondLengthTolerance);
          if (!linkedAtoms.isEmpty()) {
            for (            Atom[] atoms : linkedAtoms) {
              mc.addAtomLinkage(StructureUtil.getStructureAtomLinkage(atoms[0],false,atoms[1],false));
            }
            identifiedGroups.add(group1);
            break;
          }
        }
      }
    }
    start=n;
    n=identifiedGroups.size();
  }
}

Fixed version (ground truth):
/** 
 * identify additional groups that are not directly attached to amino acids.
 * @param mc {@link ModifiedCompound}
 * @param ligands {@link Group}
 * @param chains List of {@link Chain}s
 * @return a list of added groups
 */
private void identifyAdditionalAttachments(ModifiedCompound mc,List<Group> ligands,List<Chain> chains){
  if (ligands.isEmpty()) {
    return;
  }
  List<Group> identifiedGroups=new ArrayList<Group>();
  for (  StructureGroup num : mc.getGroups(false)) {
    Group group;
    try {
      ResidueNumber resNum=new ResidueNumber();
      resNum.setChainId(num.getChainId());
      resNum.setSeqNum(num.getResidueNumber());
      resNum.setInsCode(num.getInsCode());
      group=getGroup(num,chains);
    }
 catch (    StructureException e) {
      logger.error("String_Node_Str",e);
      continue;
    }
    identifiedGroups.add(group);
  }
  int start=0;
  int n=identifiedGroups.size();
  while (n > start) {
    for (    Group group1 : ligands) {
      for (int i=start; i < n; i++) {
        Group group2=identifiedGroups.get(i);
        if (!identifiedGroups.contains(group1)) {
          List<Atom[]> linkedAtoms=StructureUtil.findAtomLinkages(group1,group2,false,bondLengthTolerance);
          if (!linkedAtoms.isEmpty()) {
            for (            Atom[] atoms : linkedAtoms) {
              mc.addAtomLinkage(StructureUtil.getStructureAtomLinkage(atoms[0],false,atoms[1],false));
            }
            identifiedGroups.add(group1);
            break;
          }
        }
      }
    }
    start=n;
    n=identifiedGroups.size();
  }
}