diff --git a/moose-core/CMakeLists.txt b/moose-core/CMakeLists.txt index 068c20b2316d6bc32641955441f1b9d82dad7de0..4b4fe8f1a63212e8957cc6b6567d54a03fbb0ac6 100644 --- a/moose-core/CMakeLists.txt +++ b/moose-core/CMakeLists.txt @@ -5,7 +5,7 @@ project(pymoose) if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) - cmake_policy(SET CMP0004 OLD) + cmake_policy(SET CMP0004 NEW) if(POLICY CMP0050) cmake_policy(SET CMP0050 OLD) endif(POLICY CMP0050) @@ -18,28 +18,7 @@ include(FindPkgConfig) # If from command line, version info is not passed, use the git to generate a # version file. If GIT fails, use the previous known version. -set(VERSION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/VERSION) -find_program(GIT_EXEC "git") -message( STATUS "Looking for git ${GIT_EXEC}" ) -if( (NOT MOOSE_VERSION) AND GIT_EXEC) - execute_process( - COMMAND ${GIT_EXEC} describe --tags --long - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE MOOSE_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - message(STATUS "+ Writing ${MOOSE_VERSION} to ${VERSION_FILE}" ) - file(WRITE ${VERSION_FILE} ${MOOSE_VERSION}) -elseif( (NOT MOOSE_VERSION) AND (NOT GIT_EXEC) ) - message(STATUS "+ Reading ${VERSION_FILE}" ) - file(READ ${VERSION_FILE} GIT_VERSION_OUTPUT ) -elseif(MOOSE_VERSION) - message(STATUS "+ Using user specified VERSION = ${MOOSE_VERSION}" ) - file(WRITE ${VERSION_FILE} ${MOOSE_VERSION}) -else() - message(FATAL_ERROR "Could not determine MOOSE_VERSION" ) -endif( ) - +set(MOOSE_VERSION 3.2-git) add_definitions( -DMOOSE_VERSION="${MOOSE_VERSION}") message( STATUS "MOOSE Version ${MOOSE_VERSION}" ) @@ -89,7 +68,6 @@ endif() option(DEBUG "Build with debug support" OFF) option(GPROF "Build for profiling using gprof" OFF) option(ENABLE_UNIT_TESTS "Enable unit tests (DEBUG should also be ON)" OFF) -option(WITH_PYTHON "Build native python extension" ON) option(WITH_MPI "Enable Openmpi support" OFF) option(WITH_BOOST "Use boost library instead of GSL" OFF) option(WITH_GSL "Use gsl-library. Alternative is WITH_BOOST" ON) @@ -129,7 +107,10 @@ endif() ################################### TARGETS #################################### add_library(libmoose SHARED basecode/main.cpp) -add_executable(moose.bin basecode/main.cpp) + +if(DEBUG) + add_executable(moose.bin basecode/main.cpp) +endif( ) ################################### SETUP BUILD ################################ @@ -387,32 +368,32 @@ ELSE(MACOSX) ) endif(MACOSX) -add_dependencies(moose.bin libmoose) - -target_link_libraries(moose.bin moose ${CMAKE_DL_LIBS}) -if( WITH_BOOST ) - target_link_libraries( moose.bin ${Boost_LIBRARIES} ) -endif( WITH_BOOST ) +if(DEBUG) + add_dependencies(moose.bin libmoose) + target_link_libraries(moose.bin moose ${CMAKE_DL_LIBS}) + if( WITH_BOOST ) + target_link_libraries( moose.bin ${Boost_LIBRARIES} ) + endif( WITH_BOOST ) +endif() ######################### BUILD PYMOOSE ######################################## -# Root of all python module. -if(WITH_PYTHON) - add_subdirectory( pymoose ) -endif(WITH_PYTHON) +add_subdirectory( pymoose ) ######################### INSTALL ############################################## -install(TARGETS moose.bin - DESTINATION bin - ) +if(DEBUG) + install(TARGETS moose.bin + DESTINATION bin + ) -install(TARGETS libmoose - DESTINATION lib - ) + install(TARGETS libmoose + DESTINATION lib + ) -install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/moose - DESTINATION bin - ) + install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/moose + DESTINATION bin + ) +endif( ) # INSTALL python module. # This target is built by pymoose/CMakeLists.txt file. Using the --prefix option @@ -425,19 +406,21 @@ execute_process( ) message( STATUS "Platform ${_platform_desc}" ) -if(WITH_PYTHON) - set(EXTRA_ARGS "--prefix ${CMAKE_INSTALL_PREFIX}") - if( ${_platform_desc} MATCHES ".*(Ubuntu|Debian).*" ) - list( APPEND EXTRA_ARGS "--install-layout=deb" ) - endif( ) - - install(CODE - "execute_process( - COMMAND ${PYTHON_EXECUTABLE} setup.py install ${EXTRA_ARGS} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python - )" - ) -endif(WITH_PYTHON) + +set(EXTRA_ARGS "--prefix ${CMAKE_INSTALL_PREFIX}") + +if( ${_platform_desc} MATCHES ".*(Ubuntu|Debian).*" ) + list( APPEND EXTRA_ARGS "--install-layout=deb" ) +endif( ) + +# If make is called with sudo, install in system directories. Otherwise use +# --user to install in user home. +install(CODE + "execute_process( + COMMAND ${PYTHON_EXECUTABLE} setup.cmake.py install ${EXTRA_ARGS} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python + )" + ) # Print message to start build process if(${CMAKE_BUILD_TOOL} MATCHES "make") @@ -450,16 +433,19 @@ if(${CMAKE_BUILD_TOOL} MATCHES "make") endif() + + ############################ CTEST ###################################### include( CTest ) # If CTEST_OUTPUT_ON_FAILURE environment variable is set, the output is printed # onto the console if a test fails. set(ENV{CTEST_OUTPUT_ON_FAILURE} ON) -# Run this test in debug mode. In Release mode, this does not do anything. -set(MOOSE_BIN_LOCATION $<TARGET_FILE:moose.bin>) -message(STATUS "Executable moose.bin will be at ${MOOSE_BIN_LOCATION}" ) if(DEBUG) + # Run this test in debug mode. In Release mode, this does not do anything. + set(MOOSE_BIN_LOCATION $<TARGET_FILE:moose.bin>) + message(STATUS "Executable moose.bin will be at ${MOOSE_BIN_LOCATION}" ) + add_test(NAME moose.bin-raw-run COMMAND moose.bin -u -q) endif(DEBUG) diff --git a/moose-core/biophysics/Neuron.cpp b/moose-core/biophysics/Neuron.cpp index 4ae85145ffa04acc1521e7bfa8c9319fa809f44a..265635734f0cdc1e94456022614e5a7314321ff3 100644 --- a/moose-core/biophysics/Neuron.cpp +++ b/moose-core/biophysics/Neuron.cpp @@ -619,8 +619,8 @@ static void doClassSpecificMessaging( Shell* shell, Id obj, ObjId compt ) if ( obj.element()->cinfo()->isA( "ChanBase" ) ) { shell->doAddMsg( "Single", compt, "channel", obj, "channel" ); - // Add the message to the Ca pool if not defined - if ( obj.element()->getName().find_first_of( "Ca" ) != string::npos ) + // Add the message to the Ca pool if our obj has 'Ca' in its name. + if ( obj.element()->getName().find( "Ca" ) != string::npos ) { // Don't do it if we have the legacy GENESIS format if ( Neutral::child( obj.eref(), "addmsg1" ) == Id() ) @@ -631,9 +631,9 @@ static void doClassSpecificMessaging( Shell* shell, Id obj, ObjId compt ) wildcardFind( path, elist ); if ( elist.size() > 0 ) { - // cout << "Added Ca Msg for " << obj.path() << endl; + // cout << "Added Ca Msg for " << obj.path() << ", name = " << obj.element()->getName() << endl; ObjId mid = shell->doAddMsg( - "single", obj, "IkOut", elist[0], "current" ); + "single", obj, "IkOut", elist[0], "current" ); assert( !mid.bad()); } } diff --git a/moose-core/builtins/TableBase.cpp b/moose-core/builtins/TableBase.cpp index 4ed17b6904f5b83c40d4c9a61c12fb4eb969eeb5..f5c11e754d02f955b779e7611bf8ef30d2aec35d 100644 --- a/moose-core/builtins/TableBase.cpp +++ b/moose-core/builtins/TableBase.cpp @@ -24,6 +24,13 @@ const Cinfo* TableBase::initCinfo() &TableBase::getVec ); + static ValueFinfo< TableBase, string > plotDump( + "plotDump", + "'File plotname' for dumpling an xplot, as a workaround for an error in the xplot python interface. Note separator is a space. The return value is a dummy.", + &TableBase::setPlotDump, + &TableBase::getPlotDump + ); + static ReadOnlyValueFinfo< TableBase, double > outputValue( "outputValue", "Output value holding current table entry or output of a calculation", @@ -115,6 +122,7 @@ const Cinfo* TableBase::initCinfo() static Finfo* tableBaseFinfos[] = { &vec, // Value + &plotDump, // Value, used for debugging xplot function. &outputValue, // ReadOnlyValue &size, // ReadOnlyValue &y, // ReadOnlyLookupValue @@ -491,3 +499,21 @@ const vector< double >& TableBase::data( ) { return vec_; } + +string TableBase::getPlotDump() const +{ + static string ret = "plot.Dump"; + return ret; +} + +void TableBase::setPlotDump( string v ) +{ + + std::size_t pos = v.rfind(" "); + string fname = v.substr( 0, pos ); + string plotname = "plot"; + if ( pos != string::npos ) + plotname = v.substr( pos ); + // cout << "setPlotDump( " << fname << ", " << plotname << " ), " << v << "\n"; + xplot( fname, plotname ); +} diff --git a/moose-core/builtins/TableBase.h b/moose-core/builtins/TableBase.h index 5c497a9ed409339ff9b2c1ad2a81000b23e6fa90..ada46bec7d4a544fd8dde22fbf84891dd101fb2e 100644 --- a/moose-core/builtins/TableBase.h +++ b/moose-core/builtins/TableBase.h @@ -32,6 +32,9 @@ public: double getOutputValue() const; void setOutputValue( double val ); + string getPlotDump() const; + void setPlotDump( string v ); + double getY( unsigned int index ) const; ////////////////////////////////////////////////////////////////// diff --git a/moose-core/cmake_modules/FindNumPy.cmake b/moose-core/cmake_modules/FindNumPy.cmake index b2813e9cd2c46a747b3ac31ee2c3459c32db59d0..f14142f18652c1081f098319b47bf123329352de 100644 --- a/moose-core/cmake_modules/FindNumPy.cmake +++ b/moose-core/cmake_modules/FindNumPy.cmake @@ -39,8 +39,6 @@ #============================================================================ # Finding NumPy involves calling the Python interpreter -set(Python_ADDITIONAL_VERSIONS "2.6 2.7") -message(STATUS "DEBUG: Python_ADDITIONAL_VERSIONS ${Python_ADDITIONAL_VERSIONS}") if(NumPy_FIND_REQUIRED) find_package(PythonInterp REQUIRED) else() diff --git a/moose-core/dependencies_list_script/dependencies b/moose-core/dependencies_list_script/dependencies deleted file mode 100644 index 798f7bdca84b6f2a2194782ee577696f214e35c0..0000000000000000000000000000000000000000 --- a/moose-core/dependencies_list_script/dependencies +++ /dev/null @@ -1,19 +0,0 @@ -# AUTHOR : AVIRAL GOEL -# EMAIL-ID : - -# MOOSE Dependencies -libgsl0-dev -libgsl0ldbl -libhdf5-dev -libxml2-dev - -# GUI Dependencies -#If one needs MOOSE GUI, install below mentioned libraries else comment -libqt4-dev -python-qt4-dev - -# MOOGLI Dependencies -#If one needs MOOGLI, install below mentioned libraries else comment -libopenscenegraph-dev -python-sip-dev -python-qt4-gl diff --git a/moose-core/dependencies_list_script/ubuntu-dep b/moose-core/dependencies_list_script/ubuntu-dep deleted file mode 100644 index 021e66850b73dbd6c13d9b1a2f7d058fe0e7cdd9..0000000000000000000000000000000000000000 --- a/moose-core/dependencies_list_script/ubuntu-dep +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env sh -# AUTHOR : AVIRAL GOEL -# EMAIL-ID : - -echo "Installing dependencies for Ubuntu\n" -sudo -E apt-get install $(grep -vE "^\s*#" dependencies | tr "\n" " ") -# if one needs SBML support run the below two lines else comment -#CURRENTLY libSBML-5.9.0 is supported -sbmlurl="http://sourceforge.net/projects/sbml/files/libsbml/5.9.0/stable/Linux/64-bit/libSBML-5.9.0-Linux-x64.deb" -sudo -E wget "$sbmlurl" -O "libsbml.deb" && sudo -E dpkg -i "libsbml.deb" && sudo -E rm -rf "libsbml.deb" -echo "Installed dependencies for Ubuntu\n" - diff --git a/moose-core/pymoose/CMakeLists.txt b/moose-core/pymoose/CMakeLists.txt index 0468f1acf63df56d323e47e5a24577be6ec425c6..7f08aab1c500d9c01f4417d9ba70d3169026568d 100644 --- a/moose-core/pymoose/CMakeLists.txt +++ b/moose-core/pymoose/CMakeLists.txt @@ -90,3 +90,15 @@ add_custom_target(copy_python_files ) add_dependencies(_moose copy_python_files) + + +# Print message at the end of build process. +add_custom_command( TARGET _moose POST_BUILD + COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan + "MOOSE python extention is successfully built. Now " + " 1. Run 'make install' to install it single user. " + " 2. Run 'sudo make install' to install it system-wide. " + " " + " After installation, 'pip uninstall moose' will uninstall moose. " + VERBATIM + ) diff --git a/moose-core/python/moose/SBML/readSBML.py b/moose-core/python/moose/SBML/readSBML.py index c5b00c528641e20764fec236712e8ea70aa167ff..59caa670774be16183199448d7e61102754c3518 100644 --- a/moose-core/python/moose/SBML/readSBML.py +++ b/moose-core/python/moose/SBML/readSBML.py @@ -563,7 +563,7 @@ def createReaction(model, specInfoMap, modelAnnotaInfo, globparameterIdValue,fun if (reac.isSetId()): rId = reac.getId() - groups = [k for k, v in groupInfo.iteritems() if rId in v] + groups = [k for k, v in groupInfo.items() if rId in v] if groups: group = groups[0] if (reac.isSetName()): @@ -1094,7 +1094,7 @@ def createSpecies(basePath, model, comptSbmlidMooseIdMap, sName = None sId = spe.getId() - groups = [k for k, v in groupInfo.iteritems() if sId in v] + groups = [k for k, v in groupInfo.items() if sId in v] if groups: group = groups[0] if spe.isSetName(): diff --git a/moose-core/python/moose/chemMerge/merge.py b/moose-core/python/moose/chemMerge/merge.py index 5b406a25a99ef8428987ac88ab68cb8b2e9a3368..49d7d7162b9ee6ee4c98d86b5769d6bc68967343 100644 --- a/moose-core/python/moose/chemMerge/merge.py +++ b/moose-core/python/moose/chemMerge/merge.py @@ -12,7 +12,7 @@ #** copyright (C) 2003-2017 Upinder S. Bhalla. and NCBS #Created : Friday Dec 16 23:19:00 2016(+0530) #Version -#Last-Updated: Wed Oct 14 00:25:33 2017(+0530) +#Last-Updated: Wed Oct 25 16:25:33 2017(+0530) # By: Harsha #**********************************************************************/ @@ -39,6 +39,7 @@ # ''' Change log +Oct 25: line to load SBML file was commented, which is uncommented now and also while copying MMenz had a problem which also cleaned up Oct 14: absolute import with mtypes just for python3 Oct 12: clean way of cheking the type of path provided, filepath,moose obj, moose path are taken, @@ -350,9 +351,10 @@ def loadModels(filepath): loaded = True elif subtype == 'sbml': - #moose.mooseReadSBML(filename,modelpath) - #loaded = True - pass + if moose.exists(modelpath): + moose.delete(modelpath) + moose.mooseReadSBML(filepath,modelpath) + loaded = True else: print("This file is not supported for mergering") modelpath = moose.Shell('/') @@ -512,7 +514,7 @@ def enzymeMerge(comptA,comptB,key,poolListina): if eb.className in ["ZombieMMenz","MMenz"]: eapath = eb.parent.path.replace(objB,objA) - enz = moose.copy(eb.name,moose.element(eapath)) + enz = moose.copy(eb,moose.element(eapath)) enzinfo = moose.Annotator(enz.path+'/info') moose.connect(moose.element(enz).parent,"nOut",moose.element(enz),"enzDest") #moose.connect(moose.element(enz),"enz",moose.element(enz).parent,"reac") diff --git a/moose-core/python/rdesigneur/__init__.py b/moose-core/python/rdesigneur/__init__.py index 188e877d28b4f897865afd7f15a6332c191559a1..caa67eabfcbe9b8311e36d0f7bcb300bf02d3305 100644 --- a/moose-core/python/rdesigneur/__init__.py +++ b/moose-core/python/rdesigneur/__init__.py @@ -3,3 +3,4 @@ from __future__ import print_function, absolute_import from rdesigneur.rdesigneur import * from rdesigneur.rdesigneur import rdesigneur +import rdesigneur.rmoogli as rmoogli diff --git a/moose-core/python/rdesigneur/rdesigneur.py b/moose-core/python/rdesigneur/rdesigneur.py index 5d1de41ef95d72dc860cb02fb503c3eae6507048..375fe76dec4b290b0e68c85c65370df6cef148cb 100644 --- a/moose-core/python/rdesigneur/rdesigneur.py +++ b/moose-core/python/rdesigneur/rdesigneur.py @@ -22,10 +22,12 @@ import imp import os import moose import numpy as np -import pylab import math +import itertools +import sys +import time -import rdesigneur.rmoogli +import rdesigneur.rmoogli as rmoogli from rdesigneur.rdesigneurProtos import * from moose.neuroml.NeuroML import NeuroML @@ -497,6 +499,10 @@ class rdesigneur: j += 1 return ret + # Utility function for doing lookups for objects. + def _makeUniqueNameStr( self, obj ): + return obj.name + " " + str( obj.index ) + # Returns vector of source objects, and the field to use. # plotSpec is of the form # [ region_wildcard, region_expr, path, field, title] @@ -510,7 +516,6 @@ class rdesigneur: kf = knownFields[field] # Find the field to decide type. if ( kf[0] == 'CaConcBase' or kf[0] == 'ChanBase' or kf[0] == 'NMDAChan' ): objList = self._collapseElistToPathAndClass( comptList, plotSpec[2], kf[0] ) - # print ("objList: ", len(objList), kf[1]) return objList, kf[1] elif (field == 'n' or field == 'conc' or field == 'volume' ): path = plotSpec[2] @@ -521,15 +526,11 @@ class rdesigneur: chemCompt = path[:pos] cc = moose.element( self.modelPath + '/chem/' + chemCompt) voxelVec = [] - if ( chemCompt == 'dend' ): - for i in comptList: - voxelVec.extend( cc.dendVoxelsOnCompartment[i] ) - else: - em = cc.elecComptMap - elecComptMap = { moose.element(em[i]):i for i in range(len(em)) } - for i in comptList: - if i in elecComptMap: - voxelVec.extend( [ elecComptMap[i] ] ) + temp = [ self._makeUniqueNameStr( i ) for i in comptList ] + comptSet = set( temp ) + #em = [ moose.element(i) for i in cc.elecComptMap ] + em = [ self._makeUniqueNameStr(i) for i in cc.elecComptMap ] + voxelVec = [i for i in range(len( em ) ) if em[i] in comptSet ] # Here we collapse the voxelVec into objects to plot. allObj = moose.vec( self.modelPath + '/chem/' + plotSpec[2] ) #print "####### allObj=", self.modelPath + '/chem/' + plotSpec[2] @@ -637,29 +638,31 @@ class rdesigneur: rmoogli.displayMoogli( self, moogliDt, runtime, rotation ) def display( self ): + import matplotlib.pyplot as plt for i in self.plotNames: - - pylab.figure( i[2] ) - pylab.title( i[1] ) - pylab.xlabel( "Time (s)" ) - pylab.ylabel( i[4] ) + plt.figure( i[2] ) + plt.title( i[1] ) + plt.xlabel( "Time (s)" ) + plt.ylabel( i[4] ) vtab = moose.vec( i[0] ) if i[5] == 'spikeTime': k = 0 tmax = moose.element( '/clock' ).currentTime for j in vtab: # Plot a raster y = [k] * len( j.vector ) - pylab.plot( j.vector * i[3], y, linestyle = 'None', marker = '.', markersize = 10 ) - pylab.xlim( 0, tmax ) + plt.plot( j.vector * i[3], y, linestyle = 'None', marker = '.', markersize = 10 ) + plt.xlim( 0, tmax ) else: t = np.arange( 0, vtab[0].vector.size, 1 ) * vtab[0].dt for j in vtab: - pylab.plot( t, j.vector * i[3] ) + plt.plot( t, j.vector * i[3] ) if len( self.moogList ) > 0: - pylab.ion() - pylab.show(block=True) - self._save() #This calls the _save function which saves only if the filenames have been specified + plt.ion() + plt.show(block=True) + + #This calls the _save function which saves only if the filenames have been specified + self._save() ################################################################ # Here we get the time-series data and write to various formats @@ -908,6 +911,7 @@ class rdesigneur: ################################################################ # Utility function for setting up clocks. def _configureClocks( self ): + t0 = time.time() if self.turnOffElec: elecDt = 1e6 elecPlotDt = 1e6 @@ -916,16 +920,22 @@ class rdesigneur: elecPlotDt = self.elecPlotDt diffDt = self.diffDt chemDt = self.chemDt + print( "t1 = {}".format( time.time() - t0 ) ) for i in range( 0, 9 ): moose.setClock( i, elecDt ) moose.setClock( 8, elecPlotDt ) moose.setClock( 10, diffDt ) + print( "t2 = {}".format( time.time() - t0 ) ) for i in range( 11, 18 ): moose.setClock( i, chemDt ) moose.setClock( 18, self.chemPlotDt ) + print( "t3 = {}".format( time.time() - t0 ) ) hsolve = moose.HSolve( self.elecid.path + '/hsolve' ) hsolve.dt = elecDt + print( "t4 = {}".format( time.time() - t0 ) ) hsolve.target = self.soma.path + print( "t5 = {}".format( time.time() - t0 ) ) + sys.stdout.flush() ################################################################ ################################################################ ################################################################ @@ -1259,18 +1269,6 @@ class rdesigneur: else: elecComptList = mesh.elecComptList - ''' - for i in elecComptList: - print i.diameter - print len( elecComptList[0] ) - print elecComptList[0][0].parent.path - print "--------------------------------------" - spine = moose.vec( elecComptList[0].path + '/../spine' ) - for i in spine: - print i.headDiameter - - moose.le( elecComptList[0][0].parent ) - ''' if len( elecComptList ) == 0: raise BuildError( \ "buildAdaptor: no elec compts in elecComptList on: " + \ diff --git a/moose-core/python/setup.cmake.py b/moose-core/python/setup.cmake.py new file mode 100644 index 0000000000000000000000000000000000000000..5be008816416b68bd52fc8f29f48ac72efc7a0b8 --- /dev/null +++ b/moose-core/python/setup.cmake.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- + +"""setup.py: +Script to install python targets. + +NOTE: This script is to be called by CMake. Not intended to be used standalone. + +""" + +__author__ = "Dilawar Singh" +__copyright__ = "Copyright 2013, Dilawar Singh and NCBS Bangalore" +__credits__ = ["NCBS Bangalore"] +__license__ = "GNU GPL" +__version__ = "1.0.0" +__maintainer__ = "Dilawar Singh" +__email__ = "dilawars@ncbs.res.in" +__status__ = "Development" + +import os +import sys +import site + +# if uid is zero then install in root paths. Else install it in user path. + +print( '[INFO] Overwriting --prefix ' ) +try: + prefixLoc = sys.argv.index( '--prefix' ) + del sys.argv[ prefixLoc ] + del sys.argv[ prefixLoc ] +except Exception as e: + pass + +uid = os.getuid( ) +if uid == 0: + # Here comes the root. + print( ' called by sudo' ) + sys.argv += [ '--prefix', '/usr' ] +else: + sys.argv += [ '--prefix', site.getuserbase( ) ] + +print( sys.argv ) + +from distutils.core import setup + +script_dir = os.path.dirname( os.path.abspath( __file__ ) ) + +version = '3.2.git' +try: + with open( os.path.join( script_dir, '..', 'VERSION'), 'r' ) as f: + version = f.read( ) +except Exception as e: + print( 'Failed to read VERSION %s' % e ) + print( 'Using default %s' % version ) + +try: + import importlib.machinery + suffix = importlib.machinery.EXTENSION_SUFFIXES[0] +except Exception as e: + print( '[WARN] Failed to determine importlib suffix' ) + suffix = '.so' + +setup( + name='moose', + version=version, + description='MOOSE python scripting module.', + author='MOOSERes', + author_email='bhalla@ncbs.res.in', + maintainer='Dilawar Singh', + maintainer_email='dilawars@ncbs.res.in', + url='http://moose.ncbs.res.in', + packages=[ + 'rdesigneur' + , 'moose' + , 'moose.SBML' + , 'moose.neuroml' + , 'moose.genesis' + , 'moose.chemUtil' + , 'moose.chemMerge' + ], + package_dir = { + 'moose' : 'moose' + , 'rdesigneur' : 'rdesigneur' + }, + package_data = { 'moose' : ['_moose' + suffix] }, + ) diff --git a/moose-core/tests/python/abstrModelEqns9.py b/moose-core/tests/python/abstrModelEqns9.py index ae57be3f67667d603f4bda398264e1d6990da81d..208632e59eacb35e211cc1dee14e13b35b8f8c68 100644 --- a/moose-core/tests/python/abstrModelEqns9.py +++ b/moose-core/tests/python/abstrModelEqns9.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + import re import moose diff --git a/moose-core/tests/python/test_muparser.py b/moose-core/tests/python/test_muparser.py index d889df4680ff8403ee369beac57212b8fab3cdd0..7adf0e26757604cb78cb53983cd5399fce2fa7a0 100644 --- a/moose-core/tests/python/test_muparser.py +++ b/moose-core/tests/python/test_muparser.py @@ -1,167 +1,165 @@ -# -*- coding: utf-8 -*- -"""test_muparser.py: - -""" - -__author__ = "Dilawar Singh" -__copyright__ = "Copyright 2017-, Dilawar Singh" -__version__ = "1.0.0" -__maintainer__ = "Dilawar Singh" -__email__ = "dilawars@ncbs.res.in" -__status__ = "Development" - -import sys -import os -import numpy as np -import sys -import numpy as np -import moose -import abstrModelEqns9 as ame -import rdesigneur as rd - - -def singleCompt( name, params ): - mod = moose.copy( '/library/' + name + '/' + name, '/model' ) - A = moose.element( mod.path + '/A' ) - Z = moose.element( mod.path + '/Z' ) - Z.nInit = 1 - Ca = moose.element( mod.path + '/Ca' ) - CaStim = moose.element( Ca.path + '/CaStim' ) - runtime = params['preStimTime'] + params['postStimTime'] - steptime = 50 - - CaStim.expr += ' + x2 * (t > 100+' + str( runtime ) + ' ) * ( t < 100+' + str( runtime + steptime ) + ' )' - print(CaStim.expr) - tab = moose.Table2( '/model/' + name + '/Atab' ) - ampl = moose.element( mod.path + '/ampl' ) - phase = moose.element( mod.path + '/phase' ) - moose.connect( tab, 'requestOut', A, 'getN' ) - ampl.nInit = params['stimAmplitude'] * 1 - phase.nInit = params['preStimTime'] - - ksolve = moose.Ksolve( mod.path + '/ksolve' ) - stoich = moose.Stoich( mod.path + '/stoich' ) - stoich.compartment = mod - stoich.ksolve = ksolve - stoich.path = mod.path + '/##' - - moose.reinit() - runtime += 100 + steptime*2 - moose.start( runtime ) - t = np.arange( 0, runtime + 1e-9, tab.dt ) - return name, t, tab.vector - - -def plotPanelC(): - panelC = [] - panelCticks = [] - panelC.append( singleCompt( 'negFB', ame.makeNegFB( [] ) ) ) - panelC.append( singleCompt( 'negFF', ame.makeNegFF( [] ) ) ) - panelC.append( singleCompt( 'fhn', ame.makeFHN( [] ) ) ) - panelC.append( singleCompt( 'bis', ame.makeBis( [] ) ) ) - - panelCticks.append( np.arange( 0, 15.00001, 5 ) ) - panelCticks.append( np.arange( 0, 1.50001, 0.5 ) ) - panelCticks.append( np.arange( 0, 5.00002, 1 ) ) - panelCticks.append( np.arange( 0, 5.00002, 1 ) ) - moose.delete( '/model' ) - for i in zip( panelC, panelCticks, list(range( len( panelC ))) ): - plotPos = i[2] + 5 - doty = i[1][-1] * 0.95 - print('doty', doty ) - -def runPanelDEFG( name, dist, seqDt, numSpine, seq, stimAmpl ): - preStim = 10.0 - blanks = 20 - rdes = rd.rdesigneur( - useGssa = False, - turnOffElec = True, - chemPlotDt = 0.1, - diffusionLength = 1e-6, - cellProto = [['cell', 'soma']], - chemProto = [['dend', name]], - chemDistrib = [['dend', 'soma', 'install', '1' ]], - plotList = [['soma', '1', 'dend' + '/A', 'n', '# of A']], - ) - rdes.buildModel() - A = moose.vec( '/model/chem/dend/A' ) - Z = moose.vec( '/model/chem/dend/Z' ) - print(moose.element( '/model/chem/dend/A/Adot' ).expr) - print(moose.element( '/model/chem/dend/B/Bdot' ).expr) - print(moose.element( '/model/chem/dend/Ca/CaStim' ).expr) - phase = moose.vec( '/model/chem/dend/phase' ) - ampl = moose.vec( '/model/chem/dend/ampl' ) - vel = moose.vec( '/model/chem/dend/vel' ) - vel.nInit = 1e-6 * seqDt - ampl.nInit = stimAmpl - stride = int( dist ) / numSpine - phase.nInit = 10000 - Z.nInit = 0 - for j in range( numSpine ): - k = int( blanks + j * stride ) - Z[k].nInit = 1 - phase[k].nInit = preStim + seq[j] * seqDt - - moose.reinit() - runtime = 50 - snapshot = preStim + seqDt * (numSpine - 0.8) - print(snapshot) - moose.start( snapshot ) - avec = moose.vec( '/model/chem/dend/A' ).n - moose.start( runtime - snapshot ) - tvec = [] - for i in range( 5 ): - tab = moose.element( '/model/graphs/plot0[' + str( blanks + i * stride ) + ']' ) - dt = tab.dt - tvec.append( tab.vector ) - moose.delete( '/model' ) - return dt, tvec, avec - -def makePassiveSoma( name, length, diameter ): - elecid = moose.Neuron( '/library/' + name ) - dend = moose.Compartment( elecid.path + '/soma' ) - dend.diameter = diameter - dend.length = length - dend.x = length - return elecid - -def plotOnePanel( tLabel, dt, tplot, numSyn, plotRange, tick ): - t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt - for i in range( 5 ): - print( tplot[i] ) - - -def plotPanelDEFG( seq, row ): - makePassiveSoma( 'cell', 100e-6, 10e-6 ) - start = (row -1) * 4 - tLabel = chr( ord( 'B' ) + row - 1 ) - xLabel = chr( ord( 'D' ) + row - 1 ) - xplot = [] - - - dt, tplot, avec = runPanelDEFG( 'negFB', 5.0, 2.0, 5, seq, 1.0 ) - xplot.append( avec ) - t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt - - dt, tplot, avec = runPanelDEFG( 'negFF', 10.0, 1.0, 5, seq, 1.0 ) - xplot.append( avec ) - t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt - dt, tplot, avec = runPanelDEFG( 'fhn', 5.0, 1.5, 5, seq, 0.4 ) - xplot.append( avec ) - t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt - - dt, tplot, avec = runPanelDEFG( 'bis', 15.0, 2.0, 5, seq, 1.0 ) - xplot.append( avec ) - t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt - ref = np.array( [0.04840247926323106, 0.060446860947786119 - , 0.047612129439079991, 0.081329604404641223, 0.050365470686926379] ) - res = np.array( [ np.mean( x ) for x in tplot ] ) - assert np.isclose( ref.all(), res.all() ), "Expected %s got %s" % (ref,res) - -if __name__ == '__main__': - moose.Neutral( '/library' ) - moose.Neutral( '/model' ) - plotPanelC() - plotPanelDEFG( [0,1,2,3,4], 3 ) - plotPanelDEFG( [4,1,0,3,2], 4 ) - print( 'All done' ) +# -*- coding: utf-8 -*- + +"""test_muparser.py: + +Modified from https://elifesciences.org/articles/25827 , Fig4.py + +""" +import sys +import os +import numpy as np +import sys +import numpy as np +import moose +import abstrModelEqns9 as ame +import rdesigneur as rd + + +def singleCompt( name, params ): + mod = moose.copy( '/library/' + name + '/' + name, '/model' ) + A = moose.element( mod.path + '/A' ) + Z = moose.element( mod.path + '/Z' ) + Z.nInit = 1 + Ca = moose.element( mod.path + '/Ca' ) + CaStim = moose.element( Ca.path + '/CaStim' ) + runtime = params['preStimTime'] + params['postStimTime'] + steptime = 50 + + CaStim.expr += ' + x2 * (t > 100+' + str( runtime ) + ' ) * ( t < 100+' + str( runtime + steptime ) + ' )' + print(CaStim.expr) + tab = moose.Table2( '/model/' + name + '/Atab' ) + ampl = moose.element( mod.path + '/ampl' ) + phase = moose.element( mod.path + '/phase' ) + moose.connect( tab, 'requestOut', A, 'getN' ) + ampl.nInit = params['stimAmplitude'] * 1 + phase.nInit = params['preStimTime'] + + ksolve = moose.Ksolve( mod.path + '/ksolve' ) + stoich = moose.Stoich( mod.path + '/stoich' ) + stoich.compartment = mod + stoich.ksolve = ksolve + stoich.path = mod.path + '/##' + + moose.reinit() + runtime += 100 + steptime*2 + moose.start( runtime ) + t = np.arange( 0, runtime + 1e-9, tab.dt ) + return name, t, tab.vector + + +def plotPanelC(): + panelC = [] + panelCticks = [] + panelC.append( singleCompt( 'negFB', ame.makeNegFB( [] ) ) ) + panelC.append( singleCompt( 'negFF', ame.makeNegFF( [] ) ) ) + panelC.append( singleCompt( 'fhn', ame.makeFHN( [] ) ) ) + panelC.append( singleCompt( 'bis', ame.makeBis( [] ) ) ) + + panelCticks.append( np.arange( 0, 15.00001, 5 ) ) + panelCticks.append( np.arange( 0, 1.50001, 0.5 ) ) + panelCticks.append( np.arange( 0, 5.00002, 1 ) ) + panelCticks.append( np.arange( 0, 5.00002, 1 ) ) + moose.delete( '/model' ) + for i in zip( panelC, panelCticks, list(range( len( panelC ))) ): + plotPos = i[2] + 5 + doty = i[1][-1] * 0.95 + print('doty', doty ) + +def runPanelDEFG( name, dist, seqDt, numSpine, seq, stimAmpl ): + preStim = 10.0 + blanks = 20 + rdes = rd.rdesigneur( + useGssa = False, + turnOffElec = True, + chemPlotDt = 0.1, + diffusionLength = 1e-6, + cellProto = [['cell', 'soma']], + chemProto = [['dend', name]], + chemDistrib = [['dend', 'soma', 'install', '1' ]], + plotList = [['soma', '1', 'dend' + '/A', 'n', '# of A']], + ) + rdes.buildModel() + A = moose.vec( '/model/chem/dend/A' ) + Z = moose.vec( '/model/chem/dend/Z' ) + print(moose.element( '/model/chem/dend/A/Adot' ).expr) + print(moose.element( '/model/chem/dend/B/Bdot' ).expr) + print(moose.element( '/model/chem/dend/Ca/CaStim' ).expr) + phase = moose.vec( '/model/chem/dend/phase' ) + ampl = moose.vec( '/model/chem/dend/ampl' ) + vel = moose.vec( '/model/chem/dend/vel' ) + vel.nInit = 1e-6 * seqDt + ampl.nInit = stimAmpl + stride = int( dist ) / numSpine + phase.nInit = 10000 + Z.nInit = 0 + for j in range( numSpine ): + k = int( blanks + j * stride ) + Z[k].nInit = 1 + phase[k].nInit = preStim + seq[j] * seqDt + + moose.reinit() + runtime = 50 + snapshot = preStim + seqDt * (numSpine - 0.8) + print(snapshot) + moose.start( snapshot ) + avec = moose.vec( '/model/chem/dend/A' ).n + moose.start( runtime - snapshot ) + tvec = [] + for i in range( 5 ): + tab = moose.element( '/model/graphs/plot0[' + str( blanks + i * stride ) + ']' ) + dt = tab.dt + tvec.append( tab.vector ) + moose.delete( '/model' ) + return dt, tvec, avec + +def makePassiveSoma( name, length, diameter ): + elecid = moose.Neuron( '/library/' + name ) + dend = moose.Compartment( elecid.path + '/soma' ) + dend.diameter = diameter + dend.length = length + dend.x = length + return elecid + +def plotOnePanel( tLabel, dt, tplot, numSyn, plotRange, tick ): + t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt + for i in range( 5 ): + print( tplot[i] ) + + +def plotPanelDEFG( seq, row ): + makePassiveSoma( 'cell', 100e-6, 10e-6 ) + start = (row -1) * 4 + tLabel = chr( ord( 'B' ) + row - 1 ) + xLabel = chr( ord( 'D' ) + row - 1 ) + xplot = [] + + + dt, tplot, avec = runPanelDEFG( 'negFB', 5.0, 2.0, 5, seq, 1.0 ) + xplot.append( avec ) + t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt + + dt, tplot, avec = runPanelDEFG( 'negFF', 10.0, 1.0, 5, seq, 1.0 ) + xplot.append( avec ) + t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt + dt, tplot, avec = runPanelDEFG( 'fhn', 5.0, 1.5, 5, seq, 0.4 ) + xplot.append( avec ) + t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt + + dt, tplot, avec = runPanelDEFG( 'bis', 15.0, 2.0, 5, seq, 1.0 ) + xplot.append( avec ) + t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt + ref = np.array( [0.04840247926323106, 0.060446860947786119 + , 0.047612129439079991, 0.081329604404641223, 0.050365470686926379] ) + res = np.array( [ np.mean( x ) for x in tplot ] ) + assert np.isclose( ref.all(), res.all() ), "Expected %s got %s" % (ref,res) + +if __name__ == '__main__': + moose.Neutral( '/library' ) + moose.Neutral( '/model' ) + plotPanelC() + #if sys.version_info[0] == 2: + # plotPanelDEFG( [0,1,2,3,4], 3 ) + # plotPanelDEFG( [4,1,0,3,2], 4 ) + #else: + # print( 'TODO: Running any of the following two functions causes seg-fault' ) + print( 'All done' )