prc_unidirectional_microcircuit.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from brian2.units import *
  4. from scripts.models import hodgkin_huxley_params, hodgkin_huxley_eqs_with_synaptic_conductance, ih_params, eqs_ih, \
  5. exponential_synapse, exponential_synapse_on_pre, exponential_synapse_params
  6. from scripts.prc_and_iterative_diagram.timed_inhibition import TimedInhibition
  7. def analyze_response_curve(period_unperturbed, inhibitory_delay, periods):
  8. plt.plot(inhibitory_delay / ms, periods / ms)
  9. plt.hlines(period_unperturbed / ms, inhibitory_delay[0] / ms, inhibitory_delay[-1] / ms, label="No inhibition")
  10. plt.xlabel("Delay spike to inhibition (ms)")
  11. plt.ylabel("Period (ms")
  12. plt.legend()
  13. plt.show()
  14. phases = inhibitory_delay / period_unperturbed
  15. dphases = (period_unperturbed - periods) / period_unperturbed
  16. optimal_inhibitory_delay_idx = np.argmax(dphases)
  17. optimal_inhibitory_delay = inhibitory_delay[optimal_inhibitory_delay_idx] # assumes a single maximum
  18. plt.figure()
  19. plt.plot(phases, dphases)
  20. plt.vlines(optimal_inhibitory_delay, -1, 1)
  21. plt.title("Phase response curve")
  22. plt.ylim(-1, 1)
  23. plt.figure()
  24. if optimal_inhibitory_delay_idx == 0:
  25. delta_i = phases
  26. else:
  27. delta_i = phases[:-optimal_inhibitory_delay_idx]
  28. delta_iplus1 = delta_i + 1 + dphases[optimal_inhibitory_delay_idx:]
  29. plt.plot(delta_i, delta_iplus1)
  30. plt.plot(delta_i, delta_i, '--')
  31. plt.hlines(1, 0, 1)
  32. plt.xlabel("Delta i")
  33. plt.ylabel("Delta i+1")
  34. plt.title("Iterative map")
  35. plt.ylim(0, 1.2)
  36. plt.xlim(0, 1)
  37. plt.show()
  38. ### With conductance based delta synapse
  39. neuron_eqs = hodgkin_huxley_eqs_with_synaptic_conductance + eqs_ih
  40. synapse_model = exponential_synapse
  41. synapse_on_pre = exponential_synapse_on_pre
  42. synapse_params = exponential_synapse_params
  43. neuron_params = hodgkin_huxley_params
  44. neuron_params.update(ih_params)
  45. neuron_params.update({"E_i": -120 * mV})
  46. spike_threshold = -40 * mV
  47. inhibition_off = 0.0 * nS
  48. inhibition_on = 150 * nS
  49. record_variables = ['v', 'r', 'g_syn']
  50. integration_method = 'exponential_euler'
  51. initial_states = {
  52. "v": hodgkin_huxley_params["El"]
  53. }
  54. current_drive = 0.85 * nA
  55. n_simulations = 50
  56. before_spike = 1 * ms
  57. after_spike = 1 * ms
  58. timed_inhibition_experiment = TimedInhibition(neuron_eqs, synapse_model, synapse_on_pre, neuron_params,
  59. synapse_params, initial_states, spike_threshold, integration_method,
  60. current_drive, record_variables)
  61. period_unperturbed, inhibitory_delay, periods = timed_inhibition_experiment.measure_response_curve(n_simulations,
  62. inhibition_on,
  63. offset_before_spike_peak=before_spike,
  64. offset_after_spike_peak=after_spike)
  65. analyze_response_curve(period_unperturbed, inhibitory_delay, periods)
  66. spike_recorder, neuron_state_recorder = timed_inhibition_experiment.run_sim(delay=3 * ms, record_states=True,
  67. pulse_strength=inhibition_off,
  68. duration=200 * ms)
  69. ### Visualization of the h current role
  70. def plot_trace():
  71. t_state = neuron_state_recorder.t
  72. v_state = neuron_state_recorder[1].v
  73. g_state = neuron_state_recorder[1].g_syn
  74. r_state = neuron_state_recorder[1].r
  75. fig, (ax1, ax2, ax3) = plt.subplots(nrows=3)
  76. ax1.plot(t_state / ms, v_state / mV, 'C2')
  77. ax1.set_ylabel("V (mV)")
  78. ax2.plot(t_state / ms, r_state, 'C1')
  79. ax2.set_xlabel("t (ms)")
  80. ax2.set_ylabel("Ih activation")
  81. ax2.set_ylim(0,1)
  82. ax3.plot(t_state / ms, g_state/nS, 'C1')
  83. ax3.set_ylabel("g (nS)")
  84. fig.suptitle("Inhibition {:.1f}nS and delay {:.1f}ms".format(pulse_strength / nS, delay / ms))
  85. # delay = 0 * ms
  86. # pulse_strength = inhibition_off
  87. #
  88. # spike_recorder, neuron_state_recorder = timed_inhibition_experiment.run_sim(delay=delay, record_states=True,
  89. # pulse_strength=pulse_strength,
  90. # duration=100 * ms)
  91. # plot_trace()
  92. #
  93. # delay = 3 * ms
  94. # pulse_strength = inhibition_on
  95. #
  96. # spike_recorder, neuron_state_recorder = timed_inhibition_experiment.run_sim(delay=delay, record_states=True,
  97. # pulse_strength=pulse_strength,
  98. # duration=100 * ms)
  99. # plot_trace()
  100. #
  101. #
  102. # delay = 15 * ms
  103. # pulse_strength = inhibition_on
  104. #
  105. # spike_recorder, neuron_state_recorder = timed_inhibition_experiment.run_sim(delay=delay, record_states=True,
  106. # pulse_strength=pulse_strength,
  107. # duration=100 * ms)
  108. # plot_trace()
  109. #
  110. # plt.show()