An example layout.
51 def createDimensions(width, height):
52 """Create a dimension object with given width and height""" 58 def createPoint(x, y):
59 """Create a point object with given coordinates""" 65 def createBoundingBox(id, x, y, width, height):
66 """Create a bounding box object with given coordinates and dimensions""" 76 document=SBMLDocument(2,1)
79 model=document.createModel(
"TestModel")
80 document.enablePackage(LayoutExtension.getXmlnsL2(),
"layout",
True)
84 compartment=model.createCompartment()
85 compartment.setId(
"Compartment_1")
88 species1=model.createSpecies()
89 species1.setId(
"Species_1")
90 species1.setCompartment(compartment.getId())
92 species2=model.createSpecies()
93 species2.setId(
"Species_2")
94 species2.setCompartment(compartment.getId())
98 reaction1=model.createReaction()
99 reaction1.setId(
"Reaction_1")
100 reaction1.setReversible(
False)
102 reference1=reaction1.createReactant()
103 reference1.setSpecies(species1.getId())
104 reference1.setId(
"SpeciesReference_1")
106 reference2=reaction1.createProduct()
107 reference2.setSpecies(species2.getId())
108 reference2.setId(
"SpeciesReference_2")
110 reaction2=model.createReaction()
111 reaction2.setId(
"Reaction_2")
112 reaction2.setReversible(
False)
114 reference3=reaction1.createReactant()
115 reference3.setSpecies(species2.getId())
116 reference3.setId(
"SpeciesReference_3")
118 reference4=reaction1.createProduct()
119 reference4.setSpecies(species1.getId())
120 reference4.setId(
"SpeciesReference_4")
123 mplugin = model.getPlugin(
"layout")
124 layout = mplugin.createLayout()
126 layout.setId(
"Layout_1")
127 layout.setDimensions(createDimensions(400.0,220.0))
132 compartmentGlyph=layout.createCompartmentGlyph()
133 compartmentGlyph.setId(
"CompartmentGlyph_1")
134 compartmentGlyph.setCompartmentId(compartment.getId())
135 compartmentGlyph.setBoundingBox(createBoundingBox(
"bb1",5,5,390,210))
140 speciesGlyph1=layout.createSpeciesGlyph()
141 speciesGlyph1.setId(
"SpeciesGlyph_1")
142 speciesGlyph1.setSpeciesId(species1.getId())
143 speciesGlyph1.setBoundingBox(createBoundingBox(
"bb2",80,26,240,24))
145 textGlyph1=layout.createTextGlyph()
146 textGlyph1.setId(
"TextGlyph_01")
147 textGlyph1.setBoundingBox(createBoundingBox(
"bbA",92,26,228,24))
148 textGlyph1.setOriginOfTextId(speciesGlyph1.getId())
149 textGlyph1.setGraphicalObjectId(speciesGlyph1.getId())
152 speciesGlyph2=layout.createSpeciesGlyph()
153 speciesGlyph2.setId(
"SpeciesGlyph_2")
154 speciesGlyph2.setSpeciesId(species2.getId())
155 speciesGlyph2.setBoundingBox(createBoundingBox(
"bb3",80,170,240,24))
157 textGlyph2=layout.createTextGlyph()
158 textGlyph2.setId(
"TextGlyph_02")
159 textGlyph2.setBoundingBox(createBoundingBox(
"bbB",92,170,228,24))
160 textGlyph2.setOriginOfTextId(speciesGlyph2.getId())
161 textGlyph2.setGraphicalObjectId(speciesGlyph2.getId())
165 reactionGlyph1=layout.createReactionGlyph()
166 reactionGlyph1.setId(
"ReactionGlyph_1")
167 reactionGlyph1.setReactionId(reaction1.getId())
169 reactionCurve1=reactionGlyph1.getCurve()
170 ls=reactionCurve1.createLineSegment()
171 ls.setStart(createPoint(165,105))
172 ls.setEnd(createPoint(165,115))
174 reactionGlyph2=layout.createReactionGlyph()
175 reactionGlyph2.setId(
"ReactionGlyph_1")
176 reactionGlyph2.setReactionId(reaction2.getId())
178 reactionCurve2=reactionGlyph2.getCurve()
179 ls=reactionCurve2.createLineSegment()
180 ls.setStart(createPoint(235,105))
181 ls.setEnd(createPoint(235,115))
185 speciesReferenceGlyph1=reactionGlyph1.createSpeciesReferenceGlyph()
186 speciesReferenceGlyph1.setId(
"SpeciesReferenceGlyph_1")
187 speciesReferenceGlyph1.setSpeciesGlyphId(speciesGlyph1.getId())
188 speciesReferenceGlyph1.setSpeciesReferenceId(reference1.getId())
189 speciesReferenceGlyph1.setRole(SPECIES_ROLE_SUBSTRATE)
191 speciesReferenceCurve1=speciesReferenceGlyph1.getCurve()
192 cb=speciesReferenceCurve1.createCubicBezier()
193 cb.setStart(createPoint(165,105))
194 cb.setBasePoint1(createPoint(165,90))
195 cb.setBasePoint2(createPoint(165,90))
196 cb.setEnd(createPoint(195,60))
198 speciesReferenceGlyph2=reactionGlyph1.createSpeciesReferenceGlyph()
199 speciesReferenceGlyph2.setId(
"SpeciesReferenceGlyph_2")
200 speciesReferenceGlyph2.setSpeciesGlyphId(speciesGlyph2.getId())
201 speciesReferenceGlyph2.setSpeciesReferenceId(reference2.getId())
202 speciesReferenceGlyph2.setRole(SPECIES_ROLE_PRODUCT)
204 speciesReferenceCurve2=speciesReferenceGlyph2.getCurve()
205 cb=speciesReferenceCurve2.createCubicBezier()
206 cb.setStart(createPoint(165,115))
207 cb.setBasePoint1(createPoint(165,130))
208 cb.setBasePoint2(createPoint(165,130))
209 cb.setEnd(createPoint(195,160))
212 speciesReferenceGlyph3=reactionGlyph2.createSpeciesReferenceGlyph()
213 speciesReferenceGlyph3.setId(
"SpeciesReferenceGlyph_3")
214 speciesReferenceGlyph3.setSpeciesGlyphId(speciesGlyph2.getId())
215 speciesReferenceGlyph3.setSpeciesReferenceId(reference3.getId())
216 speciesReferenceGlyph3.setRole(SPECIES_ROLE_SUBSTRATE)
218 speciesReferenceCurve3=speciesReferenceGlyph3.getCurve()
219 cb=speciesReferenceCurve3.createCubicBezier()
220 cb.setStart(createPoint(235,115))
221 cb.setBasePoint1(createPoint(235,130))
222 cb.setBasePoint2(createPoint(235,130))
223 cb.setEnd(createPoint(205,160))
225 speciesReferenceGlyph4=reactionGlyph2.createSpeciesReferenceGlyph()
226 speciesReferenceGlyph4.setId(
"SpeciesReferenceGlyph_4")
227 speciesReferenceGlyph4.setSpeciesGlyphId(speciesGlyph1.getId())
228 speciesReferenceGlyph4.setSpeciesReferenceId(reference4.getId())
229 speciesReferenceGlyph4.setRole(SPECIES_ROLE_PRODUCT)
231 speciesReferenceCurve4=speciesReferenceGlyph4.getCurve()
232 cb=speciesReferenceCurve4.createCubicBezier()
233 cb.setStart(createPoint(235,105))
234 cb.setBasePoint1(createPoint(235,90))
235 cb.setBasePoint2(createPoint(235,90))
236 cb.setEnd(createPoint(205,60))
239 writeSBML(document,
"TestModel1-python.xml")