EFMouse: 1x1 montage

EFMouse is a Matlab tool for electric field modelling in the mouse brain.
This notebook reproduces results for the 1x1 montage in:
Sanchez-Romero R., Akyuz, S., & Krekelberg, B. (2024). EFMouse: a Matlab toolbox to model electric fields in the mouse brain. bioRxiv. https://doi.org/10.1101/2024.07.25.605227
The notebook is also an introductory tutorial to simulate other montages.
(Developed by Ruben Sanchez-Romero and Bart Krekelberg,
Rutgers-Newark, Center for Molecular and Behavioral Neuroscience,
for support open an issue in https://github.com/klabhub/EFMouse/issues)
Table of Contents

Introduction

EFMouse combines several elements from previous work:
Key new functionality includes:
For details see Sanchez-Romero et al., (2024) and EFMouse.m Matlab code.

Typical workflow

The typical workflow to generate a model consists of several stages

Stage 0: Initialize

We start by setting up the basic parameters of the EFMouse object:
o = EFMouse; % Create a default empty object of the class EFMouse
o.dir = '/Users/rubensanchez/desktop/EFMouse/1x1Montage'; % Results and the object (1x1.mat) will be saved here.
o.ID = '1x1'; % A name/tag for this simulation.
o.log = true; % Create a log file.
Note: The log file is created but doesn't update when running a simulation from a notebook (like here). It will properly update when running EFMouse directly from the Matlab command line.
initialize() creates the folder to store the results. With overwrite=true, anything in this folder will be deleted.
o.initialize(overwrite=true);
The initialized EFMouse object contains the default mouse mesh (without stimulation electrodes). Let's visualize it.
plotMesh(o)
The mesh is pretty dense, so it will look like a black blob. The olfactory bulbs are visible on the top. In a regular figure window, you can use the Matlab figure tools to rotate or zoom. (You can also adapt the plotMesh() function in EFMouse.m to modifiy the figure directly.)

Stage 1: Create electrodes and a craniotomy

Now we define a 1x1 stimulation montage: 1 electrode on the anterior and 1 return electrode on the posterior targeting visual areas.
o.eTag = ["Anterior" "Posterior"];
% currents need to sum to 0. (In milliamps (mA) units.)
o.eCurrent = [0.2,-0.2];
% center coordinate of the electrode position (in mesh space)
o.eCenter = [-3.56,29.5,5.45;
-3.43,24.8,6.02]';
% radius of the electrodes (in mesh space units) (1 mesh unit ~ 1 mm)
o.eRadius = [0.71,0.67]
o = EF Mouse Model (label: 1x1) in directory /Users/rubensanchez/desktop/EFMouse/1x1Montage (stage=0).
Add a craniotomy:
% center coordinate of the craniotomy position (in mesh space)
o.cCenter = [-3.4236,27.1067,5]';
% radius of the creaniotomy (in mesh space units) (1 mesh unit ~ 1 mm)
o.cRadius = 1.5;
To add these to the model, we run the pipeline to stage 1. With show=true, this also opens a figure for inspection of the mesh:
o.run(targetStage=1,show=true)
Compute stage 1 - computeMesh EF Mouse Model (label: 1x1) in directory /Users/rubensanchez/desktop/EFMouse/1x1Montage (stage=0). -Creating craniotomy- Craniotomy: touching tissue: gray: num elements = 6884 csf: num elements = 6083 bone: num elements = 8247 skin: num elements = 1551 Craniotomy only removes skin and bone. -Creating 2 electrodes- Electrode: Anterior: touching tissue: skin: num elements = 39 Creating electrode Anterior in max touched tissue: skin. Electrode: Posterior: touching tissue: skin: num elements = 46 Creating electrode Posterior in max touched tissue: skin.
Stage 1 complete - 57.9925 seconds
This mesh now shows the electrodes in red and blue (return), for the craniotomy, skin removal is shown in green and skull removal shown in yellow.

Stage 2: Find the electrode boundaries and add to the mesh

In this stage, EFMouse searches for the edges of the electrodes as this is where the current flows into the model. The boundary conditions of the Laplace equation are set here.
o.run(targetStage=2)
Compute stage 2 - computeBoundary Electrode Area ______________ Anterior 0.78309 Posterior 0.67532 Stage 2 complete - 64.5896 seconds

Stage 3: export the mesh and model

Up until this stage, all changes were internal to the Matlab object (saved in 1x1.mat), now we export files that the FEM solver getDP can read. The .msh file contains information on the mesh (all the nodes, elements, labels and boundaries), and the .pro file tells getDP which partial differential equations (PDE) model it needs to solve in this mesh.
o.run(targetStage=3)
Compute stage 3 - export data ----Starting saveMesh...29-Jan-2025 20:37:03 ----saveMesh elapsed time: 32.8988 seconds ----Starting savePro...29-Jan-2025 20:37:36 ----savePro elapsed time: 0.0752 seconds Stage 3 complete - 54.5425 seconds
For troubleshooting, have a look at the .pro file in the project folder; it contains all the model specifications, including conductivity (in siemens per meter S/m) for the different tissues/elements.
type(file(o,"PRO"))
/* .pro file created by EFMouse on 29-Jan-2025 20:37:36 ID: 1x1 Dir: /Users/rubensanchez/desktop/EFMouse/1x1Montage */ Group { gray = Region[1]; csf = Region[2]; bone = Region[3]; skin = Region[4]; eye = Region[5]; craniotomy = Region[6]; skinremoved = Region[7]; Anterior = Region[8]; Posterior = Region[9]; boundaryAnterior = Region[10]; boundaryPosterior = Region[11]; DomainC = Region[{gray,csf,bone,skin,eye,craniotomy,skinremoved,Anterior,Posterior}]; AllDomain = Region[{gray,csf,bone,skin,eye,craniotomy,skinremoved,Anterior,Posterior,boundaryAnterior,boundaryPosterior}]; } Function { sigma[gray] = 0.275; sigma[csf] = 1.654; sigma[bone] = 0.01; sigma[skin] = 0.465; sigma[eye] = 0.5; sigma[craniotomy] = 1.654; sigma[skinremoved] = 2.5e-14; sigma[Anterior] = 5.9e+07; sigma[Posterior] = 5.9e+07; du_dn1[] = 255.398816; du_dn2[] = -296.157649; } Jacobian { { Name Vol ; Case { { Region All ; Jacobian Vol ; } } } { Name Sur ; Case { { Region All ; Jacobian Sur ; } } } } Integration { { Name GradGrad ; Case { {Type Gauss ; Case { { GeoElement Triangle ; NumberOfPoints 3 ; } { GeoElement Quadrangle ; NumberOfPoints 4 ; } { GeoElement Tetrahedron ; NumberOfPoints 4 ; } { GeoElement Hexahedron ; NumberOfPoints 6 ; } { GeoElement Prism ; NumberOfPoints 9 ; } } } } } } FunctionSpace { { Name Hgrad_v_Ele; Type Form0; BasisFunction { // v = v s , for all nodes // n n { Name sn; NameOfCoef vn; Function BF_Node; Support AllDomain; Entity NodesOf[ All ]; } } } } Formulation { { Name Electrostatics_v; Type FemEquation; Quantity { { Name v; Type Local; NameOfSpace Hgrad_v_Ele; } } Equation { Galerkin { [ sigma[] * Dof{d v} , {d v} ]; In DomainC; Jacobian Vol; Integration GradGrad; } Galerkin{ [ -du_dn1[], {v} ]; In boundaryAnterior ; Jacobian Sur; Integration GradGrad;} Galerkin{ [ -du_dn2[], {v} ]; In boundaryPosterior ; Jacobian Sur; Integration GradGrad;} } } } Resolution { { Name EleSta_v; System { { Name Sys_Ele; NameOfFormulation Electrostatics_v; } } Operation { Generate[Sys_Ele]; Solve[Sys_Ele]; SaveSolution[Sys_Ele]; } } } PostProcessing { { Name EleSta_v; NameOfFormulation Electrostatics_v; Quantity { { Name v; Value { Local { [ {v} ]; In AllDomain; Jacobian Vol; } } } { Name e; Value { Local { [ -{d v} ]; In AllDomain; Jacobian Vol; } } } } } } PostOperation { { Name Map; NameOfPostProcessing EleSta_v; Operation { Print [ v, OnElementsOf DomainC, File "/Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1_v.pos", Format NodeTable ]; Print [ e, OnElementsOf DomainC, Smoothing, File "/Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1_e.pos", Format NodeTable ]; } } }
This file can be opened in the getDP gui to run it manually, but stage 4 runs it for you.

Stage 4: run getDP

It will take getDP between 15 and 30 minutes to compute the solutions of the Laplace equation (on 2024 Mac or Windows hardware). The results are saved in _e.pos and _v.pos files (in getDP format). In the object the results are saved as .field and .voltage.
o.run(targetStage=4,show=false);
Compute stage 4 - computeField Info : Running '/Users/rubensanchez/Desktop/roast/EFmouse_class/EFMouse/lib/getdp-3.2.0/bin/getdpMac /Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1.pro -solve EleSta_v -msh /Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1.msh -pos Map' [GetDP 3.2.0, 1 node, max. 1 thread] Info : Started (Wed Jan 29 20:48:20 2025, Wall = 0.056675s, CPU = 0.050258s, Mem = 5.33594Mb) Info : Initializing Gmsh [1m[31mError : Unknown number option 'General.NativeFileChooser'[0m Info : Loading problem definition '/Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1.pro' Info : Selected Resolution 'EleSta_v' Info : Loading Geometric data '/Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1.msh' Info : System 'Sys_Ele' : Real [34mP r e - P r o c e s s i n g . . .[0m Info : Treatment Formulation 'Electrostatics_v' 0% : Pre-processing 10% : Pre-processing 20% : Pre-processing 30% : Pre-processing 40% : Pre-processing 50% : Pre-processing 60% : Pre-processing 70% : Pre-processing 80% : Pre-processing 90% : Pre-processing Info : System 1/1: 1027341 Dofs Info : (Wall = 41.8548s, CPU = 34.0105s, Mem = 683.652Mb) [34mE n d P r e - P r o c e s s i n g[0m [34mP r o c e s s i n g . . .[0m Info : Generate[Sys_Ele] 0% : Processing (Generate) 10% : Processing (Generate) 20% : Processing (Generate) 30% : Processing (Generate) 40% : Processing (Generate) 50% : Processing (Generate) 60% : Processing (Generate) 70% : Processing (Generate) 80% : Processing (Generate) 90% : Processing (Generate) Info : Solve[Sys_Ele] Info : N: 1027341 - preonly lu mumps Info : SaveSolution[Sys_Ele] Info : (Wall = 1701.34s, CPU = 2046.29s, Mem = 7523.01Mb) [34mE n d P r o c e s s i n g[0m [34mP o s t - P r o c e s s i n g . . .[0m Info : NameOfSystem not set in PostProcessing: selected 'Sys_Ele' Info : Selected PostProcessing 'EleSta_v' Info : Selected Mesh '/Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1.msh' Info : PostOperation 1/2 > '/Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1_v.pos' 0% : Post-processing (Compute) 10% : Post-processing (Compute) 20% : Post-processing (Compute) 30% : Post-processing (Compute) 40% : Post-processing (Compute) 50% : Post-processing (Compute) 60% : Post-processing (Compute) 70% : Post-processing (Compute) 80% : Post-processing (Compute) 90% : Post-processing (Compute) Info : PostOperation 2/2 > '/Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1_e.pos' 0% : Post-processing (Generate) 10% : Post-processing (Generate) 20% : Post-processing (Generate) 30% : Post-processing (Generate) 40% : Post-processing (Generate) 50% : Post-processing (Generate) 60% : Post-processing (Generate) 70% : Post-processing (Generate) 80% : Post-processing (Generate) 90% : Post-processing (Generate) 0% : Post-processing (Compute) Info : Smoothing (phase 1) Info : Smoothing (phase 2) Info : (Wall = 1985.36s, CPU = 2243.16s, Mem = 7523.01Mb) [34mE n d P o s t - P r o c e s s i n g[0m Info : Stopped (Wed Jan 29 21:21:26 2025, Wall = 1986.86s, CPU = 2243.59s, Mem = 7523.01Mb) Stage 4 complete - 2057.4535 seconds
Use the plotEf() function to visualize the electric field in the X direction, and then the electric field magnitude.
plotEf(o,type='eX',percentile=98, tissue='gray');
----Starting plotEf...29-Jan-2025 22:31:45
----plotEf elapsed time: 5.4188 seconds
plotEf(o,type='eMag',percentile=98,tissue='gray')
----Starting plotEf...29-Jan-2025 22:31:50
----plotEf elapsed time: 2.4874 seconds

Tissue Based Analysis

In general, we focus on the brain, but if necessary, we can compute electric field estimates for the rest of the mouse body for a full characterization of the anatomical effects of the electrical stimulation protocol. See Sanchez-Romero et al., (2024) for a full description of the electric field metrics.
analyzeTissue(o)
----Starting analyzeTissue...29-Jan-2025 22:32:05 Electric field summary statistics for gray tissue mean median std min max _______ ________ ______ _______ ______ eX 0.79299 0.67688 1.6794 -11.718 26.464 eY -1.6743 -1.3555 2.2744 -31.965 19.517 eZ -0.7507 -0.39775 2.1183 -40.614 12.768 eMag 2.8329 1.9901 2.907 0.16347 46.878 [Homogeneity ranges from 0 to 1] Homogeneity = 0.7158, for ef_norm_mean: (0.311 -0.591 -0.258) Electric field summary statistics for csf tissue mean median std min max _______ ________ ______ _______ ______ eX 1.0715 0.63196 8.8472 -146.11 156.66 eY -3.5474 -1.4987 6.7035 -116.41 23.956 eZ -2.1805 -0.43898 15.95 -320.87 220.04 eMag 8.656 3.5688 17.922 0.16347 375.57 [Homogeneity ranges from 0 to 1] Homogeneity = 0.5590, for ef_norm_mean: (0.233 -0.437 -0.260) Electric field summary statistics for bone tissue mean median std min max ________ ___________ ______ __________ ______ eX 0.38235 -8.4878e-05 7.4283 -246.54 228.78 eY -1.7159 -0.00010046 6.5135 -291.83 53.14 eZ -0.81987 0.00018048 13.909 -469.68 363.73 eMag 4.5893 0.32701 16.546 3.8421e-07 549.63 [Homogeneity ranges from 0 to 1] Homogeneity = 0.2119, for ef_norm_mean: (-0.119 -0.099 0.144) Electric field summary statistics for skin tissue mean median std min max ________ ___________ ______ __________ ______ eX 0.070676 -0.00014692 3.4757 -164.39 204.77 eY -0.35876 -1.6779e-05 3.5846 -291.83 135.88 eZ -0.11102 0.00051892 5.7609 -351.37 268.62 eMag 1.1142 0.027176 7.5513 1.8066e-07 393.33 [Homogeneity ranges from 0 to 1] Homogeneity = 0.3722, for ef_norm_mean: (-0.237 -0.076 0.277) Electric field summary statistics for eye tissue mean median std min max _______ ________ ________ ________ ________ eX 0.32421 0.31987 0.098822 0.11803 0.70714 eY 0.18109 -0.32307 0.63697 -0.53708 1.4884 eZ -1.065 -0.42903 0.78516 -2.723 -0.24954 eMag 1.3183 0.73095 0.7522 0.51214 3.0326 [Homogeneity ranges from 0 to 1] Homogeneity = 0.8006, for ef_norm_mean: (0.345 -0.142 -0.708) Electric field summary statistics for craniotomy tissue mean median std min max ________ _______ ______ _______ ______ eX 2.1583 2.4491 15.216 -90.646 106.97 eY -20.948 -16.524 21.146 -243.81 21.396 eZ 0.036908 0.37678 27.394 -185.12 235.45 eMag 27.737 18.292 33.214 5.6737 330.1 [Homogeneity ranges from 0 to 1] Homogeneity = 0.8593, for ef_norm_mean: (0.107 -0.851 0.057) Electric field summary statistics for skinremoved tissue mean median std min max _______ _______ ______ _______ ______ eX -1.1064 0.85367 33.668 -110.51 118.73 eY -50.387 -40.131 36 -227 -10.55 eZ 9.5068 5.1237 62.022 -211.26 246.39 eMag 75.225 59.257 56.943 14.853 330.1 [Homogeneity ranges from 0 to 1] Homogeneity = 0.7491, for ef_norm_mean: (-0.006 -0.737 0.132)

ROI Analysis

Now that we have the field estimates for each node in the mesh, we can do an ROI based analysis. For instance, a box ROI.
For the relative focality the reference area is the rest of the gray tissue.
roi.shape = 'box';
roi.dim = [[-4.0087 -2.56];[26.4022 27.64];[3 4]]';% Define the limits of the box ROI (x,y,z)(in mesh space units) (1 mesh unit ~ 1 mm)
summary = analyzeRoi(o,roi,plot=true,foc_percentile_max=99.9,foc_threshold=75); % Define values for relative focality metric.
----Starting analyzeRoi...29-Jan-2025 22:32:39 Electric field summary statistics for a box roi in gray mean median std min max _________ _______ ______ _______ _______ eX 2.5123 2.5692 1.1623 -1.4944 5.4232 eY -8.5358 -7.9802 3.063 -16.525 -2.7663 eZ -0.062983 0.44015 2.6286 -9.1839 4.856 eMag 9.4239 8.6681 2.8276 5.3249 18.619 [Relative focality ranges from 0 to 1] Relative focality = 0.9880, with 161805 reference nodes (cutoff: eMag > 75.00% of the target area max (99.90th percentile)) [Homogeneity ranges from 0 to 1] Homogeneity = 0.9392, for ef_norm_mean: (0.296 -0.891 0.023)
% Rotate and zoom to view the (purple) box ROI underneath the craniotomy
xlim([-3.31 1.13])
ylim([26.3 36.1])
zlim([2.31 4.98])
view([62.61 27.62])

For comparison, define an homologous box ROI but in the right hemisphere
roi_control.shape = 'box';
roi_control.dim = [[2.56 4.0087];[26.4022 27.64];[3 4]]';% Define the limits of the box ROI (in mesh space units)
summary = analyzeRoi(o,roi_control,plot=true,foc_percentile_max=99.9,foc_threshold=75);
----Starting analyzeRoi...29-Jan-2025 22:32:47 Electric field summary statistics for a box roi in gray mean median std min max ________ ________ _______ ________ _______ eX 0.20141 0.27985 0.29016 -0.64429 0.7175 eY -1.6552 -1.6222 0.27954 -2.4277 -1.0444 eZ -0.15023 -0.15194 0.11007 -0.4589 0.17793 eMag 1.7029 1.6824 0.27753 1.1081 2.4321 [Relative focality ranges from 0 to 1] Relative focality = 0.4278, with 161865 reference nodes (cutoff: eMag > 75.00% of the target area max (99.90th percentile)) [Homogeneity ranges from 0 to 1] Homogeneity = 0.9823, for ef_norm_mean: (0.111 -0.971 -0.095)
% Rotate and zoom to view the (purple) box ROI underneath the craniotomy
xlim([-3.31 1.13])
ylim([26.3 36.1])
zlim([2.31 4.98])
view([62.61 27.62])

Stage 5: Volumetric Analysis

The mesh coordinates are not particularly intuitive, and you may want to estimate electric fields in specific brain areas (as defined in an atlas). EFMouse does this in reference to the Allen Mouse Brain Atlas.
To use this, we first have to map the mesh-based results to the Allen Atlas. This is Stage 5 of the pipeline. This stage first exports the mesh-based results to a volume (using linear interpolation) and then uses the FLIRT tool in FSL to transform this volume to the coordinates of the Allen Atlas. Note that the alignment between the Digimouse mesh and the Allen Atlas is not perfect because they are based on different imaging modalities (and different mouse strains). (See Sanchez-Romero et al., (2014), for more details.)
This will fail if FSL is not installed.
o.run(targetStage=5,startStage=5)
Compute stage 5 - computeVoxelSpace ----Starting computeVoxelSpace...29-Jan-2025 22:35:54 ----Exporting to NIFTI volumes ---/Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1_efm.nii.gz created ---/Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1_efX.nii.gz created ---/Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1_efY.nii.gz created ---/Users/rubensanchez/desktop/EFMouse/1x1Montage/1x1_efZ.nii.gz created ----computeVoxelSpace elapsed time: 41.8426 seconds

Atlas Based Analysis

Once stage 5 has completed we can query electric fields based on a region that is defined in the Allen Atlas. For instance: 'Visual areas' for the left hemisphere.
For the relative focality the reference area is the rest of the Allen atlas "Isocortex".
T = analyzeAtlas(o,"Visual areas",hemisphere="left",foc_threshold=75,foc_percentile_max=99.9,foc_reference='Isocortex');
----Starting analyzeAtlas...29-Jan-2025 22:37:34 Area: Visual areas (1.0% of brain) , hemisphere left mean median std min max _______ _______ ______ _________ ______ eX 4.7816 3.8599 4.6812 -5.4848 23.523 eY -10.723 -10.354 5.2165 -28.129 3.3482 eZ -3.4174 -2.1581 5.6399 -31.189 10.11 eMag 13.909 12.969 6.1341 0.0061045 36.793 [Relative focality ranges from 0 to 1] Relative focality = 0.9988, with 92410 reference voxels (cutoff: eMag > 75.00% of the target area max (99.90th percentile)) [Homogeneity ranges from 0 to 1] Homogeneity = 0.8764, for ef_norm_mean: (0.342 -0.787 -0.176) ----analyzeAtlas elapsed time: 3.2990 seconds
For comparison, we can query results for the right hemisphere, which is contra-lateral from the targeted area.
T = analyzeAtlas(o,"Visual areas",hemisphere="right",foc_threshold=75,foc_percentile_max=99.9,foc_reference='Isocortex');
----Starting analyzeAtlas...29-Jan-2025 22:37:37 Area: Visual areas (1.0% of brain) , hemisphere right mean median std min max __________ _________ _______ _________ _______ eX 0.51646 0.37269 0.48088 -0.60438 2.2759 eY -1.9512 -2.1449 0.83912 -3.5042 0 eZ -0.0027768 -0.063365 0.27453 -0.76167 0.81006 eMag 2.0683 2.2373 0.89994 0.0022396 3.5414 [Relative focality ranges from 0 to 1] Relative focality = 0.5179, with 92457 reference voxels (cutoff: eMag > 75.00% of the target area max (99.90th percentile)) [Homogeneity ranges from 0 to 1] Homogeneity = 0.9763, for ef_norm_mean: (0.241 -0.946 -0.002) ----analyzeAtlas elapsed time: 2.8087 seconds

Tips and Tricks

o = EFMouse(dir='/Users/rubensanchez/desktop/EFMouse/1x1Montage',ID='1x1')