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

Commit

Permalink
reafactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed Mar 4, 2024
1 parent 028dddb commit 75a33f5
Show file tree
Hide file tree
Showing 2 changed files with 236 additions and 186 deletions.
17 changes: 12 additions & 5 deletions biosimulator_processes/processes/copasi_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,18 @@ def __init__(self, config=None, core=None):
if species_changes:
for species_change in species_changes:
if isinstance(species_change, dict):
set_species(**species_change, model=self.copasi_model_object)
species_name = species_change.pop('name')
changes_to_apply = {}
for spec_param_type, spec_param_value in species_change.items():
if spec_param_value:
changes_to_apply[spec_param_type] = spec_param_value
set_species(**changes_to_apply, model=self.copasi_model_object)

# Get the species (floating only) TODO: add boundary species
self.floating_species_list = get_species(model=self.copasi_model_object).index.tolist()
self.floating_species_initial = get_species(model=self.copasi_model_object)['concentration'].tolist()

# ----GLOBAL PARAMS: set global parameter changes
existing_global_parameters = get_parameters(model=self.copasi_model_object).index
global_parameter_changes = self.model_changes.get('global_parameter_changes', [])
if global_parameter_changes:
for param_change in global_parameter_changes:
Expand All @@ -156,9 +160,12 @@ def __init__(self, config=None, core=None):
# handle changes to existing params
set_parameters(name=param_name, **param_change, model=self.copasi_model_object)
# set new params
if param_name not in existing_global_parameters:
assert param_change.get('initial_concentration') is not None, "You must pass an initial_concentration value if adding a new global parameter."
add_parameter(name=param_name, **param_change, model=self.copasi_model_object)
global_params = get_parameters(model=self.copasi_model_object)
if global_params:
existing_global_parameters = global_params.index
if param_name not in existing_global_parameters:
assert param_change.get('initial_concentration') is not None, "You must pass an initial_concentration value if adding a new global parameter."
add_parameter(name=param_name, **param_change, model=self.copasi_model_object)

# Get the list of parameters and their values (it is possible to run a model without any parameters)
model_parameters = get_parameters(model=self.copasi_model_object)
Expand Down
Loading

0 comments on commit 75a33f5

Please sign in to comment.