Program: 16689
Project: 16689
Buggy source:
/** 
 * Superimpose all structures in a BlockSet to the reference structure
 * @param alignment The MultipleAlignment object to superimpose.
 * @throws StructureAlignmentException 
 */
@Override public void superimpose(MultipleAlignment alignment) throws StructureException, StructureAlignmentException {
  if (alignment.getEnsemble() == null) {
    throw new NullPointerException("String_Node_Str");
  }
  List<Atom[]> atomArrays=alignment.getEnsemble().getAtomArrays();
  List<Block> blocks=alignment.getBlocks();
  if (blocks.size() < 1)   throw new StructureAlignmentException("String_Node_Str");
  if (reference < 0 || atomArrays.size() <= reference) {
    throw new IndexOutOfBoundsException(String.format("String_Node_Str",reference,atomArrays.size()));
  }
  List<Matrix4d> transforms=new ArrayList<Matrix4d>(atomArrays.size());
  double totalDistanceSq=0;
  double totalLength=0;
  double totalTM=0;
  for (int i=0; i < atomArrays.size(); i++) {
    if (i == reference) {
      Matrix4d ident=new Matrix4d();
      ident.setIdentity();
      transforms.add(ident);
      continue;
    }
    Atom[] ref=atomArrays.get(reference);
    Atom[] curr=atomArrays.get(i);
    List<Atom> atomSet1=new ArrayList<Atom>();
    List<Atom> atomSet2=new ArrayList<Atom>();
    for (    Block blk : blocks) {
      if (blk.size() != atomArrays.size()) {
        throw new StructureAlignmentException(String.format("String_Node_Str",atomArrays.size(),blk.size()));
      }
      for (int j=0; j < blk.length(); j++) {
        Integer pos1=blk.getAlignRes().get(0).get(j);
        Integer pos2=blk.getAlignRes().get(i).get(j);
        if (pos1 == null || pos2 == null)         continue;
        atomSet1.add(ref[pos1]);
        atomSet2.add(curr[pos2]);
      }
    }
    Atom[] array1=atomSet1.toArray(new Atom[atomSet1.size()]);
    Atom[] array2=atomSet2.toArray(new Atom[atomSet2.size()]);
    array2=StructureTools.cloneAtomArray(array2);
    SVDSuperimposer svd=new SVDSuperimposer(array1,array2);
    transforms.add(svd.getTransformation());
    double rmsd=SVDSuperimposer.getRMS(array1,array2);
    totalDistanceSq+=rmsd * rmsd * array1.length;
    totalLength+=array1.length;
    totalTM+=SVDSuperimposer.getTMScore(array1,array2,ref.length,curr.length);
  }
  alignment.setTransformations(transforms);
  for (  BlockSet bs : alignment.getBlockSets()) {
    bs.setTransformations(null);
  }
  alignment.putScore("String_Node_Str",totalDistanceSq / totalLength);
  alignment.putScore("String_Node_Str",totalTM / atomArrays.size());
}

Fixed version (ground truth):
/** 
 * Superimpose all structures in a MultipleAlignment to the reference structure. <p> This method only calculates and sets the transformation 4D matrices. If any score is needed it should be calculated and set separately afterwards with   {@link MultipleAlignmentScorer}.
 * @param alignment The MultipleAlignment object to superimpose.
 * @throws StructureAlignmentException 
 */
@Override public void superimpose(MultipleAlignment alignment) throws StructureException, StructureAlignmentException {
  if (alignment.getEnsemble() == null) {
    throw new NullPointerException("String_Node_Str");
  }
  List<Atom[]> atomArrays=alignment.getEnsemble().getAtomArrays();
  List<Block> blocks=alignment.getBlocks();
  if (blocks.size() < 1)   throw new StructureAlignmentException("String_Node_Str");
  if (reference < 0 || atomArrays.size() <= reference) {
    throw new IndexOutOfBoundsException(String.format("String_Node_Str",reference,atomArrays.size()));
  }
  List<Matrix4d> transforms=new ArrayList<Matrix4d>(atomArrays.size());
  for (int i=0; i < atomArrays.size(); i++) {
    if (i == reference) {
      Matrix4d ident=new Matrix4d();
      ident.setIdentity();
      transforms.add(ident);
      continue;
    }
    Atom[] ref=atomArrays.get(reference);
    Atom[] curr=atomArrays.get(i);
    List<Atom> atomSet1=new ArrayList<Atom>();
    List<Atom> atomSet2=new ArrayList<Atom>();
    for (    Block blk : blocks) {
      if (blk.size() != atomArrays.size()) {
        throw new StructureAlignmentException(String.format("String_Node_Str",atomArrays.size(),blk.size()));
      }
      for (int j=0; j < blk.length(); j++) {
        Integer pos1=blk.getAlignRes().get(0).get(j);
        Integer pos2=blk.getAlignRes().get(i).get(j);
        if (pos1 == null || pos2 == null)         continue;
        atomSet1.add(ref[pos1]);
        atomSet2.add(curr[pos2]);
      }
    }
    Atom[] array1=atomSet1.toArray(new Atom[atomSet1.size()]);
    Atom[] array2=atomSet2.toArray(new Atom[atomSet2.size()]);
    array2=StructureTools.cloneAtomArray(array2);
    SVDSuperimposer svd=new SVDSuperimposer(array1,array2);
    Calc.transform(array2,svd.getTransformation());
    transforms.add(svd.getTransformation());
  }
  alignment.setTransformations(transforms);
  for (  BlockSet bs : alignment.getBlockSets()) {
    bs.setTransformations(null);
  }
}