def test_prd_pacement():
    sim = S.Simulation(low=[-10, -10, -10], high=[10, 10, 10], quit_at_end=1)
    sim.setRandomSeed(10)
    blue = sim.addSpecies(name="blue", color="blue", difc=1, display_size=0.3)
    red = sim.addSpecies(name="red", color="red", difc=0, display_size=0.3)
    sim.addMolecules(blue, number=100, lowpos=[-5, -5, -5], highpos=[5, 5, 5])
    sim.addMolecules(red, number=1, pos=[0, 0, 0])

    s1 = sim.addSurface(
        "membrane",
        panels=[
            sim.addSphere(center=[0, 0, 0], radius=10, slices=10, stacks=10)
        ],
    )
    s1.setStyle("both", drawmode="edge", color="green")
    s1.setAction(face="both", species=[blue, red], action="reflect")

    stick = sim.addReaction(name="stick",
                            subs=[blue, red],
                            prds=[red, red],
                            rate=20)
    stick.productPlacement(method="bounce", param=0.6)
    sim.addOutputData("data")
    sim.addCommand("molcount data", "E")
    # sim.setGraphics('opengl_good', 1)
    sim.run(stop=100, dt=0.1)
    d = sim.getOutputData("data")
    d = np.array(d)
    assert (d[:, 1] + d[:, 2] == 101).all()

    y = d.std(axis=0)
    ym = d.mean(axis=0)
    assert np.allclose(ym, [50, 20.75524, 80.24475], atol=1e-3, rtol=1e-3), ym
    assert np.allclose(y, [28.89636655, 20.5, 20.5], atol=1e-1, rtol=1e-1), y
    print(d)
def test_data():
    s = smoldyn.Simulation(low=[0, 0, 0], high=[100, 100, 100])
    s.seed = 100

    R = s.addSpecies("R", difc=1, color="red")
    B = s.addSpecies("B", difc=1, color="blue")

    s.addReaction("r1", subs=[R], prds=[], rate=0.1)

    R.addToSolution(400)
    B.addToSolution(1, pos=[50, 50, 50])
    s.addOutputData("mydata")
    s.addCommand("molcount mydata", "E")

    # s.setGraphics( "opengl" )
    s.run(stop=10, dt=0.01)
    print(s.stop, s.dt)
    data = s.getOutputData("mydata", 0)
    assert len(data) == 1001, len(data)
    assert len(data[0]) == 3, len(data[0])
    assert data[0] == [0.0, 400.0, 1.0], data[0]
    assert is_close(data[-1], [10.0, 142.0, 1.0]), data[-1]
    for row in data:
        assert row
        print(row)
def test_connect():
    global a, avals
    s = smoldyn.Simulation(low=(0, 0), high=(10, 10))
    a = s.addSpecies("a", color="black", difc=0.1)
    s.connect(new_dif, update_difc, step=10, args=[1, 1])
    s.run(100, dt=1)
    for a, b in zip(avals[1:], expected_a[1:]):
        print("test_connect", a, b)
        assert math.isclose(a[1], b[1], rel_tol=1e-6,
                            abs_tol=1e-6), (a[1], b[1])
def test_connect_2():
    global spb, bvals
    s1 = smoldyn.Simulation(low=(0, 0), high=(10, 10))
    spb = s1.addSpecies("b", color="blue", difc=1)
    s1.connect(new_dif_2, "spb.difc", step=1, args=[1, 1])
    s1.run(stop=100, dt=10)
    assert len(bvals) == len(expected_b)
    for _x, _y in zip(bvals, expected_b):
        print("test_connect_2", _x, _y)
        assert tuple_isclose(_x, _y), (_x, _y)
def test_connect_1():
    global spa, avals
    s = smoldyn.Simulation(low=(0, 0), high=(10, 10))
    spa = s.addSpecies("a", color="black", difc=0.1)
    s.connect(new_dif_1, "spa.difc", step=10, args=[1, 1])
    s.run(200, dt=1)
    assert len(avals) == len(expected_a)
    for _x, _y in zip(avals, expected_a):
        print("test_connect_1", _x, _y)
        assert tuple_isclose(_x, _y), (_x, _y)
