CompartmentalSystemBuilder#

class pharmpy.model.CompartmentalSystemBuilder(cs=None)[source]#

Bases: object

Builder for CompartmentalSystem

Methods Summary

add_compartment(compartment)

Add compartment to system

add_flow(source, destination, rate)

Add flow between two compartments

find_compartment(name)

move_dose(source, destination[, admid, replace])

Move a dose input from one compartment to another

remove_compartment(compartment)

Remove compartment from system

remove_flow(source, destination)

Remove flow between two compartments

set_bioavailability(compartment, bioavailability)

Set bioavailability of compartment

set_dose(compartment, dose[, replace, admid])

Set dose of compartment, replacing the previous by default.

set_input(compartment, input)

Set zero order input of compartment

set_lag_time(compartment, lag_time)

Set lag time of compartment

Methods Documentation

add_compartment(compartment)[source]#

Add compartment to system

The compartment will be added without any flows to other compartments. Use the add_flow method to add flows to and from the newly added compartment.

Parameters:

compartment (Compartment) – Compartment to add

Examples

>>> from pharmpy.model import CompartmentalSystemBuilder
>>> cb = CompartmentalSystemBuilder()
>>> central = cb.add_compartment("CENTRAL")
add_flow(source, destination, rate)[source]#

Add flow between two compartments

Parameters:
  • source (Compartment) – Source compartment

  • destination (Compartment) – Destination compartment

  • rate (Expression) – Symbolic rate of flow

Examples

>>> from pharmpy.model import Compartment, CompartmentalSystemBuilder
>>> cb = CompartmentalSystemBuilder()
>>> depot = Compartment.create("DEPOT")
>>> cb.add_compartment(depot)
>>> central = Compartment.create("CENTRAL")
>>> cb.add_compartment(central)
>>> cb.add_flow(depot, central, "KA")
find_compartment(name)[source]#
move_dose(source, destination, admid=None, replace=True)[source]#

Move a dose input from one compartment to another

Parameters:
  • source (Compartment) – Source compartment

  • destination (Compartment) – Destination compartment

  • admid (int) – Move dose with specified admid, move all if None. Default is None.

  • replace (bool) – Replace dose of destination or add to. Default to True

remove_compartment(compartment)[source]#

Remove compartment from system

Parameters:

compartment (Compartment) – Compartment object to remove from system

Examples

>>> from pharmpy.model import CompartmentalSystemBuilder
>>> cb = CompartmentalSystemBuilder()
>>> central = Compartment.create("CENTRAL")
>>> cb.add_compartment(central)
>>> cb.remove_compartment(central)
remove_flow(source, destination)[source]#

Remove flow between two compartments

Parameters:
  • source (Compartment) – Source compartment

  • destination (Compartment) – Destination compartment

Examples

>>> from pharmpy.model import CompartmentalSystemBuilder
>>> cb = CompartmentalSystemBuilder()
>>> depot = Compartment.create("DEPOT")
>>> cb.add_compartment(depot)
>>> central = Compartment.create("CENTRAL")
>>> cb.add_compartment(central)
>>> cb.add_flow(depot, central, "KA")
>>> cb.remove_flow(depot, central)
set_bioavailability(compartment, bioavailability)[source]#

Set bioavailability of compartment

Parameters:
  • compartment (Compartment) – Compartment for which to change bioavailability

  • bioavailability (expr) – New bioavailability

Returns:

Compartment – The new updated compartment

set_dose(compartment, dose, replace=True, admid=None)[source]#

Set dose of compartment, replacing the previous by default.

Set replace to False to instead add the dose to existing ones.

Given an admid, the given dose will replace the corresponding dose based on that admid. This will ignore the ‘replace’ argument.

Parameters:
  • compartment (Compartment) – Compartment for which to change dose

  • dose (Dose) – New dose

  • replace (bool) – Replace existing doses or not. Default is True

  • admid (Optional[int]) – Option to replace doses with specified admid.

Returns:

Compartment – The new updated compartment

set_input(compartment, input)[source]#

Set zero order input of compartment

Parameters:
  • compartment (Compartment) – Compartment for which to change zero order input

  • input (expr) – New input

Returns:

Compartment – The new updated compartment

set_lag_time(compartment, lag_time)[source]#

Set lag time of compartment

Parameters:
  • compartment (Compartment) – Compartment for which to change lag time

  • lag_time (expr) – New lag time

Returns:

Compartment – The new updated compartment