def simulation(fnamehead,
               pathfem,
               pos_centre=[-74.296158, -10.213354, 28.307243],
               pos_ydir=[-74.217369, -37.293205, 20.05232],
               distance=4,
               current_change=1e6):
    # Initalize a session
    s = sim_struct.SESSION()
    # Name of head mesh
    s.fnamehead = fnamehead
    # Output folder
    s.pathfem = pathfem
    # Not to visualize results in gmsh when running simulations (else set to True)
    s.open_in_gmsh = False
    # Initialize a list of TMS simulations
    tmslist = s.add_tmslist()
    # Select coil. For full list of available coils, please see simnibs documentation
    tmslist.fnamecoil = 'Magstim_70mm_Fig8.nii.gz'

    # Initialize a coil position
    pos = tmslist.add_position()
    pos.centre = pos_centre  # Place the coil over
    pos.pos_ydir = pos_ydir  # Point the coil towards
    pos.distance = distance  # Distance between coil and head
    pos.didt = current_change  # Rate of change of current in the coil, in A/s.
    run_simnibs(s)
Beispiel #2
0
    def run_simulation(self,
                       sim_output_name,
                       fnamecoil='MagVenture_MC_B70.ccd',
                       didt=1e6,
                       overwrite=False):

        s = sim_struct.SESSION()
        s.fnamehead = os.path.join(self.mesh_dir, self.subject + '.msh')
        print('output dir: ', self.wf_base_dir)

        try:
            if overwrite and os.path.exists(os.path.join(
                    self.wf_base_dir), 'simnibs_simulations', sim_output_name):
                os.rmdir(
                    os.path.join(self.wf_base_dir, 'simnibs_simulations',
                                 sim_output_name))
            os.makedirs(
                os.path.join(self.wf_base_dir, 'simnibs_simulations',
                             sim_output_name))
        except:
            raise OSError(
                'simulation directory exists, overwrite=True to overwrite the results!'
            )

        s.pathfem = os.path.join(self.wf_base_dir, 'simnibs_simulations',
                                 sim_output_name)
        s.map_to_vol = True
        s.map_to_surf = True
        tms = s.add_tmslist()
        tms.fnamecoil = os.path.join(Simnibs.SIMNIBSDIR, 'simnibs',
                                     'ccd-files', fnamecoil)
        tms.add_positions_from_csv(
            os.path.join(self.wf_base_dir, 'simnibs_targets', self.csv_fname))

        for p in tms.pos:
            p.didt = didt

        run_simnibs(s)
Beispiel #3
0
Retcontr.thickness = [1.5, 1.5]

ConditionA.electrode.append(deepcopy(Retcontr))
ConditionA.electrode[-1].centre = [-41.2, 78.8, -34.1]
# coordinates determined in simnibs_gui

# Define Condition B
S.poslists.append(deepcopy(ConditionA))
ConditionB = S.poslists[-1]

ConditionB.electrode[0].channelnr = 3
ConditionB.electrode[1].channelnr = 3
ConditionB.electrode[2].channelnr = 3
ConditionB.electrode[6].channelnr = 1
ConditionB.electrode[7].channelnr = 1

# Define Condition C
S.poslists.append(deepcopy(ConditionA))
ConditionC = S.poslists[-1]

ConditionC.electrode[0].channelnr = 2
ConditionC.electrode[1].channelnr = 1
ConditionC.electrode[2].channelnr = 2
ConditionC.electrode[3].channelnr = 3
ConditionC.electrode[4].channelnr = 3
ConditionC.electrode[5].channelnr = 3
ConditionC.electrode[6].channelnr = 3
ConditionC.electrode[7].channelnr = 3

run_simnibs(S)
Beispiel #4
0
''' Example of a SimNIBS tDCS leadfield in Python
    Run with:

    simnibs_python leadfield.py

    Copyright (C) 2019 Guilherme B Saturnino
    
    place script in the “ernie” folder of the example dataset
'''
from simnibs import sim_struct, run_simnibs

tdcs_lf = sim_struct.TDCSLEADFIELD()
# head mesh
tdcs_lf.fnamehead = 'ernie.msh'
# output directory
tdcs_lf.pathfem = 'leadfield'

# Uncoment to use the pardiso solver
#tdcs_lf.solver_options = 'pardiso'
# This solver is faster than the default. However, it requires much more
# memory (~12 GB)

