1"""Some tests for CPP API.
2
3"""
4
5__author__ = "Dilawar Singh"
6__email__ = "dilawars@ncbs.res.in"
7
8# Test only the extension module. It has to be imported by the user.
9import smoldyn._smoldyn as CppApi
10
11print(CppApi.__version__)
12
13
14def test_library():
15    """We test the C API here"""
16    s = CppApi.Simulation([-50, -50], [50, 50], ["r", "r"])
17    #  assert s.getDim() == 2
18    s.setRandomSeed(1)
19
20    s.setPartitions("molperbox", 4)
21    s.setPartitions("boxsize", 12.5)
22
23    s.addSpecies("ACA")
24    s.addSpecies("ATP")
25    s.addSpecies("cAMP")
26    s.addSpecies("cAR1")
27
28    for i, name in enumerate(["ACA", "ATP", "cAMP", "cAR1"]):
29        assert (
30            s.getSpeciesName(i + 1) == name
31        ), f"Expected {name}, got {s.getSpeciesName(i+1)}"
32
33    MS = CppApi.MolecState  # enum MolcState
34    SA = CppApi.SrfAction  # enum SrfAction
35    PF = CppApi.PanelFace  # enum PanelFace
36    PS = CppApi.PanelShape  # enum PanelShape
37
38    s.setSpeciesMobility("ACA", MS.all, 1.0)
39    s.setSpeciesMobility("ATP", MS.all, 1.0)
40    s.setSpeciesMobility("cAMP", MS.all, 1.0)
41    s.setSpeciesMobility("cAR1", MS.all, 1.0)
42
43    # Adding surface.
44    s.addSurface("Membrane00")
45    s.setSurfaceAction("Membrane00", PF.both, "ATP", MS.soln, SA.reflect, "")
46
47    params = [-20.0, 20.0, 10.0, 20.0, 20.0]
48    s.addPanel("Membrane00", PS.sph, "", "", params)
49
50    s.addCompartment("Cell00")
51    s.addCompartmentSurface("Cell00", "Membrane00")
52    s.addCompartmentPoint("Cell00", params)
53    s.addSurfaceMolecules("ACA", MS.down, 30, "Membrane00", PS.all, "all", [])
54    s.addSurfaceMolecules("cAR1", MS.up, 30, "Membrane00", PS.all, "all", [])
55    s.addReaction("r100", "", MS.all, "", MS.all, ["ATP"], [MS.soln], 0.02)
56    s.setReactionRegion("r100", "Cell00", "")
57
58    s.runSim(200.0, 0.01, True, True)
59
60
61def main():
62    test_library()
63
64
65if __name__ == "__main__":
66    main()
67