def import_sbml(document):
from ecell4.util.decorator import generate_ratelaw<EOL>m = document.getModel()<EOL>if m.getNumCompartments() == <NUM_LIT:0>:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>elif m.getNumCompartments() > <NUM_LIT:1>:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>".format(m.getNumCompartments())<EOL>+ "<STR_LIT>")<EOL><DEDENT>comp1 = m.getCompartment(<NUM_LIT:0>)<EOL>volume = comp1.getVolume()<EOL>y0 = {}<EOL>sid_map = {}<EOL>for s1 in m.getListOfSpecies():<EOL><INDENT>sid = s1.getId()<EOL>serial = s1.getName()<EOL>sid_map[sid] = serial<EOL>value = s1.getInitialAmount()<EOL>if value != <NUM_LIT:0>:<EOL><INDENT>y0[serial] = value<EOL><DEDENT><DEDENT>kmap = {}<EOL>for p1 in m.getListOfParameters():<EOL><INDENT>pid = p1.getId()<EOL>if not re.match("<STR_LIT>", pid):<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>".format(pid))<EOL><DEDENT>rid = "<STR_LIT>".format(pid[<NUM_LIT:1>: ])<EOL>kmap[rid] = p1.getValue()<EOL><DEDENT>is_ode = False<EOL>rrs = []<EOL>for r1 in m.getListOfReactions():<EOL><INDENT>rid = r1.getId()<EOL>print(rid)<EOL>is_massaction = (rid in kmap.keys())<EOL>if is_massaction:<EOL><INDENT>k = kmap[rid]<EOL><DEDENT>else:<EOL><INDENT>kinetic_law = r1.getKineticLaw()<EOL>formula = kinetic_law.getFormula()<EOL>k = replace_parseobj(formula, sid_map)<EOL><DEDENT>reactants, products = [], []<EOL>for s1 in r1.getListOfReactants():<EOL><INDENT>sid = s1.getSpecies()<EOL>if sid not in sid_map:<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>".format(sid))<EOL><DEDENT>serial = sid_map[sid]<EOL>coef = s1.getStoichiometry()<EOL>reactants.append((serial, coef))<EOL><DEDENT>for s1 in r1.getListOfProducts():<EOL><INDENT>sid = s1.getSpecies()<EOL>if sid not in sid_map:<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>".format(sid))<EOL><DEDENT>serial = sid_map[sid]<EOL>coef = s1.getStoichiometry()<EOL>products.append((serial, coef))<EOL><DEDENT>if (not is_massaction<EOL>or len(reactants) > <NUM_LIT:2><EOL>or any([coef not in (<NUM_LIT:1>, <NUM_LIT:2>) for sp, coef in reactants])<EOL>or any([not coef.is_integer() for sp, coef in products])<EOL>or (len(reactants) == <NUM_LIT:2> and (reactants[<NUM_LIT:0>][<NUM_LIT:1>] == <NUM_LIT:2> or reactants[<NUM_LIT:1>][<NUM_LIT:1>] == <NUM_LIT:2>))):<EOL><INDENT>rr = ecell4_base.core.ReactionRule()<EOL>if is_massaction:<EOL><INDENT>desc = ecell4_base.core.ReactionRuleDescriptorMassAction(k)<EOL><DEDENT>else:<EOL><INDENT>func = generate_ratelaw(k, rr)<EOL>desc = ecell4_base.core.ReactionRuleDescriptorPyfunc(func, k)<EOL><DEDENT>desc.set_reactant_coefficients([coef for _, coef in reactants])<EOL>desc.set_product_coefficients([coef for _, coef in products])<EOL>rr.set_descriptor(desc)<EOL><DEDENT>else:<EOL><INDENT>if len(reactants) == <NUM_LIT:1> and reactants[<NUM_LIT:0>][<NUM_LIT:1>] == <NUM_LIT:2>:<EOL><INDENT>reactants[<NUM_LIT:0>] = (reactants[<NUM_LIT:0>][<NUM_LIT:0>], <NUM_LIT:1>)<EOL>reactants.append(reactants[<NUM_LIT:0>])<EOL><DEDENT>rr = ecell4_base.core.ReactionRule()<EOL>for serial, coef in reactants:<EOL><INDENT>rr.add_reactant(ecell4_base.core.Species(serial))<EOL><DEDENT>for serial, coef in products:<EOL><INDENT>for _ in range(int(coef)):<EOL><INDENT>rr.add_product(ecell4_base.core.Species(serial))<EOL><DEDENT><DEDENT>rr.set_k(k)<EOL><DEDENT>rrs.append(rr)<EOL><DEDENT>m = ecell4_base.core.NetworkModel()<EOL>for rr in rrs:<EOL><INDENT>m.add_reaction_rule(rr)<EOL><DEDENT>return m, y0, volume<EOL>
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.