Skip to content
Snippets Groups Projects
Commit 34d5a609 authored by Dilawar Singh's avatar Dilawar Singh
Browse files

Merge branch 'chamcham' of github.com:BhallaLab/moose into chamcham

parents 08c05259 6321ad1a
No related branches found
No related tags found
No related merge requests found
Installation
============
Use pre-built packages
----------------------
Linux
^^^^^
We recommend that you use our repositories hosted at `Open Build Service
<http://build.opensuse.org>`_. We have packages for the following distributions
- Debian 7.0, 8.0
- Ubuntu 12.04, 14.04, 15.04, 15.10, 16.04
- CentOS 6, 7
- Fedora 20, 21, 22, 23
- OpenSUSE 13.1, 13.2, Factory ARM, Leap 42.1, Tumbleweed
- SLE 12, 12 SP1
- RHEL 7
- Scientific Linux 7
Visit `this page
<https://software.opensuse.org/download.html?project=home:moose&package=moose>`_
pick you distribution and follow instructions.
.. note::
``moogli`` (tool to visualize network activity) is not available for CentOS-6.
.. raw:: html
<iframe
src="http://software.opensuse.org/download/package.iframe?project=moose&package=moose"></iframe>
.. todo:: Packages for gentoo, Arch Linux
Mac OSX
^^^^^^
Download the ``dmg`` file from `here <https://github.com/BhallaLab/moose/releases/download/ghevar_3.0.2/Moose_3.0.2_OSX.dmg>`_.
Alternatively, you can use ``homebrew`` to install ``moose``
::
$ brew install homebrew/science/moose
Windows/Cygwin
^^^^^^^^^^^^^^
Building MOOSE
--------------
In case your distribution is not listed on `our repository page
<https://software.opensuse.org/download.html?project=home:moose&package=moose>`_
, or if you want to build the lastest development code, read on.
First, you need to get the source code. You can use ``git`` (clone the
repository) or download snapshot of github repo by clicking on `this link
<https://github.com/BhallaLab/moose/archive/master.zip>`_.::
$ git clone https://github.com/BhallaLab/moose
Or,
::
$ wget https://github.com/BhallaLab/moose/archive/master.zip
$ unzip master.zip
If you don't want lasest snapshot of ``MOOSE``, you can download other released
versions from here `https://github.com/BhallaLab/moose/releases`.
Install dependencies
~~~~~~~~~~~~~~~~~~~
Next, you need to install required dependencies. Depending on your OS, names of
following packages may vary.
- cmake (version 2.8 or higher)
- gsl-1.16 or higher `download <ftp://ftp.gnu.org/gnu/gsl/>`_.
- libhdf5 development package e.g. `libhdf5-serial-dev` or `libhdf5-devel`
- python development package e.g. `python-dev` or `python-devel`
- numpy e.g. `python-numpy` or `numpy`
Most of the dependencies can be installed using package manager.
On ``Debian/Ubuntu``
::
$ sudo apt-get install libhdf5-dev cmake libgsl0-dev libpython-dev python-numpy
.. note::
Ubuntu 12.04 does not have required version of ``gsl`` (required 1.16 or
higher, available 1.15). On Ubuntu 16.04, package name is ``libgsl-dev``.
On ``CentOS/Fedora/RHEL/Scientific Linux``
::
$ sudo yum install hdf5-devel cmake libgsl-dev python-devel python-numpy
On ``OpenSUSE``
::
$ sudo zypper install hdf5-devel cmake libgsl-dev python-devel python-numpy
Now use `cmake` to build moose
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. codeblock:: bash
$ cd /to/moose/source/code
$ mkdir _build
$ cd _build
$ cmake ..
$ make
$ ctest --output-on-failure # optional
This will build pyMOOSE (MOOSE's python extention), `ctest` will run few tests to
check if build process was successful.
.. note::
To install MOOSE into non-standard directory, pass additional argument
`-DCMAKE_INSTALL_PREFIX=path/to/install/dir` to cmake
::
$ cmake -DCMAKE_INSTALL_PREFIC=$HOME/.local ..
To use different version of python
::
$ cmake -DPYTHON_EXECUTABLE=/opt/python3/bin/python3 ..
After that installation is pretty easy
::
$ sudo make install
If everything went fine, you should be able to import moose in python shell.
.. code-block:: python
import moose
Graphical User Interface (GUI)
------------------------------
You can get the source of ``moose-gui`` from `here
<https://github.com/BhallaLab/moose-gui>`_. You can download it either by
clicking on `this link <https://github.com/BhallaLab/moose-gui/archive/master.zip>`_
or by using ``git`` ::
$ git clone https://github.com/BhallaLab/moose-gui
To be able to launch ``moose-gui``, you need to install some more packages
- matplotlib
- python-qt4
On ``Ubuntu/Debian``, these can be installed with
::
$ sudo apt-get install python-matplotlib python-qt4
On ``CentOS/Fedora/RHEL``
::
$ sudo yum install python-matplotlib python-qt4
Now you can fire up the GUI
::
$ cd /to/moose-gui
$ python mgui.py
.. note::
If you have installed ``moose`` package, then GUI is launched by
running following commnad::
$ moose
Building moogli
---------------
``moogli`` is subproject of ``MOOSE`` for visualizing models. More details can
be found `here <http://moose.ncbs.res.in/moogli>`_.
`Moogli` is part of `moose` package. Building moogli can be tricky because of
multiple depednecies it has.
To get the latest source code of ``moogli``, click on `this link <https://github.com/BhallaLab/moogli/archive/master.zip>`_.
Moogli depends on ``OpenSceneGraph`` (version 3.2.0 or higher) which may not
be easily available for your operating system.
For this reason, we distribute required ``OpenSceneGraph`` with ``moogli``
source code.
Depending on distribution of your operating system, you would need following
packages to be installed.
On ``Ubuntu/Debian``
::
$ sudo apt-get install python-qt4-dev python-qt4-gl python-sip-dev libqt4-dev
On ``Fedora/CentOS/RHEL``
::
$ sudo yum install sip-devel PyQt4-devel qt4-devel libjpeg-devel PyQt4
On ``openSUSE``
::
$ sudo zypper install python-sip python-qt4-devel libqt4-devel python-qt4
After this, building and installing ``moogli`` should be as simple as
::
$ cd /path/to/moogli
$ mkdir _build
$ cd _build
$ cmake ..
$ make
$ sudo make install
If you run into troubles, please report it on our `github repository
<https://github.com/BhallaLab/moose/issues>`_.
# analogStimTable.py ---
#
# Filename: analogStimTable.py
# Description:
# Author: Upi Bhalla
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street, Fifth
# Floor, Boston, MA 02110-1301, USA.
#
import numpy as np
import pylab
import moose
from moose import utils
def analogStimTable():
simtime = 150
simdt = 0.1
model = moose.Neutral('/model')
data = moose.Neutral('/data')
# This is the stimulus generator
stimtable = moose.StimulusTable('/model/stim')
a = moose.BufPool( '/model/a' )
b = moose.Pool( '/model/b' )
reac = moose.Reac( '/model/reac' )
reac.Kf = 0.1
reac.Kb = 0.1
moose.connect( stimtable, 'output', a, 'setConcInit' )
moose.connect( reac, 'sub', a, 'reac' )
moose.connect( reac, 'prd', b, 'reac' )
aPlot = moose.Table('/data/aPlot')
moose.connect(aPlot, 'requestOut', a, 'getConc')
bPlot = moose.Table('/data/bPlot')
moose.connect(bPlot, 'requestOut', b, 'getConc')
moose.setClock( stimtable.tick, simdt )
moose.setClock( a.tick, simdt )
moose.setClock( aPlot.tick, simdt )
####################################################
# Here we set up the stimulus table. It is half a sine-wave.
stim = [ np.sin(0.01 * float(i) ) for i in range( 314 )]
stimtable.vector = stim
stimtable.stepSize = 0 # This forces use of current time as x value
# The table will interpolate its contents over the time start to stop:
# At values less than startTime, it emits the first value in table
stimtable.startTime = 5
# At values more than stopTime, it emits the last value in table
stimtable.stopTime = 60
stimtable.doLoop = 1 # Enable repeat playbacks.
stimtable.loopTime = 10 + simtime / 2.0 # Repeat playback over this time
moose.reinit()
moose.start(simtime)
t = [ x * simdt for x in range( len( aPlot.vector ) )]
pylab.plot( t, aPlot.vector, label='Stimulus waveform' )
pylab.plot( t, bPlot.vector, label='Reaction product b' )
pylab.legend()
pylab.show()
def main():
"""
Example of using a StimulusTable as an analog signal source in
a reaction system. It could be used similarly to give other
analog inputs to a model, such as a current or voltage clamp signal.
This demo creates a StimulusTable and assigns it half a sine wave.
Then we assign the start time and period over which to emit the wave.
The output of the StimTable is sent to a pool **a**, which participates
in a trivial reaction::
table ----> a <===> b
The output of **a** and **b** are recorded in a regular table
for plotting.
"""
analogStimTable()
if __name__ == '__main__':
main
#
# stimtable.py ends here
# function.py ---
#
# Filename: function.py
# Description:
# Author: Subhasis Ray
# Maintainer:
# Created: Tue Sep 9 17:59:50 2014 (+0530)
# Version:
# Last-Updated: Sun Dec 20 00:02:50 2015 (-0500)
# By: subha
# Update #: 4
# URL:
# Keywords:
# Compatibility:
#
#
# Commentary:
#
#
#
#
# Change log:
#
#
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street, Fifth
# Floor, Boston, MA 02110-1301, USA.
#
#
# Code:
import numpy as np
import sys
import matplotlib.pyplot as plt
import moose
simtime = 1.0
def example():
demo = moose.Neutral('/model')
function = moose.Function('/model/function')
function.c['c0'] = 1.0
function.c['c1'] = 2.0
function.x.num = 1
function.expr = 'c0 * exp(c1*x0) * cos(y0) + sin(t)'
# mode 0 - evaluate function value, derivative and rate
# mode 1 - just evaluate function value,
# mode 2 - evaluate derivative,
# mode 3 - evaluate rate
function.mode = 0
function.independent = 'y0'
nsteps = 1000
xarr = np.linspace(0.0, 1.0, nsteps)
# Stimulus tables allow you to store sequences of numbers which
# are delivered via the 'output' message at each time step. This
# is a placeholder and in real scenario you will be using any
# sourceFinfo that sends out a double value.
input_x = moose.StimulusTable('/xtab')
input_x.vector = xarr
input_x.startTime = 0.0
input_x.stepPosition = xarr[0]
input_x.stopTime = simtime
moose.connect(input_x, 'output', function.x[0], 'input')
yarr = np.linspace(-np.pi, np.pi, nsteps)
input_y = moose.StimulusTable('/ytab')
input_y.vector = yarr
input_y.startTime = 0.0
input_y.stepPosition = yarr[0]
input_y.stopTime = simtime
moose.connect(function, 'requestOut', input_y, 'getOutputValue')
# data recording
result = moose.Table('/ztab')
moose.connect(result, 'requestOut', function, 'getValue')
derivative = moose.Table('/zprime')
moose.connect(derivative, 'requestOut', function, 'getDerivative')
rate = moose.Table('/dz_by_dt')
moose.connect(rate, 'requestOut', function, 'getRate')
x_rec = moose.Table('/xrec')
moose.connect(x_rec, 'requestOut', input_x, 'getOutputValue')
y_rec = moose.Table('/yrec')
moose.connect(y_rec, 'requestOut', input_y, 'getOutputValue')
dt = simtime/nsteps
for ii in range(32):
moose.setClock(ii, dt)
moose.reinit()
moose.start(simtime)
# Uncomment the following lines and the import matplotlib.pyplot as plt on top
# of this file to display the plot.
plt.subplot(3,1,1)
plt.plot(x_rec.vector, result.vector, 'r-', label='z = {}'.format(function.expr))
z = function.c['c0'] * np.exp(function.c['c1'] * xarr) * np.cos(yarr) + np.sin(np.arange(len(xarr)) * dt)
plt.plot(xarr, z, 'b--', label='numpy computed')
plt.xlabel('x')
plt.ylabel('z')
plt.legend()
plt.subplot(3,1,2)
plt.plot(y_rec.vector, derivative.vector, 'r-', label='dz/dy0')
# derivatives computed by putting x values in the analytical formula
dzdy = function.c['c0'] * np.exp(function.c['c1'] * xarr) * (- np.sin(yarr))
plt.plot(yarr, dzdy, 'b--', label='numpy computed')
plt.xlabel('y')
plt.ylabel('dz/dy')
plt.legend()
plt.subplot(3,1,3)
# *** BEWARE *** The first two entries are spurious. Entry 0 is
# *** from reinit sending out the defaults. Entry 2 is because
# *** there is no lastValue for computing real forward difference.
plt.plot(np.arange(2, len(rate.vector), 1) * dt, rate.vector[2:], 'r-', label='dz/dt')
dzdt = np.diff(z)/dt
plt.plot(np.arange(0, len(dzdt), 1.0) * dt, dzdt, 'b--', label='numpy computed')
plt.xlabel('t')
plt.ylabel('dz/dt')
plt.legend()
plt.tight_layout()
plt.show()
def main():
"""
Function objects can be used to evaluate expressions with arbitrary
number of variables and constants. We can assign expression of the
form::
f(c_, c1, ..., cM, x0, x1, ..., xN, y0,..., yP )
where `ci`'s are constants and `xi`'s and `yi`'s are variables.
The constants must be defined before setting the expression and
variables are connected via messages. The constants can have any
name, but the variable names must be of the form x{i} or y{i}
where i is increasing integer starting from 0.
The `xi`'s are field elements and you have to set their number
first (function.x.num = N). Then you can connect any source field
sending out double to the 'input' destination field of the
`x[i]`.
The `yi`'s are useful when the required variable is a value field
and is not available as a source field. In that case you connect
the `requestOut` source field of the function element to the
`get{Field}` destination field on the target element. The `yi`'s
are automatically added on connecting. Thus, if you call::
moose.connect(function, 'requestOut', a, 'getSomeField')
moose.connect(function, 'requestOut', b, 'getSomeField')
then ``a.someField`` will be assigned to ``y0`` and
``b.someField`` will be assigned to ``y1``.
In this example we evaluate the expression: ``z = c0 * exp(c1 *
x0) * cos(y0)``
with x0 ranging from -1 to +1 and y0 ranging from -pi to
+pi. These values are stored in two stimulus tables called xtab
and ytab respectively, so that at each timestep the next values of
x0 and y0 are assigned to the function.
Along with the value of the expression itself we also compute its
derivative with respect to y0 and its derivative with respect to
time (rate). The former uses a five-point stencil for the
numerical differentiation and has a glitch at y=0. The latter uses
backward difference divided by dt.
Unlike Func class, the number of variables and constants are
unlimited in Function and you can set all the variables via
messages.
"""
example()
if __name__ == '__main__':
main()
#
# function.py ends here
# vclamp.py ---
#
# Filename: vclamp.py
# Description:
# Author:Subhasis Ray
# Maintainer:
# Created: Sat Feb 2 19:16:54 2013 (+0530)
# Version:
# Last-Updated: Tue Jun 11 17:35:20 2013 (+0530)
# By: subha
# Update #: 178
# URL:
# Keywords:
# Compatibility:
#
#
# Commentary:
#
#
#
#
# Change log:
#
#
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street, Fifth
# Floor, Boston, MA 02110-1301, USA.
#
#
# Code:
import sys
sys.path.append('../../python')
import moose
sys.path.append('../squid')
from squid import SquidAxon
from pylab import *
def vclamp_demo(simtime=50.0, dt=1e-2):
## It is good practice to modularize test elements inside a
## container
container = moose.Neutral('/vClampDemo')
## Create a compartment with properties of a squid giant axon
comp = SquidAxon('/vClampDemo/axon')
# Create and setup the voltage clamp object
clamp = moose.VClamp('/vClampDemo/vclamp')
## The defaults should work fine
# clamp.mode = 2
# clamp.tau = 10*dt
# clamp.ti = dt
# clamp.td = 0
# clamp.gain = comp.Cm / dt
## Setup command voltage time course
command = moose.PulseGen('/vClampDemo/command')
command.delay[0] = 10.0
command.width[0] = 20.0
command.level[0] = 50.0
command.delay[1] = 1e9
moose.connect(command, 'output', clamp, 'commandIn')
## Connect the Voltage Clamp to the compartemnt
moose.connect(clamp, 'currentOut', comp, 'injectMsg')
moose.connect(comp, 'VmOut', clamp, 'sensedIn')
## setup stimulus recroding - this is the command pulse
stimtab = moose.Table('/vClampDemo/vclamp_command')
moose.connect(stimtab, 'requestOut', command, 'getOutputValue')
## Set up Vm recording
vmtab = moose.Table('/vClampDemo/vclamp_Vm')
moose.connect(vmtab, 'requestOut', comp, 'getVm')
## setup command potential recording - this is the filtered input
## to PID controller
commandtab = moose.Table('/vClampDemo/vclamp_filteredcommand')
moose.connect(commandtab, 'requestOut', clamp, 'getCommand')
## setup current recording
Imtab = moose.Table('/vClampDemo/vclamp_inject')
moose.connect(Imtab, 'requestOut', clamp, 'getCurrent')
# Scheduling
moose.setClock(0, dt)
moose.setClock(1, dt)
moose.setClock(2, dt)
moose.setClock(3, dt)
moose.useClock(0, '%s/##[TYPE=Compartment]' % (container.path), 'init')
moose.useClock(0, '%s/##[TYPE=PulseGen]' % (container.path), 'process')
moose.useClock(1, '%s/##[TYPE=Compartment]' % (container.path), 'process')
moose.useClock(2, '%s/##[TYPE=HHChannel]' % (container.path), 'process')
moose.useClock(2, '%s/##[TYPE=VClamp]' % (container.path), 'process')
moose.useClock(3, '%s/##[TYPE=Table]' % (container.path), 'process')
moose.reinit()
print(('RC filter in VClamp:: tau:', clamp.tau))
print(('PID controller in VClamp:: ti:', clamp.ti, 'td:', clamp.td, 'gain:', clamp.gain))
moose.start(simtime)
print(('Finished simulation for %g seconds' % (simtime)))
tseries = linspace(0, simtime, len(vmtab.vector))
subplot(211)
title('Membrane potential and clamp voltage')
plot(tseries, vmtab.vector, 'g-', label='Vm (mV)')
plot(tseries, commandtab.vector, 'b-', label='Filtered command (mV)')
plot(tseries, stimtab.vector, 'r-', label='Command (mV)')
xlabel('Time (ms)')
ylabel('Voltage (mV)')
legend()
# print len(commandtab.vector)
subplot(212)
title('Current through clamp circuit')
# plot(tseries, stimtab.vector, label='stimulus (uA)')
plot(tseries, Imtab.vector, label='injected current (uA)')
xlabel('Time (ms)')
ylabel('Current (uA)')
legend()
show()
def main():
"""
This snippet is to demonstrate modelling of voltage clamping.
"""
vclamp_demo()
if __name__ == '__main__':
main()
#
# vclamp.py ends here
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment