예제 #1
0
def main():

    # Create the MCell world
    world = m.mcell_create()
    m.mcell_init_state(world)

    # Set iterations, step size
    dt = 1e-5
    iterations = 100
    m.mcell_set_time_step(world, dt)
    m.mcell_set_iterations(world, iterations)

    # Define volume molecule
    vm1_sym = m.create_species(world, "vm1", 1e-6, False)

    # Create a scene
    scene_name = "Scene"
    scene = m.create_instance_object(world, scene_name)

    # Create release pattern with a delay
    rel_pattern = m.create_release_pattern(world,
                                           "Release Pattern",
                                           delay=5e-4)

    # Create box objects
    box_name = "Box_Union_Outer"
    r = (0.1, 0.1, 0.1)
    ctr = (-0.3, 0.3, 0)
    box_mesh = create_rectangle(world, scene, r, ctr, box_name)

    # List of mols to release
    mol_list = m.mcell_add_to_species_list(vm1_sym, False, 0, None)

    # Release
    rel_object = m.object()
    box_rel_object = m.mcell_create_region_release(world, scene, box_mesh,
                                                   "Box Release", "ALL",
                                                   mol_list, 1000, 0, 1,
                                                   rel_pattern, rel_object)
    m.mcell_delete_species_list(mol_list)

    # Create viz data
    viz_list = m.mcell_add_to_species_list(vm1_sym, False, 0, None)
    m.mcell_create_viz_output(world, "./viz_data/test", viz_list, 0,
                              iterations, 1)

    m.mcell_init_simulation(world)
    m.mcell_init_output(world)

    output_freq = 10
    for i in range(iterations):
        m.mcell_run_iteration(world, output_freq, 0)
    m.mcell_flush_data(world)
    m.mcell_print_final_warnings(world)
    m.mcell_print_final_statistics(world)
예제 #2
0
def main():
    world = m.mcell_create()
    m.mcell_init_state(world)

    dt = 1e-5
    iterations = 100
    m.mcell_set_time_step(world, dt)
    m.mcell_set_iterations(world, iterations)

    # Define one volume molecule
    vm1_sym = m.create_species(world, "vm1", 1e-6, False)
    sm1_sym = m.create_species(world, "sm1", 1e-6, True)

    scene_name = "Scene"
    scene = m.create_instance_object(world, scene_name)

    # Create box object
    box_name = "Box"
    box_mesh = m.create_box(world, scene, 1.0, box_name)

    # Release site object
    # One volume list
    (vol_rel_obj, success_vol) = m.create_list_release_site(
        world, scene, [vm1_sym, vm1_sym], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0],
        "rel_name_vol")
    # One surface list
    (surf_rel_obj,
     success_surf) = m.create_list_release_site(world,
                                                scene, [sm1_sym, sm1_sym],
                                                [1.0, 0.0], [0.0, 1.0],
                                                [0.0, 0.0],
                                                "rel_name_surf",
                                                surf_flags=[True, True],
                                                orientations=[1, 1])

    # Create viz data
    viz_list = m.mcell_add_to_species_list(vm1_sym, False, 0, None)
    viz_list = m.mcell_add_to_species_list(sm1_sym, True, 1, viz_list)
    m.mcell_create_viz_output(world, "./test_release_list_viz/test", viz_list,
                              0, iterations, 1)

    m.mcell_init_simulation(world)
    m.mcell_init_output(world)

    output_freq = 1
    for i in range(iterations):
        m.mcell_run_iteration(world, output_freq, 0)
    m.mcell_flush_data(world)
    m.mcell_print_final_warnings(world)
    m.mcell_print_final_statistics(world)
예제 #3
0
    def run_sim(self) -> None:
        """ Run the entire simulation without interruption. """
        if self._finished:
            print("The simulation is done running")
            return

        m.mcell_init_simulation(self._world)
        m.mcell_init_output(self._world)

        for i in range(self._iterations + 1):
            m.mcell_run_iteration(self._world, self._output_freq, 0)
        m.mcell_flush_data(self._world)
        m.mcell_print_final_warnings(self._world)
        m.mcell_print_final_statistics(self._world)
        self._finished = True