Exemple #6
0
def test_getters():
    s = smoldyn.Simulation(low=[0, 0], high=[100, 100], types="r")
    A = s.addSpecies("A",
                     color={"all": "red"},
                     difc={"all": 1},
                     display_size=dict(all=1))
    B = s.addSpecies("B",
                     color={"all": "green"},
                     difc={"all": 1},
                     display_size=dict(all=1))
    C = s.addSpecies("C",
                     color={"all": "blue"},
                     difc={"all": 1},
                     display_size=dict(all=1))

    p1 = smoldyn.Rectangle(corner=(0, 0), dimensions=[100], axis="+x")
    p2 = smoldyn.Rectangle(corner=(100, 0), dimensions=[100], axis="-x")
    p3 = smoldyn.Rectangle(corner=(0, 0), dimensions=[100], axis="+y")
    p4 = smoldyn.Rectangle(corner=(0, 100), dimensions=[100], axis="-y")
    walls = s.addSurface("walls", panels=[p1, p2, p3, p4])
    walls.setAction("both", [A, B, C], "reflect")

    r1 = smoldyn.Rectangle(corner=[49, 30],
                           dimensions=[20],
                           axis="+x",
                           name="r1")
    t1 = smoldyn.Triangle(vertices=[[49, 50], [29, 70]], name="t1")
    left = s.addSurface(name="left", panels=[r1, t1])

    r1.neighbor = t1
    t1.neighbor = r1
    left.setAction("both", [A, B, C], "reflect")
    left.addMolecules((A, "up"), 20)

    r1 = smoldyn.Rectangle(corner=[50, 30],
                           dimensions=[20],
                           axis="+x",
                           name="r1")
    t1 = smoldyn.Triangle(vertices=[[50, 30], [70, 10]], name="t1")
    right = s.addSurface(name="right", panels=[r1, t1])
    r1.neighbor = t1
    t1.neighbor = r1
    right.setAction("both", [A, B, C], "reflect")
    right.addMolecules((B, "up"), 20)

    rxn1 = s.addReaction(
        name="rxn1",
        subs=[(A, "up"), (B, "up")],
        prds=[(A, "up"), (C, "bsoln")],
        binding_radius=2,
    )
    rxn1.setIntersurface([1, 1])

    s.addGraphics("opengl_good")
    s = s.run(1000, dt=0.1)
Exemple #7
0
def build_model():
    """
    Size of bouton: 1 cubic µm
    diameter of Synaptic Vesicle (SV): 40 nm
    Diff of SV: 0.024 um^2/s (2400 nm^2/s)
    1px = 1nm throughout.
    """
    global r1_, bouton_
    s = smoldyn.Simulation(low=[-500, -500], high=[1500, 1500])

    # a molecule that self-generate
    sv = s.addSpecies("SV",
                      difc=dict(all=2400, front=10),
                      color="blue",
                      display_size=10)
    sv.addToSolution(100, lowpos=(0, 0), highpos=(1000, 1000))
    s.addReaction("svgen", [sv], [sv, sv], rate=1e-6)
    svFused = s.addSpecies("VSOpen", color="blue", display_size=10)

    # intermediate speficies with a lifetime.
    B = s.addSpecies("B", color="red", difc=10000, display_size=2)
    decay = s.addReaction("decay", subs=[B], prds=[], rate=math.log(2) / 20e-3)

    # A very non-interesting surface.
    path = s.addPath2D((1000, 0), (1000, 1000), (0, 1000), (0, 0))
    bouton_ = s.addSurface("bouton", panels=path.panels)
    bouton_.setStyle("both", color="blue")

    # try to add all actions.
    bouton_.setAction("both", [sv], "reflect")
    bouton_.setAction("both", [sv], "trans")
    bouton_.setAction("back", [sv], "absorb")
    bouton_.setAction("back", [sv], "jump")
    bouton_.setAction("back", [sv], "port")

    # NOTE: action 'mult', 'no' and 'none' causes error here.

    # this is the bottom surface of bouton. This is sticky for synaptic
    # vesciles
    rect1 = smoldyn.Rectangle(corner=(0, 0), dimensions=[1000], axis="+y")
    bottom = s.addSurface("boutonBottom", panels=[rect1])
    bottom.setStyle("both", color="red")
    bottom.setAction("back", B, "reflect")
    bottom.setAction("back", B, "trans")
    bottom.setAction("back", B, "absorb")
    bottom.setAction("back", B, "jump")
    bottom.setAction("back", B, "port")

    return s
    def __init__(self, parameters=None):
        super().__init__(parameters)

        self.dt = self.parameters['dt']

        # initialize the simulation
        if self.parameters['file']:
            self.simulation = sm.Simulation.fromFile(self.parameters['file'], "q")
        else:
            self.simulation = sm.Simulation(
                low=self.parameters['low'],
                high=self.parameters['high'],
                types=self.parameters['boundary'],
                setFlags="q"
            )

        # set output type
        self.simulation.addOutputData('counts')
        self.simulation.addCommand(cmd='molcount counts', cmd_type='E')

        # get the species names
        species_count = self.simulation.count()['species']
        self.species = []
        for index in range(species_count):
            species_name = self.simulation.getSpeciesName(index)
            self.species.append(species_name)

        # make the species
        species = {}
        for name, config in self.parameters['species'].items():
            species[name] = self.simulation.addSpecies(name, **config)
            self.species.append(name)

        # make the reactions
        for rxn_name, config in self.parameters['reactions'].items():
            substrate_names = config.pop('subs')
            product_names = config.pop('prds')
            substrates = [species[name] for name in substrate_names]
            products = [species[name] for name in product_names]
            self.simulation.addReaction(
                rxn_name,
                subs=substrates,
                prds=products,
                **config)

        if self.parameters['animate']:
            self.simulation.addGraphics('opengl')
