Documentation
pkmodel is a Pharmokinetic modelling library.
It contains functionality for creating, solving, and visualising the solution of Parmokinetic (PK) models
Classes
AbstractModel.py: Abstract class for 1st Order Linear ODE for pharmokinetic model
- class pkmodel.AbstractModel.AbstractModel
- abstract solve() pkmodel.AbstractSolution.AbstractSolution
Abstract class for 1st Order Linear ODE for pharmokinetic model
- Raises
NotImplementedError – Must be implemented by subclasses.
AbstractProtocol.py: Abstract class for 1st Order Linear ODE for pharmokinetic model
- class pkmodel.AbstractProtocol.AbstractProtocol
- 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.
AbstractSolution.py: Abstract class for solution of 1st Order Linear ODE for pharmokinetic model
- class pkmodel.AbstractSolution.AbstractSolution
- abstract property get_solution
Returns linear approximate solution of Model, computed with scipy ivp
- Raises
NotImplementedError – Must be implemented by subclass
Dose functions defining the dosing regimens of pharmokinetic model.
- members
- inherited-members
- class pkmodel.protocol.Protocol(file_dir=None)
Protocol 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
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)
Class for the intravenous bolus model with a single central compartment and variable number of peripheral compartments
- 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
- 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
- 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.Model(parameters)
Base 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)
Class for the subcutaneous injection model with a single central compartment, a single absorption compartment, and variable number of peripheral compartments
- 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
- 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
- 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
” Solution.py: Class implementation for Solution of 1st Order ODE for pharmokinetic model
- class pkmodel.solution.Solution(solution_vector, parameter_dict)
- 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