Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions bionetgen/modelapi/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ class Pattern:
"""

def __init__(
self, molecules=[], bonds=None, compartment=None, label=None, canonicalize=False
self,
molecules=None,
bonds=None,
compartment=None,
label=None,
canonicalize=False,
):
self.molecules = molecules
self.molecules = list(molecules) if molecules is not None else []
self._bonds = bonds
self.compartment = compartment
self.label = label
Expand Down Expand Up @@ -287,6 +292,12 @@ def __eq__(self, other):
other.canonical_label is not None
):
return self.canonical_label == other.canonical_label
if len(self.molecules) != len(other.molecules):
logger.debug(
f"molecule count differs: {len(self.molecules)} vs {len(other.molecules)}",
loc=loc,
)
return False
# now we can check contents
for molecule in self:
if molecule not in other.molecules:
Expand Down Expand Up @@ -374,8 +385,6 @@ def __getitem__(self, key):
def __iter__(self):
return self.molecules.__iter__()

# TODO: Implement __contains__


class Molecule:
"""
Expand All @@ -402,9 +411,9 @@ class Molecule:
(for molecule types) "states"
"""

def __init__(self, name="0", components=[], compartment=None, label=None):
def __init__(self, name="0", components=None, compartment=None, label=None):
self._name = name
self._components = components
self._components = list(components) if components is not None else []
self._compartment = compartment
self._label = label
self.canonical_order = None
Expand Down Expand Up @@ -435,6 +444,12 @@ def __eq__(self, other):
# we can check canonical labels
if self.canonical_label != other.canonical_label:
return False
if len(self.components) != len(other.components):
logger.debug(
f"component count differs: {len(self.components)} vs {len(other.components)}",
loc=loc,
)
return False
# check components now
for component in self:
if component not in other.components:
Expand Down Expand Up @@ -547,14 +562,14 @@ def label(self, value):
# print("Warning: Logical checks are not complete")
self._label = value

def _add_component(self, name, state=None, states=[]):
def _add_component(self, name, state=None, states=None):
comp_obj = Component()
comp_obj.name = name
comp_obj.state = state
comp_obj.states = states
comp_obj.states = list(states) if states is not None else []
self.components.append(comp_obj)

def add_component(self, name, state=None, states=[]):
def add_component(self, name, state=None, states=None):
# TODO: Add built-in logic here
# print("Warning: Logical checks are not complete")
self._add_component(name, state, states)
Expand Down
Loading