bionetgen.modelapi package

Submodules

bionetgen.modelapi.blocks module

class bionetgen.modelapi.blocks.ActionBlock[source]

Bases: bionetgen.modelapi.blocks.ModelBlock

Action block object, subclass of ModelBlock.This is the one object that doesn’t need a begin/end block tag to be in the model.

_action_listlist[str]

list of supported action names

add_action(name, action_type=None, action_args=[])

adds an action by making a new Action object and passing the args/kwargs to its initialization.

clear_actions()

add_action(action_type, action_args)None[source]

adds action, needs type as string and args as list of tuples (which preserve order) of (argument, value) pairs

clear_actions()None[source]
gen_string()str[source]
class bionetgen.modelapi.blocks.CompartmentBlock[source]

Bases: bionetgen.modelapi.blocks.ModelBlock

Compartment block object, subclass of ModelBlock.

add_compartment(name, dim, size, outside=None)

adds a compartment by making a new Compartment object and passing the args/kwargs to its initialization.

add_compartment(*args, **kwargs)None[source]
class bionetgen.modelapi.blocks.FunctionBlock[source]

Bases: bionetgen.modelapi.blocks.ModelBlock

Function block object, subclass of ModelBlock.

add_function(name, name, expr, args=None)

adds a function by making a new Function object and passing the args/kwargs to its initialization.

add_function(*args, **kwargs)None[source]
class bionetgen.modelapi.blocks.ModelBlock[source]

Bases: object

Base block object that will be used for each block in the model.

namestr

Name of the block which will be used to write the BNGL text

comment(str, str)

comment at the begin {block} or end {block} statements, tuple

itemsOrderedDict

all the model objects in the block

_changesOrderedDict

a dictionary to keep track of all the changes done in a block after it is originally created

_recompilebool

a tag that tells a potential future simulator if the model needs to be recompiled. TODO: has to be computed from _changes property upon get request.

reset_compilation_tags()

resets _recompile and _changes tags for the block

add_item((name,value))

sets self.item[name] = value to add a particular model object into a block

add_items(item_list)

loops over every element in the list and uses add_item on it

gen_string()

for every block this method generates the BNGL string of the block. it has to be overwritten for each block.

add_item(item_tpl)None[source]
add_items(item_list)None[source]
gen_string()str[source]
reset_compilation_tags()None[source]
class bionetgen.modelapi.blocks.MoleculeTypeBlock[source]

Bases: bionetgen.modelapi.blocks.ModelBlock

Molecule type block, subclass of ModelBlock.

add_molecule_type(name, name, components)

adds a molecule type by making a new MoleculeType object and passing the args/kwargs to its initialization.

add_molecule_type(name, components)None[source]
class bionetgen.modelapi.blocks.ObservableBlock[source]

Bases: bionetgen.modelapi.blocks.ModelBlock

Observable block object, subclass of ModelBlock.

add_observable(name, otype, patterns=[])

adds an observable by making a new Observable object and passing the args/kwargs to its initialization.

add_observable(*args, **kwargs)None[source]
class bionetgen.modelapi.blocks.ParameterBlock[source]

Bases: bionetgen.modelapi.blocks.ModelBlock

Parameter block object, subclass of ModelBlock.

add_parameter(name, value, expr=None)

adds a parameter by making a new Parameter object and passing the args/kwargs to its initialization.

add_parameter(*args, **kwargs)None[source]
class bionetgen.modelapi.blocks.RuleBlock[source]

Bases: bionetgen.modelapi.blocks.ModelBlock

Rule block object, subclass of ModelBlock.

add_rule(name, name, reactants=[], products=[], rate_constants=())

adds a rule by making a new Rule object and passing the args/kwargs to its initialization.

consolidate_rulesNone

XML loading makes it so that reversible rules are split into two unidirectional rules. This find them and combines them into a single rule to correctly represent the original model rule.

add_rule(*args, **kwargs)None[source]
consolidate_rules()None[source]

Generated XML only has unidirectional rules and uses “_reverse_” tag to make bidirectional rules for NFSim. Take all the “_reverse_” tagged rules and convert them to bidirectional rules

class bionetgen.modelapi.blocks.SpeciesBlock[source]

