Program: 17097
Project: 17097
Buggy source:
/** 
 * Record unidentifiable atom linkages in a chain. Only linkages between two residues or one residue and one ligand will be recorded.
 */
private void recordUnidentifiableAtomLinkages(List<ModifiedCompound> modComps,List<Group> residues,List<Group> ligands){
  Set<StructureAtomLinkage> identifiedLinkages=new HashSet<StructureAtomLinkage>();
  for (  ModifiedCompound mc : modComps) {
    identifiedLinkages.addAll(mc.getAtomLinkages());
  }
  int nRes=residues.size();
  for (int i=0; i < nRes - 1; i++) {
    Group group1=residues.get(i);
    for (int j=i + 1; j < nRes; j++) {
      Group group2=residues.get(j);
      List<Atom[]> linkages=StructureUtil.findNonNCAtomLinkages(group1,true,group2,true,bondLengthTolerance);
      for (      Atom[] atoms : linkages) {
        StructureAtomLinkage link=StructureUtil.getStructureAtomLinkage(atoms[0],ComponentType.LIGAND,atoms[1],ComponentType.LIGAND);
        if (!identifiedLinkages.contains(link)) {
          unidentifiableAtomLinkages.add(link);
        }
      }
    }
  }
  int nLig=ligands.size();
  for (int i=0; i < nRes; i++) {
    Group group1=residues.get(i);
    for (int j=0; j < nLig; j++) {
      Group group2=ligands.get(j);
      if (group1 == group2) {
        continue;
      }
      List<Atom[]> linkages=StructureUtil.findNonNCAtomLinkages(group1,true,group2,false,bondLengthTolerance);
      for (      Atom[] atoms : linkages) {
        StructureAtomLinkage link=StructureUtil.getStructureAtomLinkage(atoms[0],ComponentType.LIGAND,atoms[1],ComponentType.LIGAND);
        if (!identifiedLinkages.contains(link)) {
          unidentifiableAtomLinkages.add(link);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Record unidentifiable atom linkages in a chain. Only linkages between two residues or one residue and one ligand will be recorded.
 */
private void recordUnidentifiableAtomLinkages(List<ModifiedCompound> modComps,List<Group> residues,List<Group> ligands){
  Set<StructureAtomLinkage> identifiedLinkages=new HashSet<StructureAtomLinkage>();
  for (  ModifiedCompound mc : modComps) {
    identifiedLinkages.addAll(mc.getAtomLinkages());
  }
  int nRes=residues.size();
  for (int i=0; i < nRes - 1; i++) {
    Group group1=residues.get(i);
    for (int j=i + 1; j < nRes; j++) {
      Group group2=residues.get(j);
      List<Atom[]> linkages=StructureUtil.findNonNCAtomLinkages(group1,true,group2,true,bondLengthTolerance);
      for (      Atom[] atoms : linkages) {
        StructureAtomLinkage link=StructureUtil.getStructureAtomLinkage(atoms[0],ComponentType.AMINOACID,atoms[1],ComponentType.AMINOACID);
        if (!identifiedLinkages.contains(link)) {
          unidentifiableAtomLinkages.add(link);
        }
      }
    }
  }
  int nLig=ligands.size();
  for (int i=0; i < nRes; i++) {
    Group group1=residues.get(i);
    for (int j=0; j < nLig; j++) {
      Group group2=ligands.get(j);
      if (group1 == group2) {
        continue;
      }
      List<Atom[]> linkages=StructureUtil.findNonNCAtomLinkages(group1,true,group2,false,bondLengthTolerance);
      for (      Atom[] atoms : linkages) {
        StructureAtomLinkage link=StructureUtil.getStructureAtomLinkage(atoms[0],ComponentType.AMINOACID,atoms[1],ComponentType.LIGAND);
        if (!identifiedLinkages.contains(link)) {
          unidentifiableAtomLinkages.add(link);
        }
      }
    }
  }
}