Skip to content

Commit 07a11d3

Browse files
authored
Merge pull request #11 from dilawar/master
Made script compatible with both python2 and python3.
2 parents 469e3f3 + 536b53e commit 07a11d3

File tree

176 files changed

+6002
-6098
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+6002
-6098
lines changed

.travis.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ install:
1212
- sudo apt-key add - < Release.key
1313
- sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/moose/xUbuntu_12.04/ /' >> /etc/apt/sources.list.d/moose.list"
1414
- sudo apt-get -y update
15-
- sudo apt-get install python-h5py
16-
- sudo apt-get install python3
15+
- sudo apt-get -y install python-qt4
1716
- sudo apt-get -y install moose
1817

1918
script:
2019
- # Making sure no python3 incompatible file.
2120
- python3 -m compileall -q .
21+
- python2 -m compileall -q .
2222
- python -c 'import moose'
23-
- python -c 'import moogli'
2423
- cd _travis && ./find_scripts_to_run.sh && ./run_scripts.sh

_travis/run_scripts.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TEMP=$PWD/__temp__
1010
rm -f $BLACKLISTED $SUCCEEDED $FAILED $TEMP TORUN
1111
$PWD/find_scripts_to_run.sh
1212

13-
PYC=`which python`
13+
PYC=`which python2`
1414
MATPLOTRC=$PWD/matplotlibrc
1515
if [ ! -f $MATPLOTRC ]; then
1616
echo "$MATPLOTRC not found"

hopfield/guiHopfield.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def connectElements(self):
5353
self.connect(self.computeSynWeightsPushButton,QtCore.SIGNAL('clicked()'),self.computeAllWeights)
5454

5555
def saveInput(self):
56-
print 'saving current pattern as input'
56+
print('saving current pattern as input')
5757
inpList = []
5858
for i in range(100):
5959
exec(('inpList.append(int(self.pushButton_%s.isChecked()))' %i))

hopfield/hopfield.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def updateWeights(self, memory):
5858
memory[j] = -1
5959
self.synWeights[i*len(memory)+j] += memory[i]*memory[j]
6060

61-
print self.synWeights[0:100]
61+
print((self.synWeights[0:100]))
6262
self.numMemories += 1
63-
print self.numMemories, '#number Of saved memories'
63+
print((self.numMemories, '#number Of saved memories'))
6464

6565
def createNetwork(self):
6666
'''setting up of the cells and their connections'''

hopfield/test.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@
3737
#else, goes back to 0 in tau time
3838

3939
VmVal = moose.Table(cellPath+'/Vm_cell')
40-
print 'table>cellVm:', moose.connect(VmVal, 'requestOut', cell, 'getVm')
40+
print(('table>cellVm:', moose.connect(VmVal, 'requestOut', cell, 'getVm')))
4141
spikeTime = moose.Table(cellPath+'/spikeTimes')
42-
print 'table>cellSpike:', moose.connect(cell, 'spike', spikeTime, 'input')
42+
print(('table>cellSpike:', moose.connect(cell, 'spike', spikeTime, 'input')))
4343

4444
inSpkGen = moose.SpikeGen(cellPath+'/inSpkGen')
4545
inSpkGen.setField('threshold', 2.0)
4646
inSpkGen.setField('edgeTriggered', True)
4747

4848
if inputGiven == 1:
49-
print 'pulse>spike:', moose.connect(pg, 'output', moose.element(cellPath+'/inSpkGen'), 'Vm')
49+
print(('pulse>spike:', moose.connect(pg, 'output', moose.element(cellPath+'/inSpkGen'), 'Vm')))
5050
inTable = moose.Table(cellPath+'/inSpkGen/inTable')
51-
print 'table>spike:',moose.connect(inTable, 'requestOut', inSpkGen, 'getHasFired')
51+
print(('table>spike:',moose.connect(inTable, 'requestOut', inSpkGen, 'getHasFired')))
5252

53-
print 'spike>cell:', moose.connect(inSpkGen, 'spikeOut', cell.synapse[0] ,'addSpike')
53+
print(('spike>cell:', moose.connect(inSpkGen, 'spikeOut', cell.synapse[0] ,'addSpike')))
5454
#print 'spike>cell:', moose.connect(pg, 'output', cell ,'injectDest')
5555

5656
moose.setClock(0, 1e-4)

izhikevich/Izhikevich.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def setup(self, key):
197197
neuron = self._get_neuron(key)
198198
pulsegen = self._make_pulse_input(key)
199199
if pulsegen is None:
200-
print key, 'Not implemented.'
200+
print((key, 'Not implemented.'))
201201

