diff --git a/bionetgen/modelapi/pattern.py b/bionetgen/modelapi/pattern.py index 0205453..810233b 100644 --- a/bionetgen/modelapi/pattern.py +++ b/bionetgen/modelapi/pattern.py @@ -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): @@ -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): diff --git a/bionetgen/modelapi/xmlparsers.py b/bionetgen/modelapi/xmlparsers.py index ff9f9e3..2f3f5fa 100644 --- a/bionetgen/modelapi/xmlparsers.py +++ b/bionetgen/modelapi/xmlparsers.py @@ -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(quantity) + f = float(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): @@ -262,7 +274,7 @@ def parse_xml(self, xml) -> list: return patterns -###### Parsers ###### +###### Parsers ###### class ParameterBlockXML(XMLObj): """ PatternBlock XML parser, derived from XMLObj. Creates diff --git a/tests/models/hybrid_test.bngl b/tests/models/hybrid_test.bngl index a8bf61a..ba381de 100644 --- a/tests/models/hybrid_test.bngl +++ b/tests/models/hybrid_test.bngl @@ -30,7 +30,7 @@ begin observables Species R2 R==2 Species R3 R==3 Species R4 R==4 - Species R5 R>4 + Species R5 R<4 end observables begin reaction rules R(l!1).L(r!1) -> R(l) + L(r) koff @@ -45,5 +45,4 @@ 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()"]}) \ No newline at end of file