Bases: bionetgen.modelapi.blocks.ModelBlock

Species block object, subclass of ModelBlock.

add_species(name, pattern=Pattern(), count=0)

adds a species by making a new Species object and passing the args/kwargs to its initialization.

add_species(*args, **kwargs)None[source]

bionetgen.modelapi.bngfile module

class bionetgen.modelapi.bngfile.BNGFile(path, BNGPATH='/home/docs/checkouts/readthedocs.org/user_builds/pybionetgen/checkouts/latest/bionetgen/bng-linux')[source]

Bases: object

File object designed to deal with .bngl file manipulations.

Usage: BNGFile(bngl_path)

BNGFile(bngl_path, BNGPATH)

pathstr

path to the file the object needs to deal with

_action_listlist[str]

list of acceptible actions

BNGPATHstr

optional path to bng folder that contains BNG2.pl

bngexecstr

path to BNG2.pl

generate_xml(xml_file, model_file=None)bool

takes the given BNGL file and generates a BNG-XML from it

strip_actions(model_path, folder)str

deletes actions from a given BNGL file

write_xml(open_file, xml_type=”bngxml”, bngl_str=None)bool

given a bngl file or a string, writes an SBML or BNG-XML from it

generate_xml(xml_file, model_file=None)bool[source]
strip_actions(model_path, folder)str[source]

Strips actions from a BNGL file and makes a copy into the given folder

write_xml(open_file, xml_type='bngxml', bngl_str=None)bool[source]

write new BNG-XML or SBML of file by calling BNG2.pl again or can take BNGL string in as well.

bionetgen.modelapi.bngparser module

class bionetgen.modelapi.bngparser.BNGParser(path, BNGPATH='/home/docs/checkouts/readthedocs.org/user_builds/pybionetgen/checkouts/latest/bionetgen/bng-linux')[source]

Bases: object

Parser object that deals with reading in the BNGL file and setting up the model object

Usage: BNGParser(bngl_path)

BNGParser(bngl_path, BNGPATH)

bngfileBNGFile

BNGFile object that’s responsible for .bngl file manipulations

parse_model(model_file)

parses the BNGL model at the given path and adds everything to a given model object

parse_xml(xml_str)

parses given xml string and adds everything to a given model object

parse_model(model_obj)None[source]

Will determine the parser route eventually and call the right parser

parse_xml(xml_str, model_obj)None[source]

bionetgen.modelapi.model module

class bionetgen.modelapi.model.bngmodel(bngl_model, BNGPATH='/home/docs/checkouts/readthedocs.org/user_builds/pybionetgen/checkouts/latest/bionetgen/bng-linux')[source]

Bases: object

Main model object and entry point for model API. The goal of this object is to generate and read the BNGXML of a given BNGL model and give the user a pythonic interface to the resulting model object.

Usage: bngmodel(bng_model)

bngmodel(bng_model, BNGPATH)

active_blockslist[str]

a list of the blocks that have been parsed in the model

bngparserBNGParser

BNGParser object that’s responsible for .bngl file reading and model setup

model_namestr

name of the model, generally set from the given BNGL file

recompilebool

a tag to keep track if any changes have been made to the model via the XML API by the user

changesdict

a list of changes the user have made to the model

reset_compilation_tags()

resets compilation tags of each block to keep track of any changes the user makes to the model via the API

add_action(action_type, action_args)

adds the action of action_type with arguments given by the optional keyword argument action_args which is a list of lists where each element is of the form [ArgumentName, ArgumentValue]

write_model(model_name)

write the model in BNGL format to the path given

setup_simulator(sim_type)

sets up a simulator in bngmodel.simulator where the only current supported type of simulator is libRR for libRoadRunner simulator.

add_action(action_type, action_args=[])[source]
add_actions_block(block=None)[source]
add_block(block)[source]
add_compartments_block(block=None)[source]
add_functions_block(block=None)[source]
add_molecule_types_block(block=None)[source]
add_observables_block(block=None)[source]
add_parameters_block(block=None)[source]
add_rules_block(block=None)[source]
add_species_block(block=None)[source]
property changes
property recompile
reset_compilation_tags()[source]
setup_simulator(sim_type='libRR')[source]

