Skip to content

pbpk figures

The figures of a model and of individuals, see Figures: the anatomy resources, the body of an individual, the shared icons, the content of a definition, the anatomical figure, its interactive page and the publication figure. The schematic is pkpdsim.pbpk.figure (model_figure).

The anatomical figure of a model: the male and the female build on their reference individuals.

The man and the woman stand next to each other (their midlines MIDLINES apart, the arms overlapping, the man drawn over the woman), each captioned with its build. The bodies carry what the definition has:

  • the organs in their drawn forms, sized by their volumes (body.Body);
  • the connections of the model: the portal vein into the liver, the bile from the liver over the gallbladder into the duodenum, the ureters to the bladder and out, the feces, the oral route from the mouth to the stomach;
  • circled icons: the tablet of an oral dose at the mouths, the drop of the blood sample at the arm vein of the man, the syringe of an intravenous dose at the arm of the woman.

Every organ has a label in one of two columns, the left one (right-aligned) pointing into the man, the right one into the woman; the builds share the structure of the definition, so one label serves both. A label shows the circled icon of the organ, its substances (filled: enters the tissue; dashed: plasma only) and, for an organ with processes, its submodel: a row per substance, the compartments plasma, interstitium, cells and the apical side (bile, urine, lumen) as columns, a chip per species the build has, arrows for the exchange, the metabolism (with its enzyme), the apical transport (with its transporter) and the filtration; below it the process lines of the schematic unless the figure is compact. The credit (the anatomy, the license, pkpdsim) belongs in the legend of a figure, never inside it.

OBSERVER_TEXT module-attribute

OBSERVER_TEXT = (
    "arm vein: the observer Carm of every substance"
)

The text of the line of the blood sample, the observer of the arm vein.

MIDLINES module-attribute

MIDLINES = 70.0

The distance of the midlines of the man and the woman [cm].

LEFT module-attribute

LEFT = ('br', 'lu', 'he', 'li', 'sk', 'ki', 'la', 'blood')

The labels of the left column, pointing into the man.

RIGHT module-attribute

RIGHT = (
    "st",
    "sp",
    "pa",
    "si",
    "iv",
    "lumen",
    "ad",
    "bo",
    "mu",
    "go",
    "urine",
)

The labels of the right column, pointing into the woman.

TITLES module-attribute

TITLES = {
    "lu": "lung",
    "he": "heart",
    "br": "brain",
    "li": "liver",
    "ki": "kidney",
    "st": "stomach",
    "si": "small intestine",
    "la": "large intestine",
    "sp": "spleen",
    "pa": "pancreas",
    "go": "gonads",
    "mu": "muscle",
    "sk": "skin",
    "ad": "adipose tissue",
    "bo": "bone",
    "lumen": "intestinal lumen",
    "urine": "urine",
    "blood": "blood sample",
    "iv": "intravenous dose",
}

The headings of the labels.

AnatomyFigure

AnatomyFigure(
    content, *, compact=False, man=None, woman=None
)

The anatomical figure of the content of a model on the reference man and woman.

Parameters:

Name Type Description Default
content ModelContent

the content of the definition.

required
compact bool

labels without the process lines (the panel of a publication figure, whose schematic shows them).

False
man Body | None

the body of the man, the reference man by default.

None
woman Body | None

the body of the woman, the reference woman by default.

None

Prepare the two views.

shown

shown(key)

Whether a label of a key applies to the model.

has_submodel

has_submodel(key)

Whether an organ has processes (or the urine), so its label shows its submodel.

submodel

submodel(key, x, y)

The submodel grid of an organ at (x, y): the SVG, its width and height.

label

label(key, x, y, width, side)

A label at (x, y) of a width; the left column (side -1) right-aligned; the SVG and its height.

place staticmethod

place(items, top, bottom, gap=8.0)

The tops of labels near the heights of their anchors.

Overlapping labels merge into a cluster centred on the anchors of its members (pool adjacent violators); the clusters stay inside [top, bottom].

svg

svg(
    *,
    title=True,
    substances=True,
    scale=3.3,
    text=1.3,
    left=LEFT,
    right=RIGHT,
    tags=False,
    annotations=True,
    sexes=None,
)

The figure as a standalone SVG.

Parameters:

Name Type Description Default
title bool

the name of the model and its builds at the top.

True
substances bool

the substances with their colours at the top.

True
scale float

the bodies [px per cm].

