Program: 16275
Project: 16275
Buggy source:
/** 
 * Two nonoverlapping stretches of three residues each, i-1,i,i+1 and j-1,j,j+1, form either a parallel or antiparallel bridge, depending on which of two basic patterns is matched. We assign a bridge between residues i and j if there are two H bonds characteristic of beta- structure; in particular: <p> Parallel Bridge(i,j) =: [Hbond(i-1,j) and Hbond(j,i+1)] or [Hbond(j-1,i) and Hbond(i,j+1)] <p> Antiparallel Bridge(i,j) =: [Hbond(i,j) and Hbond(j,i)] or [Hbond(i-1,j+1) and Hbond(j-1,i+1)] Optimised to use the contact set
 */
private void findBridges(){
  Iterator<AtomContact> myIter=contactSet.iterator();
  List<Pair<Integer>> outList=new ArrayList<Pair<Integer>>();
  while (myIter.hasNext()) {
    AtomContact ac=myIter.next();
    Group g1=ac.getPair().getFirst().getGroup();
    Group g2=ac.getPair().getSecond().getGroup();
    int i=indResMap.get(g1.getResidueNumber().getChainName() + g1.getResidueNumber().getSeqNum());
    int j=indResMap.get(g2.getResidueNumber().getChainName() + g2.getResidueNumber().getSeqNum());
    if (i > j) {
      int old=i;
      i=j;
      j=old;
    }
    if (j < i + 3) {
      continue;
    }
    if (i == 0) {
      continue;
    }
    if (j == 0) {
      continue;
    }
    if (i == groups.length - 1) {
      continue;
    }
    if (j == groups.length - 1) {
      continue;
    }
    Pair<Integer> thisPair=new Pair<Integer>(i,j);
    outList.add(thisPair);
  }
  Collections.sort(outList,new Comparator<Pair<Integer>>(){
    @Override public int compare(    Pair<Integer> o1,    Pair<Integer> o2){
      if (o1.getFirst() < o2.getFirst()) {
        return -1;
      }
 else       if (o1.getFirst() > o2.getFirst()) {
        return +1;
      }
 else {
        if (o1.getSecond() < o2.getSecond()) {
          return -1;
        }
 else         if (o1.getSecond() > o2.getSecond()) {
          return 1;
        }
 else {
          return 0;
        }
      }
    }
  }
);
  for (  Pair<Integer> p : outList) {
    int i=p.getFirst();
    int j=p.getSecond();
    BridgeType btype=null;
    if ((isBonded(i - 1,j) && isBonded(j,i + 1)) || (isBonded(j - 1,i) && isBonded(i,j + 1))) {
      btype=BridgeType.parallel;
    }
 else     if ((isBonded(i,j) && isBonded(j,i)) || (isBonded(i - 1,j + 1) && (isBonded(j - 1,i + 1)))) {
      btype=BridgeType.antiparallel;
    }
    if (btype != null) {
      registerBridge(i,j,btype);
    }
  }
}

Fixed version (ground truth):
/** 
 * Two nonoverlapping stretches of three residues each, i-1,i,i+1 and j-1,j,j+1, form either a parallel or antiparallel bridge, depending on which of two basic patterns is matched. We assign a bridge between residues i and j if there are two H bonds characteristic of beta- structure; in particular: <p> Parallel Bridge(i,j) =: [Hbond(i-1,j) and Hbond(j,i+1)] or [Hbond(j-1,i) and Hbond(i,j+1)] <p> Antiparallel Bridge(i,j) =: [Hbond(i,j) and Hbond(j,i)] or [Hbond(i-1,j+1) and Hbond(j-1,i+1)] Optimised to use the contact set
 */
private void findBridges(){
  Iterator<AtomContact> myIter=contactSet.iterator();
  List<Pair<Integer>> outList=new ArrayList<Pair<Integer>>();
  while (myIter.hasNext()) {
    AtomContact ac=myIter.next();
    Group g1=ac.getPair().getFirst().getGroup();
    Group g2=ac.getPair().getSecond().getGroup();
    int i=indResMap.get(g1.getResidueNumber());
    int j=indResMap.get(g2.getResidueNumber());
    if (i > j) {
      int old=i;
      i=j;
      j=old;
    }
    if (j < i + 3) {
      continue;
    }
    if (i == 0) {
      continue;
    }
    if (j == 0) {
      continue;
    }
    if (i == groups.length - 1) {
      continue;
    }
    if (j == groups.length - 1) {
      continue;
    }
    Pair<Integer> thisPair=new Pair<Integer>(i,j);
    outList.add(thisPair);
  }
  Collections.sort(outList,new Comparator<Pair<Integer>>(){
    @Override public int compare(    Pair<Integer> o1,    Pair<Integer> o2){
      if (o1.getFirst() < o2.getFirst()) {
        return -1;
      }
 else       if (o1.getFirst() > o2.getFirst()) {
        return +1;
      }
 else {
        if (o1.getSecond() < o2.getSecond()) {
          return -1;
        }
 else         if (o1.getSecond() > o2.getSecond()) {
          return 1;
        }
 else {
          return 0;
        }
      }
    }
  }
);
  for (  Pair<Integer> p : outList) {
    int i=p.getFirst();
    int j=p.getSecond();
    BridgeType btype=null;
    if ((isBonded(i - 1,j) && isBonded(j,i + 1)) || (isBonded(j - 1,i) && isBonded(i,j + 1))) {
      btype=BridgeType.parallel;
    }
 else     if ((isBonded(i,j) && isBonded(j,i)) || (isBonded(i - 1,j + 1) && (isBonded(j - 1,i + 1)))) {
      btype=BridgeType.antiparallel;
    }
    if (btype != null) {
      registerBridge(i,j,btype);
    }
  }
}