
from neuromllite import Network, Cell, InputSource, Population, Synapse
from neuromllite import Projection, RandomConnectivity, Input, Simulation
import sys

################################################################################
###   Build new network

net = Network(id='IzhikevichTest')
net.notes = 'Example Izhikevich'
net.parameters = { 'N': 1}

cell = Cell(id='izhCell', 
            neuroml2_cell='izhikevich2007Cell')
cell.parameters = {}

params = {'v0':'-160mV', 'C':'100 pF', 'k':'0.7 nS_per_mV', \
          'vr':'-60 mV', 'vt':'-40 mV', 'vpeak':'35 mV', \
          'a':'0.03 per_ms', 'b':'-2 nS', 'c':'-50 mV', 'd':'100 pA'}

for p in params:
    cell.parameters[p]=p
    net.parameters[p]=params[p]
    
net.cells.append(cell)


pop = Population(id='izhPop', size='1', component=cell.id, properties={'color':'.7 0 0'})
net.populations.append(pop)

net.parameters['delay'] = '100ms'
net.parameters['stim_amp'] = '100pA'
net.parameters['duration'] = '500ms'
input_source = InputSource(id='iclamp_0', 
                           neuroml2_input='PulseGenerator', 
                           parameters={'amplitude':'stim_amp', 'delay':'delay', 'duration':'duration'})
net.input_sources.append(input_source)

net.inputs.append(Input(id='stim',
                        input_source=input_source.id,
                        population=pop.id,
                        percentage=100))
                            
print(net)
print(net.to_json())
new_file = net.to_json_file('%s.json'%net.id)


################################################################################
###   Build Simulation object & save as JSON

sim = Simulation(id='Sim%s'%net.id,
                 network=new_file,
                 duration='1000',
                 dt='0.025',
                 recordVariables={'v':{'all':'*'},
                                  'u':{'all':'*'}},
                 plots2D={'vu':{'x_axis':'izhPop[0]/v',
                                 'y_axis':'izhPop[0]/u'}})
                 
sim.to_json_file()



################################################################################
###   Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run
import sys

check_to_generate_or_run(sys.argv, sim)

@@ -468,17 +468,16 @@
 %7B'v0':'-
-1
 60mV', '
@@ -1728,18 +1728,17 @@
 ration='
-10
+7
 00',%0A   
@@ -1979,16 +1979,150 @@
 %5B0%5D/u'%7D%7D
+,%0A                plots3D=%7B'X-Y-Z':%7B'x_axis':'t',%0A                  'y_axis':'izhPop%5B0%5D/u',%0A                  'z_axis':'izhPop%5B0%5D/v'%7D%7D
 )%0A      

Add 3d plot