BioNetGen integration (pysb.bng)

class pysb.bng.BngBaseInterface(model=None, verbose=False, cleanup=False, output_prefix=None, output_dir=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]

Reads the results of a BNG simulation and parses them into a numpy array

class pysb.bng.BngConsole(model=None, verbose=False, cleanup=True, output_dir=None, output_prefix=None, timeout=30, suppress_warnings=False)[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

generate_network(overwrite=False)[source]

Generates a network in BNG and returns the network file contents as a string

Parameters:

overwrite: bool, optional

Overwrite existing network file, if any

load_bngl(bngl_file)[source]

Loads a BNGL file in the BNG console

Parameters:

bngl_file : string

The filename of a .bngl file

exception pysb.bng.BngInterfaceError[source]

BNG reported an error

exception pysb.bng.NoInitialConditionsError[source]

Model initial_conditions is empty.

exception pysb.bng.NoRulesError[source]

Model rules is empty.

pysb.bng.generate_equations(model, cleanup=True, verbose=False)[source]

Generate math expressions for reaction rates and species in a model.

This fills in the following pieces of the model:

  • odes
  • species
  • reactions
  • reactions_bidirectional
  • observables (just coefficients and species fields for each element)
pysb.bng.generate_network(model, cleanup=True, append_stdout=False, verbose=False)[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, optional

If True, print output from BNG to stdout.

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, optional

If True, print BNG screen output.

additional_args: kwargs, optional

Additional arguments to pass to BioNetGen