Beispiel #1
0
def singlerun(T, S):

    m = model.ParticleModel(1e-3)

    A = model.Species('A', 1e-12, 5e-9)
    m.add_species_type(A)

    w = gfrdbase.create_world(m, 3)
    nrw = gfrdbase.create_network_rules_wrapper(m)
    # s = EGFRDSimulator(w, myrandom.rng, nrw)
    # s.set_user_max_shell_size(S)
    s = _gfrd._EGFRDSimulator(w, nrw, myrandom.rng, 1, 1e-5, S)

    particleA = gfrdbase.place_particle(w, A, [0, 0, 0])

    end_time = T
    s.step()

    while 1:
        next_time = s.t + s.dt
        if next_time > end_time:
            # s.stop(end_time)
            s.step(end_time)
            break
        s.step()

    pos = w.get_particle(iter(w.get_particle_ids(A.id)).next())[1].position
    distance = w.distance([0, 0, 0], pos)
    return distance, s.t
Beispiel #2
0
def singlerun(T, S):

    m = model.ParticleModel(1e-3)

    A = model.Species('A', 1e-12, 5e-9)
    m.add_species_type(A)

    w = gfrdbase.create_world(m, 3)
    nrw = gfrdbase.create_network_rules_wrapper(m)
    # s = EGFRDSimulator(w, myrandom.rng, nrw)
    # s.set_user_max_shell_size(S)
    s = _gfrd._EGFRDSimulator(w, nrw, myrandom.rng, 1, 1e-5, S)
    
    particleA = gfrdbase.place_particle(w, A, [0, 0, 0])

    end_time = T
    s.step()

    while 1:
        next_time = s.t + s.dt
        if next_time > end_time:
            # s.stop(end_time)
            s.step(end_time)
            break
        s.step()

    pos = w.get_particle(iter(w.get_particle_ids(A.id)).next())[1].position
    distance = w.distance([0,0,0], pos)
    return distance, s.t
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
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
 def setUp(self):
     self.m = model.ParticleModel(1e-5)
     self.S = model.Species('S', 2e-11, 5e-8)
     self.A = model.Species('A', 0, 1e-8)
     self.B = model.Species('B', 2e-11, 5e-9)
     self.m.add_species_type(self.S)
     self.m.add_species_type(self.A)
     self.m.add_species_type(self.B)
     self.m.set_all_repulsive()
     self.w = gfrdbase.create_world(self.m, 10)
     self.nrw = _gfrd.NetworkRulesWrapper(self.m.network_rules)
     self.s = bd.BDSimulator(self.w, myrandom.rng, self.nrw)
Beispiel #7
0
 def setUp(self):
     self.m = model.ParticleModel(1e-5)
     self.S = model.Species('S', 2e-11, 5e-8)
     self.A = model.Species('A', 0, 1e-8)
     self.B = model.Species('B', 2e-11, 5e-9)
     self.m.add_species_type(self.S)
     self.m.add_species_type(self.A)
     self.m.add_species_type(self.B)
     self.m.set_all_repulsive()
     self.w = gfrdbase.create_world(self.m, 10)
     self.nrw = _gfrd.NetworkRulesWrapper(self.m.network_rules)
     self.s = bd.BDSimulator(self.w, myrandom.rng, self.nrw)
Beispiel #8
0
def singlerun(T):

    sigma = 5e-9
    r0 = sigma
    D = 1e-12
    D_tot = D * 2

    tau = sigma * sigma / D_tot

    kf = 100 * sigma * D_tot
    koff = 0.1 / tau

    m = model.ParticleModel(1e-3)

    A = model.Species('A', D, sigma / 2)
    B = model.Species('B', D, sigma / 2)
    C = model.Species('C', D, sigma / 2)

    m.add_species_type(A)
    m.add_species_type(B)
    m.add_species_type(C)

    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, koff)
    m.network_rules.add_reaction_rule(r2)

    w = gfrdbase.create_world(m, 3)
    nrw = _gfrd.NetworkRulesWrapper(m.network_rules)
    s = EGFRDSimulator(w, myrandom.rng, nrw)

    place_particle(w, A, [0, 0, 0])
    place_particle(w, B,
                   [(float(A['radius']) + float(B['radius'])) + 1e-23, 0, 0])

    end_time = T
    s.step()

    while 1:
        next_time = s.get_next_time()
        if next_time > end_time:
            s.stop(end_time)
            break
        s.step()

    if len(s.world.get_particle_ids(C.id)) != 0:
        return 0, s.t

    distance = w.distance(s.get_position(A.id), s.get_position(B.id))

    return distance, s.t
