create_test_network.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. """
  2. Create a test network using NeuroMLlite.
  3. """
  4. from neuromllite import *
  5. from neuromllite.NetworkGenerator import *
  6. from neuromllite.utils import create_new_model
  7. import sys
  8. colors = {'HL23PYR':'0.2 0.2 0.2', 'HL23PV':'0 0.9 0', 'HL23VIP':'0.9 0.9 0', 'HL23SST':'0.9 0 0'}
  9. def generate(cell_numbers, duration=300, config='IClamp', parameters = None):
  10. reference = "%s"%(config)
  11. cells_nmll = {}
  12. for cell in cell_numbers:
  13. cell_id = '%s'%cell
  14. reference+='_%s'%cell_id
  15. cells_nmll[cell_id] = Cell(id=cell_id, neuroml2_source_file='%s.cell.nml'%(cell))
  16. ################################################################################
  17. if 'IClamp' in config:
  18. if not parameters:
  19. parameters = {}
  20. parameters['stim_amp'] = '200pA'
  21. input_source = InputSource(id='iclamp_0',
  22. neuroml2_input='PulseGenerator',
  23. parameters={'amplitude':'stim_amp',
  24. 'delay':'50ms',
  25. 'duration':'200ms'})
  26. else:
  27. if not parameters:
  28. parameters = {}
  29. parameters['average_rate'] = '100 Hz'
  30. parameters['number_per_cell'] = '10'
  31. net = Network(id=config)
  32. net.notes = "Network example"
  33. net.seed = 1234
  34. net.temperature = 34.0
  35. net.parameters = parameters
  36. r1 = RectangularRegion(id="L23", x=0, y=0, z=0, width=1000, height=1000, depth=1000)
  37. net.regions.append(r1)
  38. ampa = Synapse(id="AMPA_syn", neuroml2_source_file="synapses/AMPA_syn.synapse.nml")
  39. net.synapses.append(ampa)
  40. input_source = InputSource(id='pfs0',
  41. neuroml2_input='PoissonFiringSynapse',
  42. parameters={'average_rate':'average_rate',
  43. 'synapse':ampa.id,
  44. 'spike_target':"./%s"%ampa.id})
  45. net.input_sources.append(input_source)
  46. if 'IClamp' in config:
  47. cell_nmll = list(cells_nmll.values())[0]
  48. sim, net = create_new_model(reference,
  49. duration,
  50. dt=0.01, # ms
  51. temperature=34.0, # degC
  52. parameters = parameters,
  53. cell_for_default_population=cell_nmll,
  54. color_for_default_population=colors[cell_nmll.id],
  55. input_for_default_population=input_source)
  56. else:
  57. for cell in cell_numbers:
  58. cell_nmll = cells_nmll[cell]
  59. net.cells.append(cell_nmll)
  60. size = cell_numbers[cell]
  61. net.parameters['num_%s'%cell] = size
  62. pE = Population(
  63. id="Pop_%s"%cell,
  64. size='num_%s'%cell,
  65. component=cell,
  66. properties={"color": colors[cell]},
  67. random_layout=RandomLayout(region=r1.id),
  68. )
  69. net.populations.append(pE)
  70. net.inputs.append(
  71. Input(
  72. id="stim_%s"%cell,
  73. input_source=input_source.id,
  74. population=pE.id,
  75. percentage=100,
  76. weight=0.1,
  77. )
  78. )
  79. net_file = net.to_json_file("%s.json" % net.id)
  80. sim = Simulation(
  81. id="Sim_%s"%net.id,
  82. network=net_file,
  83. duration="300",
  84. seed="1111",
  85. dt="0.01",
  86. record_traces={"all": "*"},
  87. record_spikes={"all": "*"},
  88. )
  89. sim.to_json_file()
  90. return sim, net
  91. if __name__ == "__main__":
  92. if '-all' in sys.argv or '-net' in sys.argv:
  93. if '-all' in sys.argv:
  94. for cell in colors:
  95. sim, net = generate({cell:1}, 300, config="IClamp",parameters={'stim_amp':'200pA'})
  96. check_to_generate_or_run(sys.argv, sim)
  97. sim, net = generate({'HL23PV':1, 'HL23PYR':1, 'HL23VIP':1, 'HL23SST':1}, 1000, config="TestNetwork", parameters={'average_rate':'200 Hz'})
  98. check_to_generate_or_run(sys.argv, sim)
  99. elif '-net2' in sys.argv:
  100. sim, net = generate({'HL23PV':5, 'HL23PYR':5, 'HL23VIP':5, 'HL23SST':5}, 300, config="LargeNetwork", parameters={'average_rate':'50 Hz'})
  101. check_to_generate_or_run(sys.argv, sim)
  102. elif '-net3' in sys.argv:
  103. sim, net = generate({'HL23PV':3, 'HL23PYR':3, 'HL23VIP':3, 'HL23SST':3}, 300, config="MediumNetwork", parameters={'average_rate':'20 Hz'})
  104. check_to_generate_or_run(sys.argv, sim)
  105. elif '-vip' in sys.argv:
  106. sim, net = generate({'HL23VIP':1}, 300, config="IClamp",parameters={'stim_amp':'200pA'})
  107. check_to_generate_or_run(sys.argv, sim)
  108. elif '-sst' in sys.argv:
  109. sim, net = generate({'HL23SST':1}, 300, config="IClamp",parameters={'stim_amp':'200pA'})
  110. check_to_generate_or_run(sys.argv, sim)
  111. else:
  112. sim, net = generate({'HL23PV':1}, 300, config="IClamp",parameters={'stim_amp':'200pA'})
  113. check_to_generate_or_run(sys.argv, sim)