Exemple #1
0
Description: 
2D diffusion on a real 2D surface
- initial release on a patch by either density or Boolean intersection of e.g. a sphere with a plane

"""

import pymcell as pm

# Make worlds:
world = pm.make_world()

# Add objects:
box = pm.make_object(name='Box', type='CUBE')
# could also write: faces = ['BOTTOM']
surface = pm.redefine_object(name='Surface',
                             type='SURFACE',
                             objects=[box],
                             faces=[[0, 1, 2], [0, 2, 3]])
world.add_object(box, surface)

# Add species:
mol_a = pm.make_species(name='a', type='SURFACE', scale_factor=.5)
world.add_species(mol_a)

# Add release patterns:
rel_a = pm.make_release_pattern(species_list=[mol_a], release_region=surface)
world.add_release_pattern(rel_a)

# Run simulations:
sim_1 = pm.make_simulation()  # using default iteration and time_step
world.run_simulation(sim_1)
# Make worlds:
world = pm.make_world()

# Add objects:
box = pm.make_object(name='Box', type='CUBE')  # default size and position
world.add_object(box)

# Add species:
mol_a = pm.make_species(name='a')  # red, Sphere_1, 1e-6, and VOLUME by default
mol_b = pm.make_species(name='b', color=[0, 0, 1])  # blue
mol_c = pm.make_species(name='c', color=[0, 1, 0])  # green
world.add_species(mol_a, mol_b, mol_c)

# Add release patterns:
rel_a_b = pm.make_release_pattern(species_list=[mol_a, mol_b],
                                  release_region=box)
world.add_release_pattern(rel_a_b)

# Add reactions:
react_1 = pm.make_reaction(name='React_1',
                           reaction='a -> NULL')  # 1e3 forward_rate by default
react_2 = pm.make_reaction(name='React_2', reaction='a -> b', forward_rate=1e4)
react_3 = pm.make_reaction(name='React_3',
                           reaction='a + b -> c',
                           forward_rate=5e3)  # isn't this redundant?
react_4 = pm.make_reaction(name='React_4',
                           reaction='a + b <-> c',
                           forward_rate=5e3,
                           backward_rate=1e8)
world.add_reaction(react_1, react_2, react_3, react_4)
# Add release patterns:
"""
Defaults:
    name = 'rel_1' # then rel_2, ...
    boundary = release_region

Other Parameters:
    release_region
    species_list = []

"""
# Example_1:
# Note that you can include multiple species to the release patterns, but all those species will then have all the same release parameters (quantity, probability, etc.)
rel_a = pm.make_release_pattern(species_list=[mol_a],
                                location=[0, 0, 0],
                                shape='SPHERICAL',
                                probablity=1,
                                quantity=1000)
world.add_release_pattern(rel_a)

#-----------------------------------#
# Add reactions:
"""
Default Parameters:
    name = 'react_1' # then react_2, ...
    forward_rate = 1e6
    rate = forward_rate
    backward_rate = 1e6
    
Other Parameters:
    reaction 
"""

import pymcell as pm

# Make worlds:
world = pm.make_world()

# Add objects:
x_len = 1
y_len = 1
z_len = 1
dynmc_box = pm.make_object(name = 'Dynamic_box', type = 'CUBE', edge_dimensions = [x_len,y_len,z_len]) # default position
world.add_object(dynmc_box)

# Add species:
diff_const = 1e-6
mol_a = pm.make_species(name = 'a') # red, Sphere_1, 1e-6, and VOLUME by default
world.add_species(mol_a)

# Add release patterns:
rel_a = pm.make_release_pattern(species_list = [mol_a], release_region = dynmc_box)
world.add_release_pattern(rel_a)

# Run simulations:
iters = 500
sim_1 = pm.make_simulation(iterations = iters, time_step = 1e-5)
for i in range(0,iters):
    world.run_simulation_step(simulations = [sim_1], step_number = i) # step_duration = sim_1.time_step by default 
    # "name" is used to ID which object we're changing, then all "new_" parameters update the previous version
    world.modify_object(name = 'Dynamic_box', new_edge_dimensions = [1,1,1.0 + i/250]) # z dim growing slowly.
     [ 1, 4, 5 ],
     [ 2, 4, 0 ],
     [ 7, 1, 5 ],
     [ 3, 2, 0 ],
     [ 7, 6, 2 ],
     [ 5, 4, 6 ],
     [ 1, 0, 4 ],
     [ 2, 6, 4 ],
     [ 7, 3, 1 ] ]
"""
funky_shape = pm.make_object(name='Polyhedron',
                             type='POLYHEDRON',
                             vertices=verts_list,
                             faces=faces_list)
