# File Formats in SimNIBS¶

SimNIBS’ head models are meshes (.msh files). This means that the head head is represented as a set of Nodes and Elements.

• The Nodes are points located in the 3-dimensional volume.

• The Elements are triangles and tetrahedra. They are defined using 3 nodes (triangles) or 4 nodes (tetrahedra).

This type of format is highly advantageous for Finite Element (FEM) calculations, especially for complex geometries such as the human head.

Head Meshes are stored in binary gmsh version 2 format, as described in the Gmsh documentation. SimNIBS can read arbitrary mesh files. But it can’t write files with elements other then first order triangles and tetrahedra.

SimNIBS offers the Python simnibs.msh.read_msh() function and the MATLAB function mesh_load_gmsh4 to read .msh files.

## Simulation Results¶

By default, Simulation results are also stored in Gmsh format. There are 2 types of fields used in SimNIBS:

• NodeData is defined at each nodes. By default, only the electric potential “v” is stored as NodeData

• ElementData is defined for each element. This is the format of choice for the electric field, current density and their respective norms.

The choice of format for each field is due to how the Finite Element Method works. After the FEM calculations, we obtain values of “v” at each node. To obtain the electric field and the current density, we take the gradient of the potential. However, the gradient operation is defined element-wise, and not node-wise.

Together with the .msh files, we often also save .opt files to facilitate visualization.

## Surface Fields¶

When fields are mapped to the middle gray matter surface, either on the subject or on the FsAverage, it saves results as a FreeSurfer .curv file, which contains values for each point in the surface. SimNIBS has the mesh_load_fsresults MATLAB function and the simnibs.msh.read_curv() Python function to load this kind of file.

The surfaces themselves are stored in different places depend on how the head model was created:

• Subject surfaces: m2m_subID/segment/cat/surf/

• FsAverage surfaces: SIMNIBSDIR/resources/spm12/toolbox/cat12/templates_surfaces/

• Functions:

• Python: simnibs.msh.read_gifti_surface()

• Subject surfaces: fs_subID/surf/

• FsAverage surfaces: \$FREESURFER_HOME/subjects/fsaverage/surf/

• format: FreeSurfer surface format

• Functions:

• Python: simnibs.msh.read_freesurfer_surface()