- Author:
- WeiweiAi <wai484@aucklanduni.ac.nz>
- Date:
- 2023-04-04 15:51:18+12:00
- Desc:
- Add a steady state example
- Permanent Source URI:
- https://models.physiomeproject.org/workspace/6bc/rawfile/a7940fcacd455a09bdb7beac0da91eca79cf1adb/Scripts/readme.txt
This folder includes the scripts to build cellML models, validate the models using libcellml, run OpenCOR simulation using a Python script, plot the simulation results.
The software tools or language needed are Matlab, OpenCOR and Python. This document does not provide instructions for each script execution but only some examples, source of relevant documentation, or the software environment settings.
1. Set up virtual environment and packages for Python to process CellML modelling tasks:
python -m venv venvCellML
pip install matplotlib
pip install numpy
pip install setuptools
pip install libcellml
pip install pandas
2. preModels.psl can be used to activate the Python virtual environment provided the Python virtual environment folder has to be changed to match the one on your machine.
3. The documentation of Python support for OpenCOR: https://opencor.github.io/user/pythonSupport.html#pythonsupport
4. Install a Python package (e.g, pandas) for OpenCOR in PowerShell:
(1) Navigate to the OpenCOR installation folder, e.g., cd C:\Users\wai484\Documents\OpenCOR
(2) Type "./jupyterconsole.bat"
(3) !pip install pandas
(4) Here is an example of command history:
(venvCellML) PS C:\Users\wai484\Documents\OpenCOR> ./jupyterconsole.bat
Jupyter console 6.0.0
Jupyter kernel for OpenCOR
!pip install pandas
5. The procedure of converting .txt file to .cellml using OpenCOR in PowerShell:
(1) # The OpenCOR installation folder path
$dpath= 'C:/Users/wai484/Documents/OpenCOR'
(2) # The model directory where .txt and .cellml are saved
$mpath='C:/Users/wai484/Documents/SinglePASMC/Experiments'
(3) # Execute the command to do the conversion
.$dpath/OpenCOR -c CellMLTextView::export $mpath/PASMC_test.txt | out-file $mpath/PASMC_test.cellml -encoding utf8
6. Validate the cellML models using libcellml:
(1) In the Simulation view in OpenCOR, export the model as COMBINE Archive
(2) Upload the .omex file to https://libcellml.org/translate, where provides the service that will accept CellML 1.0/1.1 compliant files and transform them into CellML 2.0 compliant files.
(3) Download and unzip the model file.
(4) modelValidation.py can be reused to write the validation script for specific models.
7. Run OpenCOR simulation using Python shell in PowerShell:
(1) # The OpenCOR installation folder path
$dpath= 'C:/Users/wai484/Documents/OpenCOR'
(2) # The simulation Python script directory where the script is present
$mpath='C:/Users/wai484/Documents/SinglePASMC/Simulation/src'
(3) # The simulation Python script
$mfile='simFig4.py'
(4) # Run the simulation script using Python shell
.$dpath/pythonshell.bat $mpath/$mfile
8. simExp.py and plotExp.py can be reused to write Python scripts to run OpenCOR simulation and plot the simulation results.
9. Prepare the documentation for the model publication in PMR using reStructuredText
(1) In the Python virtual environment install the package Sphinx if haven't: pip install -U Sphinx
(2) Navigate to the folder where you want to place the documentation files, e.g., cd to C:\Users\wai484\Documents\EC_uterineSMC\Doc
(3) Activate the Python virtual environment, and type "sphinx-quickstart" in the terminal
(4) Create .rst files in the folder and edit them in VS code.
10. The Matlab scripts are for building cellML models without OpenCOR editor but not ready for public use yet.
(0) addpath(genpath('../../cellLib/Scripts/'))
(1) comp: struct array, comp(1).name="component name"; comp(2).children=["chd1";"chd2";...]; comp(2).vars=[t.vars,t.values,t.units,t.init,t.pub,t.priv,t.vios,t.vctgs;...]; comp(2).Eqs=["eq1","eq2",..];
(2) comp=encapNew(comp,encap,chd,idx),% encap=""; chd(1).name='';chd(1).def='';chd(1).label=["var1","alia1";"var2","alia2";]; or []
(3) %% Build new components from the .csv
csvFile=[pwd filesep 'Vars.csv'];
(4) %% Reuse existing cellml components
libPath="C:/Users/wai484/Documents/ECC_MSK_Rios_1993/cellLib";
cellmlFiles=[libPath+ "/Protocols/Patch_clamp_protocol.cellml",libPath+ "/Components/time.cellml",...
];
whichComp=["dPulse_protocol_ms","time_ms"];
(5) % Specify the inputs of the existing components, otherwise the variable would be categorized as parameters if pub:in
labelRead={};
nm=1;
labelRead(nm).comp="S2";
labelRead(nm).vars=["S_1","S_2","norm","t","k_i1","k_i2","k_1i","k_2i","Si_init"];
(6) %% Encapsuate new components, encap: struct array with the fields:
encap={};
m=1;
encap(m).name="C0_S2";
encap(m).chd.name=["S2",];
encap(m).chd.def=["S2",];
encap(m).chd.from=[strcat("../cellLib/Components/MarkovS.cellml"),];
encap(m).chd.impComp=["S2",];
encap(m).chd.label=[];
label={};
label(nm).comp=sprintf("C%d",i)
label(nm).vars=[var1,alia1;var2,alia2;...];
(7) %% Add equations to components, Eqs: struct array with the fields:
Eqs={};
m=1;
Eqs(m).comp="MWC_18";
Eqs(m).listEqs=["k_C = 0.5{dimensionless}*alpha*exp((V-V0)/(8{dimensionless}*K));",...
];
(8) model=buildModel(modelname,comp,listComp,idx),
listComp={};
m=1;
listComp(m).name="time";
listComp(m).def="time_ms";
listComp(m).from="../cellLib/Components/time.cellml";
listComp(m).impComp="time_ms";
listComp(m).label=["time","t";];