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. NeuroImage 2021; 228: 117696.

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 setting-up a TMS simulation. In the most basic setting, 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

import os
from simnibs import opt_struct

# Initialize structure
tms_opt = opt_struct.TMSoptimize()
# Subject folder
tms_opt.subpath = 'm2m_ernie'
# Select output folder
tms_opt.pathfem = 'tms_optimization/'
# Select the coil model
tms_opt.fnamecoil = os.path.join('legacy_and_other','Magstim_70mm_Fig8.ccd')
# Select a target for the optimization
tms_opt.target = [-39.7, 7.5, 65.6]
# 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 to get optimal coil position
opt_pos=tms_opt.run()

MATLAB

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

tms_opt = opt_struct('TMSoptimize');
% Subject folder
tms_opt.subpath = 'm2m_ernie';
% Select output folder
tms_opt.pathfem = 'tms_optimization/';
% Select the coil model
tms_opt.fnamecoil = fullfile('legacy_and_other','Magstim_70mm_Fig8.ccd');
% Select a target for the optimization
tms_opt.target = [-39.7, 7.5, 65.6];
% 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 magnitude at the target.

The optimization will create the Gmsh output file ernie_TMS_optimize_Magstim_70mm_Fig8_nii.msh 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 = os.path.join('legacy_and_other','Magstim_70mm_Fig8.ccd')
tms_opt.method = 'ADM'

Python

import os
from simnibs import opt_struct, mni2subject_coords

# Initialize structure
tms_opt = opt_struct.TMSoptimize()
# Subject folder
tms_opt.subpath = 'm2m_ernie'
# Select output folder
tms_opt.pathfem = 'tms_optimization_adm'
# Select the coil model
# The ADM method requires a '.ccd' coil model
tms_opt.fnamecoil = os.path.join('legacy_and_other','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
opt_pos=tms_opt.run()

MATLAB

tms_opt = opt_struct('TMSoptimize');
% Subject folder
tms_opt.subpath = 'm2m_ernie';
% Select output folder
tms_opt.pathfem = 'tms_optimization_adm';
% Select the coil model
% The ADM method requires a '.ccd' coil model
tms_opt.fnamecoil = fullfile('legacy_and_other','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 helping with the development of this functionality, and Luis Gomez for contributing the code for the ADM optimization.

Further Reading

Please see TMSoptimize for a detailed description of all TMS optimization options.

References

Weise, K., Numssen, O., Thielscher, A., Hartwigsen, G., Knösche, T.R. (in review) A novel approach to localize cortical TMS effects. bioRxiv, 595603.

Gomez, L. J., Dannhauer, M., & Peterchev, A. V. (2020). Fast computational optimization of TMS coil placement for individualized electric field targeting. bioRxiv