def plot_bng_and_kappa_sims(model, t_end, n_steps, title):
    # BNG
    x = bng.run_ssa(model, t_end=t_end, n_steps=n_steps)
    plt.figure()
    for name in x.dtype.names:
        if not name == 'time':
            plt.plot(x['time'], x[name], label="B:"+name)
    # Kappa
    x = kappa.run_simulation(model, time=t_end, points=n_steps)
    for name in x.dtype.names:
        if not name == 'time':
            plt.plot(x['time'], x[name], label="K:"+name)
    plt.title(title)
    plt.ylabel("Number")
    plt.xlabel("Time")
    plt.legend(loc='upper right')
Beispiel #2
0
    def run_site_cpt(self):
        """Run a set of simulations using the site_cpt implementation.

        Builds the model using the :py:meth:`Job.build` method, then runs
        the number of simulations specified in ``self.num_sims`` using
        `pysb.kappa.run_simulation` and returns the results.

        Returns
        -------
        list of numpy.recarrays
            List of record arrays, each one containing the results of a
            single stochastic simulation. The entries in the record array
            correspond to observables in the model.
        """
        b = self.site_cpt_builder()
        xrecs = []
        for i in range(self.num_sims):
            xrecs.append(kappa.run_simulation(b.model, time=self.tmax,
                                              points=self.n_steps,
                                              output_dir='.'))
        return xrecs
    def run_model(self, tmax=12000, num_sims=1, use_kappa=True,
                  figure_ids=[0, 1]):
        xrecs = []   # The array to store the simulation data
        dr_all = []  # TODO: Delete this

        # Run multiple simulations and collect data
        for i in range(0, num_sims):
            # Run simulation using Kappa:
            if use_kappa:
                ssa_result = kappa.run_simulation(self.model, time=tmax,
                                                  points=100,
                                                  output_dir='simdata')
                xrecs.append(ssa_result)
            # Run simulation using BNG SSA implementation:
            else:
                ssa_result = bng.run_ssa(self.model, t_end=tmax, n_steps=100,
                                         cleanup=True)
                xrecs.append(ssa_result)
                #dr_all.append(get_dye_release(model, 'pores', ssa_result))

        # Convert the multiple simulations in an array...
        xall = array([x.tolist() for x in xrecs])

        # ...and calculate the Mean and SD across the simulations
        x_std = recarray(xrecs[0].shape, dtype=xrecs[0].dtype, buf=std(xall, 0))
        x_avg = recarray(xrecs[0].shape, dtype=xrecs[0].dtype,
                         buf=mean(xall, 0))

        # Plotting parameters, aliases
        ci = color_iter()
        marker = 'x'
        linestyle = '-'
        tBid_0 = self['tBid_0']
        Bax_0 = self['Bax_0']

        # Translocation: plot cyto/mito tBid, and cyto/mito Bax
        plt.ion()
        plt.figure(figure_ids[0])
        plt.errorbar(x_avg['time'], x_avg['ctBid']/tBid_0.value,
                 yerr=x_std['ctBid']/tBid_0.value,
                 color=ci.next(), marker=marker, linestyle=linestyle)
        plt.errorbar(x_avg['time'], x_avg['mtBid']/tBid_0.value,
                 yerr=x_std['mtBid']/tBid_0.value,
                 color=ci.next(), marker=marker, linestyle=linestyle)
        plt.errorbar(x_avg['time'], x_avg['cBax']/Bax_0.value,
                 yerr=x_std['cBax']/Bax_0.value,
                 color=ci.next(), marker=marker, linestyle=linestyle)
        plt.errorbar(x_avg['time'], x_avg['mBax']/Bax_0.value,
                 yerr=x_std['mBax']/Bax_0.value,
                 color=ci.next(), marker=marker, linestyle=linestyle)

        # Activation: plot iBax and tBidBax
        plt.errorbar(x_avg['time'], x_avg['iBax']/Bax_0.value,
                 yerr=x_std['iBax']/Bax_0.value, label='iBax',
                 color=ci.next(), marker=marker, linestyle=linestyle)
        plt.errorbar(x_avg['time'], x_avg['tBidBax']/tBid_0.value,
                 yerr=x_std['tBidBax']/tBid_0.value,
                 color=ci.next(), marker=marker, linestyle=linestyle)

        # Dye release calculated exactly ----------
        #dr_avg = mean(dr_all, 0)
        #dr_std = std(dr_all, 0)
        #errorbar(x_avg['time'], dr_avg,
        #         yerr=dr_std, label='dye_release',
        #         color=ci.next(), marker=marker, linestyle=linestyle)


        # Pore Formation
        #plot(x['time'], x['pBax']/Bax_0.value, label='pBax')
        #leg = legend()
        #ltext = leg.get_texts()
        #setp(ltext, fontsize='small')

        #xlabel("Time (seconds)")
        #ylabel("Normalized Concentration")

        #ci = color_iter()
        # Plot pores/vesicle in a new figure ------
        #figure(2)
        #errorbar(x_avg['time'], x_avg['pores'] / float(NUM_COMPARTMENTS),
        #         yerr=x_std['pores']/float(NUM_COMPARTMENTS), label='pores',
        #         color=ci.next(), marker=marker, linestyle=linestyle)

        #F_t = 1 - dr_avg
        #pores_poisson = -log(F_t)
        #plot(x_avg['time'], pores_poisson, color=ci.next(), label='-ln F(t),
        #     stoch',
        #        marker=marker, linestyle=linestyle)
        #xlabel("Time (seconds)")
        #ylabel("Pores/vesicle")
        #title("Pores/vesicle")
        #legend()

        #xlabel("Time (seconds)")
        #ylabel("Dye Release")
        #title("Dye release calculated via compartmental model")

        return xrecs[0]