Пример #1
0
class DSMTS_001_01(DSMTS_Test):
    species = ['X']
    process = stocal.Process([
        stocal.MassAction(['X'], ['X', 'X'], 0.1),
        stocal.MassAction(['X'], [], 0.11)
    ])
    initial_state = {'X': 100}
Пример #2
0
class DSMTS_004_01(DSMTS_Test):
    species = ['X']
    process = stocal.Process([
        stocal.MassAction([], {'X': 5}, 1.),
        stocal.MassAction(['X'], [], 0.2)
    ])
    initial_state = {}
Пример #3
0
class DSMTS_003_01(DSMTS_Test):
    species = ['P', 'P2']
    process = stocal.Process([
        stocal.MassAction(['P', 'P'], ['P2'], 0.001),
        stocal.MassAction(['P2'], ['P', 'P'], 0.01)
    ])
    initial_state = {'P': 100}
Пример #4
0
 def test_transitions_counts_mutliplicities(self):
     """Sampler.transitions should give access to all transitions."""
     proc = stocal.Process()
     sampler = self.Sampler(proc, {})
     sampler.add_transition(stocal.MassAction({}, {'a': 1}, 1.))
     sampler.add_transition(stocal.MassAction({}, {'a': 1}, 1.))
     sampler.add_transition(stocal.MassAction({}, {'b': 1}, 1.))
     self.assertEqual(len(sampler.transitions), 3)
Пример #5
0
class DSMTS_002_03(DSMTS_002_01):
    # The original test tests for the overloading of global parameters
    # by local parameters. stocal does not have these concepts.
    # We merely check whether the process produces reported results
    # for an immigration rate of 5.
    process = stocal.Process(
        [stocal.MassAction([], ['X'], 5.),
         stocal.MassAction(['X'], [], 0.1)])
Пример #6
0
 def test_propose_potential_transition_seed(self):
     """Samplers initialized with the same random seed propose equal transitions"""
     process = stocal.Process([stocal.MassAction([], ['a'], 1.)])
     sampler_a = self.Sampler(process, {'a': 100}, seed=10)
     sampler_b = self.Sampler(process, sampler_a.state, seed=10)
     self.assertEqual(sampler_a.propose_potential_transition(),
                      sampler_b.propose_potential_transition())
Пример #7
0
 def test_propose_potential_transition_in_finite_time(self):
     """Proposed (time,transition) for empty process is (inf,None)"""
     process = stocal.Process([stocal.MassAction([], ['a'], 1.)])
     sampler = self.Sampler(process, {}, tmax=100.)
     time, transition, args = sampler.propose_potential_transition()
     self.assertTrue(time < float('inf'))
     self.assertNotEqual(transition, None)
Пример #8
0
 def test_perform_transition_advances_time(self):
     transition = stocal.MassAction([], ['a'], 1.)
     process = stocal.Process([transition])
     sampler = self.Sampler(process, {}, tmax=100.)
     time, trans, args = sampler.propose_potential_transition()
     sampler.perform_transition(time, trans, *args)
     self.assertGreater(sampler.time, 0.)
Пример #9
0
 def test_perform_transition_changes_state(self):
     transition = stocal.MassAction([], ['a'], 1.)
     process = stocal.Process([transition])
     sampler = self.Sampler(process, {}, tmax=100.)
     time, trans, args = sampler.propose_potential_transition()
     sampler.perform_transition(time, trans, *args)
     self.assertEqual(sampler.state, {'a': 1})
Пример #10
0
 def test_iter_steps(self, steps=50):
     """If steps is given, sampler returns this many transitions"""
     transition = stocal.MassAction({'a': 1}, {}, 1.)
     sampler = self.Sampler(stocal.Process([transition]), {'a': 100},
                            steps=steps)
     self.assertEqual(sum(1 for _ in sampler), steps)
     self.assertEqual(sampler.step, steps)
Пример #11
0
 def test_update_state_disables_static(self):
     """update_state can disable static transitions"""
     transition = stocal.MassAction({'a': 1}, {}, 1.)
     sampler = self.Sampler(stocal.Process([transition]), {'a': 1})
     sampler.update_state({'a': 0})
     with self.assertRaises(StopIteration):
         next(iter(sampler))
Пример #12
0
 def test_iter_steps_and_tmax(self):
     """if steps exceed, time should not be advanced to tmax"""
     transition = stocal.MassAction({'a': 1}, {}, 1.)
     proc = stocal.Process([transition])
     sampler = self.Sampler(proc, {'a': 100}, steps=0, tmax=10.)
     with self.assertRaises(StopIteration):
         next(iter(sampler))
     self.assertEqual(sampler.step, 0)
     self.assertEqual(sampler.time, 0.)
Пример #13
0
 def test_flatten_static_process_is_invariant(self):
     """Processes without rules return a copy of themselves"""
     process = self.Process(stocal.MassAction(['a'], ['b'], 1.))
     self.assertEqual(process, process.flatten(['a', 'b']))