Sets up a simulator attribute that is a generic front-end to all other simulators. At the moment only libroadrunner is supported

write_model(file_name)[source]

write the model to file

bionetgen.modelapi.pattern module

class bionetgen.modelapi.pattern.Component[source]

Bases: object

Component object that describes the state, label and bonding for each component. Molecules can optionally contain components

namestr

name of the component

_labelstr

label of the component

_statestr

state of the component, not used for molecule types

_stateslist[str]

list of states for molecule types

_bondslist[Bond]

list of bond objects that describes bonding of the component

add_state()

not implemented. will eventually be used to add additional states to an existing component

add_bond()

not implemented. will eventually be used to add additional bonds to an existing component

add_bond()[source]
add_state()[source]
property bonds
property label
property name
property state
property states
class bionetgen.modelapi.pattern.Molecule(name='0', components=[], compartment=None, label=None)[source]

Bases: object

Molecule object. A pattern is a list of molecules. This object also handles molecule types where components have a list of possible states.

_namestr

name of the molecule

_compartmentstr

compartment of the molecule

_labelstr

label of the molecule

_componentslist[Component]

list of components for this molecule

add_component(name, state=None, states=[])

add a component object to the list of components with name “name”, current state “state” or a list of states (for molecule types) “states”

add_component(name, state=None, states=[])[source]
property compartment
property components
property label
property name
class bionetgen.modelapi.pattern.Pattern(molecules=[], bonds=None, compartment=None, label=None)[source]

Bases: object

Pattern object. Fundamentally it’s just a list of molecules which are defined later.

_bondsBonds

setting a pattern requires you to keep track of all bonds to correctly label them, this object tracks everything

_compartmentstr

compartment of the overall pattern (not the same thing as molecule compartment, those have their own)

_labelstr

label of the overall pattern (not the same thing as molecule label, those have their own)

moleculeslist[Molecule]

list of molecule objects that are in the pattern

fixedbool

used for constant species, sets “$” at the beginning of the pattern string

MatchOncebool

used for matchOnce syntax, “{MatchOnce}PatternStr”

property compartment
property label

bionetgen.modelapi.runner module

bionetgen.modelapi.runner.run(inp, out=None)[source]

Convenience function to run BNG2.pl as a library

Usage: run(path_to_input_file, output_folder)

path_to_input_filestr

this has to point to a BNGL file

output_folderstr

(optional) this points to a folder to put the results into. If it doesn’t exist, it will be created.

bionetgen.modelapi.structs module

class bionetgen.modelapi.structs.Action(action_type=None, action_args=[])[source]

Bases: bionetgen.modelapi.structs.ModelObj

Class for all parameters in the model, subclass of ModelObj.

In BNGL actions are of the form

action_type({arg1=>value1, arg2=>value2, …})

typestr

type of action, e.g. simulate or writeFile

argslist[(arg_name,arg_value)]

(argument,value) pair list for the action

gen_string()str[source]
print_line()str[source]
class bionetgen.modelapi.structs.Compartment(name, dim, size, outside=None)[source]

Bases: bionetgen.modelapi.structs.ModelObj

Class for all compartments in the model, subclass of ModelObj.

In BNGL the compartments are of the form

compartment_name dimensions size

or

compartment_name dimensions size parent_compartment

the second form only applies when one compartment is contained in another compartment.

namestr

name of the compartment

dimstr

dimensionality of the compartment

sizestr

size/volume of the compartment

outsidestr

parent compartment, if exists

write_exprbool

boolean that describes if the size is a volume or an expression

gen_string()str[source]
class bionetgen.modelapi.structs.Function(name, expr, args=None)[source]

Bases: bionetgen.modelapi.structs.ModelObj

Class for all parameters in the model, subclass of ModelObj.

In BNGL functions are of the form

function_name function_expression

or

function_name = function_expression

and functions can have arguments

function_name(arg1, arg2, …, argN)

namestr

name of the function

exprstr

function expression

argslist

optional list of arguments for the function

gen_string()str[source]
class bionetgen.modelapi.structs.ModelObj[source]

Bases: object

The base class for all items in a model (parameter, observable etc.).

