Exemplo n.º 1
0
    def set_model(self, model):
        model.set_all_repulsive()
        model.set_default_surface_size(self.world.world_size)

        for st in model.species_types:
            if st["surface"] == "":
                st["surface"] = self.model.default_surface.name

            try:
                self.world.get_species(st.id)
            except:
                self.world.add_species(_gfrd.SpeciesInfo(st.id, 
                                                   float(st["D"]), 
                                                   float(st["radius"]), 
                                                   st["surface"]))
            # else: keep particle data for this species.

        for surface in itertools.chain(model.surface_list.itervalues(), [model.default_surface]):
            _surface_class = self.surface_conv_map.get(type(surface))
            if _surface_class is None:
                raise NotImplementedError("Unsupported surface type: %s" % surface)
            _surface = _surface_class(surface.name, surface.shape)
            self.world.add_surface(_surface)

        self.network_rules = _gfrd.NetworkRulesWrapper(model.network_rules)
        self.model = model
Exemplo n.º 2
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
Exemplo n.º 3
0
 def setUp(self):
     self.m = _gfrd.Model()
     self.s1 = self.m.new_species_type()
     self.s1['radius'] = '0.1'
     self.s1['D'] = '0.2'
     self.s2 = self.m.new_species_type()
     self.s2['radius'] = '0.3'
     self.s2['D'] = '0.4'
     self.nr = _gfrd.NetworkRulesWrapper(self.m.network_rules)
Exemplo n.º 4
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)
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
0
def get_reaction_rules(model_or_simulator):
    """Return three lists with all the reaction rules defined in the 
    ParticleModel or EGFRDSimulator.

    The three lists are:
        - reaction rules of only one reactant.
        - reaction rules between two reactants with a reaction rate 
          larger than 0.
        - repulsive reaction rules between two reactants with a 
          reaction rate equal to 0.

    Arguments:
        - model_or_simulator
            a ParticleModel or EGFRDSimulator.

    """
    if isinstance(model_or_simulator, EGFRDSimulator):
        model = model_or_simulator.world.model
    else:
        model = model_or_simulator

    # Return 3 lists with different types of reaction rules.
    reaction_rules_1 = []
    reaction_rules_2 = []
    repulsive_rules = []

    # Wrap the network_rules first, the iterator over the products
    # of the unwrapped one fails when there are no products.
    network_rules = _gfrd.NetworkRulesWrapper(model.network_rules)

    for index_of_si1, si1 in enumerate(model.species_types):
        rri_vector = network_rules.query_reaction_rule(si1)
        for rr_info in rri_vector:
            reaction_rules_1.append(rr_info)
        for si2 in list(model.species_types)[index_of_si1:]:
            rri_vector = network_rules.query_reaction_rule(si1, si2)
            for rr_info in rri_vector:
                if rr_info.k > 0:
                    reaction_rules_2.append(rr_info)
                else:
                    repulsive_rules.append(rr_info)

    return reaction_rules_1, reaction_rules_2, repulsive_rules
Exemplo n.º 8
0
def create_network_rules_wrapper(model):
    return _gfrd.NetworkRulesWrapper(model.network_rules)
Exemplo n.º 9
0
S2 = m.new_species_type()
S2['D'] = '.01'
S2['radius'] = '.01'
S2['surface'] = 'default'

colors = {
    S0.id: (1., 0., 0.),
    S1.id: (0., 1., 0.),
    S2.id: (1., 1., 0.),
}

rr = _gfrd.ReactionRule((S0, S1), (S2, ))
rr['k'] = '.01'
m.network_rules.add_reaction_rule(rr)

nrw = _gfrd.NetworkRulesWrapper(m.network_rules)


class MyParticleContainer(_gfrd._ParticleContainer):
    def __init__(self, world_size):
        _gfrd._ParticleContainer.__init__(self)
        self.particles = {}
        self.surfaces = {}
        self.species = {}
        self.pidgen = _gfrd.ParticleIDGenerator(0)
        self.world_size = world_size

    def add_surface(self, surface):
        self.surfaces[surface.id] = surface

    def add_species(self, species):