# TDCS Network Optimization¶

As of SimNIBS 3.2, you can use SimNIBS to optimize electric fields based on distributed targets, such as t-maps from resting state networks. We use the problem set-up proposed in (Ruffini et al. 2014), and solve it using algorithms proposed in (Saturnino et al. 2019). The connection between the two algorithms is explained here

Note

## Optimiztion¶

In the examples below, we use the T-map defined in ID03_MOTOR_ICA file as a target. This T-map is defined in MNI space

### Python¶

''' Example of a SimNIBS tDCS optimization with a distributed target in Python
Run with:

simnibs_python tdcs_optimize_distributed.py

Copyright (C) 2020 Guilherme B Saturnino
'''
import simnibs

# Initialize structure
opt = simnibs.opt_struct.TDCSDistributedOptimize()
# Subject path
opt.subpath = 'm2m_ernie/'
# Select a name for the optimization
opt.name = 'optimization/distributed'

# Select a maximum total current (in A)
opt.max_total_current = 4e-3
# Select a maximum current at each electrodes (in A)
opt.max_individual_current = 1e-3
# Select a maximum number of active electrodes (optional)
opt.max_active_electrodes = 10

# Image with the field we want
opt.target_image = 'ID03_MOTOR_ICA.nii.gz'
opt.mni_space = True # set to False if target_image is in subject space
# Target electric field intensity
opt.intensity = 0.1

# Run optimization
simnibs.run_simnibs(opt)


### MATLAB¶

% Example of a SimNIBS tDCS optimization with a distributed target in Python

%    Copyright (C) 2020 Guilherme B Saturnino

% Initialize structure
opt = opt_struct('TDCSDistributedOptimize');
% Subject path
opt.subpath = 'm2m_ernie/';
% Select a name for the optimization
opt.name = 'optimization/distributed';

% Select a maximum total current (in A)
opt.max_total_current = 4e-3;
% Select a maximum current at each electrodes (in A)
opt.max_individual_current = 1e-3;
% Select a maximum number of active electrodes (optional)
opt.max_active_electrodes = 10;

% Image with the field we want
opt.target_image = 'ID03_MOTOR_ICA.nii.gz';
opt.mni_space = true; % set to false if target_image is in subject space
% Target electric field intensity
opt.intensity = 0.1;

% Run optimization
run_simnibs(opt)