def add_reaction(self, rxn: Reaction) -> None: """ Add a Reaction object to the simulation. """ r_spec_list = None p_spec_list = None # Figure out if it's an iterable of reactants or a single reactant try: for r in rxn.reactants: if isinstance(r, m.OrientedSpecies): r_sym = self._species[r.spec.name] r_spec_list = m.mcell_add_to_species_list( r_sym, True, r.orient_num, r_spec_list) else: r_sym = self._species[r.name] r_spec_list = m.mcell_add_to_species_list( r_sym, False, 0, r_spec_list) except TypeError: r = rxn.reactants if isinstance(r, m.OrientedSpecies): r_sym = self._species[r.spec.name] r_spec_list = m.mcell_add_to_species_list( r_sym, True, r.orient_num, r_spec_list) else: r_sym = self._species[r.name] r_spec_list = m.mcell_add_to_species_list( r_sym, False, 0, r_spec_list) try: for p in rxn.products: if isinstance(r, m.OrientedSpecies): p_sym = self._species[p.spec.name] p_spec_list = m.mcell_add_to_species_list( p_sym, True, p.orient_num, p_spec_list) else: p_sym = self._species[p.name] p_spec_list = m.mcell_add_to_species_list( p_sym, False, 0, p_spec_list) except TypeError: p = rxn.products if isinstance(r, m.OrientedSpecies): p_sym = self._species[p.spec.name] p_spec_list = m.mcell_add_to_species_list( p_sym, True, p.orient_num, p_spec_list) else: p_sym = self._species[p.name] p_spec_list = m.mcell_add_to_species_list( p_sym, False, 0, p_spec_list) logging.info("Add reaction '%s' to simulation" % rxn.print_friendly_repr) m.create_reaction(self._world, r_spec_list, p_spec_list, rxn.rate_constant, rxn.bkwd_rate_constant, name=rxn.name)
mol_A = m.create_species(name="A", dc=1) world.species_list.append(mol_A) mol_B = m.create_species(name="B", dc=1) world.species_list.append(mol_B) mol_C = m.create_species(name="C", dc=1) world.species_list.append(mol_C) ### # Define reactions ### # A + B -> C rxn = m.create_reaction("%m + %m -> %m" % (mol_A, mol_B, mol_C), name="rxn", fwd_rate=10) # Add to the world world.rxn_list.append(rxn) ### # Release molecules into box ### list_of_mols_to_release = [mol_A, mol_B] number_of_each_to_release = [100, 100] world.release_mols(list_of_mols_to_release, nrel=number_of_each_to_release, loc="%o" % (box))
mol_A = m.create_species(name="A",dc=1) world.species_list.append(mol_A) mol_B = m.create_species(name="B",dc=1,type="SURFACE") world.species_list.append(mol_B) mol_C = m.create_species(name="C",dc=1) world.species_list.append(mol_C) ### # Define reactions ### # A' + B' @ surf_reg_plane -> C, rxn = m.create_reaction("%m + %m @ %r -> %m" % (mol_A, mol_B, surf_reg_plane, mol_C), name="rxn", fwd_rate = 10) # Add to the world world.rxn_list.append(rxn) ### # Release molecules into box ### list_of_mols_to_release = [mol_A] number_of_each_to_release = [100] world.release_mols( list_of_mols_to_release, nrel = number_of_each_to_release, loc = [0.5,0,0])
mol_A = m.create_species(name="A", dc=1) world.species_list.append(mol_A) mol_B = m.create_species(name="B", dc=1) world.species_list.append(mol_B) mol_C = m.create_species(name="C", dc=1) world.species_list.append(mol_C) ### # Define reactions ### # A -> 0 rxn_1 = m.create_reaction("%m -> 0" % (mol_A), name="rxn 1", fwd_rate=10) # A -> B rxn_2 = m.create_reaction("%m -> %m" % (mol_A, mol_B), name="rxn 2", fwd_rate=10) # A + B -> C rxn_3 = m.create_reaction("%m + %m -> %m" % (mol_A, mol_B, mol_C), name="rxn 3", fwd_rate=10) # A + B <-> C rxn_4 = m.create_reaction("%m + %m -> %m" % (mol_A, mol_B, mol_C), name="rxn 4", fwd_rate=10,
mol_A = m.create_species(name="A",dc=1) world.species_list.append(mol_A) mol_B = m.create_species(name="B",dc=1,type="SURFACE") world.species_list.append(mol_B) mol_C = m.create_species(name="C",dc=1,type="SURFACE") world.species_list.append(mol_C) ### # Define reactions ### # A + B @ box[surf_reg] -> C rxn_1 = m.create_reaction("%m; + %m; @ %o[%r] -> %m;" % (mol_A,mol_B,box,surf_reg,mol_C), name="rxn 1", fwd_rate = 10) # Add to the world world.rxn_list.append(rxn_1) ### # Release molecules into the box ### list_of_mols_to_release = [mol_A, mol_B] number_of_each_to_release = [100, 100] world.release_mols(list_of_mols_to_release, nrel = number_of_each_to_release, loc = ["%o" % (box), "%o[%r]" % (box, surf_reg)], orientations = ["",";"]) ###
# Create pyMCell instance world = m.mcell_create() m.mcell_init_state(world) dt = 1e-6 iterations = 300 m.mcell_set_time_step(world, dt) m.mcell_set_iterations(world, iterations) # Define one surface molecule and three volume molecules vm1_sym = m.create_species(world, "vm1", 1e-6, False) # vm1 -> NULL [1e5] reactants2 = m.mcell_add_to_species_list(vm1_sym, False, 0, None) m.create_reaction(world, reactants2, None, 0.01, name="rxn") # Create Scene for simulation scene_name = "Scene" scene = m.create_instance_object(world, scene_name) # Create a spherical release site pos_vec3 = m.Vector3() diam_vec3 = m.Vector3(0.015, 0.015, 0.015) position, diameter, sphere_release_object = m.create_release_site( world, scene, pos_vec3, diam_vec3, m.SHAPE_SPHERICAL, 500, 0, vm1_sym, "vm1_rel") obj_name = "Torus" mesh = m.create_polygon_object(world, torus.vert_list, torus.face_list,