Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
updated copasi process updater
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed Feb 28, 2024
1 parent 34fe120 commit 55f50a5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 153 deletions.
41 changes: 26 additions & 15 deletions biosimulator_processes/processes/copasi_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ class CopasiProcess(Process):
},
'biomodel_id': 'maybe[string]', # <-- implies the lack of either model_file or model_reactions
'units': 'maybe[tree[string]]',
'method': {
'_type': 'string',
'_default': 'lsoda'
}
'method': 'maybe[string]'
# 'method': {
# '_type': 'string',
# '_default': 'lsoda'
# }
}

def __init__(self, config=None, core=None):
Expand All @@ -117,7 +118,7 @@ def __init__(self, config=None, core=None):
else:
self.copasi_model_object = new_model(name='CopasiProcess Model')

self.model_changes: Dict = self.config['model']['model_changes']
self.model_changes: Dict = self.config['model'].get('model_changes', {})
reaction_changes: Dict = self.model_changes.get('reaction_changes')

# add reactions
Expand Down Expand Up @@ -145,6 +146,8 @@ def __init__(self, config=None, core=None):
# Get a list of compartments
self.compartments_list = get_compartments(model=self.copasi_model_object).index.tolist()

self.method = self.config.get('method')

def initial_state(self):
floating_species_dict = dict(
zip(self.floating_species_list, self.floating_species_initial))
Expand Down Expand Up @@ -191,20 +194,28 @@ def update(self, inputs, interval):
model=self.copasi_model_object)

# run model for "interval" length; we only want the state at the end
timecourse = run_time_course(
start_time=inputs['time'],
duration=interval,
# intervals=1,
update_model=True,
model=self.copasi_model_object)
#method=self.config['solver'])
timecourse_args = {
'start_time': inputs['time'],
'duration': interval,
'update_model': True,
# 'intervals': 1,
'model': self.copasi_model_object}
if self.method:
timecourse_args['method'] = self.method

# run the time course with given kwargs
timecourse = run_time_course(**timecourse_args)

# extract end values of concentrations from the model and set them in results
results = {'time': interval}
results['floating_species'] = {
mol_id: float(get_species(name=mol_id, exact=True,
model=self.copasi_model_object).concentration[0])
for mol_id in self.floating_species_list}
mol_id: float(get_species(
name=mol_id,
exact=True,
model=self.copasi_model_object
).concentration[0])
for mol_id in self.floating_species_list
}

return results

Expand Down
6 changes: 3 additions & 3 deletions biosimulator_processes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def fetch_biomodel_by_term(term: str, index: int = 0):
"""
models = biomodels.search_for_model(term)
model = models[index]
sbml = biomodels.get_content_for_model(model['id'])
return load_model_from_string(sbml)
return fetch_biomodel(model['id'])


def fetch_biomodel(model_id: str):
return biomodels.get_content_for_model(model_id)
sbml = biomodels.get_content_for_model(model_id)
return load_model_from_string(sbml)
Loading

0 comments on commit 55f50a5

Please sign in to comment.