def run_single(T, V, N, R, D): L = numpy.power(V, 1.0/3.0) # cuboid side length # matrix_size = 3 # min matrix size matrix_size = max(3, int(min(numpy.power(N, 1.0 / 3.0), L / (2 * R)))) m = model.ParticleModel(L) A = model.Species('A', D, R) m.add_species_type(A) m.set_all_repulsive() w = gfrdbase.create_world(m, matrix_size) gfrdbase.throw_in_particles(w, A, N) nrw = gfrdbase.create_network_rules_wrapper(m) sim = _gfrd._EGFRDSimulator(w, nrw, myrandom.rng) stirTime = T*0.01 t = 0.0 gc.disable while (sim.step(stirTime)): pass print "Now running",int(N),"molecules for",T,"s" endTime = stirTime+T start = time.time() while (sim.step(endTime)): pass print "time",sim.t,endTime end = time.time() gc.collect() gc.enable() duration = end-start print duration,"s" return duration
def run_single(T, V, N): print 'T =', T, '; V= ', V, '; N=', N # disable gc import gc gc.disable() L = math.pow(V * 1e-3, 1.0 / 3.0) matrix_size = max(3, int((3 * N) ** (1.0/3.0))) print 'matrix_size=', matrix_size D = 1e-12 m = model.ParticleModel(L) A = model.Species('A', D, 2.5e-9) m.add_species_type(A) m.set_all_repulsive() w = gfrdbase.create_world(m, matrix_size) nrw = _gfrd.NetworkRulesWrapper(m.network_rules) s = EGFRDSimulator(w, myrandom.rng, nrw) gfrdbase.throw_in_particles(w, A, N) print 'stir' t = 0 stir_time = T * .1 while 1: s.step() next_time = s.get_next_time() if next_time > stir_time: s.stop(stir_time) break print 'reset' s.reset() print 'run' run_time = T start = time.time() while s.t < run_time: s.step() end = time.time() timing = end - start steps = s.step_counter stepspersec = float(steps) / timing print 'steps (total)= ', steps print 'steps/sec= ', stepspersec, ', steps/N= ', float(steps) / N print 'TIMING:\n', timing, '\n' gc.collect() gc.enable() return end - start, steps, stepspersec
def run_single(T, V, N): print 'T =', T, '; V= ', V, '; N=', N # disable gc import gc gc.disable() L = math.pow(V * 1e-3, 1.0 / 3.0) matrix_size = max(3, int((3 * N)**(1.0 / 3.0))) print 'matrix_size=', matrix_size D = 1e-12 m = model.ParticleModel(L) A = model.Species('A', D, 2.5e-9) m.add_species_type(A) m.set_all_repulsive() w = gfrdbase.create_world(m, matrix_size) nrw = _gfrd.NetworkRulesWrapper(m.network_rules) s = EGFRDSimulator(w, myrandom.rng, nrw) gfrdbase.throw_in_particles(w, A, N) print 'stir' t = 0 stir_time = T * .1 while 1: s.step() next_time = s.get_next_time() if next_time > stir_time: s.stop(stir_time) break print 'reset' s.reset() print 'run' run_time = T start = time.time() while s.t < run_time: s.step() end = time.time() timing = end - start steps = s.step_counter stepspersec = float(steps) / timing print 'steps (total)= ', steps print 'steps/sec= ', stepspersec, ', steps/N= ', float(steps) / N print 'TIMING:\n', timing, '\n' gc.collect() gc.enable() return end - start, steps, stepspersec
def singlerun(T_list, N_B, N_X): """ Function that performs one simulation run of binding/ rebinding. Arguments: - T_list: List of times at which distance between particles is evaluated and logged. - N_B: Number of instances ("molecules") of particle B. - N_X: Number of instances ("molecules") of particle X. """ ################# Define the model: # Create model class m = model.ParticleModel(L) # Particle species classes A = model.Species('A', D, radius) m.add_species_type(A) B = model.Species('B', D, radius) m.add_species_type(B) C = model.Species('C', D, radius) m.add_species_type(C) X = model.Species('X', DX, radius) m.add_species_type(X) # Reaction rules r1 = model.create_binding_reaction_rule(A, B, C, kf) m.network_rules.add_reaction_rule(r1) r2 = model.create_unbinding_reaction_rule(C, A, B, 1e3) m.network_rules.add_reaction_rule(r2) ################# Set up simulator w = gfrdbase.create_world(m, matrix_size) nrw = gfrdbase.create_network_rules_wrapper(m) s = EGFRDSimulator(w, myrandom.rng, nrw) ################# Place particles # Throw in some X particles and stirr if N_X != 0: gfrdbase.throw_in_particles(w, X, N_X) end_time = tau * 1 while 1: s.step() next_time = s.get_next_time() if next_time > end_time: s.stop(end_time) break # Reset simulation, so stirring has no effect on output data s.reset() # Define positions for particles to place. A_pos = [0,0,0] B_pos = [(float(A['radius']) + float(B['radius']))+1e-23,0,0] # Clear an area at position A_pos and place particle A there # # How this should be done: # - find particles at position A_pos within species A radius # - delete those # - add a number of X particles _randomly to the box_, the # number being equal to # removed particles. # - if a particle is accidently placed within the "cleared" # area, repeat the process (in very crowded box, this # leads to infinite loop) # # Currently, however, it doesn't get the particles within a certain radius, # but the particles which domain lies within a certain radius. # # Therefore, you might be removing particles that after bursting are not # within the radius anymore, but whose (now bursted) domains were. # # TODO # This code should thus be adapted to solve this problem. # # Perhaps it would be more easy to just place all the particles at # the beginning, but give A and B initially a diffusion constant of # 0, then stirr, and then set the diffusion constant to their # desired values..""" while 1: # Burst domains within a certain volume and collect their ids dd = s.clear_volume(A_pos, float(A['radius'])) if not dd: break for d in dd: for p in d.particle_id_pair: s.remove_particle(p) s.throw_in_particles(X, len(pp), box1) place_particle(w, A, A_pos) # Idem for a particle B: while 1: # Burst domains within a certain volume and collect their ids dd = s.clear_volume(B_pos, float(B['radius'])) if not dd: break for d in dd: for p in d.particle_id_pair: s.remove_particle(p) s.throw_in_particles(X, len(pp), box1) place_particle(w, B, B_pos) # Place rest of B at random positions if N_B > 1: gfrdbase.throw_in_particles(w, B, N_B-1) # Create some vars and perform first simulation step r_list = [] t_list = [] t_last = 0 s.step() next_stop = T_list[0] i_T = 0 # ### Start simulating while 1: # What happens in the following if-statement: # Create a list of the durations particles were in bound state. # # If there was a reaction: # - Binding: Indicated by the fact that there are no C-particles. # In this case: record the current time (s.t) to t_last. # - Unbinding: Indicated because this is the only other case when # a reaction has taken place. # In this case: record the time binding lasted, i.e. dt between # current time (s.t) and last reaction time (t_last). if s.last_reaction: # aka if there was a reaction if len(s.world.get_particle_ids(C.id)) == 0: #A,B print ' - set t_last', str(s.t) # set t_last to "current time" in simulator t_last = s.t else: print ' - reaction: ', str(s.t - t_last) t_list.append(s.t - t_last) # If it's time to log, then log distance between particles. next_time = s.get_next_time() if next_time > next_stop: print '* Measuring distances at ', str(next_stop),\ '(measurement #', str(i_T), ')' s.stop(next_stop) print '* stopped' # If there is a particle C, the distance is "0". if len(s.world.get_particle_ids(C.id)) != 0: #A,B r_list.append(0) # If particles are manifested as A and B, log distance # inbetween. else: # C = 0, i.e. there are particles A and B # Calculate distances: A_pos = s.get_position(A.id) distance_list = [] # If there are >1 B particles, we want to log all # distances seperately, hence the loop: for particle_id in w.get_particle_ids(B.id): B_pos = s.get_position(particle_id) distance = w.distance(A_pos, B_pos) distance_list.append(distance) # Write list to distances table r_list.append(distance_list) i_T += 1 next_stop = T_list[i_T] # If there are no measuring moments on the list any more, and # a duration of being bounded has been recorded, then stop if (next_stop == INF) and (len(t_list) != 0): print 'break', s.t break s.step() return r_list, t_list
P = model.Species('P', D, R) m.add_species_type(E) m.add_species_type(S) m.add_species_type(ES) m.add_species_type(P) fwd = model.create_binding_reaction_rule(E, S, ES, 0.01e-18) back = model.create_unbinding_reaction_rule(ES, E, S, 0.1) prod = model.create_unbinding_reaction_rule(ES, E, P, 0.1) m.network_rules.add_reaction_rule(fwd) m.network_rules.add_reaction_rule(back) m.network_rules.add_reaction_rule(prod) m.set_all_repulsive() w = gfrdbase.create_world(m, matrix_size) gfrdbase.throw_in_particles(w, E, nE) gfrdbase.throw_in_particles(w, S, nS) nrw = gfrdbase.create_network_rules_wrapper(m) sim = _gfrd._EGFRDSimulator(w, nrw, myrandom.rng) start = time.time() t = 0 f = open('egfrd_small_r.csv','w') while (sim.step(T)): t = t+1e-2 while (sim.step(t)): pass f.write(str(sim.t)+','+str(len(w.get_particle_ids(E)))+','+str(len(w.get_particle_ids(S)))+','+str(len(w.get_particle_ids(ES)))+','+str(len(w.get_particle_ids(P)))+'\n') f.flush() print "time",sim.t,T end = time.time()
def singlerun(T_list, N_B, N_X): """ Function that performs one simulation run of binding/ rebinding. Arguments: - T_list: List of times at which distance between particles is evaluated and logged. - N_B: Number of instances ("molecules") of particle B. - N_X: Number of instances ("molecules") of particle X. """ ################# Define the model: # Create model class m = model.ParticleModel(L) # Particle species classes A = model.Species('A', D, radius) m.add_species_type(A) B = model.Species('B', D, radius) m.add_species_type(B) C = model.Species('C', D, radius) m.add_species_type(C) X = model.Species('X', DX, radius) m.add_species_type(X) # Reaction rules r1 = model.create_binding_reaction_rule(A, B, C, kf) m.network_rules.add_reaction_rule(r1) r2 = model.create_unbinding_reaction_rule(C, A, B, 1e3) m.network_rules.add_reaction_rule(r2) ################# Set up simulator w = gfrdbase.create_world(m, matrix_size) nrw = gfrdbase.create_network_rules_wrapper(m) s = EGFRDSimulator(w, myrandom.rng, nrw) ################# Place particles # Throw in some X particles and stirr if N_X != 0: gfrdbase.throw_in_particles(w, X, N_X) end_time = tau * 1 while 1: s.step() next_time = s.get_next_time() if next_time > end_time: s.stop(end_time) break # Reset simulation, so stirring has no effect on output data s.reset() # Define positions for particles to place. A_pos = [0, 0, 0] B_pos = [(float(A['radius']) + float(B['radius'])) + 1e-23, 0, 0] # Clear an area at position A_pos and place particle A there # # How this should be done: # - find particles at position A_pos within species A radius # - delete those # - add a number of X particles _randomly to the box_, the # number being equal to # removed particles. # - if a particle is accidently placed within the "cleared" # area, repeat the process (in very crowded box, this # leads to infinite loop) # # Currently, however, it doesn't get the particles within a certain radius, # but the particles which domain lies within a certain radius. # # Therefore, you might be removing particles that after bursting are not # within the radius anymore, but whose (now bursted) domains were. # # TODO # This code should thus be adapted to solve this problem. # # Perhaps it would be more easy to just place all the particles at # the beginning, but give A and B initially a diffusion constant of # 0, then stirr, and then set the diffusion constant to their # desired values..""" while 1: # Burst domains within a certain volume and collect their ids dd = s.clear_volume(A_pos, float(A['radius'])) if not dd: break for d in dd: for p in d.particle_id_pair: s.remove_particle(p) s.throw_in_particles(X, len(pp), box1) place_particle(w, A, A_pos) # Idem for a particle B: while 1: # Burst domains within a certain volume and collect their ids dd = s.clear_volume(B_pos, float(B['radius'])) if not dd: break for d in dd: for p in d.particle_id_pair: s.remove_particle(p) s.throw_in_particles(X, len(pp), box1) place_particle(w, B, B_pos) # Place rest of B at random positions if N_B > 1: gfrdbase.throw_in_particles(w, B, N_B - 1) # Create some vars and perform first simulation step r_list = [] t_list = [] t_last = 0 s.step() next_stop = T_list[0] i_T = 0 # ### Start simulating while 1: # What happens in the following if-statement: # Create a list of the durations particles were in bound state. # # If there was a reaction: # - Binding: Indicated by the fact that there are no C-particles. # In this case: record the current time (s.t) to t_last. # - Unbinding: Indicated because this is the only other case when # a reaction has taken place. # In this case: record the time binding lasted, i.e. dt between # current time (s.t) and last reaction time (t_last). if s.last_reaction: # aka if there was a reaction if len(s.world.get_particle_ids(C.id)) == 0: #A,B print ' - set t_last', str(s.t) # set t_last to "current time" in simulator t_last = s.t else: print ' - reaction: ', str(s.t - t_last) t_list.append(s.t - t_last) # If it's time to log, then log distance between particles. next_time = s.get_next_time() if next_time > next_stop: print '* Measuring distances at ', str(next_stop),\ '(measurement #', str(i_T), ')' s.stop(next_stop) print '* stopped' # If there is a particle C, the distance is "0". if len(s.world.get_particle_ids(C.id)) != 0: #A,B r_list.append(0) # If particles are manifested as A and B, log distance # inbetween. else: # C = 0, i.e. there are particles A and B # Calculate distances: A_pos = s.get_position(A.id) distance_list = [] # If there are >1 B particles, we want to log all # distances seperately, hence the loop: for particle_id in w.get_particle_ids(B.id): B_pos = s.get_position(particle_id) distance = w.distance(A_pos, B_pos) distance_list.append(distance) # Write list to distances table r_list.append(distance_list) i_T += 1 next_stop = T_list[i_T] # If there are no measuring moments on the list any more, and # a duration of being bounded has been recorded, then stop if (next_stop == INF) and (len(t_list) != 0): print 'break', s.t break s.step() return r_list, t_list
P = model.Species('P', 1e-12, 7e-9) m.add_species_type(S) m.add_species_type(P) r1 = model.create_binding_reaction_rule(S, S, P, 1e7 / N_A) r2 = model.create_unbinding_reaction_rule(P, S, S, 1e3) m.network_rules.add_reaction_rule(r1) m.network_rules.add_reaction_rule(r2) m.set_all_repulsive() world = create_world(m, int((N * 6)**(1. / 3.))) nrw = _gfrd.NetworkRulesWrapper(m.network_rules) s = _gfrd._EGFRDSimulator(world, nrw, myrandom.rng) s.paranoiac = True #s = BDSimulator(world. myrandom.rng, nrw) throw_in_particles(s.world, S, N / 2) throw_in_particles(s.world, P, N / 2) #l = Logger('dimer') l = None interrupter = None if l is not None: interrupter = FixedIntervalInterrupter(s, 1e-7, l.log) import myrandom myrandom.seed(0) def profrun(): if l is not None:
P = model.Species('P', 1e-12, 7e-9) m.add_species_type(S) m.add_species_type(P) r1 = model.create_binding_reaction_rule(S, S, P, 1e7 / N_A) r2 = model.create_unbinding_reaction_rule(P, S, S, 1e3) m.network_rules.add_reaction_rule(r1) m.network_rules.add_reaction_rule(r2) m.set_all_repulsive() world = create_world(m, int((N * 6) ** (1. / 3.))) nrw = _gfrd.NetworkRulesWrapper(m.network_rules) s = _gfrd._EGFRDSimulator(world, nrw, myrandom.rng) s.paranoiac = True #s = BDSimulator(world. myrandom.rng, nrw) throw_in_particles(s.world, S, N / 2) throw_in_particles(s.world, P, N / 2) #l = Logger('dimer') l = None interrupter = None if l is not None: interrupter = FixedIntervalInterrupter(s, 1e-7, l.log) import myrandom myrandom.seed(0) def profrun():