Beispiel #9
0
def singlerun(T):

    sigma = 5e-9
    r0 = sigma
    D = 1e-12
    D_tot = D * 2

    tau = sigma * sigma / D_tot

    kf = 100 * sigma * D_tot
    koff = 0.1 / tau

    m = model.ParticleModel(1e-3)

    A = model.Species('A', D, sigma/2)
    B = model.Species('B', D, sigma/2)
    C = model.Species('C', D, sigma/2)

    m.add_species_type(A)
    m.add_species_type(B)
    m.add_species_type(C)

    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, koff)
    m.network_rules.add_reaction_rule(r2)

    w = gfrdbase.create_world(m, 3)
    nrw = _gfrd.NetworkRulesWrapper(m.network_rules)
    s = EGFRDSimulator(w, myrandom.rng, nrw)

    place_particle(w, A, [0,0,0])
    place_particle(w, B, [(float(A['radius']) + float(B['radius']))+1e-23,0,0])

    end_time = T
    s.step()

    while 1:
        next_time = s.get_next_time()
        if next_time > end_time:
            s.stop(end_time)
            break
        s.step()

    
    if len(s.world.get_particle_ids(C.id)) != 0:
        return 0, s.t

    distance = w.distance(s.get_position(A.id), s.get_position(B.id))

    return distance, s.t
Beispiel #10
0
def singlerun(T):

    sigma = 5e-9
    r0 = sigma
    D = 1e-12
    D_tot = D * 2

    kf = 100 * sigma * D_tot

    m = model.ParticleModel(1e-3)

    A = model.Species('A', D, sigma/2)
    m.add_species_type(A)
    B = model.Species('B', D, sigma/2)
    m.add_species_type(B)
    C = model.Species('C', D, sigma/2)
    m.add_species_type(C)

    r1 = model.create_binding_reaction_rule(A, B, C, kf)
    m.network_rules.add_reaction_rule(r1)

    w = gfrdbase.create_world(m, 3)
    nrw = gfrdbase.create_network_rules_wrapper(m)
    s = _gfrd._EGFRDSimulator(w, nrw, myrandom.rng)

    class check_reactions:
        def __init__(self):
            self.reactions = []

        def __call__(self, ri):
            self.reactions.append(ri)

    cr = check_reactions()
    s.reaction_recorder = cr

    pid1 = gfrdbase.place_particle(w, A, [0,0,0])[0]
    pid2 = gfrdbase.place_particle(w, B, [float(A['radius']) + 
                                          float(B['radius'])+1e-23,0,0])[0]

    end_time = T

    while s.step(end_time):
        if len(cr.reactions) != 0:
            cr.reactions = []
            return 0, s.t

    p1 = s.world.get_particle(pid1)[1]
    p2 = s.world.get_particle(pid2)[1]

    distance = w.distance(p1.position, p2.position)

    return distance, s.t
Beispiel #11
0
def singlerun(T):

    sigma = 5e-9
    r0 = sigma
    D = 1e-12
    D_tot = D * 2

    tau = sigma * sigma / D_tot

    kf = 100 * sigma * D_tot
    koff = 0.1 / tau

    m = model.ParticleModel(1e-3)

    A = model.Species('A', D, sigma/2)
    B = model.Species('B', D, sigma/2)
    C = model.Species('C', D, sigma/2)

    m.add_species_type(A)
    m.add_species_type(B)
    m.add_species_type(C)

    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, koff)
    m.network_rules.add_reaction_rule(r2)

    w = gfrdbase.create_world(m, 3)
    nrw = _gfrd.NetworkRulesWrapper(m.network_rules)
    s = _gfrd._EGFRDSimulator(w, nrw, myrandom.rng)

    place_particle(w, A, [0,0,0])
    place_particle(w, B, 
                   [(float(A['radius']) + float(B['radius']))+1e-23,
                    0,0])

    end_time = T

    while s.step(end_time):
        pass

    if len(s.world.get_particle_ids(C.id)) != 0:
        return 0, s.t

    pid1 = list(s.world.get_particle_ids(A.id))[0]
    pid2 = list(s.world.get_particle_ids(B.id))[0]
    p1 = s.world.get_particle(pid1)[1]
    p2 = s.world.get_particle(pid2)[1]
    distance = w.distance(p1.position, p2.position)

    return distance, s.t
