 # SiMRX - A Simulation toolbox for MRX

SiMRX is a MRX simulation toolbox written in MATLAB for simulation of realistic 2D and 3D Magnetorelaxometry (MRX) setups, including coils, sensors and activation patterns. MRX is a new modality that uses magnetic nanoparticles (MNP) as contrast agent and shows promising results in medical applications, e.g. cancer treatment. Its basic principles were outlined in [Baumgarten et al., 2008], further elaborated in [Liebl et al., 2014], transferred into a rigorous mathematical model and analyzed in [Föcke et al., 2018]. SiMRX is available at https://gitlab.com/foecke/SiMRX/.

## Authors

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

Many new and experimental treatment methods in medical applications use magnetic nanoparticles as a contrast agent. These particles allow for multiple different approaches (see [Hiergeist et al., 1999, Alexiou et al., 2011]), however for the named methods the exact knowledge about the particle distribution is crucial. Here, Magnetorelaxometry (MRX) can be used to determine the amount of particles in a region of interest as shown in [Baumgarten et al., 2008, Liebl et al., 2014]. Based on this approach an imaging technique called Magnetorelaxometry Imaging (MRXI) has been proposed.

The SiMRX toolbox provides a set of tools to model and simulate such an MRX system. It is based on the mathematical model developed in [Föcke et al., 2018].

### 1.1 Model

This following subsection (including notation) is part of [Föcke et al., 2018], which, for interested readers, provides an in depth look in the analysis of the following operator. The magnetic field in induced by a coil is given by

 Bcoilα:Ω→R3,w↦ϑLα∫0φ′α(s)×(w−φα(s)|w−φα(s)|3)ds, (1)

where is the length of the coil. The magnetization of the magnetic nanoparticles (MNP) after the reorientation process in is described by

 mα:Ω→R3,w↦13Bcoilα(w)c(w), (2)

where is the desired particle distribution. The particle induced magnetic response from particles in measured by a sensor is modeled by

 Bmeasα:Ω×Σ →R (w,σ) (3)

In the end we receive the following forward operator for a coil :

 Kα:L2(Ω)→L2(Σ),c↦⎡⎢⎣σ↦∫ΩBmeasα(w,σ) c(w)d3w⎤⎥⎦. (4)

### 1.2 Discretization

First we consider the 3D case: Here the conductor coil is approximated by a set list of segments, with starting points and ending points for the -th segment respectively. Then the magnetic field in is [Hanson and Hirshman, 2002]:

 Bcoilα,k:Ω →R3 w ↦ϑ|ak−w|+|bk−w||ak−w||bk−w|(ak−w)×(bk−w)|ak−w||bk−w|+(ak−w)⋅(bk−w). (5)

For the MNP response equation (3) still holds in the discrete case.

In the 2D case a coil simplification leads to the usage of variants of (3) for both coil and dipole response (see [Föcke et al., 2018, section 4.2]).

## 2 Structure

The SiMRX toolbox is a modular toolkit that has separate functions which are necessary for a successful simulation of an MRX experiment. SiMRX is capable of simulating synthetic or real setups and datasets.

The simulation tool runs a sequence of modular functions that subsequently handle the creation of a voxel grid, the calculation of the coil activation fields and the data acquisition at the sensors. See subsection 3.1 for a detailed description of the simulation step and relate to Figure 1 for an illustration of the simulation process.

For the simulation of an MRX experiment a setup and config file are required. The setup file includes information about the number of dimensions, coil position and shape (and, if necessary, orientation), sensor position and orientation, as well as intervals that define the region of interest. The config file includes information about the resolution of the phantom within the region of interest and a coil activation pattern. Both files are forwarded to the simulation script, that return a matrix representation of the given setup and configuration. Detailed information on the creation of setup and config file can be found in subsection 3.3.

Furthermore SiMRX provides useful tools that visualize MRX setups and internal states (subsection 3.2), and includes a tool for the creation of phantoms (subsection 3.4).

## 3 Features Figure 1: Schematics of the system matrix creation workflow. Variables are marked with a rounded corner box, functions are marked with a gray box. The variable usage is color coded: green (dashed) as input and red (solid) as output argument.

