Exemple #1
0
def __get_kinetic_law(sbml_model, gillespy_model, reaction):
    kinetic_law = reaction.getKineticLaw()

    if kinetic_law is None:
        raise gillespyError.InvalidModelError(
            f"Failed to load SBML model: Reaction '{reaction}' is missing its propensity function."
        )

    tree = kinetic_law.getMath()
    params = kinetic_law.getListOfParameters()
    local_params = kinetic_law.getListOfLocalParameters()
    for i in range(kinetic_law.getNumLocalParameters()):
        lp = local_params.get(i)
        old_id = lp.getId()
        new_id = ('{}_{}'.format(reaction.getId(), lp.getId()))
        traverse_math(tree, old_id, new_id)
        lp.setId(new_id)
        gillespy_parameter = gillespy2.Parameter(name=new_id, expression=lp.getValue())
        gillespy_model.add_parameter([gillespy_parameter])
    for i in range(kinetic_law.getNumParameters()):
        p = params.get(i)
        if not p.getId() in gillespy_model.listOfParameters:
            gillespy_parameter = gillespy2.Parameter(name=p.getId(), expression=p.getValue())
            gillespy_model.add_parameter([gillespy_parameter])
    return tree
    def test_compile_w_spaces(self):
        import gillespy2
        self.solvers = [
            gillespy2.ODECSolver, gillespy2.SSACSolver,
            gillespy2.TauLeapingCSolver, gillespy2.TauHybridCSolver
        ]

        # create a model
        model = gillespy2.Model(name="Michaelis_Menten")

        # parameters
        rate1 = gillespy2.Parameter(name='rate1', expression=0.0017)
        rate2 = gillespy2.Parameter(name='rate2', expression=0.5)
        rate3 = gillespy2.Parameter(name='rate3', expression=0.1)
        model.add_parameter([rate1, rate2, rate3])

        # Species
        A = gillespy2.Species(name='A', initial_value=301)
        B = gillespy2.Species(name='B', initial_value=120)
        C = gillespy2.Species(name='C', initial_value=0)
        D = gillespy2.Species(name='D', initial_value=0)
        model.add_species([A, B, C, D])

        # reactions
        r1 = gillespy2.Reaction(name="r1",
                                reactants={
                                    A: 1,
                                    B: 1
                                },
                                products={C: 1},
                                rate=rate1)

        r2 = gillespy2.Reaction(name="r2",
                                reactants={C: 1},
                                products={
                                    A: 1,
                                    B: 1
                                },
                                rate=rate2)

        r3 = gillespy2.Reaction(name="r3",
                                reactants={C: 1},
                                products={
                                    B: 1,
                                    D: 1
                                },
                                rate=rate3)
        model.add_reaction([r1, r2, r3])
        model.timespan(gillespy2.TimeSpan.linspace(t=100, num_points=101))

        # run the model
        for solver in self.solvers:
            with self.subTest(solver=solver.name):
                if platform.system() == "Windows":
                    with self.assertRaises(gillespy2.SimulationError):
                        model.run(solver=solver)
                else:
                    result = model.run(solver=solver)
                    self.assertTrue(gillespy2.__file__ == os.path.join(
                        self.prefix_base_dir, 'A SPACE/gillespy2/__init__.py'))
 def create_event_test_model(parameter_values=None):
     model = gillespy2.Model(name='Event Test Model')
     model.add_species([gillespy2.Species(name='S', initial_value=0)])
     model.add_parameter(
         gillespy2.Parameter(name='event_tracker', expression=99))
     model.add_parameter(
         gillespy2.Parameter(name='event_tracker2', expression=0))
     model.add_reaction(
         gillespy2.Reaction(
             name='r1',
             products={'S': 1},
             rate=model.listOfParameters['event_tracker2']))
     eventTrig1 = gillespy2.EventTrigger(expression='t>=2')
     event1 = gillespy2.Event(name='event1', trigger=eventTrig1)
     event1.add_assignment(
         gillespy2.EventAssignment(variable='event_tracker',
                                   expression='t'))
     eventTrig2 = gillespy2.EventTrigger(
         expression='t >= event_tracker + 2')
     event2 = gillespy2.Event(name='event2', trigger=eventTrig2)
     event2.add_assignment(
         gillespy2.EventAssignment(variable='event_tracker2',
                                   expression='t'))
     model.add_event([event1, event2])
     return model
