Program: 17008
Project: 17008
Buggy source:
/** 
 * Calculate the rotation axis for the normal case, where there is a significant rotation angle
 * @param rotation
 * @param translation
 * @param c
 */
private void calculateRotationalAxis(Matrix rotation,Atom translation,double c){
  double sum=0;
  double[] rotAx=new double[3];
  for (int i=0; i < 3; i++) {
    rotAx[i]=Math.sqrt(rotation.get(i,i) - c);
    sum+=rotAx[i] * rotAx[i];
  }
  for (int i=0; i < 3; i++) {
    rotAx[i]/=Math.sqrt(sum);
  }
  double d0=rotation.get(2,1) - rotation.get(1,2);
  double d1=rotation.get(0,2) - rotation.get(2,0);
  double d2=rotation.get(1,0) - rotation.get(0,1);
  double s12=rotation.get(2,1) + rotation.get(1,2);
  double s02=rotation.get(0,2) + rotation.get(2,0);
  double s01=rotation.get(1,0) + rotation.get(0,1);
  if (Math.abs(d0) < Math.abs(d1)) {
    if (Math.abs(d1) < Math.abs(d2)) {
      if (d2 >= 0) {
        if (s02 < 0)         rotAx[0]=-rotAx[0];
        if (s12 < 0)         rotAx[1]=-rotAx[1];
      }
 else {
        rotAx[2]=-rotAx[2];
        if (s02 >= 0)         rotAx[0]=-rotAx[0];
        if (s12 >= 0)         rotAx[1]=-rotAx[1];
      }
    }
 else {
      if (d1 >= 0) {
        if (s01 < 0)         rotAx[0]=-rotAx[0];
        if (s12 < 0)         rotAx[2]=-rotAx[2];
      }
 else {
        rotAx[1]=-rotAx[1];
        if (s01 >= 0)         rotAx[0]=-rotAx[0];
        if (s12 >= 0)         rotAx[2]=-rotAx[2];
      }
    }
  }
 else {
    if (d0 >= 0) {
      if (s01 < 0)       rotAx[0]=-rotAx[0];
      if (s02 < 0)       rotAx[2]=-rotAx[2];
    }
 else {
      rotAx[0]=-rotAx[0];
      if (s01 >= 0)       rotAx[0]=-rotAx[0];
      if (s02 >= 0)       rotAx[2]=-rotAx[2];
    }
  }
  rotationAxis=new AtomImpl();
  rotationAxis.setCoords(rotAx);
  double dotProduct=Calc.skalarProduct(rotationAxis,translation);
  screwTranslation=Calc.scale(rotationAxis,dotProduct);
  otherTranslation=Calc.subtract(translation,screwTranslation);
  Atom hypot=Calc.vectorProduct(otherTranslation,rotationAxis);
  Calc.scaleEquals(hypot,.5 / Math.tan(theta / 2.0));
  rotationPos=Calc.scaleAdd(.5,otherTranslation,hypot);
}

Fixed version (ground truth):
/** 
 * Calculate the rotation axis for the normal case, where there is a significant rotation angle
 * @param rotation
 * @param translation
 * @param c
 */
private void calculateRotationalAxis(Matrix rotation,Atom translation,double c){
  double sum=0;
  double[] rotAx=new double[3];
  for (int i=0; i < 3; i++) {
    rotAx[i]=Math.sqrt(rotation.get(i,i) - c);
    sum+=rotAx[i] * rotAx[i];
  }
  for (int i=0; i < 3; i++) {
    rotAx[i]/=Math.sqrt(sum);
  }
  double d0=rotation.get(2,1) - rotation.get(1,2);
  double d1=rotation.get(0,2) - rotation.get(2,0);
  double d2=rotation.get(1,0) - rotation.get(0,1);
  double s12=rotation.get(2,1) + rotation.get(1,2);
  double s02=rotation.get(0,2) + rotation.get(2,0);
  double s01=rotation.get(1,0) + rotation.get(0,1);
  if (Math.abs(d0) < Math.abs(d1)) {
    if (Math.abs(d1) < Math.abs(d2)) {
      if (d2 >= 0) {
        if (s02 < 0)         rotAx[0]=-rotAx[0];
        if (s12 < 0)         rotAx[1]=-rotAx[1];
      }
 else {
        rotAx[2]=-rotAx[2];
        if (s02 >= 0)         rotAx[0]=-rotAx[0];
        if (s12 >= 0)         rotAx[1]=-rotAx[1];
      }
    }
 else {
      if (d1 >= 0) {
        if (s01 < 0)         rotAx[0]=-rotAx[0];
        if (s12 < 0)         rotAx[2]=-rotAx[2];
      }
 else {
        rotAx[1]=-rotAx[1];
        if (s01 >= 0)         rotAx[0]=-rotAx[0];
        if (s12 >= 0)         rotAx[2]=-rotAx[2];
      }
    }
  }
 else {
    if (Math.abs(d0) < Math.abs(d2)) {
      if (d2 >= 0) {
        if (s02 < 0)         rotAx[0]=-rotAx[0];
        if (s12 < 0)         rotAx[1]=-rotAx[1];
      }
 else {
        rotAx[2]=-rotAx[2];
        if (s02 >= 0)         rotAx[0]=-rotAx[0];
        if (s12 >= 0)         rotAx[1]=-rotAx[1];
      }
    }
 else {
      if (d0 >= 0) {
        if (s01 < 0)         rotAx[1]=-rotAx[1];
        if (s02 < 0)         rotAx[2]=-rotAx[2];
      }
 else {
        rotAx[0]=-rotAx[0];
        if (s01 >= 0)         rotAx[1]=-rotAx[1];
        if (s02 >= 0)         rotAx[2]=-rotAx[2];
      }
    }
  }
  rotationAxis=new AtomImpl();
  rotationAxis.setCoords(rotAx);
  double dotProduct=Calc.skalarProduct(rotationAxis,translation);
  screwTranslation=Calc.scale(rotationAxis,dotProduct);
  otherTranslation=Calc.subtract(translation,screwTranslation);
  Atom hypot=Calc.vectorProduct(otherTranslation,rotationAxis);
  Calc.scaleEquals(hypot,.5 / Math.tan(theta / 2.0));
  rotationPos=Calc.scaleAdd(.5,otherTranslation,hypot);
}