def test_data_output():
    s = sm.Simulation(low=[0, 0, 0], high=[100, 100, 100], boundary_type="ppp")

    s.addBox(size=10)

    # declaration of species A, B, and C with attributes.
    a = s.addSpecies("A", state="soln", difc=1, color="red", mol_list="Alist")
    b = s.addSpecies("B",
                     state="soln",
                     color="green",
                     difc=1,
                     mol_list="Blist")
    c = s.addSpecies("C",
                     state="soln",
                     difc=1.0,
                     color="blue",
                     mol_list="Clist")
    s.addMolecules(a, 1000)
    s.addMolecules(b, 1000)

    s.addBidirectionalReaction("r1", subs=[c], prds=(a, b), kf=0.1, kb=100)

    # FIXME: Prints only upto 10 (2 iterations rather than 100)
    s.setOutputFile("box.dat")
    # s.setGraphics("opengl")
    c = s.addCommand("molcount box.dat", "i", on=0, off=100, step=10)
    s.run(100, dt=0.1, overwrite=True)
    print("Simulation over")

    # Now read the box.dat and verify the results.
    # On OSX, it may not work. Homebrew python is a shell script which chdir to
    # script dir before running it. I.e., box.dat would not be found easily.
    if not os.path.exists('box.dat'):
        quit(0)
    data = np.loadtxt("box.dat")
    assert data.shape == (11, 4), data.shape
    expected = [50.036, 590.727, 590.727, 409.272]
    print(data.mean(axis=0), expected)
    assert np.isclose(data.mean(axis=0), expected, atol=1e-1,
                      rtol=1e-1).all(), data.mean(axis=0)
    quit(0)
Exemple #10
0
def sim2():
    sim = smoldyn.Simulation(low=[0, 0, 0], high=[100, 100, 100])

    # Set it after Simulation object is created.
    sim.seed = 0

    spRed = sim.addSpecies("red", color="red", difc=3, display_size=3)
    spRed.addToSolution(20, highpos=[10, 50, 50])

    spGreen = sim.addSpecies("green", color="green", difc=1, display_size=3)
    sim.addMolecules(spGreen, 20, highpos=[10, 50, 50])

    # Add Surfaces
    r1 = sim.addRectangle(corner=[100, 0, 0], dimensions=[100, 100], axis="-x")
    r2 = sim.addRectangle(corner=[0, 0, 0], dimensions=[100, 100], axis="+y")
    r3 = sim.addRectangle(corner=[0, 100, 0], dimensions=[100, 100], axis="-y")
    r4 = sim.addRectangle(corner=[0, 0, 0], dimensions=[100, 100], axis="+z")
    r5 = sim.addRectangle(corner=[0, 0, 100], dimensions=[100, 100], axis="-z")

    s1 = sim.addSurface("walls", panels=[r1, r2, r3, r4, r5])
    # s1.both.setStyle(drawmode='edge')
    s1.setStyle("both", drawmode="edge")
    s1.setAction("both", [spRed, spGreen], "reflect")

    # portsurf
    rr = sim.addRectangle(corner=[0, 0, 0], dimensions=[100, 100], axis="+x")
    portSurf = sim.addSurface("portsurf", panels=[rr])
    portSurf.setStyle("front", drawmode="face", color="gray")
    portSurf.setStyle("back", drawmode="face", color=[0.2, 0, 0, 1])
    portSurf.setAction("front", [spRed, spGreen], "port")
    portSurf.setAction("back", [spRed, spGreen], "reflect")

    # Ports
    sim.addPort(name="testport", surface=portSurf, panel="front")

    #  sim.setGraphics("opengl", 20)
    sim.addOutputData("data2")
    sim.addCommand("molcount data2", 'E')
    return sim
