Skip to content

Commit

Permalink
Added multiple models convection model
Browse files Browse the repository at this point in the history
Added new functionality: Multiple species pressure based convection model for biomass propagation. v.0.5.0 06/22/24 ID
  • Loading branch information
dukovski committed Jun 22, 2024
1 parent c69f67b commit 96e962d
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 8 deletions.
Binary file modified cometspy/__pycache__/comets.cpython-39.pyc
Binary file not shown.
Binary file modified cometspy/__pycache__/layout.cpython-39.pyc
Binary file not shown.
Binary file modified cometspy/__pycache__/model.cpython-39.pyc
Binary file not shown.
15 changes: 8 additions & 7 deletions cometspy/comets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import numpy as np
import platform

__author__ = "Djordje Bajic, Jean Vila, Jeremy Chacon"
__author__ = "Djordje Bajic, Jean Vila, Jeremy Chacon, Ilija Dukovski"
__copyright__ = "Copyright 2024, The COMETS Consortium"
__credits__ = ["Djordje Bajic", "Jean Vila", "Jeremy Chacon"]
__credits__ = ["Djordje Bajic", "Jean Vila", "Jeremy Chacon", "Ilija Dukovski"]
__license__ = "MIT"
__version__ = "0.4.20"
__comets_compatibility__ = "2.11.1" # version of comets this was tested with (except signaling)
__comets_compatibility_signaling__ = "2.11.1" # version signaling was tested with
__version__ = "0.5.0"
__comets_compatibility__ = "2.12.0" # version of comets this was tested with (except signaling)
__comets_compatibility_signaling__ = "2.12.0" # version signaling was tested with

__maintainer__ = "Djordje Bajic"
__email__ = "[email protected]"
Expand Down Expand Up @@ -347,6 +347,7 @@ def run(self, delete_files : bool = True):
"""
print('\nRunning COMETS simulation ...')
print('\nDebug Here ...')

# If evolution is true, write the biomass but not the total biomass log
if self.parameters.all_params['evolution']:
Expand Down Expand Up @@ -389,10 +390,10 @@ def run(self, delete_files : bool = True):
shell=True, stdout=sp.PIPE, stderr=sp.STDOUT)

self.run_output, self.run_errors = p.communicate()
self.run_output = self.run_output.decode()
self.run_output = self.run_output.decode('ascii','ignore')

if self.run_errors is not None:
self.run_errors = self.run_errors.decode()
self.run_errors = self.run_errors.decode('ascii','ignore')
else:
self.run_errors = "STDERR empty."

Expand Down
68 changes: 67 additions & 1 deletion cometspy/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def __init__(self, input_obj : list = None):
self.region_map = None
self.region_parameters = {}

self.models_pairs_frictions =[]
self.models_substrate_frictions =[]

self.__local_media_flag = False
self.__diffusion_flag = False
self.__refresh_flag = False
Expand All @@ -119,6 +122,8 @@ def __init__(self, input_obj : list = None):
self.__region_flag = False
self.__ext_rxns_flag = False
self.__periodic_media_flag = False
self.__models_frictions_flag = False
self.__models_pairs_frictions_flag = False

if input_obj is None:
print('building empty layout model\nmodels will need to be added' +
Expand Down Expand Up @@ -701,7 +706,7 @@ def add_barriers(self, barriers : list):
if len(self.barriers) > 0:
self.__barrier_flag = True
self.barriers = list(set(self.barriers))

def set_metabolite_diffusion(self, diffusion_constant : float):
"""
sets the default diffusion constant for all metabolites
Expand Down Expand Up @@ -967,6 +972,44 @@ def set_specific_static_at_location(self, met : str,
self.local_static[location] = {}
self.local_static[location][met] = amount

def set_models_substrate_frictions(self,
friction : list):
"""
sets the values of the friction paremeters between the organisms and substrate
Parameters
----------
model : int
the order of the model
location : tuple
the (x, y) location of the fixed metabolite amount. x, y are int
amount : float
the amount, in mmol, that is in each box at each time step
"""
self.__models_frictions_flag = True
self.models_substrate_frictions=friction

def set_models_pairs_frictions(self,
pairs_frictions : list):
"""
sets the values of the friction paremeters between the organisms and substrate
Parameters
----------
model : int
the order of the model
location : tuple
the (x, y) location of the fixed metabolite amount. x, y are int
amount : float
the amount, in mmol, that is in each box at each time step
"""
self.__models_pairs_frictions_flag = True
self.models_pairs_frictions=pairs_frictions

def add_typical_trace_metabolites(self, amount : float=1000.0,
static : bool =True):
"""
Expand Down Expand Up @@ -1055,6 +1098,8 @@ def write_layout(self, working_dir : str, to_append = ""):
self.__write_barrier_chunk(lyt)
self.__write_regions_chunk(lyt)
self.__write_periodic_media_chunk(lyt)
self.__write_models_frictions_chunk(lyt)
self.__write_models_pairs_frictions_chunk(lyt)
lyt.write(r' //' + '\n')

self.__write_initial_pop_chunk(lyt)
Expand Down Expand Up @@ -1300,6 +1345,27 @@ def __write_initial_pop_chunk(self, lyt):
lyt.write(r' //' + '\n')
lyt.write(r'//' + '\n')

def __write_models_frictions_chunk(self, lyt):
""" writes the models frictions to the open
lyt file and adds the closing //s """
if self.__models_frictions_flag:
print('HERE')
lyt.write(' modelsFriction\n')
for i in self.models_substrate_frictions:
print('HERE1')
lyt.write(' ' + str(self.models_substrate_frictions.index(i))+ ' ' + str(i) + '\n')
lyt.write(r' //' + '\n')

def __write_models_pairs_frictions_chunk(self, lyt):
""" writes the intermodels pairs frictions to the open
lyt file and adds the closing //s """
if self.__models_pairs_frictions_flag:
lyt.write(' interModelPairsFriction\n')
for i in range(len(self.models_pairs_frictions)):
for j in range(len(self.models_pairs_frictions)):
lyt.write(' ' + str(i) + ' ' +str(j) + ' ' + str(self.models_pairs_frictions[i][j]) + '\n')
lyt.write(r' //' + '\n')

def update_models(self):
""" updates layout properties when models are added / removed
Expand Down
12 changes: 12 additions & 0 deletions cometspy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,18 @@ def change_hill(self, reaction, hill):
self.reactions.loc[self.reactions[
'REACTION_NAMES'] == reaction, 'HILL'] = hill

def change_optimizer(self, optimizer):
""" changes the optimizer to a specified one.
Parameters
----------
optimizer : str
the name of the optimizer
"""
self.optimizer = optimizer

def read_cobra_model(self, path : str, randomtag : bool = False):
""" reads a cobra model from a file and loads it into this model
Expand Down
Binary file modified dist/cometspy-0.4.20-py3-none-any.whl
Binary file not shown.
Binary file modified dist/cometspy-0.4.20.tar.gz
Binary file not shown.

0 comments on commit 96e962d

Please sign in to comment.