Program: 16482
Project: 16482
Buggy source:
public void write(MmtfDecoderInterface decoder){
  this.mmtfDecoderInterface=decoder;
  MmtfUtils.fixMicroheterogenity(structure);
  MmtfUtils.calculateDsspSecondaryStructure(structure);
  Map<String,Integer> chainIdToIndexMap=MmtfUtils.getChainIdToIndexMap(structure);
  List<Chain> allChains=MmtfUtils.getAllChains(structure);
  List<Atom> allAtoms=MmtfUtils.getAllAtoms(structure);
  int numBonds=MmtfUtils.getNumBonds(allAtoms);
  mmtfDecoderInterface.initStructure(numBonds,allAtoms.size(),MmtfUtils.getNumGroups(structure),allChains.size(),structure.nrModels(),structure.getPDBCode());
  PDBHeader pdbHeader=structure.getPDBHeader();
  PDBCrystallographicInfo xtalInfo=pdbHeader.getCrystallographicInfo();
  mmtfDecoderInterface.setHeaderInfo(pdbHeader.getRfree(),1.0f,pdbHeader.getResolution(),pdbHeader.getTitle(),MmtfUtils.dateToIsoString(pdbHeader.getDepDate()),MmtfUtils.techniquesToStringArray(pdbHeader.getExperimentalTechniques()));
  mmtfDecoderInterface.setXtalInfo(MmtfUtils.getSpaceGroupAsString(xtalInfo.getSpaceGroup()),MmtfUtils.getUnitCellAsArray(xtalInfo));
  storeBioassemblyInformation(chainIdToIndexMap,pdbHeader.getBioAssemblies());
  storeEntityInformation(allChains,structure.getEntityInfos());
  for (int modelIndex=0; modelIndex < structure.nrModels(); modelIndex++) {
    List<Chain> modelChains=structure.getChains(modelIndex);
    mmtfDecoderInterface.setModelInfo(modelIndex,modelChains.size());
    for (int chainInModelIndex=0; chainInModelIndex < modelChains.size(); chainInModelIndex++) {
      Chain chain=modelChains.get(chainInModelIndex);
      List<Group> groups=chain.getAtomGroups();
      List<Group> sequenceGroups=chain.getSeqResGroups();
      mmtfDecoderInterface.setChainInfo(chain.getChainID(),chain.getInternalChainID(),groups.size());
      for (int groupInChainIndex=0; groupInChainIndex < groups.size(); groupInChainIndex++) {
        Group group=groups.get(groupInChainIndex);
        List<Atom> atomsInGroup=MmtfUtils.getAtomsForGroup(group);
        ChemComp chemComp=group.getChemComp();
        Character insCode=group.getResidueNumber().getInsCode();
        if (insCode == null) {
          insCode=MmtfBean.UNAVAILABLE_CHAR_VALUE;
        }
        mmtfDecoderInterface.setGroupInfo(group.getPDBName(),group.getResidueNumber().getSeqNum(),insCode.charValue(),chemComp.getPdbx_type(),atomsInGroup.size(),chemComp.getBonds().size(),chemComp.getOne_letter_code().charAt(0),sequenceGroups.indexOf(group));
        for (        Atom atom : atomsInGroup) {
          mmtfDecoderInterface.setAtomInfo(atom.getName(),atom.getPDBserial(),atom.getAltLoc().charValue(),(float)atom.getX(),(float)atom.getY(),(float)atom.getZ(),atom.getOccupancy(),atom.getTempFactor(),atom.getElement().toString(),atom.getCharge());
          addBonds(atom,atomsInGroup,allAtoms);
        }
      }
    }
  }
  mmtfDecoderInterface.finalizeStructure();
}

Fixed version (ground truth):
public void write(MmtfDecoderInterface decoder){
  this.mmtfDecoderInterface=decoder;
  MmtfUtils.fixMicroheterogenity(structure);
  MmtfUtils.calculateDsspSecondaryStructure(structure);
  Map<String,Integer> chainIdToIndexMap=MmtfUtils.getChainIdToIndexMap(structure);
  List<Chain> allChains=MmtfUtils.getAllChains(structure);
  List<Atom> allAtoms=MmtfUtils.getAllAtoms(structure);
  int numBonds=MmtfUtils.getNumBonds(allAtoms);
  mmtfDecoderInterface.initStructure(numBonds,allAtoms.size(),MmtfUtils.getNumGroups(structure),allChains.size(),structure.nrModels(),structure.getPDBCode());
  PDBHeader pdbHeader=structure.getPDBHeader();
  PDBCrystallographicInfo xtalInfo=pdbHeader.getCrystallographicInfo();
  mmtfDecoderInterface.setHeaderInfo(pdbHeader.getRfree(),1.0f,pdbHeader.getResolution(),pdbHeader.getTitle(),MmtfUtils.dateToIsoString(pdbHeader.getDepDate()),MmtfUtils.techniquesToStringArray(pdbHeader.getExperimentalTechniques()));
  mmtfDecoderInterface.setXtalInfo(MmtfUtils.getSpaceGroupAsString(xtalInfo.getSpaceGroup()),MmtfUtils.getUnitCellAsArray(xtalInfo));
  storeBioassemblyInformation(chainIdToIndexMap,pdbHeader.getBioAssemblies());
  storeEntityInformation(allChains,structure.getEntityInfos());
  for (int modelIndex=0; modelIndex < structure.nrModels(); modelIndex++) {
    List<Chain> modelChains=structure.getChains(modelIndex);
    mmtfDecoderInterface.setModelInfo(modelIndex,modelChains.size());
    for (int chainInModelIndex=0; chainInModelIndex < modelChains.size(); chainInModelIndex++) {
      Chain chain=modelChains.get(chainInModelIndex);
      List<Group> groups=chain.getAtomGroups();
      List<Group> sequenceGroups=chain.getSeqResGroups();
      mmtfDecoderInterface.setChainInfo(chain.getChainID(),chain.getInternalChainID(),groups.size());
      for (int groupInChainIndex=0; groupInChainIndex < groups.size(); groupInChainIndex++) {
        Group group=groups.get(groupInChainIndex);
        List<Atom> atomsInGroup=MmtfUtils.getAtomsForGroup(group);
        ChemComp chemComp=group.getChemComp();
        Character insCode=group.getResidueNumber().getInsCode();
        if (insCode == null) {
          insCode=MmtfBean.UNAVAILABLE_CHAR_VALUE;
        }
        mmtfDecoderInterface.setGroupInfo(group.getPDBName(),group.getResidueNumber().getSeqNum(),insCode.charValue(),chemComp.getType(),atomsInGroup.size(),MmtfUtils.getNumBondsInGroup(atomsInGroup),chemComp.getOne_letter_code().charAt(0),sequenceGroups.indexOf(group));
        for (        Atom atom : atomsInGroup) {
          mmtfDecoderInterface.setAtomInfo(atom.getName(),atom.getPDBserial(),atom.getAltLoc().charValue(),(float)atom.getX(),(float)atom.getY(),(float)atom.getZ(),atom.getOccupancy(),atom.getTempFactor(),atom.getElement().toString(),atom.getCharge());
          addBonds(atom,atomsInGroup,allAtoms);
        }
      }
    }
  }
  mmtfDecoderInterface.finalizeStructure();
}