TMS Optimization

SimNIBS can help finding the best TMS position for stimulating a certain target. This is done by searching coil positions in a grid around the target position and turning the coil at various angles.

Basic Setting

Setting up a TMS optimization is similar to set-up a TMS simulation. In the most basic settings, you need to select the head model, the coil being used and the target position. The target position has to be given in SimNIBS coordinates and can be determined using the nifti volumes produced by headreco, mri2mesh or by using the mni2subject_coords command line tool.

For accelerating the simulations, SimNIBS can use the MKL Pardiso direct solver. However, this solver uses approximately three times more memory than the standard solver.

Python

from simnibs import opt_struct

# Initialize structure
tms_opt = opt_struct.TMSoptimize()
# Select the head mesh
tms_opt.fnamehead = 'ernie.msh'
# Select output folder
tms_opt.pathfem = 'tms_optimization/'
# Select the coil model
tms_opt.fnamecoil = 'Magstim_70mm_Fig8.nii.gz'
# Select a target for the optimization
tms_opt.target = [-43.4, -20.7, 83.4]
# Optional: Use the MKL PARDISO solver
# Will make the simulations much faster
# but has large (approx 12GB) memory usage
tms_opt.solver_options = 'pardiso'
# Run optimization
tms_opt.run()

MATLAB

% Example script to run a TMS optimization
% Guilherme Saturnino, 2019

tms_opt = opt_struct('TMSoptimize');
% Select the head mesh
tms_opt.fnamehead = 'ernie.msh';
% Select output folder
tms_opt.pathfem = 'tms_optimization/';
% Select the coil model
tms_opt.fnamecoil = 'Magstim_70mm_Fig8.nii.gz';
% Select a target for the optimization
tms_opt.target = [-43.4, -20.7, 83.4];
% Optional: Use the MKL PARDISO solver
% Will make the simulations much faster
% but has large (approx 12GB) memory usage
tms_opt.solver_options = 'pardiso';
% Run optimization
run_simnibs(tms_opt);

This will first generate a grid of positions and start simulating. After it is done simulating, SimNIBS will return with the position that causes the largest electric field norm at the target.

The optimization will create the output file ernie_TMS_optimize_Magstim_70mm_Fig8_nii.msh: Gmsh .msh file with the optimized field and coil position

Acknowledgements

We would like to thank Ole Numssen and Konstantin Weise for the help in developing this functionality

Further Reading

Please see TMSoptimize for a detail description of all TMS optimization options