def test_simptr_simobj():
    s1 = smoldyn.Simulation([0, 0], [10, 10])
    assert s1
    assert s1.getSimPtr()
    assert s1.simptr == s1.getSimPtr()
    assert s1.simptr.dt == 0.0, "dt should be initialized to 0"

    modelfile = sdir / "min.txt"
    s2 = smoldyn.Simulation.fromFile(modelfile, "")  # type: Simulation

    assert s2
    assert s2.getSimPtr() and s2.getSimPtr() == s2.simptr

    assert s2.start == 0.0
    assert s2.stop == 500
    assert s2.dt == 0.002
    s2.addOutputData('moments')
    s2.addCommand("molmoments MinD_ATP(front) moments", "N", step=10)
    s2.run(stop=100, dt=1)
    data = s2.getOutputData("moments")
    assert len(data) == 11, len(data)
    for row in data:
        print(row)
Exemple #12
0
def test_getter():
    s = smoldyn.Simulation(low=[0, 0],
                           high=[10, 10],
                           types="p",
                           output_files=["bistableout.txt"])

    # species X A B A2 B2
    X = s.addSpecies("X", difc=0, color="green", display_size=3)
    A = s.addSpecies("A", difc=1, color="red", display_size=3)
    B = s.addSpecies("B", difc=1, color="blue", display_size=3)
    A2 = s.addSpecies("A2", difc=1, color="red", display_size=5)
    B2 = s.addSpecies("B2", difc=1, color="blue", display_size=5)

    # mol 1 X 5 5
    X.addToSolution(1, pos=[5, 5])

    express = s.addReaction("express", subs=[X], prds=[X, A, B], rate=1)
    Adimer = s.addBidirectionalReaction("Adimer",
                                        subs=[A, A],
                                        prds=[A2],
                                        kf=1,
                                        kb=1)
    Bdimer = s.addBidirectionalReaction("Bdimer",
                                        subs=[B, B],
                                        prds=[B2],
                                        kf=1,
                                        kb=1)
    AxB = s.addReaction("AxB", subs=[A2, B], prds=[A2], rate=1)
    BxA = s.addReaction("BxA", subs=[B2, A], prds=[B2], rate=1)
    Adegrade = s.addReaction("Adegrade", subs=[A], prds=[], rate=0.01)
    Bdegrade = s.addReaction("Bdegrade", subs=[B], prds=[], rate=0.01)

    s.addCommand("molcountheader bistableout.txt", cmd_type="B")
    s.addCommand("molcount bistableout.txt", cmd_type="N", step=10)
    s.setGraphics("opengl")
    d = s.count()
    print(d)
Exemple #13
0
def sim1():
    s = smoldyn.Simulation(low=[0, 0], high=[100, 100])
    red = s.addSpecies("red",
                       color="red",
                       difc=dict(all=3, front=0),
                       display_size=5)
    yellow = s.addSpecies("yellow",
                          color="black",
                          difc=dict(soln=3, back=1),
                          display_size=5)
    blue = s.addSpecies("blue", color="blue", difc=3, display_size=5)

    red.addToSolution(100)
    yellow.addToSolution(50, pos=(50, 50))
    blue.addToSolution(50, pos=(20, 20))

    # Construct a closed path in 2D.
    p = s.addPath2D((0, 0), (100, 0), (100, 100), (0, 100), closed=True)
    walls = s.addSurface("walls", panels=p.panels)
    walls.setAction("both", [red, yellow, blue], "reflect")
    walls.setStyle("both", color="black")

    sph = s.addSphere(center=(50, 50), radius=20, slices=20)
    surf = s.addSurface("stick", panels=[sph])
    surf.setRate(red, "fsoln", "front", rate=10, revrate=1)
    surf.setRate(yellow, "bsoln", "back", rate=10, revrate=1)
    surf.setRate(blue, "fsoln", "bsoln", rate=10, revrate=1)
    surf.setStyle("front", color=(1, 0.7, 0))
    surf.setStyle("back", color=(0.6, 0, 0.6))
    surf.addMolecules((red, "front"), 100)

    # FIXME: Concurrent simulation doesn't work when graphics is enabled.
    # s.setGraphics("opengl")
    s.addCommand("killmolinsphere red all", "b")
    s.addOutputData("data1")
    s.addCommand("molcount data1", 'E')
    return s
Exemple #14
0
import smoldyn
import smoldyn._smoldyn as S
import numpy
import matplotlib.pyplot as plt

