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.

Note

When using this feature in a publication, please cite either

Weise, K., Numssen, O., Thielscher, A., Hartwigsen, G., & Knösche, T. R. (2020). A novel approach to localize cortical TMS effects. Neuroimage, 209, 116486.

or

Gomez, L. J., Dannhauer, M., & Peterchev, A. V. (2020). Fast computational optimization of TMS coil placement for individualized electric field targeting. bioRxiv in case you use the ADM method. The ADM code is distributed under the conditions below:

Authors of auxiliary dipole method (ADM) and code for determining rapidly the optimum coil position and orientation: Luis J. Gomez, Moritz Dannhauer, and Angel V. Peterchev; Duke University, Durham, North Carolina, U.S.A.

The development of the Duke ADM algorithm and code were supported by the National Institute of Mental Health and the National Institute on Aging of the National Institutes of Health under Award Numbers K99MH120046, RF1MH114268, RF1MH114253, and U01AG050618. The content is solely the responsibility of the authors and does not necessarily represent the official views of the National Institutes of Health.

The copyrights of this software are owned by Duke University. As such, two licenses to this software are offered:

As a recipient of this software, you may choose which license to receive the code under. Outside contributions to the Duke owned code base cannot be accepted unless the contributor transfers the copyright to those changes over to Duke University.

To enter a license agreement without the GPL-v2.0 restrictions, please contact the Digital Innovations department at Duke Office of Licensing and Ventures (https://olv.duke.edu/software/) at olvquestions@duke.edu with reference to “OLV File No. 7148” in your email.

Please note that this software is distributed AS IS, WITHOUT ANY WARRANTY; and without the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

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

Auxiliary Dipole Method (ADM)

To use the Auxiliary Dipole Method (ADM), simply use a .ccd coil file and set the method = 'ADM'

tms_opt.fnamecoil = 'Magstim_70mm_Fig8.ccd'
tms_opt.method = 'ADM'

Python

from simnibs import opt_struct, mni2subject_coords

# 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
# The ADM method requires a '.ccd' coil model
tms_opt.fnamecoil = 'Magstim_70mm_Fig8.ccd'
# Select a target for the optimization
tms_opt.target = mni2subject_coords([-37, -21, 58], 'm2m_ernie')
# Use the ADM method
tms_opt.method = 'ADM'
# Run optimization
tms_opt.run()

MATLAB

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
% The ADM method requires a '.ccd' coil model
tms_opt.fnamecoil = 'Magstim_70mm_Fig8.ccd';
% Select a target for the optimization
tms_opt.target = mni2subject_coords([-37, -21, 58], 'm2m_ernie');
% Use the ADM method
tms_opt.method = 'ADM';
% Run optimization
run_simnibs(tms_opt);

Acknowledgements

We would like to thank Ole Numssen and Konstantin Weise for the help in developing this functionality, and Luis Gomez for contributing the code for the ADM optimization

Further Reading

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