Beispiel #12
0
def singlerun(T):

    sigma = 5e-9
    r0 = sigma
    D = 1e-12
    D_tot = D * 2

    kf = 100 * sigma * D_tot

    m = model.ParticleModel(1e-3)

    A = model.Species('A', D, sigma / 2)
    m.add_species_type(A)
    B = model.Species('B', D, sigma / 2)
    m.add_species_type(B)
    C = model.Species('C', D, sigma / 2)
    m.add_species_type(C)

    r1 = model.create_binding_reaction_rule(A, B, C, kf)
    m.network_rules.add_reaction_rule(r1)

    w = gfrdbase.create_world(m, 3)
    nrw = gfrdbase.create_network_rules_wrapper(m)
    s = _gfrd._EGFRDSimulator(w, nrw, myrandom.rng)

    class check_reactions:
        def __init__(self):
            self.reactions = []

        def __call__(self, ri):
            self.reactions.append(ri)

    cr = check_reactions()
    s.reaction_recorder = cr

    pid1 = gfrdbase.place_particle(w, A, [0, 0, 0])[0]
    pid2 = gfrdbase.place_particle(
        w, B, [float(A['radius']) + float(B['radius']) + 1e-23, 0, 0])[0]

    end_time = T

    while s.step(end_time):
        if len(cr.reactions) != 0:
            cr.reactions = []
            return 0, s.t

    p1 = s.world.get_particle(pid1)[1]
    p2 = s.world.get_particle(pid2)[1]

    distance = w.distance(p1.position, p2.position)

    return distance, s.t
Beispiel #13
0
def singlerun(T):

    sigma = 5e-9
    r0 = sigma
    D = 1e-12
    D_tot = D * 2

    tau = sigma * sigma / D_tot

    kf = 100 * sigma * D_tot
    koff = 0.1 / tau

    m = model.ParticleModel(1e-3)

    A = model.Species('A', D, sigma / 2)
    B = model.Species('B', D, sigma / 2)
    C = model.Species('C', D, sigma / 2)

    m.add_species_type(A)
    m.add_species_type(B)
    m.add_species_type(C)

    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, koff)
    m.network_rules.add_reaction_rule(r2)

    w = gfrdbase.create_world(m, 3)
    nrw = _gfrd.NetworkRulesWrapper(m.network_rules)
    s = _gfrd._EGFRDSimulator(w, nrw, myrandom.rng)

    place_particle(w, A, [0, 0, 0])
    place_particle(w, B,
                   [(float(A['radius']) + float(B['radius'])) + 1e-23, 0, 0])

    end_time = T

    while s.step(end_time):
        pass

    if len(s.world.get_particle_ids(C.id)) != 0:
        return 0, s.t

    pid1 = list(s.world.get_particle_ids(A.id))[0]
    pid2 = list(s.world.get_particle_ids(B.id))[0]
    p1 = s.world.get_particle(pid1)[1]
    p2 = s.world.get_particle(pid2)[1]
    distance = w.distance(p1.position, p2.position)

    return distance, s.t
Beispiel #14
0
 def setUp(self):
     self.m = model.ParticleModel(1e-5)
     self.S = model.Species("S", 2e-11, 5e-8)
     self.SS = model.Species("SS", 1e-12, 5e-9)
     self.A = model.Species("A", 0, 1e-8)
     self.B = model.Species("B", 2e-11, 5e-9)
     self.m.add_species_type(self.S)
     self.m.add_species_type(self.SS)
     self.m.add_species_type(self.A)
     self.m.add_species_type(self.B)
     self.m.set_all_repulsive()
     self.w = gfrdbase.create_world(self.m)
     self.nrw = _gfrd.NetworkRulesWrapper(self.m.network_rules)
     self.s = EGFRDSimulator(self.w, myrandom.rng, self.nrw)