The SiMRX toolbox is separated in the following submodules (each in its own subfolder):

•  ./simulation ./visualization ./configuration ./phantom

We give a short overview of each module in the upcoming subsections. The syntax to use the specified functions is found in a help section at the beginning of each file. We recommend the MATLAB help function (F1) for more information about features and syntax of any module/function that comes with SiMRX .

### 3.1 Simulation

The simulation module is the core element of the toolbox. All necessary files can be found in the subfolder ./simulation. The main script is provided by the file createSystemMatrix.m. It processes a given MRX setup and a coil configuration into a linear operator, namely a matrix A. It requires a valid setup file that provides dimension information, region of interest, coil position and orientation, as well as sensor position and orientation. Furthermore voxel/pixel resolution within the region of interest and coil activation schemes are provided by a config file. Internally createSystemMatrix.m calls the functions createSystemMatrixRaw.m and subsequently applyCoilSequence.m. The internal processes, variables and function arguments are illustrated in Figure 1.

At first, createSystemMatrixRaw.m calls createVoxelGrid.m, which creates a valid voxelGrid. This voxel grid combines the desired resolution (config.res) with the demanded region of interest (setup.roi). Then createMagneticFields2D.m and createMagneticFields3D.m, respectively, are called to apply a uniform basic current to each given coil (setup.coils). The magnetic fields induced by theses coils are derived on the provided voxelgrid and are stored for each coil individually. Finally createDipoleFields.m translates the fields present on the voxel grid into a magnetization. Then it derives the resulting magnetic response, which is acquired by the sensors (setup.sensors), for each coil separately in a temporary system matrix ARaw. The set of operators ARaw is finally returned by createSystemMatrixRaw.m.

To this point only a uniform coil activation current is used. Due to the linearity of this forward propagation, we can apply an arbitrary coil activation sequence by using applyCoilSequence.m. This derives a linear combination of the temporary system matrices ARaw and creates a linear operator A.

It is possible to trigger each step separately, such that one can investigate the effects of different coil activations without repeating the whole simulation for each new activation pattern.

### 3.2 Visualization Figure 2: Visualization of a 2D and 3D MRX setup with schematics of coil induced magnetic fields. From left to right: visualization using visualizeSetup.m with 2D data, visualizeCoilActivation.m with 2D data, visualizeSetup.m with 3D data and finally visualizeCoilActivation.m with 3D data.

SiMRX provides tools to visualize the region of interest, coils and sensors. The function visualizeSetup.m combines named visualization functions to create a representation of a full MRX setup. We recommend the usage during the creation of a new MRX setup, since it uses only the setup file and does not require the simulation of a given setup.

Furthermore the function visualizeField.m provides a tool to visualize the magnetic fields induced by the activation coils. It uses the magnetic fields created by createMagneticFields2D.m and createMagneticFields3D.m, respectively, during the simulation process. A combination of visualizeSetup.m and visualizeField.m is given by visualizeCoilActivation.m. This function allows to scroll through each coil activation subsequently.

Figure 2 shows visualizeSetup.m and visualizeCoilActivation.m in a 2D and 3D example. The code of the 2D example is shown in Listing 1.

### 3.3 Configuration

This module provides a set of functions to create setup and config files.

#### 3.3.1 Setup file

setup files are structs in MATLAB. They hold the following fields

•  dim, roi, coils, and sensors.

SiMRX supports 2D and 3D systems, therefore setup.dim is either 2 or 3. The region of interest setup.roi is a struct with fields x, y and z, that holds boundary information in an array, e.g. setup.roi.x = [0,10]. Yet again setup.coils and setup.sensors are arrays of structs with fields:

•  coils(i).Position, sensors(i).Position, coils(i).Normal, sensors(i).Normal, coils(i).Segments,

where is the -th coil/sensor. For the fields Position and Normal

a three element vector is used.

To add new coil and sensor entries to the setup, the functions addCoilArray.m and addSensorArray.m can be used. In the current version both functions take two points, a normal and a number of repetition. Then addCoilArray.m adds a list of equidistant points, that represent the coil position, as well as the coil normal to the given setup (sensors analogously).

