SloppyCell :: ReactionNetworks :: Network_mod :: Network :: Class Network
[hide private]

Class Network

source code

Instance Methods [hide private]
 
__init__(self, id, name='') source code
 
_add_variable(self, var) source code
 
add_compartment(self, id, initial_size=1.0, name='', typical_value=None, is_constant=True, is_optimizable=False)
Add a compartment to the Network.
source code
 
add_species(self, id, compartment, initial_conc=0, name='', typical_value=None, is_boundary_condition=False, is_constant=False, is_optimizable=False, uniprot_ids=set())
Add a species to the Network.
source code
 
add_parameter(self, id, initial_value=1.0, name='', typical_value=None, is_constant=True, is_optimizable=True)
Add a parameter to the Network.
source code
 
add_event(self, id, trigger, event_assignments={}, delay=0, name='', buffer=0)
Add an event to the Network.
source code
 
add_constraint(self, id, trigger, message=None, name='')
Add a constraint to the Network.
source code
 
add_func_def(self, id, variables, math, name='')
Add a function definition to the Network.
source code
 
make_func_defs(self) source code
 
addReaction(self, id, *args, **kwargs) source code
 
add_assignment_rule(self, var_id, rhs)
Add an assignment rule to the Network.
source code
 
add_rate_rule(self, var_id, rhs)
Add a rate rule to the Network.
source code
 
add_algebraic_rule(self, rhs)
Add an algebraic rule to the Network.
source code
 
remove_component(self, id)
Remove the component with the given id from the Network.
source code
 
_checkIdUniqueness(self, id)
Check whether a given id is already in use by this Network.
source code
 
set_id(self, id)
Set the id of this Network
source code
 
get_id(self)
Get the id of this Network.
source code
 
set_name(self, name)
Set the name of this Network
source code
 
get_name(self)
Get the name of this Network.
source code
 
set_deterministic(self)
Disables the stochastic simulation of network dynamics
source code
 
set_stochastic(self, seed=None, fill_dt=None, rmsd=None)
set_stochastic enables the stochastic simulation of the network dynamics (instead of deterministic integration).
source code
 
set_periodic(self, period, xtol=0.001, maxfun=100, phase=None, minVel=None, level=2, log=False, rel=False)
set_periodic ensures that a period solution has satisfactorily approached a limit cycle before returning the solution.
source code
 
_iter_limit_cycle(self, params, varNames, s0)
Internal function used to integrate a trajectory and find the point nearest the initial point (defined as the root sum squared distance) in the period range of [0.475*tau, 1.5*tau].
source code
 
_eliminate_slowest_mode(self, s0, s1, s2)
Internal function which finds and eliminates the slowest decaying mode in the approach to a limit cycle: si = [tau_i, x0_0, .., x0_i] F0 = s_star + vector_1 + ...
source code
 
_find_limit_cycle(self, params)
Internal function to find a stable limit cycle (if one exists), given a parameter set, an estimated period, and a set of initial conditions.
source code
 
calculate(self, vars, params=None) source code
 
Calculate(self, vars, params=None) source code
 
CalculateSensitivity(self, vars, params) source code
 
GetName(self) source code
 
GetParameters(self) source code
 
GetParameterTypicalValues(self) source code
 
GetResult(self, vars) source code
 
GetSensitivityResult(self, vars) source code
 
integrate(self, times, params=None, returnEvents=False, addTimes=True, rtol=None) source code
 
integrateSensitivity(self, times, params=None, returnEvents=False, addTimes=True, rtol=None) source code
 
integrateStochastic(self, times, params=None) source code
 
_sub_for_piecewise(self, expr, time)
Runs through expr and replaces all piecewise expressions by the clause that is currently active.
source code
 
_sub_for_piecewise_ast(self, ast, time) source code
 
evaluate_expr(self, expr, time=0, var_vals=None)
Evaluate the given expression using the current values of the network variables.
source code
 
set_var_typical_val(self, id, value)
Set the typical value for a variable.
source code
 
get_var_typical_val(self, id)
Return the typical value for a variable.
source code
 
get_var_typical_vals(self)
Return the variable typical values as a KeyedList.
source code
 
set_var_ic(self, id, value, warn=True, update_constants=True)
Set the initial condition of the variable with the given id.
source code
 
get_var_ic(self, id)
Return the initial condition for a variable
source code
 
get_var_ics(self)
Return the variable initial conditions as a KeyedList
source code
 
