Program: 16597
Project: 16597
Buggy source:
protected AFPChain align(Atom[] ca10,Atom[] ca2O,Object param) throws StructureException {
  if (!(param instanceof CESymmParameters))   throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str");
  this.params=(CESymmParameters)param;
  ca1=ca10;
  ca2=StructureTools.duplicateCA2(ca2O);
  rows=ca1.length;
  cols=ca2.length;
  if (rows == 0 || cols == 0) {
    throw new StructureException("String_Node_Str");
  }
  Matrix origM=null;
  AFPChain myAFP=new AFPChain();
  afpAlignments=new ArrayList<AFPChain>();
  calculator=new CECalculator(params);
  boolean multiple=(params.getRefineMethod() == RefineMethod.MULTIPLE);
  Matrix lastMatrix=null;
  int i=0;
  do {
    if (origM != null) {
      myAFP.setDistanceMatrix((Matrix)origM.clone());
    }
    origM=align(myAFP,ca1,ca2,params,origM,calculator,i);
    double tmScore2=AFPChainScorer.getTMScore(myAFP,ca1,ca2);
    myAFP.setTMScore(tmScore2);
    AFPChain newAFP=(AFPChain)myAFP.clone();
    newAFP=CeCPMain.postProcessAlignment(newAFP,ca1,ca2,calculator);
    double tmScore3=AFPChainScorer.getTMScore(newAFP,ca1,ca2);
    newAFP.setTMScore(tmScore3);
    logger.debug("String_Node_Str" + (i + 1) + "String_Node_Str"+ newAFP.getTMScore());
    if (tmScore3 < params.getSymmetryThreshold()) {
      logger.debug("String_Node_Str" + newAFP.getTMScore());
      if (i == 0)       afpAlignments.add(newAFP);
      lastMatrix=newAFP.getDistanceMatrix().copy();
      break;
    }
    afpAlignments.add(newAFP);
    i++;
  }
 while (i < params.getMaxSymmOrder() && multiple);
  if (lastMatrix == null && afpAlignments.size() > 1) {
    AFPChain last=afpAlignments.get(afpAlignments.size() - 1);
    lastMatrix=SymmetryTools.blankOutPreviousAlignment(last,ca2,last.getCa1Length(),last.getCa2Length(),calculator,origM,params.getWinSize());
    lastMatrix=lastMatrix.getMatrix(0,last.getCa1Length() - 1,0,last.getCa2Length() - 1);
  }
  afpChain=afpAlignments.get(0);
  String name=ca1[0].getGroup().getChain().getStructure().getIdentifier();
  afpChain.setName1(name);
  afpChain.setName2(name);
  if (params.getRefineMethod() == RefineMethod.NOT_REFINED) {
    return afpChain;
  }
  type=params.getSymmetryType();
  if (type == SymmetryType.AUTO) {
    if (afpChain.getBlockNum() == 1) {
      type=SymmetryType.OPEN;
      logger.info("String_Node_Str");
    }
 else {
      type=SymmetryType.CLOSE;
      logger.info("String_Node_Str");
    }
  }
  Refiner refiner=null;
  try {
switch (type) {
case CLOSE:
      OrderDetector orderDetector=null;
switch (params.getOrderDetectorMethod()) {
case SEQUENCE_FUNCTION:
      orderDetector=new SequenceFunctionOrderDetector(params.getMaxSymmOrder(),0.4f);
    order=orderDetector.calculateOrder(afpChain,ca1);
  break;
case USER_INPUT:
order=params.getUserOrder();
break;
}
refiner=new SingleRefiner();
break;
default :
refiner=new OpenRefiner();
order=params.getUserOrder();
break;
}
afpChain=refiner.refine(afpAlignments,ca1,order);
refined=true;
}
 catch (RefinerFailedException e) {
logger.info("String_Node_Str" + e.getMessage());
return afpChain;
}
int order=afpChain.getBlockNum();
axes=new SymmetryAxes();
Matrix rot=afpChain.getBlockRotationMatrix()[0];
Atom shift=afpChain.getBlockShiftVector()[0];
Matrix4d axis=Calc.getTransformation(rot,shift);
List<List<Integer>> superposition=new ArrayList<List<Integer>>();
List<Integer> chain1=new ArrayList<Integer>();
List<Integer> chain2=new ArrayList<Integer>();
superposition.add(chain1);
superposition.add(chain2);
List<Integer> subunitTrans=new ArrayList<Integer>();
switch (type) {
case CLOSE:
for (int bk=0; bk < order; bk++) {
chain1.add(bk);
chain2.add((bk + 1) % order);
subunitTrans.add(bk);
}
axes.addAxis(axis,superposition,subunitTrans,order);
break;
default :
subunitTrans.add(0);
for (int bk=0; bk < order - 1; bk++) {
chain1.add(bk);
chain2.add(bk + 1);
subunitTrans.add(bk + 1);
}
axes.addAxis(axis,superposition,subunitTrans,order);
break;
}
return afpChain;
}

