1# Python version of cmddata.txt 2# Author: Steve 3# Modified by: Dilawar 4 5import smoldyn 6import math 7 8 9def is_close(listA, listB): 10 for a, b in zip(listA, listB): 11 if not math.isclose(a, b, rel_tol=1e-3, abs_tol=1e-4): 12 return False 13 return True 14 15 16def test_data(): 17 s = smoldyn.Simulation(low=[0, 0, 0], high=[100, 100, 100]) 18 s.seed = 100 19 20 R = s.addSpecies("R", difc=1, color="red") 21 B = s.addSpecies("B", difc=1, color="blue") 22 23 s.addReaction("r1", subs=[R], prds=[], rate=0.1) 24 25 R.addToSolution(400) 26 B.addToSolution(1, pos=[50, 50, 50]) 27 s.addOutputData("mydata") 28 s.addCommand("molcount mydata", "E") 29 30 # s.setGraphics( "opengl" ) 31 s.run(stop=10, dt=0.01) 32 print(s.stop, s.dt) 33 data = s.getOutputData("mydata", 0) 34 assert len(data) == 1001, len(data) 35 assert len(data[0]) == 3, len(data[0]) 36 assert data[0] == [0.0, 400.0, 1.0], data[0] 37 assert is_close(data[-1], [10.0, 142.0, 1.0]), data[-1] 38 for row in data: 39 assert row 40 print(row) 41 42 43def main(): 44 test_data() 45 46 47if __name__ == "__main__": 48 main() 49