See also

This page was generated from examples/example14.ipynb.

Download the Jupyter Notebook for this section: example14.ipynb. View in nbviewer.

https://colab.research.google.com/assets/colab-badge.svg https://mybinder.org/badge_logo.svg

The sGFRD Method

The numpy-stl module is required for visualizations of a STL mesh.

[1]:
# !pip install numpy-stl
import stl
/home/kaizu/.local/share/virtualenvs/python-eSbFG-Wg/lib/python3.7/importlib/_bootstrap.py:219: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  return f(*args, **kwds)

Set Plotly as the default backend.

[2]:
from ecell4.prelude import *
[3]:
import ecell4.plotting
import ecell4.plotting._plotly
ecell4.plotting.BACKEND = ecell4.plotting._plotly
from ecell4.plotting._plotly import plot_stl
[4]:
f = sgfrd.Factory()

Diffusion on a Triangle Mesh

Here is a STL-format file named stanford_bunny.stl:

[5]:
plot_stl("stanford_bunny.stl")
[6]:
with species_attributes():
    A | {"radius": 0.005, "D": 1.0}

m = get_model()
[7]:
edge_lengths = Real3(90, 70, 90)
w = f.polygon("stanford_bunny.stl", STLFormat.Ascii).world(edge_lengths)
[8]:
w.bind_to(m)
[9]:
w.add_molecules(Species('A'), 50)
[10]:
plotting.plot_world(w, stl=["stanford_bunny.stl"])
[11]:
s = f.simulator(w, m)
obs = FixedIntervalTrajectoryObserver(1.0)
s.run(100.0, obs)
[12]:
plotting.plot_trajectory(obs, max_count=50, stl=["stanford_bunny.stl"], layout=dict(showlegend=False))

Reaction-Diffusion on a Planar Surface

[13]:
plot_stl("plane10x10.stl")
[14]:
with species_attributes():
    A | B | C | {"radius": 0.005, "D": 1.0}

with reaction_rules():
    A + B == C | (12.0, 60.0)

m = get_model()
[15]:
edge_lengths = Real3(10, 10, 2)
w = f.polygon("plane10x10.stl", STLFormat.Ascii).world(edge_lengths)
[16]:
w.bind_to(m)
[17]:
w.add_molecules(Species('A'), 1000)
w.add_molecules(Species('B'), 1000)
[18]:
s = f.simulator(w, m)
obs = FixedIntervalNumberObserver(0.001)
s.run(0.2, obs)
[19]:
show(obs)
[28]:
plotting.plot_world(w, stl=["plane10x10.stl"], max_count=50)
[ ]: