Program: 17053
Project: 17053
Buggy source:
/** 
 * Finds the optimal alignment between two proteins allowing for a circular permutation (CP). This algorithm performs a CE alignment for each possible CP site. This is quite slow. Use   {@link #alignHeuristic(Atom[],Atom[],Object)} for afaster algorithm.
 * @param ca1 CA atoms of the first protein
 * @param ca2 CA atoms of the second protein
 * @param param {@link CeParameters} object
 * @param alignments If not null, should be an empty array of the same length asca2. This will be filled with the alignments from permuting ca2 by  0 to n-1 residues.
 * @return The best-scoring alignment
 * @throws StructureException
 */
public AFPChain alignOptimal(Atom[] ca1,Atom[] ca2,Object param,AFPChain[] alignments) throws StructureException {
  long startTime=System.currentTimeMillis();
  if (alignments.length != ca2.length) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  Atom[] ca2p=StructureTools.cloneCAArray(ca2);
  AFPChain unaligned=super.align(ca1,ca2,param);
  AFPChain bestAlignment=unaligned;
  if (debug) {
    System.out.print("String_Node_Str");
  }
  if (alignments != null) {
    alignments[0]=unaligned;
  }
  for (int cp=1; cp < ca2.length; cp++) {
    AFPChain currentAlignment=alignPermuted(ca1,ca2p,param,1);
    if (debug)     System.out.print("String_Node_Str");
    try {
      currentAlignment.setName2(ca2[0].getGroup().getChain().getParent().getName() + "String_Node_Str" + cp);
    }
 catch (    Exception e) {
    }
    double currentScore=currentAlignment.getAlignScore();
    if (alignments != null) {
      alignments[cp]=currentAlignment;
    }
    if (currentScore > bestAlignment.getAlignScore()) {
      bestAlignment=currentAlignment;
    }
  }
  if (debug) {
    long elapsedTime=System.currentTimeMillis() - startTime;
    System.out.println();
    System.out.format("String_Node_Str",ca2.length,elapsedTime / 1000.,(double)elapsedTime / ca2.length);
  }
  return bestAlignment;
}

Fixed version (ground truth):
/** 
 * Finds the optimal alignment between two proteins allowing for a circular permutation (CP). This algorithm performs a CE alignment for each possible CP site. This is quite slow. Use   {@link #alignHeuristic(Atom[],Atom[],Object)} for afaster algorithm.
 * @param ca1 CA atoms of the first protein
 * @param ca2 CA atoms of the second protein
 * @param param {@link CeParameters} object
 * @param alignments If not null, should be an empty array of the same length asca2. This will be filled with the alignments from permuting ca2 by  0 to n-1 residues.
 * @return The best-scoring alignment
 * @throws StructureException
 */
public AFPChain alignOptimal(Atom[] ca1,Atom[] ca2,Object param,AFPChain[] alignments) throws StructureException {
  long startTime=System.currentTimeMillis();
  if (alignments.length != ca2.length) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  AFPChain unaligned=super.align(ca1,ca2,param);
  AFPChain bestAlignment=unaligned;
  if (debug) {
    System.out.print("String_Node_Str");
    for (int cp=1; cp < ca2.length - 1; cp++) {
      System.out.print("String_Node_Str");
    }
    System.out.println("String_Node_Str");
    System.out.print("String_Node_Str");
  }
  if (alignments != null) {
    alignments[0]=unaligned;
  }
  for (int cp=1; cp < ca2.length; cp++) {
    Atom[] ca2p=StructureTools.cloneCAArray(ca2);
    AFPChain currentAlignment=alignPermuted(ca1,ca2p,param,cp);
    if (debug)     System.out.print("String_Node_Str");
    try {
      currentAlignment.setName2(ca2[0].getGroup().getChain().getParent().getName() + "String_Node_Str" + cp);
    }
 catch (    Exception e) {
    }
    double currentScore=currentAlignment.getAlignScore();
    if (alignments != null) {
      alignments[cp]=currentAlignment;
    }
    if (currentScore > bestAlignment.getAlignScore()) {
      bestAlignment=currentAlignment;
    }
  }
  if (debug) {
    long elapsedTime=System.currentTimeMillis() - startTime;
    System.out.println();
    System.out.format("String_Node_Str",ca2.length,elapsedTime / 1000.,(double)elapsedTime / ca2.length);
  }
  return bestAlignment;
}