Beispiel #15
0
def singlerun2(T):

    #s.set_user_max_shell_size(1e-7)
    #s.set_user_max_shell_size(1e-3)

    sigma = 5e-9
    r0 = sigma
    D = 1e-12
    D_tot = D * 2

    kf = 100 * sigma * D_tot

    m = model.ParticleModel(1e-3)

    A = model.Species('A', D, sigma / 2)
    m.add_species_type(A)
    B = model.Species('B', D, sigma / 2)
    m.add_species_type(B)
    C = model.Species('C', D, sigma / 2)
    m.add_species_type(C)

    r1 = model.create_binding_reaction_rule(A, B, C, kf)
    m.network_rules.add_reaction_rule(r1)

    w = gfrdbase.create_world(m, 3)
    nrw = gfrdbase.create_network_rules_wrapper(m)
    s = EGFRDSimulator(w, myrandom.rng, nrw)

    particleA = gfrdbase.place_particle(w, A, [0, 0, 0])
    particleB = gfrdbase.place_particle(
        w, B, [float(A['radius']) + float(B['radius']) + 1e-23, 0, 0])

    end_time = T

    while 1:
        s.step()
        if s.last_reaction:
            #print 'reaction'
            return 0.0, s.t

        next_time = s.get_next_time()
        if next_time > end_time:
            s.stop(end_time)
            break

    distance = w.distance(s.get_position(particleA), s.get_position(particleB))

    return distance, s.t
Beispiel #16
0
def singlerun2(T):

    #s.set_user_max_shell_size(1e-7)
    #s.set_user_max_shell_size(1e-3)

    sigma = 5e-9
    r0 = sigma
    D = 1e-12
    D_tot = D * 2

    kf = 100 * sigma * D_tot

    m = model.ParticleModel(1e-3)

    A = model.Species('A', D, sigma/2)
    m.add_species_type(A)
    B = model.Species('B', D, sigma/2)
    m.add_species_type(B)
    C = model.Species('C', D, sigma/2)
    m.add_species_type(C)

    r1 = model.create_binding_reaction_rule(A, B, C, kf)
    m.network_rules.add_reaction_rule(r1)

    w = gfrdbase.create_world(m, 3)
    nrw = gfrdbase.create_network_rules_wrapper(m)
    s = EGFRDSimulator(w, myrandom.rng, nrw)

    particleA = gfrdbase.place_particle(w, A, [0,0,0])
    particleB = gfrdbase.place_particle(w, B, [float(A['radius']) + float(B['radius'])+1e-23,0,0])

    end_time = T

    while 1:
        s.step()
        if s.last_reaction:
            #print 'reaction'
            return 0.0, s.t

        next_time = s.get_next_time()
        if next_time > end_time:
            s.stop(end_time)
            break

    distance = w.distance(s.get_position(particleA), s.get_position(particleB))

    return distance, s.t
Beispiel #17
0
def single_run(N, LOGGING):
    """ Single run of simulation """
    global w, A, C, k1, k2
    # Basic set up simulator
    # ===============================
    # Model
    m = model.ParticleModel(world_size)
    # Species
    A = model.Species('A', 0, sigma/2)                                   
    m.add_species_type(A) 
    B = model.Species('B', D, sigma/2)                                   
    m.add_species_type(B) 
    C = model.Species('C', 0, sigma/2)                                   
    m.add_species_type(C) 
    # Reaction rules
    r1 = model.create_binding_reaction_rule(A, B, C, k1)
    m.network_rules.add_reaction_rule(r1)
    r2 = model.create_unbinding_reaction_rule(C, A, B, k2)
    m.network_rules.add_reaction_rule(r2)

    # World
    w = gfrdbase.create_world(m, 3)
    # Simulator   
    s = EGFRDSimulator(w, myrandom.rng)

    # Put in cluster
    make_cluster(N, world_size/2, world_size/2, world_size/2)

    # Put in reactants
    # place_particle(w, B, [world_size/2, world_size/2, world_size/2+sigma+spacing])    

    # Enable VTK Logger
    # ===============================
    if (LOGGING == True):
        vtk_output_directory = 'VTK_out'
        if (os.path.exists(vtk_output_directory)):
            print '** Warning: VTK directory already exists.'
        l = vtklogger.VTKLogger(s, vtk_output_directory, extra_particle_step=True) 
    
    # Running 
    # ===============================
    numberDetected = 0

    if (LOGGING == True):
        while 1:
            l.log() # log
            s.step() # and make eGFRD step
            if s.last_reaction:
                numberDetected = numberDetected+1
                if (numberDetected == 2):
                    # print "2nd Reaction detected at: " + str(s.t) + "(" + str(s.last_reaction) + ")"
                    reaction_time = s.t - previous_time
                    break  
                else: previous_time = s.t
        l.stop() 
    else:
        while 1:
            s.step() # make eGFRD step
            if s.last_reaction:
                numberDetected = numberDetected+1
                if (numberDetected == 2):
                    # print "2nd Reaction detected at: " + str(s.t) + "(" + str(s.last_reaction) + ")"
                    reaction_time = s.t - previous_time
                    break  
                else: previous_time = s.t

    s.stop(s.t)
    return (reaction_time)
