ReactionVessel
PyCellChemistry documentation index
source code: src/artchem/ReactionVessel.py

#---------------------------------------------------------------------------
#
# ReactionVessel.py: a reaction vessel for well-stirred explicit
# Artificial Chemistries (S, R, A) in which molecules and reactions
# are represented explicitly, and for which the set of possible
# molecular species S and the set of reactions R does not change.
#
# Two algorithms A are implemented as specializations of the basic
# ReactionVessel class:
# - WellStirredVessel: a simple ODE integration algorithm based on
# Euler's method
# - GillespieVessel: a simple implementation of Gillespie's stochastic
# simulation algorithm (SSA) using the direct method
#
# by Lidia Yamamoto, Univ. Basel, Switzerland, January 2010
# June 2013: adapted to the PyCellChemistry package
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# Copyright (C) 2015 Lidia A. R. Yamamoto
# Contact: http://www.artificial-chemistries.org/
#
# This file is part of PyCellChemistry.
#
# PyCellChemistry is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 3, as published by the Free Software Foundation.
#
# PyCellChemistry is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyCellChemistry, see file COPYING. If not, see
# http://www.gnu.org/licenses/
#


Modules
numpy
sys


Classes
ReactionVessel
GillespieVessel(ReactionVessel, Multiset.Multiset)
WellStirredVessel


class GillespieVessel(ReactionVessel, Multiset.Multiset)
Method resolution order:
GillespieVessel
ReactionVessel
Multiset.Multiset

Methods defined here:
__init__(self, nav=1000)
initialize empty reaction vessel for stochastic simulation;
'nav' is the initial N_A * V quantity (Avogadro constant
times volume of the vessel); typically a smaller nav
(hence smaller volume) leads to more prominent stochastic
fluctuations
close(self)
create data structures necessary for stochastic simulation;
convert the macroscopic kinetic constants (k) to
microscopic equivalents (c) using Wolkenhauer's relation
deposit(self, mol, conc)
deposit a concentration 'conc' of molecule 'mol';
first must convert 'conc' [S] to number of molecules (ns)
to be injected: [S] = ns / NAV => ns = [S] * NAV
factorial(self, n, m=1)
recursively computes the factorial of n, stopping at m:
factorial(n, m) = n*(n-1)*...*m for 1 < m < n
get_conc(self, mol)
calculate concentration of molecule 'mol': [S] = ns / NAV
get_nav(self)
current N_A * V value
get_volume(self)
volume of the vessel
integrate(self, dt=1.0)
iterate Gillespie SSA for an interval of size at least dt
iterate(self)
one iteration of the Gillespie stochastic simulation algorithm
nchoosek(self, n, k)
computes the binomial coefficient or "n choose k" function:
C(n,k) for two integers n & k, where n > k
C(n,k) = n!/((k!)(n-k)!) = n(n-1)(n-2)...(n-k+1)/k!
efficient when either k or (n-k) is small (n can be big)
nspecies(self)
total number of possible molecular species (static)
nspecies_mset(self)
number of species currently present in the multiset (dynamic)
perform_reaction(self, rno)
perform a given reaction, extracting the needed educts
from the multiset and injecting the resulting products
propensity(self)
calculate reaction propensities, store them in wv[j], total=wt
react(self, dice)
perform the reaction pointed by the given dice
relies on pre-calculated propensity values stored in wv[j]
set_coefficient(self, i, k)
update kinetic coefficient for reaction, together with its
corresponding mesoscopic value
set_nav(self, newnav)
sets the value of N_A*V = NAV:

this is useful when we have the parameters from the ODE
(initial concentrations, kinetic constants k) and want to
perform a stochastic simulation based on the same
parameters

in order to adjust NAV we use the relation:

[S] = ns / NAV => ns = [S]*NAV

thus by setting NAV small, we make the reactor small for
the same concentration, that is, the number of molecules
in the reactor will be smaller, hence the stochastic
effects can be more easily seen; increase NAV to simulate
larger particle numbers in the reactor, for a given
concentration.
set_volume(self, newvol)
sets the volume of the vessel, recalculating NAV = N_A*V
and the mesoscopic kinetic constants accordingly
trace(self)
print internal variables, for debug purposes
trace_conc(self, prefix='')
print concentrations, like trace_mult but concentrations
are calculated as [S] = ns / NAV
trace_mult(self, prefix='')
print molecule counts to tab-separated line for plotting.
a one-letter prefix can be given to print only molecules
starting with that letter
wolkenhauer(self, j)
calculate the microscopic stochastic rate constants (c)
from the macroscopic ones (k), according to [Wolkenhauer2004]:

c = k / (NAV)^(m - 1) * prod_i=1;L(li!)

where:
. m is the total number of colliding molecules (size of
educt multiset)
. L is the number of species in the educt multiset
. li is the educt stoichiometric coefficient of substance i
. NAV = N_A * V (CAUTION!!! must be refreshed if NAV changes!!)

