diff --git a/CHANGELOG.md b/CHANGELOG.md index de772d84..46ccd58a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +### 2.68 + +- Fixed a bug in Python `setAction` command: action `trans` as not exposed. ### 2.67 (11/2/21) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3735e438..ef6d121b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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}") @@ -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() @@ -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") @@ -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) @@ -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) @@ -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() @@ -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) @@ -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() @@ -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) @@ -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} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e7bc2b2b..a1c6c608 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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. diff --git a/scripts/build_wheels_osx.sh b/scripts/build_wheels_osx.sh index 8e62d8d7..51af4943 100755 --- a/scripts/build_wheels_osx.sh +++ b/scripts/build_wheels_osx.sh @@ -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" @@ -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 @@ -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" diff --git a/source/python/module.cpp b/source/python/module.cpp index e6fe376b..11a18325 100644 --- a/source/python/module.cpp +++ b/source/python/module.cpp @@ -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_(m, "MolecState") .value("soln", MolecState::MSsoln) diff --git a/source/python/setup.py.in b/source/python/setup.py.in index e8a98f59..dd792a63 100644 --- a/source/python/setup.py.in +++ b/source/python/setup.py.in @@ -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", ], ) diff --git a/source/python/smoldyn/smoldyn.py b/source/python/smoldyn/smoldyn.py index c436679a..285ee87b 100644 --- a/source/python/smoldyn/smoldyn.py +++ b/source/python/smoldyn/smoldyn.py @@ -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( @@ -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( @@ -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): diff --git a/tests/test_actions.py b/tests/test_actions.py new file mode 100644 index 00000000..46664dd1 --- /dev/null +++ b/tests/test_actions.py @@ -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()