Ejemplo n.º 1
0
    def test_constructor(self):

        # Create a Voxel object
        v = pystospa.Voxel([10], 1.0)

        # Check that the Voxel attributes are as expected
        self.assertEqual(len(v.get_molecules()), 1)
        self.assertEqual(v.get_molecules()[0], 10)
        self.assertEqual(v.get_voxel_size(), 1.0)
Ejemplo n.º 2
0
    def test_constructor(self):

        # Create a Simulator object
        v = pystospa.Voxel([10], 1.0)
        v.add_reaction(pystospa.Reaction(1.5, lambda x, y: x[0], [-1]))
        s = pystospa.Simulator([v])

        # Check that the Simulator attributes are as expected
        self.assertEqual(s.get_time(), 0.0)
        self.assertEqual(s.get_voxels()[0].get_molecules()[0], 10)
Ejemplo n.º 3
0
    def test_member_functions(self):

        # Create a Voxel object
        v = pystospa.Voxel([10], 1.0)
        r = pystospa.Reaction(1.5, lambda x, y: x[0], [-1])

        # Check that a Reaction object has been added correctly
        v.add_reaction(r)
        rs = v.get_reactions()
        self.assertEqual(len(rs), 1)
        self.assertEqual(rs[0].get_rate(), 1.5)
        self.assertEqual(v.get_total_propensity(), 15)
Ejemplo n.º 4
0
    def test_member_functions(self):

        # Create a Simulator object
        v = pystospa.Voxel([10], 1.0)
        v.add_reaction(pystospa.Reaction(1.5, lambda x, y: x[0], [-1]))
        s = pystospa.Simulator([v])

        # Check setting seed for generating random number
        s.set_seed(153)
        self.assertEqual(s.get_seed(), 153)

        # Check a single step in SSA works
        s.step()
        self.assertGreater(s.get_time(), 0)
        self.assertEqual(s.get_voxels()[0].get_molecules()[0], 9)

        # Check that getting to specific time point works
        s.advance(1.0)
        self.assertGreater(s.get_time(), 1.0)
Ejemplo n.º 5
0
#!/usr/bin/env python

import matplotlib.pyplot as plt
import numpy as np
import pystospa as ss

# Create voxel object. Arguments: vector of number of molecules, size of the voxel
initial_num = [100]  # number of molecules of species A
domain_size = 10.0  # size of the domain in cm
v = ss.Voxel(initial_num, domain_size)

# Create reaction object.
# Arguments: reaction rate, propensity func, stoichiometry vector
k = 1.0
propensity = lambda num_mols, area: num_mols[0]
stoch = [-1]
r = ss.Reaction(k, propensity, stoch)

# Add a reaction to a voxel
v.add_reaction(r)

# Pass the voxel with the reaction(s) to the simulator object
s = ss.Simulator([v])
# Run the simulation. Arguments: path to output file, time step, number of steps
s.run("cme_example.dat", 0.01, 500)

# Read the file containing the data
data = np.loadtxt("cme_example.dat")
time = data[:, 0]  # Time points
num_A = data[:, 1]  # Number of molecules of A
Ejemplo n.º 6
0
#!/usr/bin/env python

import matplotlib.pyplot as plt
import numpy as np
import pystospa as ss

# Create a vector of voxel objects. Voxel arguments: vector of number of molecules, size of the voxel
initial_num = [10000]
voxel_size = 1.0
domain = [ss.Voxel(initial_num, voxel_size)]
# We add nine voxels with no molecules
for i in range(9):
    domain.append(ss.Voxel([0], voxel_size))

# Create and add the reaction objects
d = 1.0  # diffusion rate
k = 1.0  # decay rate
propensity = lambda num_mols, length : num_mols[0]
stoch = [-1]
for i, vox in enumerate(domain):
    # Add diffusion jump to the right from voxel i to voxel i+1 (if one exists)
    if i < len(domain)-1: vox.add_reaction(ss.Reaction(d, propensity, stoch, i+1))
    # Add diffusion jump to the left from voxel i+1 to voxel i (if one exists)
    if i > 0: vox.add_reaction(ss.Reaction(d, propensity, stoch, i-1))
    vox.add_reaction(ss.Reaction(k, propensity, stoch))

# Pass the voxels with the reaction(s) to the simulator object
s = ss.Simulator(domain)

# Run the simulation. Arguments: path to output file, time step, number of steps
s.run("rdme_example_2.dat", 0.01, 200)