File: groups_example1.py

package info (click to toggle)
libsbml 5.19.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 157,308 kB
  • sloc: cpp: 972,686; xml: 332,385; python: 128,188; cs: 57,289; ansic: 54,332; java: 27,244; makefile: 9,740; perl: 9,114; sh: 8,777; ruby: 4,760; javascript: 1,605; php: 202; csh: 3
file content (116 lines) | stat: -rw-r--r-- 3,294 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python3
# 
#  @file    groups_example1.py
#  @brief   SBML Groups example
#  @author  Akiya Jouraku
#  @author  Frank Bergmann (python port)
#  
#  $Id: example1.py 11938 2010-09-20 02:04:23Z mhucka $
#  $HeadURL: https://sbml.svn.sourceforge.net/svnroot/sbml/branches/libsbml-5/examples/groups/example1.py $
#  
#  This file is part of libSBML.  Please visit http:# sbml.org for more
#  information about SBML, and the latest version of libSBML.
#  

from libsbml import *
# 
#  Creates an SBMLNamespaces object with the given SBML level, version
#  package name, package version.
# 
#  (NOTE) By default, the name of package (i.e. "groups") will be used
#  if the argument for the prefix is missing or empty. Thus the argument
#  for the prefix can be added as follows:
# 
#     SBMLNamespaces sbmlns(3,1,"groups",1,"GROUP");
# 

sbmlns = SBMLNamespaces(3,1,"groups",1)

# 
#  (NOTES) The above code creating an SBMLNamespaces object can be replaced 
#          with one of the following other styles.
# 
#  (1) Creates an SBMLNamespace object with a SBML core namespace and then
#      adds a groups package namespace to the object. 
# 
#          SBMLNamespaces sbmlns(3,1);
#          sbmlns.addPkgNamespace("groups",1);
# 
#           OR
# 
#          SBMLNamespaces sbmlns(3,1);
#          sbmlns.addNamespace(GroupsExtension::XmlnsL3V1V1,"groups");
# 
#  (2) Creates a GroupsPkgNamespaces object (SBMLNamespace derived class for
#      groups package. The class is basically used for creating an SBase derived
#      objects defined in the groups package) with the given SBML level, version, 
#      and package version
# 
#         GroupsPkgNamespaces sbmlns(3,1,1);
#      


#  create the document

document = SBMLDocument(sbmlns)
document.setPkgRequired('groups', False)

#  create the Model

model= document.createModel()

#  create the Compartment

compartment = model.createCompartment()
compartment.setId("cytosol")
compartment.setConstant(True)

compartment=model.createCompartment()
compartment.setId("mitochon")
compartment.setConstant(True)

#  create the Species

species = model.createSpecies()
species.setId("ATPc")
species.setCompartment("cytosol")
species.setInitialConcentration(1)
species.setHasOnlySubstanceUnits(False)
species.setBoundaryCondition(False)
species.setConstant(False)

species = model.createSpecies()
species.setId("ATPm")
species.setCompartment("mitochon")
species.setInitialConcentration(2)
species.setHasOnlySubstanceUnits(False)
species.setBoundaryCondition(False)
species.setConstant(False)

#  create the Groups

# 
#  Get a GroupsModelPlugin object plugged in the model object.
# 
#  The type of the returned value of SBase::getPlugin() function is SBasePlugin, and
#  thus the value needs to be casted for the corresponding derived class. 
# 
mplugin = model.getPlugin("groups")

# 
#  Creates a Group object via GroupsModelPlugin object.
# 
group = mplugin.createGroup()

group.setId("ATP")
group.setKind("classification")
group.setSBOTerm("SBO:0000252")

member = group.createMember()
member.setIdRef("ATPc")

member = group.createMember()
member.setIdRef("ATPm")

writeSBML(document,"groups_example1-python.xml")