Developing matRad, an Open-Source Dose Calculation and Optimization Toolkit for Radiation Therapy Planning
By Dr. Mark Bangert, German Cancer Research Center (DKFZ), Prof. Oliver Jäkel, German Cancer Research Center (DKFZ) and University of Heidelberg, Dr. Niklas Wahl, German Cancer Research Center (DKFZ), and Dr. Hans-Peter Wieser, Ludwig-Maximilian-Universität München (LMU Munich)
Radiotherapy, surgery, and chemotherapy constitute the three pillars of cancer treatment. One key element of radiotherapy is a heavily computer-aided process known as radiation treatment planning. In this process, oncologists and other clinicians rely on treatment planning software to accurately simulate the effect of radiation on patient tissue and to optimize the radiation dose so as to ensure tumor coverage while sparing surrounding tissue and organs.
Commercially developed radiotherapy treatment planning software is proprietary and closed-source, which limits its value to researchers working to advance treatment planning technology. As a result, many institutes and universities either invest significant effort in developing and maintaining their own software or use open-source packages, most of which focus on only a single step in treatment planning or a single radiation modality.
Our development team at the German Cancer Research Center (Deutsches Krebsforschungszentrum, or DKFZ) has created matRad1, an open-source, multimodality dose calculation and optimization toolkit for radiation treatment planning (Figure 1). Because matRad is written entirely in MATLAB®, researchers can easily modify the code to evaluate new algorithms. MATLAB excels at performing the many sparse matrix operations involved in treatment planning; as a result, matRad produces clinically accurate treatment plans as quickly and easily as its commercial counterparts.
Using matRad in a Treatment Planning Workflow
The matRad package includes MATLAB scripts, functions, and classes that span the entire treatment planning workflow, from setting treatment parameters and optimizing the plan to visualizing and evaluating the results. Researchers initiate each step in this workflow either in the matRad interface or from the MATLAB command line.
A researcher first imports computer tomography (CT) scan data from one of their own patients or from one of the anonymized patient cases provided by matRad. The software reads the data from MATLAB files or from files in the Digital Imaging and Communications in Medicine (DICOM) and DICOM-RT standard formats using functions from Image Processing Toolbox™.
Next, the researcher specifies parameters for the treatment plan and the radiotherapy machine to be used. These parameters could include the number of angles for the gantry (used to position the radiation source around the patient) and the treatment modality to be applied: intensity-modulated photons, scanned protons, or scanned carbon ions. The parameters can be set via the interface or by editing the matRad script (Figure 2).
matRad generates the beam geometry based on the parameters specified. The researcher then invokes the function for matRad dose calculation, which computes a matrix of the dose delivered to individual regions of the target tumor and to surrounding normal tissue for each radiation source element (Figure 3).
Finally, the researcher defines clinical objectives and constraints for the treatment. These might include the prescribed minimum dose to be delivered to the tumor and the maximum dose allowed to reach a nearby organ. After translating these clinical objectives and constraints into mathematical objectives and constraints, matRad runs an optimization solver to find the best dose distribution. For the optimization, matRad can be set up to use
fmincon from Optimization Toolbox™ or IPOPT, an open-source optimization software library written in C++ and imported into MATLAB as a MEX file. The results of the optimization can be reviewed in matRad in a variety of plots and visualizations (Figure 4).
Researchers can supplement or modify the algorithms used in matRad to explore ideas for improving treatment planning. In this way, matRad acts as a platform for prototyping and evaluating new approaches. In fact, matRad has been cited in more than 40 published peer-reviewed research papers in the past three years, and it is actively used in numerous research groups worldwide.
matRad in the Classroom
matRad is not only used in research; it is also used as a teaching tool. In a course at Heidelberg University, for example, students use matRad to learn about treatment planning for particle therapy, a relatively new modality. matRad plays an important role in letting students explore how different medical decisions, patient scenarios, and machine capabilities affect treatment planning. We packaged a standalone version of matRad with MATLAB Compiler™ for use by students who do not have MATLAB installed.
For high school students, the International Particle Physics Research Group offers a series of International Masterclasses. In a new Particle Therapy Masterclass, which we initiated in 2019 in collaboration with CERN and GSI Darmstadt, students learn about cancer treatment using radiotherapy and watch a demonstration of treatment planning using the standalone version of matRad.
Several factors led our team to develop matRad in MATLAB. First, MATLAB is widely used in the medical physics community and at research universities. In addition, MATLAB enables us to prototype new algorithms quickly. Its visualization capabilities support rapid debugging and offer perspectives on the results that open additional avenues to explore. MATLAB is well suited to the calculations that matRad performs with sparse matrices. The highly optimized linear algebra operations in MATLAB enable us to complete dose calculation and optimizations for realistic patient cases with run-times comparable to those of commercial treatment planning systems. Finally, developing matRad in MATLAB enabled us to make the software highly versatile: users can interact with the software via an interface or via the MATLAB command line, develop their own functions, and use matRad for both research and teaching.
Ongoing matRad Development
matRad remains under active development, and we regularly accept pull requests from researchers who have made improvements to some aspect of the code. For example, we recently worked with Dr. Edgardo Dörner at Pontificia Universidad Católica de Chile to incorporate a Monte Carlo photon dose calculation engine into matRad. The engine was written in C and imported into matRad as a MEX file.
In addition, we have started taking advantage of MATLAB object-oriented programming features. For example, matRad now uses an object-oriented framework for setting optimization objectives. Researchers who are interested in exploring new optimization objectives can derive their own class from our existing class, implement improvements, and then immediately try the new objective in a test treatment plan.
We are now using Parallel Computing Toolbox™ to execute matRad on multiple computing cores. For example, in uncertainty analyses we calculate multiple doses from different patient positions. Parallel Computing Toolbox enables us to rapidly set up and run this embarrassingly parallel task on a multicore workstation. We’ve also started running matRad on OpenStack to take advantage of larger pools of high-performance computing resources in the cloud.
matRad was designed as a research tool, and therefore cannot be used to treat real patients. The dose calculations it produces, however, closely match those produced by clinically approved treatment planning systems. This level of performance opens opportunities to use matRad as an independent tool for validating treatment plans generated by other software.
1 The current release is matRad ‘Blaise’ 2.10.0.