EFMouse: 1 x 1 with craniotomy (skin, bone csf) montage

EFMouse is a Matlab tool for electric field modelling in the mouse brain.
This notebook reproduces results for the 1 x 1 with craniotomy (skin, bone csf) montage in:
Sanchez-Romero R., Akyuz, S., & Krekelberg, B. (2025). EFMouse: a 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., (2025) and EFMouse.m Matlab code.

Typical workflow

The typical workflow to generate a model consists of several stages

Stage INIT: 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.ID = '1x1_craniotomy_csf-csf'; % A name/tag for this simulation.
o.dir = '/Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf'; % Results and the object (1x1_cran.mat) will be saved here.
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 the brain tissue. You can select different tissues to visualize.
plotMesh(o,tissue='gray')
The mesh is pretty dense, so it may 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 MESH: Create electrodes and a craniotomy

Now we define a 1x1 stimulation montage, targeting visual areas. The surface type is an electrode that is placed on top of the animal (simulating how gel would be placed on the skin).
o.addElectrode(tag = "Anode",current = 0.2,type="surface",shape="circle",center= [-3.5,30,6],radius=0.6, thickness=1);
o.addElectrode(tag = "Cathode",current = -0.2,type="surface",shape="circle",center= [-3.5,25,6],radius=0.6, thickness=1);
Add a craniotomy between the stimulation electrodes. Select the material replacing the space where skin and bone were removed. Here, we simulate csf flowing into the space of removed bone and skin.
o.addCraniotomy(tag = "left", center=[-3.5,27.5,6], radius=1.5, material=["csf","csf"]);
To update the model with the electrodes and the craniotomy, we run the pipeline to Stage.MESH. With show=true, this also opens a figure for inspection of the mesh:
o.run(targetStage=Stage.MESH,show=true)
Compute stage MESH EF Mouse Model (label: 1x1_craniotomy_csf-csf) in directory /Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf (stage=INIT). -Meshing 2 electrodes- Closest skin node is 0.7 away from the Anode electrode target position. Closest skin node is 0.1 away from the Cathode electrode target position. Found tet #2891752 at a distance of 0.46 from the target (label : skin) Replacing skin with csf Replacing bone with csf
Stage MESH complete - 9.3419 seconds
This mesh shows the electrodes in red (anode) and blue (cathode). For the craniotomy, the two tissue types that have been removed (skin and bone) are shown in cyan and magenta.

Stage EXPORT: export the mesh and model