run_simnibs(tdcs_lf)
Beispiel #5
0
    Copyright (C) 2019 Guilherme B Saturnino
'''

import simnibs

# Initialize structure
opt = simnibs.opt_struct.TDCSoptimize()
# Select the leadfield file
opt.leadfield_hdf = 'leadfield/ernie_leadfield_EEG10-10_UI_Jurak_2007.hdf5'
# Select a name for the optimization
opt.name = 'optimization/single_target'

# Select a maximum total current (in A)
opt.max_total_current = 2e-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 = 8

# Define optimization target
target = opt.add_target()
# Position of target, in subject space!
# please see tdcs_optimize_mni.py for how to use MNI coordinates
target.positions = [-55.4, -20.7, 73.4]
# Intensity of the electric field (in V/m)
target.intensity = 0.2

# Run optimization
simnibs.run_simnibs(opt)
Beispiel #6
0
def main():
    args = parseArguments(sys.argv[1:])
    run_simnibs(args.simnibs_file, args.cpus)
anode = tdcslist.add_electrode()
anode.channelnr = 1
anode.centre = 'C3'
anode.pos_ydir = 'C1'
anode.shape = 'rect'
anode.dimensions = [50, 50]
anode.thickness = 4

cathode = tdcslist.add_electrode()
cathode.channelnr = 2
cathode.centre = 'AF4'
cathode.pos_ydir = 'F6'
cathode.shape = 'rect'
cathode.dimensions = [50, 70]
cathode.thickness = 4

# Run the simulation in each subject
for sub in subjects:
    # ALWAYS create a new SESSION when changing subjects
    s = sim_struct.SESSION()
    s.map_to_fsavg = True
    s.fnamehead = os.path.join(sub, sub + '.msh')
    s.pathfem = os.path.join(sub, 'bipolar')
    # Don't open in gmsh
    s.open_in_gmsh = False
    # Add the tdcslist we defined above
    s.add_poslist(tdcslist)
    # Run the sumulation
    run_simnibs(s)
pos.distance = 1.  # coil distance (mm)
pos.didt = tint * 1e6  # TMS intensity (A/s)
pos.pos_ydir = ([1, 0, 0])  # coil towards right
pos.calc_matsimnibs(mesh)  # scalp projection
pos.pos_ydir = (pos.matsimnibs[0:3, 3] + [1, 0, 0]).tolist()
A = pos.centre
B = pos.pos_ydir  #### params needed !!!

################# HERE WE GO ....
k = sim_struct.SESSION()

k.fnamehead = meshfile
k.subpath = m2mfile
k.pathfem = outfile

mylist = k.add_tmslist()
mylist.fnamecoil = coilnifti
mylist.anisotropy_type = 'scalar'

POS = mylist.add_position()
POS.centre = A  # entry coordinates
POS.distance = 1.  # coil distance (mm)
POS.didt = tint * 1e6  # TMS intensity (A/s)
POS.pos_ydir = B

k.open_in_gmsh = False
k.map_to_vol = True
k.map_to_MNI = True

run_simnibs(k)
Beispiel #9
0
import simnibs
from simnibs import sim_struct

### General Infoarmation
S = sim_struct.SESSION()
S.fnamehead = 'ernie.msh'  # head mesh
S.pathfem = 'tms_hand'  # Directory for the simulation

## Define the TMS simulation
tms = S.add_tmslist()
tms.fnamecoil = 'Magstim_70mm_Fig8.nii.gz'  # Choose a coil from the ccd-files folder

# Define the coil position
pos = tms.add_position()
# Place coil over the hand knob
# Here, the hand knob is defined in MNI coordinates (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2034289/)
# And transformed to subject coordinates
# We can use positions in the cortex. SimNIBS will automatically project them to the skin surface
# and add the specified distance
pos.centre = simnibs.mni2subject_coords([-37, -21, 58], 'm2m_ernie')
# Point the coil handle posteriorly, we just add 10 mm to the original M1 y coordinate
pos.pos_ydir = simnibs.mni2subject_coords([-37, -21 - 10, 58], 'm2m_ernie')
pos.distance = 4  #  4 mm distance from coil surface to head surface

# Run Simulation
simnibs.run_simnibs(S)