# Model Simulation

Similar to the single SAC example you can simulate, trace the voltage at the soma and plot it:

```
simulation.simulate()
results = simulation.trace_voltages_at_soma()

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(8,5))
for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]:
    plt.plot(results[0]['0'][i]['t'], results[0]['0'][i]['v'], ls='-', c='r', label='Expanding stimulus',linewidth=3)
plt.show()
```

Note that here voltages are traced in all 13 cells:

![](/files/HgwivGhlGzRpPUYE9i1f)

You can use the code below to generate the following synapse activity video, visualized over the SAC plexus:

{% file src="/files/ryIL2cTUEInCTPCWLrwE" %}

Note that the following code is not a native RSME code and that it might require the installation of video codecs in accordance with your operating system.

```
import seaborn as sns
import pandas as pd
from matplotlib import animation, rc
from IPython.display import HTML
from neuron import h
import matplotlib as mpl

xs = []
ys = []
sps = []

for cell in simulation.synapse_dict['light']['0']:
    for i in range(len(simulation.synapse_dict['light']['0'][cell]['x'])):
        x = simulation.synapse_dict['light']['0'][cell]['x'][i]
        y = simulation.synapse_dict['light']['0'][cell]['y'][i]
        syn = simulation.synapse_dict['light']['0'][cell]['BC_syn'][i]
        spike_times = simulation.simulation['spikes']['0'][cell][i]
        for sp_time in spike_times:
            xs.append(x)
            ys.append(y)
            sps.append(sp_time)

mpl.rcParams['animation.embed_limit']= 100
df = pd.DataFrame({'x':xs,'y':ys,'sps':sps})
df.index = df.sps
df = df.sort_index()

fig = figure(figsize=(9,9))
ax1 = subplot(1,1,1)
color = sns.color_palette("Paired",14)
for cell in simulation.simulation['cells']['0']['instances']:
    for sec in simulation.simulation['cells']['0']['instances'][cell]['section_dict']['section_list']:
        xs2 =[]
        ys2 =[]
        for i in range(int(sec.n3d())):
            xs2.append(sec.x3d(i))
            ys2.append(sec.y3d(i))
        plot(xs2, ys2,color=color[cell-1])
    plt.axis('equal')

old_sps =scatter([0],[0],marker='o')
def show_spikes(dt):
    global time, old_sps
    title(f't = {time} ms')
    sps = df.loc[time:time+dt]
    old_sps.remove()
    scs = scatter(sps.x,sps.y,marker='o', color='k')
    old_sps = scs
    time +=dt
    return []

time = 0
anim = animation.FuncAnimation(fig, show_spikes, frames=[1] + [4]*200)
Writer = animation.writers['ffmpeg']
writer = Writer(fps=15, metadata=dict(artist='NBEL'), bitrate=1800)
anim.save('plexus_SAC_stimulus.mp4', writer=writer)
HTML(anim.to_jshtml())
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://elishai.gitbook.io/retinal-stimulation-modeling-environment/sac-plexus-model/model-simulation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
