libSBML Python API  5.18.0
groups_example1.py

Using the 'groups' package example.

1 #!/usr/bin/env python
2 #
3 # @file groups_example1.py
4 # @brief SBML Groups example
5 # @author Akiya Jouraku
6 # @author Frank Bergmann (python port)
7 #
8 # $Id: example1.py 11938 2010-09-20 02:04:23Z mhucka $
9 # $HeadURL: https://sbml.svn.sourceforge.net/svnroot/sbml/branches/libsbml-5/examples/groups/example1.py $
10 #
11 # This file is part of libSBML. Please visit http:# sbml.org for more
12 # information about SBML, and the latest version of libSBML.
13 #
14 
15 from libsbml import *
16 #
17 # Creates an SBMLNamespaces object with the given SBML level, version
18 # package name, package version.
19 #
20 # (NOTE) By default, the name of package (i.e. "groups") will be used
21 # if the argument for the prefix is missing or empty. Thus the argument
22 # for the prefix can be added as follows:
23 #
24 # SBMLNamespaces sbmlns(3,1,"groups",1,"GROUP");
25 #
26 
27 sbmlns = SBMLNamespaces(3,1,"groups",1)
28 
29 #
30 # (NOTES) The above code creating an SBMLNamespaces object can be replaced
31 # with one of the following other styles.
32 #
33 # (1) Creates an SBMLNamespace object with a SBML core namespace and then
34 # adds a groups package namespace to the object.
35 #
36 # SBMLNamespaces sbmlns(3,1);
37 # sbmlns.addPkgNamespace("groups",1);
38 #
39 # OR
40 #
41 # SBMLNamespaces sbmlns(3,1);
42 # sbmlns.addNamespace(GroupsExtension::XmlnsL3V1V1,"groups");
43 #
44 # (2) Creates a GroupsPkgNamespaces object (SBMLNamespace derived class for
45 # groups package. The class is basically used for creating an SBase derived
46 # objects defined in the groups package) with the given SBML level, version,
47 # and package version
48 #
49 # GroupsPkgNamespaces sbmlns(3,1,1);
50 #
51 
52 
53 # create the document
54 
55 document = SBMLDocument(sbmlns)
56 document.setPkgRequired('groups', False)
57 
58 # create the Model
59 
60 model= document.createModel()
61 
62 # create the Compartment
63 
64 compartment = model.createCompartment()
65 compartment.setId("cytosol")
66 compartment.setConstant(True)
67 
68 compartment=model.createCompartment()
69 compartment.setId("mitochon")
70 compartment.setConstant(True)
71 
72 # create the Species
73 
74 species = model.createSpecies()
75 species.setId("ATPc")
76 species.setCompartment("cytosol")
77 species.setInitialConcentration(1)
78 species.setHasOnlySubstanceUnits(False)
79 species.setBoundaryCondition(False)
80 species.setConstant(False)
81 
82 species = model.createSpecies()
83 species.setId("ATPm")
84 species.setCompartment("mitochon")
85 species.setInitialConcentration(2)
86 species.setHasOnlySubstanceUnits(False)
87 species.setBoundaryCondition(False)
88 species.setConstant(False)
89 
90 # create the Groups
91 
92 #
93 # Get a GroupsModelPlugin object plugged in the model object.
94 #
95 # The type of the returned value of SBase::getPlugin() function is SBasePlugin, and
96 # thus the value needs to be casted for the corresponding derived class.
97 #
98 mplugin = model.getPlugin("groups")
99 
100 #
101 # Creates a Group object via GroupsModelPlugin object.
102 #
103 group = mplugin.createGroup()
104 
105 group.setId("ATP")
106 group.setKind("classification")
107 group.setSBOTerm("SBO:0000252")
108 
109 member = group.createMember()
110 member.setIdRef("ATPc")
111 
112 member = group.createMember()
113 member.setIdRef("ATPm")
114 
115 writeSBML(document,"groups_example1-python.xml")
116