Exemple #4
0
    def __init__(self, parameter_values=None):
        # Initialize the model.
        gillespy2.Model.__init__(self, name="toggle_switch")
        # Parameters
        alpha1 = gillespy2.Parameter(name='alpha1', expression=1)
        alpha2 = gillespy2.Parameter(name='alpha2', expression=1)
        beta = gillespy2.Parameter(name='beta', expression="2.0")
        gamma = gillespy2.Parameter(name='gamma', expression="2.0")
        mu = gillespy2.Parameter(name='mu', expression=1.0)
        self.add_parameter([alpha1, alpha2, beta, gamma, mu])

        # Species
        U = gillespy2.Species(name='U', initial_value=10)
        V = gillespy2.Species(name='V', initial_value=10)
        self.add_species([U, V])

        # Reactions
        cu = gillespy2.Reaction(name="r1",
                                reactants={},
                                products={U: 1},
                                propensity_function="alpha1/(1+pow(V,beta))")
        cv = gillespy2.Reaction(name="r2",
                                reactants={},
                                products={V: 1},
                                propensity_function="alpha2/(1+pow(U,gamma))")
        du = gillespy2.Reaction(name="r3",
                                reactants={U: 1},
                                products={},
                                rate=mu)
        dv = gillespy2.Reaction(name="r4",
                                reactants={V: 1},
                                products={},
                                rate=mu)
        self.add_reaction([cu, cv, du, dv])
        self.timespan(np.linspace(0, 50, 101))
Exemple #5
0
    def __init__(self, parameter_values=None):
        # First call the gillespy2.Model initializer.
        super().__init__(self)

        # Define parameters for the rates of creation and dissociation.
        k_c = gillespy2.Parameter(name='k_c', expression=0.005)
        k_d = gillespy2.Parameter(name='k_d', expression=0.08)
        self.add_parameter([k_c, k_d])

        # Define variables for the molecular species representing M and D.
        m = gillespy2.Species(name='monomer', initial_value=30)
        d = gillespy2.Species(name='dimer', initial_value=0)
        self.add_species([m, d])

        # Define the reactions representing the process.  In GillesPy2,
        # the list of reactants and products for a Reaction object are each a
        # Python dictionary in which the dictionary keys are Species objects
        # and the values are stoichiometries of the species in the reaction.
        r_creation = gillespy2.Reaction(name="r_creation",
                                        rate=k_c,
                                        reactants={m: 2},
                                        products={d: 1})
        r_dissociation = gillespy2.Reaction(name="r_dissociation",
                                            rate=k_d,
                                            reactants={d: 1},
                                            products={m: 2})
        self.add_reaction([r_creation, r_dissociation])

        # Set the timespan for the simulation.
        self.timespan(numpy.linspace(0, 100, 101))
        def create_boundary_condition_test_model(parameter_values=None):
            model = gillespy2.Model(name="BoundaryConditionTestModel")
            s1 = gillespy2.Species(name="S1", boundary_condition=True, initial_value=0.001, mode='continuous')
            s2 = gillespy2.Species(name="S2", boundary_condition=False, initial_value=0.002, mode='continuous')
            s3 = gillespy2.Species(name="S3", boundary_condition=False, initial_value=0.001, mode='continuous')
            s4 = gillespy2.Species(name="S4", boundary_condition=True, initial_value=0.002, mode='continuous')
            model.add_species([s1, s2, s3, s4])

            k1 = gillespy2.Parameter(name="k1", expression="0.75")
            k2 = gillespy2.Parameter(name="k2", expression="0.25")
            model.add_parameter([k1, k2])

            reaction1 = gillespy2.Reaction(name="reaction1", propensity_function="vol*k1*S1*S2",
                                           reactants={s1: 1, s2: 1},
                                           products={s3: 1})
            reaction2 = gillespy2.Reaction(name="reaction2", propensity_function="vol*k2*S3",
                                           reactants={s3: 1},
                                           products={s1: 1, s2: 1})
            reaction3 = gillespy2.Reaction(name="reaction3", propensity_function="vol*k2*S3",
                                           reactants={s1: 1, s2: 2, s3: 1},
                                           products={s4: 1})
            model.add_reaction([reaction1, reaction2, reaction3])

            model.timespan(numpy.linspace(0, 20, 51))
            return model
        def __init__(self, t, s0, i0, r0, beta, gamma):
            # First call the gillespy2.Model initializer.
            gillespy2.Model.__init__(self, name='StochasticSIR')

            # Define parameters for the rates of creation and dissociation.
            k_i = gillespy2.Parameter(name='k_i', expression=beta / N)
            k_r = gillespy2.Parameter(name='k_r', expression=gamma)
            self.add_parameter([k_i, k_r])

            # Define variables for the molecular species representing M and D.
            s = gillespy2.Species(name='S', initial_value=s0)
            i = gillespy2.Species(name='I', initial_value=i0)
            r = gillespy2.Species(name='R', initial_value=r0)
            self.add_species([s, i, r])

            # The list of reactants and products for a Reaction object are each a
            # Python dictionary in which the dictionary keys are Species objects
            # and the values are stoichiometries of the species in the reaction.
            r_i = gillespy2.Reaction(name="infection",
                                     rate=k_i,
                                     reactants={
                                         s: 1,
                                         i: 1
                                     },
                                     products={i: 2})
            r_r = gillespy2.Reaction(name="recovery",
                                     rate=k_r,
                                     reactants={i: 1},
                                     products={r: 1})
            self.add_reaction([r_i, r_r])

            # Set the timespan for the simulation.
            self.timespan(t)
