def import_sbml(document):
    """
    Import a model from a SBMLDocument.

    Parameters
    ----------
    document : SBMLDocument

    Returns
    -------
    model : NetworkModel
    y0 : dict
        Initial condition.
    volume : Real or Real3, optional
        A size of the simulation volume.

    """
    from ecell4.util.decorator import generate_ratelaw

    m = document.getModel()

    if m.getNumCompartments() == 0:
        raise RuntimeError("No compartment was found.")
    elif m.getNumCompartments() > 1:
        warnings.warn(
            "[{:d}] compartments were found.".format(m.getNumCompartments())
            + " The second or later ones would be omitted.")

    comp1 = m.getCompartment(0)
    volume = comp1.getVolume()

    y0 = {}
    sid_map = {}
    for s1 in m.getListOfSpecies():
        sid = s1.getId()
        serial = s1.getName()
        sid_map[sid] = serial
        value = s1.getInitialAmount()
        if value != 0:
            y0[serial] = value

    kmap = {}
    for p1 in m.getListOfParameters():
        pid = p1.getId()
        if not re.match("^k[0-9]+$", pid):
            warnings.warn(
                "Parameter [{:s}] was just ommited.".format(pid))
        rid = "r{:s}".format(pid[1: ])
        kmap[rid] = p1.getValue()

    is_ode = False
    rrs = []

    for r1 in m.getListOfReactions():
        rid = r1.getId()
        print(rid)

        is_massaction = (rid in kmap.keys())
        if is_massaction:
            k = kmap[rid]
        else:
            kinetic_law = r1.getKineticLaw()
            formula = kinetic_law.getFormula()
            k = replace_parseobj(formula, sid_map)

        reactants, products = [], []

        #XXX: The order of reactants is not consistent
        for s1 in r1.getListOfReactants():
            sid = s1.getSpecies()
            if sid not in sid_map:
                raise RuntimeError(
                    "Unknown Species' Id [{:s}] was given".format(sid))
            serial = sid_map[sid]
            coef = s1.getStoichiometry()
            reactants.append((serial, coef))

        #XXX: The order of products is not consistent
        for s1 in r1.getListOfProducts():
            sid = s1.getSpecies()
            if sid not in sid_map:
                raise RuntimeError(
                    "Unknown Species' Id [{:s}] was given".format(sid))
            serial = sid_map[sid]
            coef = s1.getStoichiometry()
            products.append((serial, coef))

        if (not is_massaction
            or len(reactants) > 2
            or any([coef not in (1, 2) for sp, coef in reactants])
            or any([not coef.is_integer() for sp, coef in products])
            or (len(reactants) == 2 and (reactants[0][1] == 2 or reactants[1][1] == 2))):
            rr = ecell4_base.core.ReactionRule()

            if is_massaction:
                desc = ecell4_base.core.ReactionRuleDescriptorMassAction(k)
            else:
                func = generate_ratelaw(k, rr)
                desc = ecell4_base.core.ReactionRuleDescriptorPyfunc(func, k)

            desc.set_reactant_coefficients([coef for _, coef in reactants])
            desc.set_product_coefficients([coef for _, coef in products])

            rr.set_descriptor(desc)
        else:
            if len(reactants) == 1 and reactants[0][1] == 2:
                reactants[0] = (reactants[0][0], 1)
                reactants.append(reactants[0])

            rr = ecell4_base.core.ReactionRule()
            for serial, coef in reactants:
                rr.add_reactant(ecell4_base.core.Species(serial))
            for serial, coef in products:
                for _ in range(int(coef)):
                    rr.add_product(ecell4_base.core.Species(serial))
            rr.set_k(k)

        rrs.append(rr)

    m = ecell4_base.core.NetworkModel()
    for rr in rrs:
        m.add_reaction_rule(rr)

    return m, y0, volume
Import a model from a SBMLDocument.

    Parameters
    ----------
    document : SBMLDocument

    Returns
    -------
    model : NetworkModel
    y0 : dict
        Initial condition.
    volume : Real or Real3, optional
        A size of the simulation volume.