202202
def simulate(self, key):
203203
self.setup(key)
@@ -207,7 +207,7 @@ def run(self, key):
207207
try:
208208
Vm = self.Vm_tables[key]
209209
u = self.u_tables[key]
210-
except KeyError, e:
210+
except KeyError as e:
211211
Vm = moose.Table(self.data_container.path + '/' + key + '_Vm')
212212
nrn = self.neurons[key]
213213
moose.connect(Vm, 'requestOut', nrn, 'getVm')
@@ -217,7 +217,7 @@ def run(self, key):
217217
self.u_tables[key] = utable
218218
try:
219219
Im = self.inject_tables[key]
220-
except KeyError, e:
220+
except KeyError as e:
221221
Im = moose.Table(self.data_container.path + '/' + key + '_inject') # May be different for non-pulsegen sources.
222222
Im.connect('requestOut', self._get_neuron(key), 'getIm')
223223
self.inject_tables[key] = Im
@@ -237,7 +237,7 @@ def run(self, key):
237237
time = linspace(0, IzhikevichDemo.parameters[key][7], len(Vm.vector))
238238
# DEBUG
239239
nrn = self._get_neuron(key)
240-
print 'a = %g, b = %g, c = %g, d = %g, initVm = %g, initU = %g' % (nrn.a,nrn.b, nrn.c, nrn.d, nrn.initVm, nrn.initU)
240+
print(('a = %g, b = %g, c = %g, d = %g, initVm = %g, initU = %g' % (nrn.a,nrn.b, nrn.c, nrn.d, nrn.initVm, nrn.initU)))
241241
#! DEBUG
242242
return (time, Vm, Im)
243243

@@ -246,14 +246,14 @@ def _get_neuron(self, key):
246246
try:
247247
params = IzhikevichDemo.parameters[key]
248248
except KeyError as e:
249-
print ' %s : Invalid neuron type. The valid types are:' % (key)
249+
print((' %s : Invalid neuron type. The valid types are:' % (key)))
250250
for key in IzhikevichDemo.parameters:
251-
print key
251+
print(key)
252252
raise e
253253
try:
254254
neuron = self.neurons[key]
255255
return neuron
256-
except KeyError, e:
256+
except KeyError as e:
257257
neuron = moose.IzhikevichNrn(self.model_container.path + '/' + key)
258258

