Skip to content

Commit

Permalink
Beginning of parsing branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cjarmstrong97 committed Sep 21, 2021
1 parent 74e3f43 commit 29357ec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 4 additions & 0 deletions bionetgen/modelapi/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def __init__(self, molecules=[], bonds=None, compartment=None, label=None):
self._label = label
self.fixed = False
self.MatchOnce = False
self.relation = None
self.quantity = None

@property
def compartment(self):
Expand Down Expand Up @@ -73,6 +75,8 @@ def __str__(self):
if imol > 0:
sstr += "."
sstr += str(mol)
if self.relation is not None:
sstr += f"{self.relation}{self.quantity}"
return sstr

def __repr__(self):
Expand Down
22 changes: 17 additions & 5 deletions bionetgen/modelapi/xmlparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,29 @@ def parse_xml(self, xml) -> Pattern:
bonds = BondsXML()
pattern._bonds = bonds
self._bonds = bonds
#
# check for compartment and add if exists
if "@compartment" in xml:
pattern.compartment = xml["@compartment"]
#
# check for label and add if exists
if "@label" in xml:
pattern.label = xml["@label"]
#
# check to see if pattern is fixed
if "@Fixed" in xml:
if xml["@Fixed"] == "1":
pattern.fixed = True
#
# check for relation & quantity, add if exist
if ("@relation" in xml) and ("@quantity" in xml):
relation = xml["@relation"]
quantity = xml["@quantity"]
pattern.relation = relation
try:
n = int(pattern.quantity)
f = float(pattern.quantity)
if n == f:
pattern.quantity = quantity
except ValueError as e:
print("Quantity needs to be an integer")
# check for either list of molecules or single molecule, add if exist
mols = xml["ListOfMolecules"]["Molecule"]
molecules = []
if isinstance(mols, list):
Expand Down Expand Up @@ -262,7 +274,7 @@ def parse_xml(self, xml) -> list:
return patterns


###### Parsers ######
###### Parsers ######
class ParameterBlockXML(XMLObj):
"""
PatternBlock XML parser, derived from XMLObj. Creates
Expand Down
7 changes: 5 additions & 2 deletions tests/models/hybrid_test.bngl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ begin observables
Species R3 R==3
Species R4 R==4
Species R5 R>4
Species R5le R<=4
Species R5l R<4
Species R5ge R>=4
end observables
begin reaction rules
R(l!1).L(r!1) -> R(l) + L(r) koff
Expand All @@ -45,5 +48,5 @@ end population maps
end model

## actions ##
generate_hybrid_model({overwrite=>1, execute=>1, verbose=>1, safe=>0, actions=>["writeXML()"]})

#generate_hybrid_model({overwrite=>1, execute=>1, verbose=>1, safe=>0, actions=>["writeXML()"]})
writeXML()

0 comments on commit 29357ec

Please sign in to comment.