Methods inherited from ReactionVessel:
add(self, reaction)
add a new chemical reaction to the vessel's set of reactions;
'reaction' must be an object of the Reaction class
get_coefficient(self, i)
get kinetic coefficient for reaction
get_names(self)
list of all possible molecular species (set S of S,R,A)
nreactions(self)
total number of reactions: |R| in S,R,A
parse(self, reactlist)
invoke the ReactionParser to parse a list of reactions
parse_file(self, fname)
invoke the ReactionParser to parse the file named 'fname'
parse_input(self, infile)
invoke the ReactionParser to parse an already open input file
parse_stdin(self)
invoke the ReactionParser to parse the standard input (stdin)
trace_title(self, prefix='')
output tab-separated title line for plotting;
an optional prefix can be given to print only molecules
starting with that character
vtime(self)
current simulation time

Methods inherited from Multiset.Multiset:
absorb(self, victim)
absorb victim multiset into my own (victim will return empty)
clear(self)
delete all molecules from the multiset
divide(self)
divide multiset in two parts; returns daughter multiset created
empty(self)
true if this multiset is empty
expel(self, mol, mult=1)
expel a given amount of a molecule from the multiset;
returns the number of molecules actually expelled
expelrnd(self)
expel a random molecule from the multiset
inject(self, mol, mult=1)
inject a given amount of a molecule in the multiset
keys(self)
list containing the set of different objects in the multiset
mult(self, mol='')
multiplicity: number of molecules of type 'mol' present
in the multiset
nmolecules(self)
total number of molecules in the multiset
rndmol(self)
peek at a random molecule from the multiset, without
removing it
topkeys(self)
list of molecules in the multiset, ordered by decreasing
multiplicity
trace_frequencies(self)
print a histogram of molecule multiplicities


class ReactionVessel
Methods defined here:
__init__(self)
initialize empty reaction vessel
add(self, reaction)
add a new chemical reaction to the vessel's set of reactions;
'reaction' must be an object of the Reaction class
get_coefficient(self, i)
get kinetic coefficient for reaction
get_names(self)
list of all possible molecular species (set S of S,R,A)
nreactions(self)
total number of reactions: |R| in S,R,A
nspecies(self)
total number of molecular species: |S| in S,R,A
parse(self, reactlist)
invoke the ReactionParser to parse a list of reactions
parse_file(self, fname)
invoke the ReactionParser to parse the file named 'fname'
parse_input(self, infile)
invoke the ReactionParser to parse an already open input file
parse_stdin(self)
invoke the ReactionParser to parse the standard input (stdin)
set_coefficient(self, i, k)
update kinetic coefficient for reaction
trace(self)
print internal variables, for debug purposes
trace_title(self, prefix='')
output tab-separated title line for plotting;
an optional prefix can be given to print only molecules
starting with that character
vtime(self)
current simulation time


class WellStirredVessel(ReactionVessel)
Methods defined here:
__init__(self)
initialize empty reaction vessel for ODE integration
apply_dilution(self)
apply dilution to vessel capacity: normalize the
concentrations to the vessel capacity, such that the sum
of concentrations of all species in the system does not
exceed the vessel capacity
close(self)
after all reactions have been parsed, this method should
be called in order to create all the data structures
needed for numeric integration
deposit(self, mol, conc)
increase the concentration of molecule 'mol' by an amount
'conc'
get_coefficient(self, i)
get kinetic coefficient for reaction (overrides default
ReactionVessel method in order to use vector kv directly;
the result of both methods should be the same though)
get_conc(self, mol)
get the concentration of molecule 'mol'
get_dilution(self)
get vessel capacity (measured in concentration)
integrate(self, dt=1.0)
ODE integration for one timestep of size dt
reset(self, mol='', conc=0.0)
reset the concentration of molecule 'mol' to 'conc';
if 'mol' is not specified (mol='') then set the
concentration of all molecules to the value 'conc';
hence a reset() without parameters will reset all the
concentration values to zero
set_coefficient(self, i, k)
update kinetic coefficient for reaction
set_conc(self, mol, conc)
set the concentration of molecule 'mol' to 'conc'
set_dilution(self, cap)
set dilution to vessel capacity, where 'cap' is the
maximum concentration that the vessel should contain
trace(self)
print internal variables, for debug purposes
trace_conc(self)
trace concentrations to tab-separated line for plotting

Methods inherited from ReactionVessel:
add(self, reaction)
add a new chemical reaction to the vessel's set of reactions;
'reaction' must be an object of the Reaction class
get_names(self)
list of all possible molecular species (set S of S,R,A)
nreactions(self)
total number of reactions: |R| in S,R,A
nspecies(self)
total number of molecular species: |S| in S,R,A
parse(self, reactlist)
invoke the ReactionParser to parse a list of reactions
parse_file(self, fname)
invoke the ReactionParser to parse the file named 'fname'
parse_input(self, infile)
invoke the ReactionParser to parse an already open input file
parse_stdin(self)
invoke the ReactionParser to parse the standard input (stdin)
trace_title(self, prefix='')
output tab-separated title line for plotting;
an optional prefix can be given to print only molecules
starting with that character
vtime(self)
current simulation time


Generated automatically by pydoc, July 10, 2015


Generated automatically by pydoc, July 10, 2015