pkmodel package
Subpackages
Submodules
pkmodel.AbstractModel module
AbstractModel.py: Abstract class for 1st Order Linear ODE for pharmokinetic model
- class pkmodel.AbstractModel.AbstractModel
Bases:
abc.ABC- abstract solve() pkmodel.AbstractSolution.AbstractSolution
Abstract class for 1st Order Linear ODE for pharmokinetic model
- Raises
NotImplementedError – Must be implemented by subclasses.
pkmodel.AbstractProtocol module
AbstractProtocol.py: Abstract class for 1st Order Linear ODE for pharmokinetic model
- class pkmodel.AbstractProtocol.AbstractProtocol
Bases:
abc.ABC- abstract generate_model() pkmodel.AbstractModel.AbstractModel
Generates 1st Order linear ODE pharmokinetic model from input arguments that define model protocol.
- Raises
NotImplementedError – Must be implemented by subclasses.
pkmodel.AbstractSolution module
AbstractSolution.py: Abstract class for solution of 1st Order Linear ODE for pharmokinetic model
pkmodel.dose module
Dose functions defining the dosing regimens of pharmokinetic model.
- pkmodel.dose.pulse_series_dose(t, X1, X2=0.0, pulse_width=0.1, interval=0.1)
- Pulse function for dose administration, with X1 and X2 amounts
alternately administered.
- Parameters
t (float) – current time point
X1 (float) – amount of dose administered in high pulse
X2 (float, optional) – amount of dose administered in low pulse, defaults to 0.
pulse_width (float, optional) – time duration of high pulse, defaults to 0.1
interval (float, optional) – time duration of low pulse, ie interval between high pulses; defaults to 0.1
- Returns
dose administered at time t
- Return type
float
- pkmodel.dose.select_dose(key)
Function to select dose function specified by key in config or protocol.
- Parameters
key (String) – [‘normal’, ‘pulse’, ‘zero’] selection ID for function from parameters
- Raises
Exception – Dose key incorrect, does not point to a dose function
- Returns
dose function
- Return type
function
- pkmodel.dose.unit_fn_dose(t, X)
- Unit step function (Heaviside) for dosing regimen, with amount X of
dose administered at every time step.
- Parameters
t (float) – current time point
X (float) – amount of dose administered
- Returns
dose X administered at time t
- Return type
float
- pkmodel.dose.zero_dose(t, X)
Dose function returns zero dose at all times.
- Parameters
t (float) – current time point
X (float) – amount of dose administered
- Returns
zero
- Return type
float
pkmodel.models module
models.py contains Model baseclass and Intravenous and Subcutaneous model subclasses.
- return
solution to PK ODE Model
- rtype
Solution object
- class pkmodel.models.IntravenousModels(parameters)
Bases:
pkmodel.models.ModelClass for the intravenous bolus model with a single central compartment and variable number of peripheral compartments
- rhs(t, y)
Right Hand Side (rhs) of the ODE model. Contains the implementation of the differential equations defining the PK model.
dq_c / dt = Dose(t) - (q_c / V_c) * CL - Q_px( q_c / V_c - q_px / V_px)dq_px / dt = Q_px(q_c / V_c - q_px / V_px)Called as lambda function within scipy solve_ivp.- Parameters
t (float) – current time point
y (array of float) – [q_c, q_p1, …, q_pn] - current amount in compartment at time point t with dimensions N where N is total number of compartments
- Returns
dq_dt - an array of all compartments’ dq_dt values at time t with dimensions N where N is total number of compartments
- Return type
array of float
- class pkmodel.models.Model(parameters)
Bases:
pkmodel.AbstractModel.AbstractModelBase model for PK 1st order linear ODE model with variable number of peripheral compartments.
- Parameters
parameters (dict) – parameters and constants of the model
- generate_transition(parameter_tuple, q_central, q_peripheral)
Helper function computes single transition equation describing flux between central compartment and single peripheral compartment.
- Parameters
parameter_tuple (tuple of non-negative floats) – (V_peripheral, Q_peripheral) - tuple containing volume and rate constants that define a peripheral compartment
q_central (float) – time variable amount q in central compartment solved numerically at time t
q_peripheral (float) – time variable amount q in peripheral compartment solved numerically at time t
- Returns
computed transition value describing flux between central and peripheral compartment at time t
- Return type
float
- solve()
Function computes the numeric solution of the PK ODE model with scipy solve_ivp for a specified time interval.
- Returns
numeric solution of amount for each compartment as float array with dimensions N x T, where N is the total number of compartments and T is the length of the time eval vector.
- Return type
- class pkmodel.models.SubcutaneousModels(parameters)
Bases:
pkmodel.models.ModelClass for the subcutaneous injection model with a single central compartment, a single absorption compartment, and variable number of peripheral compartments
- rhs(t, y)
Right Hand Side (rhs) of the ODE model. Contains the implementation of the differential equations defining the PK model.
dq0 / dt = Dose(t) - k_a * q_0dq_c / dt = k_a * q_0 - (q_c / V_c) CL - Q_px( q_c / V_c - q_px / V_px )dq_px / dt = Q_px (q_c / V_c - q_px / V_px)Called as lambda function within scipy solve_ivp.- Parameters
t (float) – current time point
y (array of float) – [q_0, q_c, q_p1, …, q_pn] - current amount in compartment at time point t with dimensions N where N is total number of compartments
- Returns
dq_dt - an array of all compartments’ dq_dt values at time t with dimensions N where N is total number of compartments
- Return type
array of float
pkmodel.protocol module
- class pkmodel.protocol.Protocol(file_dir=None)
Bases:
pkmodel.AbstractProtocol.AbstractProtocolProtocol object which initialises the Model based on the input parameters and default parameters
- Args:
AbstractProtocol (Class): AbstractProtocol is super-class of Protocol.
- call_all_checks()
Calls all the check functions at once
- check_fill_parametersCLX()
Checks that parameters CL and X are floats and larger than 0
- Raises:
TypeError: If CL or X is not a float ValueError: If CL or X is less than 0
- check_fill_parametersdict()
Checks the parameters are a dictionary
- Raises:
TypeError: If parameters are not a dictionary
- check_fill_parametersint()
Checks that nr_compartments and time paramters are integers
- Raises:
TypeError: If nr_compartments or time are not an integer ValueError: If nr_compartments or time are less than 0 ValueError: If time is larger than 5
- check_fill_parametersperip()
Checks that periph_* parameters are a tuple with two floats both larger than 0.
- Raises:
TypeError: If periph_* parameter is not a tuple TypeError: If a value in the tuple is not a float ValueError: If a value in the tuple is less than 0
- check_fill_parametersstr()
Checks the name and injection_type parameters are strings
- Raises:
TypeError: If the name and injection_type parameters are not strings
- fill_parameters(file_dir)
Fills the parameters using the config file and updates the default values based on these values
- Args:
file_dir (string): Relative path for the config file
- generate_model()
Generates a model object based on the parameters in the Protocol object
- Raises:
Exception: If an incorrect mode is given (not intravenous nor subcutaneous)
- Returns:
Model Obnject: An initiated model using the defined parameters
- read_config(file_dir)
Reads in config file and converts into python dictionary
- Args:
file_dir (string): Relative path for the config file
- Returns:
dict: Dictionary of the parameters
pkmodel.solution module
” Solution.py: Class implementation for Solution of 1st Order ODE for pharmokinetic model
- class pkmodel.solution.Solution(solution_vector, parameter_dict)
Bases:
pkmodel.AbstractSolution.AbstractSolution- Parameters
AbstractSolution ([type]) – [description]
- generate_plot()
Generate solution vector plots
- Returns
plots of quantity vs time for each compartment
- Type
matplotlib plot
- property get_parameters
Return parameter dictionary
:return dictionary of paremters :type: dict
- property get_solution
Return list of y and t arrays from solution vector
- Returns
list of y, t –> where y = np.array of quantities and
<– t = np.array of time :rtype: list of numpy arrays
- output()
creates and populates output directory <– with saved plot, parameters, and solution
- Returns
None
- save_parameters(dir_path, model_no)
saves input parameters in text file
- Returns
None
- save_plot(dir_path, model_no)
saves plot of solutions as png
- Returns
None
- save_solution(dir_path, model_no)
saves solutions in a csv file
- Returns
None
- show_plot()
displays plot for testing
- Returns
None
pkmodel.version_info module
Module contents
pkmodel is a Pharmokinetic modelling library.
It contains functionality for creating, solving, and visualising the solution of Parmokinetic (PK) models