BioNetGen integration (pysb.bng
)¶
-
class
pysb.bng.
BngBaseInterface
(model=None, verbose=False, cleanup=False, output_prefix=None, output_dir=None, model_additional_species=None, model_population_maps=None)[source]¶ Abstract base class for interfacing with BNG
-
action
(action, **kwargs)[source]¶ Generates code to execute a BNG action command
Parameters: action: string
The name of the BNG action function
kwargs: kwargs, optional
Arguments and values to supply to BNG
-
base_filename
¶ Returns the base filename (without extension) for BNG output files
-
bng_filename
¶ Returns the BNG command list (.bngl) filename (does not check whether the file exists)
-
net_filename
¶ Returns the BNG network filename (does not check whether the file exists)
-
read_netfile
()[source]¶ Reads a BNG network file as a string. Note that you must execute network generation separately before attempting this, or the file will not be found. :return: Contents of the BNG network file as a string
-
read_simulation_results
()[source]¶ Read the results of a BNG simulation as a numpy array
Returns: numpy.ndarray
Simulation results in a 2D matrix (time on Y axis, species/observables/expressions on X axis depending on simulation type)
-
static
read_simulation_results_multi
(base_filenames)[source]¶ Read the results of multiple BNG simulations
Parameters: base_filenames: list of str
A list of filename stems to read simulation results in from, including the full path but not including any file extension.
Returns: list of numpy.ndarray
List of simulation results, each in a 2D matrix (time on Y axis, species/observables/expressions on X axis depending on simulation type)
-
-
class
pysb.bng.
BngConsole
(model=None, verbose=False, cleanup=True, output_dir=None, output_prefix=None, timeout=30, suppress_warnings=False, model_additional_species=None)[source]¶ Interact with BioNetGen through BNG Console
-
action
(action, **kwargs)[source]¶ Generates a BNG action command and executes it through the console, returning any console output
Parameters: action : string
The name of the BNG action function
kwargs : kwargs, optional
Arguments and values to supply to BNG
-
-
pysb.bng.
generate_equations
(model, cleanup=True, verbose=False, **kwargs)[source]¶ Generate math expressions for reaction rates and species in a model.
This fills in the following pieces of the model:
- species
- reactions
- reactions_bidirectional
- observables (just coefficients and species fields for each element)
Parameters: model : Model
Model to pass to generate_network.
cleanup : bool, optional
If True (default), delete the temporary files after the simulation is finished. If False, leave them in place (in output_dir). Useful for debugging.
verbose : bool or int, optional (default: False)
Sets the verbosity level of the logger. See the logging levels and constants from Python’s logging module for interpretation of integer values. False is equal to the PySB default level (currently WARNING), True is equal to DEBUG.
-
pysb.bng.
generate_network
(model, cleanup=True, append_stdout=False, verbose=False, **kwargs)[source]¶ Return the output from BNG’s generate_network function given a model.
The output is a BNGL model definition with additional sections ‘reactions’ and ‘groups’, and the ‘species’ section expanded to contain all possible species. BNG refers to this as a ‘net’ file.
Parameters: model : Model
Model to pass to generate_network.
cleanup : bool, optional
If True (default), delete the temporary files after the simulation is finished. If False, leave them in place (in output_dir). Useful for debugging.
append_stdout : bool, optional
This option is no longer supported and has been left here for API compatibility reasons.
verbose : bool or int, optional (default: False)
Sets the verbosity level of the logger. See the logging levels and constants from Python’s logging module for interpretation of integer values. False is equal to the PySB default level (currently WARNING), True is equal to DEBUG.
-
pysb.bng.
load_equations
(model, netfile)[source]¶ Load model equations from a specified netfile
Useful for large models where BioNetGen network generation takes a long time - the .net file can be saved and reloaded using this function at a later date.
Parameters: model: pysb.Model
PySB model file
netfile: str
BNG netfile
-
pysb.bng.
run_ssa
(model, t_end=10, n_steps=100, param_values=None, output_dir=None, output_file_basename=None, cleanup=True, verbose=False, **additional_args)[source]¶ Simulate a model with BNG’s SSA simulator and return the trajectories.
Parameters: model : Model
Model to simulate.
t_end : number, optional
Final time point of the simulation.
n_steps : int, optional
Number of steps in the simulation.
param_values : vector-like or dictionary, optional
Values to use for every parameter in the model. Ordering is determined by the order of model.parameters. If not specified, parameter values will be taken directly from model.parameters.
output_dir : string, optional
Location for temporary files generated by BNG. If None (the default), uses a temporary directory provided by the system. A temporary directory with a random name is created within the supplied location.
output_file_basename : string, optional
This argument is used as a prefix for the temporary BNG output directory, rather than the individual files.
cleanup : bool, optional
If True (default), delete the temporary files after the simulation is finished. If False, leave them in place. Useful for debugging.
verbose : bool or int, optional (default: False)
Sets the verbosity level of the logger. See the logging levels and constants from Python’s logging module for interpretation of integer values. False is equal to the PySB default level (currently WARNING), True is equal to DEBUG.
additional_args: kwargs, optional
Additional arguments to pass to BioNetGen