Exemple #8
0
    def __init__(self, parameter_values=None, init_v=1):
        #initialize Model
        gillespy2.Model.__init__(self, name="Simple_Hybrid_Model")

        #Species
        A = gillespy2.Species(name='A', initial_value=init_v)
        V = gillespy2.Species(name='V', initial_value=init_v)

        self.add_species([A, V])

        #parameters
        rate1 = gillespy2.Parameter(name='rate1', expression=20.0)
        rate2 = gillespy2.Parameter(name='rate2', expression=10.0)
        #             rate_rule1 = gillespy2.RateRule(V, "cos(t)")
        self.add_parameter([rate1, rate2])
        #             self.add_rate_rule(rate_rule1)

        #reactions
        r1 = gillespy2.Reaction(name="r1",
                                reactants={},
                                products={A: 1},
                                propensity_function="rate1 * V")

        r2 = gillespy2.Reaction(name="r2",
                                reactants={A: 1},
                                products={},
                                rate=rate2)

        self.add_reaction([r1, r2])
        self.timespan(numpy.linspace(0, 100, 101))
    def __init__(self, parameter_values=None):

        # Initialize the model.
        gillespy2.Model.__init__(self, name="simple1")

        # Parameters
        k1 = gillespy2.Parameter(name='k1', expression=parameter_values[0])
        k2 = gillespy2.Parameter(name='k2', expression=parameter_values[1])
        k3 = gillespy2.Parameter(name='k3', expression=parameter_values[2])
        self.add_parameter([k1, k2, k3])

        # Species
        S1 = gillespy2.Species(name='S1', initial_value=100)
        S2 = gillespy2.Species(name='S2', initial_value=0)
        self.add_species([S1, S2])

        # Reactions
        rxn1 = gillespy2.Reaction(name='S1 production',
                                  reactants={},
                                  products={S1: 1},
                                  rate=k1)

        rxn2 = gillespy2.Reaction(name='dimer formation',
                                  reactants={S1: 2},
                                  products={S2: 1},
                                  rate=k2)

        rxn3 = gillespy2.Reaction(name='dimer degradation',
                                  reactants={S2: 1},
                                  products={},
                                  rate=k3)

        self.add_reaction([rxn1, rxn2, rxn3])
        self.timespan(np.linspace(0, 100, 101))
