Program: 16869
Project: 16869
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.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");
    int eId=0;
    try {
      eId=Integer.parseInt(asym.getEntity_id());
    }
 catch (    NumberFormatException e) {
      logger.warn("String_Node_Str",asym.getEntity_id());
    }
    Entity e=getEntity(eId);
    for (    EntitySrcGen esg : entitySrcGens) {
      if (!esg.getEntity_id().equals(asym.getEntity_id()))       continue;
      Compound c=structure.getCompoundById(eId);
      if (c == null) {
        if (e != null && e.getType().equals("String_Node_Str")) {
          c=createNewCompoundFromESG(esg,eId);
          c.setMolName(e.getPdbx_description());
          structure.addCompound(c);
          logger.debug("String_Node_Str",eId,c.getMolName());
        }
      }
    }
    for (    EntitySrcNat esn : entitySrcNats) {
      if (!esn.getEntity_id().equals(asym.getEntity_id()))       continue;
      Compound c=structure.getCompoundById(eId);
      if (c == null) {
        if (e != null && e.getType().equals("String_Node_Str")) {
          c=createNewCompoundFromESN(esn,eId);
          c.setMolName(e.getPdbx_description());
          structure.addCompound(c);
          logger.debug("String_Node_Str",eId,c.getMolName());
        }
      }
    }
    for (    EntitySrcSyn ess : entitySrcSyns) {
      if (!ess.getEntity_id().equals(asym.getEntity_id()))       continue;
      Compound c=structure.getCompoundById(eId);
      if (c == null) {
        if (e != null && e.getType().equals("String_Node_Str")) {
          c=createNewCompoundFromESS(ess,eId);
          c.setMolName(e.getPdbx_description());
          structure.addCompound(c);
          logger.debug("String_Node_Str",eId,c.getMolName());
        }
      }
    }
    Compound c=structure.getCompoundById(eId);
    if (c == null) {
      c=new Compound();
      c.setMolId(eId);
      if (e != null && e.getType().equals("String_Node_Str")) {
        if (e != null)         c.setMolName(e.getPdbx_description());
        structure.addCompound(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);
      if (compound == null) {
        logger.warn("String_Node_Str",eId,chain.getChainID(),chain.getInternalChainID());
      }
 else {
        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()]));
  }
}

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");
    int eId=0;
    try {
      eId=Integer.parseInt(asym.getEntity_id());
    }
 catch (    NumberFormatException e) {
      logger.warn("String_Node_Str",asym.getEntity_id());
    }
    Entity e=getEntity(eId);
    for (    EntitySrcGen esg : entitySrcGens) {
      if (!esg.getEntity_id().equals(asym.getEntity_id()))       continue;
      Compound c=structure.getCompoundById(eId);
      if (c == null) {
        if (e != null && e.getType().equals("String_Node_Str")) {
          c=createNewCompoundFromESG(esg,eId);
          c.setMolName(e.getPdbx_description());
          structure.addCompound(c);
          logger.debug("String_Node_Str",eId,c.getMolName());
        }
      }
    }
    for (    EntitySrcNat esn : entitySrcNats) {
      if (!esn.getEntity_id().equals(asym.getEntity_id()))       continue;
      Compound c=structure.getCompoundById(eId);
      if (c == null) {
        if (e != null && e.getType().equals("String_Node_Str")) {
          c=createNewCompoundFromESN(esn,eId);
          c.setMolName(e.getPdbx_description());
          structure.addCompound(c);
          logger.debug("String_Node_Str",eId,c.getMolName());
        }
      }
    }
    for (    EntitySrcSyn ess : entitySrcSyns) {
      if (!ess.getEntity_id().equals(asym.getEntity_id()))       continue;
      Compound c=structure.getCompoundById(eId);
      if (c == null) {
        if (e != null && e.getType().equals("String_Node_Str")) {
          c=createNewCompoundFromESS(ess,eId);
          c.setMolName(e.getPdbx_description());
          structure.addCompound(c);
          logger.debug("String_Node_Str",eId,c.getMolName());
        }
      }
    }
    Compound c=structure.getCompoundById(eId);
    if (c == null) {
      c=new Compound();
      c.setMolId(eId);
      if (e != null && e.getType().equals("String_Node_Str")) {
        if (e != null)         c.setMolName(e.getPdbx_description());
        structure.addCompound(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);
      if (compound == null) {
        logger.warn("String_Node_Str",eId,chain.getChainID(),chain.getInternalChainID());
      }
 else {
        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()]));
  }
  structure.getCompounds();
}