(userdocs:simulators)=
# Simulating NeuroML Models

```{admonition} Validate NeuroML 2 files before using them.
:class: tip
It is good practice to {ref}`validate NeuroML 2 files <userdocs:validating_models>` to check them for correctness before simulating them.
```
(userdocs:simulating_models:osb)=
## Using Open Source Brain

Models that have already been converted to NeuroML and added to the [Open Source Brain](https://www.opensourcebrain.org/) platform can be simulated through your browser.

```{figure} ../images/OSBv1.png
:alt: Open Source Brain
:align: center
:scale: 25 %

Examples of NeuroML 2 models visualised on Open Source Brain. A) [Hodgkin Huxley model](https://www.opensourcebrain.org/projects/hodgkin-huxley-tutorial?explorer=https%3A%2F%2Fraw.githubusercontent.com%2Fopensourcebrain%2Ftutorials%2Fdevelopment%2Fmodels%2FhodgkinHuxley%2FGEPPETTO.json) interactive tutorial. B) Integrate and fire network model of cortical column ([Potjans and Diesmann 2014](https://www.opensourcebrain.org/projects/potjansdiesmann2014)), showing network connectivity. C) Cortical model with multicompartmental cells ([Traub et al. 2005](https://www.opensourcebrain.org/projects/thalamocortical)), showing network properties and simulated membrane potential activity. D) Model of C. elegans nervous system from [OpenWorm project](https://www.opensourcebrain.org/projects/c302/). All visualisation/analysis/simulation enabled due to models being in standardised NeuroML format.

```
Most of the [OSB example projects](https://www.opensourcebrain.org/projects) feature prebuilt NeuroML models which can be simulated in this way.

A discussion on the steps required for sharing your own models on OSB, with a view to simulating them on the platform, can be found {ref}`here <userdocs:creating_models:converting_conductance>`.

(userdocs:simulating_models:jlems)=
(userdocs:simulating_models:jnml)=
## Using jNeuroML/pyNeuroML

{ref}`jLEMS <jlems>` is the reference implementation of the LEMS language in Java, and can be used to simulate single compartment models written in NeuroML/LEMS.
It is included in both {ref}`jNeuroML <jneuroml>` and {ref}`pyNeuroML <pyNeuroML>`.

```{figure} ../images/pynml_jnml.svg
:alt: jNeuroML and pyNeuroML
:align: center
:width: 500px

Relationship between {ref}`jLEMS <jlems>`,  {ref}`jNeuroML <jneuroml>` and {ref}`pyNeuroML <pyNeuroML>`.

```

{ref}`jNeuroML <jneuroml>` and {ref}`pyNeuroML <pyNeuroML>` can be used at the command line as follows, when a {ref}`LEMS Simulation file <userdocs:lemssimulation>` has been created to describe what to simulate/plot/save:

```{code-block} console
# Simulate the model using jNeuroML
jnml <LEMS simulation file>

# Simulate the model using pyNeuroML
pynml <LEMS simulation file>
```

You can also run LEMS simulations using jNeuroML straight from a Python script using the {ref}`pyNeuroML <pyneuroml>` API:

```{code-block} python
from pyneuroml.pynml import run_lems_with_jneuroml

...

run_lems_with_jneuroml(lems_file_name)
```

(userdocs:simulating_models:neuron)=
## Using NEURON

For more complex models that can not be simulated using jLEMS (e.g. incorporating multicompartmental cells), we can use the {ref}`NEURON <userdocs:neuron>` simulator, also using {ref}`jNeuroML <jneuroml>` or {ref}`pyNeuroML <pyNeuroML>`, pointing at a {ref}`LEMS Simulation file <userdocs:lemssimulation>` describing what to simulate, and using the `-neuron` option:

```{code-block} console
# Simulate the model using NEURON with python/hoc/mod files generated by jNeuroML
jnml <LEMS simulation file> -neuron -run

# Simulate the model using NEURON with python/hoc/mod files generated by pyNeuroML
pynml <LEMS simulation file> -neuron -run
```

You can also run LEMS simulations using the NEURON simulator using the {ref}`pyNeuroML <pyneuroml>` API:

```{code-block} python
from pyneuroml.pynml import run_lems_with_jneuroml_neuron

...

run_lems_with_jneuroml_neuron(lems_file_name)
```
There is a **dedicated page on NEURON/NeuroML interactions** {ref}`here <userdocs:neuron>`.


(userdocs:simulating_models:netpyne)=
## Using NetPyNE

You can also generate and run [NetPyNE](https://netpyne.org) code from NeuroML.
To generate and run NetPyNE code, use {ref}`jNeuroML <jneuroml>` or {ref}`pyNeuroML <pyNeuroML>`:

```{code-block} console
# Simulate the model using NetPyNE with python/hoc/mod files generated by jNeuroML
jnml <LEMS simulation file> -netpyne -run

# Simulate the model using NetPyNE with python/hoc/mod files generated by pyNeuroML
pynml <LEMS simulation file> -netpyne -run
```

The main generated Python file name will end in `_netpyne.py`.

You can also run LEMS simulations using the NetPyNE simulator using the {ref}`pyNeuroML <pyneuroml>` API:

```{code-block} python
from pyneuroml.pynml import run_lems_with_jneuroml_netpyne

...

run_lems_with_jneuroml_netpyne(lems_file_name)
```

There is a **dedicated page on NetPyNE/NeuroML interactions** {ref}`here <userdocs:netpyne>`.


(userdocs:simulating_models:brian2)=
## Using Brian2

You can export single component NeuroML models to Python scripts for running them using the [Brian2](https://briansimulator.org) simulator:

```{code-block} console
# Using jnml
jnml <LEMS simulation file> -brian2

# Using pynml
pynml <LEMS simulation file> -brian2
```

You can also run LEMS simulations using the Brian2 simulator using the {ref}`pyNeuroML <pyneuroml>` API:

```{code-block} python
from pyneuroml.pynml import run_lems_with_jneuroml_brian2

...

run_lems_with_jneuroml_brian2(lems_file_name)
```

There is a **dedicated page on Brian/NeuroML interactions** {ref}`here <userdocs:brian>`.

(userdocs:simulating_models:moose)=
## Using MOOSE

You can export NeuroML models to the MOOSE simulator format using {ref}`jNeuroML <jneuroml>` or {ref}`pyNeuroML <pyNeuroML>`, pointing at a {ref}`LEMS Simulation file <userdocs:lemssimulation>` describing what to simulate, and using the `-moose` option:

```{code-block} console
# Using jnml
jnml <LEMS simulation file> -moose

# Using pynml
pynml <LEMS simulation file> -moose
```
There is a **dedicated page on MOOSE/NeuroML interactions** {ref}`here <userdocs:moose>`.


(userdocs:simulating_models:eden)=
## Using EDEN

The EDEN simulator can load and simulate NeuroML v2 models.

There is a **dedicated page on EDEN/NeuroML interactions** {ref}`here <userdocs:eden>`.



(userdocs:simulating_models:arbor)=
## Using Arbor

You can import NeuroML models to the Arbor simulator.

There is a **dedicated page on Arbor/NeuroML interactions** {ref}`here <userdocs:arbor>`.
