Program: 16875
Project: 16875
Buggy source:
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 {
    logger.debug("String_Node_Str");
  }
  structure.addModel(current_model);
  for (  StructAsym asym : structAsyms) {
    logger.debug("String_Node_Str" + asym.getEntity_id() + "String_Node_Str"+ asym.getId());
    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");
    for (    EntitySrcGen esg : entitySrcGens) {
      String eId=esg.getEntity_id();
      if (!eId.equals(asym.getEntity_id()))       continue;
      int eIdInt=0;
      try {
        eIdInt=Integer.parseInt(eId);
      }
 catch (      NumberFormatException e) {
        logger.warn("String_Node_Str",eId);
      }
      Compound c=structure.getCompoundById(eIdInt);
      if (c == null) {
        c=createNewCompoundFromESG(esg,eIdInt);
        List<Compound> compounds=structure.getCompounds();
        compounds.add(c);
        structure.setCompounds(compounds);
      }
      c.addChain(s);
    }
    for (    EntitySrcNat esn : entitySrcNats) {
      String eId=esn.getEntity_id();
      if (!eId.equals(asym.getEntity_id()))       continue;
      int eIdInt=0;
      try {
        eIdInt=Integer.parseInt(eId);
      }
 catch (      NumberFormatException e) {
        logger.warn("String_Node_Str",eId);
      }
      Compound c=structure.getCompoundById(eIdInt);
      if (c == null) {
        c=createNewCompoundFromESN(esn,eIdInt);
        List<Compound> compounds=structure.getCompounds();
        compounds.add(c);
        structure.setCompounds(compounds);
      }
      c.addChain(s);
    }
    for (    EntitySrcSyn ess : entitySrcSyns) {
      String eId=ess.getEntity_id();
      if (!eId.equals(asym.getEntity_id()))       continue;
      int eIdInt=0;
      try {
        eIdInt=Integer.parseInt(eId);
      }
 catch (      NumberFormatException e) {
        logger.warn("String_Node_Str",eId);
      }
      Compound c=structure.getCompoundById(eIdInt);
      if (c == null) {
        c=createNewCompoundFromESS(ess,eIdInt);
        List<Compound> compounds=structure.getCompounds();
        compounds.add(c);
        structure.setCompounds(compounds);
      }
      c.addChain(s);
    }
  }
  if (params.isAlignSeqRes()) {
    SeqRes2AtomAligner aligner=new SeqRes2AtomAligner();
    List<Chain> atomList=structure.getModel(0);
    for (    Chain seqResChain : seqResChains) {
      Chain atomChain=aligner.getMatchingAtomRes(seqResChain,atomList);
      List<Group> seqResGroups=seqResChain.getAtomGroups();
      for (int seqResPos=0; seqResPos < seqResGroups.size(); seqResPos++) {
        Group seqresG=seqResGroups.get(seqResPos);
        boolean found=false;
        for (        Group atomG : atomChain.getAtomGroups()) {
          int internalNr=getInternalNr(atomG);
          if (seqresG.getResidueNumber().getSeqNum() == internalNr) {
            seqResGroups.set(seqResPos,atomG);
            found=true;
            break;
          }
        }
        if (!found)         seqresG.setResidueNumber(null);
      }
      atomChain.setSeqResGroups(seqResGroups);
    }
  }
  addBonds();
  Set<String> asymIds=asymStrandId.keySet();
  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 : asymIds) {
        if (chain.getChainID().equals(asym)) {
          String newChainId=asymStrandId.get(asym);
          logger.debug("String_Node_Str" + asym + "String_Node_Str"+ 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);
  }
  PDBHeader header=structure.getPDBHeader();
  header.setNrBioAssemblies(strucAssemblies.size());
  Map<String,List<BiologicalAssemblyTransformation>> transformationMap=new HashMap<String,List<BiologicalAssemblyTransformation>>();
  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);
    transformationMap.put(psa.getId(),transformations);
  }
  structure.getPDBHeader().setBioUnitTranformationMap(transformationMap);
  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((Matrix4d[])ncsOperators.toArray(new Matrix4d[ncsOperators.size()]));
  }
}