3.3
text float

the scale of the labels, icons and the key.

1.3
left Sequence[str]

the labels of the left column.

LEFT
right Sequence[str]

the labels of the right column.

RIGHT
tags bool

mark the organs of the bodies for hover cards.

False
annotations bool

the labels, the substances, the connections of the model, the captions and the key; without them the bodies with their organs alone, e.g. for a slide (title and substances are then ignored).

True
sexes Sequence[Sex] | None

the sexes which are built, which the subtitle names; None names no build.

None

Returns:

Type Description
str

The SVG, deterministic.

substance_key

substance_key(sid)

The key (data-k) of a substance: its chip and its legend dot, sub:<sid>.

line_key

line_key(badge, text)

The key (data-k) of a process line of a label, txt:<badge>: <text>.

anatomy_figure

anatomy_figure(
    definition,
    path,
    *,
    compact=False,
    title=True,
    substances=True,
    scale=3.3,
    text=1.3,
    annotations=True,
    sexes=None,
)

Write the anatomical figure of a definition on the reference man and woman.

A definition of a laboratory animal (species) is drawn on its animal (pkpdsim.pbpk.visual.animal), the sexes with a physiology in the library.

Parameters:

Name Type Description Default
definition PBPKDefinition

the definition.

required
path Path

the SVG file to write.

required
compact bool

labels without the process lines.

False
title bool

the name of the model at the top.

True
substances bool

the substances at the top.

True
scale float

the bodies [px per cm].

3.3
text float

the scale of the labels, icons and the key.

1.3
annotations bool

the labels, substances, connections, captions and key; without them the bodies with their organs alone, on a transparent background (e.g. for a slide).

True
sexes Sequence[Sex] | None

the sexes which are built (create_archive(..., sexes=...)), which the subtitle names; None names no build, since the two bodies of the figure are the reference individuals and not the builds of the model.

None

Returns:

Type Description
Path

The path of the figure.

The interactive figures: hover cards on the static SVG.

One self-contained HTML file per figure (no external script or style), for the docs and GitHub Pages: hovering an element with a data-k key shows its card, an organ (its volumes in the reference man and woman, its UBERON ids, the form of every substance, the processes), a substance (its mechanisms), a route, the blood sample, the lumen or the urine; a key txt:<text> shows its own text (a process line). The credit (pkpdsim, the anatomy or the organ icons and the license of the anatomograms, CREDIT, ICON_CREDIT) sits in the legend below the figure, never in a card.

The file is a whole page (html_page), which a docs page embeds in a frame, or a snippet (html_snippet, interactive_figure(..., snippet=True)), one <div> which a page of markdown or HTML embeds as it is: everything of the snippet, its style and the ids of its SVG, is scoped to that <div>, so two snippets of one model stand on one page without touching it or each other. The factory of a model writes the snippets beside its SVG figures (pkpdsim.pbpk.create_archive) and the release of a model repository shows them on its index page.

CREDIT module-attribute

CREDIT = figure_credit('anatomy')

The credit of an anatomical figure, for its legend (HTML).

ICON_CREDIT module-attribute

ICON_CREDIT = figure_credit('organ icons')

The credit of a schematic, for its legend (HTML): its organ icons are the shapes of the anatomograms (pkpdsim.pbpk.visual.icons), so the license asks for the attribution, but the figure draws no anatomy.

CONTRACT module-attribute

CONTRACT = 'figurereadouts/1'

The version of the payload of the sidecar write_readouts writes.

Readout dataclass

Readout(id, label, unit, kind)

One timecourse of the model which a place of the figure reports.

Attributes:

Name Type Description
id str

the selection in the compiled model whose values this reports, as the id scheme gives it; it is not checked against a compiled model, the consumer filters the ids the model does not contain. The concentration of a species is the bracket form ([LI__Cpl_api]), since the plain id of a species with hasOnlySubstanceUnits="false" selects its amount in mmole and not its concentration in mM; a concentration which is a parameter (Carm_api, LI__Cu_is_api) and every amount, rate and flux is the plain id.

label str

what it is, in words (apixaban, liver plasma).

unit str

the unit the model uses for it (mmole/liter).

kind Literal['concentration', 'amount', 'rate', 'flux']

concentration, amount, rate or flux.

ReadoutGroup dataclass

ReadoutGroup(label, readouts)

What a key of the figure reports: its label and its readouts.

Attributes:

Name Type Description
label str

