Program: 16505
Project: 16505
Buggy source:
@Override public void documentEnd(){
  if (current_chain != null) {
    current_chain.addGroup(current_group);
    if (isKnownChain(current_chain.getChainID(),current_model) == null) {
      current_model.add(current_chain);
    }
  }
 else   if (!params.isHeaderOnly()) {
    logger.warn("String_Node_Str");
  }
  structure.addModel(current_model);
  for (  StructAsym asym : structAsyms) {
    logger.debug("String_Node_Str",asym.getEntity_id(),asym.getId());
    asymId2entityId.put(asym.getId(),asym.getEntity_id());
    Chain s=getEntityChain(asym.getEntity_id());
    Chain seqres=(Chain)s.clone();
    seqres=removeSeqResHeterogeneity(seqres);
    seqres.setChainID(asym.getId());
    seqResChains.add(seqres);
    logger.debug("String_Node_Str" + asym.getId() + "String_Node_Str"+ seqres+ "String_Node_Str");
    addCompounds(asym);
  }
  if (structAsyms.isEmpty()) {
    logger.warn("String_Node_Str");
  }
  if (params.isAlignSeqRes() && !params.isHeaderOnly()) {
    logger.debug("String_Node_Str");
    alignSeqRes();
  }
 else {
    logger.debug("String_Node_Str");
    SeqRes2AtomAligner.storeUnAlignedSeqRes(structure,seqResChains,params.isHeaderOnly());
  }
  if (!params.isHeaderOnly()) {
    if (params.shouldCreateAtomBonds()) {
      addBonds();
    }
    if (params.shouldCreateAtomCharges()) {
      addCharges();
    }
  }
  if (asymStrandId.isEmpty()) {
    logger.warn("String_Node_Str");
    asymStrandId=asymId2StrandIdFromAtomSites;
  }
  if (asymId2StrandIdFromAtomSites.isEmpty()) {
    logger.warn("String_Node_Str");
    asymId2StrandIdFromAtomSites=asymStrandId;
  }
  if (params.isUseInternalChainId() == false) {
    for (int i=0; i < structure.nrModels(); i++) {
      List<Chain> model=structure.getModel(i);
      List<Chain> pdbChains=new ArrayList<Chain>();
      for (      Chain chain : model) {
        for (        String asym : asymId2StrandIdFromAtomSites.keySet()) {
          if (chain.getChainID().equals(asym)) {
            String newChainId=asymId2StrandIdFromAtomSites.get(asym);
            logger.debug("String_Node_Str",asym,chain.getAtomGroups().size(),newChainId);
            chain.setChainID(newChainId);
            chain.setInternalChainID(asym);
            for (            Group g : chain.getAtomGroups()) {
              ResidueNumber resNum=g.getResidueNumber();
              if (resNum != null)               resNum.setChainId(newChainId);
            }
            for (            Group g : chain.getSeqResGroups()) {
              ResidueNumber resNum=g.getResidueNumber();
              if (resNum != null)               resNum.setChainId(newChainId);
            }
            Chain known=isKnownChain(chain.getChainID(),pdbChains);
            if (known == null) {
              pdbChains.add(chain);
            }
 else {
              for (              Group g : chain.getAtomGroups()) {
                known.addGroup(g);
              }
            }
            break;
          }
        }
      }
      structure.setModel(i,pdbChains);
    }
  }
 else {
    for (int i=0; i < structure.nrModels(); i++) {
      List<Chain> model=structure.getModel(i);
      for (      Chain chain : model) {
        for (        String asym : asymId2StrandIdFromAtomSites.keySet()) {
          if (chain.getChainID().equals(asym)) {
            String authChainId=asymId2StrandIdFromAtomSites.get(asym);
            chain.setInternalChainID(authChainId);
            break;
          }
        }
      }
    }
  }
  linkCompounds();
  if (!params.isHeaderOnly()) {
    addSites();
  }
  if (params.isParseBioAssembly()) {
    Map<Integer,BioAssemblyInfo> bioAssemblies=new HashMap<Integer,BioAssemblyInfo>();
    for (    PdbxStructAssembly psa : strucAssemblies) {
      List<PdbxStructAssemblyGen> psags=new ArrayList<PdbxStructAssemblyGen>(1);
      for (      PdbxStructAssemblyGen psag : strucAssemblyGens) {
        if (psag.getAssembly_id().equals(psa.getId())) {
          psags.add(psag);
        }
      }
      BiologicalAssemblyBuilder builder=new BiologicalAssemblyBuilder();
      List<BiologicalAssemblyTransformation> transformations=builder.getBioUnitTransformationList(psa,psags,structOpers);
      int mmSize=0;
      int bioAssemblyId=-1;
      try {
        bioAssemblyId=Integer.parseInt(psa.getId());
      }
 catch (      NumberFormatException e) {
        logger.info("String_Node_Str",psa.getId());
      }
      try {
        mmSize=Integer.parseInt(psa.getOligomeric_count());
      }
 catch (      NumberFormatException e) {
        if (bioAssemblyId != -1)         logger.warn("String_Node_Str",psa.getOligomeric_count(),psa.getId());
 else         logger.info("String_Node_Str",psa.getOligomeric_count(),psa.getId());
      }
      if (bioAssemblyId != -1) {
        BioAssemblyInfo bioAssembly=new BioAssemblyInfo();
        bioAssembly.setId(bioAssemblyId);
        bioAssembly.setMacromolecularSize(mmSize);
        bioAssembly.setTransforms(transformations);
        bioAssemblies.put(bioAssemblyId,bioAssembly);
      }
    }
    structure.getPDBHeader().setBioAssemblies(bioAssemblies);
  }
  ArrayList<Matrix4d> ncsOperators=new ArrayList<Matrix4d>();
  for (  StructNcsOper sNcsOper : structNcsOper) {
    if (sNcsOper.getCode().equals("String_Node_Str")) {
      ncsOperators.add(sNcsOper.getOperator());
    }
  }
  if (ncsOperators.size() > 0) {
    structure.getCrystallographicInfo().setNcsOperators(ncsOperators.toArray(new Matrix4d[ncsOperators.size()]));
  }
  Map<String,List<SeqMisMatch>> misMatchMap=new HashMap<String,List<SeqMisMatch>>();
  for (  StructRefSeqDif sdif : sequenceDifs) {
    SeqMisMatch misMatch=new SeqMisMatchImpl();
    misMatch.setDetails(sdif.getDetails());
    String insCode=sdif.getPdbx_pdb_ins_code();
    if (insCode != null && insCode.equals("String_Node_Str"))     insCode=null;
    misMatch.setInsCode(insCode);
    misMatch.setOrigGroup(sdif.getDb_mon_id());
    misMatch.setPdbGroup(sdif.getMon_id());
    misMatch.setPdbResNum(sdif.getPdbx_auth_seq_num());
    misMatch.setUniProtId(sdif.getPdbx_seq_db_accession_code());
    misMatch.setSeqNum(sdif.getSeq_num());
    List<SeqMisMatch> mms=misMatchMap.get(sdif.getPdbx_pdb_strand_id());
    if (mms == null) {
      mms=new ArrayList<SeqMisMatch>();
      misMatchMap.put(sdif.getPdbx_pdb_strand_id(),mms);
    }
    mms.add(misMatch);
  }
  for (  String chainId : misMatchMap.keySet()) {
    try {
      Chain c=structure.getChainByPDB(chainId);
      c.setSeqMisMatches(misMatchMap.get(chainId));
    }
 catch (    Exception e) {
      logger.warn("String_Node_Str" + chainId);
    }
  }
}