set_var_vals(self, kl, time=0)
Set current variable values from a KeyedList or dictionary.
source code
 
get_var_val(self, id)
Return the current value of a variable
source code
 
get_var_vals(self, ids=None)
Return the current variable values as a KeyedList
source code
 
get_initial_velocities(self)
Returns the vector field evaluated at the initial conditions
source code
 
set_var_ics(self, kl)
Set variable initial conditions from a KeyedList or dictionary.
source code
 
set_var_val(self, id, val, time=0, warn=True, do_assignments=True)
Set the current stored value of the variable with the given id.
source code
 
setTypicalVariableValue(self, id, value)
Set the typical value for a variable.
source code
 
get_variable(self, id)
Return the class instance with a given variable id.
source code
 
update_optimizable_vars(self, params)
Update the net's optimizable vars from a passed-in KeyedList, dictionary, or sequence.
source code
 
getInitialVariableValue(self, id)
Return the initial condition for a variable
source code
 
getDynamicVarValues(self) source code
 
resetDynamicVariables(self) source code
 
set_dyn_var_ics(self, values) source code
 
updateVariablesFromDynamicVars(self, values, time) source code
 
updateAssignedVars(self, time) source code
 
set_var_optimizable(self, id, is_optimizable) source code
 
set_var_constant(self, id, is_constant) source code
 
get_var_constant(self, id) source code
 
_makeDiffEqRHS(self) source code
 
_make_res_function(self) source code
 
_make_root_func(self) source code
 
_make_alg_deriv_func(self) source code
 
_make_alg_res_func(self) source code
 
_make_dres_dc_function(self) source code
 
_make_dres_dcdot_function(self) source code
 
_make_ddaskr_jac(self) source code
 
_make_dres_dsinglep(self) source code
 
_make_sens_rhs(self) source code
 
_make_log_funcs(self) source code
 
_make_integrate_stochastic_tidbit(self) source code
 
_add_assignments_to_function_body(self, body, in_c=False, include_dts=False)
Adds the assignment rules for this Network to the list of lines that are in body.
source code
 
fireEvent(self, event, dynamicVarValues, time) source code
 
executeEvent(self, event, time_fired, y_fired, y_current, time_current) source code
 
_smooth_trigger(self, trigger) source code
 
executeEventAndUpdateSens(self, holder, ysens_pre_exec, opt_var) source code
 
_makeCrossReferences(self)
Create the cross-reference lists for the Network.
source code
 
disable_deriv_funcs(self)
Disables the creation of derivative functions, which can speed up integration.
source code
 
enable_deriv_funcs(self)
Enables the creation of derivative functions, which allows sensitivity integration and may speed up normal integration as well.
source code
 
compile(self, disable_c=None)
Create the dynamically-generated functions for this Network.
source code
 
_get_structure(self)
Return a tuple representing the structure of the Network.
source code
 
exec_dynamic_functions(self, disable_c=False, del_c_files=True, curr_c_code=None) source code
 
get_c_code(self) source code
 
output_c(self, c_code, mod_name=None) source code
 
run_f2py(self, mod_name, hide_f2py_output=True) source code
 
import_c_funcs_from_module(self, module) source code
 
takeDerivative(self, input, wrt, vars_used=None, simplify=True)
Take the derivative of a math expression wrt a given variable id.
source code
 
copy(self, new_id=None, new_name=None)
Return a copy of the given network, with an optional new id.
source code
 
__getstate__(self) source code
 
__setstate__(self, newdict) source code
 
get_component_name(self, id, TeX_form=False)
Return a components's name if it exists, else just return its id.
source code
 
get_eqn_structure(self) source code
 
addCompartment(self, id, size=1.0, name='', typicalValue=False, isConstant=True, isOptimizable=False) source code
 
addVariable(self, var) source code
 
addSpecies(self, id, compartment, initialConcentration=None, name='', typicalValue=None, is_boundary_condition=False, isConstant=False, isOptimizable=False, uniprot_ids=set()) source code
 
addParameter(self, id, value=0.0, typicalValue=None, name='', isConstant=True, isOptimizable=True) source code
 
addRateRule(self, var_id, rhs)
Add a rate rule to the Network.
source code
 
dyn_var_fixed_point(self, dv0=None) source code
 
FindFixedPoint(self, dv0=None) source code
 
set_initial_var_value(self, id, value, warn=True, update_constants=True)
Set the initial condition of the variable with the given id.
source code
 
