Program: 16661
Project: 16661
Buggy source:
/** 
 * Superimpose all structures in a MultipleAlignment to the reference structure. The superposition is done for all individual BlockSets. If there is only one BlockSet, the superposition is alse set in the  MultipleAlignment as the global superposition. <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 MultipleAlignment object to superimpose.
 */
@Override public void superimpose(MultipleAlignment alignment) throws StructureException {
  if (alignment.getEnsemble() == null)   throw new NullPointerException("String_Node_Str");
  List<Atom[]> atomArrays=alignment.getEnsemble().getAtomArrays();
  if (alignment.getBlockSets().size() < 1)   throw new IndexOutOfBoundsException("String_Node_Str");
  if (atomArrays.size() <= reference) {
    throw new IndexOutOfBoundsException(String.format("String_Node_Str",reference,atomArrays.size()));
  }
  alignment.clear();
  for (  BlockSet bs : alignment.getBlockSets()) {
    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 : bs.getBlocks()) {
        if (blk.size() != atomArrays.size()) {
          throw new IllegalStateException(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());
    }
    bs.setTransformations(transforms);
  }
  if (alignment.getBlockSets().size() == 1)   alignment.setTransformations(alignment.getBlockSets().get(0).getTransformations());
}

Fixed version (ground truth):
/** 
 * Superimpose all structures in a MultipleAlignment to the reference structure. The superposition is done for all individual BlockSets. If there is only one BlockSet, the superposition is alse set in the  MultipleAlignment as the global superposition. <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 MultipleAlignment object to superimpose.
 */
@Override public void superimpose(MultipleAlignment alignment) throws StructureException {
  if (alignment.getEnsemble() == null)   throw new NullPointerException("String_Node_Str");
  List<Atom[]> atomArrays=alignment.getEnsemble().getAtomArrays();
  if (alignment.getBlockSets().size() < 1)   throw new IndexOutOfBoundsException("String_Node_Str");
  if (atomArrays.size() <= reference) {
    throw new IndexOutOfBoundsException(String.format("String_Node_Str",reference,atomArrays.size()));
  }
  alignment.clear();
  for (  BlockSet bs : alignment.getBlockSets()) {
    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 : bs.getBlocks()) {
        if (blk.size() != atomArrays.size()) {
          throw new IllegalStateException(String.format("String_Node_Str",atomArrays.size(),blk.size()));
        }
        for (int j=0; j < blk.length(); j++) {
          Integer pos1=blk.getAlignRes().get(reference).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());
    }
    bs.setTransformations(transforms);
  }
  if (alignment.getBlockSets().size() == 1)   alignment.setTransformations(alignment.getBlockSets().get(0).getTransformations());
}