Ejemplo n.º 1
0
def test_rectangles():
    """Tests geometric shape by converting them to quivalent smoldyn text
    lines.

    >>> test_rectangles()
    panel PanelShape.rect +x 0 10 1 10 20 A
    panel PanelShape.tri  0 0 0 1 1 1 1 3 -10 t1
    panel PanelShape.sph  0 -10 0 3 10 10 s1
    panel PanelShape.cyl  20 30 70 20 50 70 4 20 20 cyl1
    panel PanelShape.disk  20 20 20 10 10 20 20 d1
    """
    r1 = S.Rectangle((0, 10, 1), dimensions=(10, 20), axis="+x", name="A")
    print(r1.toText())
    tr = S.Triangle(vertices=[[0, 0, 0], [1, 1, 1], [1, 3, -10]], name="t1")
    print(tr.toText())
    sph = S.Sphere(center=[0, -10, 0],
                   radius=3,
                   slices=10,
                   stacks=10,
                   name="s1")
    print(sph.toText())
    cyl = S.Cylinder(start=[20, 30, 70],
                     end=[20, 50, 70],
                     radius=4,
                     slices=20,
                     stacks=20,
                     name="cyl1")
    print(cyl.toText())
    disk = S.Disk(center=[20, 20, 20],
                  radius=10,
                  vector=[10, 20, 20],
                  name="d1")
    print(disk.toText())
Ejemplo n.º 2
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
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
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])
sides.setStyle('back', color=[0, 0, 0.5])
sides.setStyle('both', thickness=1)

## Both styles are equivalent.
Ejemplo n.º 5
0
__date__   = "2020-06-30"


import smoldyn as S

b = S.Boundaries(low=[0,0,0], high=[100,100,100])
S.setSeed(0)

spRed = S.Species('red', color='red', difc=3, display_size=3)
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])
Ejemplo n.º 6
0
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)
s.addReaction("decay", subs=[trans], prds=[], rate=math.log(2) / 20e-3)

# BOUTON
path = s.addPath2D((1000, 0), (550, 1000), (450, 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")

# SV stick to bottom of the bouton.
bottom_.setRate(sv, "fsoln", "front", rate=100, revrate=0)
# but it reflect neurotranmitter
bottom_.setAction('back', trans, "reflect")

# They also merge to the surface, this value is dependant on the membrane
# potential. See connect
bottom_.setRate(sv, "front", "bsoln", rate=100, new_species=svFused)

# Open vesicle turns into 1000 to 2000 or neurotransmitters. Note that rate of
# this reaction is updated below. We still need to add a non-zero value of
# rate.
Ejemplo n.º 7
0
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])
# sim.addMolecules(spRed, 20, highpos=[10,50,50])

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

# Add Surfaces
r1 = smoldyn.Rectangle(corner=[100, 0, 0], dimensions=[100, 100], axis="-x")
r2 = smoldyn.Rectangle(corner=[0, 0, 0], dimensions=[100, 100], axis="+y")
r3 = smoldyn.Rectangle(corner=[0, 100, 0], dimensions=[100, 100], axis="-y")
r4 = smoldyn.Rectangle(corner=[0, 0, 0], dimensions=[100, 100], axis="+z")
r5 = smoldyn.Rectangle(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 = smoldyn.Rectangle(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])
Ejemplo n.º 8
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")