Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Tests/Unit/test_chemicalReactionNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_initial_condition_vector(self):
def test_get_all_species_containing(self):
# test that the species arument must be Species object
with self.assertRaisesRegex(
ValueError, 'species argument must be an instance of Species!'
ValueError, 'species argument must be an instance of Species'
):
self.crn.get_all_species_containing(species=self.species_list)

Expand Down
6 changes: 5 additions & 1 deletion Tests/Unit/test_component_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def test_enzyme():
products = 'P1'
enzyme = 'E1'

e = Enzyme(enzyme=enzyme, substrates=substrates, products=products)
e = Enzyme(
enzyme=enzyme, substrates=substrates, products=products,
)
e.default_mechanism=None # override failsafe

assert any([s.name == 'S1' for s in e.substrates])
assert any([p.name == 'P1' for p in e.products])
assert enzyme == e.enzyme.name
Expand Down
5 changes: 5 additions & 0 deletions Tests/Unit/test_component_membrane.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_DiffusibleMolecule():

assert dm.get_species().name == 'DP'

dm.default_mechanism = None # override failsafe
with pytest.raises(
KeyError,
match='Unable to find mechanism of type diffusion in Component',
Expand All @@ -46,6 +47,7 @@ def test_IntegralMembraneProtein():

assert imp.get_species().name == 'MP1'

imp.default_mechanism = None # override failsafe
with pytest.raises(
KeyError,
match='Unable to find mechanism of type membrane_insertion in Component',
Expand All @@ -70,6 +72,7 @@ def test_MembraneChannel():

assert mc.get_species().name == 'IMP1'

mc.default_mechanism = None # override failsafe
with pytest.raises(
KeyError,
match='Unable to find mechanism of type transport in Component',
Expand All @@ -94,6 +97,7 @@ def test_MembranePump():

assert mp.get_species().name == 'MPump1'

mp.default_mechanism = None # override failsafe
with pytest.raises(
KeyError,
match='Unable to find mechanism of type transport in Component',
Expand Down Expand Up @@ -125,6 +129,7 @@ def test_MembraneSensor():

assert ms.get_species().name == 'MSensor1'

ms.default_mechanism = None # override failsafe
with pytest.raises(
KeyError,
match='Unable to find mechanism of type membrane_sensor in Component',
Expand Down
6 changes: 6 additions & 0 deletions biocrnpyler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

# All utilities
from .utils import *
from .utils.plotting import (
plot_all_species_containing as plot_all_species_containing,
)
from .utils.plotting import (
plot_gene_expression_data as plot_gene_expression_data,
)

try:
from ._version import version as __version__
Expand Down
29 changes: 26 additions & 3 deletions biocrnpyler/components/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from ..core.component import Component
from ..core.reaction import Reaction
from ..core.species import Complex, Species
from ..mechanisms.binding import One_Step_Binding
from ..mechanisms.enzyme import MichaelisMenten
from ..mechanisms.metabolite import OneStepPathway


class DNA(Component):
Expand Down Expand Up @@ -402,7 +405,17 @@ def __init__(
else:
self.products.append(self.set_species(p))

Component.__init__(self=self, name=name, **kwargs)
if precursors is not None or products is not None:
default_mechanism = OneStepPathway()
else:
default_mechanism = None

Component.__init__(
self=self,
name=name,
default_mechanism=default_mechanism,
**kwargs,
)

def get_species(self) -> Species:
"""Get the metabolite species.
Expand Down Expand Up @@ -602,7 +615,12 @@ def __init__(
if name is None:
name = self.species.name

Component.__init__(self=self, name=name, **kwargs)
Component.__init__(
self=self,
name=name,
default_mechanism=One_Step_Binding(),
**kwargs,
)

def get_species(self) -> List[Species]:
"""Get the complex species.
Expand Down Expand Up @@ -773,7 +791,12 @@ def __init__(
self.substrates = substrates
self.products = products

Component.__init__(self=self, name=self.enzyme.name, **kwargs)
Component.__init__(
self=self,
name=self.enzyme.name,
default_mechanism=MichaelisMenten(),
**kwargs,
)

@property
def substrates(self) -> List:
Expand Down
8 changes: 6 additions & 2 deletions biocrnpyler/components/combinatorial_conformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ def __init__(

if name is None:
name = str(self.internal_polymer.name)
Component.__init__(self, name=name, **kwargs)
self.add_mechanism(One_Step_Reversible_Conformation_Change())
Component.__init__(
self,
name=name,
default_mechanism=One_Step_Reversible_Conformation_Change(),
**kwargs,
)

# Helper function to assert the correct class type
def _assert_conformation(self, states, input_name='states'):
Expand Down
60 changes: 49 additions & 11 deletions biocrnpyler/components/membrane.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
from ..core.compartment import Compartment
from ..core.component import Component
from ..core.species import Species
from ..mechanisms.signaling import Membrane_Signaling_Pathway_MM
from ..mechanisms.transport import (
Facilitated_Transport_MM,
Membrane_Protein_Integration,
Primary_Active_Transport_MM,
Simple_Diffusion,
Simple_Transport,
)


class DiffusibleMolecule(Component):
Expand Down Expand Up @@ -108,7 +116,11 @@ def __init__(
name = self.substrate.name + '_' + self.substrate.compartment.name

Component.__init__(
self=self, name=name, attributes=attributes, **kwargs
self=self,
name=name,
attributes=attributes,
default_mechanism=Simple_Diffusion(),
**kwargs,
)

def get_species(self):
Expand Down Expand Up @@ -334,7 +346,12 @@ def __init__(
+ self.membrane_protein.compartment.name
)

Component.__init__(self=self, name=name, **kwargs)
Component.__init__(
self=self,
name=name,
default_mechanism=Membrane_Protein_Integration(),
**kwargs,
)

def get_species(self):
"""Get the membrane protein species before insertion.
Expand Down Expand Up @@ -504,7 +521,7 @@ def __init__(
integral_membrane_protein = self.set_species(
integral_membrane_protein,
material_type='protein',
attributes='Passive' if direction is None else direction,
attributes=['Passive'] if direction is None else direction,
)
self.integral_membrane_protein = integral_membrane_protein

Expand Down Expand Up @@ -568,7 +585,12 @@ def __init__(
+ self.integral_membrane_protein.compartment.name
)

Component.__init__(self=self, name=name, **kwargs)
Component.__init__(
self=self,
name=name,
default_mechanism=Simple_Transport(),
**kwargs,
)

def get_species(self):
"""Get the integral membrane protein species.
Expand Down Expand Up @@ -782,14 +804,14 @@ def __init__(
self.membrane_pump = self.set_species(
membrane_pump,
material_type='protein',
attributes='Passive',
attributes=['Passive'],
)
self.membrane_pump.ATP = ATP
else:
self.membrane_pump = self.set_species(
membrane_pump,
material_type='protein',
attributes=direction,
attributes=[direction],
)
self.membrane_pump.ATP = ATP
if direction == 'Importer':
Expand All @@ -812,19 +834,19 @@ def __init__(
self.integral_membrane_protein = self.set_species(
membrane_pump,
material_type='protein',
attributes='Passive',
attributes=['Passive'],
)
elif membrane_pump.attributes[0] == 'Exporter':
self.membrane_pump = self.set_species(
membrane_pump,
material_type='protein',
attributes='Exporter',
attributes=['Exporter'],
)
elif membrane_pump.attributes[0] == 'Importer':
self.membrane_pump = self.set_species(
membrane_pump,
material_type='protein',
attributes='Importer',
attributes=['Importer'],
)
self.energy = self.set_species(
'ATP',
Expand Down Expand Up @@ -867,7 +889,18 @@ def __init__(
+ self.membrane_pump.compartment.name
)

Component.__init__(self=self, name=name, **kwargs)
# Determine the default mechanism
if 'Passive' in self.membrane_pump.attributes:
default_mechanism = Primary_Active_Transport_MM()
else:
default_mechanism = Facilitated_Transport_MM()

Component.__init__(
self=self,
name=name,
default_mechanism=default_mechanism,
**kwargs,
)

def get_species(self):
"""Get the membrane pump protein species.
Expand Down Expand Up @@ -1137,7 +1170,12 @@ def __init__(
+ self.membrane_sensor_protein.compartment.name
)

Component.__init__(self=self, name=name, **kwargs)
Component.__init__(
self=self,
name=name,
default_mechanism=Membrane_Signaling_Pathway_MM(),
**kwargs,
)

def get_species(self):
"""Get the membrane sensor protein species.
Expand Down
15 changes: 9 additions & 6 deletions biocrnpyler/core/chemical_reaction_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def initial_condition_vector(
return x0

def get_all_species_containing(
self, species: Species, return_as_strings=False
self, species: Union[Species, str], return_as_strings=False
):
"""Find all species (complexes) that contain a given species.

Expand All @@ -613,8 +613,9 @@ def get_all_species_containing(

Parameters
----------
species : Species
The species to search for within other species.
species : Species or str
The species to search for within other species. If given as a
string, returns all species with that string as part of the name.
return_as_strings : bool, default=False
If True, returns species as string representations. If False,
returns actual Species objects.
Expand Down Expand Up @@ -645,13 +646,15 @@ def get_all_species_containing(

"""
return_list = []
if not isinstance(species, Species):
if not isinstance(species, (Species, str)):
raise ValueError(
"species argument must be an instance of Species!"
"species argument must be an instance of Species or str."
)

for s in self._species:
if species in s.get_species(recursive=True):
if (
isinstance(species, str) and species in s.name
) or species in s.get_species(recursive=True):
if return_as_strings:
return_list.append(repr(s))
else:
Expand Down
Loading
Loading