259259
if key == 'integrator' or key == 'Class_1': # Integrator has different constants
@@ -354,7 +354,7 @@ def _make_pulse_input(self, key):
354354
self.inputs[key] = input_table
355355
return input_table
356356
else:
357-
print key, ': Stimulus is not based on pulse generator.'
357+
print((key, ': Stimulus is not based on pulse generator.'))
358358
raise
359359
pulsegen = self._make_pulsegen(key,
360360
firstLevel,
@@ -529,9 +529,9 @@ def getEquation(self, key):
529529
plot(time, Im.vector)
530530
subplot(3,1,3)
531531
show()
532-
print 'Finished simulation.'
532+
print('Finished simulation.')
533533
except ImportError:
534-
print 'Matplotlib not installed.'
534+
print('Matplotlib not installed.')
535535

536536
#
537537
# Izhikevich.py ends here

izhikevich/demogui_qt.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ def __init__(self, *args):
6262
self.controlPanel = QtGui.QFrame(self.demoFrame)
6363
self.figureNo = {}
6464
self.buttons = {}
65-
for key, value in IzhikevichDemo.parameters.items():
65+
for key, value in list(IzhikevichDemo.parameters.items()):
6666
button = QtGui.QPushButton(key, self.controlPanel)
6767
self.figureNo[value[0]] = key
6868
self.buttons[key] = button
69-
keys = self.figureNo.keys()
69+
keys = list(self.figureNo.keys())
7070
keys.sort()
7171
length = len(keys)
7272
rows = int(numpy.rint(numpy.sqrt(length)))

kinetics/test_ksolve.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def createChemModel( neuroCompt, spineCompt, psdCompt ):
306306

307307
# Just for printf debugging
308308
def printMolVecs( title ):
309-
print title
309+
print(title)
310310
"""
311311
nCa = moose.vec( '/model/chem/neuroMesh/Ca' )
312312
sCa = moose.vec( '/model/chem/spineMesh/Ca' )
@@ -477,7 +477,7 @@ def testCubeMultiscale( useSolver ):
477477
moose.reinit()
478478
t = time.time()
479479
moose.start( 1.0 )
480-
print("Total time taken: %s sec for 1.0 sec of simulation" % (time.time() - t))
480+
print(("Total time taken: %s sec for 1.0 sec of simulation" % (time.time() - t)))
481481
dumpPlots( plotName )
482482

483483
def main():

moogli/purkinje_simulation.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
popdict, projdict = moose.neuroml.loadNeuroML_L123(filename)
2727

2828
# setting up hsolve object for each neuron
29-
for popinfo in popdict.values():
30-
for cell in popinfo[1].values():
29+
for popinfo in list(popdict.values()):
30+
for cell in list(popinfo[1].values()):
3131
solver = moose.HSolve(cell.path + "/hsolve")
3232
solver.target = cell.path
3333

@@ -37,9 +37,7 @@
3737
SIMULATION_DELTA = 0.001
3838
SIMULATION_TIME = 0.03
3939

40-
ALL_COMPARTMENTS = map( lambda x : x.path
41-
, moose.wildcardFind("/cells[0]/##[ISA=CompartmentBase]")
42-
)
40+
ALL_COMPARTMENTS = [x.path for x in moose.wildcardFind("/cells[0]/##[ISA=CompartmentBase]")]
4341
BASE_VM_VALUE = -0.065
4442
PEAK_VM_VALUE = -0.060
4543
BASE_VM_COLOR = [1.0, 0.0, 0.0, 0.1]
@@ -69,9 +67,7 @@
6967

7068
# set initial color of all compartments in accordance with their vm
7169
morphology.set_color( "group-all"
72-
, map( lambda x : moose.element(x).Vm
73-
, ALL_COMPARTMENTS
74-
)
70+
, [moose.element(x).Vm for x in ALL_COMPARTMENTS]
7571
)
7672

7773
# instantiate the visualizer with the morphology object created earlier
@@ -90,9 +86,7 @@ def callback(morphology, viewer):
9086
# a value higher than peak value will be clamped to peak value
9187
# a value lower than base value will be clamped to base value.
9288
morphology.set_color( "group-all"
93-
, map( lambda x : x.Vm
94-
, moose.wildcardFind("/cells[0]/##[ISA=CompartmentBase]")
95-
)
89+
, [x.Vm for x in moose.wildcardFind("/cells[0]/##[ISA=CompartmentBase]")]
9690
)
9791
# if the callback returns true, it will be called again.
9892
# if it returns false it will not be called ever again.

moogli/purkinje_simulation_with_rm.py

+8-20
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
popdict, projdict = moose.neuroml.loadNeuroML_L123(filename)
2929

3030
# setting up hsolve object for each neuron
31-
for popinfo in popdict.values():
32-
for cell in popinfo[1].values():
31+
for popinfo in list(popdict.values()):
32+
for cell in list(popinfo[1].values()):
3333
solver = moose.HSolve(cell.path + "/hsolve")
3434
solver.target = cell.path
3535

@@ -39,17 +39,11 @@
3939
SIMULATION_DELTA = 0.001
4040
SIMULATION_TIME = 0.03
4141

42-
ALL_COMPARTMENTS = map( lambda x : x.path
43-
, moose.wildcardFind("/cells[0]/##[ISA=CompartmentBase]")
44-
)
42+
ALL_COMPARTMENTS = [x.path for x in moose.wildcardFind("/cells[0]/##[ISA=CompartmentBase]")]
4543

46-
BASE_RM_VALUE = min( map( lambda x : moose.element(x).Rm
47-
, ALL_COMPARTMENTS
48-
)
44+
BASE_RM_VALUE = min( [moose.element(x).Rm for x in ALL_COMPARTMENTS]
4945
)
50-
PEAK_RM_VALUE = max( map( lambda x : moose.element(x).Rm
51-
, ALL_COMPARTMENTS
52-
)
46+
PEAK_RM_VALUE = max( [moose.element(x).Rm for x in ALL_COMPARTMENTS]
5347
)
5448
BASE_RM_COLOR = [0.0, 1.0, 0.0, 0.1]
5549
PEAK_RM_COLOR = [1.0, 0.0, 0.0, 1.0]
@@ -86,9 +80,7 @@ def create_vm_visualizer():
8680

8781
# set initial color of all compartments in accordance with their vm
8882
vm_morphology.set_color( "group-all"
89-
, map( lambda x : moose.element(x).Vm
90-
, ALL_COMPARTMENTS
91-
)
83+
, [moose.element(x).Vm for x in ALL_COMPARTMENTS]
9284
)
9385

9486
# instantiate the visualizer with the morphology object created earlier
@@ -105,9 +97,7 @@ def callback(morphology, viewer):
10597
# a value higher than peak value will be clamped to peak value
10698
# a value lower than base value will be clamped to base value.
10799
morphology.set_color( "group-all"
108-
, map( lambda x : moose.element(x).Vm
109-
, ALL_COMPARTMENTS
110-
)
100+
, [moose.element(x).Vm for x in ALL_COMPARTMENTS]
111101
)
112102
# if the callback returns true, it will be called again.
113103
# if it returns false it will not be called again.
@@ -148,9 +138,7 @@ def create_rm_visualizer():
148138

149139
# set initial color of all compartments in accordance with their rm
150140
morphology.set_color( "group-all"
151-
, map( lambda x : moose.element(x).Rm
152-
, ALL_COMPARTMENTS
153-
)
141+
, [moose.element(x).Rm for x in ALL_COMPARTMENTS]
154142
)
155143

156144
# instantiate the visualizer with the morphology object created earlier

moogli/purkinje_simulation_with_rm_and_graph.py

+8-20
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
popdict, projdict = moose.neuroml.loadNeuroML_L123(filename)
3131

3232
# setting up hsolve object for each neuron
33-
for popinfo in popdict.values():
34-
for cell in popinfo[1].values():
33+
for popinfo in list(popdict.values()):
34+
for cell in list(popinfo[1].values()):
3535
solver = moose.HSolve(cell.path + "/hsolve")
3636
solver.target = cell.path
3737

@@ -49,17 +49,11 @@
4949
SIMULATION_DELTA = 0.001
5050
SIMULATION_TIME = 0.03
5151

52-
ALL_COMPARTMENTS = map( lambda x : x.path
53-
, moose.wildcardFind("/cells[0]/##[ISA=CompartmentBase]")
54-
)
52+
ALL_COMPARTMENTS = [x.path for x in moose.wildcardFind("/cells[0]/##[ISA=CompartmentBase]")]
5553

56-
BASE_RM_VALUE = min( map( lambda x : moose.element(x).Rm
57-
, ALL_COMPARTMENTS
58-
)
54+
BASE_RM_VALUE = min( [moose.element(x).Rm for x in ALL_COMPARTMENTS]
5955
)
60-
PEAK_RM_VALUE = max( map( lambda x : moose.element(x).Rm
61-
, ALL_COMPARTMENTS
62-
)
56+
PEAK_RM_VALUE = max( [moose.element(x).Rm for x in ALL_COMPARTMENTS]
6357
)
6458
BASE_RM_COLOR = [0.0, 1.0, 0.0, 0.1]
6559
PEAK_RM_COLOR = [1.0, 0.0, 0.0, 1.0]
@@ -111,9 +105,7 @@ def create_vm_visualizer():
111105

112106
# set initial color of all compartments in accordance with their vm
113107
vm_morphology.set_color( "group-all"
114-
, map( lambda x : moose.element(x).Vm
115-
, ALL_COMPARTMENTS
116-
)
108+
, [moose.element(x).Vm for x in ALL_COMPARTMENTS]
117109
)
118110

119111
# instantiate the visualizer with the morphology object created earlier
@@ -130,9 +122,7 @@ def callback(morphology, viewer):
130122
# a value higher than peak value will be clamped to peak value
131123
# a value lower than base value will be clamped to base value.
132124
morphology.set_color( "group-all"
133-
, map( lambda x : moose.element(x).Vm
134-
, ALL_COMPARTMENTS
135-
)
125+
, [moose.element(x).Vm for x in ALL_COMPARTMENTS]
136126
)
137127
# if the callback returns true, it will be called again.
138128
# if it returns false it will not be called again.
@@ -181,9 +171,7 @@ def create_rm_visualizer():
181171

182172
# set initial color of all compartments in accordance with their rm
183173
morphology.set_color( "group-all"
184-
, map( lambda x : moose.element(x).Rm
185-
, ALL_COMPARTMENTS
186-
)
174+
, [moose.element(x).Rm for x in ALL_COMPARTMENTS]
187175
)
188176

189177
# instantiate the visualizer with the morphology object created earlier

neuroml/CA1PyramidalCell/CA1.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ def loadGran98NeuroML_L123(filename):
3131
#somaIKCa = setupTable('somaIKCa',moose.HHChannel(soma_path+'/Gran_KCa_98'),'Gk')
3232
#KDrX = setupTable('ChanX',moose.HHChannel(soma_path+'/Gran_KDr_98'),'X')
3333
soma = moose.Compartment(soma_path)
34-
print "Reinit MOOSE ... "
34+
print("Reinit MOOSE ... ")
3535
resetSim(['/elec','/cells'],simdt,plotdt,simmethod='ee') # from moose.utils
36-
print "Running ... "
36+
print("Running ... ")
3737
moose.start(runtime)
3838
tvec = arange(0.0,runtime,simdt)
3939
plot(tvec,somaVm.vector[1:])
4040
title('Soma Vm')
4141
xlabel('time (s)')
4242
ylabel('Voltage (V)')
43-
print "Showing plots ..."
43+
print("Showing plots ...")
4444
show()
4545

4646
if __name__ == "__main__":

0 commit comments

Comments
 (0)