Program: 16591
Project: 16591
Buggy source:
/** 
 * Transforms atoms according to the superposition stored in the alignment. <p> For each structure in the alignment, returns an atom for each representative atom in the aligned columns, omitting unaligned residues (i.e. an array of length <tt>alignment.length()</tt> ). <p> All blocks are concatenated together, so Atoms may not appear in the same order as in their parent structure. If the alignment blocks contain null residues (gaps), then the returned array will also contain null Atoms in the same positions.
 * @param alignment MultipleAlignment
 * @return List of Atom arrays of only the aligned atoms of every structure(null Atom if a gap position)
 */
public static List<Atom[]> transformAtoms(MultipleAlignment alignment){
  if (alignment.getEnsemble() == null) {
    throw new NullPointerException("String_Node_Str");
  }
  List<Atom[]> atomArrays=alignment.getAtomArrays();
  List<Atom[]> transformed=new ArrayList<Atom[]>(atomArrays.size());
  for (int i=0; i < atomArrays.size(); i++) {
    Matrix4d transform=null;
    Atom[] curr=atomArrays.get(i);
    Atom[] transformedAtoms=new Atom[alignment.length()];
    int transformedAtomsLength=0;
    for (    BlockSet bs : alignment.getBlockSets()) {
      Atom[] blocksetAtoms=new Atom[bs.length()];
      for (      Block blk : bs.getBlocks()) {
        if (blk.size() != atomArrays.size()) {
          throw new IllegalStateException(String.format("String_Node_Str" + "String_Node_Str",atomArrays.size(),blk.size()));
        }
        for (int j=0; j < blk.length(); j++) {
          Integer alignedPos=blk.getAlignRes().get(i).get(j);
          if (alignedPos != null) {
            blocksetAtoms[j]=(Atom)curr[alignedPos].clone();
          }
        }
      }
      Matrix4d blockTrans=null;
      if (bs.getTransformations() != null)       blockTrans=bs.getTransformations().get(i);
      if (blockTrans == null) {
        blockTrans=transform;
      }
      for (      Atom a : blocksetAtoms) {
        if (a != null)         Calc.transform(a,blockTrans);
        transformedAtoms[transformedAtomsLength]=a;
        transformedAtomsLength++;
      }
    }
    assert(transformedAtomsLength == alignment.length());
    transformed.add(transformedAtoms);
  }
  return transformed;
}

Fixed version (ground truth):
/** 
 * Transforms atoms according to the superposition stored in the alignment. <p> For each structure in the alignment, returns an atom for each representative atom in the aligned columns, omitting unaligned residues (i.e. an array of length <tt>alignment.length()</tt> ). <p> All blocks are concatenated together, so Atoms may not appear in the same order as in their parent structure. If the alignment blocks contain null residues (gaps), then the returned array will also contain null Atoms in the same positions.
 * @param alignment MultipleAlignment
 * @return List of Atom arrays of only the aligned atoms of every structure(null Atom if a gap position)
 */
public static List<Atom[]> transformAtoms(MultipleAlignment alignment){
  if (alignment.getEnsemble() == null) {
    throw new NullPointerException("String_Node_Str");
  }
  List<Atom[]> atomArrays=alignment.getAtomArrays();
  List<Atom[]> transformed=new ArrayList<Atom[]>(atomArrays.size());
  for (int i=0; i < atomArrays.size(); i++) {
    Matrix4d transform=null;
    Atom[] curr=atomArrays.get(i);
    Atom[] transformedAtoms=new Atom[alignment.length()];
    int transformedAtomsLength=0;
    for (    BlockSet bs : alignment.getBlockSets()) {
      Atom[] blocksetAtoms=new Atom[bs.length()];
      int blockPos=0;
      for (      Block blk : bs.getBlocks()) {
        if (blk.size() != atomArrays.size()) {
          throw new IllegalStateException(String.format("String_Node_Str" + "String_Node_Str",atomArrays.size(),blk.size()));
        }
        for (int j=0; j < blk.length(); j++) {
          Integer alignedPos=blk.getAlignRes().get(i).get(j);
          if (alignedPos != null) {
            blocksetAtoms[blockPos]=(Atom)curr[alignedPos].clone();
          }
          blockPos++;
        }
      }
      Matrix4d blockTrans=null;
      if (bs.getTransformations() != null)       blockTrans=bs.getTransformations().get(i);
      if (blockTrans == null) {
        blockTrans=transform;
      }
      for (      Atom a : blocksetAtoms) {
        if (a != null)         Calc.transform(a,blockTrans);
        transformedAtoms[transformedAtomsLength]=a;
        transformedAtomsLength++;
      }
    }
    assert(transformedAtomsLength == alignment.length());
    transformed.add(transformedAtoms);
  }
  return transformed;
}