Program: 16726
Project: 16726
Buggy source:
/** 
 * Creates the seed of the multiple structure alignment, before optimization, from all-to-all pairwise alignments of the structures. The alignments are generated in parallel using the Java API for concurrency management.  The closest structure to all others is chosen as the reference and all the alignments to it are taken to generate  an ungapped seed MultipleAlignment. This method is static because can be used outside this alignment class.
 * @param atomArrays List of Atoms to align of the structures
 * @return MultipleAlignment seed alignment
 * @throws ExecutionException 
 * @throws InterruptedException 
 * @throws StructureException 
 * @throws StructureAlignmentException 
 */
public static MultipleAlignment generateSeed(List<Atom[]> atomArrays) throws InterruptedException, ExecutionException, StructureAlignmentException, StructureException {
  int size=atomArrays.size();
  List<List<AFPChain>> afpAlignments=new ArrayList<List<AFPChain>>();
  for (int i=0; i < size; i++) {
    afpAlignments.add(new ArrayList<AFPChain>());
    for (int j=0; j < size; j++)     afpAlignments.get(i).add(null);
  }
  ExecutorService executor=Executors.newCachedThreadPool();
  List<Future<AFPChain>> afpFuture=new ArrayList<Future<AFPChain>>();
  for (int i=0; i < size; i++) {
    for (int j=i + 1; j < size; j++) {
      Callable<AFPChain> worker=new ParallelAlignment(atomArrays.get(i),atomArrays.get(j),new CeMain());
      Future<AFPChain> submit=executor.submit(worker);
      afpFuture.add(submit);
    }
  }
  int index=0;
  for (int i=0; i < size; i++) {
    for (int j=i; j < size; j++) {
      if (i != j) {
        afpAlignments.get(i).add(j,afpFuture.get(index).get());
        afpAlignments.get(j).add(i,afpFuture.get(index).get());
        index++;
      }
    }
  }
  executor.shutdown();
  List<Double> RMSDs=new ArrayList<Double>();
  for (int i=0; i < size; i++) {
    double rmsd=0.0;
    for (int j=0; j < size; j++) {
      if (i != j)       rmsd+=afpAlignments.get(i).get(j).getTotalRmsdOpt();
    }
    RMSDs.add(rmsd);
  }
  int ref=0;
  for (int i=1; i < size; i++) {
    if (RMSDs.get(i) < RMSDs.get(ref))     ref=i;
  }
  return seedFromReference(afpAlignments.get(ref),atomArrays,ref);
}

Fixed version (ground truth):
/** 
 * Creates the seed of the multiple structure alignment, before optimization, from all-to-all pairwise alignments of the structures. The alignments are generated in parallel using the Java API for concurrency management.  The closest structure to all others is chosen as the reference and all the alignments to it are taken to generate  an ungapped seed MultipleAlignment. This method is static because can be used outside this alignment class.
 * @param atomArrays List of Atoms to align of the structures
 * @return MultipleAlignment seed alignment
 * @throws ExecutionException 
 * @throws InterruptedException 
 * @throws StructureException 
 * @throws StructureAlignmentException 
 */
public MultipleAlignment generateSeed(List<Atom[]> atomArrays) throws InterruptedException, ExecutionException, StructureAlignmentException, StructureException {
  int size=atomArrays.size();
  List<List<AFPChain>> afpAlignments=new ArrayList<List<AFPChain>>();
  for (int i=0; i < size; i++) {
    afpAlignments.add(new ArrayList<AFPChain>());
    for (int j=0; j < size; j++)     afpAlignments.get(i).add(null);
  }
  ExecutorService executor=Executors.newCachedThreadPool();
  List<Future<AFPChain>> afpFuture=new ArrayList<Future<AFPChain>>();
  for (int i=0; i < size; i++) {
    for (int j=i + 1; j < size; j++) {
      Callable<AFPChain> worker=new ParallelAlignment(atomArrays.get(i),atomArrays.get(j),new CeMain());
      Future<AFPChain> submit=executor.submit(worker);
      afpFuture.add(submit);
    }
  }
  int index=0;
  for (int i=0; i < size; i++) {
    for (int j=i; j < size; j++) {
      if (i != j) {
        afpAlignments.get(i).add(j,afpFuture.get(index).get());
        afpAlignments.get(j).add(i,afpFuture.get(index).get());
        index++;
      }
    }
  }
  executor.shutdown();
  List<Double> RMSDs=new ArrayList<Double>();
  for (int i=0; i < size; i++) {
    double rmsd=0.0;
    for (int j=0; j < size; j++) {
      if (i != j)       rmsd+=afpAlignments.get(i).get(j).getTotalRmsdOpt();
    }
    RMSDs.add(rmsd);
  }
  int ref=0;
  for (int i=1; i < size; i++) {
    if (RMSDs.get(i) < RMSDs.get(ref))     ref=i;
  }
  return seedFromReference(afpAlignments.get(ref),atomArrays,ref);
}