Пример #14
0
class DSMTS_002_04(DSMTS_002_01):
    process = stocal.Process([
        stocal.MassAction([], ['X'], 1000.),
        stocal.MassAction(['X'], [], 0.1)
    ])
Пример #15
0
class DSMTS_001_07(DSMTS_001_01):
    species = ['X', 'Sink']
    process = stocal.Process([
        stocal.MassAction(['X'], ['X', 'X'], 0.1),
        stocal.MassAction(['X'], ['Sink'], 0.11)
    ])
Пример #16
0
class DSMTS_002_06(DSMTS_002_01):
    species = ['X', 'Sink']
    process = stocal.Process([
        stocal.MassAction([], ['X'], 10.),
        stocal.MassAction(['X'], ['Sink'], 0.1)
    ])
Пример #17
0
class DSMTS_003_02(DSMTS_003_01):
    process = stocal.Process([
        stocal.MassAction(['P', 'P'], ['P2'], 0.0002),
        stocal.MassAction(['P2'], ['P', 'P'], 0.004)
    ])
    initial_state = {'P': 1000}
Пример #18
0
class DSMTS_004_03(DSMTS_004_01):
    process = stocal.Process([
        stocal.MassAction([], {'X': 100}, 1.),
        stocal.MassAction(['X'], [], 4.)
    ])
Пример #19
0
"""Event example

stocal.Event's can be added to a processes definition just like
Reactions. Process.trajectory returns an StochasticSimulationAlgorithm
that can cope with deterministic transitions (e.g. FirstReactionMethod).
Sampler selection and usage is entirely transparent to the user.
"""
import stocal


process = stocal.Process([
    stocal.MassAction(['A', 'A'], ['A2'], 0.01),
    stocal.MassAction(['A2'], ['A', 'A'], 1.),
    stocal.Event([], ['A'], 0., 1.)
])


if __name__ == '__main__':
    traj = process.sample({}, tmax=100)
    for _ in traj:
        print(traj.time, traj.state['A'], traj.state['A2'])
Пример #20
0
class DSMTS_001_03(DSMTS_001_01):
    process = stocal.Process([
        stocal.MassAction(['X'], ['X', 'X'], 1.),
        stocal.MassAction(['X'], [], 1.1)
    ])
Пример #21
0
 def test_update_state_enables_static(self):
     """update_state can enable static transitions"""
     transition = stocal.MassAction({'a': 1}, {}, 1.)
     sampler = self.Sampler(stocal.Process([transition]), {})
     sampler.update_state({'a': 1})
     self.assertIs(next(iter(sampler)), transition)
Пример #22
0
A stochastic realization of the famous Brusselator system, first
proposed in I. Prigogine and R. Lefever, Symmetry Breaking Instabilities
in Dissipative Systems, J. Chem. Phys. 48, 1695 (1968).

This is a simple example of a process with only static (non-infered)
reactions. The deterministic system exhibits ascillations when b>a+1.
"""

import stocal

a = 2.
b = 10.

process = stocal.Process([
    stocal.MassAction({}, {"x": 1}, a),
    stocal.MassAction({
        "x": 2,
        "y": 1
    }, {"x": 3}, 1.),
    stocal.MassAction({"x": 1}, {
        "y": 1,
        "c": 1
    }, b),
    stocal.MassAction({"x": 1}, {"d": 1}, 1.),
])

if __name__ == '__main__':
    traj = process.sample({}, tmax=50)
    print("# time\tx\ty\tc\td")
    for dt, transitions in traj:
Пример #23
0
 def test_add_transition_enables_transition(self):
     """transitions added with add_transition must be executable"""
     sampler = self.Sampler(stocal.Process([]), {'a': 1})
     transition = stocal.MassAction({'a': 1}, {}, 1.)
     sampler.add_transition(transition)
     self.assertIs(next(iter(sampler)), transition)
Пример #24
0
    return low + (high - low) * (sin(2 * pi * time / period) + 1) / 2.


class Dissociation(stocal.MassAction):
    """Temperature dependent dissocition

    The normal mass action propensity is modulated by a factor that
    accounts for the system temperature at any time. The stochastic
    rate constant is therefore k = k_forward * exp((dH-T*dS)/T).
    k_forward is provided as rate constant to the MassAction constructor
    and the exponential transform is performed in the overloaded
    propensity method.
    """
    def propensity(self, state, time):
        T = temp(time)
        return super(Dissociation, self).propensity(state) * exp(
            (dH - T * dS) / T)


process = stocal.Process([
    stocal.MassAction(['x', 'x'], ['x2'], 2 * k_forward),
    Dissociation(['x2'], ['x', 'x'], k_forward),
])

state = {'x2': x_tot // 3, 'x': x_tot - 2 * x_tot // 3}

if __name__ == '__main__':
    traj = process.sample(state, tmax=125.)
    for trans in traj:
        print(traj.time, traj.state['x'], traj.state['x2'], temp(traj.time))