Skip to content

Commit

Permalink
fix: setAction was not accepting trans action (#116)
Browse files Browse the repository at this point in the history
* ci: Building is passing locally

Probably it is an issue with M1 silicon.

* ci: export MACOSX_DEPLOYMENT_TARGET=11_0

As suggested by some good FOSS citizens.

* fix: Support action 'trans'

- Hide actions that were for internal use.
- Added tests for setting actions.

* chore: update to python classifiers

Added Python3 only.

* ci: glut search is failing on OSX in pipeline

build: OPTION_STATIC is removed

libsmoldyn_static is always built. Required for Python module.

* ci: MACOSX_DEPLOYMENT_TARGET is set to 10.4

* ci: Trying with target 10.9
  • Loading branch information
Dilawar Singh authored Jan 11, 2022
1 parent a962821 commit 9a22e5f
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 64 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

### 2.68

- Fixed a bug in Python `setAction` command: action `trans` as not exposed.

### 2.67 (11/2/21)

Expand Down
62 changes: 13 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ option(OPTION_MINGW "Cross-compile for Windows using MinGW compiler" OFF)

option(OPTION_NSV "Compile Smoldyn with NextSubvolume functionality" ON)
option(OPTION_VTK "Compile Smoldyn with VTK functionality" OFF)
option(OPTION_STATIC "Compile Smoldyn with static libraries" OFF)
option(OPTION_USE_OPENGL "Build with OpenGL support" ON)
option(OPTION_USE_LIBTIFF "Build with LibTiff support" ON)
option(OPTION_USE_ZLIB "Build with Zlib support" OFF)
Expand Down Expand Up @@ -89,7 +88,6 @@ if (OPTION_MINGW)
endif ()
message(STATUS "Option to include NextSubvolume: ${OPTION_NSV}")
message(STATUS "Option to include VTK: ${OPTION_VTK}")
message(STATUS "Option to compile with static libraries: ${OPTION_STATIC}")
message(STATUS "Option to include OpenGL support: ${OPTION_USE_OPENGL}")
message(STATUS "Option to include LibTiff: ${OPTION_USE_LIBTIFF}")
message(STATUS "Option to include Zlib: ${OPTION_USE_ZLIB}")
Expand Down Expand Up @@ -203,7 +201,7 @@ if(OPTION_TARGET_LIBSMOLDYN)
list(APPEND SRC_FILES ${CMAKE_SOURCE_DIR}/source/Smoldyn/libsmoldyn.cpp)
endif(OPTION_TARGET_LIBSMOLDYN)

if(OPTION_USE_LIBTIFF AND NOT OPTION_USE_OPENGL)
if(OPTION_USE_LIBTIFF AND (NOT OPTION_USE_OPENGL))
message(WARNING "LibTiff won't be used because build does not include OpenGL.")
set(OPTION_USE_LIBTIFF OFF)
endif()
Expand All @@ -226,7 +224,9 @@ if (OPTION_VCELL)
message(STATUS "Compiling for VCell")
add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/source/vcell)
elseif (OPTION_MINGW)
endif()

if (OPTION_MINGW)
set(MINGW_BUILD ON)
message(STATUS "Cross-compiling for Windows using MinGW libraries from: ${MINGWDIR}")
set(BNG2_PATH "%PROGRAMFILES%\\\\Smoldyn\\\\BioNetGen\\\\BNG2.pl")
Expand Down Expand Up @@ -265,15 +265,10 @@ message(STATUS "BioNetGen path: '${BNG2_PATH}' ")

####### Option: Build with OpenGL (gl and glu only, not glut) ##########

if (OPTION_USE_OPENGL)
if (OPTION_USE_OPENGL AND NOT APPLE)
# see cmake --help-policy CMP0072"
set(OpenGL_GL_PREFERENCE LEGACY)

