Is it possible to implement a non neuron ODE in Brian2

Hello everyone,

I am quite new to the world of Brian and would like to find out if it is possible to implement a ODE, which has nothing to do with the behaviour of a neuron, as an equation for a NeuronGroup. It is about the Kelvin-Maxwell model, which can be described by the following ODEs:

d^2e(t)/dt^2 = 1/m*(F_Ext(t)+A_c*(sigma_MW(t)+n_0de(t)/dt+k_0e(t)) (1)
de(t)/dt*k1=dsigma_MW(t)/dt + sigma_MW(t)*a1 (2)

The ODE should calculate the strain e(t) of the Kelvin-Maxwell Element due to an external force F_Ext. Can you give an opinion on whether this is possible if, for example, the order of (1) is reduced by substitution and what an implementation might look like? Many thanks in advance!



Minimal code to reproduce problem

eqs = Equations(‘’’
dv/dt=1/m*(F_ext+Ac * sigmaMW1+Ac * n0 * v+Ac * k0 * e) : 1
v=de/dt : 1/second
v*k1=dsigmaMW1/dt+sigmaMW1 * a1 : pascal

G = NeuronGroup(1, eqs)

Full traceback of error (if relevant)

ERROR Brian 2 encountered an unexpected error. If you think this is a bug in Brian 2, please report this issue either to the discourse forum at, or to the issue tracker at Please include this file with debug information in your report: C:\Users\Admin\AppData\Local\Temp\brian_debug_brpfs0m0.log Additionally, you can also include a copy of the script that was run, available at: C:\Users\Admin\AppData\Local\Temp\ Thanks! [brian2]
Traceback (most recent call last):
File “c:\Users\Admin\venv\brian\Lib\site-packages\brian2\equations\”, line 344, in parse_string_equations
parsed = EQUATIONS.parseString(eqns, parseAll=True)
File “c:\Users\Admin\venv\brian\Lib\site-packages\pyparsing\”, line 1141, in parse_string
raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected end of text, found ‘v’ (at char 82), (line:4, col:5)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “c:\Users\Admin\Documents\PhD\Code\Python\Brian2\DEA_model\”, line 33, in
eqs = Equations(‘’’
File “c:\Users\Admin\venv\brian\Lib\site-packages\brian2\equations\”, line 554, in init
self._equations = parse_string_equations(eqns)
File “c:\Users\Admin\venv\brian\Lib\site-packages\brian2\utils\”, line 101, in cached_func
func._cache[cache_key] = func(args, **kwds)
File “c:\Users\Admin\venv\brian\Lib\site-packages\brian2\equations\”, line 346, in parse_string_equations
raise EquationError(“Parsing failed: \n” + str(p_exc.line) + “\n” +
brian2.equations.equations.EquationError: Parsing failed:
k1=dsigmaMW1/dt+sigmaMW1*a1 : pascal
Expected end of text, found ‘v’ (at char 82), (line:4, col:5)

You can absolutely use brian2 to integrate non neuronal ODE’s.
The error you are currently dealing with is due to this line
v*k1=dsigmaMW1/dt+sigmaMW1 * a1 : pascal
Essentially brian2 does not like the multiplication on the left-hand side of the equation.
Howevering fixing this will lead to a different error, due to the duplicate definitions for the variable ‘v’.
I tried renaming them:

eqs = Equations("""dv/dt=1/m*(F_ext+Ac * sigmaMW1+Ac * n0 * v+Ac * k0 * e) : 1
v_1=de/dt : 1/second
v_2=dsigmaMW1/dt+sigmaMW1 * a1 : pascal""")

I am not too familiar with this model, so I am unsure exactly where to go from here.

Hope this helps!

1 Like