def build_spike_trains(N=N_LIF_exc + N_LIF_inh): from bmtk.utils.reports.spike_trains import PoissonSpikeGenerator from bmtk.utils.reports.spike_trains import sort_order # Steadily increase the firing rate of each virtual cell from 1.0 Hz (node 0) to 50.0 Hz (node 12499) firing_rates = 500 * np.ones(N) psg = PoissonSpikeGenerator(population='external') for i in range(N): # create a new spike-train for each node. psg.add(node_ids=i, firing_rate=firing_rates[i], times=(0.0, 3.0)) psg.to_sonata('inputs/injective_500hz.h5', sort_order=sort_order.by_id)
def build_input(t_sim, numPN_A=640, numPN_C=260, numBask=100): print("Building input for " + str(t_sim) + " (ms)") psg = PoissonSpikeGenerator(population='mthalamus') psg.add( node_ids=range(numPN_A + numPN_C), # Have nodes to match mthalamus # firing_rate=2.0, # 15 Hz, we can also pass in a nonhomoegenous function/array firing_rate=lognorm_fr_list(numPN_A + numPN_C, 2, 1), times=(0.0, t_sim / 1000.0)) # Firing starts at 0 s up to 3 s psg.to_sonata('mthalamus_spikes.h5') psg = PoissonSpikeGenerator(population='exc_bg_bask') psg.add( node_ids=range(numBask), # Have nodes to match mthalamus # firing_rate=2.0, # 15 Hz, we can also pass in a nonhomoegenous function/array firing_rate=lognorm_fr_list(numBask, 2, 1), times=(0.0, t_sim / 1000.0)) # Firing starts at 0 s up to 3 s psg.to_sonata('exc_bg_bask_spikes.h5') print("Done")
import os from bmtk.utils.reports.spike_trains import PoissonSpikeGenerator if not os.path.exists('inputs'): os.mkdir('inputs') psg = PoissonSpikeGenerator(population='external') psg.add( node_ids=range(100), firing_rate=10.0, ) psg.add(node_ids=range(100), firing_rate=10.0, times=(0.0, 3.0)) psg.to_sonata('inputs/external_spike_trains.h5')
network_dir='./network', tstop=t_sim, dt=0.1, spikes_inputs=[('mthalamus', 'mthalamus_spikes.h5'), ('exc_bg_bask', 'exc_bg_bask_spikes.h5'), ('exc_bg_chn', 'exc_bg_chn_spikes.h5')], components_dir='biophys_components', compile_mechanisms=True) from bmtk.utils.reports.spike_trains import PoissonSpikeGenerator # psg = PoissonSpikeGenerator(population='mthalamus') psg.add(node_ids=range(numPN_A + numPN_C), # Have nodes to match mthalamus firing_rate=0.2, # 15 Hz, we can also pass in a nonhomoegenous function/array times=(0.0, t_sim)) # Firing starts at 0 s up to 3 s psg.to_sonata('mthalamus_spikes.h5') psg = PoissonSpikeGenerator(population='exc_bg_bask') psg.add(node_ids=range(numBask), # Have nodes to match mthalamus firing_rate=0.2, # 15 Hz, we can also pass in a nonhomoegenous function/array times=(0.0, t_sim)) # Firing starts at 0 s up to 3 s psg.to_sonata('exc_bg_bask_spikes.h5') psg = PoissonSpikeGenerator(population='exc_bg_chn') psg.add(node_ids=range(numAAC), # Have nodes to match mthalamus firing_rate=0.2, # 15 Hz, we can also pass in a nonhomoegenous function/array times=(0.0, t_sim)) # Firing starts at 0 s up to 3 s psg.to_sonata('exc_bg_chn_spikes.h5') def syn_dist_delay(source, target, min_delay, pos):
thalamus.save_nodes(output_dir='network') thalamus.save_edges(output_dir='network') print("External nodes and edges built") from bmtk.utils.sim_setup import build_env_bionet build_env_bionet( base_dir='./', network_dir='./network', tstop=1000.0, dt=0.1, spikes_inputs=[( 'mthalamus', # Name of population which spikes will be generated for 'mthalamus_spikes.h5')], report_vars=['v', 'cai' ], # Record membrane potential and calcium (default soma) components_dir='biophys_components', compile_mechanisms=True) from bmtk.utils.reports.spike_trains import PoissonSpikeGenerator psg = PoissonSpikeGenerator(population='mthalamus') psg.add( node_ids=range(numPN_A + numPN_C + numBask), # Have nodes to match mthalamus firing_rate= 15.0, # 15 Hz, we can also pass in a nonhomoegenous function/array times=(0.0, 3.0)) # Firing starts at 0 s up to 3 s psg.to_sonata('mthalamus_spikes.h5')
# SPIKE TRAINS t_sim = 40000 #build_env_bionet(base_dir='./', # network_dir='./network', # tstop=t_sim, dt=0.1, # report_vars=['v'], # components_dir='biophys_components', # config_file='config.json', # spikes_inputs=[('bg_pn_c', '2_cell_inputs/bg_pn_c_spikes.h5'), # ('bg_pv', '2_cell_inputs/bg_pv_spikes.h5')], # compile_mechanisms=False) psg = PoissonSpikeGenerator(population='bg_pn_c') psg.add( node_ids=range(1), # need same number as cells firing_rate=6, # 1 spike every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('2_cell_inputs/bg_pn_c_spikes.h5') print('Number of background spikes for PN_C: {}'.format(psg.n_spikes())) psg = PoissonSpikeGenerator(population='bg_pv') psg.add( node_ids=range(1), # need same number as cells firing_rate=7.7, # 8 spikes every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('2_cell_inputs/bg_pv_spikes.h5') print('Number of background spikes for PV: {}'.format(psg.n_spikes()))
from bmtk.utils.sim_setup import build_env_bionet build_env_bionet(base_dir='../', network_dir='./network', tstop=t_sim, dt=0.1, spikes_inputs=[('tone', './10_cell_spikes/tone_spikes.csv'), ('shock', './10_cell_spikes/shock_spikes.csv'), ('bg_pn', '10_cell_spikes/bg_pn_spikes.h5'), ('bg_pv', '10_cell_spikes/bg_pv_spikes.h5')], components_dir='../biophys_components', config_file='config.json', compile_mechanisms=False) psg = PoissonSpikeGenerator(population='bg_pn') psg.add( node_ids=range(8), # need same number as cells firing_rate=2, # 1 spike every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('10_cell_spikes/bg_pn_spikes.h5') print('Number of background spikes for pn: {}'.format(psg.n_spikes())) psg = PoissonSpikeGenerator(population='bg_pv') psg.add( node_ids=range(2), # need same number as cells firing_rate=8, # 8 spikes every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('10_cell_spikes/bg_pv_spikes.h5') print('Number of background spikes for pv: {}'.format(psg.n_spikes()))
target_sections=['somatic'], distance_range=[0.0, 150.0], dynamics_params='AMPA_ExcToExc.json', model_template='exp2syn') net.build() net.save(output_dir='network') thalamus.build() thalamus.save(output_dir='network') psg = PoissonSpikeGenerator(population='mthalamus') psg.add( node_ids=1, # Have 5 nodes to match mthalamus firing_rate=8, # 2 Hz times=(0.0, 1)) # time is in seconds for some reason psg.to_sonata('virtual_spikes.h5') print('Number of background spikes: {}'.format(psg.n_spikes())) from bmtk.utils.sim_setup import build_env_bionet build_env_bionet( base_dir='../', network_dir='./network', tstop=1000.0, dt=0.1, report_vars=['v'], spikes_inputs=[('mthalamus', 'virtual_spikes.h5')], #current_clamp={ # 'amp': -0.100, # 'delay': 250.0, # 'duration': 200 #200 for bask 600 for pyr #},
from bmtk.utils.reports.spike_trains import SpikeTrains, PoissonSpikeGenerator # A constant firing rate of 10 Hz from 0 to 3 seconds times = (0.0, 3.0) firing_rate = 10.0 ## Uncomment to model the input firing rates on a sin wave # times = np.linspace(0.0, 3.0, 1000) # firing_rate = 10.0*np.sin(times) + 10.0 psg = PoissonSpikeGenerator() # Uses 'seed' to ensure same results every time psg.add(node_ids='network/thalamus_nodes.h5', firing_rate=firing_rate, times=times, population='thalamus') psg.to_sonata('thalamus.h5') psg.to_csv('thalamus.csv')
def build_input(t_sim, numPN_A=569, numPN_C=231, numBask=93, numSOM=51, numCR=56): print("Building input for " + str(t_sim) + " (ms)") psg = PoissonSpikeGenerator(population='vpsi_pyr') psg.add( node_ids=range(numPN_A + numPN_C), # Have nodes to match mthalamus # firing_rate=2.0, # 15 Hz, we can also pass in a nonhomoegenous function/array firing_rate=lognorm_fr_list(numPN_A + numPN_C, 2, 1), times=(0.0, t_sim / 1000.0)) # Firing starts at 0 s up to 3 s psg.to_sonata('vpsi_pyr_spikes.h5') psg = PoissonSpikeGenerator(population='vpsi_pv') psg.add( node_ids=range(numBask), # Have nodes to match mthalamus # firing_rate=2.0, # 15 Hz, we can also pass in a nonhomoegenous function/array firing_rate=lognorm_fr_list(numBask, 2, 1), times=(0.0, t_sim / 1000.0)) # Firing starts at 0 s up to 3 s psg.to_sonata('vpsi_pv_spikes.h5') # THALAMUS psg = PoissonSpikeGenerator(population='thalamus_pyr') psg.add( node_ids=range(numPN_A + numPN_C), # Have nodes to match # firing_rate=2.0, # 15 Hz, we can also pass in a nonhomoegenous function/array firing_rate=lognorm_fr_list(numPN_A + numPN_C, 4, 1), times=(0.0, t_sim / 1000.0)) # Firing starts at 0 s up to 3 s psg.to_sonata('thalamus_pyr_spikes.h5') psg = PoissonSpikeGenerator(population='thalamus_pv') psg.add( node_ids=range(numBask), # Have nodes to match # firing_rate=2.0, # 15 Hz, we can also pass in a nonhomoegenous function/array firing_rate=lognorm_fr_list(numBask, 2, 1), times=(0.0, t_sim / 1000.0)) # Firing starts at 0 s up to 3 s psg.to_sonata('thalamus_pv_spikes.h5') psg = PoissonSpikeGenerator(population='thalamus_som') psg.add( node_ids=range(numSOM), # Have nodes to match # firing_rate=2.0, # 15 Hz, we can also pass in a nonhomoegenous function/array firing_rate=lognorm_fr_list(numSOM, 2, 1), times=(0.0, t_sim / 1000.0)) # Firing starts at 0 s up to 3 s psg.to_sonata('thalamus_som_spikes.h5') psg = PoissonSpikeGenerator(population='thalamus_cr') psg.add( node_ids=range(numCR), # Have nodes to match # firing_rate=2.0, # 15 Hz, we can also pass in a nonhomoegenous function/array firing_rate=lognorm_fr_list(numCR, 2, 1), times=(0.0, t_sim / 1000.0)) # Firing starts at 0 s up to 3 s psg.to_sonata('thalamus_cr_spikes.h5') print("Done")
from bmtk.utils.reports.spike_trains import PoissonSpikeGenerator psg = PoissonSpikeGenerator(population='LGN') psg.add( node_ids=range(0, 100), firing_rate=8.0, # we can also pass in a nonhomoegenous function/array times=(0.0, 2.0) # Firing starts at 0 s up to 3 s ) psg.to_sonata('inputs/lgn_spikes.poisson.h5') psg.to_csv('inputs/lgn_spikes.poisson.csv')
# report_vars=['v'], # spikes_inputs=[('tone', './12_cell_inputs/tone_spikes.csv'), # ('shock', './12_cell_inputs/shock_spikes.csv'), # ('bg_pn', '12_cell_inputs/bg_pn_spikes.h5'), # ('bg_pv', '12_cell_inputs/bg_pv_spikes.h5'), # ('bg_olm', '12_cell_inputs/bg_olm_spikes.h5')], # components_dir='biophys_components', # config_file='config.json', # compile_mechanisms=False) psg = PoissonSpikeGenerator(population='tone') psg.add( node_ids=range(1), # need same number as cells firing_rate=2, # 1 spike every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('12_cell_inputs/tone_background.h5') print('Number of background spikes for tone: {}'.format(psg.n_spikes())) psg = PoissonSpikeGenerator(population='bg_pn_a') psg.add( node_ids=range(5), # need same number as cells firing_rate=6, # 1 spike every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('12_cell_inputs/bg_pn_a_spikes.h5') print('Number of background spikes for PN_A: {}'.format(psg.n_spikes())) psg = PoissonSpikeGenerator(population='bg_pn_c') psg.add( node_ids=range(3), # need same number as cells
thalamus.build() thalamus.save_nodes(output_dir='%s/network' % (savedir)) thalamus.save_edges(output_dir='%s/network' % (savedir)) # Set spike trains from bmtk.utils.reports.spike_trains import PoissonSpikeGenerator spikesFilename = '%s/inputs/mthalamus_spikes.h5' % (savedir) psg = PoissonSpikeGenerator(population='mthalamus') psg.add( node_ids=range(10), # Have 10 nodes to match mthalamus firing_rate= 15.0, # 10 Hz, we can also pass in a nonhomoegenous function/array times=(0.0, 3.0)) # Firing starts at 0 s up to 3 s if not (os.path.isfile(spikesFilename)): psg.to_sonata(spikesFilename) # ---------------------------------------------------- # 2. Set up the BioNet environment # ---------------------------------------------------- '''Before running a simulation, we will need to create the runtime environment, including parameter files, run-script and configuration files. This will also compile mechanisms''' # Mechanisms need to be compiled? compile_mechanisms = True if os.path.isdir('%s/components/mechanisms/x86_64/' % (savedir)): compile_mechanisms = False # Build network build_env_bionet( base_dir=savedir,
net.save_edges(output_dir='network') exc_stim.build() exc_stim.save_nodes(output_dir='network') inh_stim.build() inh_stim.save_nodes(output_dir='network') from bmtk.utils.reports.spike_trains import PoissonSpikeGenerator from bmtk.utils.reports.spike_trains.spikes_file_writers import write_csv exc_psg = PoissonSpikeGenerator(population='exc_stim') exc_psg.add(node_ids=range(np.sum(num_exc)), firing_rate=int(exc_fr) / 1000, times=(200.0, 1200.0)) exc_psg.to_sonata('exc_stim_spikes.h5') inh_psg = PoissonSpikeGenerator(population='inh_stim') inh_psg.add(node_ids=range(np.sum(num_inh)), firing_rate=int(inh_fr) / 1000, times=(200.0, 1200.0)) inh_psg.to_sonata('inh_stim_spikes.h5') from bmtk.utils.sim_setup import build_env_bionet build_env_bionet(base_dir='./', network_dir='./network', tstop=1200.0, dt=0.1, report_vars=['v'], spikes_inputs=[('exc_stim', 'exc_stim_spikes.h5'),
import os from bmtk.utils.reports.spike_trains import PoissonSpikeGenerator from bmtk.utils.reports.spike_trains import SpikeTrains import matplotlib.pyplot as plt import numpy as np if os.path.exists('inputs/ramping_spikes.h5'): os.remove('inputs/ramping_spikes.h5') # Create PGN firing rate time_range = np.linspace(0.0, 10.0, 20000) psg = PoissonSpikeGenerator(mode='w') psg.add(node_ids=[0], firing_rate=np.linspace(1.0, 10.0, 30000), population='external', times=time_range) psg.to_sonata('inputs/ramping_spikes.h5') #st = SpikeTrains.from_sonata('inputs/ramping_spikes.h5') #print(st.get_times(0)) #spikes = np.zeros(100001, dtype=np.int) #spikes[(st.get_times(0) / 0.1).astype(np.int)] = 1 #plt.plot(spikes) #plt.show()
# report_vars=['v'], # spikes_inputs=[('tone', './12_cell_inputs/tone_spikes.csv'), # ('shock', './12_cell_inputs/shock_spikes.csv'), # ('bg_pn', '12_cell_inputs/bg_pn_spikes.h5'), # ('bg_pv', '12_cell_inputs/bg_pv_spikes.h5'), # ('bg_olm', '12_cell_inputs/bg_olm_spikes.h5')], # components_dir='biophys_components', # config_file='config.json', # compile_mechanisms=False) psg = PoissonSpikeGenerator(population='bg_pn') psg.add( node_ids=range(8), # need same number as cells firing_rate=1, # 1 spike every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('12_cell_inputs/bg_pn_spikes.h5') print('Number of background spikes for pn: {}'.format(psg.n_spikes())) psg = PoissonSpikeGenerator(population='bg_pv') psg.add( node_ids=range(2), # need same number as cells firing_rate=8, # 8 spikes every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('12_cell_inputs/bg_pv_spikes.h5') print('Number of background spikes for pv: {}'.format(psg.n_spikes())) psg = PoissonSpikeGenerator(population='bg_olm') psg.add( node_ids=range(2), # need same number as cells
def build_model(): if os.path.isdir('network'): shutil.rmtree('network') if os.path.isdir('2_cell_inputs'): shutil.rmtree('2_cell_inputs') seed = 967 random.seed(seed) np.random.seed(seed) load() syn = syn_params_dicts() # Initialize our network net = NetworkBuilder("biophysical") num_inh = [1] num_exc = [1] ################################################################################## ###################################BIOPHY######################################### # PN net.add_nodes(N=1, pop_name='PyrC', mem_potential='e', model_type='biophysical', model_template='hoc:Cell_C', morphology=None) # PV net.add_nodes(N=1, pop_name="PV", mem_potential='e', model_type='biophysical', model_template='hoc:basket', morphology=None) backgroundPN_C = NetworkBuilder('bg_pn_c') backgroundPN_C.add_nodes(N=1, pop_name='tON', potential='exc', model_type='virtual') backgroundPV = NetworkBuilder('bg_pv') backgroundPV.add_nodes(N=2, pop_name='tON', potential='exc', model_type='virtual') # if neuron is sufficiently depolorized enough post synaptic calcium then synaptiic weight goes up # pyr->pyr & pyr->PV # PV->pyr PV->PV def one_to_all(source, target): sid = source.node_id tid = target.node_id print("connecting bio cell {} to bio cell {}".format(sid, tid)) return 1 def BG_to_PN_C(source, target): sid = source.node_id tid = target.node_id if sid == tid: print("connecting BG {} to PN_C{}".format(sid, tid)) return 1 else: return 0 def BG_to_PV(source, target): sid = source.node_id tid = target.node_id sid = sid + 1 if sid == tid: print("connecting BG {} to PV{}".format(sid, tid)) return 1 else: return 0 conn = net.add_edges(source=net.nodes(pop_name='PyrC'), target=net.nodes(pop_name="PV"), connection_rule=one_to_all, syn_weight=1.0, delay=0.1, distance_range=[-10000, 10000], dynamics_params='PN2PV.json', model_template=syn['PN2PV.json']['level_of_detail']) conn.add_properties(['sec_id', 'sec_x'], rule=(1, 0.9), dtypes=[np.int32, np.float]) conn = net.add_edges(source=net.nodes(pop_name='PV'), target=net.nodes(pop_name="PyrC"), connection_rule=one_to_all, syn_weight=1.0, delay=0.1, distance_range=[-10000, 10000], dynamics_params='PV2PN.json', model_template=syn['PV2PN.json']['level_of_detail']) conn.add_properties(['sec_id', 'sec_x'], rule=(1, 0.9), dtypes=[np.int32, np.float]) conn = net.add_edges(source=backgroundPN_C.nodes(), target=net.nodes(pop_name='PyrC'), connection_rule=BG_to_PN_C, syn_weight=1.0, delay=0.1, distance_range=[-10000, 10000], dynamics_params='BG2PNC.json', model_template=syn['BG2PNC.json']['level_of_detail']) conn.add_properties(['sec_id', 'sec_x'], rule=(2, 0.9), dtypes=[np.int32, np.float]) # places syn on apic at 0.9 conn = net.add_edges(source=backgroundPV.nodes(), target=net.nodes(pop_name='PV'), connection_rule=BG_to_PV, syn_weight=1.0, delay=0.1, distance_range=[-10000, 10000], dynamics_params='BG2PV.json', model_template=syn['BG2PV.json']['level_of_detail']) conn.add_properties(['sec_id', 'sec_x'], rule=(1, 0.9), dtypes=[np.int32, np.float]) backgroundPN_C.build() backgroundPN_C.save_nodes(output_dir='network') backgroundPV.build() backgroundPV.save_nodes(output_dir='network') net.build() net.save(output_dir='network') # SPIKE TRAINS t_sim = 40000 # build_env_bionet(base_dir='./', # network_dir='./network', # tstop=t_sim, dt=0.1, # report_vars=['v'], # components_dir='biophys_components', # config_file='config.json', # spikes_inputs=[('bg_pn_c', '2_cell_inputs/bg_pn_c_spikes.h5'), # ('bg_pv', '2_cell_inputs/bg_pv_spikes.h5')], # compile_mechanisms=False) psg = PoissonSpikeGenerator(population='bg_pn_c') psg.add( node_ids=range(1), # need same number as cells firing_rate=6, # 1 spike every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('2_cell_inputs/bg_pn_c_spikes.h5') print('Number of background spikes for PN_C: {}'.format(psg.n_spikes())) psg = PoissonSpikeGenerator(population='bg_pv') psg.add( node_ids=range(1), # need same number as cells firing_rate=7.7, # 8 spikes every 1 second Hz times=(0.0, t_sim / 1000)) # time is in seconds for some reason psg.to_sonata('2_cell_inputs/bg_pv_spikes.h5') print('Number of background spikes for PV: {}'.format(psg.n_spikes()))