s = smoldyn.Simulation(low=[-10, -10, -10], high=[10, 10, 10])
target = s.addSpecies("target",
                      color=dict(all="red"),
                      display_size={"all": 10})
protein = s.addSpecies("protein",
                       color="black",
                       display_size=3,
                       difc=dict(all=1))
counter = s.addSpecies("counter", color="white", display_size=0)

sph1 = smoldyn.Sphere(center=[0, 0, 0], radius=10, slices=20, stacks=20)
membrane = s.addSurface(name="membrane", panels=[sph1])
membrane.setStyle("both", color="blue", drawmode="edge")
#membrane.setRate(protein, "bsoln", "back", rate=1, revrate=0.1)

r1 = s.addReaction("r1",
                   subs=[(target, "up"), (protein, "bsoln")],
                   prds=[(target, "up"), counter],
                   rate=6)
r2 = s.addReaction("r2",
                   subs=[(target, "up"), (protein, "back")],
                   prds=[(target, "up"), counter],
                   rate=12)

#s.setGraphics("opengl", frame_thickness=0, text_display=["time",protein,(protein,"back"), counter])
s.addOutputData("output")
Exemple #15
0
# Demonstration of absorbing, periodic, and reflective boundaries
import smoldyn
import smoldyn._smoldyn as S

# dim 2
# low_wall x 0 a
# high_wall x 100 r
# boundaries y 0 100 p
s = smoldyn.Simulation(low=[0, 0], high=[100, 100], types=["ar", "p"])

# species red green
# difc red 3
# difc green 3
# color red red
# color green green
red = s.addSpecies("red", color="red", difc=3)
green = s.addSpecies("green", color="green", difc=3)

S.Simulation.readConfigString(s, "drift", "red 0.2 0")
S.Simulation.setFlags(s, "q")

# mol 300 red u u
# mol 30 green 50 5
red.addToSolution(300)
green.addToSolution(30, pos=[50, 5])

S.Simulation.runCommand(s, "molcount stdout")

# time_start 0
# time_stop 200
# time_step 0.01
Exemple #16
0
import smoldyn

s = smoldyn.Simulation(low=[-1000, -1000, -10000],
                       high=[1000, 1000, 10000],
                       output_files=["cylinder.txt"])

d1 = s.addDisk(name="d1",
               center=[50, 25, 8500],
               radius=850,
               slices=12,
               vector=[0, 0, -1])
test = s.addSurface("test", panels=[d1])
Exemple #17
0
# Simulation file for Lotka-Voltera reaction
import smoldyn
from pathlib import Path

scriptdir = Path(__file__).parent

s = smoldyn.Simulation([-100, -100, -10], [100, 100, 10], boundary_type="p")
rabbit = s.addSpecies("rabbit", color="red", display_size=2, mol_list="rlist", difc=100)
fox = s.addSpecies("fox", color="blue", display_size=3, mol_list="flist", difc=100)
s.addMoleculePerBox(1)

r1 = s.addReaction("r1", subs=[rabbit], prds=[rabbit, rabbit], rate=10)
r2 = s.addReaction("r2", subs=[rabbit, fox], prds=[fox, fox], rate=8000)
r3 = s.addReaction("r3", subs=[fox], prds=[], rate=10)

rabbit.addToSolution(1000)
fox.addToSolution(1000)

#s.setTiff("OpenGl")
#s.setGraphics("opengl", iter=5, text_display=["time", "rabbit", "fox"])

# NOTE: Can not set the absolute path. Its always relative to the current
# working directory.
datafile = "lotvoltout.txt"
s.setOutputFile(datafile)
s.addCommand(f"molcount {datafile}", "i", on=0, off=20, step=0.01)
s.addCommand("molcount stdout", "i", on=0, off=20, step=0.1)

s = s.run(5, dt=0.001, overwrite=True)

# make sure that datafile is generated.
Exemple #18
0
# Bistable reaction system
__author__ = "Dilawar Singh"
__email__ = "*****@*****.**"

import smoldyn

s = smoldyn.Simulation(low=[0, 0],
                       high=[10, 10],
                       types="p",
                       output_files=["bistableout.txt"])

# species X A B A2 B2
X = s.addSpecies("X", difc=0, color="green", display_size=3)
A = s.addSpecies("A", difc=1, color="red", display_size=3)
B = s.addSpecies("B", difc=1, color="blue", display_size=3)
A2 = s.addSpecies("A2", difc=1, color="red", display_size=5)
B2 = s.addSpecies("B2", difc=1, color="blue", display_size=5)