setInitialVariableValue(self, id, value, warn=True, update_constants=True)
Set the initial condition of the variable with the given id.
source code
 
setOptimizables(self, params)
Update the net's optimizable vars from a passed-in KeyedList, dictionary, or sequence.
source code
 
addEvent(self, id, trigger, eventAssignments, delay=0, name='') source code
 
addConstraint(self, id, trigger, message=None, name='') source code
 
addFunctionDefinition(self, id, variables, math, name='')
Add a function definition to the Network.
source code
 
addAssignmentRule(self, var_id, rhs)
Add an assignment rule to the Network.
source code
Class Methods [hide private]
 
full_speed(cls)
Do not add timepoints to returned trajectories.
source code
 
fill_traj(cls)
Allow the integrator to automatically add timepoints to the interior of a trajectory.
source code
 
pretty_plotting(cls)
Add timepoints to the interior of a trajectory, plus 5% past the last timepoint requested.
source code
Class Variables [hide private]
  _dynamic_structure_methods = ['_make_res_function', '_make_alg...
  _dynamic_event_methods = ['_make_root_func']
  _common_namespace = {'log': scipy.log, 'log10': scipy.log10, '...
  _standard_func_defs = [('root', ['n', 'x'], 'x**(1./n)'), ('co...
  _logical_comp_func_defs = [('gt', ['x', 'y'], 'x > y'), ('geq'...
  _common_func_strs = KeyedList()
  _common_func_strs_c = KeyedList()
  _common_prototypes_c = KeyedList()
  _sens_event_derivs_cache = []
  _last_structure = None
  disable_c = SloppyCell.disable_c
  _last_disabled_c = SloppyCell.disable_c
  _py_func_dict_cache = {}
  _c_module_cache = {}
Method Details [hide private]

fill_traj(cls)
Class Method

source code 

Allow the integrator to automatically add timepoints to the interior of
a trajectory.

This is slower, but may capture the dynamics better.

pretty_plotting(cls)
Class Method

source code 

Add timepoints to the interior of a trajectory, plus 5% past the last
timepoint requested.

This produces the prettiest plots.

add_compartment(self, id, initial_size=1.0, name='', typical_value=None, is_constant=True, is_optimizable=False)

source code 

Add a compartment to the Network.

All species must reside within a compartment.

add_event(self, id, trigger, event_assignments={}, delay=0, name='', buffer=0)

source code 

Add an event to the Network.

id - id for this event
trigger - The event firest when trigger passes from False to True.
    Examples: To fire when time becomes greater than 5.0:
               trigger = 'gt(time, 5.0)'
              To fire when A becomes less than sin(B/C):
               trigger = 'lt(A, sin(B/C))'
event_assignments - A dictionary or KeyedList of assignments to make
              when the event executes.
    Example: To set A to 4.3 and D to B/C
              event_assignments = {'A': 4.3,
                                   'D': 'B/C'}
delay - Optionally, assignments may take effect some time after the
    event fires. delay may be a number or math expression
name - A more detailed name for the event, not restricted to the id
    format

add_constraint(self, id, trigger, message=None, name='')

source code 

Add a constraint to the Network.

id - id for this constraint
trigger - We treat constraints as events that correspond to an
    invalid solution whenever the trigger is True.
    Example: To have an invalid solution when species A is > 5.0:
               trigger = 'gt('A', 5.0)'
name - A more detailed name for the constraint, not restricted to the id
    format

add_func_def(self, id, variables, math, name='')

source code 

Add a function definition to the Network.

id - id for the function definition
variables - The variables used in the math expression whose
            values should be subsituted.
math - The math expression the function definition represents
name - A more extended name for the definition

Example:
    To define f(x, y, z) = y**2 - cos(x/z)
    net.add_func_def('my_func', ('x', 'y', 'z'), 'y**2 - cos(x/z)')

add_assignment_rule(self, var_id, rhs)

source code 

Add an assignment rule to the Network.

A rate rules species that <var_id> = rhs.

add_rate_rule(self, var_id, rhs)

source code 

Add a rate rule to the Network.

A rate rules species that d <var_id>/dt = rhs.

add_algebraic_rule(self, rhs)

source code 

Add an algebraic rule to the Network.

An algebraic rule specifies that 0 = rhs.

remove_component(self, id)

source code 

Remove the component with the given id from the Network.

Components that can be removed are variables, reactions, events,
function definitions, assignment rules, rate rules, and constraints.

set_stochastic(self, seed=None, fill_dt=None, rmsd=None)

source code 

set_stochastic enables the stochastic simulation of the network
dynamics (instead of deterministic integration). This will discretize
the dynamic variables in the model (making them integers). This
simulation has only limited support for events*, and does not
implement algebraic rules** or rates rules**. We use a kinetic MC
algorithm (aka Gillespie algorithm). The complementary function
'set_deterministic' may be used to disable stochastic simulations of
network dynamics. Please note the results returned for exactly the
times asked are interpolations between the surrounding points, thus
concentrations may be floats instead of integers.

* Since there is no exact way to implement events in a stochastic
  simulation, only a very primative method is present. This algorithm
  currently only supports time triggered events (more complex triggers
  may be added in the future) and fires them as soon after that time
  is passed as possible. Please note that it is the users
  responsibility to ensure the events are firing in a sensible
  way. Non-sensible output will arise when the time steps are too
  large and events are not fired near their target trigger times. The
  fired times are logged in the logger at the debug level.

** Possible future implementation, although parsing rate rules have the
   possible issue of creating negative reaction rates (which have no
   physical meaning). Add reactions instead of rate rules for stochastic
   simulations.

Inputs:
(seed=None, fill_dt=None, rmsd=None)
seed -- RNG seed used in the simulation. If none, generated from the
        system time and os.urandom (if available).
fill_dt -- Fill in the trajectory at the requested time interval. This
           is the simplest way to fill in a trajectory.
rmsd -- Maximum root mean squared distance in the dynamic variable
        space before taking a data point (a better trajectory filler).

Outputs: None

set_periodic(self, period, xtol=0.001, maxfun=100, phase=None, minVel=None, level=2, log=False, rel=False)

source code 

set_periodic ensures that a period solution has satisfactorily
approached a limit cycle before returning the solution. Please note that
this has not been implemented for sensitivity calculations.

Inputs:
(period, xtol=0.001, maxfun=100, phase=None, minVel=None, level=2,
log=False, rel=False)
period -- initial guess of the period (required)
xtol -- tolerance required for convergence (all chemicals). If set too
        high, numerical (in)precision may cause no stable limit cycle.
maxfun -- maximum number of iterations (one trajectory found in each)
phase -- set to a ('name', value) tuple to set the t=0 solution to a
         particular state in systems which no forcing. Value may be
         'max','min', or a float concentration (careful with the later).
minVel -- used to detect fixed points:
          when the (max IC velocity)**2 < minVel the integration
          is halted, the stability set to True, and the period set to
          0.0 (indicating nonperiodic, fixed point soln).
level -- correlation level (>=1) to use to find the period. For example,
         if level=2, the difference between x(0)-x(1*tau) and
         x(0)-x(2*tau) is used.
log -- Set to True to use logarithms of state variables, constraining
       the solution to non-zero values
rel -- Set to True to use relative differences (x1-x0)/min(x0,x1) in
       the limit cycle period search.
       
Outputs: (stored in net.periodic dictionary)
tol -- tolerance of the solution (rmsd of ic1 to ic0 for each level)
period -- actual period of oscillation
stable -- whether a stable solution was found
feval -- number of iterations
stableIC -- stable initial condition

Additionally, the period is accessible during the calculation and
afterwards via the '_tau' variable (useful for assignments which
rely on the period).

_iter_limit_cycle(self, params, varNames, s0)

source code 

Internal function used to integrate a trajectory and find the point
nearest the initial point (defined as the root sum squared distance)
in the period range of [0.475*tau, 1.5*tau]. The point found and period
(tau) is returned.

Inputs:
(params, varNames, s0)
params -- Network parameters
varNames -- Names corresponding to the values in ln_x0
s0 -- Initial state (period and conditions) where s0[0]=period and
      s0[1:]=initial conditions

Outputs:
(s1)
s1 -- New state found (period and conditions defined same as input)

_eliminate_slowest_mode(self, s0, s1, s2)

source code 

Internal function which finds and eliminates the slowest decaying
mode in the approach to a limit cycle:
si = [tau_i, x0_0, .., x0_i]
F0 = s_star + vector_1 + ...
F1 = s_star + lambda_1 * vector_1 + ...
F2 = s_star + lambda_1^2 * vector_1 + ...

lambda_1 = (F2-F1)*(F1-F0)/|F1-F0|^2
vector_1 = (F2-F1)/(lambda_1 * (lambda_1 - 1.0))

Inputs: (s0, s1, s2)
Three vectors representing three consecutive steps towards a limit cycle

Ouptuts: (s_star)
s_star = s2 - lambda_1^2 * vector_1

_find_limit_cycle(self, params)

source code 

Internal function to find a stable limit cycle (if one exists), given a
parameter set, an estimated period, and a set of initial conditions.
This function calculates two iterations (which are hopefully approaching
a limit cycle), and use this to estimate a point on the limit cycle - an
estimation which is kept if it is closer to the limit cycle.

Inputs:
(params,)
params -- model parameters

Outputs: None

get_var_vals(self, ids=None)

source code 

Return the current variable values as a KeyedList

ids -- List o variable ids to return values for. If None, all variables
       are used.

update_optimizable_vars(self, params)

source code 

Update the net's optimizable vars from a passed-in KeyedList,
 dictionary, or sequence.

Only those variables that intersect between the net and params are
changed if a KeyedList or dict is passed in.

compile(self, disable_c=None)

source code 

Create the dynamically-generated functions for this Network.

Note that if a model involves many copies of the same network, with 
differences only in events or initial conditions, it will save time
to compile the base Network before copying it.

_get_structure(self)

source code 

Return a tuple representing the structure of the Network.

The tuple contains the functionDefinitions, reactions, and rules for
the Network. It also contains information on the constancy and
optimizability of the variables.

takeDerivative(self, input, wrt, vars_used=None, simplify=True)

source code 

Take the derivative of a math expression wrt a given variable id.

Does the chain rule through assigned variables.

addRateRule(self, var_id, rhs)

source code 

Add a rate rule to the Network.

A rate rules species that d <var_id>/dt = rhs.

setOptimizables(self, params)

source code 

Update the net's optimizable vars from a passed-in KeyedList,
 dictionary, or sequence.

Only those variables that intersect between the net and params are
changed if a KeyedList or dict is passed in.

addFunctionDefinition(self, id, variables, math, name='')

source code 

Add a function definition to the Network.

id - id for the function definition
variables - The variables used in the math expression whose
            values should be subsituted.
math - The math expression the function definition represents
name - A more extended name for the definition

Example:
    To define f(x, y, z) = y**2 - cos(x/z)
    net.add_func_def('my_func', ('x', 'y', 'z'), 'y**2 - cos(x/z)')

addAssignmentRule(self, var_id, rhs)

source code 

Add an assignment rule to the Network.

A rate rules species that <var_id> = rhs.


Class Variable Details [hide private]

_dynamic_structure_methods

Value:
['_make_res_function', '_make_alg_deriv_func', '_make_alg_res_func', '\
_make_dres_dc_function', '_make_dres_dcdot_function', '_make_ddaskr_ja\
c', '_make_dres_dsinglep', '_make_sens_rhs', '_make_log_funcs', '_make\
_integrate_stochastic_tidbit']

_common_namespace

Value:
{'log': scipy.log, 'log10': scipy.log10, 'exp': math.exp, 'cos': math.\
cos, 'sin': math.sin, 'tan': math.tan, 'acos': math.acos, 'asin': math\
.asin, 'atan': math.atan, 'cosh': math.cosh, 'sinh': math.sinh, 'tanh'\
: math.tanh, 'pow': math.pow, 'sqrt': math.sqrt, 'exponentiale': math.\
e, 'pi': math.pi, 'scipy': scipy, 'operator': operator,}

_standard_func_defs

Value:
[('root', ['n', 'x'], 'x**(1./n)'), ('cot', ['x'], '1./tan(x)'), ('arc\
cot', ['x'], 'atan(1/x)'), ('coth', ['x'], '1./tanh(x)'), ('csc', ['x'\
], '1./sin(x)'), ('arccsc', ['x'], 'asin(1./x)'), ('csch', ['x'], '1./\
sinh(x)'), ('sec', ['x'], '1./cos(x)'), ('arcsec', ['x'], 'acos(1./x)'\
), ('sech', ['x'], '1./cosh(x)'),]

_logical_comp_func_defs

Value:
[('gt', ['x', 'y'], 'x > y'), ('geq', ['x', 'y'], 'x >= y'), ('lt', ['\
x', 'y'], 'x < y'), ('leq', ['x', 'y'], 'x <= y'), ('eq', ['x', 'y'], \
'y == x'), ('not_func', ['x'], 'not x'), ('and_func', '*', 'x and y'),\
 ('or_func', '*', 'x or y'),]