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

Commit

Permalink
updated init and copasi process
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed Feb 28, 2024
1 parent dedd260 commit 34fe120
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 36 deletions.
25 changes: 0 additions & 25 deletions biosimulator_processes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +0,0 @@
from process_bigraph import process_registry


# Define a list of processes to attempt to import and register
processes_to_register = [
('cobra', 'cobra_process.CobraProcess'),
('copasi', 'copasi_process.CopasiProcess'),
('smoldyn', 'smoldyn_process.SmoldynProcess'),
('tellurium', 'tellurium_process.TelluriumProcess'),
]

for process_name, process_path in processes_to_register:
module_name, class_name = process_path.rsplit('.', 1)
try:
# Dynamically import the module
process_module = __import__(
f'biosimulator_processes.processes.{module_name}', fromlist=[class_name])
# Get the class from the module
process_class = getattr(process_module, class_name)

# Register the process
process_registry.register(process_name, process_class)
print(f"{class_name} registered successfully.")
except ImportError as e:
print(f"{class_name} not available. Error: {e}")
26 changes: 18 additions & 8 deletions biosimulator_processes/processes/copasi_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
# 'reactions': 'tree[string]',
# 'model_changes': 'tree[string]',
# Newton/Raphson method distance/rate: steady state Use newton method and time course simulation
# try newton stopp if epsilon satistfies
# run tc for 0.1unit of time stop if ep satis
# try newton stop if e satisfied
# run tc for 10x longer time stop if e
# if time>10^10 units of time stop otherwise go back to number 3
"""


from typing import Dict
from basico import (
load_model,
get_species,
Expand Down Expand Up @@ -78,7 +87,7 @@ class CopasiProcess(Process):
'_type': 'tree[string]',
'_default': MODEL_TYPE
},
'biomodel_id': 'string', # <-- implies the lack of either model_file or model_reactions
'biomodel_id': 'maybe[string]', # <-- implies the lack of either model_file or model_reactions
'units': 'maybe[tree[string]]',
'method': {
'_type': 'string',
Expand All @@ -89,11 +98,13 @@ class CopasiProcess(Process):
def __init__(self, config=None, core=None):
super().__init__(config, core)

# exact values from configuration
model_file = self.config.get('model').get('model_source')
sed_model_id = self.config.get('model').get('model_id')
biomodel_id = self.config.get('biomodel_id')
source_model_id = biomodel_id or sed_model_id

# ensure only model_file OR biomodel_id
assert not (model_file and biomodel_id), 'You can only pass either a model_file or a biomodel_id.'

# A. enter with model_file
Expand All @@ -106,16 +117,18 @@ 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']
reaction_changes: Dict = self.model_changes.get('reaction_changes')

# add reactions
if self.config.get('reactions'):
for reaction_name, reaction_spec in self.config['reactions'].items():
if reaction_changes:
for reaction_name, reaction_spec in reaction_changes.items():
add_reaction(
name=reaction_name,
scheme=reaction_spec,
model=self.copasi_model_object
)

# self.model_changes =
# 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()
Expand All @@ -127,14 +140,11 @@ def __init__(self, config=None, core=None):
# Get a list of reactions
self.reaction_list = get_reactions(model=self.copasi_model_object).index.tolist()
if not self.reaction_list:
raise AttributeError('You must provide either a model filepath, a biomodel id, or reaction definitions.')
raise AttributeError('No reactions could be parsed from this model. Your model must contain reactions to run.')

# Get a list of compartments
self.compartments_list = get_compartments(model=self.copasi_model_object).index.tolist()

if self.config.get('method'):
pass

def initial_state(self):
floating_species_dict = dict(
zip(self.floating_species_list, self.floating_species_initial))
Expand Down
6 changes: 3 additions & 3 deletions notebooks/copasi_process_composer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "c6c10dc5988e52d4",
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-02-28T16:57:16.121555Z",
"start_time": "2024-02-28T16:57:14.285002Z"
"end_time": "2024-02-28T18:42:15.497044Z",
"start_time": "2024-02-28T18:42:13.902065Z"
}
},
"outputs": [
Expand Down

0 comments on commit 34fe120

Please sign in to comment.