Skip to content

Commit

Permalink
Split media update and uptake constraint processes
Browse files Browse the repository at this point in the history
  • Loading branch information
thalassemia committed Aug 31, 2023
1 parent 8bef769 commit a5eb30e
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 21 deletions.
6 changes: 4 additions & 2 deletions ecoli/composites/ecoli_configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"profile": false,
"processes": [
"bulk-timeline",
"media_update",
"exchange_data",

"ecoli-tf-unbinding",
Expand Down Expand Up @@ -91,9 +92,10 @@
}
},
"flow": {
"exchange_data": [],
"media_update": [],
"exchange_data": [["media_update"]],

"ecoli-tf-unbinding": [["exchange_data"]],
"ecoli-tf-unbinding": [["media_update"]],

"ecoli-equilibrium": [["ecoli-tf-unbinding"]],
"ecoli-two-component-system": [["ecoli-tf-unbinding"]],
Expand Down
2 changes: 0 additions & 2 deletions ecoli/composites/ecoli_configs/fba_redux.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
},
"exclude_processes": ["exchange_data"],
"flow": {
"ecoli-tf-unbinding": [],

"ecoli-metabolism-redux": [["ecoli-chromosome-structure"]],
"ecoli-mass-listener": [["ecoli-metabolism-redux"]],
"RNA_counts_listener": [["ecoli-metabolism-redux"]],
Expand Down
2 changes: 0 additions & 2 deletions ecoli/composites/ecoli_configs/fba_redux_div.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
},
"exclude_processes": ["exchange_data"],
"flow": {
"ecoli-tf-unbinding": [],

"ecoli-metabolism-redux": [["ecoli-chromosome-structure"]],
"ecoli-mass-listener": [["ecoli-metabolism-redux"]],
"RNA_counts_listener": [["ecoli-metabolism-redux"]],
Expand Down
7 changes: 7 additions & 0 deletions ecoli/library/sim_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ def get_config_by_name(self, name, time_step=1, parallel=False):
'rnap_data_listener': self.get_rnap_data_listener_config,
'unique_molecule_counts': self.get_unique_molecule_counts_config,
'exchange_data': self.get_exchange_data_config,
'media_update': self.get_media_update_config,
'bulk-timeline': self.get_bulk_timeline_config,
}

Expand Down Expand Up @@ -1470,6 +1471,12 @@ def get_exchange_data_config(self, time_step=1, parallel=False):
'_parallel': parallel,
'exchange_data_from_concentrations': self.sim_data.external_state.exchange_data_from_concentrations,
'environment_molecules': list(self.sim_data.external_state.env_to_exchange_map.keys()),
}

def get_media_update_config(self, time_step=1, parallel=False):
return {
'time_step': time_step,
'_parallel': parallel,
'saved_media': self.sim_data.external_state.saved_media
}

Expand Down
2 changes: 2 additions & 0 deletions ecoli/processes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from ecoli.processes.environment.local_field import LocalField
from ecoli.processes.environment.field_timeline import FieldTimeline
from ecoli.processes.environment.exchange_data import ExchangeData
from ecoli.processes.environment.media_update import MediaUpdate
from ecoli.processes.shape import Shape
from ecoli.processes.antibiotics.cell_wall import CellWall
from ecoli.processes.antibiotics.pbp_binding import PBPBinding
Expand Down Expand Up @@ -91,6 +92,7 @@
process_registry.register(LocalField.name, LocalField)
process_registry.register(FieldTimeline.name, FieldTimeline)
process_registry.register(ExchangeData.name, ExchangeData)
process_registry.register(MediaUpdate.name, MediaUpdate)

# auxiliary processes
process_registry.register(Chemostat.name, Chemostat)
Expand Down
18 changes: 4 additions & 14 deletions ecoli/processes/environment/exchange_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class ExchangeData(Step):
"""
Update environment concentrations and metabolism exchange constraints.
Update metabolism exchange constraints according to environment concs.
"""
name = NAME
topology = TOPOLOGY
Expand All @@ -28,7 +28,6 @@ def __init__(self, parameters=None):
self.exchange_data_from_concentrations = self.parameters[
'exchange_data_from_concentrations']
self.environment_molecules = self.parameters['environment_molecules']
self.saved_media = self.parameters['saved_media']

def ports_schema(self):
return {
Expand All @@ -38,7 +37,6 @@ def ports_schema(self):
}
},
'environment': {
'media_id': {'_default': ''},
'exchange_data': {
'constrained': {'_default': {}, '_updater': 'set'},
'unconstrained': {'_default': set(), '_updater': 'set'}
Expand All @@ -54,22 +52,14 @@ def ports_schema(self):
def next_update(self, timestep, states):
if states['first_update']:
return {'first_update': False}

env_concs = self.saved_media[states['environment']['media_id']]
conc_update = {}
# Calculate concentration delta to get from environment specified
# by old media ID to the one specified by the current media ID
for mol, conc in env_concs.items():
conc_update[mol] = conc * units.mM - states['boundary']['external'][mol]


# Set exchange constraints for metabolism
env_concs = {mol: states['boundary']['external'][mol].to('mM').magnitude
for mol in self.environment_molecules}
exchange_data = self.exchange_data_from_concentrations(env_concs)
unconstrained = exchange_data['importUnconstrainedExchangeMolecules']
constrained = exchange_data['importConstrainedExchangeMolecules']
return {
'boundary': {
'external': conc_update
},
'environment': {
'exchange_data': {
'constrained': constrained,
Expand Down
60 changes: 60 additions & 0 deletions ecoli/processes/environment/media_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from ecoli.processes.registries import topology_registry
from vivarium.core.process import Step
from vivarium.library.units import units

NAME = 'media_update'
TOPOLOGY = {
'boundary': ('boundary',),
'environment': ('environment',),
'first_update': ('first_update', 'media_update')
}
topology_registry.register(NAME, TOPOLOGY)

class MediaUpdate(Step):
"""
Update environment concentrations according to current media ID.
"""
name = NAME
topology = TOPOLOGY
defaults = {
'saved_media': {},
'time_step': 1,
}

def __init__(self, parameters=None):
super().__init__(parameters)
self.saved_media = self.parameters['saved_media']

def ports_schema(self):
return {
'boundary': {
'external': {
'*': {'_default': 0 * units.mM}
}
},
'environment': {
'media_id': {'_default': ''}
},
'first_update': {
'_default': True,
'_updater': 'set',
'_divider': {'divider': 'set_value',
'config': {'value': True}}},
}

def next_update(self, timestep, states):
if states['first_update']:
return {'first_update': False}

env_concs = self.saved_media[states['environment']['media_id']]
conc_update = {}
# Calculate concentration delta to get from environment specified
# by old media ID to the one specified by the current media ID
for mol, conc in env_concs.items():
conc_update[mol] = conc * units.mM - states['boundary']['external'][mol]

return {
'boundary': {
'external': conc_update
}
}
2 changes: 1 addition & 1 deletion ecoli/processes/metabolism.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ def set_molecule_levels(self, metabolite_counts, counts_to_molar,
current_media_id, unconstrained, constrained, conc_updates,
)
self.fba.update_homeostatic_targets(objective)
self.homeostatic_objective = objective
self.homeostatic_objective = {**self.homeostatic_objective, **objective}

# Internal concentrations
metabolite_conc = counts_to_molar * metabolite_counts
Expand Down

0 comments on commit a5eb30e

Please sign in to comment.