if (VCELL_BUILD)
set(HAVE_OPENGL TRUE)
set(HAVE_GL_GL_H TRUE)
set(HAVE_GL_GLU_H TRUE)
elseif (MINGW_BUILD)
if (MINGW_BUILD)
list(APPEND DEP_LIBS opengl32 glu32 freeglut_static gdi32 winmm)
find_file(HAVE_GL_GL_H GL/gl.h PATHS ${MINGWDIR}/include)
find_file(HAVE_OPENGL_GL_H OpenGL/gl.h PATHS ${MINGWDIR}/include)
Expand Down Expand Up @@ -320,18 +315,8 @@ endif()


####### Option: Build with OpenGL (glut only) ##########

if (OPTION_USE_OPENGL)
if (VCELL_BUILD)
set(HAVE_GL_GLUT_H TRUE)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/windows/glut-3.7.6)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/windows/glut-3.7.6)
if (ARCH_64bit)
list(APPEND DEP_LIBS glut64)
else()
list(APPEND DEP_LIBS glut32 zlib)
endif()
elseif (MINGW_BUILD)
if (OPTION_USE_OPENGL AND NOT APPLE)
if (MINGW_BUILD)
add_compile_definitions(FREEGLUT_STATIC)
find_file(HAVE_GL_GLUT_H GL/glut.h PATHS ${MINGWDIR}/include)
find_path(GLUT_INCLUDE_DIR glut.h PATHS ${MINGWDIR}/include/GL)
Expand All @@ -352,10 +337,8 @@ if (OPTION_USE_OPENGL)
set(GLUT_FOUND TRUE)
endif ()

if(GLUT_FOUND)
message(STATUS "Glut found: '${GLUT_INCLUDE_DIR}', '${GLUT_LIBRARIES}'")
else()
message(STATUS "Glut include and library variables: '${GLUT_INCLUDE_DIR}', '${GLUT_LIBRARIES}'")
message(STATUS "Glut found: Include dir: '${GLUT_INCLUDE_DIR}', libs: '${GLUT_LIBRARIES}'")
if(NOT GLUT_FOUND)
message(FATAL_ERROR "Glut not found. Building without OpenGL is possible.")
endif()

Expand All @@ -364,20 +347,6 @@ if (OPTION_USE_OPENGL)
endif()


####### Build with LibX11 (only required for static build on Mac) ##########

#if (OPTION_STATIC AND OPTION_USE_OPENGL AND HAVE_OPENGL)
# find_package(X11)
# if (X11_FOUND)
# message(STATUS "Found X11: '${X11_INCLUDE_DIR}', '${X11_LIBRARIES}'")
# else ()
# message(FATAL_ERROR "X11 not found")
# endif ()
# include_directories(${X11_INCLUDE_DIR})
# list(APPEND DEP_LIBS ${X11_LIBRARIES})
#endif()


####### Option: Build with LibTiff ##########

if (OPTION_USE_LIBTIFF)
Expand All @@ -389,9 +358,6 @@ if (OPTION_USE_LIBTIFF)
set(HAVE_TIFF_H TRUE)
find_file(TIFF_LIBRARY NAMES tiff.lib PATHS source/MSVClibs NO_DEFAULT_PATH)
set(TIFF_FOUND TRUE)
elseif (OPTION_STATIC)
find_path(TIFF_INCLUDE_DIR tiff.h PATHS ${CMAKE_SOURCE_DIR}/Mac/libtiff/include NO_DEFAULT_PATH)
find_library(TIFF_LIBRARY libtiff.a ${CMAKE_SOURCE_DIR}/Mac/libtiff/lib NO_DEFAULT_PATH)
else ()
find_package(TIFF)
endif()
Expand All @@ -416,11 +382,6 @@ if(OPTION_USE_ZLIB)
if(OPTION_MINGW)
find_path(ZLIB_INCLUDE_DIRS zlib.h PATHS ${MINGWDIR}/include NO_DEFAULT_PATH)
find_library(ZLIB_LIBRARIES libz.a PATHS ${MINGWDIR}/lib NO_DEFAULT_PATH)
elseif(OPTION_STATIC)
find_path(ZLIB_INCLUDE_DIRS zlib.h)
find_library(ZLIB_LIBRARIES libz.a)
else()
include(FindZlib)
endif()

