Trouble Making Synapse with AMPA and NMDA receptors

Description of problem

I am working with coding for an excitatory AMPAR-like synapses (see AMPA synapse and target neuron eqs below). It works fine. I also generated an excitatory NMDAR-like synapses (see NMDA synapse and target neuron eqs. below). These synapses have a target conductance that ranges linearly from zero at target cell voltage < -50mV to maximal at target cell voltage > -20mV, with a linearly increasing conductance between -50 to -20 mV. This works fine, too. I now wish to make an excitatory synapses that have AMPA and NMDA conductances at any desired ratio using a term NAratio. When constructing these synapses (see Dual Conductance synapse and target neuron eqs.), I am getting error messages that I have not yet been able to troubleshoot. Any suggestions?

Minimal code to reproduce problem

For AMPAR-like synapses

### Some parameters
vr = -52.0* mV # resting potential
alpha = 1.47826 /second
Beta = 200 /second
s_inf =alpha/(alpha+Beta)
tau_s =1/(alpha+Beta)
g_e = 118* nS # EPSC conductance
Ee=0 *mV # EPSC reversal potential
klow = 0.1* nS/mV # inward K rectifier

### Define the target cell equations
eqs_target = """
Isyn_e_target = g_e*(v-Ee)*s_sum_e_target : amp
s_sum_e_target : 1
dv/dt = (klow*v*(v-vr)-Isyn_e_target)/C_target : volt
"""

### Define the Excitatory TGT_Post Synapse model

S_source_target=Synapses(SRC,TGT,
       model="""
              ds0/dt=-(s0-s_inf)/(tau_s) :1 (clock-driven)
              ds1/dt=-s1*Beta :1 (clock-driven)
              s_tot=clip(s0,0,s1) :1
              s_sum_e_target_post = s_tot : 1 (summed)
       """,
       on_pre="""
              s0=s1
              s1=(s_inf*(1-exp(-0.001*second/tau_s))+s1*exp(-0.001*second/tau_s))*exp(0.001*Beta*second)
              delay=0.001*second
       """,
          method = 'exact')

This works fine

For NMDAR-like synapses

### Some parameters
NAratio = 0.5  # ratio of NMDARmax:AMPAR conductances
vunit = 1 * mV  # needed in eq to make fracNMDA unitless
alpha = 1.4 /second
Beta = 50 /second
s_inf =alpha/(alpha+Beta)
tau_s =1/(alpha+Beta)
g_e = 118 * nS # EPSC conductance
Ee=0 *mV # EPSC reversal potential
klow = 0.1 * nS/mV # inward K rectifier

### Define the target cell equations

eqs_target = """
fracNMDA = clip((v+vunit*50)/(vunit*20),0,1) : 1
Isyn_e_target = g_e*NAratio*fracNMDA*(v-Ee)*s_sum_e_target : amp
s_sum_e_target : 1
dv/dt = (klow*v*(v-vr)-Isyn_e_target)/C_target : volt
"""

### Define the Excitatory TGT_Post Synapse model
S_source_target=Synapses(SRC,TGT,
       model="""
              ds0/dt=-(s0-s_inf)/(tau_s) :1 (clock-driven)
              ds1/dt=-s1*Beta :1 (clock-driven)
              s_tot=clip(s0,0,s1) :1
              s_sum_e_target_post = s_tot : 1 (summed)
       """,
       on_pre="""
              s0=s1
              s1=(s_inf*(1-exp(-0.001*second/tau_s))+s1*exp(-0.001*second/tau_s))*exp(0.001*Beta*second)
              delay=0.001*second
       """,
          method = 'exact')

This works fine

For Dual Conductance synapses

### Some parameters

NAratio = 0.5  # ratio of NMDARmax:AMPAR conductances
vunit = 1 * mV  # needed in eq to make fracNMDA unitless
g_e = 118 * nS # EPSC conductance
alpha_AMPA = 1.47826 /second
Beta_AMPA = 200 /second
s_inf_AMPA =alpha_AMPA/(alpha_AMPA+Beta_AMPA)
tau_s_AMPA =1/(alpha_AMPA+Beta_AMPA)
alpha_NMDA = 1.4 /second
Beta_NMDA = 50 /second
s_inf_NMDA =alpha_NMDA/(alpha_NMDA+Beta_NMDA)
tau_s_NMDA =1/(alpha_NMDA+Beta_NMDA)
Ee=0*mV # EPSC reversal potential
klow = 0.1 * nS/mV # inward K rectifier

### Define the target cell equations
eqs_target = """
Isyn_e_target = g_e*(v-Ee)*s_sum_e_target : amp
s_sum_e_target : 1
dv/dt = (klow*v*(v-vr)-Isyn_e_target)/C_target : volt
"""