Fixed version (ground truth):
@Override public void documentEnd(){
  if (current_chain != null) {
    current_chain.addGroup(current_group);
    if (isKnownChain(current_chain.getChainID(),current_model) == null) {
      current_model.add(current_chain);
    }
  }
 else   if (!params.isHeaderOnly()) {
    logger.warn("String_Node_Str");
  }
  structure.addModel(current_model);
  for (  StructAsym asym : structAsyms) {
    logger.debug("String_Node_Str",asym.getEntity_id(),asym.getId());
    asymId2entityId.put(asym.getId(),asym.getEntity_id());
    Chain s=getEntityChain(asym.getEntity_id());
    Chain seqres=(Chain)s.clone();
    seqres=removeSeqResHeterogeneity(seqres);
    seqres.setChainID(asym.getId());
    seqResChains.add(seqres);
    logger.debug("String_Node_Str" + asym.getId() + "String_Node_Str"+ seqres+ "String_Node_Str");
    addCompounds(asym);
  }
  if (structAsyms.isEmpty()) {
    logger.warn("String_Node_Str");
  }
  if (params.isAlignSeqRes() && !params.isHeaderOnly()) {
    logger.debug("String_Node_Str");
    alignSeqRes();
  }
 else {
    logger.debug("String_Node_Str");
    SeqRes2AtomAligner.storeUnAlignedSeqRes(structure,seqResChains,params.isHeaderOnly());
  }
  if (asymStrandId.isEmpty()) {
    logger.warn("String_Node_Str");
    asymStrandId=asymId2StrandIdFromAtomSites;
  }
  if (asymId2StrandIdFromAtomSites.isEmpty()) {
    logger.warn("String_Node_Str");
    asymId2StrandIdFromAtomSites=asymStrandId;
  }
  if (params.isUseInternalChainId() == false) {
    for (int i=0; i < structure.nrModels(); i++) {
      List<Chain> model=structure.getModel(i);
      List<Chain> pdbChains=new ArrayList<Chain>();
      for (      Chain chain : model) {
        for (        String asym : asymId2StrandIdFromAtomSites.keySet()) {
          if (chain.getChainID().equals(asym)) {
            String newChainId=asymId2StrandIdFromAtomSites.get(asym);
            logger.debug("String_Node_Str",asym,chain.getAtomGroups().size(),newChainId);
            chain.setChainID(newChainId);
            chain.setInternalChainID(asym);
            for (            Group g : chain.getAtomGroups()) {
              ResidueNumber resNum=g.getResidueNumber();
              if (resNum != null)               resNum.setChainId(newChainId);
            }
            for (            Group g : chain.getSeqResGroups()) {
              ResidueNumber resNum=g.getResidueNumber();
              if (resNum != null)               resNum.setChainId(newChainId);
            }
            Chain known=isKnownChain(chain.getChainID(),pdbChains);
            if (known == null) {
              pdbChains.add(chain);
            }
 else {
              for (              Group g : chain.getAtomGroups()) {
                known.addGroup(g);
              }
            }
            break;
          }
        }
      }
      structure.setModel(i,pdbChains);
    }
  }
 else {
    for (int i=0; i < structure.nrModels(); i++) {
      List<Chain> model=structure.getModel(i);
      for (      Chain chain : model) {
        for (        String asym : asymId2StrandIdFromAtomSites.keySet()) {
          if (chain.getChainID().equals(asym)) {
            String authChainId=asymId2StrandIdFromAtomSites.get(asym);
            chain.setInternalChainID(authChainId);
            break;
          }
        }
      }
    }
  }
  if (!params.isHeaderOnly()) {
    if (params.shouldCreateAtomBonds()) {
      addBonds();
    }
    if (params.shouldCreateAtomCharges()) {
      addCharges();
    }
  }
  linkCompounds();
  if (!params.isHeaderOnly()) {
    addSites();
  }
  if (params.isParseBioAssembly()) {
    Map<Integer,BioAssemblyInfo> bioAssemblies=new HashMap<Integer,BioAssemblyInfo>();
    for (    PdbxStructAssembly psa : strucAssemblies) {
      List<PdbxStructAssemblyGen> psags=new ArrayList<PdbxStructAssemblyGen>(1);
      for (      PdbxStructAssemblyGen psag : strucAssemblyGens) {
        if (psag.getAssembly_id().equals(psa.getId())) {
          psags.add(psag);
        }
      }
      BiologicalAssemblyBuilder builder=new BiologicalAssemblyBuilder();
      List<BiologicalAssemblyTransformation> transformations=builder.getBioUnitTransformationList(psa,psags,structOpers);
      int mmSize=0;
      int bioAssemblyId=-1;
      try {
        bioAssemblyId=Integer.parseInt(psa.getId());
      }
 catch (      NumberFormatException e) {
        logger.info("String_Node_Str",psa.getId());
      }
      try {
        mmSize=Integer.parseInt(psa.getOligomeric_count());
      }
 catch (      NumberFormatException e) {
        if (bioAssemblyId != -1)         logger.warn("String_Node_Str",psa.getOligomeric_count(),psa.getId());
 else         logger.info("String_Node_Str",psa.getOligomeric_count(),psa.getId());
      }
      if (bioAssemblyId != -1) {
        BioAssemblyInfo bioAssembly=new BioAssemblyInfo();
        bioAssembly.setId(bioAssemblyId);
        bioAssembly.setMacromolecularSize(mmSize);
        bioAssembly.setTransforms(transformations);
        bioAssemblies.put(bioAssemblyId,bioAssembly);
      }
    }
    structure.getPDBHeader().setBioAssemblies(bioAssemblies);
  }
  ArrayList<Matrix4d> ncsOperators=new ArrayList<Matrix4d>();
  for (  StructNcsOper sNcsOper : structNcsOper) {
    if (sNcsOper.getCode().equals("String_Node_Str")) {
      ncsOperators.add(sNcsOper.getOperator());
    }
  }
  if (ncsOperators.size() > 0) {
    structure.getCrystallographicInfo().setNcsOperators(ncsOperators.toArray(new Matrix4d[ncsOperators.size()]));
  }
  Map<String,List<SeqMisMatch>> misMatchMap=new HashMap<String,List<SeqMisMatch>>();
  for (  StructRefSeqDif sdif : sequenceDifs) {
    SeqMisMatch misMatch=new SeqMisMatchImpl();
    misMatch.setDetails(sdif.getDetails());
    String insCode=sdif.getPdbx_pdb_ins_code();
    if (insCode != null && insCode.equals("String_Node_Str"))     insCode=null;
    misMatch.setInsCode(insCode);
    misMatch.setOrigGroup(sdif.getDb_mon_id());
    misMatch.setPdbGroup(sdif.getMon_id());
    misMatch.setPdbResNum(sdif.getPdbx_auth_seq_num());
    misMatch.setUniProtId(sdif.getPdbx_seq_db_accession_code());
    misMatch.setSeqNum(sdif.getSeq_num());
    List<SeqMisMatch> mms=misMatchMap.get(sdif.getPdbx_pdb_strand_id());
    if (mms == null) {
      mms=new ArrayList<SeqMisMatch>();
      misMatchMap.put(sdif.getPdbx_pdb_strand_id(),mms);
    }
    mms.add(misMatch);
  }
  for (  String chainId : misMatchMap.keySet()) {
    try {
      Chain c=structure.getChainByPDB(chainId);
      c.setSeqMisMatches(misMatchMap.get(chainId));
    }
 catch (    Exception e) {
      logger.warn("String_Node_Str" + chainId);
    }
  }
}