world.add_object(funky_shape)

# Add species:
mol_a = pm.make_species(name='a')  # red, Sphere_1, 1e-6, and VOLUME by default
world.add_species(mol_a)

# Add release patterns:
rel_a = pm.make_release_pattern(species_list=[mol_a],
                                release_region=funky_shape)
world.add_release_pattern(rel_a)

# Add reactions:

# Run simulations:
sim_1 = pm.make_simulation(
    time_step=1e-5)  # using default iteration and custom time_step
world.run_simulation(sim_1)
Exemple #6
0
world = pm.make_world()

# Add objects:
box = pm.make_object(name='Box', type='CUBE')  # default size and position
# adding partial box surface object for "# Add release patterns:" section:
# box_surfaces = pm.make_object(name = 'Surfaces', type = 'SURFACE', objects = [box], faces = [[0,1,2],[0,2,3],[4,5,6],[4,6,7]])
world.add_object(box)

# Add species:
mol_a = pm.make_species(name='a')  # red, Sphere_1, 1e-6, and VOLUME by default
mol_b = pm.make_species(name='b', color=[0, 0, 1], type='SURFACE')  # blue
mol_c = pm.make_species(name='c', color=[0, 1, 0], type='SURFACE')  # green
world.add_species(mol_a, mol_b, mol_c)

# Add release patterns:
rel_a = pm.make_release_pattern(species_list=[mol_a], release_region=box)
# since mol_b is a surface molecule, I shouldn't have to specify that it only exists on the box surfaces.
rel_b = pm.make_release_pattern(species_list=[mol_b],
                                quantity=200,
                                release_region=box)
# Alternative: if you only wanted mol_b on some of the box surfaces, then you must specify further:
# rel_b_alt = pm.make_release_pattern(species = mol_b, quantity = 200, release_region = box_surfaces)
world.add_release_pattern(rel_a, rel_b)

# Add reactions:
react_1 = pm.make_reaction(name='React_1', reaction='a + b -> c')
world.add_reaction(react_1)

# Run simulations:
sim_1 = pm.make_simulation()  # using default iteration and time_step
world.run_simulation(sim_1)
Exemple #7
0
# In make_object(), there are many input parameters, and if you don't include the necessary \
# parameters for the given object type, you'll get default values and perhaps a notification.
cylinder = pm.make_object(name='Cylinder',
                          type='CYLINDER',
                          center=[0, 0, 0],
                          radius=1,
                          normal_vector=[1, 0, 0],
                          extrude_length=20)
plane = pm.make_object(name='Plane',
                       type='PLANE',
                       center=[0, 0, 0],
                       normal_vector=[1, 0, 0])
world.add_object(cylinder, plane)

# Add species:
mol_a = pm.make_species(name='a', scale_factor=2)
world.add_species(mol_a)

# Add release patterns:
rel_a = pm.make_release_pattern(species_list=[mol_a],
                                release_region=plane,
                                boundary=cylinder)
world.add_release_pattern(rel_a)

# Add reactions:
react_1 = pm.make_reaction(name='React_1', reaction='a -> NULL')
world.add_reaction(react_1)

# Run simulations:
sim_1 = pm.make_simulation()  # using default iteration and time_step
world.run_simulation(sim_1)