commentstr

comment at the end of the line/object

line_labelstr

line label at the beginning of the line/object

print_line()

generates the actual line string with line label and comments if applicable

gen_string()

generates the BNGL string of the object itself, separate from line attributes

property comment: None
property line_label: str
print_line()str[source]
class bionetgen.modelapi.structs.MoleculeType(name, components)[source]

Bases: bionetgen.modelapi.structs.ModelObj

Class for all parameters in the model, subclass of ModelObj.

In BNGL the molecule types are of the form

molecule_type

where all possible states of each component of a molecule is listed, e.g.

A(b, p~0~1, k~ON~OFF~NULL)

moleculeMolecule

a molecule type only contains a molecule object which can also handle multiple component states

gen_string()str[source]
class bionetgen.modelapi.structs.Observable(name, otype, patterns=[])[source]

Bases: bionetgen.modelapi.structs.ModelObj

Class for all observable in the model, subclass of ModelObj.

In BNGL the observables are of the form

observable_type observable_name observable_patterns

where patterns can include multiple patterns separated by commas.

namestr

name of the observable

typestr

type of the observable, Molecules or Species

patternslist[Pattern]

list of patterns of the observable

add_pattern

add a Pattern object into the list of patterns for this observable

add_pattern(pat)None[source]
gen_string()str[source]
class bionetgen.modelapi.structs.Parameter(name, value, expr=None)[source]

Bases: bionetgen.modelapi.structs.ModelObj

Class for all parameters in the model, subclass of ModelObj.

In BNGL parameters are of the form

parameter_name parameter_value/expression

or

parameter_name = parameter_value/expression

namestr

name of the parameter

valuestr

value of the parameter, if loaded from XML this will always exist since NFsim needs the value and not the expression

exprstr

this exists if the parameter is a math expression, not necerssary

write_exprbool

this is a boolean that determines if the generated string has is in expression form or in value form.

gen_string()str[source]
class bionetgen.modelapi.structs.Rule(name, reactants=[], products=[], rate_constants=())[source]

Bases: bionetgen.modelapi.structs.ModelObj

Class for all parameters in the model, subclass of ModelObj.

namestr

name of the rule, optional

reactantslist[Pattern]

list of patterns for reactants

productslist[Pattern]

list of patterns for products

set_rate_constants((k_fwd,k_bck))

sets forward and backwards rate constants, backwards rate constants are optional and if not given, will set the rule to be a unidirectional rule

side_string(list[Pattern])

given a list of patterns, return a string formatted to be on one side of a rule definition

gen_string()[source]
set_rate_constants(rate_cts)[source]
side_string(patterns)[source]
class bionetgen.modelapi.structs.Species(pattern=, count=0)[source]

Bases: bionetgen.modelapi.structs.ModelObj

Class for all parameters in the model, subclass of ModelObj.

In BNGL the species/seed species are of the form

species count

where species is a single pattern and count is the starting value for that specific pattern

patternPattern

pattern of the seed species

countstr

starting value of the seed species

gen_string()str[source]

bionetgen.modelapi.utils module

bionetgen.modelapi.utils.find_BNG_path(BNGPATH=None)[source]

A simple function finds the path to BNG2.pl from * Environment variable * Assuming it’s under PATH * Given optional path as argument

Usage: test_bngexec(path)

test_bngexec()

BNGPATHstr

(optional) path to the folder that contains BNG2.pl

bionetgen.modelapi.utils.test_bngexec(bngexec)[source]

A simple function that test if BNG2.pl given runs

Usage: test_bngexec(path)

bngexecstr

path to BNG2.pl to test

bionetgen.modelapi.xmlparsers module

class bionetgen.modelapi.xmlparsers.BondsXML(bonds_xml=None)[source]

Bases: object

Bonds XML parser, derived from XMLObj.

get_bond_id(comp)[source]
get_tpl_from_id(id_str)[source]
resolve_xml(bonds_xml)[source]
set_xml(bonds_xml)[source]
tpls_from_bond(bond)[source]
class bionetgen.modelapi.xmlparsers.CompartmentBlockXML(xml)[source]

Bases: bionetgen.modelapi.xmlparsers.XMLObj

