def export_sbgn(model):
    import lxml.etree
    import lxml.builder
    from pysb.bng import generate_equations
    from indra.assemblers.sbgn import SBGNAssembler
    logger.info('Generating reaction network with BNG for SBGN export. ' +
                'This could take a long time.')
    generate_equations(model)
    sa = SBGNAssembler()
    glyphs = {}
    for idx, species in enumerate(model.species):
        glyph = sa._glyph_for_complex_pattern(species)
        if glyph is None:
            continue
        sa._map.append(glyph)
        glyphs[idx] = glyph
    for reaction in model.reactions:
        reactants = set(reaction['reactants']) - set(reaction['products'])
        products = set(reaction['products']) - set(reaction['reactants'])
        controllers = set(reaction['reactants']) & set(reaction['products'])
        process_glyph = sa._process_glyph('process')
        if not reactants:
            glyph_id = sa._none_glyph()
            sa._arc('consumption', glyph_id, process_glyph)
        else:
            for r in reactants:
                glyph = glyphs.get(r)
                if glyph is None:
                    glyph_id = sa._none_glyph()
                else:
                    glyph_id = glyph.attrib['id']
                sa._arc('consumption', glyph_id, process_glyph)
        if not products:
            glyph_id = sa._none_glyph()
            sa._arc('production', process_glyph, glyph_id)
        else:
            for p in products:
                glyph = glyphs.get(p)
                if glyph is None:
                    glyph_id = sa._none_glyph()
                else:
                    glyph_id = glyph.attrib['id']
                sa._arc('production', process_glyph, glyph_id)
        for c in controllers:
            glyph = glyphs[c]
            sa._arc('catalysis', glyph.attrib['id'], process_glyph)
    sbgn_str = sa.print_model().decode('utf-8')
    return sbgn_str