Exemple #10
0
def cbsa2gillespy(cbsa_model):
    import gillespy2 as glp
    
    gilles = glp.Model(name="Model")

    k = [glp.Parameter(name='k'+str(i), expression=cbsa_model.exp_k[i]) for i in range(1,cbsa_model.exp_n_reactions)]
    gilles.add_parameter(k)
    mols = [glp.Species(name='M'+str(i), initial_value=int(cbsa_model.exp_x0[i])) for i in range(1,cbsa_model.exp_n_molecules)]
    gilles.add_species(mols)
    
    reactions = []
    
    for i in range(1,cbsa_model.exp_n_reactions):
        reactants = list(np.where(cbsa_model.expS[:,i] < 0)[0])
        reactants_sto = list(cbsa_model.expS[:,i][reactants]*-1)
        modifiers = list(np.where(cbsa_model.expR[:,i] > 0)[0])
        modifiers_sto = list(cbsa_model.expR[:,i][modifiers])
        products = list(np.where(cbsa_model.expS[:,i] > 0)[0])
        products_sto = list(cbsa_model.expS[:,i][products])
        
        reactants += modifiers
        reactants_sto += modifiers_sto
        products += modifiers
        products_sto += modifiers_sto
        
        reactions.append(glp.Reaction(name="R"+str(i),
                                      rate=k[i-1],
                                      reactants={mols[reactants[j]-1]:reactants_sto[j] for j in range(len(reactants))},
                                      products={mols[products[j]-1]:products_sto[j] for j in range(len(products))}
                                     )
                        )
    
    gilles.add_reaction(reactions)
    
    return gilles
Exemple #11
0
    def __init__(self, parameter_values=None, volume=1.0):

        # Initialize the model.
        gillespy2.Model.__init__(self, name="simple1", volume=volume)

        # Parameters
        k1 = gillespy2.Parameter(name='k1', expression=0.03)
        self.add_parameter(k1)

        # Species
        r1 = gillespy2.Species(name='r1', initial_value=100)
        self.add_species(r1)
        r2 = gillespy2.Species(name='r2', initial_value=100)
        self.add_species(r2)

        # Reactions
        rxn1 = gillespy2.Reaction(name='r1d',
                                  reactants={r1: 2},
                                  products={},
                                  rate=k1)

        self.add_reaction(rxn1)

        rxn2 = gillespy2.Reaction(name='r2d',
                                  reactants={r2: 2},
                                  products={},
                                  propensity_function='k1/2 * r2*(r2-1)/vol')

        self.add_reaction(rxn2)
Exemple #12
0
    def test_model_add__multiple_components__in_order(self):
        import gillespy2

        s1 = gillespy2.Species(name="s1", initial_value=29)
        k1 = gillespy2.Parameter(name="k1", expression=29)
        r1 = gillespy2.Reaction(name="r1", reactants={"s1": 1}, rate="k1")
        rr1 = gillespy2.RateRule(name="rr1", variable="k1", formula="29")
        ar1 = gillespy2.AssignmentRule(name="ar1", variable="s1", formula="29")
        ea = gillespy2.EventAssignment(name="ea",
                                       variable="k1",
                                       expression="29")
        et = gillespy2.EventTrigger(expression="t > 29")
        e1 = gillespy2.Event(name="e1", trigger=et, assignments=[ea])
        divide = gillespy2.FunctionDefinition(name="divide",
                                              function="x / y",
                                              args=["x", "y"])
        tspan = gillespy2.TimeSpan(range(100))

        model = gillespy2.Model(name="Test Model")
        model.add([s1, k1, r1, rr1, ar1, e1, divide, tspan])

        self.assertIn("ar1", model.listOfAssignmentRules)
        self.assertIn("e1", model.listOfEvents)
        self.assertIn("divide", model.listOfFunctionDefinitions)
        self.assertIn("k1", model.listOfParameters)
        self.assertIn("rr1", model.listOfRateRules)
        self.assertIn("r1", model.listOfReactions)
        self.assertIn("s1", model.listOfSpecies)
        self.assertEqual(tspan, model.tspan)
Exemple #13
0
    def __init__(self, parameter_values=None):
        # First call the gillespy2.Model initializer.
        super().__init__(self)

        # Define a parameter that represents the rate of decay.
        decayrate = gillespy2.Parameter(name='decayrate', expression=0.05)
        self.add_parameter([decayrate])

        # Define a molecular species representing the protein; "initial_value"
        # sets the number of molecules initial present of simulation.
        protein = gillespy2.Species(name='protein', initial_value=50)
        self.add_species([protein])

        # Define the reaction representing the decay process.  In GillesPy2,
        # the list of reactants and products for a Reaction object are each a
        # Python dictionary in which the dictionary keys are Species objects
        # and the values are stoichiometries of the species in the reaction.
        # (In this example, we have only one reactant, and no products.) The
        # "rate" for the Reaction object is a Parameter representing the
        # propensity of this reaction firing.)
        reaction = gillespy2.Reaction(name="decay",
                                      rate=decayrate,
                                      reactants={protein: 1},
                                      products={})
        self.add_reaction([reaction])

        # Set the timespan for the simulation.
        self.timespan(numpy.linspace(0, 100, 101))
