libSBML Python API  5.10.0
 All Classes Namespaces Files Functions Variables Modules Pages
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-2014 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 from libsbml import *
44 
45 
46 def main (args):
47  # Creates an SBMLNamespaces object with the given SBML level, version
48  # package name, package version.
49  sbmlns = SBMLNamespaces(3, 1, "qual", 1);
50 
51  # Creates an SBMLDocument object
52  document = SBMLDocument(sbmlns);
53 
54  # mark qual as required
55  document.setPackageRequired("qual", True);
56 
57  # create the Model
58  model = document.createModel();
59 
60  # create the Compartment
61  compartment = model.createCompartment();
62  compartment.setId("c");
63  compartment.setConstant(True);
64 
65  # Get a QualModelPlugin object plugged in the model object.
66  mplugin = model.getPlugin("qual");
67 
68  # create the QualitativeSpecies
69  qs = mplugin.createQualitativeSpecies();
70  qs.setId("s1");
71  qs.setCompartment("c");
72  qs.setConstant(False);
73  qs.setInitialLevel(1);
74  qs.setMaxLevel(4);
75  qs.setName("sss");
76 
77  # create the Transition
78  t = mplugin.createTransition();
79  t.setId("d");
80  t.setSBOTerm(1);
81 
82  i = t.createInput();
83  i.setId("RD");
84  i.setQualitativeSpecies("s1");
85  i.setTransitionEffect("none");
86  i.setSign("negative");
87  i.setThresholdLevel(2);
88  i.setName("aa");
89 
90  o = t.createOutput();
91  o.setId("wd");
92  o.setQualitativeSpecies("s1");
93  o.setTransitionEffect("production");
94  o.setOutputLevel(2);
95  o.setName("aa");
96 
97  ft = t.createFunctionTerm();
98  math = parseL3Formula("geq(s1, 2)");
99  ft.setResultLevel(1);
100  ft.setMath(math);
101 
102  dt = t.createDefaultTerm();
103  dt.setResultLevel(2);
104 
105  writeSBML(document, "qual_example1.xml");
106 
107 
108 
109 
110 if __name__ == '__main__':
111  main(sys.argv)