code: private static AFPChain partitionAFPchain(AFPChain afpChain,
  			Atom[] ca1, Atom[] ca2, int order) throws StructureException{
  
  		int[][][] newAlgn = new int[order][][];
  		int repeatLen = afpChain.getOptLength()/order;
  
  		//Extract all the residues considered in the first chain of the alignment
  		List<Integer> alignedRes = new ArrayList<Integer>();
  		for (int su=0; su<afpChain.getBlockNum(); su++){
  			for (int i=0; i<afpChain.getOptLen()[su]; i++){
  				alignedRes.add(afpChain.getOptAln()[su][0][i]);
  			}
  		}
  
  		//Build the new alignment
  		for (int su=0; su<order; su++){
  			newAlgn[su] = new int[2][];
  			newAlgn[su][0] = new  int[repeatLen];
  			newAlgn[su][1] = new  int[repeatLen];
  			for (int i=0; i<repeatLen; i++){
  				newAlgn[su][0][i] = alignedRes.get(repeatLen*su+i);
  				newAlgn[su][1][i] = alignedRes.get(
  						(repeatLen*(su+1)+i)%alignedRes.size());
  			}
  		}
  
  		return AlignmentTools.replaceOptAln(newAlgn, afpChain, ca1, ca2);
  	}
docs: Partitions an afpChain alignment into order blocks of aligned residues.
  
  @param afpChain
  @param ca1
  @param ca2
  @param order
  @return
  @throws StructureException