Skip to content

Commit

Permalink
- fixes an issue when setting intervals / step_size via setTaskSettings
Browse files Browse the repository at this point in the history
 - adds get_model_name
 - fixes an issue where get_reaction_mappings sometime would not be able to return the complete list of mappings for a parameter (and crash instead)
  • Loading branch information
fbergmann committed Feb 15, 2024
1 parent b9e39cb commit 1464215
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions basico/model_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3227,11 +3227,15 @@ def get_reaction_mapping(reaction, **kwargs):
continue

objs = info.getMappings(j)
if objs.size() == 1:
obj_size = objs.size()
if obj_size == 1:
result[p_name] = objs[0]
continue

result[p_name] = list(objs)
obj_list = []
for i in range(obj_size):
obj_list.append(objs[i])
result[p_name] = obj_list

return result

Expand Down Expand Up @@ -3709,6 +3713,23 @@ def set_time_unit(unit, **kwargs):
else:
model.setTimeUnit(unit)

def get_model_name(**kwargs):
"""Returns the name of the current model.
:param kwargs: optional parameters
- | `model`: to specify the data model to be used (if not specified
| the one from :func:`.get_current_model` will be taken)
:return: the name of the model
"""
dm = model_io.get_model_from_dict_or_default(kwargs)
assert (isinstance(dm, COPASI.CDataModel))

model = dm.getModel()
assert (isinstance(model, COPASI.CModel))
return model.getObjectName()


def get_model_units(**kwargs):
"""Returns all model units as dictionary.
Expand Down Expand Up @@ -4644,6 +4665,16 @@ def set_task_settings(task, settings, **kwargs):
problem = task.getProblem()
_set_group_from_dict(problem, settings['problem'])

if isinstance(problem, COPASI.CTrajectoryProblem):
if 'Duration' in settings['problem']:
problem.setDuration(float(settings['problem']['Duration']))
if 'StepSize' in settings['problem']:
problem.setStepSize(float(settings['problem']['StepSize']))
if 'intervals' in settings['problem']:
problem.setStepNumber(int(settings['problem']['intervals']))
if 'StepNumber' in settings['problem']:
problem.setStepNumber(int(settings['problem']['StepNumber']))

if 'method' in settings:
method = task.getMethod()
m_dict = settings['method']
Expand Down

0 comments on commit 1464215

Please sign in to comment.