the name of the place, for the heading of its panel.

readouts tuple[Readout, ...]

the timecourses of the place, empty for a decoration of the drawing or a place of the model which carries no timecourse.

figure_credit

figure_credit(
    drawn, *, library="PBPK library", url=LIBRARY
)

Get the credit of a figure whose drawn part follows the anatomograms (HTML).

Parameters:

Name Type Description Default
drawn str

what of the figure follows the anatomograms (anatomy, organ icons).

required
library str

the name of the library of pkpdsim which drew the figure.

'PBPK library'
url str

the docs page of that library.

LIBRARY

Returns:

Type Description
str

The credit: pkpdsim with its version, the library with its page, and

str

the attribution of the anatomograms with their license.

cards

cards(content, volumes)

The hover cards of the figures by key, each a list of HTML lines.

Parameters:

Name Type Description Default
content ModelContent

the content of the definition.

required
volumes Mapping[str, Mapping[str, float]]

the organ volumes [l] (or masses [kg]) of the individuals the figure shows, by their name (reference man).

required

Returns:

Type Description
dict[str, list[str]]

The cards of the organs, substances (sub:<sid>), routes

dict[str, list[str]]

(route:oral, route:iv, iv), the sample (sample, blood), the

dict[str, list[str]]

lumen and the urine.

readouts

readouts(content, *, vein='arm vein')

The timecourses which every key of the figure reports.

The keys are the paths of the data-k keys of the figure from the outside in, joined by /, as the nesting of its SVG gives them: an organ (li), a substance of an organ (li/sub:gli), a process line of an organ (li/txt:MET: ...), the blood sample (blood, blood/sub:gli, blood/txt:OBS: ...), the legend chip of a substance (sub:gli), the sample icon (sample), the lumen, the urine and the feces with their substances, the routes and the decorations of the drawing (bladder). The three ways to point at a substance where it is sampled (sub:<sid>, sample, blood/sub:<sid>) give the same readouts, the arm vein observers.

The compartments of a substance in an organ follow its tissue form (OrganContent.parts): the plasma, then for organ the one species, for merged the tissue and its unbound form, for full the interstitium and the cells with both unbound forms. A process line reports the flux of its reaction (flat(organ, process.sid)); a line which carries no process (URI, INH, SLW), a route and a decoration have no readout. An organ reports the compartments of every substance it shows. Ids are built with pkpdsim.pbpk.ids, the keys with the helpers of the figure writer (substance_key, line_key). The ids are what the id scheme gives, not checked against a compiled model: the consumer filters the ids the model does not contain (a zonated organ, whose ids carry a zone, is not supported, see _compartments).

Parameters:

Name Type Description Default
content ModelContent

the content of the definition.

required
vein str

the name of the sampling site in the line of the blood sample, arm vein of the human figure, that of the animal figures their own (VEINS).

'arm vein'

Returns:

Type Description
dict[str, ReadoutGroup]

The group of every key, by the key path.

write_readouts

write_readouts(content, svg, *, vein='arm vein')

Write the readouts of the keys of a figure beside it, for other tools.