Beispiel #18
0
#_gfrd.PythonLoggerFactory.register_logger_factory(
#    ".*", _gfrd.PythonLoggerFactory())

m = model.ParticleModel(L)
S = model.Species('S', 1.5e-12, 5e-9)
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)
Beispiel #19
0
m.network_rules.add_reaction_rule(r4)
r5 = model.create_unimolecular_reaction_rule(ORp, ORpa, k_OC)
m.network_rules.add_reaction_rule(r5)
r6 = model.create_unbinding_reaction_rule(ORpa, T, O, 1 / t_clear)
m.network_rules.add_reaction_rule(r6)
r7 = model.create_decay_reaction_rule(M, k_dm)
m.network_rules.add_reaction_rule(r7)
r8 = model.create_unbinding_reaction_rule(M, M, Mribo, k_ribo)
m.network_rules.add_reaction_rule(r8)
r9 = model.create_unimolecular_reaction_rule(Mribo, P, 1 / t_trans)
m.network_rules.add_reaction_rule(r9)
r10 = model.create_decay_reaction_rule(P, k_dp)
m.network_rules.add_reaction_rule(r10)

# World
w = gfrdbase.create_world(m, 3)
# Simulator
s = EGFRDSimulator(w, myrandom.rng)

#####

#EMPTY = model.Species('EMPTY', 2e-12, 5e-8)

#  1 2 O + R <-> OR
#  3 4 O     <-> ORp
#  5   ORp    -> ORpa
#  6   ORpa   -> T + O
#  7   M      -> EMPTY
#  8   M      -> M + Mribo
#  9   Mribo  -> P
# 10   P      -> EMPTY
Beispiel #20
0
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
Beispiel #21
0
ES = model.Species('ES', D, R)
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
Beispiel #22
0
#_gfrd.PythonLoggerFactory.register_logger_factory(
#    ".*", _gfrd.PythonLoggerFactory())

m = model.ParticleModel(L)
S = model.Species('S', 1.5e-12, 5e-9)
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)
Beispiel #23
0
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
Beispiel #24
0
m.network_rules.add_reaction_rule(r4)
r5 = model.create_unimolecular_reaction_rule(ORp, ORpa, k_OC)
m.network_rules.add_reaction_rule(r5)
r6 = model.create_unbinding_reaction_rule(ORpa, T, O, 1/t_clear)
m.network_rules.add_reaction_rule(r6)
r7 = model.create_decay_reaction_rule(M, k_dm)
m.network_rules.add_reaction_rule(r7)
r8 = model.create_unbinding_reaction_rule(M, M, Mribo, k_ribo)
m.network_rules.add_reaction_rule(r8)
r9 = model.create_unimolecular_reaction_rule(Mribo, P, 1/t_trans)
m.network_rules.add_reaction_rule(r9)
r10 = model.create_decay_reaction_rule(P, k_dp)
m.network_rules.add_reaction_rule(r10)

# World
w = gfrdbase.create_world(m, 3)
# Simulator
s = EGFRDSimulator(w, myrandom.rng)

#####

#EMPTY = model.Species('EMPTY', 2e-12, 5e-8)

#  1 2 O + R <-> OR
#  3 4 O     <-> ORp
#  5   ORp    -> ORpa
#  6   ORpa   -> T + O
#  7   M      -> EMPTY
#  8   M      -> M + Mribo
#  9   Mribo  -> P
# 10   P      -> EMPTY