if(ZLIB_INCLUDE_DIRS AND ZLIB_LIBRARIES)
Expand Down Expand Up @@ -468,6 +429,9 @@ add_library(smoldyn_static STATIC ${SRC_FILES}
set_property(TARGET smoldyn_static PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(smoldyn_static PUBLIC ${DEP_LIBS})
set_target_properties(smoldyn_static PROPERTIES PREFIX "lib")
if (APPLE)
set_target_properties(smoldyn_static PROPERTIES LINK_FLAGS "-framework Glut -framework OpenGL")
endif()

if (OPTION_TARGET_LIBSMOLDYN)
add_library(smoldyn_shared SHARED ${SRC_FILES}
Expand Down
6 changes: 3 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ include_directories(${CMAKE_SOURCE_DIR}/source/Smoldyn)
include_directories(${CMAKE_BINARY_DIR})

add_executable(test1c S97_libsmoldyn/test1.c)
target_link_libraries(test1c smoldyn_static)
target_link_libraries(test1c PRIVATE smoldyn_static)

add_executable(test1 S97_libsmoldyn/test1.cpp)
target_link_libraries(test1 smoldyn_static)
target_link_libraries(test1 PRIVATE smoldyn_static)

add_executable(testcode S97_libsmoldyn/testcode/testcode.cpp)
target_link_libraries(testcode smoldyn_static)
target_link_libraries(testcode PRIVATE smoldyn_static)

if(UNIX)
# can't get them to work on Windows.
Expand Down
8 changes: 5 additions & 3 deletions scripts/build_wheels_osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
set -e
set -x

# See https://github.com/ssandrews/Smoldyn/runs/4770635750?check_suite_focus=true
export MACOSX_DEPLOYMENT_TARGET=10.9

brew install libtiff || echo "Failed to install libtiff"
brew install cmake || echo "Failed to install cmake"
brew install freeglut || echo "Failed to install freeglut"
Expand All @@ -23,7 +26,7 @@ if [ ! -f $PYTHON ]; then
exit -1
fi

$PYTHON -m pip install setuptools --upgrade
$PYTHON -m pip install pip setuptools --upgrade
$PYTHON -m pip install wheel --upgrade
$PYTHON -m pip install numpy --upgrade
$PYTHON -m pip install delocate --upgrade
Expand Down Expand Up @@ -62,8 +65,7 @@ PLATFORM=$($PYTHON -c "import distutils.util; print(distutils.util.get_platform(
# now use venv pyhton.
$PYTHON --version

# Use the latest wheel. There could be more than one whl files in
# WHEELHOUSE (sometimes, on github actions for sure).
# Use the latest wheel. There could be more than one whl files in WHEELHOUSE
WHEELFILE=$(ls -t "$WHEELHOUSE"/smoldyn*.whl | head -n 1)
if [ -f "${WHEELFILE}" ]; then
$PYTHON -m pip install "$WHEELFILE"
Expand Down
10 changes: 6 additions & 4 deletions source/python/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ PYBIND11_MODULE(_smoldyn, m)
.value("mult", SrfAction::SAmult)
.value("no", SrfAction::SAno)
.value("none", SrfAction::SAnone)
.value("adsorb", SrfAction::SAadsorb)
.value("revdes", SrfAction::SArevdes)
.value("irrevdes", SrfAction::SAirrevdes)
.value("flip", SrfAction::SAflip);
// IMP: Following are for internal use. If you expose them, make sure to update the user manual.
// .value("adsorb", SrfAction::SAadsorb)
// .value("revdes", SrfAction::SArevdes)
// .value("irrevdes", SrfAction::SAirrevdes)
// .value("flip", SrfAction::SAflip)
;

py::enum_<MolecState>(m, "MolecState")
.value("soln", MolecState::MSsoln)
Expand Down
2 changes: 1 addition & 1 deletion source/python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ setuptools.setup(
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Scientific/Engineering :: Bio-Informatics",
],
)
10 changes: 6 additions & 4 deletions source/python/smoldyn/smoldyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,13 @@ def __init__(
self.surfname: str = surfname
self.__valid_actions_ = [
"reflect",
"trans",
"absorb",
"transmit",
"jump",
"port",
"periodic",
"mult",
"no",
"none",
]

def setStyle(
Expand Down Expand Up @@ -813,7 +815,7 @@ def setAction(
"""
assert (
action in self.__valid_actions_
), f"Action '{action}' is not a valid action: {self.__valid_actions_}"
), f"'{action}' is not a valid action. Available actions: {', '.join(self.__valid_actions_)}"

if isinstance(species, str):
raise NameError(
Expand Down Expand Up @@ -842,7 +844,7 @@ def setAction(
sstate,
_smoldyn.SrfAction.__members__[action],
)
assert k == _smoldyn.ErrorCode.ok
assert k == _smoldyn.ErrorCode.ok, f"Failed setSurfaceAction: {k}"


class Path2D(object):
Expand Down
67 changes: 67 additions & 0 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Original author: Upinder Bhalla, NCBS Bangalore
# Modified by Dilawar Singh for smoldyn integration.

import smoldyn
import random
import math


def build_model():
"""
Size of bouton: 1 cubic µm
diameter of Synaptic Vesicle (SV): 40 nm
Diff of SV: 0.024 um^2/s (2400 nm^2/s)
1px = 1nm throughout.
"""
global r1_, bouton_
s = smoldyn.Simulation(low=[-500, -500], high=[1500, 1500])

# a molecule that self-generate
sv = s.addSpecies(
"SV", difc=dict(all=2400, front=10), color="blue", display_size=10
)
sv.addToSolution(100, lowpos=(0, 0), highpos=(1000, 1000))
s.addReaction("svgen", [sv], [sv, sv], rate=1e-6)
svFused = s.addSpecies("VSOpen", color="blue", display_size=10)

# intermediate speficies with a lifetime.
B = s.addSpecies("B", color="red", difc=10000, display_size=2)
decay = s.addReaction("decay", subs=[B], prds=[], rate=math.log(2) / 20e-3)

# A very non-interesting surface.
path = s.addPath2D((1000, 0), (1000, 1000), (0, 1000), (0, 0))
bouton_ = s.addSurface("bouton", panels=path.panels)
bouton_.setStyle("both", color="blue")

# try to add all actions.
bouton_.setAction("both", [sv], "reflect")
bouton_.setAction("both", [sv], "trans")
bouton_.setAction("back", [sv], "absorb")
bouton_.setAction("back", [sv], "jump")
bouton_.setAction("back", [sv], "port")

# NOTE: action 'mult', 'no' and 'none' causes error here.

# this is the bottom surface of bouton. This is sticky for synaptic
# vesciles
rect1 = smoldyn.Rectangle(corner=(0, 0), dimensions=[1000], axis="+y")
bottom = s.addSurface("boutonBottom", panels=[rect1])
bottom.setStyle("both", color="red")
bottom.setAction("back", B, "reflect")
bottom.setAction("back", B, "trans")
bottom.setAction("back", B, "absorb")
bottom.setAction("back", B, "jump")
bottom.setAction("back", B, "port")

return s


def test_action():
s = build_model()
print("[INFO] Starting simulation ...")
s.run(stop=20, dt=0.001)
print("Done")


if __name__ == "__main__":
test_action()

0 comments on commit 9a22e5f

Please sign in to comment.