Fixed version (ground truth):
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 {
    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");
    for (    EntitySrcGen esg : entitySrcGens) {
      String eId=esg.getEntity_id();
      if (!eId.equals(asym.getEntity_id()))       continue;
      int eIdInt=0;
      try {
        eIdInt=Integer.parseInt(eId);
      }
 catch (      NumberFormatException e) {
        logger.warn("String_Node_Str",eId);
      }
      Compound c=structure.getCompoundById(eIdInt);
      if (c == null) {
        c=createNewCompoundFromESG(esg,eIdInt);
        List<Compound> compounds=structure.getCompounds();
        compounds.add(c);
        logger.debug("String_Node_Str",eIdInt,c.getMolName());
      }
    }
    for (    EntitySrcNat esn : entitySrcNats) {
      String eId=esn.getEntity_id();
      if (!eId.equals(asym.getEntity_id()))       continue;
      int eIdInt=0;
      try {
        eIdInt=Integer.parseInt(eId);
      }
 catch (      NumberFormatException e) {
        logger.warn("String_Node_Str",eId);
      }
      Compound c=structure.getCompoundById(eIdInt);
      if (c == null) {
        c=createNewCompoundFromESN(esn,eIdInt);
        List<Compound> compounds=structure.getCompounds();
        compounds.add(c);
        logger.debug("String_Node_Str",eIdInt,c.getMolName());
      }
    }
    for (    EntitySrcSyn ess : entitySrcSyns) {
      String eId=ess.getEntity_id();
      if (!eId.equals(asym.getEntity_id()))       continue;
      int eIdInt=0;
      try {
        eIdInt=Integer.parseInt(eId);
      }
 catch (      NumberFormatException e) {
        logger.warn("String_Node_Str",eId);
      }
      Compound c=structure.getCompoundById(eIdInt);
      if (c == null) {
        c=createNewCompoundFromESS(ess,eIdInt);
        List<Compound> compounds=structure.getCompounds();
        compounds.add(c);
        logger.debug("String_Node_Str",eIdInt,c.getMolName());
      }
    }
    int eId=0;
    try {
      eId=Integer.parseInt(asym.getEntity_id());
    }
 catch (    NumberFormatException e) {
      logger.warn("String_Node_Str",asym.getEntity_id());
    }
    Compound c=structure.getCompoundById(eId);
    if (c == null) {
      c=new Compound();
      c.setMolId(eId);
      Entity e=getEntity(eId);
      if (e != null && e.getType().equals("String_Node_Str")) {
        if (e != null)         c.setMolName(e.getPdbx_description());
        List<Compound> compounds=structure.getCompounds();
        compounds.add(c);
        logger.debug("String_Node_Str",eId,c.getMolName());
      }
    }
  }
  if (params.isAlignSeqRes()) {
    SeqRes2AtomAligner aligner=new SeqRes2AtomAligner();
    List<Chain> atomList=structure.getModel(0);
    for (    Chain seqResChain : seqResChains) {
      Chain atomChain=aligner.getMatchingAtomRes(seqResChain,atomList);
      List<Group> seqResGroups=seqResChain.getAtomGroups();
      for (int seqResPos=0; seqResPos < seqResGroups.size(); seqResPos++) {
        Group seqresG=seqResGroups.get(seqResPos);
        boolean found=false;
        for (        Group atomG : atomChain.getAtomGroups()) {
          int internalNr=getInternalNr(atomG);
          if (seqresG.getResidueNumber().getSeqNum() == internalNr) {
            seqResGroups.set(seqResPos,atomG);
            found=true;
            break;
          }
        }
        if (!found)         seqresG.setResidueNumber(null);
      }
      atomChain.setSeqResGroups(seqResGroups);
    }
  }
  addBonds();
  Set<String> asymIds=asymStrandId.keySet();
  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 : asymIds) {
        if (chain.getChainID().equals(asym)) {
          String newChainId=asymStrandId.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);
    for (    Chain chain : pdbChains) {
      String entityId=asymId2entityId.get(chain.getInternalChainID());
      int eId=Integer.parseInt(entityId);
      Compound compound=structure.getCompoundById(eId);
      logger.debug("String_Node_Str",chain.getChainID(),chain.getInternalChainID(),eId);
      compound.addChain(chain);
      chain.setCompound(compound);
    }
  }
  PDBHeader header=structure.getPDBHeader();
  header.setNrBioAssemblies(strucAssemblies.size());
  Map<String,List<BiologicalAssemblyTransformation>> transformationMap=new HashMap<String,List<BiologicalAssemblyTransformation>>();
  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);
    transformationMap.put(psa.getId(),transformations);
  }
  structure.getPDBHeader().setBioUnitTranformationMap(transformationMap);
  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((Matrix4d[])ncsOperators.toArray(new Matrix4d[ncsOperators.size()]));
  }
}