zonation¶
The zonation engine, see Zonated liver: the settings of a zonated liver, the geometry of its sinusoid, the gradients along the lobule, the transport of a substance, the flow through the sinusoids, the cell model per zone, the observers, the build, the id scheme, the figures and the bridge from a simulation result of sbmlsim to them. The engine writes plain SBML with the sbml kit and imports neither the PBPK library nor the perfusion library (of pkpdsim it reads pkpdsim.sbml, pkpdsim.database.tables, pkpdsim.species and pkpdsim.zones): a caller (a zonated liver of a body model, a perfused organ) hands over its boundary and its cell model.
The zonated liver: one engine which turns a cell model into a chain of zones.
A zonated liver is a chain of zones from periportal to pericentral, each with
radial layers (pkpdsim.zonation.geometry.Layer) from the sinusoidal lumen to
the bile canaliculus.
settings¶
The settings of the zonated liver.
Geometry
¶
Bases: StrEnum
The geometry of a zone.
BileTransport
¶
Bases: StrEnum
The transport along the bile canaliculus (not implemented before the bile of the engine).
FlowBoundary
¶
Bases: StrEnum
Who supplies the ends of the chain of zones.
OPEN
class-attribute
instance-attribute
¶
The engine: the concentration <s>_<layer>_in (a parameter, 0) flows into
the first zone and the last zone flows out into nothing.
EXTERNAL
class-attribute
instance-attribute
¶
The caller (a perfusion circuit): the chain has the flows between the zones and neither an inflow nor an outflow, which the caller adds.
ZonationSettings
dataclass
¶
ZonationSettings(
n_zones=10,
geometry=SINUSOID,
flow=ImposedFlow(),
bile=ADVECTIVE,
haematocrit=None,
profiles=dict(),
species=RAT,
liver_mass=None,
reference_flow=None,
geometry_constants=None,
fractions=None,
boundary=OPEN,
cell_species=True,
)
The settings of a zonated liver.
Attributes:
| Name | Type | Description |
|---|---|---|
n_zones |
int
|
the number of zones from periportal to pericentral, at least 1 (one zone is the unzonated organ). |
geometry |
Geometry
|
the geometry of a zone. |
flow |
ImposedFlow | PressureFlow
|
how the flow through the sinusoids is given. |
bile |
BileTransport | None
|
the transport in the bile canaliculus; |
haematocrit |
float | None
|
the haematocrit of the lumen entering the chain; |
profiles |
Mapping[str, Profile]
|
the zonal profile of a process by the name of the process. |
species |
Species
|
the species of the geometry and of the reference liver. |
liver_mass |
Value | None
|
the liver mass (kg, g or mg); |
reference_flow |
Value | None
|
the blood flow of the whole reference organ (l/min or
ml/min), which an |
geometry_constants |
SinusoidGeometry | None
|
the geometry replacing the one the table gives
for the species; |
fractions |
Mapping[Layer, Value | float] | None
|
the volume fractions of the layers of the organ, replacing
the table of the species (a perfused organ states its own); the
fraction of a layer is of the parenchyma of the geometry
( |
boundary |
FlowBoundary
|
who supplies the ends of the chain. |
cell_species |
bool
|
every solute has a species in the cell layer; |
layer_fractions
¶
Get the fractions the caller states, every one with its provenance.
Returns:
| Type | Description |
|---|---|
dict[Layer, Value] | None
|
The fraction of every layer the caller states as a |
dict[Layer, Value] | None
|
plain number as the model choice of the caller it is; |
dict[Layer, Value] | None
|
where the caller states none and the table of the species |
dict[Layer, Value] | None
|
applies. |
full_fractions
¶
Get the volume fractions of the layers of the build, with their provenance.
The values of the table (geometry.fractions), or the fractions the
caller states (fractions, a perfused organ its own), a plain number
of which is the model choice it is (layer_fractions).
bile=None drops the bile volume and does not renormalise the other
fractions: the organ loses that fraction of its volume (0.4 % in the
rat) instead of redistributing it. This is deliberate, and the same in
both geometries.
These are the fractions of the whole build: the compartments, the sinusoid count of the flow chain and the calibration of a resistance factor read them here, so a caller who states its own fractions gets one geometry and not two.
Returns:
| Type | Description |
|---|---|
dict[Layer, Value]
|
The fraction of every layer of the build. |
geometry¶
The geometry of the sinusoid, the volume fractions of the layers and the haematocrit.
The fractions are those of the liver parenchyma (stereology, Blouin1977), the
geometry is that of one sinusoid. The two are two sources and not one
cylinder: a shell of the endothelial thickness t_endo (0.165 um, the
representative sinusoid of the predecessor spt model) around the lumen of
radius 4.4 um is 0.81 % of the parenchyma where the stereology assigns the
endothelium 2.8 %, a factor of 3.5 (the thickness consistent with the
fraction would be 0.547 um; the 1.0 um shell of the space of Disse gives
5.55 % against the 4.9 % of the table, which is close). So the fenestral
conductance, whose path length is the thin wall
(transport.fenestral_permeability), is about 3.3 times the one consistent
with the volume it feeds. Nothing rests on it today: the transcellular
permeabilities are 0 until a model sets them, and for a small solute neither
conductance is limiting. The numbers are in
pkpdsim/database/tables/zonation.toml, a section per species. The volume of
a layer is its fraction of the volume of the parenchyma, f_par * mass /
density, split evenly over the zones.
Every number keeps its provenance. A number of the table is a Value
with the source and the notes of its row, which travels into the notes of the
parameter the builder writes from it (pkpdsim.sbml.parameters.value_parameter,
the convention of the whole library), so a released model says where its
stereology, its sinusoid geometry and its fenestral porosity come from and a
reader can tell a measurement from a choice. A number a caller hands over
instead of the table (SinusoidGeometry, ZonationSettings.fractions) is
wrapped as the model choice it is (model_choice) and never looks sourced,
and a number computed from several rows (the plasma and the erythrocytes of
the lumen) carries the sources of the rows it rests on (derived).
Layer
¶
Bases: StrEnum
The radial layers of a zone, from the lumen to the bile.
CELL
class-attribute
instance-attribute
¶
The cells of the organ, the parenchymal cells (for the liver the hepatocytes).
The engine serves any zoned organ, so the layer, its compartment V_cell_<zone> and
its fraction f_cell carry no organ name.
SinusoidGeometry
dataclass
¶
SinusoidGeometry(
r_sin,
L_sin,
t_endo,
t_disse,
r_fen,
n_fen,
porosity_pp,
porosity_pc,
f_par,
haematocrit,
density,
)
The geometry of the sinusoid of a species, every number with its provenance.
A field is the Value of its row of tables/zonation.toml (geometry),
with the source and the notes of the row, which reach the notes of the
parameter the builder writes from it. A caller which replaces a field
(dataclasses.replace) may give a plain number, which is wrapped as the
model choice it is (model_choice, the source ModelChoice and a note
saying the caller supplied it) and never looks sourced.
Attributes:
| Name | Type | Description |
|---|---|---|
r_sin |
Value
|
the sinusoid radius (m). |
L_sin |
Value
|
the sinusoid length (m). |
t_endo |
Value
|
the thickness of the endothelium (m). |
t_disse |
Value
|
the width of the space of Disse (m). |
r_fen |
Value
|
the radius of a fenestra (m). |
n_fen |
Value
|
the number of fenestrae per endothelial area (1/m**2). |
porosity_pp |
Value
|
the fenestral porosity periportal (fraction). |
porosity_pc |
Value
|
the fenestral porosity pericentral (fraction). |
f_par |
Value
|
the parenchymal fraction of the liver mass (fraction). |
haematocrit |
Value
|
the haematocrit of the lumen (fraction). |
density |
Value
|
the density of the liver (kg/l). |
field_unit
¶
Get the unit of a field of SinusoidGeometry by its name.
Raises:
| Type | Description |
|---|---|
KeyError
|
for a name which is no field of the geometry. |
table_value
¶
Get a number of the zonation table with its unit, source and notes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section
|
str
|
the section of |
required |
key
|
str
|
the key of the number. |
required |
Returns:
| Type | Description |
|---|---|
Value
|
The value in the unit definition of its unit. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if the entry is no number. |
ValueError
|
if its unit is no unit of |
lumen_haematocrit
¶
Get the haematocrit which splits the lumen into plasma and erythrocytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
species
|
Species
|
the species. |
required |
haematocrit
|
float | None
|
the haematocrit a caller gives, which is the model choice
it is; |
None
|
Returns:
| Type | Description |
|---|---|
Value
|
The haematocrit. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a haematocrit outside [0, 1] or a species without a liver. |
fractions
¶
Get the volume fractions of the layers of a species, with their provenance.
The lumen is split into plasma and erythrocytes by the haematocrit, which
keeps the lumen; without erythrocytes (haematocrit 0) there is no RBC
layer. The two shares of the lumen rest on two rows (the lumen and the
haematocrit), so they are derived values naming both (derived); the
other layers are the rows of the table unchanged. Kupffer and stellate
cells are no layer and left out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
species
|
Species
|
the species. |
required |
haematocrit
|
float | None
|
the haematocrit of the lumen, the one of the table if
|
None
|
Returns:
| Type | Description |
|---|---|
Mapping[Layer, Value]
|
The fraction of the parenchyma of every layer. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a haematocrit outside [0, 1] or a species without a liver. |
reference_liver_mass
¶
Get the mass (kg) of the reference liver of a species.
The liver of the reference male of physiology_<species>.toml, the liver
the sourced flows of the zonation table (bile_flow) belong to.
bile_flow
¶
Get the canalicular bile flow of the reference liver of a species (l/min).
A sourced value of each species, never scaled from the other one: the rat
secretes about 14 times more bile per g of liver than the human canalicular flow, an upper bound on the species difference (the rat value includes a ductular contribution; like for like with the human total it is about 9 times; see the
entries bile_flow of tables/zonation.toml). The flow of a liver of
another mass is this flow times the mass over reference_liver_mass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
species
|
Species
|
the species. |
required |
Returns:
| Type | Description |
|---|---|
Value
|
The flow (l/min) of the liver of |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the table gives the flow in no unit of ml/min and l/min. |
geometry
¶
Get the sinusoid geometry of a species from the table.
Every field is the Value of its row, with the source and the notes of
the row (table_value): the provenance travels into the parameters the
builder and the flow write from the geometry.
mass_kg
¶
Get the mass of an organ in kg, the one conversion of the engine.
The engine reads a liver mass in one place, so that a mass in an unexpected unit is refused with one message wherever it enters (the volumes of the layers, the number of sinusoids, the flow of the chain).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Q
|
the mass, a |
required |
Returns:
| Type | Description |
|---|---|
float
|
The mass in kg. |
Raises:
| Type | Description |
|---|---|
TypeError
|
for a mass without a unit or without a number. |
ValueError
|
for a mass whose unit is no mass of |
layer_volumes
¶
Get the volume of every layer of every zone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mass
|
Q
|
the liver mass (g, kg or mg). |
required |
n_zones
|
int
|
the number of zones, which share every layer evenly. |
required |
geo
|
SinusoidGeometry
|
the geometry. |
required |
fr
|
Mapping[Layer, Value]
|
the fractions of the layers. |
required |
Returns:
| Type | Description |
|---|---|
Mapping[tuple[Layer, int], Value]
|
The volume (l) of the layer of a zone, the zones numbered from 1 (periportal). |
Raises:
| Type | Description |
|---|---|
ValueError
|
for less than one zone. |
porosities
¶
Get the fenestral porosity of every zone, the gradient of the table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_zones
|
int
|
the number of zones. |
required |
geo
|
SinusoidGeometry
|
the geometry with the periportal and the pericentral porosity. |
required |
Returns:
| Type | Description |
|---|---|
Value
|
The porosity of every zone, periportal first: the linear gradient |
...
|
from |
tuple[Value, ...]
|
centres of the zones ( |
tuple[Value, ...]
|
two ends with their provenance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for less than one zone. |
sinusoid_count
¶
Get the number of sinusoids which carry the lumen of a liver mass.
lumen_fraction
¶
The volume fraction of the lumen, the plasma and the erythrocytes of it.
axial_area
¶
Get the axial cross-section of a layer of the whole liver (m**2).
The volume of the layer in all zones over the sinusoid length.
Raises:
| Type | Description |
|---|---|
ValueError
|
for a layer without a volume in |
profiles¶
The gradients along the lobule: analytic profiles and the weight of a zone.
A protein, a transporter or any other quantity of a zonated liver varies along
the periportal to pericentral axis. A Profile declares that gradient as a
shape of the position, 0 periportal and 1 pericentral, and hands the engine
the level of every zone (Profile.values): a fit estimates the two parameters
of the shape instead of one level per zone, and the same declaration gives the
same gradient at any number of zones.
The levels are normalized: their mean over the volumes of the zones is 1, so
the total amount of the quantity in the liver does not change with its
distribution, whatever the shape. The volumes are those the engine builds, and
pkpdsim.zonation.geometry.layer_volumes splits every layer evenly over the
zones, so a profile without a weight normalizes to the arithmetic mean 1 over
the zones and follows the volumes if a later geometry makes them unequal. Only
the shape of a declaration survives the normalization, not the scale it is
written on: Linear(1.0, 4.0) is the four-fold pericentral gradient, and so is
Linear(2.0, 8.0).
The area of the lobule is lobular_weight, which is passed in where it is the
weight: the figure of the lobule and the comparison with literature values
which are weighted by the area. It is the area of the idealized hexagonal
lobule at a position: the central vein in its centre, the six portal triads in
its corners, and the position of a point the relative distance
d_pp / (d_pp + d_pc) of the nearest triad and the central vein, as the
zonation coordinate of a histological section is measured. The geometry gives
the area in closed form: the points of one position lie on an Apollonius circle
of a triad and the centre, so the area up to a position is a single integral
over one twelfth of the hexagon (lobular_area, _WEDGE_NODES, 32 nodes of
Gauss-Legendre are exact to 1e-11) and lobular_weight is its derivative. The
area of a zone is the difference of the areas of its ends, so the lobular
weighting of the zones is the sequence zone_areas(n), which is exact; a
density handed over as a callable is taken at the centre of every zone, which
for lobular_weight overstates the zone of its peak by 6.7 % as computed
(5.6 % after the levels are divided by their weighted mean, which is what a
profile does to them) and shifts a sharp profile by up to 1.5 % at 10 zones. The weight is 0 at both vessels,
peaks at
1 / (1 + sqrt(3)) where the isoline leaves the hexagon through the edges, and
cuts the lobule in the ratio 2 to 1 at the bisectors, its ⅓ beyond the
position 0.5 being the inner hexagon of the perpendicular bisectors.
The area of the hexagonal lobule reproduces the normalization constants of the
linear patterns of the spt cell model (pkdb_models
tpm/spt/models/spt_liver.py, protein = 0.5 * <constant> * <shape>) to 1 %,
where a uniform weight is 14 % and the weight of a disc 24 % off: the constants
of spt were computed from a hexagonal lobule. Its two sharp patterns it misses
by 23.78 % and 11.08 %, and no weight of the lobule reproduces them (no
distance power, vessel radius, Hill exponent or threshold of this geometry
meets both); the TODO.md of spt records those patterns as too sharp and not
symmetrical, see tests/zonation/test_profiles.py.
Weight
¶
The weight of the zones: a density of the position, the weights of the zones
themselves (zone_areas) or none, the zones of equal volume.
Profile
¶
Bases: Protocol
A gradient of a quantity along the lobule.
values
¶
The level of every zone, normalized to the weighted mean 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
the number of zones. |
required |
weight
|
Weight
|
the weight of the zones, as of |
None
|
Constant
dataclass
¶
Bases: _Pointwise
No gradient, the same level in every zone.
Attributes:
| Name | Type | Description |
|---|---|---|
level |
float
|
the level, which the normalization divides out. |
Linear
dataclass
¶
Bases: _Pointwise
A linear gradient between the two ends of the lobule.
Attributes:
| Name | Type | Description |
|---|---|---|
pp |
float
|
the periportal level (position 0). |
pc |
float
|
the pericentral level (position 1). |
Exponential
dataclass
¶
Bases: _Pointwise
An exponential gradient from the periportal end.
Attributes:
| Name | Type | Description |
|---|---|---|
level |
float
|
the periportal level (position 0), which the normalization divides out. |
decay |
float
|
the decay over the lobule, |
Sigmoid
dataclass
¶
Bases: _Pointwise
A sharp gradient, high in one half of the lobule and low in the other.
The Hill shape 1 / (1 + (x / midpoint)**steepness) of the position, the
sharp patterns of the spt cell model: Sigmoid(0.25, 10.0) is its
periportal pattern and Sigmoid(0.25, 10.0, reverse=True) its pericentral
one.
Attributes:
| Name | Type | Description |
|---|---|---|
midpoint |
float
|
the position of the half level, measured from the periportal end, or from the pericentral end of a reversed shape. |
steepness |
float
|
the Hill exponent of the step. |
reverse |
bool
|
mirror the shape, low periportal and high pericentral. |
Weights
dataclass
¶
A measured gradient, one level per zone.
The levels are those of a lobule of as many zones: a profile of a shape
serves any number of zones, these levels only the zones they were measured
in. The field is levels, since values is the method of a profile.
Attributes:
| Name | Type | Description |
|---|---|---|
levels |
Sequence[float]
|
the level of every zone, from periportal to pericentral. |
values
¶
The measured levels, normalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
the number of zones, which the levels are those of. |
required |
weight
|
Weight
|
the weight of the zones, as of |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, ...]
|
The levels divided by their weighted mean. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a lobule of another number of zones. |
Random
dataclass
¶
A random gradient, the variation of a protein between the zones.
The levels are lognormal around 1 with the coefficient of variation of the declaration, drawn from the seed and the number of zones, so a build repeats them.
Attributes:
| Name | Type | Description |
|---|---|---|
seed |
int
|
the seed of the draw. |
cv |
float
|
the coefficient of variation of the levels. |
values
¶
The drawn levels, normalized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
the number of zones. |
required |
weight
|
Weight
|
the weight of the zones, as of |
None
|
lobular_edge
¶
Get the direction in which the isoline of a position leaves the hexagon.
Up to this direction the isoline is the arc of the Apollonius circle of the
position (lobular_radius); beyond it the position lies outside the lobule
and the edge of the hexagon bounds it, so the isoline follows the straight
edge. The isoline of 0 leaves at once, it is the edge over the whole wedge,
and the isoline of 1, the central vein, never leaves. A renderer samples
the arc and takes the rest straight (pkpdsim.zonation.render).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
the lobular position, 0 periportal (the portal triads) and 1 pericentral (the central vein). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The direction in the wedge of a triad, in |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a position outside the lobule. |
lobular_area
¶
Get the area fraction of the idealized hexagonal lobule up to a position.
The periportal share of the lobule, 0 at the portal triads and 1 at the
central vein. The area beyond the position is bounded by the isoline of the
position up to the direction in which it leaves the hexagon and by the edge
of the hexagon beyond it; lobular_weight is the derivative of the area
and zone_areas the areas of the zones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
the lobular position, 0 periportal (the portal triads) and 1 pericentral (the central vein). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The fraction of the area of the lobule with a position below |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a position outside the lobule. |
lobular_radius
¶
Get the radius at which the lobule has a position in a direction.
The idealized hexagon has its centre (the central vein, position 1) at the
origin and the circumradius 1; theta is the direction measured from the
nearest portal triad, in the wedge [0, pi / 6] (a twelfth of the
hexagon). The points of a position lie on an Apollonius circle of the
triad and the centre, and the circle is cut off by the edge of the
hexagon: the area up to this radius and beyond is what lobular_area
integrates. A point at a smaller radius has a larger position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
the lobular position, 0 periportal and 1 pericentral. |
required |
theta
|
float
|
the direction in the wedge of the triad (rad). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The radius of the position in the direction, the radius of the edge of |
float
|
the hexagon where the isoline has left the lobule (always for the |
float
|
position 0), 0 for the position 1. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a position outside the lobule, or a direction outside the wedge. |
lobular_weight
¶
Get the area of the idealized hexagonal lobule at a lobular position.
The density of the area over the position (the derivative of
lobular_area): the area of the lobule between two positions is its
integral, and over the whole lobule it is 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
the lobular position, 0 periportal (the portal triads) and 1 pericentral (the central vein). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The area of the lobule at the position, 0 at both vessels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a position outside the lobule. |
zone_positions
¶
Get the lobular positions of the centres of the zones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
the number of zones. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The position |
...
|
(periportal). |
Raises:
| Type | Description |
|---|---|
ValueError
|
for less than one zone. |
face_positions
¶
Get the lobular positions of the faces of the zones.
The n + 1 faces of n zones, j / n from the periportal face of the
first zone (0) to the pericentral face of the last (1): the positions at
which the chain evaluates its flows, where zone_positions gives the
centres at which it evaluates the volumes, the profiles and the
concentrations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
the number of zones. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, ...]
|
The position |
Raises:
| Type | Description |
|---|---|
ValueError
|
for less than one zone. |
zone_areas
¶
Get the area fraction of the lobule of every zone.
The exact area of a zone, the difference of the areas of its ends
(lobular_area), and not the weight at its centre: at 10 zones the density
at the centre overstates the zone which holds the peak of the weight by
6.7 % as computed, 5.6 % after the normalisation of a profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
the number of zones. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The fraction of the area of the lobule of every zone, numbered from 1 |
...
|
(periportal), which sum to 1. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for less than one zone. |
normalized
¶
Normalize the levels of the zones to the volume-weighted mean 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
Sequence[float]
|
the level of every zone on the scale of its declaration. |
required |
n
|
int
|
the number of zones. |
required |
weight
|
Weight
|
the weight of the zones, their share of the volume of the
liver. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The levels divided by their weighted mean, so that a liver with the |
...
|
gradient holds the amount of a liver without one. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a number of levels or of weights which is not the number of zones, or for levels whose weighted mean is not positive. |
transport¶
The transport coefficients of a substance in the zonated liver.
A new substance needs only its molar mass: the aqueous diffusion coefficient is
derived from it, the cytosolic one is a fraction of it and the sieving of the
fenestrae follows from the radius of the molecule. A Substance.diffusion
overrides the derived value. The units are SI (m, m**2/s).
Correlation¶
The aqueous diffusion coefficient at 37 C is the Stokes-Einstein scaling with a hydrodynamic radius which grows with a power of the molar mass,
D = D_REF * (Mr / MR_REF) ** -EXPONENT, r = kT / (6 pi eta D),
with T = 310.15 K and the viscosity of water at 37 C, ETA = 0.692 mPa s
(Kestin, Sokolov and Wakeham 1978). EXPONENT = 0.4 lies between the
Stokes-Einstein scaling of a compact sphere (⅓, Young, Carroad and Bell
1980) and the ½ of an extended chain (Polson 1950); a single exponent of ⅓
misses the anchors by 1.15 (the Gd chelate) to 1.41 (insulin), albumin by
1.35; 0.4 keeps every anchor within 1.15. D_REF and MR_REF are the glucose
anchor. test_transport.py checks that the four sourced anchors are reproduced
within a factor of 1.5 (insulin within 2).
Anchors, D in 1e-9 m**2/s at 37 C. Where the measurement is at another
temperature it is scaled with T / eta of water (Stokes-Einstein: x 1.338 from
25 C with eta 0.890 and 0.692 mPa s, x 1.532 from 20 C with eta 1.002 mPa s):
- glucose, 180.16 g/mole: 6.7e-10 m2/s at 25 C (table of diffusion coefficients in water at 25 C, biofilmbook Table 4-1, hypertextbookshop.com), 0.90 at 37 C.
- sucrose, 342.30 g/mole: 5.2e-10 m2/s at 25 C (same table), 0.70 at 37 C.
- Gd-DOTA, 558.6 g/mole, the comparable Gd chelate: Ga-DOTA in D2O at 310 K, 4.38 +- 0.04e-10 m2/s by NMR diffusometry, valid for Gd-DOTA as the two are hydrodynamically similar (ISMRM 2014, abstract 2618). Corrected from D2O to H2O by the assumed viscosity ratio of about 1.23: 0.54 at 37 C. Consistency check, not the anchor: 2.92 +- 0.25e-10 in blood plasma, same abstract. No measured diffusion coefficient of gadoxetate itself was found.
- human serum albumin, 66.5 kDa: D(20,w) = 6.06 +- 0.07e-11 m2/s (bovine serum albumin, dynamic light scattering, extrapolated to water at 20 C and infinite dilution; Bio-protocol e4195, doi 10.21769/BioProtoc.4195), 0.093 at 37 C; the radius it gives, 3.5 nm, is the accepted one of albumin.
- insulin, 5808 g/mole: 0.20 at 37 C, from 1.5e-10 at 25 C. Not confirmed by a source: insulin self-associates, so its measured D depends on concentration, pH and zinc, monomer and hexamer differ by a factor of about 1.6. It is kept as an indicative anchor with a factor of 2 in the test.
The exponent is an interpolation between the two cited scalings, not a fit.
The cytosolic diffusion of a small solute is about a quarter of the aqueous
one: Seksek, Biwersi and Verkman 1997 (J Cell Biol 138:131) measured
D/D0 = 0.26 +- 0.01 in MDCK cells and 0.27 +- 0.01 in fibroblasts by FRAP,
independent of the size of FITC-dextran and Ficoll; F_CYT = 0.27. Dix and
Verkman 2008 (Annu Rev Biophys 37:247) found the slowing less marked than
generally assumed.
The sieving of the fenestrae is the Renkin 1954 (J Gen Physiol 38:225) partition and hindrance of a spherical solute in a cylindrical pore.
The distribution into the erythrocytes is no correlation but the vocabulary of
the PBPK library, read structurally (ErythrocyteDistribution,
erythrocytes_of, blood_cell_coefficient): the two modes are the library's
and so are the parameters of the built model, Kbc_<s> and kex_bc_<s>.
M2_PER_S
module-attribute
¶
The unit of a diffusion coefficient.
M_PER_S
module-attribute
¶
The unit of a permeability.
CM2_PER_S
module-attribute
¶
A diffusion coefficient as it is often published.
L_PER_M3
module-attribute
¶
The conversion of a volume in cubic metres into litres, which every
conductance of a permeability times an area needs (P*A*1000 l_per_m3).
ETA
module-attribute
¶
The viscosity of water at 37 C (Pa s), Kestin, Sokolov and Wakeham 1978.
D_REF
module-attribute
¶
The aqueous diffusion of the reference, glucose, at 37 C (m**2/s).
EXPONENT
module-attribute
¶
The exponent of the molar mass of the diffusion coefficient.
F_CYT
module-attribute
¶
The cytosolic diffusion as a fraction of the aqueous one, Seksek, Biwersi and Verkman 1997.
MR_UNITS
module-attribute
¶
The units of a molar mass, the factor to g/mole, by unit_text.
LENGTH_UNITS
module-attribute
¶
LENGTH_UNITS = {
"metre": 1.0,
"meter": 1.0,
"m": 1.0,
"nanometer": 1e-09,
"nm": 1e-09,
"micrometer": 1e-06,
}
The units of a radius, the factor to m, by unit_text.
ErythrocyteDistribution
¶
Bases: Protocol
How a solute distributes into the erythrocytes, the two modes of the libraries.
The protocol of pkpdsim.pbpk.substance.Erythrocytes, which satisfies it:
the engine reads it structurally because the PBPK library imports the
engine and not the other way round, and the two describe erythrocytes with
one vocabulary (the ids Kbc_<s> and kex_bc_<s> of the built model are
the library's as well).
Attributes:
| Name | Type | Description |
|---|---|---|
mode |
str
|
|
bp |
Q | None
|
the blood to plasma ratio (equilibrium), |
kbc |
Q | None
|
the erythrocyte to plasma coefficient (either mode). |
k_exchange |
Q | None
|
the exchange rate between the plasma and the erythrocytes (kinetic, 1/min). |
Partitioned
¶
Bases: Protocol
A solute which states how it distributes into the erythrocytes.
A pkpdsim.pbpk.substance.Substance satisfies it; a perfusate quantity
of a machine perfusion, which has no erythrocytes to distribute into,
does not have the attribute at all, which is why this is a protocol of
its own and not a member of Solute (erythrocytes_of reads either).
Solute
¶
Bases: Protocol
What rides the chain of zones: an id and a name, nothing more is needed.
A perfusate quantity (oxygen, glucose, an enzyme) is no PBPK substance and
has no molar mass; the engine carries it through the zones by convection.
The optional attributes add the transport which needs them: a diffusion
(or a molar mass mr to derive it from) adds the axial diffusion, a molar
mass the path through the fenestrae (the radius of the molecule). A
pkpdsim.pbpk.substance.Substance satisfies it.
Attributes:
| Name | Type | Description |
|---|---|---|
sid |
str
|
the id of the solute. |
name |
str
|
the name of the solute. |
mr |
Q | None
|
the molar mass, |
diffusion |
Value | None
|
the aqueous diffusion coefficient, |
aqueous_diffusion
¶
molecular_radius
¶
Get the Stokes-Einstein radius of a molecule (m) from its aqueous diffusion.
cytosolic_diffusion
¶
cytosolic_diffusion(d_aq, f_cyt=F_CYT)
Get the diffusion in the cytosol as a fraction of the aqueous one (m**2/s).
axial_velocity
¶
Get the velocity of the blood along a lumen (m/s).
The length over the residence time, L / (lumen / flow); the one
expression the engine and the zonated liver of the PBPK library share,
each with its own lumen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
float
|
the length of the lumen (m). |
required |
lumen
|
float
|
the volume of the lumen (l). |
required |
flow
|
float
|
the flow through the lumen (l/min). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The velocity (m/s); 0 without a flow. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a lumen of 0, which has no velocity. |
axial_diffusion_formula
¶
Get the kinetic law of the axial diffusion between two zones (mmole/min).
D * V_zone * n**2 / L**2 * 60 s_per_min * (c_up - c_down): the
conductance D * A / dx of the prism identity, the cross-section of a
layer being its volume in all zones over the length of the sinusoid
(A = n * V_zone / L) and two zones dx = L / n apart, so it follows the
volume of the zone and needs no radius. The one law of the engine
(ZonationBuilder.axial_diffusion) and of the zonated liver of the PBPK
library (pkpdsim.pbpk.variants.liver_zonated), which wrote it twice;
a caller which scales it by zone appends its factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diffusion
|
str
|
the id of the diffusion coefficient (m**2/s). |
required |
volume
|
str
|
the id of the volume of the layer in the upstream zone (l). |
required |
length
|
str
|
the id of the length of the sinusoid (m). |
required |
n_zones
|
int
|
the number of zones. |
required |
upstream
|
str
|
the id of the concentration of the upstream zone. |
required |
downstream
|
str
|
the id of the concentration of the downstream zone. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formula. |
lateral_area_formula
¶
Get the formula of the lateral area of the lumen of a zone (m**2).
2 * V_lumen / r_sin, the surface of the cylinder of the lumen of the
zone, in m**2 from a volume in litres (/ 1000 l_per_m3): it follows the
volume of the zone, so a change of the organ before a simulation reaches
it. The one expression of the engine
(ZonationBuilder._radial_assignments) and of the zonated liver of the
PBPK library (pkpdsim.pbpk.variants.liver_zonated), which wrote it
twice; the two differ in what they call the lumen of a zone (the
sinusoidal lumen, the whole vascular space), not in the formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lumen
|
str
|
the expression of the volume of the lumen of the zone (l). |
required |
radius
|
str
|
the id of the radius of the lumen (m). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formula. |
dispersion
¶
Get the numerical dispersion of an upwind chain of zones (m**2/s).
v * dx / 2 with the length dx = L / n of a zone: the dispersion the
upwind discretization of the convection adds to the physical diffusion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity
|
float
|
the velocity of the blood (m/s). |
required |
length
|
float
|
the length of the chain (m). |
required |
n_zones
|
int
|
the number of zones. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The dispersion (m**2/s). |
peclet
¶
Get the Peclet number an upwind chain of zones realizes.
v * L / (d_eff + v * dx / 2), which is 2 n when the physical
diffusion is negligible against the dispersion of the chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
velocity
|
float
|
the velocity of the blood (m/s). |
required |
length
|
float
|
the length of the chain (m). |
required |
n_zones
|
int
|
the number of zones. |
required |
d_eff
|
float
|
the effective axial diffusion (m**2/s). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The Peclet number; 0 without a flow. |
renkin
¶
Get the Renkin hindrance of a spherical solute in a cylindrical pore.
(1 - l)**2 * (1 - 2.104 l + 2.09 l**3 - 0.95 l**5) for the ratio l of
the radius of the solute to that of the pore; 1 for a point and 0 once the
solute no longer fits (l >= 1). The polynomial stays positive on [0, 1]
(0.036 at 1), so the hindrance is never negative; the clamp is a guard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lambda_
|
float
|
the ratio of the radius of the solute to that of the pore. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The hindrance in [0, 1]. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a negative ratio, which is no radius. |
reflection
¶
Get the reflection coefficient of the fenestrated endothelium for a solute.
1 - renkin(lambda) for the ratio lambda of the radius of the solute to
that of a fenestra: 0 for a solute the pore does not hinder (it is carried
with the filtered water), 1 for one which no longer fits (the water leaves
it behind). It is the factor 1 - sigma of the solvent drag of the
convective flux through the fenestrae
(ZonationBuilder.filtrate).
The sieving coefficient of the convection is taken to be the hindrance
of the diffusion, the one Renkin ratio the fenestral permeability
already uses, so that one number describes the barrier: a solute which
cannot diffuse through a fenestra is not dragged through it either, and a
solute the pore does not hinder is dragged with the water. The two are not
the same quantity (the classical convective hindrance of a cylindrical
pore, (1-lambda)^2 * (2 - (1-lambda)^2) of the Ferry treatment, exceeds
the diffusive one between the limits), so the drag of a partly sieved
solute is the conservative choice; a model which knows the sieving
coefficient sets the parameter sigma_<s> of the built model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lambda_
|
float
|
the ratio of the radius of the solute to that of the pore. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The coefficient in [0, 1]. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a negative ratio, which is no radius. |
radius_ratio
¶
Get the ratio of the radius of a solute to that of a fenestra, lambda.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
Value
|
the radius of the molecule (a length, converted to m). |
required |
geo
|
SinusoidGeometry
|
the geometry with the radius of a fenestra. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The ratio, the argument of |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a radius which is no length. |
fenestral_permeability
¶
Get the permeability of the endothelium through its fenestrae (m/s).
porosity * d_aq / t_endo * renkin(radius / r_fen).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d_aq
|
Value
|
the aqueous diffusion coefficient (an area per time). |
required |
radius
|
Value
|
the radius of the molecule (a length, converted to m). |
required |
geo
|
SinusoidGeometry
|
the geometry with the thickness of the endothelium and the radius of a fenestra. |
required |
porosity
|
float
|
the fenestral porosity (fraction). |
required |
Returns:
| Type | Description |
|---|---|
Value
|
The permeability (m/s). |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a radius which is no length. |
erythrocytes_of
¶
Get the erythrocyte distribution of a solute, None for a solute without one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
substance
|
Solute
|
the solute, which states its erythrocytes or does not have the attribute. |
required |
Returns:
| Type | Description |
|---|---|
ErythrocyteDistribution | None
|
The distribution, |
ErythrocyteDistribution | None
|
the erythrocytes (and for one which does not know the attribute): its |
ErythrocyteDistribution | None
|
erythrocyte species exchanges with nothing and carries what a caller |
ErythrocyteDistribution | None
|
puts into it. |
blood_cell_coefficient
¶
Get the erythrocyte to plasma coefficient of a distribution, Kbc.
kbc where the distribution gives it, else inverted from the blood to
plasma ratio at the haematocrit, Kbc = (BP - 1 + Hct)/Hct, which is the
relation BP = 1 - Hct + Hct*Kbc of pkpdsim.pbpk.kp.blood_to_plasma
read the other way: the engine needs the concentration of the
erythrocytes, the ratio of the whole blood is what a study measures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ery
|
ErythrocyteDistribution
|
the distribution. |
required |
haematocrit
|
float
|
the haematocrit of the lumen, above 0 (a |
required |
Returns:
| Type | Description |
|---|---|
float
|
The coefficient. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a distribution which gives neither |
diffuses
¶
Get whether a solute has a diffusion: a given one or a molar mass to derive it.
diffusion_of
¶
Get the aqueous diffusion of a substance (m**2/s), the override or derived.
Raises:
| Type | Description |
|---|---|
ValueError
|
for a solute with neither a diffusion nor a molar mass. |
diffusion_parameter
¶
Get the diffusion of a substance as a parameter D_<sid> with its provenance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
substance
|
Solute
|
the substance. |
required |
note
|
str
|
a paragraph which is appended to the notes, what the model of the caller does with the coefficient (the zonated liver of the PBPK library states the Peclet number of its chain). |
''
|
Returns:
| Type | Description |
|---|---|
Parameter
|
The parameter. |
flow¶
The flow through the sinusoids: imposed, or driven by a pressure drop.
A zonated liver has the blood flow of its sinusoids either imposed (a
number, ImposedFlow: the flow of the liver, or the flow per g of liver as the
machine perfusion states it) or driven by the pressure between the portal
and the central end of the sinusoid (PressureFlow).
The pressure-driven sinusoid is the leaky tube of the spt model: a tube of the
radius r_sin with the specific hydraulic resistance W = 8 nu / (pi r_sin**4)
(Pa s/m4) of the lumen, whose wall is crossed by the fenestrae with the
specific hydraulic resistance w (Pa s/m2) of all pores in parallel. The
pressure P(x) along the tube follows P'' = (P - P0) / lambda**2 with
lambda = sqrt(w / W) and the pressures P(0) = p_pp, P(L) = p_pc at its
ends, so the flow Q(x) = -P'(x) / W is, with l = L / lambda and s = x /
lambda,
Q(x) = (p_pp' cosh(l - s) - p_pc' cosh(s)) / (W lambda sinh(l)),
p' = p - P0. This is the exponential solution of spt (PP_Q of
spt_liver_zonated.py) written with hyperbolic functions, which stays finite
when the leak vanishes (lambda diverges, and the flow tends to the
Poiseuille flow (p_pp - p_pc) / (W L) of a tube without a leak).
The flow depends on the position, and the chain evaluates it at the faces of
its zones. What leaks through the fenestrae leaves the lumen, so a
pressure-driven sinusoid has a position-dependent flow and the convection of
the chain no longer carries one Q through all zones. A flow crosses a face,
not a volume, so the engine is a cell-centred finite volume chain: the n + 1
faces of the zones (profiles.face_positions) each have the flow
Q_sin_<site> (m**3/s of one sinusoid) and Q_li_<site> (l/min, the liver has
N_sin sinusoids, which follows the liver mass), where the site is in for
the periportal face of the chain (x = 0) and the zone for its pericentral
face (x = k L / n, ids.zone_flow). The inflow of the chain reads the flow
of the periportal face, the convection out of a zone the flow of the face it
crosses, and the outflow the flow at x = L, so the organ receives the flow at
the portal face which the calibration targets, at every zone count. The
volumes and the zonal profiles stay at the centres of the zones
(profiles.zone_positions), and a zone is read at its centre, but the upwind
scheme gives it the value of its pericentral face wherever the flow varies
along the chain: the steady concentration of a solute the fenestrae stop is
Q(0) / Q(x_k^face), +4.9 % in the first zone to -5.0 % in the last against
the average over the zone at ten zones. That bias is the first order error of
the scheme, which the zone count lowers and a higher order reconstruction
would remove (docs/zonation.md, "Numerical dispersion"). spt evaluated the flow at x = 0 only (its
FLOW: Q dependent on position); this finishes it. The chain does not move the
leaking fluid out of the lumen: the convection carries the solute with the flow
of the face from zone to zone, and the leak of the solute is the fenestral
exchange of the radial barrier.
The count of the fenestrae is derived from the porosity. w needs the
number of fenestrae per area, N_fen. The table gives n_fen = 1e13 /m**2
which with the radius r_fen = 53.5 nm is a porosity of 8.99 %, while the
measured porosity of the same table (Braet and Wisse 2002) is 6 % periportal
and 8 % pericentral and the sieving of the barrier uses it. Using both would
give one endothelium two porosities, so the count is N_fen = eps / (pi
r_fen**2) (6.7e12 periportal, 8.9e12 pericentral), and the table value is a
cross-check (tests/zonation/test_flow.py, within 35 %). The leaky tube has
one w, so it is evaluated at the mean porosity of the sinusoid, the mean of
the zones, which is exact for a tube of uniform porosity and the first order
for the linear gradient of the table. The analytic solution assumes a uniform
leak, so the hydraulic resistance uses the mean porosity and the per-zone
fenestra_counts enter only the cross-check; the zonal porosity profile
scales the solute path of the barrier and not the hydraulic resistance.
The oncotic pressure P0 (p_onc, Poc - Pot of spt) defaults to the mean
of the two pressures, as spt sets P0 = 0.5 (Pa + Pb). The net filtration is
zero then: what leaks out of the first half of the tube returns in the second
half, and the flow is symmetric about the middle. A default which filtered
would change the mass balance of every model which switches to the pressure
flow, so a lower oncotic pressure is a choice of the model.
The flow is not monotonic. With P0 at the mean of the two pressures the
flow falls from the portal end to a minimum in the middle and rises again to
the central end, though the pressure falls monotonically: fluid filters out of
the first half of the tube and is reabsorbed in the second. This is the
signature of P0 and no defect.
The resistance factor is calibrated. nu = resistance_factor * viscosity
and the default factor is derived per species so that the periportal inflow of
the reference liver at the default pressures is the reference flow of the
settings (ZonationSettings.reference_flow, which the PBPK library fills with
the total liver flow of its reference individual,
pkpdsim.pbpk.physiology.reference_flow), the flow an imposed flow
takes by default: switching between the two modes does not change the flow the
organ receives. The chain evaluates its flows at the faces of its zones, so
the flow it receives is the one at the portal face the factor is calibrated to
and the guarantee holds at every zone count, which
test_the_chain_receives_the_reference_flow_in_both_modes pins to 1e-12.
Both modes follow the liver mass from there - the pressure
flow because the number of sinusoids in parallel does
(sinusoid_count), the imposed one because it scales the reference flow with
mass / reference_liver_mass (imposed_flow) - so they agree at every liver
mass and not only at the reference one. The 10 of the spt model gives about
five times that flow for the rat. The guarantee holds at the default pressures,
p_onc, viscosity and the table geometry; the factor is calibrated at those
and does not follow a change of them.
The inflow is calibrated, the mean flow is lower. The target is the
periportal inflow, what the portal vein and the hepatic artery deliver. Q_li,
the mean over the zones, sets the velocity and the Peclet number and is not the
reference flow: with p_onc at the mean pressure the fluid filters out of the
first half and is reabsorbed in the second, so the mean throughput is 17 %
below the inflow at 10 zones (Q_li is 0.8315 of the reference flow, 0.8298 at
40 zones and 0.8297 in the continuum), and the residence time is
correspondingly longer than V / QH. It is the mean over the zones of the mean
of the two faces of a zone, the trapezoidal rule over the faces (mean_flow),
which is the inflow itself for a single zone, whose two faces are the two ends
of the chain and carry the same flow.
A pressure which gives a negative flow in a zone is refused: the chain does not run backwards.
PA_S
module-attribute
¶
The unit of a viscosity.
PA_S_PER_M4
module-attribute
¶
PA_S_PER_M4 = UnitDefinition(
"Pa_s_per_m4",
"pascal*second/meter^4",
name="pascal second per metre^4",
)
The unit of the specific hydraulic resistance of a tube.
PA_S_PER_M2
module-attribute
¶
PA_S_PER_M2 = UnitDefinition(
"Pa_s_per_m2",
"pascal*second/meter^2",
name="pascal second per metre^2",
)
The unit of the specific hydraulic resistance of the pores.
M3_PER_S
module-attribute
¶
The unit of the flow of one sinusoid.
PER_M2
module-attribute
¶
The unit of the count of fenestrae per area.
ImposedFlow
dataclass
¶
A volumetric flow imposed on the organ.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
Q | None
|
the flow through the whole liver, in a volume per time (l/min or ml/min); a plain number is l/min. |
per_mass |
Q | None
|
the flow per mass of liver (ml/min/g, l/min/kg or
ml/min/kg), which the flow of the liver follows, as the machine
perfusion states it. |
PressureFlow
dataclass
¶
PressureFlow(
p_pp=_PORTAL_PRESSURE,
p_pc=_CENTRAL_PRESSURE,
viscosity=_PLASMA_VISCOSITY,
resistance_factor=None,
p_onc=None,
)
A flow driven by the pressure drop over the sinusoid.
Attributes:
| Name | Type | Description |
|---|---|---|
p_pp |
Q
|
the pressure at the periportal end; the default 1333.22 Pa is 10 mmHg (the portal pressure of the spt model). |
p_pc |
Q
|
the pressure at the pericentral end; the default 266.64 Pa is 2 mmHg (the perivenous pressure of the spt model). |
viscosity |
Q
|
the viscosity of the plasma. |
resistance_factor |
float | None
|
the factor of the viscosity of the blood in the
sinusoid over the plasma viscosity, |
p_onc |
Q | None
|
the oncotic pressure |
LeakyTube
dataclass
¶
The leaky tube of a sinusoid, in SI units.
Attributes:
| Name | Type | Description |
|---|---|---|
r_sin |
float
|
the radius of the lumen (m). |
length |
float
|
the length (m). |
t_endo |
float
|
the thickness of the endothelium (m). |
r_fen |
float
|
the radius of a fenestra (m). |
n_fen |
float
|
the number of fenestrae per endothelial area (1/m**2); 0 is a tube without a leak. |
viscosity |
float
|
the viscosity of the blood in the sinusoid (Pa s). |
p_pp |
float
|
the periportal pressure (Pa). |
p_pc |
float
|
the pericentral pressure (Pa). |
p_onc |
float
|
the oncotic pressure (Pa). |
resistance_lumen
¶
Get the specific hydraulic resistance W of the lumen (Pa s/m**4).
resistance_pores
¶
Get the specific hydraulic resistance w of all pores (Pa s/m**2).
4 nu t_endo / (pi**2 r_fen**4 r_sin N_fen), infinite without
fenestrae.
flow
¶
Get the flow (m**3/s) of one sinusoid at a position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
float
|
the position along the tube as a fraction of its length, 0 periportal. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The flow, the Poiseuille flow |
float
|
without fenestrae. |
imposed_flow
¶
Get an imposed flow of the liver in l/min.
A flow which takes the reference flow of the settings is scaled with the
liver mass, reference * mass / reference_mass: the reference flow is
the flow of the reference liver of the species, and a liver of another
mass receives its share of it, as a flow per mass does and as the flow of
a PressureFlow does (its sinusoid count follows the mass). The two
modes therefore give the same flow at every liver mass and not only at
the reference one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
ImposedFlow
|
the imposed flow. |
required |
reference
|
Value | None
|
the reference flow of the organ
( |
required |
mass
|
float
|
the mass of the liver (kg). |
required |
reference_mass
|
float
|
the mass of the reference liver of the species (kg,
|
required |
Returns:
| Type | Description |
|---|---|
float
|
The flow (l/min), as given, not checked for its sign. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a flow which is a formula, has no flow unit, a flow per mass without a unit, or a flow which takes the reference flow of settings which state none. |
fenestra_counts
¶
Get the count of fenestrae per endothelial area of every zone (1/m**2).
The porosity of the zone over the area of a fenestra, eps / (pi r_fen**2):
the porosity of the table, interpolated over the positions of the zones,
is the one number of the endothelium (see the module docstring). The
gradient itself is geometry.porosities, the one the barrier reads, so
the hydraulics and the sieving cannot drift apart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geo
|
SinusoidGeometry
|
the geometry. |
required |
n_zones
|
int
|
the number of zones. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, ...]
|
The counts from periportal to pericentral. |
calibrated_resistance_factor
¶
Get the resistance factor for which the inflow is the reference flow.
The flow of the leaky tube is inversely proportional to the viscosity (W
and w both scale with it, lambda does not), so the factor is the
periportal inflow of the whole reference liver at the default pressures
and the plasma viscosity (factor 1) over the reference flow. The
entrance flow is what the organ receives; the flows of the zones do not
add up in a leaky tube. The factor is a property of the species, its
geometry and its volume fractions, which give the number of sinusoids the
inflow is spread over: it does not follow the pressures, the oncotic
pressure or the viscosity of a model, so the agreement with an imposed flow
holds at their defaults only. The fractions are those of the build
(ZonationSettings.full_fractions) and not the table of the species, or
the calibration would contradict the geometry it calibrates for a caller
which states its own fractions.
The inflow is calibrated, not the mean over the zones: Q_li, which sets
the velocity and the Peclet number, is 0.8315 of the reference flow at 10
zones and 0.8298 at 40, because with P0 at the mean pressure fluid
filters out of the first half of the tube and returns in the second, so
the residence time is longer than V / QH. What the chain receives is
this inflow, the flow of the periportal face of its first zone, at every
zone count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
species
|
Species
|
the species. |
required |
geo
|
SinusoidGeometry
|
the geometry. |
required |
reference
|
Value
|
the reference flow of the organ
( |
required |
fr
|
Mapping[Layer, Value]
|
the volume fractions of the layers of the build
( |
required |
Returns:
| Type | Description |
|---|---|
float
|
The factor (about 50 for the rat). |
resolved_resistance_factor
¶
Get the resistance factor of a pressure flow: the given or the calibrated one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
PressureFlow
|
the pressure flow. |
required |
geo
|
SinusoidGeometry
|
the geometry. |
required |
species
|
Species
|
the species. |
required |
reference
|
Value | None
|
the reference flow of the organ, the target of a calibration. |
required |
fr
|
Mapping[Layer, Value]
|
the volume fractions of the layers of the build, which a calibration needs. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The factor. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a factor which is calibrated and settings which state no reference flow. |
leaky_tube
¶
Get the leaky tube of a pressure flow and a geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
PressureFlow
|
the pressure flow. |
required |
geo
|
SinusoidGeometry
|
the geometry. |
required |
species
|
Species
|
the species, which calibrates a resistance factor of |
required |
reference
|
Value | None
|
the reference flow of the organ
( |
required |
fr
|
Mapping[Layer, Value]
|
the volume fractions of the layers of the build, which a calibration needs. |
required |
Returns:
| Type | Description |
|---|---|
LeakyTube
|
The tube, at the mean porosity of the sinusoid. |
face_flows
¶
Get the flow of the liver at every face of the zones of a pressure flow (l/min).
The n + 1 faces of n zones (profiles.face_positions), periportal
first: the chain carries the flow of a face across it, so the first entry
is the flow the organ receives (x = 0, the target of the calibration)
and the last the flow it releases (x = L).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
ZonationSettings
|
the settings, with a |
required |
geo
|
SinusoidGeometry
|
the geometry. |
required |
mass
|
Q
|
the liver mass. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, ...]
|
The flow of the sinusoids of the liver at every face, |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a pressure drop which gives a negative flow. |
mean_flow
¶
Get the mean flow of the chain over its zones from the flows of its faces.
The mean over the zones of the mean of the two faces of a zone, which is
the trapezoidal rule over the faces: (Q(0)/2 + Q(1/n) + ... + Q(1 -
1/n) + Q(1)/2) / n. This is Q_li of a pressure flow, the flow which
sets the velocity and the Peclet number of the chain, and it is below the
inflow Q(0) at the default oncotic pressure (0.8315 of it at 10 zones,
0.8298 at 40), and equal to it for a single zone, whose two faces are the
two ends of the chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flows
|
Sequence[float]
|
the flows of the |
required |
Returns:
| Type | Description |
|---|---|
float
|
The mean flow, in the unit of |
assignment_rule
¶
Get the assignment rule of a quantity of the flow chain.
The flow chain is computed by rules and not by initial assignments: a simulator applies a change after the initialization, so a change of the organ flow (or of a pressure, of the reference of the bile flow) reaches every flow which derives from it only through a rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pid
|
str
|
the id of the target. |
required |
formula
|
str
|
the formula. |
required |
unit
|
UnitDefinition | object
|
the unit of the formula. |
required |
name
|
str
|
the name of the target. |
required |
Returns:
| Type | Description |
|---|---|
AssignmentRule
|
The assignment rule. |
flow_objects
¶
Get the parameters and initial assignments of the flow of the liver.
An imposed flow is the parameter Q_li (l/min). A pressure flow is the
leaky tube: the pressures, the viscosity, the geometry, the resistances
W_sin and w_sin, lambda_sin, the flow of one sinusoid Q_sin_<zone>
(m**3/s) and of the liver Q_li_<zone> (l/min) at every zone, and Q_li,
the mean of the zones (the flow which sets the velocity of the chain).
The flow follows the pressures and the liver mass (the initial
assignments are evaluated again when they change before a simulation).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
ZonationSettings
|
the settings. |
required |
geo
|
SinusoidGeometry
|
the geometry. |
required |
mass
|
Q
|
the liver mass. |
required |
Returns:
| Type | Description |
|---|---|
list[Parameter | InitialAssignment | AssignmentRule]
|
The parameters, initial assignments and assignment rules. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a negative flow, or a flow which is a formula. |
composition¶
A cell model per zone, composed through SBML comp.
The cells of a zone (the hepatocytes of the liver) are a standalone cell model, which the engine
composes once per zone: one ExternalModelDefinition, one Submodel M<kk>
per zone (ids.submodel) and replaced elements which wire the compartments
and species of the zone onto the ports of the cell model. The cell model is
kept as its own model, because the individual cell models are coupled to
meshes and other architectures; the flat model is what is simulated.
The wiring is anatomical:
- The external port (
CellPorts.external,Vext) is replaced by the space of Disse of the zone, not by the plasma: a hepatocyte faces the space of Disse, and the fenestrated barrier of the radial transport (ZonationBuilder.radial_exchange) is what separates the Disse space from the lumen. In the well-stirred geometry the Disse space is merged into the vascular site, which replaces the port instead. - The cell port (
CellPorts.cell,Vli) is replaced by the hepatocyte and the bile port (CellPorts.bile,Vbi) by the bile canaliculus (not without a bile). - The concentration port
<sid>_extof every substance is replaced by the species of the substance in the Disse layer of the zone, so the cell model sees what the barrier delivers. - A port which holds a substance of the chain (
bind) is replaced by the species of the chain in the layer the caller names, e.g.gedof the cell by the cell species of the substance andged_biby its bile species, in the form of the<sid>_extline: the replaced element is the species of the chain, so its id is the one which survives the flattening (<sid>_cell_z1, notM01__ged). The external concentration stays automatic (every substance of the chain has one);bindis for a cell model which holds the substance itself, or the cell and the chain would hold two copies of it. positionis replaced by a parameterposition_<zone>per zone with the centre of the zone, fromprofiles.zone_positions, the function the profiles use, so the cell model and the profile factors agree on where a zone is.temperatureis replaced by one global parameter of the liver, the same in every submodel: the liver is isothermal (a gradient would be a profile).- Ids the caller replaces by its own model are deleted from every submodel
(
deletions). - A state of the cell which the liver observes (
expose) is reached through comp as well. The flat id of an element of a submodel,M01__glc_cell, exists in no model until the flattening has happened, so the math of the liver cannot name it. The engine adds to the liver one element per zone and exposed id, a proxy which the caller names (exposemaps the id in the cell model to a function of the zone), of the same class as the element of the cell model (a species in the compartment of the cell model's species, replaced onto the same port compartment of the zone; a parameter; a reaction) with its unit, and wires it withcomp:ReplacedByonto the element of the submodel. The proxy is a name, not a state: it copies the class, units, compartment, flags and initial value of the element of the cell model when the model is built (so it cannot drift from it), has no rule or kinetic law, and the flattening merges it with the element of the submodel: the id which survives in the flat model is the proxy's (libsbml keeps the id of the parent element of aReplacedBy), so the flat id of an exposed element is the name the caller gives, and every element which is not exposed staysM<kk>__<id>. The engine does not know how the caller names a state.
The source of the external model definition is <cell_model_id>.xml, relative
to the folder of the model that is written, so that the written pair (the comp
model and the cell model) is portable. write requires that file and raises a
FileNotFoundError naming the expected path. compose and ZonationBuilder.build
stay separate: build is the engine model without a cell model.
REFERENCE_TEMPERATURE
module-attribute
¶
The temperature (degC) of the liver.
CellPorts
dataclass
¶
CellPorts(
external="Vext",
cell="Vli",
bile="Vbi",
position="position",
temperature="temperature",
concentration="{sid}_ext",
profile="p_{process}",
)
The ids of the ports of a cell model.
Attributes:
| Name | Type | Description |
|---|---|---|
external |
str
|
the compartment of the surroundings of the cell, replaced by the space of Disse. |
cell |
str
|
the compartment of the cell, replaced by the cell layer of the zone. |
bile |
str
|
the compartment of the bile, replaced by the canaliculus. |
position |
str
|
the parameter of the lobular position (0 periportal, 1 pericentral). |
temperature |
str
|
the parameter of the temperature (degC). |
concentration |
str
|
the pattern of the concentration port of a substance
in the external compartment, with the substance as |
profile |
str
|
the pattern of the port of the zonal factor of a process of
the cell model, with the process as |
compose
¶
compose(
builder,
cell_model_id,
ports,
deletions=(),
exchange=None,
temperature=None,
shared=(),
expose=None,
cell_model=None,
bind=None,
)
Compose the model of a builder with a cell model per zone.
Without a bile (settings.bile is None) the bile port is not replaced, so
every submodel keeps its own local bile compartment (M01__Vbi, one more
compartment per zone in the flat model); this is expected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
builder
|
ZonationBuilder
|
the builder of the zonated liver; its |
required |
cell_model_id
|
str
|
the id of the cell model, which is the id of its model
and the stem of its file |
required |
ports
|
CellPorts
|
the ports of the cell model. The cell model needs the port
|
required |
deletions
|
Sequence[str]
|
the ids of ports of the cell model, deleted from every submodel (what the liver model replaces by its own). |
()
|
exchange
|
Sequence[str] | None
|
the ids of the solutes of the builder which the cell model
has a concentration port of; |
None
|
temperature
|
Parameter | None
|
the parameter of the temperature of the liver, which the
caller defines (a circuit has one, which the zones follow); |
None
|
shared
|
Sequence[str]
|
the ids of parameters of the cell model (ports) which the liver replaces in every zone by its own parameter of the same id, which the caller adds to the model: a constant of the cell, one for all zones. |
()
|
expose
|
Mapping[str, Callable[[str], str]] | None
|
the elements of the cell model (species, parameters, reactions)
which the math of the liver references: the id in the cell model
to a function of the zone token ( |
None
|
cell_model
|
Model | None
|
the cell model, which |
None
|
bind
|
Mapping[str, tuple[str, Layer]] | None
|
the ports of the cell model which hold a substance of the chain: the
id of the port to the pair of the substance and the |
None
|
Returns:
| Type | Description |
|---|---|
Model
|
The model of |
Model
|
one submodel per zone, the replaced elements, the deletions and the |
Model
|
proxies of the exposed elements. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
write
¶
Write the comp model, flatten it and return the flat model.
The comp model is written as <model id>.xml and the flat model as
<model id>_flat.xml into output_dir, where the file of every external
model definition has to be: the cell model is written there as
<cell model id>.xml when it is given, over a file which holds a version
of the same model but never over a file which holds another model. The
units the flattening copied, one set of definitions per zone, are merged in
the flat model (pkpdsim.sbml.flatten.merge_unit_definitions), so a zone
of it reads the mM of the model and not an M01__mM of its own.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
the composed model ( |
required |
output_dir
|
Path
|
the folder. |
required |
cell_model
|
Model | None
|
the cell model of the composition; |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The path of the flat model. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
if the file of an external model definition is not
in |
FileExistsError
|
if the file of the cell model holds another model. |
ValueError
|
if the composed model does not use the cell model. |
observers¶
The observers of a zonated organ: the quantities a modeller plots and fits.
The observers are read-only: assignment rules and the rate rules of cumulative
ledgers, which no reaction of the model reads, so a model with them has the same
states as a model without them. They are not part of ZonationBuilder.build();
observer_objects creates them and add_observers puts them into a model (for a
composed model after compose), so a caller who does not want them does not pay
for them.
Per substance <s> (layers are the ones whose species the model has: rbc only
at a haematocrit above 0, bile only with a bile, the single vas of the
well-stirred geometry instead of rbc, plasma, endo and disse (see
ZonationBuilder.layers), and no cell with cell_species=False, whose cells
are the species of a cell model):
<s>_pp,<s>_pc(mM): the periportal and the pericentral mean of the concentration in the blood side of the lumen (the plasma,vasin the well-stirred geometry), and<s>_<layer>_pp,<s>_<layer>_pcof every other layer. The mean is that of the first (periportal) and the last (pericentral) third of the sinusoid, every zone weighted bypkpdsim.zones.third_weights(the weighting every zonated model of pkpdsim shares, not a copy).c_outflow_<s>(mM): the concentration of the blood leaving the last zone, the flux out over the flow out. It is not the pericentral mean (<s>_pc), which averages the last third of the length: with a gradient the two differ. It is not defined without a flow and not emitted then.amount_<s>_<layer>(mmole): the amount in a layer, the sum over the zones, andamount_<s>the sum over the layers, the amount in the organ (the bile duct is outside of the organ).cum_in_<s>,cum_out_<s>(mmole): what entered through the inflow and left through the outflow since the start; the outflow ledger holds the filtrate of a net filtration as well (ZonationBuilder.filtrate_efflux, which leaves the space of Disse at the pericentral end and is negative for a net reabsorption). The two andbalance_<s>are of the ends of the chain and are written only for the boundary of the engine (FlowBoundary.OPEN): with an external boundary they belong to the caller, which holds both ends.cum_consumed_<s>(mmole): what the reactions the caller declares consumed.cum_dose_<s>(mmole): what was put into the organ by hand, the initial amounts and the doses; it starts as the amount of the initial concentrations of the model and a dose or a changed initial amount adds to it.balance_<s>(mmole), the mass balance residual, seebalance_expression.
The axial profile is the species of the zones themselves, <s>_<layer>_z<k>;
profile_ids lists them periportal first, so no copy of them is made.
LEDGERS
module-attribute
¶
The kinds of the cumulative amounts.
mean
¶
Get the id of the mean of a substance in a layer over the first or last third.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
substance
|
str
|
the id of the substance. |
required |
layer
|
Layer | str
|
the layer. |
required |
periportal
|
bool
|
the first third, else the last. |
required |
blood
|
Layer | str
|
the layer of the blood side of the lumen ( |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
outflow_concentration
¶
Get the id of the concentration of the blood leaving the organ, c_outflow_<s>.
layer_amount
¶
Get the id of the amount of a substance in a layer, amount_<s>_<layer>.
ledger
¶
Get the id of a cumulative amount, cum_<kind>_<s> (kinds: LEDGERS).
Raises:
| Type | Description |
|---|---|
ValueError
|
for a kind which is no ledger. |
profile_ids
¶
Get the species of the axial profile of a substance in a layer.
The profile is an array observable: one species per zone, concentrations
in mM, which a caller reads in this order. The order is periportal first:
index 0 is zone z1 and the last is the pericentral z<n>, the order of
third_weights and of zone_positions (0 periportal, 1 pericentral). The
species are read as [<id>] in roadrunner. The choice of the species over
a parameter or an assignment per zone is that no copy of a state has to
be kept equal to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
substance
|
str
|
the id of the substance. |
required |
layer
|
Layer | str
|
the layer. |
required |
n_zones
|
int
|
the number of zones. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The ids from periportal to pericentral. |
balance_expression
¶
Get the formula of the mass balance residual of a substance.
The conservation law is: what is in the organ now, plus what left through the outflow and into the bile duct and what the reactions consumed, equals what entered through the inflow plus what was put in by hand:
balance = amount + cum_out + duct + cum_consumed - cum_in - cum_dose
It stays at 0 (to the tolerance of the integrator) whenever the model moves the substance only between its compartments, the boundaries and the reactions declared as consumption: the axial convection and diffusion, the radial exchange and the bile in both transports, with and without a bile, at a haematocrit of 0, in the well-stirred geometry and with an imposed or a pressure driven flow. The solute is moved only by the reactions, each of which takes from one species what it gives to another, and the boundary ledgers integrate the same flows the first and last reaction use, so the balance holds there as well. It fails for a consumption or a dose which is not declared.
The residual is written for the boundary of the engine
(FlowBoundary.OPEN); a model whose ends a caller supplies has no inflow
and no outflow ledger of its own and therefore no residual of its own.
A caller who sets species after loading the model calls sync_dose once
before the simulation: the initial assignment of cum_dose_<s> is
evaluated when the model is loaded and reset, not when a caller writes a
species (the behaviour of roadrunner), so without the call the residual
equals the amount set by hand.
The observers are read-only, but the ledgers are states the integrator controls the error of, so a model with observers and one without agree to the tolerance of the integrator and not bit for bit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
substance
|
str
|
the id of the substance. |
required |
duct
|
bool
|
whether the model has a bile duct. |
required |
observer_objects
¶
Get the observers of a zonated organ.
The weighting of the thirds is pkpdsim.zones.third_weights, which every
zonated model of pkpdsim shares. mean_objects of
pkpdsim.perfusion.observers is not reused: it writes the species ids of the
perfusion core (<q>_<site>, the cells, the living fraction, the pH and the
activities of the sites), which this model does not have; its weights are
the part which carries over.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
ZonationSettings
|
the settings of the model. |
required |
substances
|
Sequence[Solute]
|
the substances of the model. |
required |
consumption
|
Mapping[str, str] | None
|
per substance the formula (mmole/min) of the net rate at which the reactions of the cells consume it, summed over the zones, e.g. the ids of the reactions of the cell models; a substance without one is not consumed. |
None
|
Returns:
| Type | Description |
|---|---|
SbmlObjects
|
The parameters, the assignment rules, the rate rules and the initial |
SbmlObjects
|
assignments of the observers of every substance. |
Note
The layers are the ones whose species the model has: a model with
cell_species=False keeps the species of its cells in its cell model,
under the ids of that model, so the engine has no amount and no mean
of the cell layer to write and writes none.
A model with an external boundary (FlowBoundary.EXTERNAL, a
perfusion circuit) has no inflow and no outflow of its own: the
ledgers cum_in_<s> and cum_out_<s> and the residual balance_<s>
belong to the caller, which holds the two ends of the chain, and are
not written. cum_consumed_<s>, cum_dose_<s>, the amounts, the
means and c_outflow_<s> (the concentration of the blood leaving the
last zone, which needs no boundary) are written as always.
add_observers
¶
Add the observers to a model, which they do not change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
the model of |
required |
objects
|
SbmlObjects
|
the observers ( |
required |
sync_dose
¶
Bring the dose ledger in line with the amounts present at the start.
Sets cum_dose_<s> to amount_<s>, the amount of the substance in the organ,
for a model whose species a caller wrote after loading it. Call it once,
after setting the species and before the first simulation; a dose given
during a run is added to cum_dose_<s> by the caller. Amounts which a
cell model holds in its own species are not in amount_<s>; the cell
model's uptake into them is declared as consumption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runner
|
RoadRunner
|
the loaded roadrunner model with the observers. |
required |
substances
|
Sequence[Solute | str]
|
the substances (or their ids). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the simulation has started (time above 0), when the amount present is no longer the dose. |
builder¶
The build of a zonated liver: one SBML model of the settings.
ZonationBuilder turns ZonationSettings, the substances and a cell model
into a model. The model has the liver mass M_li (kg), the density rho_li,
the parenchymal fraction f_par and the volume fraction f_<layer> of every
layer as constants, and the layers of the zones as compartments
V_<layer>_<zone> (l) with the initial assignment f_<layer> * f_par * M_li /
rho_li / n, so a change of the mass before a simulation sets all volumes, as
the zones of pkpdsim.perfusion follow their organ. The sinusoid has a
compartment per layer of pkpdsim.zonation.geometry.fractions (the
erythrocytes only with a haematocrit above 0); the well-stirred geometry a
vascular compartment (lumen, endothelium, Disse, the sum of their volumes), a cell compartment
(the cells, the hepatocytes of the liver) and the bile compartment per zone; bile=None omits the bile
in both geometries.
Every substance has a species <s>_<layer>_<zone> (mM) in every layer
compartment. The zones are a chain from periportal to pericentral:
- convection
FLOW_<s>_<layer>_z<k>_<layer>_z<k+1>(Q * cof the upstream zone) carries the plasma and the erythrocytes (the vascular site of the well-stirred geometry) from one zone to the next; under an imposed flow the plasma and the erythrocytes have the shares1 - HctandHctof the blood flowQ_li(Q_plasma_li,Q_rbc_li), so they have one velocity. A pressure flow has neither id: it carries the flow of the face a convection crosses (Q_plasma_li_<site>,Q_rbc_li_<site>), the erythrocytes keep the flow of the inflow and the plasma the rest, so the shares are those of the periportal face and of no other. The inflowFLOW_<s>_<layer>_in_<layer>_z1brings the concentration<s>_<layer>_in(a parameter, 0) into the first zone and the outflowFLOW_<s>_<layer>_z<n>_<layer>_outtakes the last zone's concentration out. -
axial diffusion
D_<s>_<layer>_z<k>_<layer>_z<k+1>(reversible,D * A / dx * (c_k - c_k+1)) in the plasma and the space of Disse of the sinusoid geometry.A / dxof zonekisn**2 * V_k / L_sin**2(the layer volume of the zone over the squared sinusoid length, the cross sectionaxial_areaof the whole liver over the zone length), so the conductance follows the liver mass as the volumes do (the two forms are equal becauseV_k = A * L / n, the layer volume of a zone is its cross section times its length). A zone of the well-stirred geometry is mixed and has no axial diffusion. -
radial exchange (
radial_exchange, sinusoid geometry only, the well-stirred vascular compartment contains the Disse space already):FEN_<s>_<zone>(plasma to Disse through the fenestrae),END_<s>_<zone>_inand_out(plasma to endothelial cell to Disse) andPS_<s>_<zone>(Disse to hepatocyte). The fenestral path is physics the engine knows, the paracellular permeabilityP_fen_<s>of an open pore (fenestral_permeability, from the aqueous diffusion, the radius of the molecule and the geometry) times the porosity of the zoneeps_fen_<zone>, which rises fromporosity_pptoporosity_pcof the table over the zone positions (a profileporositymultiplies it). The transcellular paths are model input of a transporter set and not of the molar mass:P_endo_in_<s>,P_endo_out_<s>andP_hep_<s>(m/s of the lateral area) are 0, the path is off, until a model sets them. The molar mass gates the fenestral path alone, because it is the radius of the molecule that it gives: a solute without one (a perfusate quantity, oxygen) has the transcellular and the basolateral path and no fenestral one. The lateral areasA_pd_<zone>(lumen),A_pe_<zone>(abluminal face of the endothelial cell, atr_sin + t_endo) andA_dh_<zone>follow the mass:n_sin * pi * 2 * r_sin * dxis2 V_lumen / r_sinof the zone (n_sin * pi * r_sin**2 * L_sinis the volume of the whole lumen) and the Disse to hepatocyte interface is that area times(r_sin + t_endo + t_disse) / r_sin. -
the filtrate (
filtrate, a pressure-driven sinusoid only): the plasma which leaves the lumen through the fenestrae where the flow of the leaky tube falls takes solute with it (SD_<s>_<zone>, the solvent drag, scaled by1 - sigma_<s>of the reflection coefficient of the fenestrae), flows along the space of Disse (FLOW_<s>_disse_z<k>_disse_z<k+1>ofQ_fil_<zone>) and is reabsorbed where the lumen regains flow. The water is conserved term by term, so a freely sieved solute keeps the concentration of the inflow through the whole chain and a solute no fenestra lets through is enriched byQ(0)/Q(x_k), which is the physics of the two. The chain evaluates its flows at the faces of its zones, so the transmural flux of a zone is the leak of its lumen between its two faces,Q_li_<z<k-1>> - Q_li_<z<k>>(Q_li_in - Q_li_z1for the first): an erythrocyte does not pass a fenestra, so the whole leak of the tube is the plasma's. The erythrocytes therefore keep their flow, the shareHctof the blood which enters the chain, across every face (Q_rbc_li_<site>), and the plasma carries the rest of the flow of the tube there (Q_plasma_li_<site> = Q_li_<site> - Hct * Q_li_in); the three add up to the inflow at every face. The static haematocrit, the ratio of the two volumes, stays the one of the inflow while the flow haematocrit rises towards the pericentral end: the engine does not zone the volumes of the two conduits. -
the exchange of the plasma with the erythrocytes (
erythrocyte_exchange, sinusoid geometry at a haematocrit above 0):RBC_<s>_<zone>,kex_bc_<s> * V_rbc_<zone> * (c_plasma - c_rbc / Kbc_<s>)of every substance which states its distribution into the erythrocytes, the rate law and the parameters of the PBPK library. A substance in equilibrium gets a rate which is fast against the transit of a zone (EQUILIBRATION) and the inflow of its erythrocytes follows that of its plasma; a kinetic one gets its own rate and keeps its own boundary. The chain then carries the blood concentration of the library,Q * BP * c_plasmawithBP = 1 - Hct + Hct*Kbc, as the sum of its two conduits. A substance which states no distribution keeps an erythrocyte species which exchanges with nothing and carries what a caller puts into it.
A flow of 0 and a diffusion of 0 emit no reaction, so the chain is closed or
has no diffusion by construction (a solute larger than a fenestra has no fenestral
reaction either) and no rate law is zero or divides by zero.
Convection is a first order upwind scheme: a chain of n zones disperses like
n tanks in series, a Peclet number of 2 n (effective_peclet).
AXIAL_DIFFUSION
module-attribute
¶
The process of the axial diffusion, which a profile scales by zone.
FILTRATION_FLOOR
module-attribute
¶
The net filtration of a sinusoid below this share of the inflow of its lumen is none.
The symmetric filtration of the default oncotic pressure cancels exactly in
the physics and to a few 1e-16 of the inflow in floating point, a genuine net
filtration is tens of percent of it (ZonationBuilder._net_filtration).
POROSITY
module-attribute
¶
The process of the fenestral porosity, which a profile scales by zone.
ENDOTHELIAL_PERMEABILITY
module-attribute
¶
The process of the transcellular path of the endothelium.
BASOLATERAL_PERMEABILITY
module-attribute
¶
The process of the exchange of the space of Disse with the hepatocyte.
CANALICULAR_FLOW
module-attribute
¶
The process of the bile flow through the canaliculus (advective bile).
CANALICULAR_DIFFUSION
module-attribute
¶
The process of the diffusion along the canaliculus (diffusive bile).
DISPERSION_FACTOR
module-attribute
¶
How far above a diffusion coefficient the numerical dispersion of the chain has to lie for the build to warn.
The upwind convection of n zones disperses like v * dx / 2, which adds to
the physical diffusion: at the physiological defaults of the engine the two are
of the same order (1.63e-9 m2/s against 0.9e-9 m2/s of glucose at ten
zones of a rat liver), so a warning at the first m**2/s of dispersion above the
coefficient fires for every build a correct caller can write and says nothing.
A factor of ten is the point where the dispersion dominates: the Peclet number
of the chain is then within 10 % of the 2 n it realizes without any physical
diffusion, so the coefficient of the substance is decoration and the zone count
alone sets the axial gradient. That is worth saying - a chain of ten zones does
it to albumin - and a chain which has no axial diffusion at all (one zone, the
well-stirred geometry) is not warned about, there being no axial gradient to
get wrong.
EQUILIBRATION
module-attribute
¶
How much faster than the transit of a zone the erythrocytes of a substance in equilibrium exchange with the plasma.
The mode equilibrium of an erythrocyte distribution states that the
erythrocytes follow the plasma instantaneously. The engine has an erythrocyte
species per zone, because the haematocrit splits the lumen into two conduits,
so it cannot collapse the two into one and realizes the equilibrium as an
exchange which is fast against the residence time of the blood in a zone: the
relaxation of the difference c_plasma - c_rbc/Kbc has the rate
kex_bc * (V_rbc/V_plasma + 1/Kbc), and kex_bc is chosen so that this rate
is EQUILIBRATION times the reciprocal of the shortest residence time of a
zone. A factor of 100 leaves the erythrocytes of a zone within about 1 % of
their equilibrium; a model which wants the departure itself states the mode
kinetic and its rate.
ZonationUnits
¶
Bases: OrganUnits
The unit definitions of the model of a zonated organ.
Those of a model of an organ (pkpdsim.sbml.units.OrganUnits: the mass
of an organ, the temperature, the oxygen partial pressure and the other
units which U lacks) and the units of the transport and the pressure
flow of the engine.
ZonationBuilder
¶
Build the SBML model of a zonated liver.
Attributes:
| Name | Type | Description |
|---|---|---|
settings |
the settings. |
|
substances |
the substances of the model. |
|
cell_model |
the cell model of the cells, supplied by the port of
the perfusion core ( |
Check the settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
ZonationSettings
|
the settings. |
required |
substances
|
Sequence[Solute]
|
the substances. |
required |
cell_model
|
object | None
|
the cell model of the cells or |
required |
cell_processes
|
Sequence[str]
|
the processes of the cell model which a profile
can scale; the zonal factor |
()
|
Raises:
| Type | Description |
|---|---|
TypeError
|
for a substance which is no solute. |
processes
¶
Get the names of the processes a profile can scale.
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
The processes: the axial diffusion (the zonal factor |
frozenset[str]
|
|
frozenset[str]
|
by the arithmetic mean of its two zones, a choice and not a result); the cell model and the barrier add |
frozenset[str]
|
theirs ( |
frozenset[str]
|
of the table, |
frozenset[str]
|
and the |
frozenset[str]
|
|
frozenset[str]
|
bile a zone secretes, which the flow of an interface collects over |
frozenset[str]
|
the zones behind it, |
frozenset[str]
|
|
frozenset[str]
|
axial diffusion; the duct interface takes the factor of |
frozenset[str]
|
profile of the one the bile of the settings does not have is |
frozenset[str]
|
refused. This is the registry a later task extends with the |
frozenset[str]
|
processes it adds, and the validation of the profiles is only as |
frozenset[str]
|
strong as its contents. |
compartments
¶
Get the layer compartments of all zones.
Returns:
| Type | Description |
|---|---|
list[Compartment]
|
A compartment |
list[Compartment]
|
volume of the reference liver. |
velocity
¶
The velocity (m/s) of the blood along the chain, 0 without a flow.
The flow over the cross-section of the space it convects through
(_carrier_fraction), which is the lumen of a sinusoid and the whole
vascular compartment of a well-stirred zone.
peclet
¶
The Peclet number the chain realizes with a physical diffusion d_eff.
v * L / (d_eff + v * dx / 2) of pkpdsim.zonation.transport.peclet,
the one expression which the notes of the model, the warning,
effective_peclet and the zonated liver of the PBPK library report;
0 without a flow.
layers
¶
Get the layers of a zone the geometry produced, from the lumen to the bile.
Returns:
| Type | Description |
|---|---|
list[Layer | str]
|
The layers of the sinusoid geometry without the erythrocytes at |
list[Layer | str]
|
a haematocrit of 0 and without the bile for |
list[Layer | str]
|
vascular site, the hepatocyte and the bile of the well-stirred |
list[Layer | str]
|
geometry. |
carrier_flow
¶
The id of the flow of a carrier layer across the face of a site.
The face of a site is the downstream one: the periportal face of the
chain for ids.INFLOW (x = 0, the flow the organ receives) and the
pericentral face of a zone for a zone (the flow it passes on, that of
the last zone the flow the organ releases). An imposed flow is one
number at all of them; a pressure flow has the flow of the leaky tube
at each face.
A well-stirred zone of a pressure flow is the exception: its one
vascular compartment holds the lumen and the space of Disse, so the
plasma which filters out of the lumen stays in it and flows on with
it. The axial water flux of the compartment is the sum of the two,
which is the flow entering the chain, the same across every face
(Q_li_in); the position-dependent Q_li_<zone> of the lumen alone
would make the zones lose water to nowhere and enrich every interior
zone by Q(0)/Q(x). The sinusoid geometry has the two conduits
apart and carries the filtrate explicitly (filtrate).
convection
¶
Get the convection along the chain, the inflow and the outflow.
Returns:
| Type | Description |
|---|---|
list[Reaction]
|
The reactions |
list[Reaction]
|
substance and carrier layer (plasma and erythrocytes; the |
list[Reaction]
|
vascular site of the well-stirred geometry), the inflow |
list[Reaction]
|
|
list[Reaction]
|
the outflow |
list[Reaction]
|
end; none for a flow of 0. A pressure flow carries the flow of |
list[Reaction]
|
the position of every zone ( |
list[Reaction]
|
filters through the fenestrae carries its solute with it |
list[Reaction]
|
( |
axial_diffusion
¶
Get the axial diffusion between consecutive zones.
Returns:
| Type | Description |
|---|---|
list[Reaction]
|
The reversible reactions |
list[Reaction]
|
every diffusing substance in the plasma and the space of Disse of |
list[Reaction]
|
the sinusoid; none for a diffusion of 0, a single zone and the |
list[Reaction]
|
well-stirred geometry. |
bile
¶
Get the transport along the canaliculus, from z<n> to z1 and the duct.
The bile runs the other way than the blood: pericentral to periportal,
and what leaves the canaliculus of z1 is collected in the duct
(<s>_bile_duct, an amount), which gives nothing back.
ADVECTIVE:FLOW_<s>_bile_z<k+1>_bile_z<k>isQ_bile_z<k+1> * cof the upstream (pericentral) zone, andFLOW_<s>_bile_z1_bile_ducttakes the first zone out atQ_bile_z1, the bile flow of the whole liver. The canaliculus collects the secretion of the zones it has passed:Q_bile_<zone>is the share(n - k + 1) / nofQ_bile(_collected_shares), so the pericentral canaliculus carries one zone's secretion and the one at the portal tract the liver's, and the water of the chain is continuous. The transit from the pericentral zone to the duct is thereforeH_n * V_bile / Q_bilewith the harmonic numberH_n(2.9290 timesV_bile / Q_bileat ten zones) and notV_bile / Q_bile, which is what a uniform flow gave. A profilecanalicular_flowis the zonal weight of the secretion, and the flow of an interface is the collected weight of the zones behind it.DIFFUSIVE:D_<s>_bile_z<k+1>_bile_z<k>is reversible,D * A / dx * (c_k+1 - c_k), withA / dx = n**2 * V_k / L_sin**2(the layer volume of a zone is its cross-section times its length,V_k = A * L_sin / n, as for the axial diffusion of the blood; the volume of an interface is the harmonic mean of its two zones). The duct is an absorbing boundary (concentration 0) half a zone from the centre ofz1, soD_<s>_bile_z1_bile_ductis2 D A / dx * c_1, without return. It needs no bile flow.
Returns:
| Type | Description |
|---|---|
list[Reaction]
|
The reactions of every substance; none for |
radial_exchange
¶
Get the radial exchange between the layers of the zones.
Returns:
| Type | Description |
|---|---|
list[Reaction]
|
The reversible reactions per zone and substance: |
list[Reaction]
|
(plasma to the space of Disse through the fenestrae, the derived |
list[Reaction]
|
paracellular path |
list[Reaction]
|
for a solute whose radius reaches the radius of a fenestra, which |
list[Reaction]
|
has no fenestral flux by construction, and none for a solute |
list[Reaction]
|
without a molar mass, which has no radius to derive the path |
list[Reaction]
|
from), |
list[Reaction]
|
(plasma to endothelial cell) and |
list[Reaction]
|
cell to Disse, over the abluminal area |
list[Reaction]
|
|
list[Reaction]
|
|
list[Reaction]
|
and 0 (off) by default. None for the well-stirred geometry. |
Note
The fenestral path is a conductance. The transcellular path is two conductances in series through a compartment with volume, the endothelial cell, so the two paths add as parallel paths only in the quasi-steady state and not instantaneously: early after a change the endothelium is a sink (and drains the Disse space through its reversible abluminal membrane), so with a weak cell path both paths can deliver less than the fenestrae alone.
A flow of 0 and a diffusion of 0 emit no reaction, but the
transcellular reactions exist with a permeability of 0. That is no
inconsistency: Q and the diffusion coefficient are structural
settings fixed at the build, while P_endo_in_<s>,
P_endo_out_<s> and P_hep_<s> are model input a caller sets on
the built model, and a parameter which can change after the build
needs its reaction present to act on. The fenestral reaction is
structural (the radius of the solute is fixed at the build) and
absent for a solute which cannot pass.
erythrocyte_exchange
¶
Get the exchange of the plasma with the erythrocytes of every zone.
RBC_<s>_<zone>: kex_bc_<s> * V_rbc_<zone> * (c_plasma - c_rbc /
Kbc_<s>), the rate law of the kinetic blood cells of the PBPK library
(pkpdsim.pbpk.organ), so the two libraries describe the
erythrocytes with one vocabulary. The erythrocytes approach
Kbc_<s> * c_plasma with the rate kex_bc_<s> / Kbc_<s>.
A substance in equilibrium gets the same reaction with a rate which
is fast against the transit of a zone (EQUILIBRATION), because the
erythrocytes of the engine are a species of their own: the chain then
carries the blood concentration Q * BP * c_plasma of the library,
BP = 1 - Hct + Hct*Kbc, as the sum of its two conduits.
Returns:
| Type | Description |
|---|---|
list[Reaction]
|
The reactions, one per substance with an erythrocyte distribution |
list[Reaction]
|
and zone; none for a substance without one (its erythrocyte |
list[Reaction]
|
species exchanges with nothing and keeps what a caller puts into |
list[Reaction]
|
it), none at a haematocrit of 0 (there is no erythrocyte layer) |
list[Reaction]
|
and none for the well-stirred geometry (one compartment holds |
list[Reaction]
|
both). |
filtrate
¶
Get the transport of the filtrate: the solvent drag and its chain.
The plasma which leaves the lumen of a zone through the fenestrae takes solute with it (the solvent drag), flows along the space of Disse and is reabsorbed where the lumen regains flow. Both are the water balance of the pressure-driven sinusoid, written for the solute:
SD_<s>_<zone>(plasma to the space of Disse of the zone where its lumen loses flow, the reverse where it gains):(1 - sigma_<s>) * (Q_fil_<zone> - Q_fil_<previous>) * c, with the concentration of the side the water comes from (upwind).sigma_<s>is the reflection coefficient of the fenestrae (transport.reflection, the Renkin ratio of the fenestral permeability): a solute which no fenestra lets through (sigma = 1) stays in the lumen and is enriched by the filtration, which is the physics; a freely sieved one (sigma = 0) is carried with the water and keeps the concentration of the inflow.FLOW_<s>_disse_z<k>_disse_z<k+1>:Q_fil_z<k> * cof the space of Disse, upwind, the filtrate flowing along the barrier. Without it the space of Disse of a zone would be a dead end, the net transmural flux would be zero at steady state whatever the drag, and the lumen would keep the whole enrichment (the defect this fixes).FLOW_<s>_disse_z<n>_disse_outat the pericentral end, the filtrate which the lumen has not taken back (the hepatic lymph): the net filtration of the whole sinusoid,Q_fil_z<n>, which is 0 at the default oncotic pressure (the mean of the two pressures, where what filters out of the first half returns in the second) and is then not emitted. The reaction is the zero-gradient boundary of the space of Disse: a net filtration leaves at the concentration of the last zone, and a net reabsorption draws water in at that same concentration, so no gradient is invented at a boundary the engine has no interstitium behind. The observers count it incum_out_<s>(observers.observer_objects), which keeps the mass balance exact.
Returns:
| Type | Description |
|---|---|
list[Reaction]
|
The reactions; none without a filtrate ( |
list[Reaction]
|
imposed flow, the well-stirred geometry, no flow) and none of the |
list[Reaction]
|
drag for a solute which is fully reflected. |
filtrate_efflux
¶
Get the flux (mmole/min) the filtrate takes out of the organ, None for none.
The lymph of the net filtration at the pericentral end
(filtrate), negative for a net reabsorption, which draws water in
there; None when the sinusoid filters and reabsorbs the same amount
(the default oncotic pressure) or carries no filtrate at all. The
observers add it to the outflow ledger.
build
¶
Build the model of the parts that exist: the chain of layers and zones.
Returns:
| Type | Description |
|---|---|
Model
|
The model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a profile of a process nothing uses
( |
effective_peclet
¶
Get the Peclet number a chain of zones realizes.
The upwind convection of n zones adds the numerical dispersion
v * dx / 2 to the physical diffusion, Pe = v * L / (d_eff + v * L / (2
n)), which is 2 n when the physical diffusion is negligible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
ZonationSettings
|
the settings (the zones, the flow, the species). |
required |
d_eff
|
float
|
the effective axial diffusion (m**2/s). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The Peclet number; 0 without a flow. |
Note
A rat liver at 10 zones with an aqueous diffusion coefficient is
expected to trigger the warning of the build: v * dx / 2 is of the
order of 1e-9 m**2/s, the same as the diffusion. That is a property of
the discretization and not a defect of the settings.
ids¶
The id scheme of the zonated liver.
Every id of the engine is built here, so that the zones, the layers, the
transport and the observers agree on them. The zone token is z<k> from
z1 (periportal) to z<n> (pericentral), the one of the PBPK library
(pkpdsim.pbpk.ids.zone) and of the perfusion (pkpdsim.perfusion.ids.zone_id).
A layer of a zone is the site <layer>_<zone> (disse_z3, site), its
volume the compartment V_<layer>_<zone> (volume) and the amount or
concentration of a quantity there <quantity>_<layer>_<zone> (species,
glc_cell_z2). The zonal factor of a process is p_<process>_<zone>
(profile), the pattern of pkpdsim.perfusion.ids.profile, and the submodel
of zone k is M<kk> (submodel, M03).
The liver parameters the layer volumes are computed from are the mass M_li
(kg), the density rho_li (kg/l), the parenchymal fraction f_par and the
volume fraction f_<layer> of every layer. The well-stirred geometry has the
vascular site vas (lumen, endothelium and Disse) instead of those layers.
The zone token and the reaction of a flow between two sites are the engine's
and not the perfusion library's (is_zone, flow): the engine names the
flows of its chain, and a perfused organ names the flows of its circuit, with
the same function, so the two agree. pkpdsim.perfusion.ids re-exports them.
PARENCHYMA
module-attribute
¶
The id of the parenchymal fraction of the liver mass.
VASCULAR
module-attribute
¶
The token of the vascular site of the well-stirred geometry.
HAEMATOCRIT
module-attribute
¶
The id of the haematocrit of the sinusoidal lumen (fraction).
LENGTH
module-attribute
¶
The id of the length of a sinusoid (m), which the zones divide.
TEMPERATURE
module-attribute
¶
The id of the temperature of the liver (degC), one for all zones.
INFLOW
module-attribute
¶
The token of the boundary upstream of the first zone (plasma_in).
OUTFLOW
module-attribute
¶
The token of the boundary downstream of the last zone (plasma_out).
DUCT
module-attribute
¶
The token of the bile duct, downstream of the canaliculus of the first zone
(bile_duct): the collector of the bile, a boundary and no zone.
PRESSURE_PORTAL
module-attribute
¶
The id of the pressure at the periportal end of the sinusoid (Pa).
PRESSURE_CENTRAL
module-attribute
¶
The id of the pressure at the pericentral end of the sinusoid (Pa).
PRESSURE_ONCOTIC
module-attribute
¶
The id of the oncotic pressure of the leaky tube (Pa), Poc - Pot of spt.
VISCOSITY_FACTOR
module-attribute
¶
The id of the factor of the hepatic resistance over the plasma viscosity.
VISCOSITY_LIVER
module-attribute
¶
The id of the viscosity of the blood in the sinusoid (Pa s), the factor times the plasma viscosity.
FENESTRA_RADIUS
module-attribute
¶
The id of the radius of a fenestra (m).
FENESTRA_COUNT
module-attribute
¶
The id of the number of fenestrae per endothelial area (1/m**2), derived from the porosity.
POROSITY_MEAN
module-attribute
¶
The id of the fenestral porosity the leaky tube is evaluated at (the mean over the sinusoid).
LUMEN_FRACTION
module-attribute
¶
The id of the volume fraction of the lumen (plasma and erythrocytes) in the liver.
N_SINUSOIDS
module-attribute
¶
The id of the number of sinusoids of the liver (dimensionless).
RESISTANCE_LUMEN
module-attribute
¶
The id of the specific hydraulic resistance of the lumen (Pa s/m**4).
RESISTANCE_PORES
module-attribute
¶
The id of the specific hydraulic resistance of all pores (Pa s/m**2).
DECAY_LENGTH
module-attribute
¶
The id of the length (m) over which the pressure of the leaky tube relaxes.
BILE_FLOW
module-attribute
¶
The id of the bile flow of the liver (l/min), through every canaliculus.
BILE_FLOW_REFERENCE
module-attribute
¶
The id of the bile flow (l/min) of the reference liver of the species.
MASS_REFERENCE
module-attribute
¶
The id of the mass (kg) of the reference liver the bile flow is given for.
zone
¶
Get the token of zone k, z<k>.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
the number of the zone, from 1 (periportal). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The zone token. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a zone below 1. |
species
¶
Get the id of a quantity in a layer of a zone, <quantity>_<layer>_<zone>.
meta_id
¶
Get the metaid of an element, meta_<sid>.
A compartment which a cell model replaces needs one, or the comp model cannot be flattened.
submodel
¶
Get the id of the submodel of zone k, M<kk>.
The two-digit padding is a minimum width for readability. Above 99 zones
the ids widen (M100) and no longer sort lexically; they stay unique.
Raises:
| Type | Description |
|---|---|
ValueError
|
for a zone below 1. |
flat
¶
Get the id of an element of the cell model of zone k in the flat model.
The flattening of a comp model prefixes the elements of a submodel with its
id, M<kk>__<id>.
layer_flow
¶
Get the flow of a layer through the chain, Q_<layer>_li (l/min).
The plasma and the erythrocytes carry the shares 1 - Hct and Hct of the
blood flow Q_li, so they have one velocity.
zone_flow
¶
Get the flow of a layer across the face of a site, Q_<layer>_li_<site> (l/min).
A pressure-driven sinusoid has a flow which depends on the position, and
the chain evaluates it at the faces of its zones: the site is INFLOW
for the periportal face of the chain (Q_li_in, the flow the organ
receives) and a zone for its pericentral face, the flow it passes on.
None (and the vascular site of the well-stirred geometry) is the blood
flow there, Q_li_<site>.
sinusoid_flow
¶
Get the flow of one sinusoid across the face of a site, Q_sin_<site> (m**3/s).
filtrate_flow
¶
Get the filtrate flow the space of Disse carries out of a zone, Q_fil_<zone> (l/min).
The water which has left the lumen through the fenestrae up to the
pericentral face of the zone, Q_plasma_li_in - Q_plasma_li_<zone> of a
pressure-driven sinusoid: it flows along the space of Disse and is
reabsorbed where the lumen regains flow.
canalicular_flow
¶
Get the bile flow the canaliculus carries out of a zone, Q_bile_<zone> (l/min).
The canaliculus collects the secretion of the zones it has passed, so the
flow leaving zone k towards the portal tract is the secretion of the
zones k to n (the pericentral end): (n - k + 1) / n * Q_bile without
a profile and the collected weights of a canalicular_flow profile with
one. The flow of the first zone, which enters the duct, is the bile flow of
the whole liver.
flow
¶
Get the reaction of the flow of a quantity between two sites.
The vascular space of a zone is the site vas_<zone> of the engine.
diffusion
¶
Get the id of the diffusion coefficient of a quantity in water, D_<q> (m**2/s).
axial
¶
Get the axial diffusion of a quantity between two sites, D_<q>_<from>_<to>.
area
¶
Get the id of the lateral area of an interface in a zone, A_<interface>_<zone>.
The interfaces are pd (plasma to the space of Disse, the lumen), pe (the
abluminal face of the endothelial cell) and dh (the space of Disse to the
hepatocyte).
permeability
¶
Get the id of a permeability of a substance, P_<path>_<quantity>.
The paths are fen (the fenestrae, of an open pore), endo_in and
endo_out (the luminal and the abluminal membrane of the endothelial cell)
and hep (the basolateral membrane of the hepatocyte).
kbc
¶
Get the id of the erythrocyte to plasma coefficient, Kbc_<q>.
The id of the PBPK library (pkpdsim.pbpk.ids.kbc): the concentration of
the erythrocytes over the one of the plasma at equilibrium.
kbc_exchange
¶
Get the id of the exchange rate of the erythrocytes, kex_bc_<q> (1/min).
The id of the PBPK library (pkpdsim.pbpk.ids.kbc_exchange): the rate of
kex_bc_<q> * V_rbc_<zone> * (c_plasma - c_rbc / Kbc_<q>).
reflection
¶
Get the id of the reflection coefficient of the endothelium, sigma_<q>.
The fraction of a solute which the filtered water leaves behind in the
lumen; 1 - sigma is dragged into the space of Disse with it
(pkpdsim.zonation.transport.reflection).
exchange
¶
Get the id of a radial exchange reaction, <kind>_<q>_<zone>[_<suffix>].
The kinds are FEN (plasma to Disse through the fenestrae), END (plasma to
endothelial cell to Disse; the suffix in or out), PS (Disse to
hepatocyte), SD (the solvent drag of the filtered water, plasma to Disse)
and RBC (plasma to erythrocytes).
figures¶
The figures of a zonated model: the profiles over the zones, in space and time.
The functions draw a simulation result of any zonated model, whatever built it,
and know nothing but the id scheme of the engine (pkpdsim.zonation.ids,
pkpdsim.zonation.observers). The result is a pandas.DataFrame with a time
column and a column per selection named by its plain id (glc_cell_z2);
result_frame converts a roadrunner result. The number of zones and the layers
which carry a substance are read from the ids present in the result.
zone_profiles draws a grid of conditions as well: a ZoneColumn per
condition carries plain arrays, the Band of every profile and time, so the
figures stay free of the result objects of a simulator.
pkpdsim.zonation.results is the bridge which reads them out of a
sbmlsim.result.scan.ScanResult, with the draws of an adopted fit as the band.
A figure is built directly as a matplotlib.figure.Figure and owned by the
caller; matplotlib.pyplot and its global state are not used. Every figure is
vector: the heatmap is not rasterized and neither is the solid of its colorbar,
so the SVG holds no embedded image (a viewer which drops embedded raster data
would show an empty panel). colorbar is the one way to that guarantee, here
and in a model, and draw_lobule the renderer of the lobule, which lobule_map
draws its one panel with and a model its own grid of lobules.
POSITION
module-attribute
¶
The label of the axis of the zones, which names its ends: a flip must be visible.
DEFAULT_TIME_UNIT
module-attribute
¶
The unit of the time of the engine (the rates of the engine are per minute).
OUTFLOW_HEIGHT
module-attribute
¶
The height of the outflow panel of space_time relative to a heatmap.
DEFAULT_UNIT
module-attribute
¶
The unit of the concentrations of the profile observers (observers.profile_ids).
MISSING
module-attribute
¶
The colour of a zone without data on a lobule, the default of draw_lobule.
NO_LEGEND
module-attribute
¶
The label matplotlib leaves out of a legend, the lines of a grid of columns.
The grid draws the handles of its legend itself (_row_legend), one set per
row and not one per column, so the lines and markers of a panel carry this
label: a caller who calls ax.legend() on a panel gets nothing, not a second
legend of the colours of one column.
ZoneProfile
dataclass
¶
A profile over the zones, a row of zone_profiles.
transform and source_unit belong to the reading of a result
(pkpdsim.zonation.results.zone_column), which reads the selections in
source_unit or unit and transforms the values into unit: a living
fraction read as dimensionless becomes the percentage of dead cells with
transform=lambda v: 100.0 * (1.0 - v). A frame carries its values in the
unit of the profile already, so zone_profiles of a frame ignores
source_unit and applies transform to the interpolated values.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
the name of the quantity, the label of the y axis. |
unit |
str
|
the unit of the quantity, the unit of the values which are drawn. |
selections |
tuple[str, ...]
|
the ids of the result by zone, periportal first; their number is the number of zones of the row. |
times |
tuple[float, ...] | None
|
the times of this row, |
transform |
Callable[[ndarray], ndarray] | None
|
the transformation of the values into |
source_unit |
str | None
|
the unit the selections are read in, |
Band
dataclass
¶
The values over the zones or over the time: the median and its band.
A simulation without draws carries its values as the median and has no ends, so it draws a line and no fill. A transformation which decreases swaps the ends (the lower draws give the larger value), which fills the same area.
The fields are arrays, which have no one truth value, so the comparison is
the identity of the object (eq=False) and not a field by field one,
which would raise ValueError: The truth value of an array ... is
ambiguous: compare the fields with numpy.allclose.
Attributes:
| Name | Type | Description |
|---|---|---|
median |
ndarray
|
the values, the median over the draws of a run over them. |
lower |
ndarray | None
|
the lower quantile of the draws, |
upper |
ndarray | None
|
the upper quantile of the draws, |
ZoneColumn
dataclass
¶
A column of zone_profiles: one condition, its values by profile and time.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
the name of the condition, the title of its panel in the top row; empty draws no title. |
values |
Mapping[tuple[str, float], Band]
|
the band of every profile and time of the figure, by the label of the profile and the time. |
color |
str | None
|
the colour of every line of the column, |
result_frame
¶
Convert a roadrunner result into the frame the figures draw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
object
|
the result of |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The frame with a column per selection, |
data_axes
¶
Get the axes of the panels of a figure, the axes of a colorbar left out.
A caller which post-processes a returned figure (a title, a limit, a
legend) needs to know which axes are panels: the colorbars of the
heatmaps carry the group id COLORBAR, and this function is the
documented way to tell them apart.
colorbar
¶
Add a colorbar which is vector and is no data axes.
The one way a figure of this package or of a model gets a colorbar: the
solids of a colorbar are a rasterized image by default, which an SVG viewer
that drops embedded raster data shows as an empty bar, so they are
un-rasterized here (tests/zonation/test_figures.py looks for <image in
the saved figures). The axes of the bar carry the group id COLORBAR, so
data_axes tells them from the panels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
figure
|
Figure
|
the figure the colorbar belongs to. |
required |
mappable
|
ScalarMappable
|
the scale which is drawn, a |
required |
ax
|
Axes | Sequence[Axes]
|
the panel the colorbar is taken from, or the panels of a grid it spans. |
required |
label
|
str | None
|
the label of the bar, |
None
|
**kwargs
|
Any
|
further arguments of |
{}
|
Returns:
| Type | Description |
|---|---|
Colorbar
|
The colorbar. |
fill_band
¶
Fill a band between its ends; a band without ends fills nothing.
The look of the bands of zone_profiles, for a model which draws a profile
of its own beside a map and fills the band of a run the same way.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
the axes to fill into. |
required |
x
|
ndarray
|
the positions of the values of the band. |
required |
band
|
Band
|
the band, of which the lower and the upper end are filled. |
required |
color
|
str | ndarray
|
the colour of the fill. |
required |
alpha
|
float
|
the opacity of the fill. |
_BAND_ALPHA
|
zone_profiles
¶
zone_profiles(
result,
profiles,
*,
times,
data=None,
time_unit=DEFAULT_TIME_UNIT,
)
Draw a row per profile and a column per condition, a line per time.
A pandas.DataFrame is one condition: one column, no title, a colour and
a line style per time (a sequential map, early to late), the data of a time
in the colour of that time, and one legend for the figure, right of the
grid, if every row has the same entries, else one per row. A sequence of
ZoneColumn is a grid of conditions: the label of a column is the title of
its panel in the top row, the colour of a line is the colour of its column
where it has one and the line style stays the style of the time, so a
reader tells the times apart inside a column and the columns apart by
colour. A band of the draws of a fit is filled between its ends; the
legend is then one per row, right of the last column, and names the times
of that row. pkpdsim.zonation.results.zone_column builds a column from a
result of sbmlsim.
The x axis is shared and the y axis is shared per row, over the values of
every column of that row. A line axis starts at zero when no value is
negative; a colour scale (space_time, lobule_map) spans the range of
its values instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DataFrame | Sequence[ZoneColumn]
|
the simulation result as a frame, or a column per condition. |
required |
profiles
|
Sequence[ZoneProfile]
|
the profiles, a row each; the number of zones is the number
of selections of a profile. A profile with |
required |
times
|
Sequence[float]
|
the times of the lines, of a row which has none of its own;
interpolated in a frame, read at the nearest point of a column
( |
required |
data
|
DataFrame | None
|
optional data, a long frame with the columns |
None
|
time_unit
|
str
|
the unit of the times, the convention of the engine (min). |
DEFAULT_TIME_UNIT
|
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the result has no column of a selection, or if a column has no band of a profile and a time it is asked for. A frame is read before the data is checked, so a missing selection is named before a label of the data which no profile has. |
ValueError
|
if |
space_time
¶
space_time(
result,
quantity,
*,
layers,
outflow=True,
unit=DEFAULT_UNIT,
time_unit=DEFAULT_TIME_UNIT,
name=None,
vmin=None,
vmax=None,
)
Draw the concentration over the zones and the time, a heatmap per layer.
The heatmaps are as tall as the figure allows and the outflow panel below them is 0.6 of one. The axis of the outflow starts at zero when no value is negative, but a colour scale spans the range of the values it draws: the zero is explicit on the ticks of a colorbar, and a scale from zero would show a gradient of a few percent as one shade.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DataFrame
|
the simulation result. |
required |
quantity
|
str
|
the id of the substance. |
required |
layers
|
Sequence[Layer | str]
|
the layers, a heatmap each, from the top. |
required |
outflow
|
bool
|
add the concentration of the blood leaving the organ below. |
True
|
unit
|
str
|
the unit of the concentrations in the labels; the default is the
unit of the profile observers ( |
DEFAULT_UNIT
|
time_unit
|
str
|
the unit of the time, the convention of the engine (min). |
DEFAULT_TIME_UNIT
|
name
|
str | None
|
the display name of the substance in the labels, the id by default. |
None
|
vmin
|
float | None
|
the lower end of the colour scale, the smallest value drawn by
default; set it (with |
None
|
vmax
|
float | None
|
the upper end of the colour scale, the largest value drawn by default. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the result has no zone of a layer or no outflow. |
ValueError
|
if there is no layer and no outflow to draw. |
layer_profile
¶
layer_profile(
result,
substance,
*,
time,
unit=DEFAULT_UNIT,
time_unit=DEFAULT_TIME_UNIT,
share_y=True,
)
Draw the profile over the zones in every layer which carries the substance.
The layers are those of which the result holds the substance in zones
from z1 on, so a well-stirred build shows its vascular site and a build of
the radial geometry its layers. The grid carries the label of the zones
and the label of the concentration once each, under and left of it.
The axes start at zero when no value is negative; a colour scale
(space_time, lobule_map) spans the range of its values instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DataFrame
|
the simulation result. |
required |
substance
|
str
|
the id of the substance. |
required |
time
|
float
|
the time of the profile, interpolated in the result. |
required |
unit
|
str
|
the unit of the concentration in the labels; the default is the
unit of the profile observers ( |
DEFAULT_UNIT
|
time_unit
|
str
|
the unit of the time, the convention of the engine (min). |
DEFAULT_TIME_UNIT
|
share_y
|
bool
|
draw every panel on one concentration scale, from zero to the
maximum over all layers (the default): the figure compares the
layers at one time, and a layer of which the substance is nearly
absent must look so. Pass |
True
|
Returns:
| Type | Description |
|---|---|
Figure
|
The figure, a panel per layer. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the result holds the substance in no layer. |
draw_lobule
¶
draw_lobule(
ax,
values,
*,
mappable,
missing=MISSING,
thirds=False,
anatomy=False,
labels=False,
points=None,
)
Draw a value per zone on the idealized hexagonal lobule, into given axes.
The renderer of the lobule of this package, which lobule_map draws its
one panel with and a model composes its own grid of maps from (its
conditions, its measured rings, its legend stay in the model; a grid takes
one colorbar over its panels through colorbar). The hexagon has the
circumradius 1, the central vein at the origin and the portal triads at the
corners on the angles 0, 60, ... degrees; a value is drawn as the band of
its zone (pkpdsim.zonation.render.lobule_bands), twelve wedges drawn as
one compound PathPatch per zone (a grid of panels stays light), bounded
by the isolines of the lobular position at (k - 1) / n and k / n, so
the area of a band is the area share of the zone, zone_areas(n). The
centre of this idealization is the central vein itself, so no disc of a
vein lumen covers the pericentral bands.
The axes are set up for the lobule: the limits of the hexagon, an equal aspect, no ticks and no spines. Everything is a vector patch or line, no image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
the axes, which the caller made and owns. |
required |
values
|
Sequence[float] | ndarray
|
the value of every zone, periportal first; their number is the
number of zones. A value which is not finite is a zone without
data and is drawn in |
required |
mappable
|
ScalarMappable
|
the colour of a value, a |
required |
missing
|
ColorType
|
the colour of a zone without data, a grey by default (any
colour matplotlib reads, a name, a hex string or an rgba). It is
taken here and not from the |
MISSING
|
thirds
|
bool
|
draw the isolines of ⅓ and ⅔ as dotted lines, the thirds of the lobulus the histology of a study counts its zones in. |
False
|
anatomy
|
bool
|
draw the outline of the hexagon and the three dots of the portal triad of every corner (portal vein, hepatic artery, bile duct). |
False
|
labels
|
bool
|
name the vessels, |
False
|
points
|
int | None
|
the sampling of the isolines of the bands, the directions over
the arc of an Apollonius circle ( |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if there is no value, so no zone to draw. |
lobule_map
¶
lobule_map(
result,
quantity,
*,
time,
zones,
layer=CELL,
unit=DEFAULT_UNIT,
time_unit=DEFAULT_TIME_UNIT,
name=None,
vmin=None,
vmax=None,
)
Draw the value of every zone on the idealized hexagonal lobule.
The central vein is the centre of the hexagon, the six portal triads are
its corners, and a point has the normalized periportal to pericentral
distance d_pp / (d_pp + d_pc) of the nearest triad and the central
vein: the rim and the corners are zone 1 (periportal), the centre is zone
zones (pericentral). The bands of the zones are bounded by the isolines
of that distance at k / zones, an interval of the position per zone, so
their areas are the area shares of the zones, zone_areas(zones). The
figure is vector: a patch per band and wedge, no image, and the solids of
its colorbar are not rasterized either.
The panel is drawn by draw_lobule, with the outline of the hexagon and
the portal triads of its corners; a model which composes its own grid of
lobules calls that renderer and colorbar directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DataFrame
|
the simulation result. |
required |
quantity
|
str
|
the id of the substance. |
required |
time
|
float
|
the time of the map, interpolated in the result. |
required |
zones
|
int
|
the number of zones of the result. |
required |
layer
|
Layer | str
|
the layer whose zones are drawn, the hepatocytes by default. |
CELL
|
unit
|
str
|
the unit of the concentrations in the labels (the default is the unit of the profile observers, mM). |
DEFAULT_UNIT
|
time_unit
|
str
|
the unit of the time, the convention of the engine (min). |
DEFAULT_TIME_UNIT
|
name
|
str | None
|
the display name of the substance in the labels, the id by default. |
None
|
vmin
|
float | None
|
the lower end of the colour scale, the smallest value drawn by
default; set it (with |
None
|
vmax
|
float | None
|
the upper end of the colour scale, the largest value drawn by default. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The figure, one panel of the hexagon and its colorbar. The colour |
Figure
|
scale spans the range of the values: a line axis starts at zero, a |
Figure
|
colour scale does not, because the zero is explicit on the ticks of a |
Figure
|
colorbar and a scale from zero would show a small gradient as one shade. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the result has no column of a zone. |
ValueError
|
for less than one zone, and for a number of zones which is
not the one of the result: the bands of the map are the area
shares of |
results¶
The bridge from a simulation result to the arrays the zone figures draw.
pkpdsim.zonation.figures draws plain numpy arrays and knows no simulator;
this module reads them out of a sbmlsim.result.scan.ScanResult, with the
units of the result and with the draws of an adopted fit as the band of a
figure: zone_values the zones at a time, zone_band the same over the
draws, series_band a time course over the draws, zone_column the
ZoneColumn of a condition of zone_profiles and band_text the text a
title names the band with. Band is a drawing input of plain arrays and lives
with the figures, next to ZoneColumn; it is re-exported here, so a caller
imports it from either module.
To read the zones at a time, take the nearest point of the result. Take the
last of several points at the same distance, so a change of the simulation
(a medium change, a second dose) uses the state after the change.
series_band aligns full time courses on a common grid. Every time is read
and returned in time_unit, minutes by default, the convention of the engine.
A band reads every selection once over all its draws (_rows, the draws of
the result as the first axis) and converts the time of the result once per
call, not once per draw and selection: a figure of three conditions, five
rows, three times, ten zones and a hundred draws is a few hundred reads of
the dataset instead of tens of thousands. Taking the last of the points
nearest the time over the raw rows of the dataset is what
sbmlsim.result.scan.point_timecourse of a single draw gives: it drops the
state before a change, which is the earlier of the two rows at its time, and
the later row is the one taken here either way;
tests/zonation/test_results.py pins the two against each other, on a grid
of times and on a ragged result whose draws keep their own time points.
Band
dataclass
¶
The values over the zones or over the time: the median and its band.
A simulation without draws carries its values as the median and has no ends, so it draws a line and no fill. A transformation which decreases swaps the ends (the lower draws give the larger value), which fills the same area.
The fields are arrays, which have no one truth value, so the comparison is
the identity of the object (eq=False) and not a field by field one,
which would raise ValueError: The truth value of an array ... is
ambiguous: compare the fields with numpy.allclose.
Attributes:
| Name | Type | Description |
|---|---|---|
median |
ndarray
|
the values, the median over the draws of a run over them. |
lower |
ndarray | None
|
the lower quantile of the draws, |
upper |
ndarray | None
|
the upper quantile of the draws, |
zone_values
¶
zone_values(
res,
selections,
time,
unit,
*,
time_unit=DEFAULT_TIME_UNIT,
)
Get the values of the zones at a time, in a unit (the state after a change).
A selection whose time points are padding alone (NaN, a draw whose
simulation failed) has no value at any time and gives NaN, which is no
error here: over the draws of a run such a draw is left out of the band
(zone_band).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
ScanResult
|
the result of the simulation, of one point of a scan. |
required |
selections
|
Sequence[str]
|
the selections of the zones, periportal first. |
required |
time
|
float
|
the time, in |
required |
unit
|
str
|
the unit of the values. |
required |
time_unit
|
str
|
the unit of |
DEFAULT_TIME_UNIT
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The value of every selection, in |
ndarray
|
padding alone. |
Raises:
| Type | Description |
|---|---|
KeyError
|
naming the variables of the result, if it has no variable of a selection. |
ValueError
|
if a selection is no time course of the result, or if the result is more than one point of a scan. |
zone_band
¶
zone_band(
res,
selections,
time,
unit,
*,
run=None,
time_unit=DEFAULT_TIME_UNIT,
)
Get the values of the zones at a time, over the draws of a run.
A draw whose simulation failed is padding alone (NaN) and is left out of
the median and of the quantiles, so the band is the band of the draws
which ran; a band of which every draw is NaN is NaN and is no error
here, it is a condition the figure draws as a gap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
ScanResult
|
the result of the simulation, of one point of a scan. |
required |
selections
|
Sequence[str]
|
the selections of the zones, periportal first. |
required |
time
|
float
|
the time, in |
required |
unit
|
str
|
the unit of the values. |
required |
run
|
UncertaintyRun | None
|
the run of the draws; |
None
|
time_unit
|
str
|
the unit of |
DEFAULT_TIME_UNIT
|
Returns:
| Type | Description |
|---|---|
Band
|
The band: the median over the draws and the quantiles of the run, or |
Band
|
the values alone for a result without draws. |
Raises:
| Type | Description |
|---|---|
KeyError
|
naming the variables of the result, if it has no variable of a selection. |
ValueError
|
if a selection is no time course of the result, or if the result is more than one point of a scan. |
series_band
¶
series_band(
res,
selection,
unit,
*,
run=None,
time_unit=DEFAULT_TIME_UNIT,
)
Get the time and the values of one selection, over the draws of a run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
ScanResult
|
the result of the simulation, with shared times or with each draw on its own time points. |
required |
selection
|
str
|
the selection. |
required |
unit
|
str
|
the unit of the values. |
required |
run
|
UncertaintyRun | None
|
the run of the draws; |
None
|
time_unit
|
str
|
the unit of the returned time, the convention of the engine (min). |
DEFAULT_TIME_UNIT
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The time in |
Band
|
grids are interpolated onto a common grid within the span of each draw. |
tuple[ndarray, Band]
|
At a change the band uses the state after it. Failed draws are skipped. |
tuple[ndarray, Band]
|
When there are no valid time points, the time and band arrays are empty. |
Raises:
| Type | Description |
|---|---|
KeyError
|
naming the variables of the result, if it has no variable of
the selection, the rule of the module ( |
ValueError
|
if the selection is no time course of the result. |
band_text
¶
Get the text of the band of a run for a title, empty without a run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run
|
UncertaintyRun | None
|
the run of the draws, |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text, |
str
|
quantiles of a run. |
zone_column
¶
zone_column(
res,
profiles,
*,
times,
run=None,
time_unit=DEFAULT_TIME_UNIT,
label="",
color=None,
)
Get the column of a condition of zone_profiles from its result.
Every profile is read at its own times (ZoneProfile.times) or at the
times of the call, in ZoneProfile.source_unit or ZoneProfile.unit, and
ZoneProfile.transform is applied to the median and to each end of the
band: a living fraction read as dimensionless becomes the percentage of
dead cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
ScanResult
|
the result of the condition, of one point of a scan. |
required |
profiles
|
Sequence[ZoneProfile]
|
the profiles of the figure, a row each. |
required |
times
|
Sequence[float]
|
the times of the figure, of a profile which has none of its own. |
required |
run
|
UncertaintyRun | None
|
the run of the draws, |
None
|
time_unit
|
str
|
the unit of the times, the convention of the engine (min). |
DEFAULT_TIME_UNIT
|
label
|
str
|
the name of the condition, the title of its panel. |
''
|
color
|
str | None
|
the colour of the condition, |
None
|
Returns:
| Type | Description |
|---|---|
ZoneColumn
|
The column, the band of every profile and time it is read at. |
render¶
The geometry of the zonated liver for renderers: the tube and the lobule hexagon.
Both are plain numpy arrays and know no figure library. lobule_bands is the
polygons of the idealized hexagonal lobule which
pkpdsim.zonation.figures.draw_lobule colours and lobule_isoline one contour
of the lobular position over the same hexagon, the outline of the lobule (the
position 0), the thirds of a histology or any other level; tube_mesh is the
sinusoid as points and cells.
The tube is the geometry of the engine (SinusoidGeometry): a cylinder of the
sinusoid radius and length along the x axis, from the portal end (x = 0) to
the central end (x = L_sin), with one segment per zone. The arrays are what a
renderer of unstructured meshes takes; the engine neither depends on one nor
renders anything: a script which draws (the videos of gdeobdtpa) installs
pyvista for its run, builds a grid of these arrays and colours the segments by
the zone values, values[k] for the segment k.
lobule_bands
¶
Get the polygons of the zones of the idealized hexagonal lobule.
The hexagon has the circumradius 1, the central vein (zone n) at the
origin and the portal triads (zone 1) at the corners on the angles 0, 60,
... degrees. The band of zone k is [(k - 1) / n, k / n] of the
normalized periportal to pericentral distance, in twelve wedges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
the number of zones. |
required |
points
|
int | None
|
the directions sampled over one wedge, the resolution of the
polygons; |
None
|
Returns:
| Type | Description |
|---|---|
list[list[ndarray]]
|
For every zone from periportal, its twelve polygons, arrays of the |
list[list[ndarray]]
|
points of the two isolines which bound the band; the areas of the |
list[list[ndarray]]
|
zones are |
list[list[ndarray]]
|
zones within 8.6e-4 of a zone at the default, 3e-6 at |
Raises:
| Type | Description |
|---|---|
ValueError
|
for less than one zone or less than two points. |
lobule_isoline
¶
Get the closed polyline of the points of one lobular position.
The isoline over the whole hexagon of lobule_bands: the twelve copies of
the arc of the wedge [0, pi / 6] (lobular_radius), joined into one ring
around the centre, counterclockwise from the triad at the angle 0. A plot
of the ring is the contour of the position and a Polygon of it the area
at or beyond the position, the pericentral side, whose share of the hexagon
is 1 - lobular_area(position).
The isoline of 0 is the hexagon itself, of the circumradius 1 towards a
portal triad and of the apothem cos(pi / 6) towards the middle of an
edge; the isoline of 1 is the centre, the central vein, every radius 0. The
radius in a direction does not grow with the position, and where an isoline
has left the hexagon it follows the edge, so two positions share that part
of their rings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
float
|
the lobular position, 0 periportal (the portal triads) and 1 pericentral (the central vein). |
required |
points
|
int | None
|
the directions sampled over one wedge; the kink where the
isoline leaves through an edge is always one of them. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The points of the ring, an array of shape |
ndarray
|
the circumradius 1 with its centre at the origin, in order around the |
ndarray
|
centre; the last point is the first, so the ring is closed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a position outside the lobule, or for less than two points per wedge. |
tube_mesh
¶
Get the mesh of the sinusoid, a segment per zone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geo
|
SinusoidGeometry
|
the geometry; its sinusoid radius and length (m) give the tube. |
required |
n_zones
|
int
|
the number of zones, the number of segments. |
required |
sides
|
int
|
the number of points of a ring (at least 3). |
24
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The points, an array of shape |
ndarray
|
rings from the periportal end (x = 0) to the pericentral end, and the |
tuple[ndarray, ndarray]
|
cells, an integer array of shape |
tuple[ndarray, ndarray]
|
segment |
tuple[ndarray, ndarray]
|
followed by the |
tuple[ndarray, ndarray]
|
order, counterclockwise about the x axis. A side face joins the ring |
tuple[ndarray, ndarray]
|
point |
tuple[ndarray, ndarray]
|
|
tuple[ndarray, ndarray]
|
the two caps are the rings themselves. VTK has no cell type of a |
tuple[ndarray, ndarray]
|
prism of |
tuple[ndarray, ndarray]
|
faces (see the documentation page). |
Raises:
| Type | Description |
|---|---|
ValueError
|
for less than one zone or less than three sides. |