예제 #4
0
    def run_iteration(self) -> None:
        """ Run a single iteration. """
        if self._finished:
            print("The simulation is done running")
            return

        if not self._started:
            m.mcell_init_simulation(self._world)
            m.mcell_init_output(self._world)
            self._started = True
        if self._current_iteration <= self._iterations:
            m.mcell_run_iteration(self._world, self._output_freq, 0)
        # You have to kill it now or it will hang
        if self._current_iteration == self._iterations:
            m.mcell_flush_data(self._world)
            m.mcell_print_final_warnings(self._world)
            m.mcell_print_final_statistics(self._world)
            self._finished = True
        self._current_iteration += 1
예제 #5
0
파일: test_bool.py 프로젝트: mdresch/mcell
def main(lexer, parser):

    # Create the MCell world
    world = m.mcell_create()
    m.mcell_init_state(world)

    # Set iterations, step size
    dt = 1e-5
    iterations = 100
    m.mcell_set_time_step(world, dt)
    m.mcell_set_iterations(world, iterations)

    # Define volume molecule
    vm1_sym = m.create_species(world, "vm1", 1e-6, False)

    # Create a scene
    scene_name = "Scene"
    scene = m.create_instance_object(world, scene_name)

    ##########
    # Create each of the three binary operations
    # Each example consists of two box objects
    ##########

    # Dictionary of release evaluator objects
    rel_eval_dict = {}

    ##########
    # Union
    ##########

    # Create box objects
    box_union_outer_name = "Box_Union_Outer"
    r_union_outer = (0.1, 0.1, 0.1)
    ctr_union_outer = (-0.3, 0.3, 0)
    box_union_outer_mesh = create_rectangle(world, scene, r_union_outer,
                                            ctr_union_outer,
                                            box_union_outer_name)

    box_union_inner_name = "Box_Union_Inner"
    r_union_inner = (0.1, 0.1, 0.12)
    ctr_union_inner = (-0.3 + 0.1, 0.3 + 0.1, 0.0)
    box_union_inner_mesh = create_rectangle(world, scene, r_union_inner,
                                            ctr_union_inner,
                                            box_union_inner_name)

    # Add to the dictionary of objects for the parser to see
    lexer.obj_dict[box_union_outer_name] = box_union_outer_mesh
    lexer.obj_dict[box_union_inner_name] = box_union_inner_mesh

    # We will use the "ALL" region specification
    # We could also define a surface region using the following code
    '''
	box_union_outer_region_name = "Box_Union_Outer_Reg"
	box_union_outer_face_list = [0,1,2,3,4,5,6,7,8,9,10,11]
	box_union_outer_region = m.create_surface_region(world, box_union_outer_mesh, box_union_outer_face_list, box_union_outer_region_name)
	box_union_inner_region_name = "Box_Union_Inner_Reg"
	box_union_inner_face_list = [0,1,2,3,4,5,6,7,8,9,10,11]
	box_union_inner_region = m.create_surface_region(world, box_union_inner_mesh, box_union_inner_face_list, box_union_inner_region_name)
	'''

    # Parse a string to create a release_evaluator
    s_union = box_union_outer_name + "[ALL]" + " + " + box_union_inner_name + "[ALL]"
    print("> Parsing: " + s_union)
    lexer.mcell_world = world
    parser.parse(s_union)
    rel_eval_dict[s_union] = lexer.release_evaluator
    print("> Finished parsing.")

    ##########
    # Subtraction
    ##########

    # Create box objects
    box_sub_outer_name = "Box_Sub_Outer"
    r_sub_outer = (0.1, 0.1, 0.1)
    ctr_sub_outer = (0.3, 0.3, 0)
    box_sub_outer_mesh = create_rectangle(world, scene, r_sub_outer,
                                          ctr_sub_outer, box_sub_outer_name)

    box_sub_inner_name = "Box_Sub_Inner"
    r_sub_inner = (0.1, 0.1, 0.12)
    ctr_sub_inner = (0.3 + 0.1, 0.3 + 0.1, 0.0)
    box_sub_inner_mesh = create_rectangle(world, scene, r_sub_inner,
                                          ctr_sub_inner, box_sub_inner_name)

    # Add to the dictionary of objects for the parser to see
    lexer.obj_dict[box_sub_outer_name] = box_sub_outer_mesh
    lexer.obj_dict[box_sub_inner_name] = box_sub_inner_mesh

    # Parse a string to create a release_evaluator
    s_sub = box_sub_outer_name + "[ALL]" + " - " + box_sub_inner_name + "[ALL]"
    print("> Parsing: " + s_sub)
    lexer.mcell_world = world
    parser.parse(s_sub)
    rel_eval_dict[s_sub] = lexer.release_evaluator
    print("> Finished parsing.")

    ##########
    # Intersection
    ##########

    # Create box objects
    box_inter_outer_name = "Box_Inter_Outer"
    r_inter_outer = (0.1, 0.1, 0.1)
    ctr_inter_outer = (0.0, -0.3, 0.0)
    box_inter_outer_mesh = create_rectangle(world, scene, r_inter_outer,
                                            ctr_inter_outer,
                                            box_inter_outer_name)

    box_inter_inner_name = "Box_Inter_Inner"
    r_inter_inner = (0.1, 0.1, 0.12)
    ctr_inter_inner = (0.1, -0.3 + 0.1, 0.0)
    box_inter_inner_mesh = create_rectangle(world, scene, r_inter_inner,
                                            ctr_inter_inner,
                                            box_inter_inner_name)

    # Add to the dictionary of objects for the parser to see
    lexer.obj_dict[box_inter_outer_name] = box_inter_outer_mesh
    lexer.obj_dict[box_inter_inner_name] = box_inter_inner_mesh

    # Parse a string to create a release_evaluator
    s_inter = box_inter_outer_name + "[ALL]" + " * " + box_inter_inner_name + "[ALL]"
    print("> Parsing: " + s_inter)
    lexer.mcell_world = world
    parser.parse(s_inter)
    rel_eval_dict[s_inter] = lexer.release_evaluator
    print("> Finished parsing.")

    ##########
    # Set up all the release sites for each: union/subtraction/intersection
    ##########

    # List of mols to release
    mol_list = m.mcell_add_to_species_list(vm1_sym, False, 0, None)

    # Union
    rel_object = m.object()
    box_union_outer_rel_object = m.mcell_create_region_release_boolean(
        world, scene, "Box Union Outer Release", mol_list, 1000, 0, 1, None,
        rel_eval_dict[s_union], rel_object)

    # Subtraction
    rel_object = m.object()
    box_sub_outer_rel_object = m.mcell_create_region_release_boolean(
        world, scene, "Box Subtraction Outer Release", mol_list, 1000, 0, 1,
        None, rel_eval_dict[s_sub], rel_object)

    # Union
    mol_list = m.mcell_add_to_species_list(vm1_sym, False, 0, None)
    rel_object = m.object()
    box_inter_outer_rel_object = m.mcell_create_region_release_boolean(
        world, scene, "Box Intersection Outer Release", mol_list, 1000, 0, 1,
        None, rel_eval_dict[s_inter], rel_object)

    m.mcell_delete_species_list(mol_list)

    ##########
    # Create viz data
    ##########

    viz_list = m.mcell_add_to_species_list(vm1_sym, False, 0, None)
    m.mcell_create_viz_output(world, "./viz_data/test", viz_list, 0,
                              iterations, 1)

    m.mcell_init_simulation(world)
    m.mcell_init_output(world)

    output_freq = 10
    for i in range(iterations):
        m.mcell_run_iteration(world, output_freq, 0)
    m.mcell_flush_data(world)
    m.mcell_print_final_warnings(world)
    m.mcell_print_final_statistics(world)
예제 #6
0
    region_release_object = m.create_region_release_site(
        world, scene, mesh, "vm1_torus_rel", "ALL", 1000, 0, vm1_sym)

    # Create viz data
    viz_list = m.mcell_add_to_species_list(vm1_sym, False, 0, None)
    m.mcell_create_viz_output(world, "./viz_data/test", viz_list, 0,
                              iterations, 1)

    # Create reaction data
    mesh_sym = m.mcell_get_obj_sym(mesh)
    count_list1, os1, out_times1, output1 = m.create_count(
        world, mesh_sym, vm1_sym, "react_data/vm1_%s.dat" % obj_name)

    # Initialize simulation
    m.mcell_init_simulation(world)
    m.mcell_init_output(world)

    # Define soma compartment with HH mechanisms
    soma = neuron.h.Section(name="soma")
    soma.nseg = 1
    soma.diam = 10
    soma.L = 10
    soma.insert("hh")
    meca = soma(.5).hh

    # Record time from NEURON
    rec_t = neuron.h.Vector()
    rec_t.record(neuron.h._ref_t)
    #record voltage from center of soma
    rec_v = neuron.h.Vector()