In the 3D case the coil wire is modeled by a list of points, which represent the coil shape. The function createCoilLoop.m creates a coil template. This template of a coil now has to be positioned at all coil positions. The function parseCoils.m receives a coil struct (with fields Position and Normal) and adds the Segments field in respect to the given coil template. Internally this uses the function relocateStructure.m that reorientates a given list of points.

In case a voxel grid is given, the corresponding region of interest can be determined using getROI.m. During the creation of a new setup the usage of visualizeSetup.m is recommended.

The script in Listing 1 can be used to create the setup file for the 2D system shown in Figure 2.

#### 3.3.2 Config file

config files are, similar to setup files, structs in MATLAB. They hold the fields

•  res, and coilSequence.

The simulated voxel resolution of the region of interest is given by a three element array and stored in res.

The coil activation sequence is stored in a matrix with one column for each coil. Each row represents the activation scheme where the entries refer to the respective coil activation current. The function addCoilSequence.m provides standard patterns and multiple other presets.

The script in Listing 2 can be used to create a config file for the 2D system shown in Figure 2.

The setup and config structs can be stored using saveSetup.m and saveConfig.m. These are stored using a custom .mrxsetup and .mrxcfg extension, that is based on the MATLAB internal .mat file format. Corresponding load functions (loadSetup.m and loadConfig.m) are available.

### 3.4 Phantom Figure 3: Selection of available 3D phantoms with a resolution of [50,50,15]. One phantom per row, each column represents a layer. Layers 1,2,14 and 15 are cut from illustration, due to clarity. Phantom names from top to bottom: ’P_2’,’shepplogan3d’,’tumor’ and ’fwhmdots_0.2’.

The function createPhantom.m provides multiple phantom options, including phantoms suited for reconstruction or resolution tests. createPhantom.m uses the function phantom3.m, which is a 3D reimplementation of the MATLAB given phantom function and able to generate 3D phantoms that are composed of multiple ellipses. For all available phantoms, please check the help section of createPhantom.m and phantom3.m. See Figure 3 for a small selection of the available phantoms.

## 4 Examples

The subfolder exmaple contains the 2D example, as of Listing 1 and 2, and a 3D example. These examples are guiding through most of the functionalities of the toolbox. Furthermore, if a function is executed without any arguments, many functions provide an internal example.

## 5 Remarks

This simulation toolbox does not guarantee its correctness and closeness to reality. SiMRX is not qualified for commercial usage.

## References

• [Alexiou et al., 2011] Alexiou, C., Tietze, R., Schreiber, E., Jurgons, R., Richter, H., Trahms, L., Rahn, H., Odenbach, S., and Lyer, S. (2011). Cancer therapy with drug loaded magnetic nanoparticles—magnetic drug targeting. Journal of Magnetism and Magnetic Materials, 323(10):1404–1407. Proceedings of 12th International Conference on Magnetic Fluid.
• [Baumgarten et al., 2008] Baumgarten, D., Liehr, M., Wiekhorst, F., Steinhoff, U., Münster, P., Miethe, P., Trahms, L., and Haueisen, J. (2008).

Magnetic nanoparticle imaging by means of minimum norm estimates from remanence measurements.

Medical & Biological Engineering & Computing, 46(12):1177.
• [Föcke et al., 2018] Föcke, J., Baumgarten, D., and Burger, M. (2018). The inverse problem of magnetorelaxometry imaging. Inverse Problems, 34(11):115008.
• [Hanson and Hirshman, 2002] Hanson, J. D. and Hirshman, S. P. (2002). Compact expressions for the biot–savart fields of a filamentary segment. Physics of Plasmas, 9(10):4410–4412.
• [Hiergeist et al., 1999] Hiergeist, R., Andrä, W., Buske, N., Hergt, R., Hilger, I., and Kaiser, W. (1999). Application of magnetite ferrofluids for hyperthermia. Journal of Magnetism and Magnetic Materials, 201(Issues 1-3):420–422.
• [Liebl et al., 2014] Liebl, M., Steinhoff, U., Wiekhorst, F., Haueisen, J., and Trahms, L. (2014). Quantitative imaging of magnetic nanoparticles by magnetorelaxometry with multiple excitation coils. Physics in Medicine & Biology, 59(21):6607.