Program: 16435
Project: 16435
Buggy source:
/** 
 * Calculate interfaces between original asymmetric unit and neighboring whole unit cells, including the original full unit cell i.e. i=0,j=0,k=0
 * @param set
 * @param cutoff
 */
private void calcInterfacesCrystal(StructureInterfaceList set,double cutoff){
  long start=-1;
  long end=-1;
  int trialCount=0;
  int skippedRedundant=0;
  int skippedAUsNoOverlap=0;
  int skippedChainsNoOverlap=0;
  int skippedSelfEquivalent=0;
  Matrix4d[] ops=null;
  if (isCrystallographic) {
    ops=structure.getCrystallographicInfo().getTransformationsOrthonormal();
  }
 else {
    ops=new Matrix4d[1];
    ops[0]=new Matrix4d(IDENTITY);
  }
  UnitCellBoundingBox bbGrid=new UnitCellBoundingBox(numOperatorsSg,numChainsAu);
  ;
  bbGrid.setBbs(structure,ops,INCLUDE_HETATOMS);
  if (!isCrystallographic)   numCells=0;
  boolean verbose=logger.isDebugEnabled();
  if (verbose) {
    trialCount=0;
    start=System.currentTimeMillis();
    int neighbors=(2 * numCells + 1) * (2 * numCells + 1) * (2 * numCells + 1) - 1;
    int auTrials=(numChainsAu * (numChainsAu - 1)) / 2;
    int trials=numChainsAu * numOperatorsSg * numChainsAu* neighbors;
    logger.debug("String_Node_Str" + auTrials);
    logger.debug("String_Node_Str" + neighbors + "String_Node_Str"+ numCells+ "String_Node_Str"+ "String_Node_Str"+ numChainsAu+ "String_Node_Str"+ numOperatorsSg+ "String_Node_Str"+ neighbors+ "String_Node_Str"+ trials);
    logger.debug("String_Node_Str" + (auTrials + trials));
  }
  for (int a=-numCells; a <= numCells; a++) {
    for (int b=-numCells; b <= numCells; b++) {
      for (int c=-numCells; c <= numCells; c++) {
        Point3i trans=new Point3i(a,b,c);
        Vector3d transOrth=new Vector3d(a,b,c);
        if (a != 0 || b != 0 || c != 0)         this.crystallographicInfo.getCrystalCell().transfToOrthonormal(transOrth);
        UnitCellBoundingBox bbGridTrans=bbGrid.getTranslatedBbs(transOrth);
        for (int n=0; n < numOperatorsSg; n++) {
          if (!bbGrid.getAuBoundingBox(0).overlaps(bbGridTrans.getAuBoundingBox(n),cutoff)) {
            skippedAUsNoOverlap++;
            continue;
          }
          CrystalTransform tt=new CrystalTransform(this.crystallographicInfo.getSpaceGroup(),n);
          tt.translate(trans);
          if (isRedundant(tt)) {
            skippedRedundant++;
            continue;
          }
          addVisited(tt);
          boolean selfEquivalent=false;
          if (tt.isEquivalent(tt)) {
            logger.debug("String_Node_Str" + tt + "String_Node_Str");
            selfEquivalent=true;
          }
          StringBuilder builder=null;
          if (verbose)           builder=new StringBuilder(tt + "String_Node_Str");
          int contactsFound=0;
          for (int j=0; j < numChainsAu; j++) {
            for (int i=0; i < numChainsAu; i++) {
              if (selfEquivalent && (j > i)) {
                skippedSelfEquivalent++;
                continue;
              }
              if (n == 0 && a == 0 && b == 0 && c == 0 && i == j)               continue;
              if (!bbGrid.getChainBoundingBox(0,i).overlaps(bbGridTrans.getChainBoundingBox(n,j),cutoff)) {
                skippedChainsNoOverlap++;
                if (verbose) {
                  builder.append("String_Node_Str");
                }
                continue;
              }
              trialCount++;
              Chain chainj=null;
              Chain chaini=structure.getChain(i);
              if (n == 0 && a == 0 && b == 0 && c == 0) {
                chainj=structure.getChain(j);
              }
 else {
                chainj=(Chain)structure.getChain(j).clone();
                Matrix4d m=new Matrix4d(ops[n]);
                translate(m,transOrth);
                Calc.transform(chainj,m);
              }
              StructureInterface interf=calcContacts(chaini,chainj,cutoff,tt,builder);
              if (interf != null) {
                contactsFound++;
                set.add(interf);
              }
            }
          }
          if (verbose) {
            if (a == 0 && b == 0 && c == 0 && n == 0)             builder.append("String_Node_Str" + contactsFound + "String_Node_Str"+ (numChainsAu * (numChainsAu - 1)) / 2 + "String_Node_Str");
 else             if (selfEquivalent)             builder.append("String_Node_Str" + contactsFound + "String_Node_Str"+ (numChainsAu * (numChainsAu + 1)) / 2 + "String_Node_Str");
 else             builder.append("String_Node_Str" + contactsFound + "String_Node_Str"+ numChainsAu * numChainsAu + "String_Node_Str");
            logger.debug(builder.toString());
          }
        }
      }
    }
  }
  end=System.currentTimeMillis();
  logger.debug("String_Node_Str" + trialCount + "String_Node_Str"+ (end - start) / 1000 + "String_Node_Str");
  logger.debug("String_Node_Str" + skippedAUsNoOverlap);
  logger.debug("String_Node_Str" + skippedChainsNoOverlap);
  logger.debug("String_Node_Str" + skippedRedundant);
  logger.debug("String_Node_Str" + skippedSelfEquivalent);
  logger.debug("String_Node_Str" + set.size() + "String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Calculate interfaces between original asymmetric unit and neighboring whole unit cells, including the original full unit cell i.e. i=0,j=0,k=0
 * @param set
 * @param cutoff
 */
private void calcInterfacesCrystal(StructureInterfaceList set,double cutoff){
  long start=-1;
  long end=-1;
  int trialCount=0;
  int skippedRedundant=0;
  int skippedAUsNoOverlap=0;
  int skippedChainsNoOverlap=0;
  int skippedSelfEquivalent=0;
  Matrix4d[] ops=null;
  if (isCrystallographic) {
    ops=structure.getCrystallographicInfo().getTransformationsOrthonormal();
  }
 else {
    ops=new Matrix4d[1];
    ops[0]=new Matrix4d(IDENTITY);
  }
  UnitCellBoundingBox bbGrid=new UnitCellBoundingBox(numOperatorsSg,numPolyChainsAu);
  ;
  bbGrid.setBbs(structure,ops,INCLUDE_HETATOMS);
  if (!isCrystallographic)   numCells=0;
  boolean verbose=logger.isDebugEnabled();
  if (verbose) {
    trialCount=0;
    start=System.currentTimeMillis();
    int neighbors=(2 * numCells + 1) * (2 * numCells + 1) * (2 * numCells + 1) - 1;
    int auTrials=(numPolyChainsAu * (numPolyChainsAu - 1)) / 2;
    int trials=numPolyChainsAu * numOperatorsSg * numPolyChainsAu* neighbors;
    logger.debug("String_Node_Str" + auTrials);
    logger.debug("String_Node_Str" + neighbors + "String_Node_Str"+ numCells+ "String_Node_Str"+ "String_Node_Str"+ numPolyChainsAu+ "String_Node_Str"+ numOperatorsSg+ "String_Node_Str"+ neighbors+ "String_Node_Str"+ trials);
    logger.debug("String_Node_Str" + (auTrials + trials));
  }
  for (int a=-numCells; a <= numCells; a++) {
    for (int b=-numCells; b <= numCells; b++) {
      for (int c=-numCells; c <= numCells; c++) {
        Point3i trans=new Point3i(a,b,c);
        Vector3d transOrth=new Vector3d(a,b,c);
        if (a != 0 || b != 0 || c != 0)         this.crystallographicInfo.getCrystalCell().transfToOrthonormal(transOrth);
        UnitCellBoundingBox bbGridTrans=bbGrid.getTranslatedBbs(transOrth);
        for (int n=0; n < numOperatorsSg; n++) {
          if (!bbGrid.getAuBoundingBox(0).overlaps(bbGridTrans.getAuBoundingBox(n),cutoff)) {
            skippedAUsNoOverlap++;
            continue;
          }
          CrystalTransform tt=new CrystalTransform(this.crystallographicInfo.getSpaceGroup(),n);
          tt.translate(trans);
          if (isRedundant(tt)) {
            skippedRedundant++;
            continue;
          }
          addVisited(tt);
          boolean selfEquivalent=false;
          if (tt.isEquivalent(tt)) {
            logger.debug("String_Node_Str" + tt + "String_Node_Str");
            selfEquivalent=true;
          }
          StringBuilder builder=null;
          if (verbose)           builder=new StringBuilder(tt + "String_Node_Str");
          int contactsFound=0;
          List<Chain> polyChains=structure.getPolyChains();
          for (int j=0; j < numPolyChainsAu; j++) {
            for (int i=0; i < numPolyChainsAu; i++) {
              if (selfEquivalent && (j > i)) {
                skippedSelfEquivalent++;
                continue;
              }
              if (n == 0 && a == 0 && b == 0 && c == 0 && i == j)               continue;
              if (!bbGrid.getChainBoundingBox(0,i).overlaps(bbGridTrans.getChainBoundingBox(n,j),cutoff)) {
                skippedChainsNoOverlap++;
                if (verbose) {
                  builder.append("String_Node_Str");
                }
                continue;
              }
              trialCount++;
              Chain chainj=null;
              Chain chaini=polyChains.get(i);
              if (n == 0 && a == 0 && b == 0 && c == 0) {
                chainj=polyChains.get(j);
              }
 else {
                chainj=(Chain)polyChains.get(j).clone();
                Matrix4d m=new Matrix4d(ops[n]);
                translate(m,transOrth);
                Calc.transform(chainj,m);
              }
              StructureInterface interf=calcContacts(chaini,chainj,cutoff,tt,builder);
              if (interf != null) {
                contactsFound++;
                set.add(interf);
              }
            }
          }
          if (verbose) {
            if (a == 0 && b == 0 && c == 0 && n == 0)             builder.append("String_Node_Str" + contactsFound + "String_Node_Str"+ (numPolyChainsAu * (numPolyChainsAu - 1)) / 2 + "String_Node_Str");
 else             if (selfEquivalent)             builder.append("String_Node_Str" + contactsFound + "String_Node_Str"+ (numPolyChainsAu * (numPolyChainsAu + 1)) / 2 + "String_Node_Str");
 else             builder.append("String_Node_Str" + contactsFound + "String_Node_Str"+ numPolyChainsAu * numPolyChainsAu + "String_Node_Str");
            logger.debug(builder.toString());
          }
        }
      }
    }
  }
  end=System.currentTimeMillis();
  logger.debug("String_Node_Str" + trialCount + "String_Node_Str"+ (end - start) / 1000 + "String_Node_Str");
  logger.debug("String_Node_Str" + skippedAUsNoOverlap);
  logger.debug("String_Node_Str" + skippedChainsNoOverlap);
  logger.debug("String_Node_Str" + skippedRedundant);
  logger.debug("String_Node_Str" + skippedSelfEquivalent);
  logger.debug("String_Node_Str" + set.size() + "String_Node_Str");
}