Up until this stage, all changes were internal to the Matlab object (saved in 1x1_craniotomy_csf-csf.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=Stage.EXPORT)
Compute stage EXPORT ----Starting saveMesh...19-Jun-2025 12:29:29 ----saveMesh elapsed time: 11.4455 seconds ----Starting savePro...19-Jun-2025 12:29:40 ----savePro elapsed time: 0.0131 seconds Stage EXPORT complete - 8.0686 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 19-Jun-2025 12:29:40 ID: 1x1_craniotomy_csf-csf Dir: /Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf */ Group { gray = Region[1]; csf = Region[2]; bone = Region[3]; skin = Region[4]; eye = Region[5]; Anode = Region[6]; Cathode = Region[7]; leftskin = Region[8]; leftbone = Region[9]; boundaryAnode = Region[10]; boundaryCathode = Region[11]; DomainC = Region[{gray,csf,bone,skin,eye,Anode,Cathode,leftskin,leftbone}]; AllDomain = Region[{gray,csf,bone,skin,eye,Anode,Cathode,leftskin,leftbone,boundaryAnode,boundaryCathode}]; } Function { sigma[gray] = 0.275; sigma[csf] = 1.654; sigma[bone] = 0.01; sigma[skin] = 0.465; sigma[eye] = 0.5; sigma[Anode] = 0.3; sigma[Cathode] = 0.3; sigma[leftskin] = 1.654; sigma[leftbone] = 1.654; du_dnAnode[] = 69.185272; du_dnCathode[] = -85.163364; } 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_dnAnode[], {v} ]; In boundaryAnode ; Jacobian Sur; Integration GradGrad;} Galerkin{ [ -du_dnCathode[], {v} ]; In boundaryCathode ; 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_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf_v.pos", Format NodeTable ]; Print [ e, OnElementsOf DomainC, Smoothing, File "/Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf_e.pos", Format NodeTable ]; } } }
This file can be opened in the GetDP gui to run it manually, but Stage.GETDP runs it for you.

Stage GETDP: 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=Stage.GETDP,show=false);
Compute stage GETDP Info : Running '/Users/rubensanchez/Desktop/Klab/EFMouse/lib/getdp-3.5.0/bin/getdpMac /Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf.pro -solve EleSta_v -msh /Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf.msh -pos Map' [GetDP 3.5.0, 1 node, max. 1 thread] Info : Started (Thu Jun 19 12:31:22 2025, Wall = 0.00178003s, CPU = 0.013006s, Mem = 4.21875Mb) Info : Initializing Gmsh Info : Loading problem definition '/Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf.pro' Info : Selected Resolution 'EleSta_v' Info : Loading Geometric data '/Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf.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 50% : Pre-processing 60% : Pre-processing 70% : Pre-processing 80% : Pre-processing 90% : Pre-processing Info : System 1/1: 1027408 Dofs Info : (Wall = 14.3883s, CPU = 14.0807s, Mem = 683.574Mb) □[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) 50% : Processing (Generate) 60% : Processing (Generate) 70% : Processing (Generate) 80% : Processing (Generate) 90% : Processing (Generate) Info : Solve[Sys_Ele] Info : N: 1027408 - preonly lu mumps Info : 0 KSP Residual norm 6.114602800366e+01 Info : 1 KSP Residual norm 5.755318483149e-07 Info : SaveSolution[Sys_Ele] Info : (Wall = 163.335s, CPU = 683.364s, Mem = 8271.8Mb) □[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_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf.msh' Info : PostOperation 'Map' 1/2 > '/Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf_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) 50% : Post-processing (Compute) 60% : Post-processing (Compute) 70% : Post-processing (Compute) 80% : Post-processing (Compute) 90% : Post-processing (Compute) Info : PostOperation 'Map' 2/2 > '/Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf_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) 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 = 265.166s, CPU = 771.283s, Mem = 8271.8Mb) □[34mE n d P o s t - P r o c e s s i n g□[0m Info : Stopped (Thu Jun 19 12:35:48 2025, Wall = 266.092s, CPU = 771.359s, Mem = 8271.8Mb) Stage GETDP complete - 277.3919 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...19-Jun-2025 12:37:34
----plotEf elapsed time: 1.6996 seconds
plotEf(o,type='eMag',percentile=98,tissue='gray')
----Starting plotEf...19-Jun-2025 12:37:35
----plotEf elapsed time: 0.8340 seconds
We can also use plotEf() to visualize a brain slice perpendicular to a given axis. Here we show a frontal/coronal plane slice (perpendicular to the y axis) in the position of the anode electrode, a sagittal slice and a horizontal slice.
plotEf(o,type='eMag',percentile=98,tissue='gray',slice = true, slice_ax = "y",slice_pos = 27)
----Starting plotEf...19-Jun-2025 12:39:34
----plotEf elapsed time: 0.6844 seconds
plotEf(o,type='eMag',percentile=98,tissue='gray',slice = true, slice_ax = "x",slice_pos = -2)
----Starting plotEf...19-Jun-2025 12:39:35
----plotEf elapsed time: 0.4983 seconds
plotEf(o,type='eMag',percentile=98,tissue='gray',slice = true, slice_ax = "z",slice_pos = 3.5)
----Starting plotEf...19-Jun-2025 12:39:35
----plotEf elapsed time: 0.5264 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. leftbone refers to the bone area removed during the craniotomy. The label is defined by joining the craniotomy tag (see Stage MESH above) and the tissue removed: left + "bone": leftbone.
See Sanchez-Romero et al., (2025) for a full description of the electric field metrics.
summary = analyzeTissue(o,["skin" "gray" "leftbone"]);
----Starting analyzeTissue...19-Jun-2025 12:40:13 Electric field summary statistics for skin tissue mean median std min max ________ ___________ ______ __________ ______ eX 0.05453 -0.00012349 2.6469 -143.03 114.36 eY -0.32071 -1.5393e-05 2.9836 -202.54 114.48 eZ -0.10273 0.00043175 4.9004 -233.64 225.53 eMag 0.93864 0.022145 6.2576 1.5013e-07 272.12 [Homogeneity ranges from 0 to 1] Homogeneity = 0.3751, for ef_norm_mean: (-0.240 -0.079 0.278) Electric field summary statistics for gray tissue mean median std min max ________ ________ ______ _______ ______ eX 0.49306 0.48332 1.0155 -6.3304 15.103 eY -1.4267 -1.2246 1.4285 -20.129 9.6985 eZ -0.50246 -0.31236 1.3152 -21.784 9.7468 eMag 2.1307 1.6249 1.6711 0.14176 23.985 [Homogeneity ranges from 0 to 1] Homogeneity = 0.7449, for ef_norm_mean: (0.262 -0.655 -0.240) Electric field summary statistics for leftbone tissue mean median std min max ________ _______ ______ _______ ______ eX 1.563 1.1533 6.2044 -20.675 38.925 eY -19.606 -18.942 7.753 -73.843 6.2223 eZ -0.50833 1.092 11.4 -74.131 23.857 eMag 22.838 20.195 9.6892 10.764 83.467 [Homogeneity ranges from 0 to 1] Homogeneity = 0.8844, for ef_norm_mean: (0.054 -0.882 0.025)

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.
See Sanchez-Romero et al.(2025), for definitions of relative focality and homogeneity.
roi.shape = 'box';
roi.center = [-3.5,27.5 3.5];
roi.width = 2; % Left/Right
roi.length = 2; % Anterior/Posterior
roi.thickness =1; % Inferior/Superior
summary = analyzeRoi(o,roi,plot=true,foc_percentile_max=99.9,foc_threshold=40); % Define values for relative focality metric.
----Starting analyzeRoi...30-Jun-2025 12:06:30 Electric field summary statistics for a box roi in gray mean median std min max _______ _______ ______ _______ _______ eX 1.1825 1.2358 1.0992 -1.8348 4.4698 eY -4.3014 -4.1723 1.113 -8.3354 -1.7983 eZ -1.7785 -1.5527 1.4243 -7.7185 2.0486 eMag 5.1021 4.9182 1.2273 2.8349 10.049 [Relative focality ranges from 0 to 1] Relative focality = 0.9012, with 160508 reference nodes (cutoff: eMag > 40.00% of the target area max (99.90th percentile)) [Homogeneity ranges from 0 to 1] Homogeneity = 0.9451, for ef_norm_mean: (0.240 -0.844 -0.351)
% Rotate and zoom to view the (yellow) 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 analogous box ROI but in the right hemisphere
roiRight = roi;
roiRight.center(1) =-1* roi.center(1)
roiRight = struct with fields:
shape: 'box' center: [3.5000 27.5000 3.5000] width: 2 length: 2 thickness: 1
summary = analyzeRoi(o,roiRight,plot=true,foc_percentile_max=99.9,foc_threshold=40);
----Starting analyzeRoi...30-Jun-2025 12:06:32 Electric field summary statistics for a box roi in gray mean median std min max ________ ________ ________ ________ ________ eX 0.29218 0.31733 0.26026 -0.55805 0.9135 eY -1.3446 -1.3176 0.22369 -2.0414 -0.86765 eZ -0.15041 -0.16567 0.086943 -0.35584 0.13753 eMag 1.4112 1.3943 0.22269 0.91501 2.0499 [Relative focality ranges from 0 to 1] Relative focality = 0.0750, with 160925 reference nodes (cutoff: eMag > 40.00% of the target area max (99.90th percentile)) [Homogeneity ranges from 0 to 1] Homogeneity = 0.9805, for ef_norm_mean: (0.204 -0.952 -0.111)
% Rotate and zoom to view the (yellow) box ROI in the right hemisphere
xlim([-3.31 1.13])
ylim([26.3 36.1])
zlim([2.31 4.98])
view([62.61 27.62])

Stage ATLAS: Volumetric/Atlas 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 ATLAS 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. (2025), for more details.)
This will fail if FSL is not installed.
o.run(targetStage=Stage.ATLAS,startStage=Stage.ATLAS)
Compute stage ATLAS ----Starting computeVoxelSpace...19-Jun-2025 12:42:24 ----Exporting to NIFTI volumes ---/Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf_efm.nii.gz created ---/Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf_efX.nii.gz created ---/Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf_efY.nii.gz created ---/Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf/1x1_craniotomy_csf-csf_efZ.nii.gz created ----computeVoxelSpace elapsed time: 8.3796 seconds Stage ATLAS complete - 16.4904 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=40,foc_percentile_max=99.9,foc_reference='Isocortex');
----Starting analyzeAtlas...30-Jun-2025 12:08:41 Area: Visual areas (1.0% of brain) , hemisphere left mean median std min max _______ _______ ______ _________ ______ eX 2.0453 1.6364 2.5583 -4.0623 13.259 eY -6.496 -6.1716 3.0458 -19.208 2.1267 eZ -1.4094 -1.0461 3.1113 -16.888 8.0297 eMag 7.8739 7.1915 3.4893 0.0041007 20.831 [Relative focality ranges from 0 to 1] Relative focality = 0.9941, with 92410 reference voxels (cutoff: eMag > 40.00% of the target area max (99.90th percentile)) [Homogeneity ranges from 0 to 1] Homogeneity = 0.8894, for ef_norm_mean: (0.256 -0.838 -0.152) ----analyzeAtlas elapsed time: 0.1977 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=40,foc_percentile_max=99.9,foc_reference='Isocortex');
----Starting analyzeAtlas...30-Jun-2025 12:08:42 Area: Visual areas (1.0% of brain) , hemisphere right mean median std min max ________ _________ _______ _________ ______ eX 0.32005 0.21072 0.35303 -0.56728 1.6958 eY -1.6604 -1.8181 0.71333 -2.9166 0 eZ 0.011844 -0.040232 0.23604 -0.61151 0.7102 eMag 1.729 1.8691 0.74925 0.0018874 2.9267 [Relative focality ranges from 0 to 1] Relative focality = 0.1794, with 92457 reference voxels (cutoff: eMag > 40.00% of the target area max (99.90th percentile)) [Homogeneity ranges from 0 to 1] Homogeneity = 0.9784, for ef_norm_mean: (0.178 -0.962 0.008) ----analyzeAtlas elapsed time: 0.1677 seconds

Tips and Tricks

o = EFMouse(dir='/Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf',ID='1x1_craniotomy_csf-csf')
o = EF Mouse Model (label: 1x1_craniotomy_csf-csf) in directory /Users/rubensanchez/desktop/efmouse_sim/1x1_craniotomy_csf-csf (stage=ATLAS).