### Define the Excitatory TGT_Post Synapse model
S_source_target=Synapses(SRC,TGT,
       model="""
              v : volt
              fracNMDA = clip((v_post+vunit*50)/(vunit*20),0,1) : 1
              ds0_AMPA/dt=-(s0_AMPA-s_inf_AMPA)/(tau_s_AMPA) :1 (clock-driven)
              ds1_AMPA/dt=-s1_AMPA*Beta_AMPA :1 (clock-driven)
              s_AMPA_tot=clip(s0_AMPA,0,s1_AMPA)*(1+p_pre)*(1-f_pre) :1
              ds0_NMDA/dt=-(s0_NMDA-s_inf_NMDA)/(tau_s_NMDA) :1 (clock-driven)
              ds1_NMDA/dt=-s1_NMDA*Beta_NMDA :1 (clock-driven)
              s_NMDA_tot=clip(s0_NMDA,0,s1_NMDA)*(1+p_pre)*(1-f_pre)*fracNMDA*NAratio :1
              s_tot=s_AMPA_tot + s_NMDA_tot
              s_sum_e_target_post = s_tot : 1 (summed)
       """,
       on_pre="""
              s0_AMPA=s1_AMPA
              s0_NMDA=s1_NMDA
              s1_AMPA=(s_inf_AMPA*(1-exp(-0.001*second/tau_s_AMPA))+s1_AMPA*exp(-0.001*second/tau_s_AMPA))*exp(0.001*Beta_AMPA*second)
              s1_NMDA=(s_inf_NMDA*(1-exp(-0.001*second/tau_s_NMDA))+s1_NMDA*exp(-0.001*second/tau_s_NMDA))*exp(0.001*Beta_NMDA*second)
              delay=0.001*second
       """,
          method = 'exact')

ERROR MSG

    s_AMPA_tot + s_NMDA_tot s_sum_e_target_post = s_tot
                            ^
SyntaxError: invalid syntax

What you have aready tried

Expected output (if relevant)

Actual output (if relevant)

Full traceback of error (if relevant)

Traceback (most recent call last):

File ~\AppData\Roaming\Python\Python313\site-packages\IPython\core\interactiveshell.py:3699 in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

Cell In[72], line 2
S_source_target=Synapses(SRC,TGT,

File c:\Users\goldf\anaconda3.1\Lib\site-packages\brian2\synapses\synapses.py:845 in _init_
model = Equations(model)

File c:\Users\goldf\anaconda3.1\Lib\site-packages\brian2\equations\equations.py:620 in _init_
self._equations = parse_string_equations(eqns)

File c:\Users\goldf\anaconda3.1\Lib\site-packages\brian2\utils\caching.py:107 in cached_func
func._cache[cache_key] = func(*args, **kwds)

File c:\Users\goldf\anaconda3.1\Lib\site-packages\brian2\equations\equations.py:417 in parse_string_equations
expression = Expression(p.sub(" ", expression))

File c:\Users\goldf\anaconda3.1\Lib\site-packages\brian2\equations\codestrings.py:108 in _init_
str_to_sympy(code)

File c:\Users\goldf\anaconda3.1\Lib\site-packages\brian2\parsing\sympytools.py:77 in str_to_sympy
return _str_to_sympy(expr)

File c:\Users\goldf\anaconda3.1\Lib\site-packages\brian2\utils\caching.py:107 in cached_func
func._cache[cache_key] = func(*args, **kwds)

File c:\Users\goldf\anaconda3.1\Lib\site-packages\brian2\parsing\sympytools.py:83 in _str_to_sympy
s_expr = SympyNodeRenderer().render_expr(expr)

File c:\Users\goldf\anaconda3.1\Lib\site-packages\brian2\parsing\rendering.py:58 in render_expr
node = ast.parse(expr, mode=“eval”)

File c:\Users\goldf\anaconda3.1\Lib\ast.py:50 in parse
return compile(source, filename, mode, flags,

File :1
s_AMPA_tot + s_NMDA_tot s_sum_e_target_post = s_tot
^
SyntaxError: invalid syntax

Hi @MitchG_HunterCollege,
your general approach looks good, the problem is in these lines:

The first one needs to end with ... : 1. As it is written now, or parsing algorithm thinks that the definition for s_tot continues in the next line, i.e. it interprets everything as a single line (the line shown in the error message):

 s_AMPA_tot + s_NMDA_tot s_sum_e_target_post = s_tot

which is of course not a valid right-hand-side for the definition of s_tot.

I did not try it out, but replacing these two lines by

s_tot=s_AMPA_tot + s_NMDA_tot : 1
s_sum_e_target_post = s_tot : 1 (summed)

or (same meaning but shorter):

s_sum_e_target_post = s_AMPA_tot + s_NMDA_tot : 1 (summed)

should make it work.

Thank you, Marcel. In the synapse model, it was necessary to correct syntax to:

s_tot=s_AMPA_tot + s_NMDA_tot : 1

It was also necessary in the synapse model to delete the first line:

v : volt

With these changes, the synapse generates a mix of AMPA and NMDA postsynaptic currents, the latter showing desired voltage dependence.

1 Like