Program: 17130
Project: 17130
Buggy source:
/** 
 * Rotate the Atoms/Groups so they are aligned for the 3D visualisation
 * @param afpChain
 * @param ca1
 * @param ca2
 * @return
 * @throws StructureException
 */
public static Group[] prepareGroupsForDisplay(AFPChain afpChain,Atom[] ca1,Atom[] ca2) throws StructureException {
  if (afpChain.getBlockRotationMatrix().length == 0) {
    throw new StructureException("String_Node_Str");
  }
  Group[] twistedGroups=new Group[ca2.length];
  int blockNum=afpChain.getBlockNum();
  int i=-1;
  List<Group> hetatms2=new ArrayList<Group>();
  List<Group> nucs2=new ArrayList<Group>();
  Group g2=ca2[0].getParent();
  Chain c2=null;
  if (g2 != null) {
    c2=g2.getParent();
    if (c2 != null) {
      hetatms2=c2.getAtomGroups("String_Node_Str");
      nucs2=c2.getAtomGroups("String_Node_Str");
    }
  }
  if ((afpChain.getAlgorithmName().equals(FatCatRigid.algorithmName)) || (afpChain.getAlgorithmName().equals(FatCatFlexible.algorithmName))) {
    for (    Atom a : ca2) {
      i++;
      twistedGroups[i]=a.getParent();
    }
    twistedGroups=AFPTwister.twistOptimized(afpChain,ca1,ca2);
  }
 else {
    Matrix m=afpChain.getBlockRotationMatrix()[0];
    Atom shift=afpChain.getBlockShiftVector()[0];
    shiftCA2(afpChain,ca2,hetatms2,nucs2,m,shift,twistedGroups);
  }
  if (afpChain.getBlockNum() > 0) {
    if ((hetatms2.size() > 0) || (nucs2.size() > 0)) {
      if (afpChain.getBlockRotationMatrix().length > 0) {
        Matrix m1=afpChain.getBlockRotationMatrix()[0];
        Atom vector1=afpChain.getBlockShiftVector()[0];
        for (        Group g : hetatms2) {
          Calc.rotate(g,m1);
          Calc.shift(g,vector1);
        }
        for (        Group g : nucs2) {
          Calc.rotate(g,m1);
          Calc.shift(g,vector1);
        }
      }
    }
  }
  return twistedGroups;
}

Fixed version (ground truth):
/** 
 * Rotate the Atoms/Groups so they are aligned for the 3D visualisation
 * @param afpChain
 * @param ca1
 * @param ca2
 * @return
 * @throws StructureException
 */
public static Group[] prepareGroupsForDisplay(AFPChain afpChain,Atom[] ca1,Atom[] ca2) throws StructureException {
  if (afpChain.getBlockRotationMatrix().length == 0) {
    System.err.println("String_Node_Str");
    afpChain.setBlockRotationMatrix(new Matrix[]{Matrix.identity(3,3)});
    afpChain.setBlockShiftVector(new Atom[]{new AtomImpl()});
  }
  Group[] twistedGroups=new Group[ca2.length];
  int i=-1;
  List<Group> hetatms2=new ArrayList<Group>();
  List<Group> nucs2=new ArrayList<Group>();
  Group g2=ca2[0].getParent();
  Chain c2=null;
  if (g2 != null) {
    c2=g2.getParent();
    if (c2 != null) {
      hetatms2=c2.getAtomGroups("String_Node_Str");
      nucs2=c2.getAtomGroups("String_Node_Str");
    }
  }
  if ((afpChain.getAlgorithmName().equals(FatCatRigid.algorithmName)) || (afpChain.getAlgorithmName().equals(FatCatFlexible.algorithmName))) {
    for (    Atom a : ca2) {
      i++;
      twistedGroups[i]=a.getParent();
    }
    twistedGroups=AFPTwister.twistOptimized(afpChain,ca1,ca2);
  }
 else {
    Matrix m=afpChain.getBlockRotationMatrix()[0];
    Atom shift=afpChain.getBlockShiftVector()[0];
    shiftCA2(afpChain,ca2,hetatms2,nucs2,m,shift,twistedGroups);
  }
  if (afpChain.getBlockNum() > 0) {
    if ((hetatms2.size() > 0) || (nucs2.size() > 0)) {
      if (afpChain.getBlockRotationMatrix().length > 0) {
        Matrix m1=afpChain.getBlockRotationMatrix()[0];
        Atom vector1=afpChain.getBlockShiftVector()[0];
        for (        Group g : hetatms2) {
          Calc.rotate(g,m1);
          Calc.shift(g,vector1);
        }
        for (        Group g : nucs2) {
          Calc.rotate(g,m1);
          Calc.shift(g,vector1);
        }
      }
    }
  }
  return twistedGroups;
}