---
tags:
  - single-cell-simulation
---

# Single Cell Simulations

Single cell simulations in OBI-ONE use **MEModel** (Morphology and Electrophysiology Model) configurations to simulate individual neurons.

## Overview

Single cell simulations are configured using `MEModelSimulationSingleConfig` or `MEModelSimulationScanConfig` for parameter scans. These simulations run individual neurons with their morphology and electrophysiological properties.

## Key Components

### MEModelSimulationSingleConfig

The `MEModelSimulationSingleConfig` class (located in `obi_one/scientific/tasks/generate_simulations/config/base.py`) is used to configure single cell simulations. It includes:

- **Circuit**: A MEModel (Morphology and Electrophysiology Model) to simulate
- **Simulation Parameters**: Duration, timestep, initial voltage, extracellular calcium concentration
- **Stimuli**: Various stimulus types that can be applied to the cell
- **Recordings**: Voltage and other electrophysiological recordings

### Simulation Execution

Simulations are executed using the `simulation_execution` module (`obi_one/scientific/library/simulation_execution.py`), which supports:

- **BlueCelluLab Backend**: Primary simulation backend using NEURON
- **Neurodamus Backend**: Alternative backend (currently not implemented)

### GenerateSimulationTask

The `GenerateSimulationTask` class (`obi_one/scientific/tasks/generate_simulations/task/task.py`) handles:

- Converting OBI-one configuration to SONATA simulation format
- Setting up circuit and node sets
- Generating simulation configuration files
- Managing entity database integration

## Configuration Structure

A typical single cell simulation configuration includes:

```python
from obi_one import MEModelSimulationSingleConfig, MEModelFromID

config = MEModelSimulationSingleConfig(
    initialize=MEModelSimulationSingleConfig.Initialize(
        circuit=MEModelFromID(id="..."),
        simulation_length=1000.0,  # ms
        v_init=-80.0,  # mV
        extracellular_calcium_concentration=1.1,  # mM
        random_seed=1
    ),
    stimuli={...},
    recordings={...},
    timestamps={...}
)
```

## Simulation Parameters

### Initialize Block

- **circuit**: MEModel to simulate (can be `MEModelCircuit` or `MEModelFromID`)
- **simulation_length**: Duration in milliseconds (default: 1000.0 ms)
- **v_init**: Initial membrane potential in millivolts (default: -80.0 mV)
- **extracellular_calcium_concentration**: Extracellular calcium concentration in mM (default: 1.1 mM)
- **random_seed**: Random seed for reproducibility
- **timestep**: Simulation time step in ms (default: 0.025 ms)
- **spike_location**: Location for spike detection - "soma" or "AIS" (default: "soma")

### Stimuli

Various stimulus types are available for single cell simulations:

- Current clamp stimuli (constant, linear, sinusoidal, etc.)
- Spike-based stimuli (Poisson, synchronous, etc.)

### Recordings

Recordings capture electrophysiological data:

- **SomaVoltageRecording**: Voltage recordings from the soma
- **TimeWindowSomaVoltageRecording**: Voltage recordings within specific time windows

## Running Simulations

### Using GenerateSimulationTask

```python
from obi_one import GenerateSimulationTask

task = GenerateSimulationTask(config=config)
task.run(output_path=Path("output"))
```

### Direct Execution

```python
from obi_one.scientific.library.simulation_execution import run

run(
    simulation_config="path/to/simulation_config.json",
    simulator="bluecellulab",
    save_nwb=True
)
```

## Output

Simulation outputs include:

- **Voltage traces**: Time-series voltage data for the simulated cell
- **Spike times**: Detected action potentials
- **NWB files**: Neurodata Without Borders format for standardized data storage
- **Reports**: Various analysis reports generated by BlueCelluLab

## Examples

See the examples directory for notebook examples:

- `examples/F_single_cell_simulations/` - Single cell simulation examples
