1 /** 2 * \file layout_example1_L3.java 3 * \brief SBML Layout example 4 * \author Ralph Gauges 5 * \author Akiya Jouraku 6 * \author Frank Bergmann (adapted to use libsbml-5 package version) 7 * 8 /* Copyright 2004 European Media Laboratories Research gGmbH 9 * 10 * This library is free software; you can redistribute it and/or modify it 11 * under the terms of the GNU Lesser General Public License as published 12 * by the Free Software Foundation; either version 2.1 of the License, or 13 * any later version. 14 * 15 * This library is distributed in the hope that it will be useful, but 16 * WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF 17 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and 18 * documentation provided hereunder is on an "as is" basis, and the 19 * European Media Laboratories Research gGmbH have no obligations to 20 * provide maintenance, support, updates, enhancements or modifications. 21 * In no event shall the European Media Laboratories Research gGmbH be 22 * liable to any party for direct, indirect, special, incidental or 23 * consequential damages, including lost profits, arising out of the use of 24 * this software and its documentation, even if the European Media 25 * Laboratories Research gGmbH have been advised of the possibility of such 26 * damage. See the GNU Lesser General Public License for more details. 27 * 28 * You should have received a copy of the GNU Lesser General Public License 29 * along with this library; if not, write to the Free Software Foundation, 30 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 31 * 32 * The original code contained here was initially developed by: 33 * 34 * Ralph Gaugess 35 * Bioinformatics Group 36 * European Media Laboratories Research gGmbH 37 * Schloss-Wolfsbrunnenweg 31c 38 * 69118 Heidelberg 39 * Germany 40 * 41 * http://www.eml-research.de/english/Research/BCB/ 42 * mailto:ralph.gauges@eml-r.villa-bosch.de 43 * 44 * Contributor(s): 45 */ 46 47 import org.sbml.libsbml.*; 48 49 public class layout_example1_L3 { 50 51 /** 52 * @param args 53 */ main(String[] args)54 public static void main(String[] args) { 55 56 System.loadLibrary("sbmlj"); 57 // 58 // Creates an SBMLNamespaces object with the given SBML level, version 59 // package name, package version. 60 // 61 // (NOTE) By defualt, the name of package (i.e. "layout") will be used 62 // if the arugment for the prefix is missing or empty. Thus the argument 63 // for the prefix can be added as follows: 64 // 65 // SBMLNamespaces sbmlns(3,1,"layout",1,"LAYOUT"); 66 // 67 68 SBMLNamespaces sbmlns = new SBMLNamespaces (3, 1, "layout", 1); 69 70 // 71 // (NOTES) The above code creating an SBMLNamespaces object can be replaced 72 // with one of the following other styles. 73 // 74 // (1) Creates an SBMLNamespace object with a SBML core namespace and then 75 // adds a layout package namespace to the object. 76 // 77 // SBMLNamespaces sbmlns(3,1); 78 // sbmlns.addPkgNamespace("layout",1); 79 // 80 // OR 81 // 82 // SBMLNamespaces sbmlns(3,1); 83 // sbmlns.addNamespace(LayoutExtension::XmlnsL3V1V1,"layout"); 84 // 85 // (2) Creates a LayoutPkgNamespaces object (SBMLNamespace derived class for 86 // layout package. The class is basically used for createing an SBase derived 87 // objects belonging to the layout package) with the given SBML level, version, 88 // and package version 89 // 90 // LayoutPkgNamespaces sbmlns(3,1,1); 91 // 92 93 // create the document 94 95 SBMLDocument document = new SBMLDocument (sbmlns); 96 97 // set the "required" attribute of layout package to "true" 98 document.setPkgRequired ("layout", false); 99 100 // create the Model 101 102 Model model = document.createModel (); 103 model.setId ("TestModel"); 104 document.setModel (model); 105 106 107 // create the Compartment 108 109 Compartment compartment = model.createCompartment (); 110 compartment.setId ("Compartment_1"); 111 compartment.setConstant (true); 112 113 // create the Species 114 115 Species species1 = model.createSpecies (); 116 species1.setId ("Species_1"); 117 species1.setCompartment (compartment.getId ()); 118 species1.setHasOnlySubstanceUnits (false); 119 species1.setBoundaryCondition (false); 120 species1.setConstant (false); 121 122 Species species2 = model.createSpecies (); 123 species2.setId ("Species_2"); 124 species2.setCompartment (compartment.getId ()); 125 species2.setHasOnlySubstanceUnits (false); 126 species2.setBoundaryCondition (false); 127 species2.setConstant (false); 128 129 // create the Reactions 130 131 Reaction reaction1 = model.createReaction (); 132 reaction1.setId ("Reaction_1"); 133 reaction1.setReversible (false); 134 reaction1.setFast (false); 135 136 SpeciesReference reference1 = reaction1.createReactant (); 137 reference1.setSpecies (species1.getId ()); 138 reference1.setId ("SpeciesReference_1"); 139 reference1.setConstant (false); 140 141 142 SpeciesReference reference2 = reaction1.createProduct (); 143 reference2.setSpecies (species2.getId ()); 144 reference2.setId ("SpeciesReference_2"); 145 reference2.setConstant (false); 146 147 Reaction reaction2 = model.createReaction (); 148 reaction2.setId ("Reaction_2"); 149 reaction2.setReversible (false); 150 reaction2.setFast (false); 151 152 SpeciesReference reference3 = reaction2.createReactant (); 153 reference3.setSpecies (species2.getId ()); 154 reference3.setId ("SpeciesReference_3"); 155 reference3.setConstant (false); 156 157 SpeciesReference reference4 = reaction2.createProduct (); 158 reference4.setSpecies (species1.getId ()); 159 reference4.setId ("SpeciesReference_4"); 160 reference4.setConstant (false); 161 162 163 // create the Layout 164 165 // 166 // set the LayoutPkgNamespaces for Level 3 Version1 Layout Version 1 167 // 168 LayoutPkgNamespaces layoutns = new LayoutPkgNamespaces (3, 1, 1); 169 170 // 171 // Get a LayoutModelPlugin object plugged in the model object. 172 // 173 // The type of the returned value of SBase::getPlugin() function is SBasePlugin, and 174 // thus the value needs to be casted for the corresponding derived class. 175 // 176 SBasePlugin basePlugin = (model.getPlugin ("layout")); 177 LayoutModelPlugin mplugin = (LayoutModelPlugin)basePlugin; 178 179 if (mplugin == null) { 180 System.err.println("[Fatal Error] Layout Extension Level " 181 + layoutns.getLevel () + " Version " 182 + layoutns.getVersion () + " package version " 183 + layoutns.getPackageVersion () + " is not registered."); 184 System.exit(1); 185 } 186 187 // 188 // Creates a Layout object via LayoutModelPlugin object. 189 // 190 Layout layout = mplugin.createLayout (); 191 192 layout.setId ("Layout_1"); 193 Dimensions dim = new Dimensions (layoutns, 400.0, 220.0); 194 layout.setDimensions (dim); 195 196 197 // create the CompartmentGlyph 198 199 CompartmentGlyph compartmentGlyph = layout.createCompartmentGlyph (); 200 compartmentGlyph.setId ("CompartmentGlyph_1"); 201 compartmentGlyph.setCompartmentId (compartment.getId ()); 202 BoundingBox bb = new BoundingBox (layoutns, "bb1", 5, 5, 390, 210); 203 compartmentGlyph.setBoundingBox (bb); 204 205 206 // create the SpeciesGlyphs 207 208 SpeciesGlyph speciesGlyph1 = layout.createSpeciesGlyph (); 209 speciesGlyph1.setId ("SpeciesGlyph_1"); 210 speciesGlyph1.setSpeciesId (species1.getId ()); 211 bb = new BoundingBox (layoutns, "bb2", 80, 26, 240, 24); 212 speciesGlyph1.setBoundingBox (bb); 213 214 TextGlyph textGlyph1 = layout.createTextGlyph (); 215 textGlyph1.setId ("TextGlyph_01"); 216 bb = new BoundingBox (layoutns, "bbA", 92, 26, 228, 24); 217 textGlyph1.setBoundingBox (bb); 218 textGlyph1.setOriginOfTextId (speciesGlyph1.getId ()); 219 textGlyph1.setGraphicalObjectId (speciesGlyph1.getId ()); 220 221 SpeciesGlyph speciesGlyph2 = layout.createSpeciesGlyph (); 222 speciesGlyph2.setId ("SpeciesGlyph_2"); 223 speciesGlyph2.setSpeciesId (species2.getId ()); 224 bb = new BoundingBox (layoutns, "bb3", 80, 170, 240, 24); 225 speciesGlyph2.setBoundingBox (bb); 226 227 TextGlyph textGlyph2 = layout.createTextGlyph (); 228 textGlyph2.setId ("TextGlyph_02"); 229 bb = new BoundingBox (layoutns, "bbB", 92, 170, 228, 24); 230 textGlyph2.setBoundingBox (bb); 231 textGlyph2.setOriginOfTextId (speciesGlyph2.getId ()); 232 textGlyph2.setGraphicalObjectId (speciesGlyph2.getId ()); 233 234 // create the ReactionGlyphs 235 236 ReactionGlyph reactionGlyph1 = layout.createReactionGlyph (); 237 reactionGlyph1.setId ("ReactionGlyph_1"); 238 reactionGlyph1.setReactionId (reaction1.getId ()); 239 240 Curve reactionCurve1 = reactionGlyph1.getCurve (); 241 LineSegment ls = reactionCurve1.createLineSegment (); 242 Point p = new Point (layoutns, 165, 105); 243 ls.setStart (p); 244 p = new Point (layoutns, 165, 115); 245 ls.setEnd (p); 246 247 ReactionGlyph reactionGlyph2 = layout.createReactionGlyph (); 248 reactionGlyph2.setId ("ReactionGlyph_2"); 249 reactionGlyph2.setReactionId (reaction2.getId ()); 250 251 Curve reactionCurve2 = reactionGlyph2.getCurve (); 252 ls = reactionCurve2.createLineSegment (); 253 p = new Point (layoutns, 235, 105); 254 ls.setStart (p); 255 p = new Point (layoutns, 235, 115); 256 ls.setEnd (p); 257 258 // add the SpeciesReferenceGlyphs 259 260 SpeciesReferenceGlyph speciesReferenceGlyph1 = reactionGlyph1.createSpeciesReferenceGlyph (); 261 speciesReferenceGlyph1.setId ("SpeciesReferenceGlyph_1"); 262 speciesReferenceGlyph1.setSpeciesGlyphId (speciesGlyph1.getId ()); 263 speciesReferenceGlyph1.setSpeciesReferenceId (reference1.getId ()); 264 speciesReferenceGlyph1.setRole (libsbml.SPECIES_ROLE_SUBSTRATE); 265 266 Curve speciesReferenceCurve1 = speciesReferenceGlyph1.getCurve (); 267 CubicBezier cb = speciesReferenceCurve1.createCubicBezier (); 268 p = new Point (layoutns, 165, 105); 269 cb.setStart (p); 270 p = new Point (layoutns, 165, 90); 271 cb.setBasePoint1 (p); 272 p = new Point (layoutns, 165, 90); 273 cb.setBasePoint2 (p); 274 p = new Point (layoutns, 195, 60); 275 cb.setEnd (p); 276 277 SpeciesReferenceGlyph speciesReferenceGlyph2 = reactionGlyph1.createSpeciesReferenceGlyph (); 278 speciesReferenceGlyph2.setId ("SpeciesReferenceGlyph_2"); 279 speciesReferenceGlyph2.setSpeciesGlyphId (speciesGlyph2.getId ()); 280 speciesReferenceGlyph2.setSpeciesReferenceId (reference2.getId ()); 281 speciesReferenceGlyph2.setRole (libsbml.SPECIES_ROLE_PRODUCT); 282 283 Curve speciesReferenceCurve2 = speciesReferenceGlyph2.getCurve (); 284 cb = speciesReferenceCurve2.createCubicBezier (); 285 p = new Point (layoutns, 165, 115); 286 cb.setStart (p); 287 p = new Point (layoutns, 165, 130); 288 cb.setBasePoint1 (p); 289 p = new Point (layoutns, 165, 130); 290 cb.setBasePoint2 (p); 291 p = new Point (layoutns, 195, 160); 292 cb.setEnd (p); 293 294 295 SpeciesReferenceGlyph speciesReferenceGlyph3 = reactionGlyph2.createSpeciesReferenceGlyph (); 296 speciesReferenceGlyph3.setId ("SpeciesReferenceGlyph_3"); 297 speciesReferenceGlyph3.setSpeciesGlyphId (speciesGlyph2.getId ()); 298 speciesReferenceGlyph3.setSpeciesReferenceId (reference3.getId ()); 299 speciesReferenceGlyph3.setRole (libsbml.SPECIES_ROLE_SUBSTRATE); 300 301 Curve speciesReferenceCurve3 = speciesReferenceGlyph3.getCurve (); 302 cb = speciesReferenceCurve3.createCubicBezier (); 303 p = new Point (layoutns, 235, 115); 304 cb.setStart (p); 305 p = new Point (layoutns, 235, 130); 306 cb.setBasePoint1 (p); 307 p = new Point (layoutns, 235, 130); 308 cb.setBasePoint2 (p); 309 p = new Point (layoutns, 205, 160); 310 cb.setEnd (p); 311 312 SpeciesReferenceGlyph speciesReferenceGlyph4 = reactionGlyph2.createSpeciesReferenceGlyph (); 313 speciesReferenceGlyph4.setId ("SpeciesReferenceGlyph_4"); 314 speciesReferenceGlyph4.setSpeciesGlyphId (speciesGlyph1.getId ()); 315 speciesReferenceGlyph4.setSpeciesReferenceId (reference4.getId ()); 316 speciesReferenceGlyph4.setRole (libsbml.SPECIES_ROLE_PRODUCT); 317 318 Curve speciesReferenceCurve4 = speciesReferenceGlyph4.getCurve (); 319 cb = speciesReferenceCurve4.createCubicBezier (); 320 p = new Point (layoutns, 235, 105); 321 cb.setStart (p); 322 p = new Point (layoutns, 235, 90); 323 cb.setBasePoint1 (p); 324 p = new Point (layoutns, 235, 90); 325 cb.setBasePoint2 (p); 326 p = new Point (layoutns, 205, 60); 327 cb.setEnd (p); 328 329 libsbml.writeSBML (document, "layout_example1_L3-java.xml"); 330 331 } 332 333 } 334 335