Program: 16392
Project: 16392
Buggy source:
/** 
 * Builds a Structure object containing the quaternary structure built from given asymUnit and transformations, by adding symmetry partners as new models. If the input Structure is multi-model, then only model 1 is retained and the quaternary structure is built in the same way with additional models.
 * @param asymUnit
 * @param transformations
 * @param useAsymIds if true use {@link Chain#getId()} to match the ids in the BiologicalAssemblyTransformation (needed if data read from mmCIF), if false use  {@link Chain#getName()} for the chain matching (needed if data read from PDB).
 * @return
 */
public Structure rebuildQuaternaryStructure(Structure asymUnit,List<BiologicalAssemblyTransformation> transformations,boolean useAsymIds){
  orderTransformationsByChainId(asymUnit,transformations);
  Structure s=asymUnit.clone();
  s.resetModels();
  for (  BiologicalAssemblyTransformation transformation : transformations) {
    List<Chain> chainsToTransform=new ArrayList<>();
    if (useAsymIds) {
      Chain c=asymUnit.getChain(transformation.getChainId());
      chainsToTransform.add(c);
    }
 else {
      Chain polyC=asymUnit.getPolyChainByPDB(transformation.getChainId());
      List<Chain> nonPolyCs=asymUnit.getNonPolyChainsByPDB(transformation.getChainId());
      chainsToTransform.add(polyC);
      chainsToTransform.addAll(nonPolyCs);
    }
    for (    Chain c : chainsToTransform) {
      Chain chain=(Chain)c.clone();
      for (      Group g : chain.getAtomGroups()) {
        for (        Atom a : g.getAtoms()) {
          transformation.transformPoint(a.getCoords());
        }
      }
      String transformId=transformation.getId();
      addChainAndModel(s,chain,transformId);
    }
  }
  s.setBiologicalAssembly(true);
  return s;
}

Fixed version (ground truth):
/** 
 * Builds a Structure object containing the quaternary structure built from given asymUnit and transformations, by adding symmetry partners as new models. If the input Structure is multi-model, then only model 1 is retained and the quaternary structure is built in the same way with additional models.
 * @param asymUnit
 * @param transformations
 * @param useAsymIds if true use {@link Chain#getId()} to match the ids in the BiologicalAssemblyTransformation (needed if data read from mmCIF), if false use  {@link Chain#getName()} for the chain matching (needed if data read from PDB).
 * @return
 */
public Structure rebuildQuaternaryStructure(Structure asymUnit,List<BiologicalAssemblyTransformation> transformations,boolean useAsymIds){
  orderTransformationsByChainId(asymUnit,transformations);
  Structure s=asymUnit.clone();
  s.resetModels();
  for (  BiologicalAssemblyTransformation transformation : transformations) {
    List<Chain> chainsToTransform=new ArrayList<>();
    if (useAsymIds) {
      Chain c=asymUnit.getChain(transformation.getChainId());
      chainsToTransform.add(c);
    }
 else {
      Chain polyC=asymUnit.getPolyChainByPDB(transformation.getChainId());
      List<Chain> nonPolyCs=asymUnit.getNonPolyChainsByPDB(transformation.getChainId());
      Chain waterC=asymUnit.getWaterChainByPDB(transformation.getChainId());
      if (polyC != null)       chainsToTransform.add(polyC);
      if (!nonPolyCs.isEmpty())       chainsToTransform.addAll(nonPolyCs);
      if (waterC != null)       chainsToTransform.add(waterC);
    }
    for (    Chain c : chainsToTransform) {
      Chain chain=(Chain)c.clone();
      for (      Group g : chain.getAtomGroups()) {
        for (        Atom a : g.getAtoms()) {
          transformation.transformPoint(a.getCoords());
        }
      }
      String transformId=transformation.getId();
      addChainAndModel(s,chain,transformId);
    }
  }
  s.setBiologicalAssembly(true);
  return s;
}