libSBML Python API  5.18.0
qual_example1.py

An example of creating a model using SBML Level 3 Qualitative Models.

1 #!/usr/bin/env python
2 ##
3 ## @file qual_example1.py
4 ## @brief Qual Example
5 ## @author Sarah Keating
6 ##
7 ## <!--------------------------------------------------------------------------
8 ## This sample program is distributed under a different license than the rest
9 ## of libSBML. This program uses the open-source MIT license, as follows:
10 ##
11 ## Copyright (c) 2013-2018 by the California Institute of Technology
12 ## (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
13 ## and the University of Heidelberg (Germany), with support from the National
14 ## Institutes of Health (USA) under grant R01GM070923. All rights reserved.
15 ##
16 ## Permission is hereby granted, free of charge, to any person obtaining a
17 ## copy of this software and associated documentation files (the "Software"),
18 ## to deal in the Software without restriction, including without limitation
19 ## the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 ## and/or sell copies of the Software, and to permit persons to whom the
21 ## Software is furnished to do so, subject to the following conditions:
22 ##
23 ## The above copyright notice and this permission notice shall be included in
24 ## all copies or substantial portions of the Software.
25 ##
26 ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29 ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 ## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 ## DEALINGS IN THE SOFTWARE.
33 ##
34 ## Neither the name of the California Institute of Technology (Caltech), nor
35 ## of the European Bioinformatics Institute (EMBL-EBI), nor of the University
36 ## of Heidelberg, nor the names of any contributors, may be used to endorse
37 ## or promote products derived from this software without specific prior
38 ## written permission.
39 ## ------------------------------------------------------------------------ -->
40 
41 import sys
42 import os.path
43 import libsbml
44 from libsbml import *
45 
46 
47 def main (args):
48  # Creates an SBMLNamespaces object with the given SBML level, version
49  # package name, package version.
50  sbmlns = SBMLNamespaces(3, 1, "qual", 1)
51 
52  # Creates an SBMLDocument object
53  document = SBMLDocument(sbmlns)
54 
55  # mark qual as required
56  document.setPackageRequired("qual", True)
57 
58  # create the Model
59  model = document.createModel()
60 
61  # create the Compartment
62  compartment = model.createCompartment()
63  compartment.setId("c")
64  compartment.setConstant(True)
65 
66  # Get a QualModelPlugin object plugged in the model object.
67  mplugin = model.getPlugin("qual")
68 
69  # create the QualitativeSpecies
70  qs = mplugin.createQualitativeSpecies()
71  qs.setId("s1")
72  qs.setCompartment("c")
73  qs.setConstant(False)
74  qs.setInitialLevel(1)
75  qs.setMaxLevel(4)
76  qs.setName("sss")
77 
78  # create the Transition
79  t = mplugin.createTransition()
80  t.setId("d")
81  t.setSBOTerm(1)
82 
83  i = t.createInput()
84  i.setId("RD")
85  i.setQualitativeSpecies("s1")
86  i.setTransitionEffect(INPUT_TRANSITION_EFFECT_NONE)
87  i.setSign(INPUT_SIGN_NEGATIVE)
88  i.setThresholdLevel(2)
89  i.setName("aa")
90 
91  o = t.createOutput()
92  o.setId("wd")
93  o.setQualitativeSpecies("s1")
94  o.setTransitionEffect(OUTPUT_TRANSITION_EFFECT_PRODUCTION)
95  o.setOutputLevel(2)
96  o.setName("aa")
97 
98  ft = t.createFunctionTerm()
99  math = parseL3Formula("geq(s1, 2)")
100  ft.setResultLevel(1)
101  ft.setMath(math)
102 
103  dt = t.createDefaultTerm()
104  dt.setResultLevel(2)
105 
106  writeSBML(document, "qual_example1.xml")
107 
108 
109 if __name__ == '__main__':
110  main(sys.argv)