def create_protein_decay(parameter_values=None):
    # Instantiate Model
    model = gillespy2.Model(name="Protein Decay")

    # Define Variables (GillesPy2.Species)
    protein = gillespy2.Species(name='protein', initial_value=50)

    # Add Variables to Model
    model.add_species(protein)

    # Define Parameters
    decayrate = gillespy2.Parameter(name='decayrate', expression=0.05)

    # Add Parameters to Model
    model.add_parameter(decayrate)

    # Define Reactions
    reaction = gillespy2.Reaction(
        name="decay", rate='decayrate', reactants={'protein': 1}, products={}
    )

    # Add Reactions to Model
    model.add_reaction(reaction)

    # Define Timespan
    tspan = gillespy2.TimeSpan.linspace(t=100, num_points=101)

    # Set Model Timespan
    model.timespan(tspan)
    return model
Exemple #15
0
 def test_math_name_overlap(self):
     gamma = gillespy2.Species('gamma',initial_value=2, mode='continuous')
     self.model.add_species([gamma])
     k2 = gillespy2.Parameter(name='k2', expression=1)
     self.model.add_parameter([k2])
     gamma_react = gillespy2.Reaction(name='gamma_react', reactants={'gamma':1}, products={}, rate=k2)
     self.model.add_reaction([gamma_react])
     self.model.run(solver=BasicTauHybridSolver)
Exemple #16
0
    def __init__(self, endtime, timestep):
        """
        Initialize the model.

        Parameters
        ----------
        endtime : endtime of simulations
        timestep : time-step of simulations
        """
        super().__init__(
            endtime=endtime,
            timestep=timestep,
            model_name="SIR",
        )

        beta = gillespy.Parameter(name='beta', expression=self.params['beta'])
        gamma = gillespy.Parameter(name='gamma',
                                   expression=self.params['gamma'])
        self.add_parameter([beta, gamma])

        # Species
        S = gillespy.Species(name='S', initial_value=100)
        I = gillespy.Species(name='I', initial_value=100)
        R = gillespy.Species(name='R', initial_value=100)
        self.add_species([S, I, R])

        # Reactions
        infection = gillespy.Reaction(
            name='infection',
            reactants={
                S: 1,
                I: 1
            },
            products={I: 2},
            propensity_function='beta*S*I/(S+I+R)',
        )
        recover = gillespy.Reaction(
            name='recover',
            reactants={I: 1},
            products={R: 1},
            rate=gamma,
        )
        self.add_reaction([infection, recover])
        nb_of_steps = int(math.ceil((endtime / timestep))) + 1
        self.timespan(np.linspace(0, endtime, nb_of_steps))
 def __init__(self):
     gillespy2.Model.__init__(self, name='Event Test Model')
     self.add_species([gillespy2.Species(name='S', initial_value=0)])
     self.add_parameter(gillespy2.Parameter(name='event_tracker',
                                             expression=99))
     self.add_parameter(gillespy2.Parameter(name='event_tracker2',
                                             expression=0))
     self.add_reaction(gillespy2.Reaction(name='r1', products={'S':1},
                                         rate=self.listOfParameters['event_tracker2']))
     eventTrig1 = gillespy2.EventTrigger(expression='t>=2')
     event1 = gillespy2.Event(name='event1', trigger=eventTrig1)
     event1.add_assignment(gillespy2.EventAssignment(
                             variable='event_tracker', expression='t'))
     eventTrig2 = gillespy2.EventTrigger(expression='t >= event_tracker + 2')
     event2 = gillespy2.Event(name='event2', trigger=eventTrig2)
     event2.add_assignment(gillespy2.EventAssignment(
                             variable='event_tracker2', expression='t'))
     self.add_event([event1, event2])
Exemple #18
0
 def __init__(self, parameter_values=None):
     gillespy2.Model.__init__(self, name='StochTest1')
     A = gillespy2.Species(name='A', initial_value=10)
     B = gillespy2.Species(name='B', initial_value=0)
     self.add_species([A, B])
     k = gillespy2.Parameter(name='k', expression=10)
     self.add_parameter([k])
     r = gillespy2.Reaction(name='r', reactants={A: 2}, products={B:1}, rate=k)
     self.add_reaction([r])
     self.timespan(np.linspace(0, 100, 101))
