{"id":3,"date":"2012-09-25T16:31:30","date_gmt":"2012-09-25T13:31:30","guid":{"rendered":"http:\/\/mednis.info\/wp\/?p=3"},"modified":"2012-10-02T13:25:56","modified_gmt":"2012-10-02T10:25:56","slug":"how-to-create-an-sbml-file-using-libsbml-in-python","status":"publish","type":"post","link":"http:\/\/mednis.info\/wp\/?p=3","title":{"rendered":"How to create an SBML file using libSBML in Python"},"content":{"rendered":"<p>This tutorial is intended as a quick introduction on how to create an SBML file using libSBML. For a full developer&#8217;s guide, please see <a href=\"http:\/\/sbml.org\/Software\/libSBML\/docs\/python-api\/\" title=\"libSBML Python API\" target=\"_blank\">libSBML Python API<\/a>.<\/p>\n<p><code>from libsbml import *<br \/>\ndocument = SBMLDocument()<br \/>\nmodel = document.createModel(2, 4) # SBML level and version <\/code><\/p>\n<p><strong>##First you have to create compartments<\/strong><br \/>\n<code>c1 = model.createCompartment()<br \/>\nc1.setName('Forest')<br \/>\nc1.setId('comp_FOREST')<\/code><\/p>\n<p><em>## Set the volume of compartments<\/em><br \/>\n<code>c1.setVolume(1000)<\/code><\/p>\n<p><em>## Continue with other compartments<\/em><br \/>\n<code>c2 = model.createCompartment()<br \/>\nc2.setName('Meadow')<br \/>\nc2.setId('comp_Meadow')<br \/>\nc2.setVolume(1000)<\/code><\/p>\n<p><strong>## When you have finished with compartments, proceed with species.<\/strong><br \/>\n<code>s1 = model.createSpecies()<br \/>\ns1.setName('Foxes')<br \/>\ns1.setId('spec_FOXES')<br \/>\ns1.setCompartment('comp_FOREST')<br \/>\ns1.setInitialAmount(10)<\/p>\n<p>s2 = model.createSpecies()<br \/>\ns2.setName('Rabbits')<br \/>\ns2.setId('spec_RABBITS')<br \/>\ns2.setCompartment('comp_FOREST')<br \/>\ns2.setInitialAmount(50)<\/p>\n<p>s3 = model.createSpecies()<br \/>\ns3.setName('Snakes')<br \/>\ns3.setId('spec_Snakes')<br \/>\ns3.setCompartment('comp_Meadow')<br \/>\ns3.setInitialAmount(100)<br \/>\n<\/code><\/p>\n<p><strong>## When you are done with compartments and species, create reactions.<\/strong><br \/>\n<code>r1 = model.createReaction()<br \/>\nr1.setName('Foxes eat rabbits')<br \/>\nr1.setId('R1')<br \/>\n<\/code><\/p>\n<p><strong>## Create reactants and products<\/strong><br \/>\n<code>reac1 = r1.createReactant()<br \/>\nreac1.setSpecies('spec_RABBITS')<br \/>\nprod1 = r1.createProduct()<br \/>\nprod1.setSpecies('spec_FOXES')<br \/>\n<\/code><\/p>\n<p><em>## if necessary, set Stoichiometry<\/em><br \/>\n<code>reac1.setStoichiometry(2) # 2 rabbits<br \/>\nprod1.setStoichiometry(1) # 1 fox<br \/>\n<\/code><\/p>\n<p><em>Notice that we create seemingly independent objects for comprartments, reaction, reactant and product. We set some values to the properties of these objects and never actually add these elements to the model. Thats because they are automatically added. You can try this inside a loop and it will still work.<\/em><\/p>\n<p><strong>##Now when you have done whith your model you have to add it to the document.<\/strong><br \/>\n<code>document.setModel(model)<\/code><\/p>\n<p><em>## If you wish you can add optional information.<\/em><br \/>\n<code>model.setName('My test model')<br \/>\nmodel.setId('MyModelID')<\/code><\/p>\n<p><strong>##Save to file.<\/strong><br \/>\n<code>writeSBMLToFile(document,'name_of_your_model.xml')<\/code><\/p>\n<p>That&#8217;s it! Copy&#038;paste this code and try it yourself!<br \/>\nPlease note that this tutorial is realy basic. For more comprehensive examples, please see the <code>examples\/<\/code> folder in the libSBML source tree.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial is intended as a quick introduction on how to create an SBML file using libSBML. For a full developer&#8217;s guide, please see libSBML Python API. from libsbml import * document = SBMLDocument() model = document.createModel(2, 4) # SBML level and version ##First you have to create compartments c1 = model.createCompartment() c1.setName(&#8216;Forest&#8217;) c1.setId(&#8216;comp_FOREST&#8217;) ## &hellip; <a href=\"http:\/\/mednis.info\/wp\/?p=3\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to create an SBML file using libSBML in Python<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,4],"tags":[5,42,43],"_links":{"self":[{"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3"}],"collection":[{"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3"}],"version-history":[{"count":20,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3\/revisions"}],"predecessor-version":[{"id":33,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3\/revisions\/33"}],"wp:attachment":[{"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mednis.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}