Skip to content

Commit b73b011

Browse files
committed
added test script to source
1 parent bedd356 commit b73b011

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

testing/example_tests.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#! /usr/bin/env python
2+
"""
3+
StochPy - Stochastic modeling in Python (http://stochpy.sourceforge.net)
4+
5+
Copyright (C) 2010-2025 T.R Maarlveld, B.G. Olivier, F.J. Bruggeman. All rights reserved.
6+
7+
This file:
8+
Author: Brett G. Olivier (b.g.olivier@vu.nl)
9+
Address: Vrije Universiteit Amsterdam, Amsterdam, Netherlands.
10+
11+
12+
Permission to use, modify, and distribute this software is given under the
13+
terms of the StochPy (BSD style) license.
14+
15+
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
16+
"""
17+
18+
print('# StochPy Basic tests')
19+
20+
print('## Import and load')
21+
22+
import stochpy
23+
smod = stochpy.SSA()
24+
25+
print('\nDone.\n\n## Basic Simulation with the Direct method')
26+
27+
smod.DoStochSim(IsTrackPropensities=True)
28+
smod.data_stochsim.simulation_endtime
29+
smod.data_stochsim.simulation_timesteps
30+
smod.GetWaitingtimes()
31+
smod.PrintWaitingtimesMeans()
32+
33+
print('\nDone.\n\n## Do some Plotting')
34+
35+
smod.PlotSpeciesTimeSeries()
36+
smod.PlotWaitingtimesDistributions()
37+
smod.PlotPropensitiesTimeSeries()
38+
39+
print('\nDone.\n\n## Write data to a text file')
40+
41+
smod.Export2File()
42+
smod.Export2File(analysis='distribution')
43+
smod.Export2File(analysis='distribution',datatype='species')
44+
smod.Export2File(analysis='mean',datatype='species')
45+
smod.Export2File(analysis='std',datatype='species')
46+
smod.Export2File(analysis='autocorrelation',datatype='species')
47+
48+
print('\nDone.\n\n## Show the means from the data of 3-th trajectory')
49+
50+
smod.DoStochSim(trajectories=3) # multiple trajectories
51+
smod.data_stochsim.simulation_trajectory
52+
smod.PrintSpeciesMeans()
53+
smod.PrintSpeciesStandardDeviations()
54+
55+
print('\nDone.\n\n## Switch to data from trajectory 1 and show the means of each species')
56+
57+
smod.GetTrajectoryData(1)
58+
smod.PrintSpeciesMeans()
59+
smod.PrintSpeciesStandardDeviations()
60+
61+
print('\nDone.\n\n## Do one long simulation')
62+
63+
smod.DoStochSim(trajectories=1,end=1000000,mode='steps')
64+
smod.PrintSpeciesMeans()
65+
smod.PrintSpeciesStandardDeviations()
66+
67+
print('\nDone.\n\n## Plot the PDF for different bin sizes')
68+
69+
smod.PlotSpeciesDistributions()
70+
smod.PlotSpeciesDistributions(bin_size=5) # larger bin size
71+
smod.PlotSpeciesDistributions(bin_size=10) # again a larger bin size
72+
smod.Export2File(analysis='distribution',datatype='species')
73+
74+
print('\nDone.\n\n## Usage of the Reload Function: `Ksyn = 20, kdeg = 0.2`')
75+
76+
smod.ChangeParameter('Ksyn',20.0)
77+
smod.ChangeParameter('Kdeg',0.2)
78+
smod.DoStochSim()
79+
smod.PrintSpeciesMeans() # should be ~Ksyn/Kdeg
80+
81+
print('\nDone.\n\n## Use another model to show the Interpolation features')
82+
83+
smod.Model('dsmts-001-01.xml.psc')
84+
smod.DoStochSim(trajectories=1000,end=50,mode='time')
85+
smod.GetRegularGrid(n_samples=51)
86+
smod.PlotAverageSpeciesTimeSeries()
87+
smod.PrintAverageSpeciesTimeSeries()
88+
smod.Export2File(datatype='species',analysis='timeseries',IsAverage=True)
89+
90+
print('\nDone.\n\n## Test each method for different models:')
91+
92+
smod.Model('Autoreg.psc')
93+
smod.DoStochSim(trajectories=1,end=1000,mode='steps')
94+
smod.Method('NextReactionMethod')
95+
smod.DoStochSim(trajectories=1,end=1000,mode='steps')
96+
smod.data_stochsim.species
97+
smod.PlotWaitingtimesDistributions()
98+
smod.Method('FirstReactionMethod')
99+
smod.DoStochSim(trajectories=1,end=1000,mode='steps')
100+
smod.Method('TauLeaping')
101+
smod.DoStochSim(trajectories=1,end=1000,mode='steps')
102+
103+
smod.Model('DecayingDimerizing.psc')
104+
smod.DoStochSim(method = 'Direct',trajectories=1,end=50,mode='time')
105+
smod.DoStochSim(method = 'NextReactionMethod',trajectories=1,end=50,mode='time')
106+
smod.DoStochSim(method = 'FirstReactionMethod',trajectories=1,end=50,mode='time')
107+
smod.PlotWaitingtimesDistributions()
108+
smod.DoStochSim(method = 'TauLeaping',trajectories=1,end=50,mode='time',epsilon=0.03) # Should outperform all other implementations
109+
smod.PlotSpeciesTimeSeries()
110+
#smod.PlotWaitingtimesDistributions() # Should give an error
111+
112+
smod.Model('chain500.psc')
113+
smod.DoStochSim(method = 'Direct',trajectories=1,end=10000,mode='steps')
114+
smod.DoStochSim(method = 'NextReactionMethod',trajectories=1,end=10000,mode='steps') # should outperform the direct method and all other implementations
115+
116+
print('\n### Use the Next Reaction Method to test a model with a time event\n')
117+
118+
smod.Model('dsmts-003-03.xml.psc')
119+
smod.DoStochSim(method = 'NextReactionMethod')
120+
smod.DoTestsuite()
121+
122+
print('\n### Use the First Reaction method to test a model with a concentration event\n')
123+
124+
smod.Model('dsmts-003-04.xml.psc')
125+
smod.DoStochSim(method = 'FirstReactionMethod')
126+
smod.DoTestsuite()
127+
128+
print('\n### Volume Models\n')
129+
130+
smod.Model('dsmts-001-11.xml.psc')
131+
smod.DoStochSim(method = 'Direct',trajectories=1000,end=50,mode ='time')
132+
smod.PrintAverageSpeciesTimeSeries()

0 commit comments

Comments
 (0)