Exemple #19
0
def __get_compartments(sbml_model, gillespy_model):
    for i in range(sbml_model.getNumCompartments()):
        compartment = sbml_model.getCompartment(i)
        name = compartment.getId()
        value = compartment.getSize()

        gillespy_parameter = gillespy2.Parameter(name=name, expression=value)
        init_state[name] = value
        gillespy_model.add_parameter([gillespy_parameter])
    '''
Exemple #20
0
def __get_kinetic_law(sbml_model, gillespy_model, reaction):
    kinetic_law = reaction.getKineticLaw()
    tree = kinetic_law.getMath()
    params = kinetic_law.getListOfParameters()
    local_params = kinetic_law.getListOfLocalParameters()
    for i in range(kinetic_law.getNumLocalParameters()):
        lp = local_params.get(i)
        old_id = lp.getId()
        new_id = ('{}_{}'.format(reaction.getId(), lp.getId()))
        traverse_math(tree, old_id, new_id)
        lp.setId(new_id)
        gillespy_parameter = gillespy2.Parameter(name=new_id, expression=lp.getValue())
        gillespy_model.add_parameter([gillespy_parameter])
    for i in range(kinetic_law.getNumParameters()):
        p = params.get(i)
        if not p.getId() in gillespy_model.listOfParameters:
            gillespy_parameter = gillespy2.Parameter(name=p.getId(), expression=p.getValue())
            gillespy_model.add_parameter([gillespy_parameter])
    return tree
    def __init__(self, parameter_values=None):
        # First call the gillespy2.Model initializer.
        gillespy2.Model.__init__(self, name='Repressilator')

        # Define parameters for the rates of creation and dissociation.
        alpha=gillespy2.Parameter(name="alpha", expression=216)
        alpha_0=gillespy2.Parameter(name="alpha_0",expression=0.216)
        beta=gillespy2.Parameter(name="beta",expression=0.8)
        self.add_parameter([alpha, alpha_0, beta])

        # Define variables for the molecular species representing M and D.
        m_lacI= gillespy2.Species(name='m_lacI', initial_value=30)
        p_lacI= gillespy2.Species(name='p_lacI', initial_value=0)
        m_tetR= gillespy2.Species(name='m_tetR', initial_value=0)
        p_tetR= gillespy2.Species(name='p_tetR', initial_value=0)
        m_cI= gillespy2.Species(name='m_cI', initial_value=0)
        p_cI= gillespy2.Species(name='p_cI', initial_value=0)
        self.add_species([m_lacI, p_lacI, p_tetR, m_tetR, m_cI, p_cI])

        # The list of reactants and products for a Reaction object are each a
        # Python dictionary in which the dictionary keys are Species objects
        # and the values are stoichiometries of the species in the reaction.
        
        m_1 = gillespy2.Reaction(name="m_1", rate=alpha/(1 + p_cI), reactants={m_lacI:1}, products={m_lacI:2+alpha_0})
        m_2 = gillespy2.Reaction(name="m_2", rate=1, reactants={m_lacI:1}, products={m_lacI:0})
        p_1 = gillespy2.Reaction(name="p_1", rate=beta, reactants={p_lacI:1}, products={p_lacI:2+m_lacI})                       
        p_2 = gillespy2.Reaction(name="p_2", rate=beta, reactants={p_lacI:1}, products={p_lacI:0})                                   
        
        m_3 = gillespy2.Reaction(name="m_3", rate=alpha/(1+p_lacI), reactants={m_tetR:1}, products={m_tetR:2+alpha_0})
        m_4 = gillespy2.Reaction(name="m_4", rate=1, reactants={m_tetR:1}, products={m_tetR:0})
        p_3 = gillespy2.Reaction(name="p_3", rate=beta, reactants={p_tetR:1}, products={p_tetR:2+m_tetR})                  
        p_4 = gillespy2.Reaction(name="p_4", rate=beta, reactants={p_tetR:1}, products={p_tetR:0})
        
        m_5 = gillespy2.Reaction(name="m_5", rate=alpha/(1+p_tetR), reactants={m_cI:1}, products={m_cI:2+alpha_0})
        m_6 = gillespy2.Reaction(name="m_6", rate=1, reactants={m_cI:1}, products={m_cI:0})
        p_5 = gillespy2.Reaction(name="p_5", rate=beta, reactants={p_cI:1}, products={p_cI:2+m_cI})                  
        p_6 = gillespy2.Reaction(name="p_6", rate=beta, reactants={p_cI:1}, products={p_cI:0})
        
        self.add_reaction([m_1,m_2,m_3,m_4,m_5,m_6,p_1,p_2,p_3,p_4,p_5,p_6])
        
        # Set the timespan for the simulation.
        self.timespan(numpy.linspace(0, 100, 101))
Exemple #22
0
 def create_stoch_test_1(parameter_values=None):
     model = gillespy2.Model(name='StochTest1')
     A = gillespy2.Species(name='A', initial_value=10)
     B = gillespy2.Species(name='B', initial_value=0)
     model.add_species([A, B])
     k = gillespy2.Parameter(name='k', expression=10)
     model.add_parameter([k])
     r = gillespy2.Reaction(name='r',
                            reactants={A: 2},
                            products={B: 1},
                            rate=k)
     model.add_reaction([r])
     model.timespan(np.linspace(0, 100, 101))
     return model
Exemple #23
0
def create_dimerization(parameter_values=None):
    # Initialize Model
    model = gillespy2.Model(name="Dimerization")

    # Define Variables (GillesPy2.Species)
    m = gillespy2.Species(name='monomer', initial_value=30)
    d = gillespy2.Species(name='dimer', initial_value=0)

    # Add Variables to Model
    model.add_species([m, d])

    # Define Parameters
    k_c = gillespy2.Parameter(name='k_c', expression=0.005)
    k_d = gillespy2.Parameter(name='k_d', expression=0.08)

    # Add Parameters to Model
    model.add_parameter([k_c, k_d])

    # Define Reactions
    r_creation = gillespy2.Reaction(name="r_creation",
                                    reactants={'monomer': 2},
                                    products={'dimer': 1},
                                    rate='k_c')
    r_dissociation = gillespy2.Reaction(name="r_dissociation",
                                        reactants={'dimer': 1},
                                        products={'monomer': 2},
                                        rate='k_d')

    # Add Reactions to Model
    model.add_reaction([r_creation, r_dissociation])

    # Define Timespan
    tspan = gillespy2.TimeSpan.linspace(t=100, num_points=101)

    # Set Model Timespan
    model.timespan(tspan)
    return model
Exemple #24
0
 def create_stoch_test_1(parameter_values=None):
     model = gillespy2.Model(name='StochTest1')
     A = gillespy2.Species(name='A', initial_value=10)
     B = gillespy2.Species(name='B', initial_value=0)
     model.add_species([A, B])
     k = gillespy2.Parameter(name='k', expression=10)
     model.add_parameter([k])
     r = gillespy2.Reaction(name='r',
                            reactants={A: 1},
                            products={B: 1},
                            propensity_function="k*A/vol"
                            )  # testing if 'vol' is a pre-set variable
     model.add_reaction([r])
     model.timespan(np.linspace(0, 100, 101))
     return model
Exemple #25
0
def __get_parameters(sbml_model, gillespy_model):

    for i in range(sbml_model.getNumParameters()):
        parameter = sbml_model.getParameter(i)
        name = parameter.getId()
        value = parameter.getValue()
        init_state[name] = value

        # GillesPy2 represents non-constant parameters as species
        if parameter.isSetConstant():
            gillespy_parameter = gillespy2.Parameter(name=name, expression=value)
            gillespy_model.add_parameter([gillespy_parameter])
        else:
            gillespy_species = gillespy2.Species(name=name,initial_value=value)
            gillespy_model.add_species([gillespy_species])
Exemple #26
0
    def convert_rates(self):
        '''
            Method to convert rate constants from non-gillespy2 Random DNA Chemistry to the gillespy2 Random DNA Chemistry
        '''

        gillespy2_rates = []

        for index_bind, (r_bind, rate_bind) in enumerate(
                self.randomDNAChem.rateConst_lookup['rate_BIND'].items()):
            name_bind = 'bind{}'.format(index_bind)
            gillespy2_kbind = gillespy2.Parameter(name=name_bind,
                                                  expression=rate_bind[0])
            gillespy2_rates.append(gillespy2_kbind)

        for index_displace, (r_displace, rate_displace) in enumerate(
                self.randomDNAChem.rateConst_lookup['rate_DISPLACE'].items()):
            name_displace = 'displace{}'.format(index_displace)
            gillespy2_kdisplace = gillespy2.Parameter(
                name=name_displace, expression=rate_displace[0])
            gillespy2_rates.append(gillespy2_kdisplace)

        for index_in, (r_in, rate_in) in enumerate(
                self.randomDNAChem.rateConst_lookup['rate_IN'].items()):
            name_in = 'influx{}'.format(index_in)
            gillespy2_kin = gillespy2.Parameter(
                name=name_in, expression=rate_in[self.rate_in_timeIndex])
            gillespy2_rates.append(gillespy2_kin)

        for index_out, (r_out, rate_out) in enumerate(
                self.randomDNAChem.rateConst_lookup['rate_OUT'].items()):
            name_out = 'efflux{}'.format(index_out)
            gillespy2_kout = gillespy2.Parameter(name=name_out,
                                                 expression=rate_out[0])
            gillespy2_rates.append(gillespy2_kout)

        self.add_parameter(gillespy2_rates)
Exemple #27
0
def __get_compartments(sbml_model, gillespy_model):
    for i in range(sbml_model.getNumCompartments()):
        compartment = sbml_model.getCompartment(i)
        name = compartment.getId()
        if compartment.isSetSize():
            value = compartment.getSize()
        else:
            value = 1

        if name == "vol":
            gillespy_model.volume = value
        else:
            gillespy_parameter = gillespy2.Parameter(name=name, expression=value)
            init_state[name] = value
            gillespy_model.add_parameter([gillespy_parameter])

    '''
        def create_rate_rule_test_model(parameter_values=None):
            model = gillespy2.Model(name="RateRuleTestModel")
            s1 = gillespy2.Species(name="S1", initial_value=0.015, mode='continuous')
            s2 = gillespy2.Species(name="S2", initial_value=0.0, mode='continuous')
            s3 = gillespy2.Species(name="S3", initial_value=1.0, mode='continuous')
            model.add_species([s1, s2, s3])

            k1 = gillespy2.Parameter(name="k1", expression="1.0")
            model.add_parameter([k1])

            rule1 = gillespy2.RateRule(name="rule1", variable="S1", formula="-k1*S1")
            rule2 = gillespy2.RateRule(name="rule2", variable="S2", formula="k1*S1")
            rule3 = gillespy2.RateRule(name="rule3", variable="S3", formula="0.015-(S1+S2)")
            model.add_rate_rule([rule1, rule2, rule3])

            model.timespan(numpy.linspace(0, 20, 51))
            return model
    def create_base_event_model(s1, s2, rate):
        model = gillespy2.Model(name="BasicEventModel")

        s1 = gillespy2.Species(name="S1", initial_value=s1, mode="continuous")
        s2 = gillespy2.Species(name="S2", initial_value=s2, mode="continuous")
        model.add_species([s1, s2])

        rate = gillespy2.Parameter(name="k1", expression=rate)
        model.add_parameter(rate)

        r1 = gillespy2.Reaction(
            name="r1",
            reactants={s1: 1},
            products={s2: 1},
            rate=rate,
        )
        model.add_reaction(r1)
        return model
Exemple #30
0
 def test_random_seed_unnamed_reactions(self):
     model = self.model
     k2 = gillespy2.Parameter(name='k2', expression=1.0)
     model.add_parameter([k2])
     unnamed_rxn = gillespy2.Reaction(reactants={}, products={'Sp':1}, rate=k2)
     model.add_reaction(unnamed_rxn)
     for solver in self.solvers:
         with self.subTest(solver=solver.name):
             solver = solver(model=self.model)
             if "ODE" in solver.name:
                 same_results = self.model.run(solver=solver)
                 compare_results = self.model.run(solver=solver)
             else:
                 same_results = self.model.run(solver=solver, seed=1)
                 compare_results = self.model.run(solver=solver,seed=1)
             self.assertTrue(np.array_equal(same_results.to_array(), compare_results.to_array()))
             if solver.name in ["ODESolver", "ODECSolver"]: continue
             diff_results = self.model.run(solver=solver, seed=2)
             self.assertFalse(np.array_equal(diff_results.to_array(), same_results.to_array()))