ReactionDiffusion
PyCellChemistry documentation index
/Users/lidia/main/research/acbook/web/website/ac-home/pycellchem/pycellchem-2.0/src/RD/ReactionDiffusion.py

#---------------------------------------------------------------------------
#
# ReactionDiffusion.py: implementation of reaction-diffusion chemical systems
#
# originally based on the breve Hypercycle.[tz/py] demo by jon klein
# <jk@spiderland.org>, www.spiderland.org
#
# by Lidia Yamamoto, Univ. Basel, Switzerland, January 2010
# 20150910: removed breve dependencies to run within PyCellChemistry
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# 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
WritePNG
sys


Classes
artchem.ReactionVessel.ODESystem(artchem.ReactionVessel.ReactionVessel)
ReactionDiffusionSystem


class ReactionDiffusionSystem(artchem.ReactionVessel.ODESystem)
a PDE integrator for a reaction-diffusion system
Method resolution order:
ReactionDiffusionSystem
artchem.ReactionVessel.ODESystem
artchem.ReactionVessel.ReactionVessel

Methods defined here:
__init__(self, x, y, dx=1.0, periodic=True, nneighs=4)
add_patch(self, mol, conc)
add a patch of chemical at a random location
add_patch_at(self, mol, conc, x, y)
add some concentration to a patch of chemical at a given
location
add_patches(self, npatches, mol, initconc)
add some random patches of chemicals
animate(self, sleeptime=1.0, transparent=True, blur=False)
display the reaction-diffusion grid using vpytyon
transparent: use transparent background instead of black
blur: produce fuzzy borders between cells on the grid
close(self)
closes the PDE system such that it can be integrated
computeTextureMatrix(self, transparent)
produce a texture matrix to be used by animate()
conc2img(self, cellsizex, cellsizey, transparent)
convert the concentration matrix to the ARGB format
accepted by png.saveAsPNG()

if the transparent flag is set, the resulting png image
will have a transparent background in the spots where
there are no chemicals;
else the image will have a black background in those spots

TODO: implement hexagonal grid
conc2img_DISABLED(self, cellsizex, cellsizey, transparent)
convert the concentration matrix to the ARGB format
accepted by png.saveAsPNG()

tried to use matrix ops for speedup, but it turned out
slower than the element-by-element implementation above
deposit(self, mol, conc, x, y)
deposit a given amount of a molecule at a precise location
diffusion_term(self, n)
calculate diffusion term for molecule with index n, for
whole grid at once using matrix operations; leave result
on self.diff
diffusion_term_NOTUSED(self, n)
calculate diffusion term for molecule with index n, leave
result on self.diff (calculate one by one, far too slow,
but I leave the code here to illustrate conceptually how
it works, it's more readable than the matrix form below)
disrupt(self, mol, val, x0, y0, x1, y1)
disrupt the concentration of a chemical within a given
rectangle: clamp the concentr to at most val
get_color(self, mol)
returns the color that has been assigned to molecule mol
get_conc(self, mol, x, y)
get concentration of molecule by name, respecting boundaries
get_conc_by_index(self, idx, x, y)
get concentration of molecule by index, respecting boundaries
get_diffcoef(self, mol)
returns the diffusion coefficient of molecule mol
get_neighbors(self)
returns the current neighborhood configuration
get_periodic(self)
True if the current setup is periodic boundary
get_pos(self, x, y)
make sure coordinates always fall within boundaries
integrate(self, dt=1.0)
PDE integration of reaction-diffusion system with timestep dt
perturb(self, mol, prob, ampl, x, y)
perturb concentration at the given point
perturbAll(self, mol, prob, ampl)
perturb the given chemical with a given probability and
amplitude: a random concentration value in the range
[-amp/2 ; ampl/2] will be deposited at each node with
probability prob (if the chemical is not in the node,
nothing happens)
perturb_region(self, mol, prob, ampl, x0, y0, x1, y1)
perturb concentrations in the given region
reaction_term(self, n)
calculate reaction term for molecule with index n, leaving
the result on self.dcdt
reset(self, mol, x, y)
reset the concentration of a given molecule to zero
resetAll(self, mol='', conc=0.0)
reset the concentration of a given molecule to a given
value, overall on the grid; if no molecule is specified,
reset the concentrations of all molecules
reset_region(self, mol, val, x0, y0, x1, y1)
set the concentration of substances in this region to the
given value
rnd_deposit(self, npoints, mol, conc, ampl=0.0)
deposit a random amount of a molecule at random locations
set_color(self, mol, color)
set color of molecule to color=(red, green, blue)
set_conc(self, mol, conc, x, y)
set the concentration of a molecule at position x,y to a
given value, respecting boundary conditions
set_diffcoef(self, mol, value)
set the diffusion coefficient of molecule mol
set_neighbors(self, nn)
set neighborhood configuration: nn =
2: simple (north and right neighbors)
4: Von Neumann
6: hexagonal lattice
8: Moore
set_patch(self, mol, conc)
create a patch of chemical at a random location
set_patch_at(self, mol, conc, x, y)
create a patch of chemical at a given location
set_patches(self, npatches, mol, initconc)
create some initial random patches of chemicals
set_periodic(self, flag)
periodic (toroidal) vs. non-periodic boundary conditions
trace(self)
print internal variables, for debug purposes
trace_conc(self)
print the full grid of concentrations for each chemical,
producing a tab-separated matrix for each chemical
trace_conc_xy(self, x, y)
print the concentations of all chemicals at position (x,y)
trace_title(self)
output tab-separated title line for plotting
writepng(self, fname, pngsizex=256, pngsizey=256, transparent=True)
write molecule concentrations to a png image; each grid
position will have a size of cellsize per cellsize pixels

Methods inherited from artchem.ReactionVessel.ODESystem:
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)
set_coefficient(self, i, k)
update kinetic coefficient for reaction

Methods inherited from artchem.ReactionVessel.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)
vtime(self)
current simulation time


Generated automatically by pydoc, July 10, 2015