pbpk¶
The PBPK library, see PBPK library: the package and the classes a model package writes its definition with, and the build. The organs, the physiology and the id scheme are on the pages pbpk organs, pbpk physiology and pbpk ids and data.
The PBPK model library: the building blocks of the PBPK models of a substance.
The base of the experiments of a model built on the library
(PBPKSimulationExperiment, ScaledRenalMap, healthy_gfr, REFERENCE_GFR,
molecular_weights of pkpdsim.pbpk.experiment), the equilibration outside
an experiment (equilibrated_simulation of pkpdsim.pbpk.equilibration)
and the validity of the kidney outflow (kidney_outflow, KidneyOutflow of
pkpdsim.pbpk.kidney_validity) are
exported lazily: they import sbmlsim, which a factory does not need, so
import pkpdsim.pbpk imports no simulator.
definition¶
The definition of a PBPK model: the substances, the chemistry and the choices.
Variants
dataclass
¶
The organ variants of a definition, the standard organ everywhere else.
Attributes:
| Name | Type | Description |
|---|---|---|
organs |
Mapping[Organ, str | OrganComponent]
|
the variant of an organ, by name or as component; the names
are resolved from the variant registry when the model is built.
The organs may be given as |
PBPKDefinition
dataclass
¶
PBPKDefinition(
sid,
substances,
chemistry=(),
variants=Variants(),
routes=(),
pd=(),
sex=MALE,
population=DEFAULT_POPULATION,
arm_vein="pksim_default",
dynamic=(),
name=None,
notes=None,
observers=(),
creators=(),
parameters=(),
starts=dict(),
deltas=(),
readouts=(),
slow_pools=(),
)
The definition of a PBPK model.
Attributes:
| Name | Type | Description |
|---|---|---|
sid |
str
|
the id of the model. |
substances |
Sequence[Substance]
|
the substances. |
chemistry |
Sequence[Metabolism | Transport | CustomReaction]
|
the processes, each defined once per organ. |
variants |
Variants
|
the organ variants. |
routes |
Sequence[Route]
|
the routes of administration. |
pd |
Sequence[PDComponent]
|
the pharmacodynamic components. |
sex |
Sex
|
the sex of the model, chosen when it is built: its reference
values and default individual; a study of both sexes uses one
model per sex, the builds of |
population |
str
|
the population ( |
arm_vein |
str
|
the preset of the weights of the arm vein sampling site
( |
dynamic |
tuple[str, ...]
|
the parameters of the top model which change during a simulation (an impairment changed in the middle of a study, a PD output): every quantity which depends on them is an assignment rule instead of an initial assignment, so it follows the change; every other quantity follows a change before the simulation only. |
name |
str | None
|
the name of the model. |
notes |
str | None
|
the notes of the model. |
observers |
Sequence[Observer]
|
the observers of the definition, parameters of the top model after the observers of the library (a sum of metabolites, a ratio, a species of an organ by its flat id): an assignment rule if it reads a state, else a constant with an initial assignment. |
creators |
Sequence[Creator]
|
the creators of the model, its model history (sbmlutils
|
parameters |
Sequence[ModelParameter]
|
the constant parameters of the top model which the model
package states ( |
starts |
Mapping[str, Q]
|
the initial concentrations (mM) of species by their flat id
( |
deltas |
tuple[str, ...]
|
the observers of the top model ( |
readouts |
tuple[str, ...]
|
the readouts of the library which the model reads, by id,
outputs of the intestine with a lumen: the dissolved amount in
the lumen |
slow_pools |
Sequence[SlowPool]
|
the slow (deep) pools of the tissues ( |
combine
classmethod
¶
Couple the definitions of several packages into one physiology.
The substances, the chemistry, the routes, the PD components, the
dynamic parameters, the observers and parameters of the definitions,
the deltas, the readouts, the slow pools and the creators are the
unions of the definitions (the observers of the library follow from
the substances), the organ variants are merged; there is
one physiology, so the definitions must agree on sex, population and
the arm vein preset. Substance ids are unique over all packages, so
nothing is renamed: an id which two definitions define is accepted
only if both define equal objects, compared by value (a shared
metabolite; a fitted value which both take from their fit records,
whose uncertainties are equal by their fields, equal_by_value; PD
components are equal by the id of their model, their inputs and
outputs; a creator is the same person when all its fields are
equal). An
organ variant is a requirement: an organ which a definition leaves
out (the default organ) means no requirement, so the coupled model
takes the variant another definition chooses (e.g. its zonated
liver); two definitions which choose different variants of an organ
raise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*definitions
|
PBPKDefinition
|
the definitions, e.g. of a drug and an inhibitor. |
()
|
sid
|
str
|
the id of the coupled model. |
required |
Returns:
| Type | Description |
|---|---|
PBPKDefinition
|
The coupled definition, in the order of the definitions. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if no definition is given, the definitions differ in sex, population or arm vein preset, two definitions define an id (substance, process, route, PD component, observer, parameter, the slow pool of a substance) differently, or choose different variants of an organ; naming the id. |
parameter_value
¶
Get the number of a constant parameter of the definition (parameters).
A constant of a formulation or a dose, e.g. the factor of the
dissolution of a prolonged release tablet, is a parameter of the
definition, so the model and its archive carry it; the experiments
read it here, the one place of the number, and set the parameter of
the library from it (f_dis_release_<s> in the simulations of the
prolonged release):
# not executed
formulation_map = {
"immediate release": 1.0,
"prolonged release": DEFINITION.parameter_value("f_dis_pr_tor"),
}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sid
|
str
|
the id of the parameter. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The number in the unit of the parameter. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the definition has no parameter of the id or its value is a formula, whose number only the model has. |
validate
¶
Check the definition.
The observers of the definition are checked against the top model:
validate composes the model without them (pkpdsim.pbpk.builder;
an element of an organ which an observer reads is exposed by the
organ) and checks that an observer id is no id of the body nor of
another observer, that every symbol of its formula is an id of the
top model, an exposed element of an organ, a requested readout or
another observer, and that the observers do not read each other in a
cycle; an observer
of constants only is accepted (a constant with an initial
assignment). compose makes the same check on the model it composes
and calls validate without it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
bool
|
check the observers against the top model. |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
with all problems found, naming the offending ids. |
substance¶
Substances and how the body treats them: binding, erythrocytes, distribution.
Binding
dataclass
¶
The binding to plasma proteins.
Attributes:
| Name | Type | Description |
|---|---|---|
fu |
Q
|
the fraction unbound in plasma. |
protein |
Literal['albumin', 'agp', 'unknown']
|
the binding protein. |
ckd |
bool
|
whether the CKD factor of the binding acts on the fu of the
substance (the CKD profile of albumin or alpha-1-acid
glycoprotein, |
Erythrocytes
dataclass
¶
The distribution into the erythrocytes.
Attributes:
| Name | Type | Description |
|---|---|---|
mode |
Literal['equilibrium', 'kinetic']
|
|
bp |
Q | None
|
the blood to plasma ratio (equilibrium). |
kbc |
Q | None
|
the blood cell to plasma coefficient (equilibrium or kinetic). |
k_exchange |
Q | None
|
the exchange rate between plasma and blood cells (kinetic). |
Mode
¶
Bases: StrEnum
How a substance is exchanged between plasma and tissue.
PERFUSION
class-attribute
instance-attribute
¶
Flow-limited: the tissue is in equilibrium with the blood leaving it.
TISSUE
class-attribute
instance-attribute
¶
Merged tissue with finite exchange PS * fu * (Cpl - Cti/Kp).
PERMEABILITY
class-attribute
instance-attribute
¶
Interstitial and intracellular space with a permeability each.
Kp
dataclass
¶
Kp(
value=None,
overrides=dict(),
interstitial=None,
*,
organs=None,
mode=TISSUE,
ftissue=None,
ps=dict(),
ps_per_volume=True,
ckd_floor=dict(),
)
Bases: _Exchange
A tissue to plasma coefficient of the whole tissue.
Every organ the substance enters has the coefficient of its override, else
the scale of interstitial times its interstitial share, else value.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
Q | None
|
the coefficient of the substance, |
overrides |
Mapping[Organ, Q]
|
the coefficients of single organs, by |
interstitial |
Q | None
|
the scale of the interstitial share, the extracellular
distribution of a substance which reaches the interstitial fluid
and not the cells (a contrast agent, a marker of the extracellular
volume, a highly bound acid): every organ without an override has
|
KpMethod
dataclass
¶
KpMethod(
method,
logp,
pka,
compound,
factor=1.0,
*,
organs=None,
mode=TISSUE,
ftissue=None,
ps=dict(),
ps_per_volume=True,
ckd_floor=dict(),
)
Bases: _Exchange
The tissue to plasma coefficients from a calculation method.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
Literal['rodgers_rowland']
|
the method. |
logp |
float
|
the log10 of the octanol:water partition coefficient. |
pka |
tuple[float, ...]
|
the pKa values. |
compound |
Literal['neutral', 'acid', 'base', 'zwitterion']
|
the type of the compound. |
factor |
Q
|
a factor on all coefficients. |
ThresholdReabsorption
dataclass
¶
A reabsorption of the filtered load up to a renal threshold.
The reabsorbed fraction of the filtrate at the plasma concentration C,
1/(1 + (fu*C/threshold)^n)^(1/n), of the unbound (filtered)
concentration fu*C: the reabsorption fu*GFR*C/(1 + (fu*C/threshold)^n)^(1/n)
takes almost all of a filtrate below the threshold and approaches the
transport maximum GFR*threshold above it, and it never exceeds the
filtration fu*GFR*C (the fraction is at most 1). n sets how sharp the
threshold is: far below it the excreted fraction of the filtrate is about
(fu*C/threshold)^n/n. The law of the reabsorption of creatine with its
renal threshold (CRREABS of the creatinine model).
Attributes:
| Name | Type | Description |
|---|---|---|
threshold |
Q
|
the renal threshold, a concentration of the filtrate (mM),
|
n |
Q
|
the sharpness of the threshold (dimensionless), |
Excretion
dataclass
¶
The excretion which is not a process of the chemistry.
Attributes:
| Name | Type | Description |
|---|---|---|
urine |
bool
|
glomerular filtration |
fraction_reabsorbed |
Q
|
the constant fraction of the filtrate which is
reabsorbed, |
reabsorption |
ThresholdReabsorption | None
|
a reabsorption which depends on the plasma
concentration instead of the constant fraction ( |
Substance
dataclass
¶
Substance(
sid,
name,
mr,
annotations=list(),
binding=None,
erythrocytes=None,
distribution=None,
excretion=Excretion(),
inhibits=(),
induces=(),
baseline=None,
)
A substance of the model.
Attributes:
| Name | Type | Description |
|---|---|---|
sid |
str
|
the short id, unique over all models (metabolites take the
prefix of the parent, |
name |
str
|
the name. |
mr |
Q
|
the molecular weight (g/mole). |
annotations |
list[tuple[BQB, str]]
|
the annotations (ChEBI, PubChem, NCIT). |
binding |
Binding | None
|
the plasma protein binding, |
erythrocytes |
Erythrocytes | None
|
the distribution into erythrocytes, |
distribution |
Kp | KpMethod | None
|
the distribution into tissues, |
excretion |
Excretion
|
the excretion. |
inhibits |
tuple[Inhibition, ...]
|
the inhibitions of proteins by the substance. |
induces |
tuple[Induction, ...]
|
the inductions of proteins by the substance. |
baseline |
Q | None
|
the plasma concentration (mM) of an endogenous substance at
the start, |
chemistry¶
The processes of the chemistry: metabolism, transport and custom reactions.
A process states its own constants, or takes its capacity as a ratio of
another process of the organ (RateOf); a metabolism converts its substrate
into its products by fractions, numbers or values with the remainder REST;
a custom reaction has the constants of its mechanism as ModelParameters, its
own constants with provenance, and may declare its rate at the steady state
(stationary): a Formula of the rate, "linear" for a rate law which is
linear in its substrate, or Saturable(vmax, km) for a Michaelis-Menten rate
of a plasma species; the builder then writes the starts of its substances at
their steady state (pkpdsim.pbpk.stationary).
The enum fields of a process (organ, direction, membrane, part) may be
given as member, value or name ("li", "liver", "basolateral"): the
process holds the member, anything else raises a ValueError which names the
field and the allowed values.
REST
module-attribute
¶
REST = Rest.REST
The product of a metabolism which takes the remainder of the fractions:
1 - sum of the fractions of the other products.
LINEAR
module-attribute
¶
The steady state of a custom reaction whose rate law is linear in its
substrate (CustomReaction.stationary): a first order clearance of a plasma
or tissue species.
Fraction
¶
The fraction of a product of a metabolism: a number, a value (fitted) or the
remainder REST.
Stationary
¶
The steady state of a custom reaction (CustomReaction.stationary).
RateOf
dataclass
¶
The constant of a process as a ratio of the constant of another process.
The vmax of MM or Hill or the k of FirstOrder of a metabolism or
transport, given as a factor times the same constant of another
metabolism or transport of the same organ (two transporters of one
substrate with a fixed ratio of their capacities): the constant
<process>_Vmax (or _k) is the initial assignment
<process>_Vmax_ratio * <other>_Vmax of the organ, so it follows a change
of the other constant before the simulation (a fit of one capacity moves
both), and the factor is the constant <process>_Vmax_ratio with its
provenance (ids.rate_ratio).
Attributes:
| Name | Type | Description |
|---|---|---|
process |
str
|
the id of the other process, a metabolism or transport of
the organ which states the same constant itself (a |
factor |
Q
|
the ratio (dimensionless), a number, a |
Rest
¶
Bases: Enum
The remainder of the product fractions of a metabolism, REST.
FirstOrder
dataclass
¶
First order kinetics on the unbound concentration.
Attributes:
| Name | Type | Description |
|---|---|---|
k |
Q | RateOf
|
the clearance per litre of organ (1/min), with |
per_volume |
bool
|
|
MM
dataclass
¶
Michaelis-Menten kinetics on the unbound concentration.
Attributes:
| Name | Type | Description |
|---|---|---|
vmax |
Q | RateOf
|
the maximal rate per litre of organ (mmole/min/l), the whole
organ has the maximal rate |
km |
Q
|
the Michaelis constant (mmole/l). |
Hill
dataclass
¶
Hill kinetics on the unbound concentration.
Attributes:
| Name | Type | Description |
|---|---|---|
vmax |
Q | RateOf
|
the maximal rate per litre of organ (mmole/min/l), the whole
organ has the maximal rate |
km |
Q
|
the concentration of the half-maximal rate (mmole/l). |
n |
Q
|
the Hill coefficient. |
Direction
¶
Bases: StrEnum
The direction of a transport relative to the cell.
Membrane
¶
Metabolism
dataclass
¶
The conversion of a substrate in an organ.
Attributes:
| Name | Type | Description |
|---|---|---|
sid |
str
|
the id of the process, unique in the definition. |
organ |
Organ
|
the organ. |
substrate |
str
|
the id of the substrate. |
products |
Mapping[str, Fraction]
|
the fractions of the substrate converted into each product;
no products is an elimination. Numbers which sum to 1 are the
stoichiometry of one reaction. A |
kinetics |
FirstOrder | MM | Hill
|
the rate law. |
protein |
str | None
|
the id of the enzyme, its activity factor multiplies the rate. |
profile |
str | None
|
the name of the abundance profile of the enzyme. |
Transport
dataclass
¶
The active transport of a substance in an organ.
Attributes:
| Name | Type | Description |
|---|---|---|
sid |
str
|
the id of the process, unique in the definition. |
organ |
Organ
|
the organ. |
substance |
str
|
the id of the transported substance. |
direction |
Direction
|
the direction relative to the cell. |
membrane |
Membrane
|
the membrane. |
kinetics |
FirstOrder | MM | Hill
|
the rate law. |
protein |
str | None
|
the id of the transporter. |
Saturable
dataclass
¶
A Michaelis-Menten rate of a plasma species, vmax*C/(km + C).
The formulas have two scopes, by where the class is used:
- the steady state of a custom reaction (
CustomReaction.stationary): its rate law is the saturable rate of the plasma species of its substrateC, so its organ starts at the root of a quadratic; the formulas read the ids of the organ, as the rate law (Vti, the parameters of the reaction) and constants of the top model; - an argument of the formulas of
pkpdsim.pbpk.steady_state(a saturable secretion of the kidney plasma, which a model writes into a parameter of the definition): the formulas read the ids of the top model only.
Attributes:
| Name | Type | Description |
|---|---|---|
vmax |
str
|
the capacity of the whole organ (mmole/min), a formula. |
km |
str
|
the Michaelis constant (mM), a formula. |
CustomReaction
dataclass
¶
CustomReaction(
sid,
organ,
part,
equation,
formula,
parameters=list(),
species=list(),
stationary=None,
)
A mechanism the library has no class for, placed like any process.
Attributes:
| Name | Type | Description |
|---|---|---|
sid |
str
|
the id of the process, unique in the definition. |
organ |
Organ
|
the organ. |
part |
Part
|
the part of the organ it acts in. |
equation |
str
|
the reaction equation. |
formula |
str
|
the rate law. |
parameters |
Sequence[ModelParameter | Parameter]
|
the constants of the rate law, local ids of the organ
( |
species |
list[Species]
|
additional species of the reaction. |
stationary |
Stationary | None
|
the rate of the reaction at the steady state of its
substances, which makes the builder start every organ part of
them at their steady state ( |
check_kinetics
¶
Check that the parameters of a rate law are positive.
A RateOf is checked by check_rate_of.
check_rate_of
¶
Check a constant of a process which is a ratio of another process, RateOf.
The other process is a metabolism or transport of the same organ which
states the same constant itself (a Vmax for a Vmax, a first order k
with the same per_volume for a k, so that both have one unit), the
factor is positive and dimensionless; a chain of ratios (and so a cycle)
is refused.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
Metabolism | Transport
|
the process. |
required |
chemistry
|
Mapping[str, Metabolism | Transport | CustomReaction]
|
the processes of the definition by id. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The problems, naming the processes. |
check_products
¶
Check the product fractions of a metabolism: their sum is never above 1.
Numbers sum to 1 (the stoichiometry of one reaction). A Value (fixed or
fitted) is a constant of the organ which a fit, a scan or an experiment
may change, so the products need the remainder REST, which keeps the
sum at 1 for every value; the remainder is never negative: the sum of
the upper ends of the ranges of the other fractions (fraction_range)
is at most 1, and not always 1 (a remainder of 0). Every fraction is
positive and its range not negative; a Formula cannot be bounded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
Metabolism
|
the metabolism. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The problems, naming the metabolism and the products. |
fraction_range
¶
Get the range of a fraction: its value and the support of the draws of a fit.
The distribution of the draws of a fitted value (the uncertainty of
fitted, truncated to the bounds of the fit) is the range a fit or an
uncertainty run gives the fraction (pkpdsim.distrib.support).
check_stationary
¶
Check the declared steady state of a custom reaction.
A Formula in mmole/min, the text "linear" or a Saturable with two
formulas; the build checks what the declaration reads and whether the
organs have a closed steady state (pkpdsim.pbpk.stationary).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
CustomReaction
|
the custom reaction. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The problems, naming the reaction. |
check_custom_parameters
¶
Check the parameters of a custom reaction, local ids of its organ.
An SId without __ (the separator of the flat ids), defined once in the
organ (defined, the ids of the other custom reactions of the organ: they
read it), a ModelParameter with a value in its unit. That an id is no
other element of the organ is checked by the build
(OrganBuilder.model_definition).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
CustomReaction
|
the custom reaction. |
required |
defined
|
set[str]
|
the parameter ids of the custom reactions of the organ so
far, to which the ids of |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The problems, naming the reaction and the ids. |
proteins¶
Enzymes and transporters, and their inhibition and induction by substances.
The protein table, the declarations of inhibition and induction and the
turnover of the proteins (turnover). The SBML is generated by the organs:
the base activity f_<protein> of every organ with a process of the protein,
the turnover state E_<protein> under mechanism-based inhibition and
induction (pkpdsim.pbpk.organ_builder), and the inhibitor terms in the rates
of the processes (pkpdsim.pbpk.placement).
Protein
dataclass
¶
An enzyme or a transporter, named once with its annotation.
Attributes:
| Name | Type | Description |
|---|---|---|
sid |
str
|
the id of the protein, also used in |
name |
str
|
the name of the protein. |
uniprot |
str
|
the UniProtKB accession of the human protein. |
ncit |
str | None
|
the NCI Thesaurus code, if the thesaurus has a concept. |
Inhibition
dataclass
¶
The inhibition of a protein by a substance, declared on the inhibitor.
It acts on every process of the protein (pkpdsim.pbpk.placement):
competitive on Km, uncompetitive on Vmax and Km, noncompetitive on Vmax,
mixed on both (Segel 1975); a mechanism-based inhibition inactivates the
protein (its turnover state, Mayhew 2000) and binds competitively with
Ki = KI while it does. A substance inhibits a protein once.
Attributes:
| Name | Type | Description |
|---|---|---|
protein |
str
|
the id of the inhibited protein (key of |
kind |
Literal['competitive', 'noncompetitive', 'uncompetitive', 'mixed', 'mechanism']
|
the type of the inhibition. |
ki |
Q
|
the inhibition constant (of the unbound inhibitor, mM), the competitive one of a mixed inhibition, the KI of a mechanism-based inhibition. |
kiu |
Q | None
|
the uncompetitive constant of a mixed inhibition, only there. |
kinact |
Q | None
|
the maximal inactivation rate (1/min) of a mechanism-based inhibition, only there. |
Induction
dataclass
¶
The induction of a protein by a substance, declared on the inducer.
It raises the synthesis of the protein, kdeg*(1 + Emax*I/(EC50 + I))
(Almond 2009), so its amount approaches 1 + Emax*I/(EC50 + I).
Attributes:
| Name | Type | Description |
|---|---|---|
protein |
str
|
the id of the induced protein (key of |
emax |
Q
|
the maximal increase of the expression (fold change - 1). |
ec50 |
Q
|
the concentration of half-maximal induction (unbound, mM). |
load_proteins
¶
Load the protein table data/proteins.toml.
Returns:
| Type | Description |
|---|---|
dict[str, Protein]
|
The proteins by their id. |
turnover
¶
Get the degradation rate constant of the proteins in an organ.
The values of CYP3A4 (data/proteins.toml, [turnover]): the liver, the
small intestine, and the hepatic value for every other organ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
organ
|
Organ
|
the organ. |
required |
Returns:
| Type | Description |
|---|---|
Value
|
|
Value
|
source (1/h). |
routes¶
The routes of administration and their dose states.
A dose is a dose state in mg, which an experiment sets or adds to
(PKPDSimulationExperiment.add_doses: "PODOSE_<s> + 10.0"), and which is
applied by a first order process, the conventions of the hand-written models:
- intravenous:
IVDOSE_<s>drains into the venous plasmaCve_<s>with the rateKiv_<s> = ln(2)/ti_<s>(ti_<s>the half-life of the injection in s); a constant infusionRi_<s>(mg/min) adds to the dose state; - oral tablet:
PODOSE_<s>is the undissolved drug in the stomach (the first segment of the intestine), which dissolves into the stomach lumen with the dissolution rate of the formulation and empties undissolved with the stomach; in the next segments the undissolved drug is a species of its own, it dissolves there and leaves undissolved into the feces; - oral solution:
SOLDOSE_<s>enters the stomach lumen dissolved with the fast rateKa_sol_<s>(1/hr).
The dose in mg is converted to mmole with the molecular weight Mr_<s>. The
dose states and the parameters of the formulations are parameters of the
top model (route_objects); the oral doses are applied by the intestine,
which reads them through ports and owns their reactions and the rate rules
of the oral dose states (the top dose states replace its inputs, so the
rules act on them).
The dissolution rate kdis (1/min) acts on the undissolved amount of every
segment:
FirstOrderDissolution(k, fed, release):kdis = k(Ka_dis_<s>, 1/hr), times the factor of a modified-release formulationf_dis_release_<s>and(1 + FED*(f_dis_fed_<s> - 1))of the fed state, of those which are set;WeibullDissolution(t50, shape, lag): the fraction dissolvedF = 1 - exp(-ln2*((t - lag)/t50)^shape)after the lag time, applied as its hazardkdis = ln2*shape/t50*((t - lag)/t50)^(shape - 1)on the undissolved amount, with the time since the dosetthe mean age of the undissolved drug (age_dis_<s>, the stateW_dis_<s>of the age-weighted amount divided by the undissolved amount): exact for one dose; doses which overlap share one clock, the amount-weighted mean age: both dissolve with the hazard of the mean age, the rest of the earlier dose as if it were younger (not at all while the mean age is below the lag time), the new dose as if it were older; a dose given after the earlier one has dissolved is exact again;DoseDependentDissolution(k, dose50):kdis = k*D50/(D50 + D)with the undissolved amountD(mg) of all segments, a dissolution which saturates with the undissolved dose (solubility-limited), at mostk*D50.
Formulation
¶
Formulation = (
FirstOrderDissolution
| WeibullDissolution
| DoseDependentDissolution
)
The dissolution of a tablet.
FirstOrderDissolution
dataclass
¶
The first order dissolution of a tablet.
Attributes:
| Name | Type | Description |
|---|---|---|
k |
Q
|
the rate of the dissolution (1/hr). |
fed |
Q | None
|
the factor of the dissolution rate in the fed state ( |
release |
Q | None
|
the factor of a modified-release formulation, the body
parameter |
WeibullDissolution
dataclass
¶
DoseDependentDissolution
dataclass
¶
Route
dataclass
¶
The administration of a substance.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['iv', 'oral', 'oral_solution']
|
intravenous, oral tablet (with dissolution) or oral solution. |
substance |
str
|
the id of the administered substance. |
formulation |
Formulation | None
|
the dissolution of the tablet, the first order
dissolution of the data ( |
dissolution_inputs
¶
Get the parameters of the top model which the dissolution of a tablet reads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route
|
Route
|
an oral route (tablet). |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, UnitDefinition, str]]
|
(id, unit, name) of every parameter of the formulation. |
dissolution_reads_fed
¶
Check whether the dissolution of a tablet depends on the fed state.
is_weibull
¶
Check whether a tablet dissolves by a Weibull function (it needs the age).
dissolution_rate
¶
Get the dissolution rate of a tablet (1/min) on its undissolved amount.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route
|
Route
|
an oral route (tablet). |
required |
undissolved
|
str
|
the undissolved amount of all segments (mg), formula. |
required |
age
|
str
|
the mean time since the dose of the undissolved drug (min), id. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formula and whether it reads a species (then the intestine makes |
bool
|
it an assignment rule). |
route_objects
¶
Get the dose state of a route and its parameters in the top model.
The intravenous route applies its dose into the venous plasma; the oral routes are applied by the intestine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route
|
Route
|
the route. |
required |
substance
|
Substance
|
the administered substance. |
required |
Returns:
| Type | Description |
|---|---|
list[Sbase]
|
The parameters (and for the intravenous route the rules and the |
list[Sbase]
|
reaction) of the route. |
pd¶
Pharmacodynamic and physiology components, coupled to the body by their ports.
A component is an sbmlutils model of the package (a PD model, a model of
body weight or of the electrolytes) with declared ports. It reads quantities
of the body through its input ports and changes quantities of the body
through its output ports; the builder adds it as a comp ModelDefinition
with a Submodel of the id of the model and generates the replacements, so
the package writes no ReplacedElement:
- an input: the element of the body (
Carm_free_api, a species, an observer) replaces the element of the input port of the component, which reads it under its own id; - an output: the element of the output port of the component replaces the
parameter of the body (
f_cardiac_function), which every quantity of the body reads; the parameter is dynamic (PBPKDefinition.dynamic), so the quantities which depend on it are assignment rules and follow it during the simulation.
The flat model has the elements of the component prefixed by its id
(<sid>__E), the replaced parameter of the body keeps its id.
PDComponent
dataclass
¶
A model with declared ports, connected to the body by name.
Two components are equal when their models have the same id and they
have the same inputs and outputs (the sbmlutils Model compares by
identity), so the component which two packages construct each for
itself is one component of a coupled model (PBPKDefinition.combine).
Attributes:
| Name | Type | Description |
|---|---|---|
model |
Model
|
the model of the component; its id is the id of its submodel and the prefix of its elements in the flat model. |
inputs |
Mapping[str, str]
|
the elements of the body which the component reads, by the
id of the element of its input port: |
outputs |
Mapping[str, str]
|
the parameters of the body which the component changes, by
the id of the element of its output port: |
ports
¶
Get the ports of a model by the id of their element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
the model. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, tuple[str, PortType | None]]
|
The id and the type of the port of every element with a port |
dict[str, tuple[str, PortType | None]]
|
( |
dict[str, tuple[str, PortType | None]]
|
every port of the model which names its element ( |
builder¶
The composition of a PBPK model from its definition, and its build.
The comp model has a top model and one submodel per organ:
- the top model holds the physiology (covariates, volumes, flows), the blood
pools (arterial, venous, portal; plasma
C<pool>_<s>and kinetic blood cellsC<pool>_bc_<s>), the parameters of the substances (Mr,fu,Kpor the factorfKp_<s>and theKp_<o>_<s>of a Kp method,BP, ...), the sinks (urine, feces, bile), the dose states of the routes and the parameters the intestine reads (ka_<s>,FED); - every organ is a
ModelDefinitionwith aSubmodel(LI,KI, ...), the standard organ or a variant (pkpdsim.pbpk.variants); it reads the elements of the body through its ports, and its outflow concentrations replace the parametersCout_<o>_<s>of the top model. The intestine (segmentedby default, orsingle_lumen) replaces small and large intestine with one submodelGU, which owns the intestinal lumen and applies the oral doses.
Every port is declared by the organ (its Boundary) and every replacement is
generated here from it; the flat model has the ids of the scheme
(LI__Cpl_<s> in the organs, the ids of the top model unprefixed).
The sinks are those of pkpdsim.pbpk.sinks, the observers (unbound and blood concentrations, hepatic and arm vein) those
of pkpdsim.pbpk.observers.
Every quantity which depends on parameters only (the physiology, the
impairment, the compartments of the pools and the organs, fu, BP, the
coefficients and exchanges of the organs) is a constant with an initial
assignment, not an assignment rule: a change before the simulation (a change
of an experiment, which sbmlsim applies with the initial assignments which
read it) is followed, a change during the simulation is not. Only what reads
a species (the outflow concentrations Cout_<o>_<s>, the observers) and the
rate of an intravenous injection Kiv_<s> (of the dose protocol, which
changes it between doses) are assignment rules. A parameter which changes
during a simulation is named in PBPKDefinition.dynamic: every quantity
downstream of it, in the top model and in the organs, is an assignment rule
(_dynamic).
The top model holds the impaired organ function as well
(pkpdsim.pbpk.impairment): the severities and their factors on the
physiology, fu and the activity of the proteins of the liver.
A PD component (pkpdsim.pbpk.pd) is a further ModelDefinition with a
Submodel of its id: the elements of the body replace its inputs, its
outputs replace parameters of the body, which are dynamic.
Every element is annotated when it is created (pkpdsim.pbpk.annotation);
an input of a component takes the annotation of the element of the body
which replaces it, and the model the annotation of a PBPK model.
BuildResult
dataclass
¶
The files of a built model.
Attributes:
| Name | Type | Description |
|---|---|---|
comp_path |
Path
|
the comp model, the organs as submodels. |
flat_path |
Path
|
the flattened model, which is simulated. |
organ_component
¶
Get the component of an organ: its variant, the standard organ by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition. |
required |
organ
|
Organ
|
the organ. |
required |
Returns:
| Type | Description |
|---|---|
OrganComponent
|
The component. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the variant of the organ is a name of no variant. |
built_organs
¶
Get the organs which are built as a submodel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition. |
required |
Returns:
| Type | Description |
|---|---|
list[Organ]
|
Every organ but those the intestine replaces besides the small |
list[Organ]
|
intestine (the large intestine). |
organ_context
¶
Get the context of an organ: every substance flows through every organ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition. |
required |
organ
|
Organ
|
the organ. |
required |
top
|
Mapping[str, tuple[str, UnitType]] | None
|
the parameters and compartments of the top model with their
kind and unit, which a |
None
|
steady
|
SteadyPlan | None
|
the generated steady state of the definition
( |
None
|
Returns:
| Type | Description |
|---|---|
OrganContext
|
The substances with their parts in the organ, the chemistry and the |
OrganContext
|
inhibitions and inductions of the substances. |
compose
¶
Compose the comp model of a definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition. |
required |
Returns:
| Type | Description |
|---|---|
Model
|
The comp model: the top model with one submodel per organ and one per |
Model
|
PD component, the observers of the definition after those of the |
Model
|
library, the creators of the definition as model history; the unit |
Model
|
definitions of |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the definition is invalid, an organ variant is unknown,
an organ reads an element the body does not have, a route is
given twice, an oral route, an apical transport of the small
intestine or a readout has no intestine with a lumen, a PD
component names a port or an element of the body which does not
exist, a PD component or an observer reads an element of an organ
which the organ does not expose, or an observer of the
definition is invalid in the top model ( |
observer_problems
¶
Check the observers of a definition against the top model.
The model is composed without the observers of the definition (an
element of an organ which an observer reads is exposed by the organ); an
observer id must be no id of the body (nor of a submodel or model
definition), every symbol of its formula a value of the top model (a
parameter, species, compartment or reaction, never a submodel or model
definition), an exposed element of an organ or another observer, and the
observers must not read each other in a cycle (_observer_problems).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition, otherwise valid. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The problems, naming the observers and the ids. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if an observer reads an element of an organ which the organ does not expose. |
build
¶
Build a definition: the comp model and the flat model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition. |
required |
output_dir
|
Path
|
the folder of the files |
required |
Returns:
| Type | Description |
|---|---|
BuildResult
|
The paths of the comp and the flat model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the definition cannot be composed, or a model has SBML errors. |
flat_model
¶
Validate a comp model and write its flat model.
The comp model is read once, validated without the units and flattened in
memory; the flat model is validated with strict units. libsbml checks the
units of a comp document only in its top model, not in the model
definitions of the organs, so the flat model, which holds the math of every
organ, is where the units are checked. The written file is checked, as
create_model checks it: libsbml checks a constructed comp document
differently from one it read.
The flat model depends on the content of the comp model alone, which the
cache of the builds of the tests uses (tests/conftest.py).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comp_path
|
Path
|
the file of the comp model. |
required |
flat_path
|
Path
|
the file of the flat model. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a model has SBML errors, or libsbml cannot flatten the comp model. |
archive¶
The factory of a library model in one call: the files and the COMBINE archive.
A model package builds its PBPKDefinition with pkpdsim.pbpk.build and
writes next to the SBML the differential equations as markdown, the antimony
of the flat model, the two license texts and the COMBINE archive.
create_archive does all of it, so the factory of a model is one call.
A model with a build per sex builds the one definition for every sex
(sexes): the build of the sex of the definition keeps its id (<sid>.xml,
<sid>_flat.xml, the master entry of the archive) and the build of another
sex is the definition with that sex and the id <sid>_<sex>, e.g.
<sid>_female_flat.xml next to the male <sid>_flat.xml. The model object
holds both (PKPDModel(model_path=..., female_model_path=...)); its model_path
is the male build, so a model with builds per sex keeps its definition male
(the default), whose build is the master entry.
sex_definition
¶
Get the definition of the build of a sex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition of the model. |
required |
sex
|
Sex
|
the sex of the build. |
required |
Returns:
| Type | Description |
|---|---|
PBPKDefinition
|
The definition itself for its own sex, else the definition with the |
PBPKDefinition
|
sex, the id |
PBPKDefinition
|
sex, |
create_archive
¶
create_archive(
definition,
model_output_dir,
*,
model,
copyright,
readme=None,
extra_models=(),
extra_files=(),
sexes=None,
figure=True,
)
Build a definition and write its files and the COMBINE archive.
Builds the definition into model_output_dir (build), writes the ODEs of
the flat model as markdown (sbmlode) and its antimony, the texts of CC
BY-SA 4.0 and MIT (with the copyright) into the parent of the directory and
the archive <model>_model.omex there, with the README, the licenses, the
comp model, the flat model (the master entry), the markdown, the antimony,
the extra models and the extra files. With sexes every sex is built
(sex_definition), each with its comp model, flat model, markdown and
antimony in the archive; the flat model of the sex of the definition stays
the master entry. With figure the figure of the definition
(model_figure, an SVG schematic of the organs, routes, substances and
processes) is written into model_output_dir as <sid>.svg and is an
entry of the archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition of the model. |
required |
model_output_dir
|
Path
|
directory of the models; the licenses and the archive are written into its parent. |
required |
model
|
str
|
name of the model, the archive is |
required |
copyright
|
str
|
copyright of the MIT license, e.g. |
required |
readme
|
Path | None
|
the README of the model repository, left out of the archive if
|
None
|
extra_models
|
Sequence[Path]
|
further SBML files (in L3V2) which are entries of the archive, e.g. a submodel which is simulated on its own. |
()
|
extra_files
|
Sequence[Path]
|
further files of other formats which are entries of the
archive, e.g. the ODEs of an extra model ( |
()
|
sexes
|
Sequence[Sex] | None
|
the sexes to build, the sex of the definition among them and
each once, e.g. |
None
|
figure
|
bool
|
write the figure of the definition, |
True
|
Every file of the archive has one location rule: it is below the parent
of model_output_dir, and its location in the archive is its path
relative to it. The built models, their markdown and antimony are in
model_output_dir (./models/<name> for the directory models of a
model package), the licenses in the parent (./mit.txt), an extra model
or file where it lies (./models/<sid>_fluid.xml, ./figures/<x>.png).
The README alone is placed, as ./README.md of the archive, wherever
the file lies.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the stem of an extra model or the key of an extra file
is the key of another entry, if an extra model or file is not below
the parent of |
Returns:
| Name | Type | Description |
|---|---|---|
dict[str, dict[str, Any]]
|
The files with their entries in the COMBINE archive, by the keys of a |
|
factory |
dict[str, dict[str, Any]]
|
|
dict[str, dict[str, Any]]
|
|
|
dict[str, dict[str, Any]]
|
build of every other sex, |
|
dict[str, dict[str, Any]]
|
figure, the stem of every |
|
dict[str, dict[str, Any]]
|
extra model and |
|
dict[str, dict[str, Any]]
|
each |
figure¶
The figure of a model: an SVG schematic of a definition.
model_figure(definition, path) draws the body of a definition as the
COMBINE archive of a model carries it (create_archive(..., figure=True)):
- the title, the substances (a chip in the color of the substance, its name and its mechanisms: binding, erythrocytes, distribution, baseline (an endogenous substance: with a given baseline, or produced with the baseline solved by the library), inhibitions and inductions), the routes, the PD components and the key;
- the circulation: the venous blood on the left, the arterial blood on the right, the lung in series between them, the organs which the arterial blood perfuses and which drain into the venous blood, the liver with the hepatic artery and the portal vein, and the organs which drain into the portal vein; the variant of an organ is named under it;
- in every organ a chip per substance, filled where the substance enters
the tissue of the organ, dashed where it stays in the plasma, and the
processes of the organ as badges: metabolism (
MET, substrate, products and enzyme), transport (TRA, the side and the transporter), custom reaction (CUS, its equation), the excretion into the urine (URI, with the reabsorption), the slow pool (SLW, the exchange with its source, the tissue or the plasma); - the lumen of the intestine: its segments in the order of the transit to
the feces, the oral routes (
ORL), the absorption (ABS), the bile (BIL), the conversions in the lumen (CNV) and the feces (FEC).
The figure is pure python and deterministic: the same definition gives the
same bytes. Its text is monospace and every label is placed by its width at
CHAR_WIDTH per character, an upper bound of the advance of the monospace
fonts it names (DejaVu Sans Mono 0.602 em), so a label stays inside its box
and labels do not overlap, also with many substances: a row grows by lines
instead of running out of its box.
CHAR_WIDTH
module-attribute
¶
The width of a character in units of the font size: an upper bound of the
advance of the monospace fonts of FONT (DejaVu Sans Mono and Liberation
Mono 0.6 em, Menlo 0.602 em, Consolas 0.55 em).
FONT
module-attribute
¶
The fonts of the figure, monospace, so that CHAR_WIDTH bounds every label.
model_figure
¶
Write the figure of a definition, an SVG schematic of the model.
The circulation with the organs, the substances in each organ, the
routes and the processes (see the module), deterministic and without a
dependency beyond the library. The builds of the sexes have the same
organs, substances and processes, so one figure shows them all; its
title names the builds (male build, male and female builds).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition
|
PBPKDefinition
|
the definition of the model. |
required |
path
|
Path
|
the SVG file to write. |
required |
sexes
|
Sequence[Sex] | None
|
the sexes which are built ( |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of the figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
slow_pool¶
The slow (deep) pool of a tissue.
A substance whose terminal phase is the slow release from a deep
compartment of the tissues (a marker of the extracellular volume, a contrast
agent in the days after a dose) has in each organ of the pool the species
Cslow_<s> in the tissue compartment Vti and its exchange with the merged
tissue (source=Part.TISSUE, the default),
or with the plasma of the organ (source=Part.PLASMA), in parallel with the
merged tissue: a deep extracellular space which the substance reaches
through the capillary wall, not through the fast interstitium,
with the exchange kslow_<s> per litre of tissue (1/min) in both forms, so
the exchange of an organ follows the tissue volume of the individual, as the
share of ftissue does, and the coefficient Kpslow_<s> of the pool to its
source: at equilibrium Cslow = Kpslow*Cti (Cslow = Kpslow*Cpl), the pool
holds Kpslow times the concentration of its source in the tissue volume.
Both are constants of the top model, one value for every organ of the pool,
which a fit changes.
The plasma form reads the total plasma concentration, as the Kp of a tissue
does: Kpslow_<s> is relative to the total plasma and the rate has no fu,
so a change of fu (the CKD profile of the binding) changes neither the
equilibrium nor the rate of the pool of a bound substance.
SOURCES
module-attribute
¶
What a slow pool exchanges with: the merged tissue or the plasma of the organ.
OrganCollection
¶
OrganCollection = (
frozenset[Organ | str]
| set[Organ | str]
| list[Organ | str]
| tuple[Organ | str, ...]
)
The organs as SlowPool.organs takes them: a frozenset, set, list or tuple of
Organ members, values or names (as_organs).
SlowPool
dataclass
¶
The slow (deep) pool of the tissue of a substance in some organs.
Attributes:
| Name | Type | Description |
|---|---|---|
substance |
str
|
the id of the substance. |
organs |
OrganCollection
|
the organs with a pool, standard organs in which the
substance has the merged tissue ( |
k |
Q
|
the exchange between the tissue and the pool per litre of tissue
(1/min), |
kp |
Q
|
the concentration of the pool to that of its source at
equilibrium (dimensionless), |
source |
Part | str
|
what the pool exchanges with ( |
check_slow_pools
¶
Check the slow pools of a definition, each on its own.
A known substance, one pool per substance (its constants are shared by
its organs), at least one organ, the tissue or the plasma as its source
(SOURCES), k and kp positive in their units.
That every organ is a standard organ in which the substance has the
merged tissue is checked by PBPKDefinition.validate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pools
|
Iterable[SlowPool]
|
the slow pools. |
required |
known
|
set[str]
|
the ids of the substances of the definition. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The problems, naming the substance. |