# mol 1 X 5 5
X.addToSolution(1, pos=[5, 5])

express = s.addReaction("express", subs=[X], prds=[X, A, B], rate=1)
Adimer = s.addBidirectionalReaction("Adimer",
                                    subs=[A, A],
                                    prds=[A2],
                                    kf=1,
                                    kb=1)
Bdimer = s.addBidirectionalReaction("Bdimer",
                                    subs=[B, B],
                                    prds=[B2],
                                    kf=1,
Exemple #19
0
def build_model_smoldyn():
    """
    Size of bouton: 1 cubic µm
    diameter of Synaptic Vesicle (SV): 40 nm
    Diff of SV: 0.024 um^2/s (2400 nm^2/s)
    1px = 1nm throughout.
    """
    global r1_, bouton_
    s = smoldyn.Simulation(low=[-500, -500], high=[1500, 1500])
    sv = s.addSpecies("SV",
                      difc=dict(all=2400, front=10),
                      color="blue",
                      display_size=10)
    sv.addToSolution(100, lowpos=(0, 0), highpos=(1000, 1000))

    # add a reaction with generates the sv at a fixed rate. Its better to
    # split so location of the new sv is inside the box.
    s.addReaction("svgen", [sv], [sv, sv], rate=1e-6)

    # fused vesicle.
    svFused = s.addSpecies("VSOpen", color="blue", display_size=10)

    # neutotransmitter. The concentration has the half-life of 2ms (PMID:
    # 19844813), that is, rate is 0.693/2e-3, k ~ 346 per sec
    trans = s.addSpecies("trans", color="red", difc=10000, display_size=2)
    decay = s.addReaction("decay",
                          subs=[trans],
                          prds=[],
                          rate=math.log(2) / 20e-3)

    # BOUTON
    path = s.addPath2D((1000, 0), (1000, 1000), (0, 1000), (0, 0))
    bouton_ = s.addSurface("bouton", panels=path.panels)
    bouton_.setStyle('both', color="blue")
    bouton_.setAction('both', [sv], "reflect")

    # this is the bottom surface of bouton. This is sticky for synaptic
    # vesciles
    rect1 = smoldyn.Rectangle(corner=(0, 0), dimensions=[1000], axis="+y")
    bottom = s.addSurface("boutonBottom", panels=[rect1])
    bottom.setStyle('both', color="red")
    bottom.setAction('back', trans,
                     "reflect")  # but it reflect neurotranmitter

    # SV stick to bottom of the bouton and also detach back with a smaller
    # rate.
    bottom.setRate(sv, "fsoln", "front", rate=10, revrate=0.001)

    # They move to outside of bouton, this value is dependant on the membrane
    # potential
    bottom.setRate(sv, "front", "bsoln", rate=10, new_species=svFused)

    # Open vesicle turns into 1000 to 2000 or neurotransmitters.
    r1_ = s.addReaction("open2trans",
                        subs=[svFused],
                        prds=[trans] * 200,
                        rate=100.0)
    s.connect(generate_spike, update_kf, step=20)

    s.addGraphics("opengl", iter=10, text_display="time")
    print('[INFO] Starting simulation ...')
    s.run(stop=20, dt=0.001)
    print("Done")
Exemple #20
0
def test_get_err():
    print('Testing test_get_err')
    s = smoldyn.Simulation(low=(0, 0), high=(1, 1))
    a = smoldyn.getError()
    print(a)
Exemple #21
0
# -*- coding: utf-8 -*-
# Dilawar Singh <*****@*****.**>, 2020-04-29
# Python implementation of box.txt

import smoldyn as sm

s = sm.Simulation(low=[0, 0, 0], high=[100, 100, 100], boundary_type="ppp")
s.addBox(size=10)

# declaration of species A, B, and C with attributes.
a = s.addSpecies("A", state="soln", difc=1, color="red", mol_list="Alist")
b = s.addSpecies("B", state="soln", color="green", difc=1, mol_list="Blist")
c = s.addSpecies("C", state="soln", difc=1.0, color="blue", mol_list="Clist")
s.addMolecules(a, 1000)
s.addMolecules(b, 1000)

s.addBidirectionalReaction("r1", subs=[c], prds=(a, b), kf=0.1, kb=100)

# FIXME: Prints only upto 10 (2 iterations rather than 100)
s.setOutputFile("box.dat", True)
c = s.addCommand("molcount box.dat", cmd_type="i", on=0, off=100, step=10)
s.run(100, dt=1, log_level=1)
Exemple #22
0
def test_newcursim():
    print("test_newcursim")
    s = smoldyn.Simulation(low=(0, 0), high=(1, 1))
    cs = s.simptr
    assert cs != None
    print(cs)
Exemple #23
0
# Zeroth order reactions
import smoldyn

s = smoldyn.Simulation(low=[0, 0, 0], high=(10, 10, 10), boundary_type="r")
red = s.addSpecies("red", difc=1, color=[1, 0, 0])
green = s.addSpecies("green", difc=1, color=[0, 1, 0])
blue = s.addSpecies("blue", difc=1, color=[0, 0, 1])
slow = s.addReaction("slow", [], [red], rate=0.001)
med = s.addReaction("med", [], [green], rate=0.01)
fast = s.addReaction("fast", [], [blue], rate=0.1)

s.setGraphics("opengl")
s.setOutputFile("zeroreactout.txt")
s.addCommand("molcount zeroreactout.txt", "e")
s = s.run(stop=10, dt=0.01, overwrite=True)
Exemple #24
0
# Periodic boundaries with surfaces

import smoldyn

s = smoldyn.Simulation(low=[0, 0], high=[100, 100])

A = s.addSpecies("A", difc=1, color="red")
B = s.addSpecies("B", difc=1, color="green")
C = s.addSpecies("C", difc=1, color="blue")

A.addToSolution(200, pos=[10, 50])
B.addToSolution(200, pos=[90, 50])

s1 = s.addSphere(center=[50, 50], radius=20, slices=50)
ball = s.addSurface("ball", panels=[s1])

ball.setAction('both', [A, B, C], "reflect")
ball.setStyle('both', color=[0, 0.5, 0], thickness=1)

r1 = smoldyn.Rectangle(corner=[0, 0], dimensions=[100], axis="+0", name="r1")
r2 = smoldyn.Rectangle(corner=[100, 0], dimensions=[100], axis="-0", name="r2")
r3 = smoldyn.Rectangle(corner=[0, 0], dimensions=[100], axis="+1", name="r3")
r4 = smoldyn.Rectangle(corner=[0, 100], dimensions=[100], axis="-1", name="r4")
sides = s.addSurface("sides", panels=[r1, r2, r3, r4])

# sides.front.setAction([A, B, C], "jump")
# sides.back.setAction([A, B, C], "reflect")
sides.setAction('front', [A, B, C], 'jump')
sides.setAction('back', [A, B, C], 'reflect')

sides.setStyle('front', color=[0.2, 0, 0])
Exemple #25
0
    global r1_, bouton_, bottom_
    kf = max(0.0, val) * 1e3 * 1e3
    r1_.setRate(kf)
    bottom_.setRate(sv, "fsoln", "front", rate=(10 + kf), revrate=0.0)
    c = min(kf / 300, 1)
    bouton_.setStyle('both', color=[c, c, c])


"""
Size of bouton: 1 cubic µm
diameter of Synaptic Vesicle (SV): 40 nm
Diff of SV: 0.024 µm^2/s (2400 nm^2/s)

1px = 1nm throughout.
"""
s = smoldyn.Simulation(low=[-500, -500], high=[1500, 1500])
sv = s.addSpecies(
    "SV",
    difc=dict(all=5000, front=100),
    color=dict(fsoln="blue", front="gray"),
    display_size=6,
)
sv.addToSolution(100, pos=(500, 500))

# fused vesicle.
svFused = s.addSpecies("VSOpen", color="red", display_size=10)
s.addReaction("prod", subs=[sv], prds=[sv, sv], rate=1e-2)

# neutotransmitter. The concentration has the half-life of 2ms (PMID:
# 19844813), that is, rate is 0.693/2e-3, k ~ 346 per sec
trans = s.addSpecies("trans", color="red", difc=10000, display_size=2)
Exemple #26
0
The model was published in Andrews (2012) Methods for Molecular Biology, 804:519.
It executes a Michaelis-Menten reaction within and on the surface of a 2D circle.
"""

__author__ = "Dilawar Singh"
__email__ = "*****@*****.**"

import smoldyn

# Model parameters
K_FWD = 0.001  # substrate-enzyme association reaction rate
K_BACK = 1  # complex dissociation reaction rate
K_PROD = 1  # complex reaction rate to product

# Simulation starts with declaring a Simulation object with the system boundaries.
s = smoldyn.Simulation(low=[-1, -1], high=[1, 1])

# Molecular species and their properties
# Species: S=substrate, E=enzyme, ES=complex, P=product
# Type `help(smoldyn.Species)` in Python console to see all parameters.
S = s.addSpecies("S",
                 difc=3,
                 color=dict(all="green"),
                 display_size=dict(all=0.02))
E = s.addSpecies("E", color=dict(all="darkred"), display_size=dict(all=0.03))
P = s.addSpecies("P",
                 difc=3,
                 color=dict(all="darkblue"),
                 display_size=dict(all=0.02))
ES = s.addSpecies("ES", color=dict(all="orange"), display_size=dict(all=0.03))
Exemple #27
0
spRed.addToSolution(20, highpos=[10,50,50])

spGreen = S.Species('green', color='green', difc=1, display_size=3)
spGreen.addToSolution(10)

# Add Surfaces
r1 = S.Rectangle(corner=[100,0,0], dimensions=[100,100], axis='-x')
r2 = S.Rectangle(corner=[0,0,0], dimensions=[100,100], axis='+y')
r3 = S.Rectangle(corner=[0,100,0], dimensions=[100,100], axis='-y')
r4 = S.Rectangle(corner=[0,0,0], dimensions=[100,100], axis='+z')
r5 = S.Rectangle(corner=[0,0,100], dimensions=[100,100], axis='-z')
s1 = S.Surface('walls', panels=[r1,r2,r3,r4,r5])
#s1.both.setStyle(drawmode='edge')
s1.setStyle('both', drawmode='edge')

s1.both.addAction('all', 'reflect')

# portsurf
rr = S.Rectangle(corner=[0,0,0], dimensions=[100,100], axis='+x')
portSurf = S.Surface('portsurf', panels=[rr])
portSurf.front.setStyle(drawmode='face', color='gray')
portSurf.back.setStyle(drawmode='face', color=[0.2,0,0,1])
portSurf.front.addAction('all', 'port')
portSurf.back.addAction('all', 'reflect')

# Ports
testport = S.Port('testport', surface=portSurf, panel='front')
s = S.Simulation(step=0.01, stop=100)
s.setGraphics('opengl', 20)
s.run()
Exemple #28
0
"""
2Dreact.txt in Python
"""
__author__ = "Dilawar Singh"
__email__ = "*****@*****.**"

import smoldyn

s = smoldyn.Simulation(
    low=[-5, -5, -5], high=[5, 5, 5], output_files=["2Dreactout.txt"]
)

red = s.addSpecies("red", difc=dict(all=0.1), color=dict(all="red"))
green = s.addSpecies("green", difc=dict(all=0.1), color=dict(all="green"))
blue = s.addSpecies("blue", difc=dict(all=0.1), color=dict(all="blue"))

h1 = s.addHemisphere(
    name="h1", center=[-3, 0, 0], radius=2, vector=[1, 0, 0], slices=10, stacks=5
)
h2 = s.addHemisphere(
    center=[3, 0, 0], radius=2, vector=[-1, 0, 0], slices=10, stacks=5, name="h2"
)
c1 = s.addCylinder(
    start=[-3, 0, 0], end=[3, 0, 0], radius=2, slices=10, stacks=5, name="c1"
)
ecoli = s.addSurface("ecoli", panels=[h1, h2, c1])
ecoli.setStyle("both", drawmode="edge", color="black")

# h1.neighbor = c1
# h2.neighbor = c1
# c1.neighbors = [h1, h2]
Exemple #29
0
__author__ = "Dilawar Singh"
__email__ = "*****@*****.**"

import smoldyn

s = smoldyn.Simulation(low=(0, 0, 0),
                       high=(100, 100, 100),
                       types=["r", "r", "r"])
red = s.addSpecies("red", difc=3, color="red")
s.addMolecules(red, 100)  # or, red.addToSolution(100)
s.addMolecules(red, 30,
               highpos=(20, 30,
                        20))  # red.addToSolution(30, highpos=[20, 30, 20])

green = s.addSpecies("green", difc=1, color="green")
s.addMolecules(green, 30)
s.setGraphics("opengl", 10)
s = s.run(100, 0.01, quit_at_end=True)
Exemple #30
0
__author__ = "Dilawar Singh"
__email__ = "*****@*****.**"

import smoldyn as S

S.setBoundaries(low=(0, 0, 0), high=(100, 100, 100), types=['r', 'r', 'r'])
red = S.Species('red', difc=3)
red.addToSolution(100)
red.addToSolution(30, highpos=[20, 30, 20])

green = S.Species('green', difc=1)
green.addToSolution(30)

s = S.Simulation(100, 0.01)
s.setGraphics('opengl', 10)
s.run()