MATLAB Answers

How to correctly compile a function containing variables with dimension and call it in SimBiology

2 views (last 30 days)
Wei Wang
Wei Wang on 22 Apr 2020
Commented: Arthur Goldsipe on 23 Apr 2020
Hi, all
I want to calculate the intestinal solubility of drug according to intestinal cyclodextrin concentration in a SimBiology model, so I compile a function like:
function [IntestinalAGSolubility] = calculateSolubilityCD(CDConcentration,CDMW,AGMW)
% This is a function to calculate solubility of a drug,AG, according to concentration
% of cyclodextrin (CD). Equation is transformed from phase solubility test.
% AGMW: AG molecular weight (g/mol); CDMW: CD molecular weight (g/mol);
% CDConcentration (mg/mL); IntestinalAGSolubility (mg/mL)
% 0.4653: slope; 0.4409: intercept (mmol/L)
if (0.4653*CDConcentration*1000/CDMW+0.4409)*AGMW>2990.1
elseif (0.4653*CDConcentration*1000/CDMW+0.4409)*AGMW<=2990.1
This function is due to the fact that the solubility of AG and CD concentraion is consistent with a equation: S (mmol/L) =0.4653*CD (mmol/L)+0.4409, and maximum solubility is 2990.1 mg/L. Variables in function with their dimension are used in my SimBiology model, which is modified from "generic PBPK model". I have turned on the UnitConversion in program and I call this function in SimBiology APP like ColonSolubility=calculateSolubilityCD(Colon.CD,CDMW,AGMW). The line: IntestinalAGSolubility=2990.1*1000; and IntestinalAGSolubility=(0.4653*CDConcentration*1000/CDMW+0.4409)*AGMW*1000 are coded like this because only by this way I can get the exepexted result that presented in figure. However, value of 2990.1*1000 is not what I want to use in AG solubility (2.990 mg/mL). I am confused why I can not use IntestinalAGSolubility=2.990 in function (which will result in 1000-fold decrease in simulated solubility).
Can anyone explain why this happens and do I make it right in other part of this function? Thanks a lot.


Sign in to comment.

Answers (1)

Arthur Goldsipe
Arthur Goldsipe on 22 Apr 2020
The issue you are seeing is addressed in the "Tip" on the documentation for UnitConversion.
The problem is that you are have written your function calculateSolubilityCD to assume that the input arguments have specific units, but SimBiology does not pass the input arguments in with those units. I would address the issue using the advice from the Tip (ensure input arguments are passed in as dimensionless) as follows:
First, I would create parameters with value 1 and the units of your input and output arguments:
  • Parameter mg_per_mL with value 1 and units "milligram/milliliter"
  • Parameter g_per_mol with value 1 and units "gram/mole"
Then, I would change
Finally, you can remove the factors of 1000 from calculateSolubilityCD.
Good luck!


Show 1 older comment
Arthur Goldsipe
Arthur Goldsipe on 23 Apr 2020
You're right, I should have been more careful when I said "you can remove the factors of 1000." I'm not sure which ones you can remove, because I don't fully understand your equations. My main confusion is whether you want to report the AG concentration in units of mg/L, mole/liter, or something else.
What I really intended by my comment was this: If you know what your equations need to look like when the variables have specific units, then you can only write your equations in that form once you've ensured the values are properly converted (using the tip to divide by a conversion parameter).
As for your second point, it doesn't actually matter what units your species is in. What matters is the parameter you divide by. If you divide a species by a parameter of "1 mg", then you can effectively write your equations as if the species had units of "mg". So yes, this would result in a value that is 1000-fold larger than if you divided by a parameter of "1 g".
And after re-reading your question, I have another idea that might reduce the confusion and simplify your model: Introduce the solubility more directly into the model, so that SimBiology handles more of the unit conversion for you. What do you think about the following modifications (assuming I'm interpreting your equations correctly)?
Add parameters:
  • slope = 0.4653 [units = milligram/millimole]
  • intercept = 0.4409 [units = milligram/liter]
  • maxSolubility = 2990.1 [units = milligram/liter]
  • solubilityEquation [units = milligram/liter, constant = false, value will be set by a repeated assignment rule]
  • solubility [units = milligram/liter, constant = false, value will be set by a repeated assignment rule]
Add repeated assignment rules:
  • solubilityEquation = slope*CDConcentration/CDMW + intercept
  • solubility = min(solubilityEquation, maxSolubility)
  • ColonSolubility = solubility/AGMW
If you use this approach, you will probably see a warning about not being able to do dimensional analysis of the rule that uses "min". That just means you need to check by hand that it's dimensionally consistent. (In this case, do that by ensuring that solubilityEquation, maxSolubility, and solubility all have the same units.) The advantage here is that SimBiology will do dimensional analysis and unit conversion of the solubility relationship for you. And this also makes it clear to me that your solubility relationship is expressed using concentrations in mg/L, but you are ultimately interested in ColonSolubility in units of mmol/L (or some other dimensionally equivalent unit).
Wei Wang
Wei Wang on 23 Apr 2020
Thanks for your specific introduction, that's really helpful.
I am interested in using funciton in model, and I think I would really need this one day, so I want to make it clear. But the method min(solubilityEquation, maxSolubility) you introduce seems very useful, and I think I could apply it to future models.
The concentration of AG and CD actually conforms to this relationship: SolubilityAG(mmol/L)=0.4653*ConcentrationCD (mmol/L)+0.4409 (mmol/L). The dimension is not what I used in my model.
So I think the parameters newly created should be:
  • slope = 0.4653 [units =dimensionless]
  • intercept = 0.4409 [units = mmol/L]
  • maxSolubility = 2.9901 [units = mg/mL]
  • solubilityEquation [units = mg/mL]
And repeated assignment rules are:
  • solubilityEquation = (slope*CDConcentration/CDMW + intercept)*AGMW
  • ColonSolubility = min(solubilityEquation, maxSolubility) [ColonSolubility is also in mg/mL]
Is this right? I am not sure whether you mean something else by unit you have set. I use solubility in dimension of mg/mL because I already define other species concentration in this unit so I want to make them uniform.
Anyway, thanks again for your zealous help.
Arthur Goldsipe
Arthur Goldsipe on 23 Apr 2020
Yes, your equations look correct to me. I wasn't sure where to put the molecular weight conversion factors, but what you've written makes sense to me. Nice!

Sign in to comment.



More Answers in the  SimBiology Community

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!