def rxn_callback(rxn_info, model): assert rxn_info.type == m.ReactionType.VOLUME_SURFACE # we will be moving in the direction # of the wall's normal w = model.get_wall(rxn_info.geometry_object, rxn_info.wall_index) # simplified computtation of offset, valid only for this test, for # a correct implementation see pymcell4/2321_release_triggered_by_surf_rxn_multiple pos = rxn_info.pos3d + m.Vec3(-0.005, -0.005, -0.005) # it is also possible to move it in the direction of the unit normal #pos = rxn_info.pos3d + w.unit_normal * m.Vec3(-0.005, -0.005, -0.005) # release molecules rel_a = m.ReleaseSite( name = 'rel_c', complex = subsystem.c.inst(), shape = m.Shape.SPHERICAL, location = pos.to_list(), site_diameter = 0, number_to_release = 10, release_time = rxn_info.time ) model.release_molecules(rel_a)
def rxn_callback(rxn_info, model): assert rxn_info.type == m.ReactionType.VOLUME_SURFACE # we will be moving in the direction # of the wall's normal w = model.get_wall(rxn_info.geometry_object, rxn_info.wall_index) # MCell3 (reference model) mdl_mcell3/2310_release_triggered_by_surf_rxn_single # computes position like this: pos = rxn_info.pos3d + rotate_about_normal(w.unit_normal, m.Vec3(-0.005, -0.005, -0.005)) # it is also possible to move it in the direction of the unit normal #pos = rxn_info.pos3d + w.unit_normal * m.Vec3(-0.005, -0.005, -0.005) # release molecules rel_a = m.ReleaseSite(name='rel_c', complex=subsystem.c.inst(), shape=m.Shape.SPHERICAL, location=pos.to_list(), site_diameter=0, number_to_release=10, release_time=rxn_info.time) model.release_molecules(rel_a)
def rxn_callback(rxn_info, model): #print(rxn_info) # release molecules rel_a = m.ReleaseSite( name='rel_c', complex=subsystem.c.inst(), shape=m.Shape.SPHERICAL, # MCell3 uses the location as offset location=(rxn_info.pos3d + m.Vec3(0.005, 0, 0)).to_list(), site_diameter=0, number_to_release=10, release_time=rxn_info.time) model.release_molecules(rel_a)
# WARNING: This is an automatically generated file and will be overwritten # by CellBlender on the next model export. import mcell as m from parameters import * from subsystem import * from geometry import * # ---- instantiation ---- # ---- release sites ---- Release_of_Syk_ps_a_Y_l_Y_tSH2_pe_CP_at_CP = m.ReleaseSite( name='Release_of_Syk_ps_a_Y_l_Y_tSH2_pe_CP_at_CP', complex=m.Complex('Syk(a~Y,l~Y,tSH2)'), region=CP, number_to_release=20) # ---- surface classes assignment ---- # ---- compartments assignment ---- default_compartment.is_bngl_compartment = True EC.is_bngl_compartment = True CP.is_bngl_compartment = True CP.surface_compartment_name = 'PM' # ---- create instantiation object and add components ----
model = m.Model() # add geometry box = m.geometry_utils.create_box('box', 1) model.add_geometry_object(box) # load our BNGL file and set directory for BNGL observables model.load_bngl('model.bngl', './react_data/seed_' + str(SEED).zfill(5) + '/') # set initial count of molecules so that we won't get to copy nr 0 when removing them # (remove more than exists is ok - in that case all molecules of given species are removed, # but this would not give us the nice sinusiodal function) rel = m.ReleaseSite( name='rel_A_initial', complex=m.Complex('A'), region=box, number_to_release=1000, # and do each release each iteration release_time=0) model.add_release_site(rel) # define release pattern for i in range(ITERATIONS): rel = m.ReleaseSite( name='rel_A_' + str(i), complex=m.Complex('A'), region=box, # we would like the number of moleucles in the system to follow the sinus curve, # derivative of that is cos, number to release is truncated to an integer, may be negative number_to_release=100 * math.cos(i / 10), # and do each release each iteration
import mcell as m from parameters import * from subsystem import * from geometry import * # ---- instantiation ---- # ---- release sites ---- Tetrahedron_rel = m.ReleaseSite( name = 'Tetrahedron_rel', complex = sm.inst(orientation = m.Orientation.UP), region = Tetrahedron, number_to_release = 10 ) # ---- surface classes assignment ---- # ---- instantiation data ---- instantiation = m.Instantiation() instantiation.add_geometry_object(Tetrahedron) instantiation.add_release_site(Tetrahedron_rel)
# WARNING: This is an automatically generated file and will be overwritten # by CellBlender on the next model export. import os import shared import mcell as m from parameters import * from subsystem import * from geometry import * MODEL_PATH = os.path.dirname(os.path.abspath(__file__)) box1_sr1_rel = m.ReleaseSite(name='box1_sr1_rel', complex=sm.inst(), region=box1_sr1, number_to_release=4) box1_sr2_rel = m.ReleaseSite(name='box1_sr2_rel', complex=sm.inst(), region=box1_sr2, number_to_release=6) # TODO: release on difference, union, and intersection box2_rel = m.ReleaseSite(name='box2_rel', complex=sm.inst(), region=box2, number_to_release=8) # ---- create instantiation object and add components ----
import mcell as m # numerical attribute c = m.Color(red=1, green=0, blue=0, alpha=1) c2 = copy.copy(c) c2.red = 0.5 # check that the original object is correct assert c.red == 1 assert c2.red == 0.5 # object rs = m.ReleaseSite(name='test', complex=m.Complex('A'), shape=m.Shape.SPHERICAL, location=(1, 2, 3), number_to_release=1000) rs2 = copy.copy(rs) rs2.complex = m.Complex('B') assert rs.complex.to_bngl_str() == 'A' assert rs2.complex.to_bngl_str() == 'B' # vector ct = m.ComponentType('u', states=['0']) ct2 = copy.copy(ct) ct2.states = ['X', 'Y']
#!/usr/bin/env python3 import sys import os MCELL_PATH = os.environ.get('MCELL_PATH', '') if MCELL_PATH: sys.path.append(os.path.join(MCELL_PATH, 'lib')) else: print("Error: variable MCELL_PATH that is used to find the mcell library was not set.") sys.exit(1) import mcell as m model = m.Model() a = m.Species('a', diffusion_constant_3d = 1e-6) model.add_species(a) rs = m.ReleaseSite('rel_a', a, location = (0, 0, 0), number_to_release = 1) model.add_release_site(rs) model.initialize()
import mcell as m subsystem = m.Subsystem() a = m.Species( name = 'a', # this species will be called 'a' diffusion_constant_3d = 1e-6 # 'a' is a volume molecule (diffuses in 3d space) ) subsystem.add_species(a) instantiation = m.Instantiation() rel_a = m.ReleaseSite( # ReleaseSite defines molecule releases name = 'rel_a', complex = a, number_to_release = 10, # 10 location = (0, 0, 0) # all molecules will be released at origin ) instantiation.add_release_site(rel_a) model = m.Model() model.add_subsystem(subsystem) # include information on species model.add_instantiation(instantiation) # include information on molecule releases model.initialize() # initialize simulation state model.run_iterations(10) # simulate 10 iterations model.end_simulation() # final simulation step # does not check anything
model = m.Model() a = m.Species( name = 'a', diffusion_constant_3d = 9.99999999999999955e-07 ) # ---- create subsystem object and add components ---- model.add_species(a) rel_a = m.ReleaseSite( name = 'rel_a', complex = a.inst(), # shape = m.Shape.SPHERICAL, # - must work even without this specification location = (0, 0, 0), site_diameter = 0, number_to_release = 2 ) model.add_release_site(rel_a) sphere = m.geometry_utils.create_icosphere('sphere', 0.1, 3) model.add_geometry_object(sphere) viz_output = m.VizOutput( mode = m.VizMode.ASCII, output_files_prefix = './viz_data/seed_' + str(parameters.SEED).zfill(5) + '/Scene',
from geometry import * MODEL_PATH = os.path.dirname(os.path.abspath(__file__)) # ---- instantiation ---- # ---- release sites ---- # ---- surface classes assignment ---- Plane.surface_class = empty # ---- compartments assignment ---- vol1_rel = m.ReleaseSite( name = 'vol1_rel', complex = m.Complex('vol1'), region = Cube, number_to_release = 2000 ) # ---- create instantiation object and add components ---- instantiation = m.Instantiation() instantiation.add_geometry_object(Plane) instantiation.add_geometry_object(Cube) instantiation.add_release_site(vol1_rel) # load seed species information from bngl file instantiation.load_bngl_compartments_and_seed_species(os.path.join(MODEL_PATH, 'model.bngl'), None, shared.parameter_overrides)
import mcell as m from parameters import * from subsystem import * from geometry import * # ---- instantiation ---- # ---- release sites ---- rel_a = m.ReleaseSite(name='rel_a', complex=a.inst(), shape=m.Shape.SPHERICAL, location=(0, 0, 0), site_diameter=0, number_to_release=100) rel_a120 = m.ReleaseSite(name='rel_a120', complex=a.inst(), shape=m.Shape.SPHERICAL, location=(0, 0, 0), site_diameter=0, number_to_release=100, release_time=120 * TIME_STEP) # ---- surface classes assignment ---- # ---- compartments assignment ---- # ---- instantiation data ----
from subsystem import * from geometry import * MODEL_PATH = os.path.dirname(os.path.abspath(__file__)) # ---- instantiation ---- # ---- release sites ---- # ---- surface classes assignment ---- box_bottom.surface_class = reflect_edge # ---- compartments assignment ---- rel_m = m.ReleaseSite( name = 'rel_m', complex = m.Complex('M'), region = box_bottom, number_to_release = 3755 ) # ---- create instantiation object and add components ---- instantiation = m.Instantiation() instantiation.add_geometry_object(box) instantiation.add_release_site(rel_m) # load seed species information from bngl file instantiation.load_bngl_compartments_and_seed_species(os.path.join(MODEL_PATH, 'model.bngl'), None, shared.parameter_overrides)
output_files_prefix='./viz_data/seed_' + str(SEED).zfill(5) + '/Scene', every_n_timesteps=5000) model.add_viz_output(viz_output) gdat_file = '' if 'GDAT' in params and params['GDAT'] == 1: gdat_file = os.path.splitext(bngl_file)[0] + '.gdat' model.load_bngl(bngl_file, './react_data/seed_' + str(SEED).zfill(5) + '/' + gdat_file, default_compartment) rel_site = m.ReleaseSite( name='x', complex=m.Complex('A@PM'), #shape = model.find_geometry_object('CP'), number_to_release=12345678900) model.add_release_site(rel_site) # ---- configuration ---- model.config.time_step = TIME_STEP model.config.seed = SEED model.config.total_iterations = ITERATIONS model.config.partition_dimension = MCELL_DEFAULT_COMPARTMENT_EDGE_LENGTH model.config.subpartition_dimension = MCELL_DEFAULT_COMPARTMENT_EDGE_LENGTH model.initialize()
import os import shared import mcell as m from parameters import * from subsystem import * from geometry import * MODEL_PATH = os.path.dirname(os.path.abspath(__file__)) instantiation = m.Instantiation() for mol in ['A', 'B']: cplx = m.Complex(mol) box1_only_rel = m.ReleaseSite(name='box1_only_rel_' + mol, complex=cplx, region=box1 - box2, number_to_release=50) box2_only_rel = m.ReleaseSite(name='box2_only_rel_' + mol, complex=cplx, region=box2 - box1, number_to_release=60) both_only_rel = m.ReleaseSite(name='both_only_rel_' + mol, complex=cplx, region=box1 * box2, number_to_release=80) instantiation.add_release_site(box1_only_rel) instantiation.add_release_site(box2_only_rel) instantiation.add_release_site(both_only_rel)
lipid_raft_A = m.SurfaceClass(name='lipid_raft_A', type=m.SurfacePropertyType.REFLECTIVE, affected_complex_pattern=m.Complex('A')) lipid_raft_B = m.SurfaceClass(name='lipid_raft_B', type=m.SurfacePropertyType.REFLECTIVE, affected_complex_pattern=m.Complex('B')) model.add_surface_class(lipid_raft_A) model.add_surface_class(lipid_raft_B) Sphere1_right.surface_class = lipid_raft_A Sphere2_left.surface_class = lipid_raft_B # release molecules in specified regions rel_A = m.ReleaseSite(name='rel_A', complex=m.Complex('A', orientation=m.Orientation.UP), region=Sphere1_right, number_to_release=350) rel_B = m.ReleaseSite(name='rel_B', complex=m.Complex('B', orientation=m.Orientation.UP), region=Sphere2_left, number_to_release=350) model.add_release_site(rel_A) model.add_release_site(rel_B) # must be 1 for visualization to work correctly (for now) VIZ_FREQUENCY = 1 # viz output to visualize molecules viz_output = m.VizOutput(mode=m.VizMode.ASCII,
# WARNING: This is an automatically generated file and will be overwritten # by CellBlender on the next model export. import os import shared import mcell as m from parameters import * from subsystem import * from geometry import * MODEL_PATH = os.path.dirname(os.path.abspath(__file__)) box1_only_rel = m.ReleaseSite(name='box1_only_rel', complex=vm.inst(), region=box1 - box2, number_to_release=4) box2_only_rel = m.ReleaseSite(name='box2_only_rel', complex=vm.inst(), region=box2 - box1, number_to_release=6) both_only_rel = m.ReleaseSite(name='both_only_rel', complex=vm.inst(), region=box1 * box2, number_to_release=8) # ---- create instantiation object and add components ---- instantiation = m.Instantiation() instantiation.add_geometry_object(box1)
import mcell as m from parameters import * from subsystem import * from geometry import * # ---- instantiation ---- # ---- release sites ---- rel_a = m.ReleaseSite(name='rel_a', complex=vm, shape=m.Shape.SPHERICAL, location=(0, 0, 0), site_diameter=0, number_to_release=100) # ---- surface classes assignment ---- # ---- instantiation data ---- instantiation = m.Instantiation() instantiation.add_geometry_object(Tetrahedron) instantiation.add_release_site(rel_a)
import mcell as m from parameters import * from subsystem import * from geometry import * # ---- instantiation ---- # ---- release sites ---- rel_a1 = m.ReleaseSite(name='rel_a1', complex=m.Complex('a'), shape=m.Shape.SPHERICAL, location=(0, 0, 0), site_diameter=0, number_to_release=20) rel_a2 = m.ReleaseSite(name='rel_a2', complex=m.Complex('a'), shape=m.Shape.SPHERICAL, location=(0.14999999999999999, 0, 0), site_diameter=0, number_to_release=20) rel_a3 = m.ReleaseSite(name='rel_a3', complex=m.Complex('a'), shape=m.Shape.SPHERICAL, location=(0.25, 0, 0), site_diameter=0, number_to_release=20)
import os import shared import mcell as m from parameters import * from subsystem import * from geometry import * MODEL_PATH = os.path.dirname(os.path.abspath(__file__)) instantiation = m.Instantiation() for mol in ['A', 'B']: cplx = m.Complex(mol) box1_sr1_rel = m.ReleaseSite(name='box1_sr1_rel_' + mol, complex=cplx, region=box1_sr1, number_to_release=40) box1_sr2_rel = m.ReleaseSite(name='box1_sr2_rel' + mol, complex=cplx, region=box1_sr2, number_to_release=60) box2_rel = m.ReleaseSite(name='box2_rel' + mol, complex=cplx, region=box2, number_to_release=30) instantiation.add_release_site(box1_sr1_rel) instantiation.add_release_site(box1_sr2_rel) instantiation.add_release_site(box2_rel)
# by CellBlender on the next model export. import mcell as m from parameters import * from subsystem import * from geometry import * # ---- instantiation ---- # ---- release sites ---- rel_a = m.ReleaseSite( name = 'rel_a', complex = a.inst(), shape = m.Shape.SPHERICAL, location = (0, 0, 0), site_diameter = 0, number_to_release = 100 ) rel_b = m.ReleaseSite( name = 'rel_b', complex = b.inst(), shape = m.Shape.SPHERICAL, location = (5.0000000000000001e-03, 0, 0), site_diameter = 0, number_to_release = 100 ) rel_sd = m.ReleaseSite( name = 'rel_sd',
import mcell as m from parameters import * from subsystem import * from geometry import * # ---- instantiation ---- # ---- release sites ---- rel_a = m.ReleaseSite( name = 'rel_a', complex = a.inst(), shape = m.Shape.SPHERICAL, location = (0, 0, 0), site_diameter = 0, number_to_release = 9 ) rel_b = m.ReleaseSite( name = 'rel_b', complex = b.inst(), shape = m.Shape.SPHERICAL, location = (1.00000000000000002e-02, 0, 0), site_diameter = 0, number_to_release = 9 ) # ---- surface classes assignment ----
MCELL_PATH = os.environ.get('MCELL_PATH', '') if MCELL_PATH: sys.path.append(os.path.join(MCELL_PATH, 'lib')) else: print( "Error: variable MCELL_PATH that is used to find the mcell library was not set." ) sys.exit(1) import mcell as m # single property rs1 = m.ReleaseSite('rel1', complex=m.Complex('X(y!1).Y(x!1)'), shape=m.Shape.SPHERICAL, location=(1, 1, 1), number_to_release=10) rs2 = m.ReleaseSite('rel1', complex=m.Complex('X(y!1).Y(x!1)'), shape=m.Shape.SPHERICAL, location=(0.1, 0.1, 0.1), number_to_release=10) assert rs1 != rs2 rs3 = m.ReleaseSite('rel1', complex=m.Complex('Y(x!1).X(y!1)'), shape=m.Shape.SPHERICAL, location=(1, 1, 1),
import mcell as m from parameters import * from subsystem import * from geometry import * # ---- instantiation ---- # ---- release sites ---- rel_a = m.ReleaseSite(name='rel_a', complex=a.inst(), shape=m.Shape.SPHERICAL, location=(0, 0, 0), site_diameter=0, number_to_release=10) rel_b = m.ReleaseSite(name='rel_b', complex=b.inst(orientation=m.Orientation.UP), region=Cube, number_to_release=80) # ---- surface classes assignment ---- # ---- compartments assignment ---- # ---- instantiation data ---- instantiation = m.Instantiation() instantiation.add_geometry_object(Cube) instantiation.add_release_site(rel_a)
model.config.time_step = TIME_STEP model.config.seed = SEED model.config.total_iterations = ITERATIONS model.config.partition_dimension = 10 model.config.subpartition_dimension = 2.5 # ---- add components ---- # TODO viz without any molecules does not work yet a = m.Species(name='a', diffusion_constant_3d=1e-6) model.add_species(a) rel = m.ReleaseSite(name='rel', complex=a, shape=m.Shape.SPHERICAL, location=(8, 8, 8), site_diameter=0, number_to_release=1) model.add_release_site(rel) model.add_geometry_object(Sphere1) model.add_geometry_object(Sphere2) model.add_observables(observables) # ---- initialization and execution ---- model.initialize() if DUMP: model.dump_internal_state()
# WARNING: This is an automatically generated file and will be overwritten # by CellBlender on the next model export. import mcell as m from parameters import * from subsystem import * from geometry import * # ---- instantiation ---- # ---- release sites ---- rel_A = m.ReleaseSite(name='rel_A', complex=m.Complex('A', orientation=m.Orientation.UP), region=up, number_to_release=100) rel_B = m.ReleaseSite(name='rel_B', complex=m.Complex('B', orientation=m.Orientation.UP), region=bottom, number_to_release=100) # ---- surface classes assignment ---- # ---- compartments assignment ---- # ---- create instantiation object and add components ---- instantiation = m.Instantiation() instantiation.add_geometry_object(up)
if MCELL_PATH: sys.path.append(os.path.join(MCELL_PATH, 'lib')) else: print("Error: variable MCELL_PATH that is used to find the mcell library was not set.") sys.exit(1) import mcell as m model = m.Model() a = m.Species('a', diffusion_constant_3d = 1e-6) model.add_species(a) rs = m.ReleaseSite( 'rel_a', a, shape = m.Shape.SPHERICAL, location = (0, 0, 0), number_to_release = 10 ) model.add_release_site(rs) model.initialize() model.run_iterations(1) all_ids = model.get_molecule_ids() a_ids = model.get_molecule_ids(a) assert len(all_ids) == 10 assert all_ids == a_ids m0 = model.get_molecule(a_ids[1]) assert m0.id == a_ids[1] # id should be 1
lib_path = os.path.join(MCELL_PATH, 'lib') sys.path.append(lib_path) else: print("Error: system variable MCELL_PATH that is used to find the mcell " "library was not set.") sys.exit(1) #0000-3) import mcell as m #0000-4) species_a = m.Species(name='a', diffusion_constant_3d=1e-6) #0000-5) release_site_a = m.ReleaseSite(name='rel_a', complex=species_a, location=(0, 0, 0), number_to_release=1) #0000-6) viz_output = m.VizOutput(output_files_prefix='./viz_data/seed_00001/Scene', ) #0010-1) """ 0020-1) In the previous section we created a simple box inside the simulation. Simple primitives (cube and icosphere) can be also created using methods provided in a submodule geometry_utils. There are two commonly used types of spheres in computer graphics: UV spheres and icospheres. The reason why we are using icospheres here is that all of their triangles have
import mcell as m from parameters import * from subsystem import * from geometry import * # ---- instantiation ---- # ---- release sites ---- rel_a = m.ReleaseSite(name='rel_a', complex=m.Complex('a'), shape=m.Shape.SPHERICAL, location=(0, 0, 0), site_diameter=0, number_to_release=1000) rel_b = m.ReleaseSite(name='rel_b', complex=m.Complex('b'), shape=m.Shape.SPHERICAL, location=(5.0000000000000001e-03, 0, 0), site_diameter=0, number_to_release=1000) # ---- surface classes assignment ---- # ---- compartments assignment ---- # ---- instantiation data ---- instantiation = m.Instantiation()