Simple example of writing a model that uses the SBML Level 3 Flux Balance Constraints package.
43 sbmlns = SBMLNamespaces(3,1,
"fbc",1)
47 document = SBMLDocument(sbmlns)
51 document.setPackageRequired(
"fbc",
False)
55 model= document.createModel()
59 compartment = model.createCompartment()
60 compartment.setId(
"compartment")
61 compartment.setConstant(
True)
62 compartment.setSize(1)
66 species = model.createSpecies()
67 species.setId(
"Node1")
68 species.setCompartment(
"compartment")
69 species.setBoundaryCondition(
False)
70 species.setConstant(
False)
71 species.setHasOnlySubstanceUnits(
False)
75 splugin = species.getPlugin(
"fbc")
76 if splugin
is not None:
79 splugin.setChemicalFormula(
"C2H5Br")
82 species = model.createSpecies()
83 species.setId(
"Node2")
84 species.setCompartment(
"compartment")
85 species.setBoundaryCondition(
False)
86 species.setConstant(
False)
87 species.setHasOnlySubstanceUnits(
False)
89 species = model.createSpecies()
90 species.setId(
"Node3")
91 species.setCompartment(
"compartment")
92 species.setBoundaryCondition(
False)
93 species.setConstant(
False)
94 species.setHasOnlySubstanceUnits(
False)
96 species = model.createSpecies()
97 species.setId(
"Node4")
98 species.setCompartment(
"compartment")
99 species.setBoundaryCondition(
False)
100 species.setConstant(
False)
101 species.setHasOnlySubstanceUnits(
False)
103 species = model.createSpecies()
104 species.setId(
"Node5")
105 species.setCompartment(
"compartment")
106 species.setBoundaryCondition(
False)
107 species.setConstant(
False)
108 species.setHasOnlySubstanceUnits(
False)
110 species = model.createSpecies()
111 species.setId(
"Node6")
112 species.setCompartment(
"compartment")
113 species.setBoundaryCondition(
False)
114 species.setConstant(
False)
115 species.setHasOnlySubstanceUnits(
False)
117 species = model.createSpecies()
118 species.setId(
"Node7")
119 species.setCompartment(
"compartment")
120 species.setBoundaryCondition(
False)
121 species.setConstant(
False)
122 species.setHasOnlySubstanceUnits(
False)
124 species = model.createSpecies()
125 species.setId(
"Node8")
126 species.setCompartment(
"compartment")
127 species.setBoundaryCondition(
False)
128 species.setConstant(
False)
129 species.setHasOnlySubstanceUnits(
False)
131 species = model.createSpecies()
132 species.setId(
"Node0")
133 species.setCompartment(
"compartment")
134 species.setBoundaryCondition(
True)
135 species.setConstant(
False)
136 species.setHasOnlySubstanceUnits(
False)
138 species = model.createSpecies()
139 species.setId(
"Node9")
140 species.setCompartment(
"compartment")
141 species.setBoundaryCondition(
True)
142 species.setConstant(
False)
143 species.setHasOnlySubstanceUnits(
False)
147 reaction = model.createReaction()
149 reaction.setReversible(
False)
150 reaction.setFast(
False)
151 reactant = reaction.createReactant()
152 reactant.setSpecies(
"Node0")
153 reactant.setStoichiometry(1)
154 reactant.setConstant(
True)
155 product = reaction.createProduct()
156 product.setSpecies(
"Node1")
157 product.setStoichiometry(1)
158 product.setConstant(
True)
160 reaction = model.createReaction()
162 reaction.setReversible(
False)
163 reaction.setFast(
False)
164 reactant = reaction.createReactant()
165 reactant.setSpecies(
"Node1")
166 reactant.setStoichiometry(1)
167 reactant.setConstant(
True)
168 product = reaction.createProduct()
169 product.setSpecies(
"Node2")
170 product.setStoichiometry(1)
171 product.setConstant(
True)
173 reaction = model.createReaction()
175 reaction.setReversible(
False)
176 reaction.setFast(
False)
177 reactant = reaction.createReactant()
178 reactant.setSpecies(
"Node2")
179 reactant.setStoichiometry(1)
180 reactant.setConstant(
True)
181 product = reaction.createProduct()
182 product.setSpecies(
"Node3")
183 product.setStoichiometry(1)
184 product.setConstant(
True)
186 reaction = model.createReaction()
188 reaction.setReversible(
False)
189 reaction.setFast(
False)
190 reactant = reaction.createReactant()
191 reactant.setSpecies(
"Node1")
192 reactant.setStoichiometry(1)
193 reactant.setConstant(
True)
194 product = reaction.createProduct()
195 product.setSpecies(
"Node4")
196 product.setStoichiometry(1)
197 product.setConstant(
True)
199 reaction = model.createReaction()
201 reaction.setReversible(
False)
202 reaction.setFast(
False)
203 reactant = reaction.createReactant()
204 reactant.setSpecies(
"Node4")
205 reactant.setStoichiometry(1)
206 reactant.setConstant(
True)
207 product = reaction.createProduct()
208 product.setSpecies(
"Node3")
209 product.setStoichiometry(1)
210 product.setConstant(
True)
212 reaction = model.createReaction()
214 reaction.setReversible(
False)
215 reaction.setFast(
False)
216 reactant = reaction.createReactant()
217 reactant.setSpecies(
"Node3")
218 reactant.setStoichiometry(1)
219 reactant.setConstant(
True)
220 product = reaction.createProduct()
221 product.setSpecies(
"Node5")
222 product.setStoichiometry(1)
223 product.setConstant(
True)
225 reaction = model.createReaction()
227 reaction.setReversible(
False)
228 reaction.setFast(
False)
229 reactant = reaction.createReactant()
230 reactant.setSpecies(
"Node5")
231 reactant.setStoichiometry(1)
232 reactant.setConstant(
True)
233 product = reaction.createProduct()
234 product.setSpecies(
"Node6")
235 product.setStoichiometry(1)
236 product.setConstant(
True)
238 reaction = model.createReaction()
240 reaction.setReversible(
False)
241 reaction.setFast(
False)
242 reactant = reaction.createReactant()
243 reactant.setSpecies(
"Node6")
244 reactant.setStoichiometry(1)
245 reactant.setConstant(
True)
246 product = reaction.createProduct()
247 product.setSpecies(
"Node7")
248 product.setStoichiometry(1)
249 product.setConstant(
True)
251 reaction = model.createReaction()
253 reaction.setReversible(
False)
254 reaction.setFast(
False)
255 reactant = reaction.createReactant()
256 reactant.setSpecies(
"Node5")
257 reactant.setStoichiometry(1)
258 reactant.setConstant(
True)
259 product = reaction.createProduct()
260 product.setSpecies(
"Node8")
261 product.setStoichiometry(1)
262 product.setConstant(
True)
264 reaction = model.createReaction()
266 reaction.setReversible(
False)
267 reaction.setFast(
False)
268 reactant = reaction.createReactant()
269 reactant.setSpecies(
"Node8")
270 reactant.setStoichiometry(1)
271 reactant.setConstant(
True)
272 product = reaction.createProduct()
273 product.setSpecies(
"Node7")
274 product.setStoichiometry(1)
275 product.setConstant(
True)
277 reaction = model.createReaction()
278 reaction.setId(
"J10")
279 reaction.setReversible(
False)
280 reaction.setFast(
False)
281 reactant = reaction.createReactant()
282 reactant.setSpecies(
"Node7")
283 reactant.setStoichiometry(1)
284 reactant.setConstant(
True)
285 product = reaction.createProduct()
286 product.setSpecies(
"Node9")
287 product.setStoichiometry(1)
288 product.setConstant(
True)
292 mplugin = model.getPlugin(
"fbc")
294 bound= mplugin.createFluxBound()
295 bound.setId(
"bound1")
296 bound.setReaction(
"J0")
297 bound.setOperation(
"equal")
300 objective = mplugin.createObjective()
301 objective.setId(
"obj1")
302 objective.setType(
"maximize")
304 mplugin.setActiveObjectiveId(
"obj1")
306 fluxObjective = objective.createFluxObjective()
307 fluxObjective.setReaction(
"J8")
308 fluxObjective.setCoefficient(1)