1__author__ = "Dilawar Singh" 2__email__ = "dilawar@subcom.tech" 3 4import smoldyn as S 5import numpy as np 6 7 8def test_prd_pacement(): 9 sim = S.Simulation(low=[-10, -10, -10], high=[10, 10, 10], quit_at_end=1) 10 sim.setRandomSeed(10) 11 blue = sim.addSpecies(name="blue", color="blue", difc=1, display_size=0.3) 12 red = sim.addSpecies(name="red", color="red", difc=0, display_size=0.3) 13 sim.addMolecules(blue, number=100, lowpos=[-5, -5, -5], highpos=[5, 5, 5]) 14 sim.addMolecules(red, number=1, pos=[0, 0, 0]) 15 16 s1 = sim.addSurface( 17 "membrane", 18 panels=[sim.addSphere(center=[0, 0, 0], radius=10, slices=10, stacks=10)], 19 ) 20 s1.setStyle("both", drawmode="edge", color="green") 21 s1.setAction(face="both", species=[blue, red], action="reflect") 22 23 stick = sim.addReaction(name="stick", subs=[blue, red], prds=[red, red], rate=20) 24 stick.productPlacement(method="bounce", param=0.6) 25 sim.addOutputData("data") 26 sim.addCommand("molcount data", "E") 27 # sim.setGraphics('opengl_good', 1) 28 sim.run(stop=100, dt=0.1) 29 d = sim.getOutputData("data") 30 d = np.array(d) 31 assert (d[:, 1] + d[:, 2] == 101).all() 32 33 y = d.std(axis=0) 34 ym = d.mean(axis=0) 35 assert np.allclose(ym, [50, 20.75524, 80.24475], atol=1e-3, rtol=1e-3), ym 36 assert np.allclose(y, [28.89636655, 20.5, 20.5], atol=1e-1, rtol=1e-1), y 37 print(d) 38 39 40def main(): 41 test_prd_pacement() 42 43 44if __name__ == "__main__": 45 main() 46