CompartmentBlock XML parser, derived from XMLObj. Creates a CompartmentBlock that contains the compartments parsed.

parse_xml(xml)[source]
class bionetgen.modelapi.xmlparsers.FunctionBlockXML(xml)[source]

Bases: bionetgen.modelapi.xmlparsers.XMLObj

FunctionBlock XML parser, derived from XMLObj. Creates a FunctionBlock that contains the functions parsed.

get_arguments(xml)

parses the argument list XML and returns a list of argument names

get_arguments(xml)list[source]
parse_xml(xml)[source]
class bionetgen.modelapi.xmlparsers.MoleculeTypeBlockXML(xml)[source]

Bases: bionetgen.modelapi.xmlparsers.XMLObj

MoleculeTypeBlock XML parser, derived from XMLObj. Creates a MoleculeTypeBlock that contains the molecule types parsed.

add_molecule_type_to_block(block,xml)

parses the XML to create a MoleculeType object and adds it to a given MoleculeTypeBlock object

add_molecule_type_to_block(block, xml)[source]
parse_xml(xml)[source]
class bionetgen.modelapi.xmlparsers.ObservableBlockXML(xml)[source]

Bases: bionetgen.modelapi.xmlparsers.XMLObj

ObservableBlock XML parser, derived from XMLObj. Creates an ObservableBlock that contains the observables parsed.

parse_xml(xml)bionetgen.modelapi.blocks.ObservableBlock[source]
class bionetgen.modelapi.xmlparsers.ParameterBlockXML(xml)[source]

Bases: bionetgen.modelapi.xmlparsers.XMLObj

PatternBlock XML parser, derived from XMLObj. Creates a ParameterBlock that contains the parameters parsed.

parse_xml(xml)bionetgen.modelapi.blocks.ParameterBlock[source]
class bionetgen.modelapi.xmlparsers.PatternListXML(xml)[source]

Bases: object

Pattern list XML parser. Takes a list of patterns and parses them using PatternXML and generates a list of patterns.

patternslist[Pattern]

list of patterns parsed from the XML dict list

parse_xml(xml)list[source]
class bionetgen.modelapi.xmlparsers.PatternXML(xml)[source]

Bases: bionetgen.modelapi.xmlparsers.XMLObj

Pattern XML parser, derived from XMLObj.

_process_mol(xml)

processes a molecule XML dictionary and returns a Molecule object

_process_comp(self, xml)

processes a component XML dictionary and returns a list of Compartment objects

parse_xml(xml)bionetgen.modelapi.pattern.Pattern[source]
class bionetgen.modelapi.xmlparsers.RuleBlockXML(xml)[source]

Bases: bionetgen.modelapi.xmlparsers.XMLObj

RuleBlock XML parser, derived from XMLObj. Creates a RuleBlock that contains the rules parsed.

resolve_ratelaw(xml)

parses a rate law XML and returns the rate constant

resolve_rxn_side(xml)

parses either reactants or products XML and returns a list of Pattern objects

parse_xml(xml)[source]
resolve_ratelaw(xml)[source]
resolve_rxn_side(xml)[source]
class bionetgen.modelapi.xmlparsers.SpeciesBlockXML(xml)[source]

Bases: bionetgen.modelapi.xmlparsers.XMLObj

SpeciesBlock XML parser, derived from XMLObj. Creates a SpeciesBlock that contains the species parsed.

parse_xml(xml)[source]
class bionetgen.modelapi.xmlparsers.XMLObj(xml)[source]

Bases: object

Base object that contains XMLs that is the parent of all XML object that will be used for BNGL blocks as we read from BNGXML. This sets up the python internals such as __repr__ and __str__ for the rest of the XML classes.

This base class assumes at least two methods will be defined by each class that inherits this base object which are defined in the methods below.

xmllist/OrderedDict

XML loaded via xmltodict to be parsed. Either a list of items or an OrderedDict.

parsed_objobj

appropriate parsed object, one of the Block objects

resolve_xml(xml)

the method that parses the XML given and is written separately for each subclass of this one

gen_string()

the method to generate the string from the parsed object

gen_string()[source]
parse_xml(xml)[source]

Module contents