Location: SLC transporters @ 65898d4880ef / src / SGLT1_ss_fast.py

Author:
Weiwei Ai <wai484@aucklanduni.ac.nz>
Date:
2024-10-21 14:11:01+13:00
Desc:
Modify SGLT1_BG_fast.cellml to allow users to modify test_volt and Glco in the simulation tab.
Permanent Source URI:
http://models.cellml.org/workspace/b65/rawfile/65898d4880efb52227f2860ddafb4c8cde585d47/src/SGLT1_ss_fast.py

import sys
import os
# Get the directory containing the current file
current_dir = os.path.dirname(os.path.abspath(__file__))
# Append the 'sedmlEditor' directory to the system path
sys.path.append(os.path.join(current_dir, '../sedmlEditor/'))
from sedDict import create_dict_sedDocment, add_sedTask2dict
from sedEditor import create_sedDocment,write_sedml, validate_sedml

# Convert the model to CellML 2.0 if needed
model_name='SGLT1_ss_fast'
path_='../Electrogenic cotransporter/CellMLV2/'
sedFilename = model_name+'.sedml' 
full_path = os.path.join(current_dir, path_, sedFilename) 
model_path ='../'
# ********** The following is to create a dictionary for the sedml file **********
dict_sedDocument=create_dict_sedDocment()
model_ids_=['_fig5','_fig5_sugar']
Glcos=['1e-12','1']
for i in range(len(model_ids_)):
    model_id_=model_ids_[i]
    Glco=Glcos[i]
    model_id = model_name+model_id_ # This is the model id in the sedml, could be different from the model file name
    # ********** The following is to add the task information to the dictionary **********

    # Note: the following is an example, you can modify it to add more tasks
    # Note: the valid sedml id should start with a letter, and only contain letters, numbers, and underscores
    # This is the model file name, assuming in the same folder with the sedml file
    model_source = model_path + model_name + '.cellml' 
    # This is to modify the model parameters if needed
    changes={'Glco':{'component':'params_BG','name':'Glco','newValue':Glco}
             }  
    # the format is {'id':{'component':str,'name':str,'newValue':str}}
    # Example: changes={'V_m':{'component':'main','name':'V_m','newValue':'-0.055'}

    # This is the output of the simulation, and the key is part of the output id
    # The value is a dictionary with the following keys: 'component', 'name', 'scale'
    # component is the component name in the CellML model where the output variable is defined
    # name is the variable name of the outputs
    # scale is the scaling factor for the output variable
    outputs={'t':{'component':'SGLT1_BG','name':'t','scale':1},
             'Ii':{'component':'SGLT1_BG','name':'Ii','scale':-1e-6},
             'Ii_1':{'component':'SGLT1_BG','name':'Ii_1','scale':-1e-6},           
             'V0_Vm':{'component':'params_BG','name':'V0_Vm','scale':1e3},
             }
    # You can add more outputs if needed

    # The following is the simulation setting
    # This is to set the maximum step size for the simulation
    dict_algorithmParameter={'kisaoID':'KISAO:0000209', 'name':'rtol','value':'1e-12'} 
    dict_algorithmParameter2={'kisaoID':'KISAO:0000211', 'name':'atol','value':'1e-12'} 
    # You can set more algorithm parameters if needed. You can refer to get_KISAO_parameters() in src/simulator.py file to get the parameters for the specific algorithm
    # Add the algorithm parameters to listOfAlgorithmParameters
    # You can choose one of the simulation algorithms specified by KISAO_ALGORITHMS in src/simulator.py file
    dict_algorithm={'kisaoID':'KISAO:0000535','name':'VODE','listOfAlgorithmParameters':[dict_algorithmParameter,dict_algorithmParameter2]} 
    # This is the simulation setting
    # You can choose one of the following simulation types: 'UniformTimeCourse', 'OneStep'
    simSetting={'type':'UniformTimeCourse','algorithm':dict_algorithm,'initialTime':0,'outputStartTime':0,'outputEndTime':20,'numberOfSteps':200}
    # simSetting={'type':'OneStep','algorithm':dict_algorithm,'step':0.1}


    # The following is to add the task information to the dictionary
    add_sedTask2dict(dict_sedDocument, model_id, model_source,changes,simSetting,outputs)

    # You can repeat the above steps to add more tasks with DIFFERENT model names.

# ********** The following is to create the sedml file, no need to modify **********
try:
    doc=create_sedDocment(dict_sedDocument)
except ValueError as err:
    print(err)
write_sedml(doc,full_path)
print(validate_sedml(full_path))