from brainlab import *
from random import *

brain=BRAIN()

print "Here are the standard channel types:"
print brain.chantypes
print "Done"

newchan=brain.Copy(brain.chantypes, 'ahp-2', 'ahp-3')
newchan.parms['STRENGTH']="0.4 0.04"
print "Here is a new channel type we just made:"
print brain.chantypes['ahp-3']
print "Done"

c1=brain.Standard1CellColumn()
#brain.AddColumn(c1)

print "Creating columns"
cols={}
size=10
# create the columns and store them in cols{}
for i in range(size):
    for j in range(size):
        c=brain.Standard1CellColumn()
        #brain.AddColumn(c)
        cols[i,j]=c

print "Connecting columns"
# now connect each column to another random column
# using a default synapse
for i in range(size):
    for j in range(0, size):
        ti=randint(0, size-1)
        tj=randint(0, size-1)
        fc=cols[i,j]; tc=cols[ti, tj]
        brain.AddConnect(fc, tc)

print "Creating and adding stims"
t=0.0
stims=[]
for s in range(20):
    t+=random()*10.0
    stims.append(t)
for i in range(size):
    brain.AddSpikeStim(cols[i,0], stims)
    #print cols[i,0]

#print brain

print "About to simulate"
for r in range(10):
    s=brain.syntypes['C.strong']
    s.parms['MAX_CONDUCT']=.01+.005*r
    brain.parms['JOB']='testbrain%d'%r
    #print "NOT RUNNING"
    brain.Run(nprocs=16)