The sidecar <svg stem>.readouts.json is {"contract": "figurereadouts/1", "model": <sid>, "keys": {<path>: {"label": str, "readouts": [{"id", "label", "unit", "kind"}]}}}, the paths and groups of readouts, so a reader of the SVG needs no import of pkpdsim: it joins the data-k of the ancestors of a clicked element into a path and looks it up. Every path the anatomical drawing draws is a key (a decoration has no readouts). That does not hold for the schematic figure (pkpdsim.pbpk.figure), which draws paths readouts does not return yet (gu, gu/sub:*, ki/urine/*, lumen/feces/*), so do not write its sidecar. The ids are those of the id scheme and are not checked against a compiled model, the reader filters the ones its model lacks.

Parameters:

Name Type Description Default
content ModelContent

the content of the model the figure shows.

required
svg Path

the SVG file of the figure.

required
vein str

the sampling site named in the figure (readouts), the vein of the animal of an animal figure.

'arm vein'

Returns:

Type Description
Path

The path of the sidecar.

html_page

html_page(svg, cards, title, width, legend, credit=CREDIT)

A self-contained page of a figure with hover cards and its legend.

Parameters:

Name Type Description Default
svg str

the figure, whose elements carry data-k keys.

required
cards dict[str, list[str]]

the cards by key.

required
title str

the title of the page.

required
width int

the width of the figure [px], the maximal width of the page.

required
legend str

the legend below the figure (HTML), the credit appended.

required
credit str

the credit (HTML), CREDIT of an anatomical figure, ICON_CREDIT of a schematic.

CREDIT

The page posts its height to the page which embeds it in a frame ({"pkpdFigure": true, "height": ...}), so the frame can fit it (docs/javascripts/figures.js).

Returns:

Type Description
str

The HTML, deterministic.

html_snippet

html_snippet(
    svg, cards, scope, width, legend, credit=CREDIT
)

A snippet of a figure with hover cards and its legend, for a page.

One <div> with the figure, its legend, its cards and its script, which a page of markdown or HTML embeds as it is, e.g. the index of a model repository. Everything of the snippet is scoped to the <div>: the style sheets of the snippet and of the SVG are written under its id and the ids of the SVG carry it (_scoped_svg), so a page shows two snippets without their styles meeting, and the script is a closure over the <div>. The snippet brings its own light background, so it reads in a dark theme as well, and it has no blank line, which would end it in markdown.

Parameters:

Name Type Description Default
svg str

the figure, whose elements carry data-k keys.

required
cards dict[str, list[str]]

the cards by key.

required
scope str

the id of the <div>, unique on a page, e.g. pkf-<model>-anatomy.

required
width int

the width of the figure [px], the maximal width of the snippet.

required
legend str

the legend below the figure (HTML), the credit appended.

required
credit str

the credit (HTML), CREDIT of an anatomical figure, ICON_CREDIT of a schematic.

CREDIT

Returns:

Type Description
str

The HTML of the snippet, deterministic.

Raises:

Type Description
ValueError

if the style sheet of the SVG cannot be scoped (_scoped_css) or the snippet has a blank line.

interactive_figure

interactive_figure(
    definition,
    path,
    *,
    figure="anatomy",
    snippet=False,
    sexes=None,
)

Write the interactive page or snippet of a figure of a definition.

Parameters:

Name Type Description Default
definition PBPKDefinition

the definition.

required
path Path

the HTML file to write.

required
figure str

anatomy (the anatomical figure of both builds) or schematic (the figure of pkpdsim.pbpk.figure).

'anatomy'
snippet bool

write the snippet of the figure (html_snippet), the <div> which a page embeds, under the id pkf-<sid>-<figure>, instead of a whole page (html_page).

False
sexes Sequence[Sex] | None

the sexes which are built (create_archive(..., sexes=...)), which the figure names as the static figures do; None is the sex of the definition only.

None

Returns:

Type Description
Path

The path of the file.

Raises:

Type Description
ValueError

for another figure.

The publication figure of a model: the anatomical figure and the schematic on one A4 page.

Panel A is the anatomical figure of both builds in compact form (the substances and the submodels, without the process text), panel B the schematic in compact form (the substance dots and the key in its top band), both at the width of the page; only the panels have to fit on the page. The legend sits below them, a caption generated from the content which explains every symbol and names the credit, also written as Markdown for the caption of a manuscript.

PAGE module-attribute

PAGE = (210.0, 297.0, 10.0)

The page: width, height and margin [mm].

legend

legend(content)

The legend of the publication figure: paragraphs of (kind, text), kind b bold, i the credit.

publication_figure

publication_figure(definition, path, *, pdf=False)

Write the publication figure of a definition.

Writes <path> (the panels on the A4 page and the legend below it), <stem>_panels.svg (the A4 page of the panels), <stem>_legend.md (the legend as Markdown) and, with pdf, <stem>_panels.pdf.

Parameters:

Name Type Description Default
definition PBPKDefinition

the definition.

required
path Path

the SVG file of the figure with its legend.

required
pdf bool

also write the PDF of the panels (needs the extra pdf).

False

Returns:

Type Description
Path

The path of the figure.

Raises:

Type Description
ImportError

for pdf without cairosvg (pip install pkpdsim[pdf]).

The body of an individual of the library, drawn from the anatomy resources.

An Individual is a sex, an age, a body weight and a height (the reference individual of the library by default), a functional liver and a gestational progress; its Quantities are the numbers of the library: the volumes of the organs (reference_individual scaled as the build scales the lean tissues, body_composition), the waist and the visceral and subcutaneous adipose tissue (visceral_composition).

A Body draws it in cm, the midline at x 0 and the top of the head at y 0:

  • the outline is the drawing of the sex mapped by the field of field.py: the proportions of the age in y, the trunk stretched by the waist, the limbs and the face by the body mass index, the pregnant belly;
  • the layers on a raster of 0.25 cm: the subcutaneous adipose tissue as a band under the skin, its thickness the subcutaneous volume over the body surface (twice on the trunk), the muscle inside it, the thorax and the abdomen;
  • the organs keep the forms of the drawing (a uniform scale and a shift only): their positions follow the box of their cavity, their size is the cube root of the volume over the volume of the reference individual of the sex, so the organs of the reference fill their cavity but a share (FREE_REF) and the space between them is visceral adipose tissue (abdomen) or mediastinum (thorax); the kidneys are moved out of the shadow of liver and spleen and the heart onto the diaphragm, so every organ shows in a frontal view.

RES_CM module-attribute

RES_CM = 0.25

The raster of the layers of a body [cm per pixel].

CAVITY_ORGANS module-attribute

CAVITY_ORGANS = MappingProxyType(
    {
        "thorax": ("lu", "he"),
        "abdomen": (
            "la",
            "si",
            "li",
            "st",
            "sp",
            "ki",
            "pa",
            "gallbladder",
            "bladder",
            "uterus",
        ),
    }
)

The organs of each cavity, in the order they are drawn (later over earlier).

FREE_REF module-attribute

FREE_REF = MappingProxyType(
    {"thorax": 0.1, "abdomen": 0.24}
)

The share of a cavity of the reference individual which no organ covers.

FREE_MIN module-attribute

FREE_MIN = 0.04

The least free share of a cavity: larger organs (a child) are scaled down together.

Quantities dataclass

Quantities(
    sex, age, bw, height, bmi, bsa, waist, vat, sat, volumes
)

The numbers of the library of an individual.

Attributes:

Name Type Description
sex Sex

the sex.

age float

the age [years].

bw float

the body weight [kg].

height float

the height [cm].

bmi float

the body mass index [kg/m2].

bsa float

the body surface area [m2].

waist float

the waist circumference [cm].

vat float

the visceral adipose tissue [kg].

sat float

the subcutaneous adipose tissue [kg].

volumes Mapping[str, float]

the volume of every organ by its key [l].

Individual dataclass

Individual(
    sex,
    age=35.0,
    bw=None,
    height=None,
    liver=1.0,
    pregnant=0.0,
    label="",
)

An individual of the library to draw.

Attributes:

Name Type Description
sex Sex | str

the sex.

age float

the age [years].

bw float | None

the body weight [kg], the reference individual of the age by default.

height float | None

the height [cm], the reference individual of the age by default.

liver float

the functional liver relative to the healthy one (the factor of a Child-Pugh class).

pregnant float

the progress of a pregnancy, 0 none to 1 at term.

label str

the caption.

quantities

quantities()

The numbers of the library: volumes, waist, adipose depots.

Body

Body(individual, reference=None)

The drawing of an individual [cm].

Parameters:

Name Type Description Default
individual Individual

the individual.

required
reference Body | None

the body of the reference individual of the sex, whose organs set the scale; None for the reference itself and, for every other individual, the cached reference_body of its sex.

None

Compute the outline, the layers and the organs.

landmarks property

landmarks

The landmarks of the drawing (units of the drawing).

size_ratio

size_ratio(key)

The linear size of an organ relative to the reference individual, (V/V_ref)^(⅓).

bounds

bounds()

The left and right edge and the height of the body [cm].

at

at(x, y)

A point of the drawing in the body [cm].

centroid

centroid(key)

The centre of the largest piece of an organ [cm].

pieces

pieces(key, n=2)

The centres of the largest pieces of an organ (the two kidneys) [cm].

toward

toward(key, side)

A point inside an organ towards a side (-1 left, 1 right of the figure) [cm].

edge_point

edge_point(y, side, inset=0.6)

A point inside the outline at the height y of the drawing, at the outer edge of a side [cm].

svg

svg(
    *,
    fills=None,
    skin=SKIN,
    layers=True,
    arteries=True,
    tags=False,
    stroke=0.22,
)

The SVG elements of the body [cm], for a group which places and scales them.

Parameters:

Name Type Description Default
fills Mapping[str, str] | None

colours by organ key over palette.ORGAN_COLORS.

None
skin str

the colour of the skin.

SKIN
layers bool

draw the subcutaneous adipose band, the muscle and the bones.

True
arteries bool

draw the arteries.

True
tags bool

mark every organ with data-k="<key>" (the interactive figure).

False
stroke float

the width of the outlines of the organs [cm].

0.22

Returns:

Type Description
str

The elements, deterministic.

path

path(subpaths, close=True)

The SVG path data of polylines [cm], to a millimetre.

reference_body cached

reference_body(sex)

The body of the reference individual of a sex (cached), the scale of the organs.

body_strip

body_strip(individuals, scale=2.4, font='sans-serif')

Bodies side by side on one scale, the feet aligned, each with its caption.

Parameters:

Name Type Description Default
individuals Sequence[Individual]

the individuals, their label the first line of the caption.

required
scale float

px per cm.

2.4
font str

the font family of the captions.

'sans-serif'

Returns:

Type Description
str

A standalone SVG.

The content of a definition which the figures show.

Read once from a PBPKDefinition through the readers of the schematic (pkpdsim.pbpk.figure), so the anatomical figure, its interactive page and the schematic show the same model: the substances with their colours and mechanisms, per organ the chips (the substance enters the tissue or stays in the plasma) and the process lines, the parts of every substance in every organ (parts_for), the processes as records, the routes, the lumen, the bile, the urine and the PD components.

SubstanceInfo dataclass

SubstanceInfo(sid, name, color, details)

A substance of the definition: its id, name, colour and mechanisms in words.

Chip dataclass

Chip(sid, color, tissue)

A substance in an organ: its id, colour and whether it enters the tissue.

OrganContent dataclass

OrganContent(key, chips, lines, variant, parts)

An organ of the definition.

Attributes:

Name Type Description
key str

the Organ value.

chips tuple[Chip, ...]

the substances of the organ.

lines tuple[tuple[str, str], ...]

the processes as (badge, text) of the schematic.

variant str | None

the variant of the organ in words, None for the standard organ.

parts Mapping[str, str]

the tissue form of every substance (none, organ, merged, full, see pkpdsim.pbpk.parts.Parts).

Process dataclass

Process(
    kind,
    sid,
    organ,
    substrate="",
    products=(),
    protein=None,
    membrane="",
    direction="",
)

A metabolism or transport of an organ (a custom reaction has kind CUS).

Attributes:

Name Type Description
kind str

MET, TRA or CUS.

sid str

the id of the process.

organ str

the Organ value.

substrate str

the substrate of a metabolism, the substance of a transport.

products tuple[str, ...]

the products of a metabolism.

protein str | None

the enzyme or transporter.

membrane str

basolateral or apical of a transport.

direction str

influx or efflux of a transport.

ModelContent dataclass

ModelContent(
    sid,
    name,
    substances,
    organs,
    processes,
    lumen_lines,
    routes,
    route_text,
    luminal,
    lumen_segments,
    readouts,
    bile,
    urine,
    pd,
)

What the figures of a definition show.

Attributes:

Name Type Description
sid str

the id of the model.

name str

the name of the model.

substances tuple[SubstanceInfo, ...]

the substances in the order of the definition.

organs Mapping[str, OrganContent]

the organs by their key.

processes tuple[Process, ...]

the processes of the chemistry.

lumen_lines tuple[tuple[str, str], ...]

the process lines of the lumen, empty without a lumen.

routes tuple[tuple[str, str], ...]

the routes as (kind, substance), kind iv, oral or oral_solution.

route_text str

the routes in words.

luminal tuple[str, ...]

the substances which reach the lumen.

lumen_segments tuple[str, ...]

the lumen segments of the intestine in the order of the transit, empty for a single lumen and without a lumen.

readouts tuple[str, ...]

the readouts of the library which the model requests (PBPKDefinition.readouts); the others are not in its build.

bile tuple[str, ...]

the substances excreted into the bile.

urine tuple[str, ...]

the substances excreted into the urine.

pd tuple[tuple[str, tuple[str, ...], tuple[str, ...]], ...]

the PD components as (id, reads, sets).

of classmethod

of(definition)

Read the content of a definition through the readers of the schematic.

color

color(sid)

The colour of a substance.

has_route

has_route(kind)

Whether a route of a kind (iv, oral) exists; oral includes the solutions.

The icons of the figures, one graphical language for all of them.

Every icon sits on a white circle: the organs (their shapes in the anatomy resources; the bowel for the intestine and its lumen, the body for the skin, fat cells for the adipose tissue, whose drawn depot has no recognisable form at this size), the oral dose (a tablet), the intravenous dose (a syringe) and the blood sample (a drop). An icon is an SVG fragment centred at a point. The pictogram of an impaired organ (impaired_organ) is the liver, a kidney or the heart with its details on a card framed in the color of an impairment class, its lost part faded.

organ_keys

organ_keys(sex='male')

The keys which have an organ icon: the organs, gu and lumen.

ring

ring(cx, cy, r, color=RING)

The white circle of an icon.

organ

organ(key, cx, cy, d=24.0, sex='male')

The icon of an organ on a circle of diameter d, centred at (cx, cy); empty without an icon.

The icon is in the greys of palette.ORGAN_GREYS, so that the colours of a figure are those of the substances and the tissues.

impaired_organ

impaired_organ(
    key,
    cx,
    cy,
    width,
    height,
    loss,
    color,
    *,
    title=None,
    sex="male",
)

The pictogram of an impaired organ on a card framed in the color of its class.

The organ (li, ki or he, its shape in the anatomy resources) is drawn in its color of palette.ORGAN_COLORS, shaded, with its details (the lobes and the gallbladder of the liver, the cortex and the vessels and the ureter at the hilum of a kidney, the groove of the heart); its lost part, loss of the area, is faded. The card is white with a frame in color, so the pictogram reads in a light and a dark theme alike. The ids of the gradient are a hash of the arguments, unique on a page.

Parameters:

Name Type Description Default
key str

the organ.

required
cx float

the centre of the card, x.

required
cy float

the centre of the card, y.

required
width float

the width of the card.

required
height float

the height of the card.

required
loss float

the lost fraction of the organ, 0 to 1.

required
color str

the color of the class, the frame of the card.

required
title str | None

the hover text, plain text (escaped here).

None
sex str

the sex of the drawing.

'male'

Returns:

Type Description
str

The SVG fragment, a group.

Raises:

Type Description
ValueError

if the organ has no pictogram or loss is outside [0, 1].

tablet

tablet(cx, cy, d=24.0)

The oral dose: a tablet on a circle.

syringe

syringe(cx, cy, d=24.0, rot=35.0)

The intravenous dose: a syringe on a circle.

drop

drop(cx, cy, d=24.0)

The blood sample: a drop on a circle.

The 2D anatomy resources: the drawings of the bodies and organs of the figures.

One JSON file per species and sex in pkpdsim/resources/anatomy/, built by scripts/visual/anatomy_assets.py from the anatomograms of the EBI Expression Atlas (CC BY 4.0, see the NOTICE.md of the folder): the outline of the body and its details, the organs of the library by their Organ key with their UBERON ids, further anatomy, the landmarks of the human drawings and the body cavities, all in the coordinates of the drawing (units of its view box, y downwards).

RESOURCES module-attribute

RESOURCES = (
    Path(__file__).resolve().parents[2]
    / "resources"
    / "anatomy"
)

The folder of the anatomy resources.

Shape dataclass

Shape(key, name, uberon, cavity, d, paths)

A drawn tissue: an organ of the library or further anatomy.

Attributes:

Name Type Description
key str

the key, an Organ value or the name of the anatomy (bladder).

name str

the name of the tissue.

uberon tuple[str, ...]

the UBERON terms of the drawing which form it.

cavity str | None

the body cavity it lies in (thorax, abdomen), head, limb or None.

d str

the path data.

paths tuple[ndarray, ...]

the polylines of the path.

Anatomy dataclass

Anatomy(
    key,
    species,
    sex,
    viewbox,
    midline,
    landmarks,
    outline,
    details,
    organs,
    anatomy,
    cavities,
    attribution,
)

The drawing of a species and sex.

Attributes:

Name Type Description
key str

the resource (human_male).

species str

the species (human, mouse, rat).

sex str

the sex (male, female).

viewbox tuple[float, float, float, float]

the box of the outline, x, y, width, height.

midline float

the x of the midline of the body.

landmarks Mapping[str, float]

the heights of the human drawings (top, neck, shoulder, armpit, waist, crotch, bottom), empty for the animals.

outline ndarray

the outline of the body, one closed polyline.

details tuple[ndarray, ...]

the small shapes of the outline (eyes, nose, mouth, hands).

organs Mapping[str, Shape]

the organs of the library by their Organ value.

anatomy Mapping[str, Shape]

further anatomy by name.

cavities Mapping[str, tuple[ndarray, ...]]

the polylines of the cavities thorax and abdomen.

attribution str

the source, license and changes.

shape

shape(key)

The organ or the anatomy of a key, None if the drawing lacks it.

parse_d

parse_d(d)

The polylines of a path of the resources (M x,y x,y ... Z, absolute).

Parameters:

Name Type Description Default
d str

the path data, subpaths of absolute points.

required

Returns:

Type Description
tuple[ndarray, ...]

One array of shape (n, 2) per subpath.

anatomy cached

anatomy(species='human', sex='male')

The anatomy resource of a species and sex.

Parameters:

Name Type Description Default
species str

human, mouse or rat (male only).

'human'
sex str

male or female.

'male'

Returns:

Type Description
Anatomy

The drawing, read once per process.

Raises:

Type Description
ValueError

for a species and sex without a resource.

The deformation of a human drawing into the body of an individual.

The outline of the drawing is rasterized and segmented into head, trunk, arms and legs (Drawing). The body of an individual is the drawing mapped by a smooth field (Field): a monotone vertical map through the landmarks gives the proportions of the age (the head, the trunk, the legs), and every part is stretched horizontally about its own axis by a sum of broad Gaussians over the height, blended between the parts by blurred masks, so the outline changes continuously and mainly by stretching in x and y. The field maps points of the drawing (Field.__call__) and is inverted by a fixed point iteration (Field.inverse), which the raster of the body needs.

RES module-attribute

RES = 0.25

The raster of the drawing: units of the drawing per pixel.

Gaussian module-attribute

Gaussian = tuple[float, float, float]

A bump of a profile over the height: centre, sigma (units of the drawing) and amplitude.

Drawing dataclass

Drawing(
    anatomy,
    mask,
    ys,
    xs,
    cx,
    labels,
    arm_axis,
    leg_axis,
    half,
    weights,
)

The parts of a human drawing on its raster.

Attributes:

Name Type Description
anatomy Anatomy

the resource.

mask ndarray

the inside of the outline.

ys ndarray

the y of every row.

xs ndarray

the x of every column.

cx float

the midline.

labels ndarray

per pixel 1 head, 2 trunk, 3 arm, 4 leg, 0 outside.

arm_axis dict[int, ndarray]

the x of the axis of the arm per row, by side (-1, 1).

leg_axis dict[int, ndarray]

the x of the axis of the leg per row, by side.

half ndarray

the half width of the trunk per row.

weights dict[str, ndarray]

the blurred masks of the parts, summing to 1.

landmarks property

landmarks

The landmarks of the drawing.

Field

Field(
    d,
    height,
    head_frac,
    leg_frac,
    trunk=(),
    arm=(),
    leg=(),
    head_w=1.0,
    belly=None,
)

The map of a drawing onto the body of an individual (units of the drawing to cm).

Parameters:

Name Type Description Default
d Drawing

the drawing.

required
height float

the height of the individual [cm].

required
head_frac float

the head (top to neck) as a fraction of the height.

required
leg_frac float

the legs (crotch to floor) as a fraction of the height.

required
trunk Sequence[Gaussian]

the relative widening of the trunk over the height.

()
arm Sequence[Gaussian]

the relative widening of the arms about their axes.

()
leg Sequence[Gaussian]

the relative widening of the legs about their axes.

()
head_w float

the width of the head relative to its height.

1.0
belly Gaussian | None

a pregnant belly, a Gaussian of the trunk (centre, sigma, amplitude).

None

Build the field of an individual.

height property

height

The height of the body [cm].

inverse

inverse(x, y, iterations=8)

The points of the drawing which the field maps onto (x, y) [cm].

raster

raster(polygons, shape, origin=(0.0, 0.0), res=RES)

The pixels inside polygons.

Parameters:

Name Type Description Default
polygons Sequence[ndarray]

closed polylines, arrays of shape (n, 2).

required
shape tuple[int, int]

the shape of the raster (rows, columns).

required
origin tuple[float, float]

the point of the pixel (0, 0).

(0.0, 0.0)
res float

the units per pixel.

RES

Returns:

Type Description
ndarray

A boolean array of the shape.

drawing cached

drawing(sex)

The segmented human drawing of a sex (cached).

Parameters:

Name Type Description Default
sex str

male or female.

required

Returns:

Type Description
Drawing

The drawing with its parts.