Skip to content

This repository set up the modeling for Principal Neurons on Medial Nucleus of Trapezoid Body, for Heller and Benites et al., 2025

Notifications You must be signed in to change notification settings

NikollasBenites/PN_MNTB_optimizations

Repository files navigation

🧠 MNTB Principal Neuron Model – NEURON Simulation (Python)

This repository contains a NEURON-based simulation of principal neurons (PN) in the Medial Nucleus of the Trapezoid Body (MNTB), developed for understanding intrinsic properties and responses after blocking the pre-sensory spontaneous activity (psSA). The model is built using Python and .mod files. The directory tree is:

PN_MNTB_modeling/
├── CSV/
│
├── data/
│
├── figures/
│
├── optimization/
│
├── results/
│
├── tests/
│
├── README.md
│
├── environment_windows.yml
├── environment_mac.yml
│
└── .gitignore

The tests folder contains one file called test_mods_smoke.py. This file is necessary to test if the mod files are properly set up. The results\test folder is the folder where the testing results should be when you are testing the scripts. **The last results for the paper are in results folder, separated specifically by experiment type (explained bellow)


🛠 Setup Instructions

1. Clone the Repository

To clone the repo is necessary that you have installed git on your computer https://github.com/git-guides/install-git. Your directory could be PN_MNTB_modeling but you can use the name you want. Just double-check your working directory.

git clone git@github.com:NikollasBenites/PN_MNTB_optimizations
cd PN_MNTB_modeling

You can also download all the files using the version v0.0.0 under Releases, or just download the .zip folder under Code

2. Create the Conda Environment

There are two envs files: one for mac and other for windows. Use the file that match your OS. Open a terminal on the directory the .yml files are. We tested the simulations exhaustively on MacOS. But, we also tested on Windows. We used PyCharm as our IDE.

conda env create -f environment_mac.yml
conda env create -f environment_windows.yml
conda activate neuron_env

MAKE SURE YOU HAVE CONDA INSTALLED AND YOUR INTERPRETER IS SET AS neuro_env

⚠️ macOS Users: You May Need Xcode Command Line Tools (CLT)

If you are using macOS, NEURON requires a C/C++ compiler to build the .mod files.
macOS does not install compilers by default.

You do not need the full Xcode application, but you do need the Xcode Command Line Tools (CLT).

You will be automatically prompted to install CLT if you try to compile mechanisms without it.
If not, you can install it manually:

xcode-select --install

If anything don't work, you can contact us anytime.

3. Compile NEURON (8.2.6) Mechanisms

FOR WINDOWS USERS IS NECESSARY TO INSTALL NEURON DIRECTLY FROM THE SOURCE. Several updates occurred on NEURON simulation environment regarding the API. We strongly recommend to use the specific version because the recent version (NEURON 9.0) was not tested. The detailed documentation and how to install the version used is found at https://nrn.readthedocs.io/en/8.2.6/install/install.html

Make sure you're in the root project directory (Mac and Windows) using Terminal. After you clone the repo, the mod folders are on ~/optimization/mod and ~/optimization/3D_and_bar_graphs/mod. Open a Terminal from those folders and use the command bellow on the Terminal.

nrnivmodl mod/

This will generate the arm64/ folder with compiled special (in Mac). In Windows OS you will generate a file nrnmech.dll in the Root.


The optimizers used from SciPy library were differential_evolution and minimize. You can find the documentation on:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.differential_evolution.html https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html

The CSV folder contains the averaged params from iMNTB and TeNT cells (avg_iMNTB_transposed.csv & avg_TeNT_transposed.csv) and also the last params used on the simulation for each cell. The data folder contains action potential sweeps used to be optimized and fitted. Also contains the VI used to fit the "passive" conductance. The figures folder contains the 3D graphs showing the behavior of simulated 2500 neurons with slightly changes in conductance values. Also contains the bar plots comparing the optimized values including the stats.


The optimization folder contains all the core codes for the paper:


PN file:

MNTB_PN_fit.py.

Essential functions:

MNTB_PN_myFunctions.py

Steady-state fitting (FIT FIRST STAGE):

Steady-state fitting in a batch.

WE RECOMMEND TO USE THESE FILES

batch_fit_passive_v2_TeNT.py

batch_fit_passive_v2_iMNTB.py

Those files work calling the function described bellow and fitting all the files proposed. You just need to run the script. All the files will be fitted and save at ~/PN_MNTB_modeling/results/test/passive_fits separated by folders. The script last about 20-30 minutes. A csv file summary will be generated. The mechanisms optimized on this stage are:

gKLT, gH, ELeak, gLeak

To fit one value at time, use:

fit_passive_v2_TeNT.py

fit_passive_v2_iMNTB.py

To use those, you need to run the code from the terminal inside the optimization folder:

python fit_passive_tent.py --data YOUR_DESIRED_FILE.cvs

python fit_passive_imntb.py --data YOUR_DESIRED_FILE.cvs

The csv files are in ~/PN_MNTB_modeling/data/fit_passive/iMNTB AND ~/TeNT.

Each fitting last about 2-5 minutes.

After fitting, they could be found at ~/PN_MNTB_modeling/results/test/passive_fits in each respective folder

AP fitting files (FIT SECOND STAGE):

fit_AP_v2_iMNTB.py

fit_AP_v2_TeNT.py

The script open the prior fitting files derived from fit_passive scripts and optimizes the conductance:

gNa, gKHT, gKA

To improving fitting, a small variation is set up on the passive conductance. Those files fit the action potentials traces using a mixed approach. The function extract features from the experimental trace and also point-by-point voltage comparison. Each AP fit could be finished in several minutes to several hours, regarding the computer. (30 minutes to 24-72hr)

✔ Point-by-point voltage comparison

MSE between experimental and simulated AP, but only in the AP window.

✔ Feature matching

Differences in:

latency

AP amplitude

peak

half-width

threshold

AHP

resting potential Weighted by biological importance.

✔ Temporal alignment

Difference in peak timing → big penalty.

✔ Firing-pattern correctness

Ensures simulated neuron fires:

“phasic” vs “tonic” at +20 pA

adds penalties if spike count is wrong

✔ Physiological constraints

Penalties for:

unrealistic RMP

bad AP peak

too many spikes

unstable resting potential

✔ Final refinement loop

Run multiple cycles of differential_evolution inside shrinking local bounds.

Simulation of the current clamp simulation:

fit_simulation.py

The filenames are in the script, on the first session. It's necessary to type the name inside filename variable (line 18). All the filenames names are in the list filenames (line 19). This script is used to double-check if the passive fit and ap fit worked properly and also to fine-tuning manually the simulation if it is necessary.

Plot voltage traces as you desire:

plotting_exp_data_traces.py


The results folder contains all the last results for the paper and also some figures and csv files to check the values of the optimization.

The output tests will be in ~/PN_MNTB_modeling/results/test: AP_fits, passive_fits, and simulations.

👤 Code adapted by

Nikollas Benites, University of South Florida

Daniel Heller, University of South Florida

📝 License

This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. https://creativecommons.org/licenses/by-nc-nd/4.0/


About

This repository set up the modeling for Principal Neurons on Medial Nucleus of Trapezoid Body, for Heller and Benites et al., 2025

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published