Fixed version (ground truth):
protected AFPChain align(Atom[] ca1) throws StructureException {
  Atom[] ca2=StructureTools.duplicateCA2(ca1);
  int rows=ca1.length;
  int cols=ca2.length;
  if (rows == 0 || cols == 0) {
    throw new StructureException("String_Node_Str");
  }
  Matrix origM=null;
  AFPChain myAFP=new AFPChain();
  CECalculator calculator=new CECalculator(params);
  boolean multiple=(params.getRefineMethod() == RefineMethod.MULTIPLE);
  Matrix lastMatrix=null;
  int i=0;
  do {
    if (origM != null) {
      myAFP.setDistanceMatrix((Matrix)origM.clone());
    }
    origM=align(myAFP,ca1,ca2,params,origM,calculator,i);
    double tmScore2=AFPChainScorer.getTMScore(myAFP,ca1,ca2);
    myAFP.setTMScore(tmScore2);
    AFPChain newAFP=(AFPChain)myAFP.clone();
    newAFP=CeCPMain.postProcessAlignment(newAFP,ca1,ca2,calculator);
    double tmScore3=AFPChainScorer.getTMScore(newAFP,ca1,ca2);
    newAFP.setTMScore(tmScore3);
    logger.debug("String_Node_Str" + (i + 1) + "String_Node_Str"+ newAFP.getTMScore());
    if (tmScore3 < params.getSymmetryThreshold()) {
      logger.debug("String_Node_Str" + newAFP.getTMScore());
      if (i == 0)       selfAlignments.add(newAFP);
      lastMatrix=newAFP.getDistanceMatrix().copy();
      break;
    }
    selfAlignments.add(newAFP);
    i++;
  }
 while (i < params.getMaxSymmOrder() && multiple);
  if (lastMatrix == null && selfAlignments.size() > 1) {
    AFPChain last=selfAlignments.get(selfAlignments.size() - 1);
    lastMatrix=SymmetryTools.blankOutPreviousAlignment(last,ca2,last.getCa1Length(),last.getCa2Length(),calculator,origM,params.getWinSize());
    lastMatrix=lastMatrix.getMatrix(0,last.getCa1Length() - 1,0,last.getCa2Length() - 1);
  }
  AFPChain optimalAFP=selfAlignments.get(0);
  if (ca1.length != 0 && ca1[0].getGroup().getChain() != null && ca1[0].getGroup().getChain().getStructure() != null) {
    String name=ca1[0].getGroup().getChain().getStructure().getName();
    optimalAFP.setName1(name);
    optimalAFP.setName2(name);
  }
  if (params.getRefineMethod() == RefineMethod.NOT_REFINED) {
    return optimalAFP;
  }
  SymmetryType type=params.getSymmetryType();
  if (type == SymmetryType.AUTO) {
    if (optimalAFP.getBlockNum() == 1) {
      type=SymmetryType.OPEN;
      logger.info("String_Node_Str");
    }
 else {
      type=SymmetryType.CLOSE;
      logger.info("String_Node_Str");
    }
  }
  Refiner refiner=null;
  int order=1;
  try {
switch (type) {
case CLOSE:
      OrderDetector orderDetector=null;
switch (params.getOrderDetectorMethod()) {
case SEQUENCE_FUNCTION:
      orderDetector=new SequenceFunctionOrderDetector(params.getMaxSymmOrder(),0.4f);
    order=orderDetector.calculateOrder(optimalAFP,ca1);
  break;
case USER_INPUT:
order=params.getUserOrder();
break;
}
refiner=new SingleRefiner();
break;
default :
refiner=new OpenRefiner();
order=params.getUserOrder();
break;
}
optimalAFP=refiner.refine(selfAlignments,ca1,order);
refined=true;
}
 catch (RefinerFailedException e) {
logger.info("String_Node_Str" + e.getMessage());
return optimalAFP;
}
order=optimalAFP.getBlockNum();
Matrix rot=optimalAFP.getBlockRotationMatrix()[0];
Atom shift=optimalAFP.getBlockShiftVector()[0];
Matrix4d axis=Calc.getTransformation(rot,shift);
List<List<Integer>> superposition=new ArrayList<List<Integer>>();
List<Integer> chain1=new ArrayList<Integer>();
List<Integer> chain2=new ArrayList<Integer>();
superposition.add(chain1);
superposition.add(chain2);
List<Integer> subunitTrans=new ArrayList<Integer>();
switch (type) {
case CLOSE:
for (int bk=0; bk < order; bk++) {
chain1.add(bk);
chain2.add((bk + 1) % order);
subunitTrans.add(bk);
}
axes.addAxis(axis,superposition,subunitTrans,order);
break;
default :
subunitTrans.add(0);
for (int bk=0; bk < order - 1; bk++) {
chain1.add(bk);
chain2.add(bk + 1);
subunitTrans.add(bk + 1);
}
axes.addAxis(axis,superposition,subunitTrans,order);
break;
}
return optimalAFP;
}