Code Structure

We designed TMMax to provide a comprehensive library that enables rapid simulations of multilayer optical thin-films, while also integrating a publicly accessible material database and implementing extensive functionalities to facilitate the evaluation and characterization of thin-film structures. As shown in figure, we structured TMMax into three main components: the nk_data module, which serves as a curated material database; the optical properties computation core, responsible for all intermediate calculations required by the TMM; and the thin-film analysis interface, which enables performance evaluation and characterization of multilayer structures. Since TMMax is written in JAX, these components adhere to functional programming principles. The design does not use classes or object-oriented structures; however, a user who prefers object-oriented design can easily encapsulate TMMax functions within their own classes.

../_images/code_structure_figure.png

Modular architecture of TMMax, structured into three main components to facilitate efficient multilayer thin-film simulations. The Material Database (top left) comprises a curated set of .npy files containing refractive index and extinction coefficient data stored in the nk data folder. The Optical Properties Calculation core (right) includes modular scripts for angle calculations, transfer matrix multiplications, Fresnel reflection or transmission, and material interpolation, among others, together performing all intermediate computations essential for the TMM. The Analysis section (bottom left) provides tools to evaluate the optical performance of thin-film stacks, including transmittance, reflectance, absorbance, and resulting color as functions of layer thickness.

Material Database

Dielectric materials used in thin-film designs are selected from a curated material database that contains refractive index and extinction coefficient data. These two optical data are obtained from the refractiveindex.info database of optical constants, which compiles data from numerous different scientific publications, carefully gathered from validated experimental studies and peer-reviewed publications to ensure optical accuracy across a wide spectral range. In addition, a reference file is available in the docs/database_info folder within TMMax GitHub repository, containing information for each material about the source publication and the measurement methods employed. Each material entry in the database is stored as a matrix in the .npy format with dimensions (3, N), where the first row contains wavelength values, and the second and third rows correspond to the refractive index and extinction coefficient values at those wavelengths, respectively. This storage format allows us to directly load data using JAX without any intermediate conversion, significantly facilitating the data loading process. Moreover, users can easily add new materials to the TMMax database. To support this, a Jupyter notebook in the examples folder provides step-by-step instructions on how to add materials using TMMax’s save_nk_data function. Users who wish to share their own materials can contribute by submitting a pull request to the TMMax GitHub repository.

Optical Properties Calculation

Optical properties of the thin-film, such as transmittance, reflectance, and absorbance, are calculated in this section. As shown in figure, this section contains eight different Python files that enable the implementation of the TMM specifically for coherent and incoherent thin-films. In TMMax, users simulate multilayer optical thin-films exclusively through the core TMM function implemented in the tmm.py module, while all other modules are specifically designed to handle intermediate computational processes required for an accurate and efficient execution of the TMM. To explain them sequentially, we calculate the angle between the light ray and the layer normal in each layer of a thin-film using the functions in angle.py. We use these angles together with the Fresnel equations implemented in fresnel.py within the reflect_transmit.py file to calculate the reflection and transmittance coefficients between layers, considering both s- and p-polarizations. While performing polarization-dependent calculations, conditional statements such as if, which are typically used when running code through the Python interpreter, are avoided. Instead, the jax.lax.cond function is employed to ensure compatibility with JIT compilation. This prevents interpreter-related bottlenecks after transformation and enables efficient, polarization-specific coefficient evaluation within the TMM function. Additionally, functions necessary to compute the normal wavevector, which is required to determine the optical phase accumulation within each layer, and functions to calculate the transmittance and reflectance ratios of thick incoherent layers are located in the wavevector.py file. Ultimately, to combine these and find the system matrix, multiplication of chain matrices is required, and this chain matrix multiplication code is implemented in cascaded_matmul.py using the jax.lax.scan function. In addition to the intermediate steps of TMM, helper functions for data preprocessing and visualization are also essential. The first of these involves loading and interpolating refractive index and extinction coefficient data from the material database, which is implemented in the data.py file. The second involves visualizing the layer-by-layer material structure of the thin-film and observing the distribution of the electric field intensity between layers; these are implemented in the plot.py file.

Analysis

The prediction of reflected color from multilayer optical thin-films under varying illumination conditions, along with the calculation of transmittance and reflectance sensitivities, is implemented within a single-file module. To observe the color of a multilayer thin-film, users can employ the functions within the analysis file, which leverage the Python-based ColorPy library [25] to perform accurate physical color calculations. Additionally, during fabrication, unavoidable variations occur from the target thicknesses in one or more layers of the multilayer structure, leading to changes in transmittance, reflectance, and consequently the resulting color of the thin-film. The analysis file implements functions that calculate how percentage deviations from these target thicknesses influence the film’s optical properties, enabling sensitivity analysis for transmittance, reflectance, and color.

References

[1]

Abelès, Florin. Recherches sur la propagation des ondes électromagnétiques sinusoïdales dans les milieux stratifiés - application aux couches minces. Ann. Phys., 12(5):596–640, 1950. URL: https://doi.org/10.1051/anphys/195012050596, doi:10.1051/anphys/195012050596.

[2]

Charalambos C Katsidis and Dimitrios I Siapkas. General transfer-matrix method for optical multilayer systems with coherent, partially coherent, and incoherent interference. Applied optics, 41(19):3978–3987, 2002.

[3]

H Angus Macleod and H Angus Macleod. Thin-film optical filters. CRC press, 2010.

[4]

Bernd Harbecke. Coherent and incoherent reflection and transmission of multilayer structures. Applied Physics B, 39(3):165–170, 1986.

[5]

Sergey A. Dyakov, Vladimir A. Tolmachev, Ekaterina V. Astrova, Sergey G. Tikhodeev, Viktor Yu. Timoshenko, and Tatiana S. Perova. Numerical methods for calculation of optical properties of layered structures. In Kamil A. Valiev and Alexander A. Orlikovsky, editors, International Conference on Micro- and Nano-Electronics 2009, volume 7521, 75210G. International Society for Optics and Photonics, SPIE, 2010. URL: https://doi.org/10.1117/12.862566, doi:10.1117/12.862566.

[6]

Rudi Santbergen, Arno H.M. Smets, and Miro Zeman. Optical model for multilayer structures with coherent, partly coherent and incoherent layers. Opt. Express, 21(S2):A262–A267, Mar 2013. URL: https://opg.optica.org/oe/abstract.cfm?URI=oe-21-102-A262, doi:10.1364/OE.21.00A262.

[7]

Emanuele Centurioni. Generalized matrix method for calculation of internal light energy flux in mixed coherent and incoherent multilayers. Appl. Opt., 44(35):7532–7539, Dec 2005. URL: https://opg.optica.org/ao/abstract.cfm?URI=ao-44-35-7532, doi:10.1364/AO.44.007532.

[8]

Yu Shi, Wei Li, Aaswath Raman, and Shanhui Fan. Optimization of multilayer optical films with a memetic algorithm and mixed integer programming. Acs Photonics, 5(3):684–691, 2017.

[9]

Steven J. Byrnes. Multilayer optical calculations. 2020. URL: https://arxiv.org/abs/1603.02720, arXiv:1603.02720.

[10]

Pavel Dmitriev. PyTMM: python implementation of the transfer matrix method for optical simulations. 2017. Archived on Zenodo; accessed 2025‑07‑14. URL: https://github.com/kitchenknif/PyTMM, doi:10.5281/zenodo.1063716.

[11]

Filip Dominec. Transfer_matrix_method: python implementation of the transfer matrix method. https://github.com/FilipDominec/transfer_matrix_method, 2017. Accessed: 2025-07-14.

[12]

James Bradbury, Roy Frostig, Peter Hawkins, Matthew James Johnson, Chris Leary, Dougal Maclaurin, George Necula, Adam Paszke, Jake VanderPlas, Skye Wanderman-Milne, and Qiao Zhang. JAX: composable transformations of Python+NumPy programs. 2018. URL: http://github.com/jax-ml/jax.

[13]

OpenXLA Team. XLA: Accelerated Linear Algebra Compiler for Machine Learning. https://github.com/openxla/xla, 2023. Accessed: 2025-07-13. URL: https://github.com/openxla/xla.

[14]

Kazufumi Nishida, Yasuaki Ito, and Koji Nakano. Accelerating the dynamic programming for the matrix chain product on the gpu. In 2011 Second International Conference on Networking and Computing, volume, 320–326. 2011. doi:10.1109/ICNC.2011.62.

[15]

Ravi S. Hegde. Accelerating optics design optimizations with deep learning. Optical Engineering, 58(6):065103, 2019. URL: https://doi.org/10.1117/1.OE.58.6.065103, doi:10.1117/1.OE.58.6.065103.

[16]

Atilim Gunes Baydin, Barak A Pearlmutter, Alexey Andreyevich Radul, and Jeffrey Mark Siskind. Automatic differentiation in machine learning: a survey. Journal of machine learning research, 18(153):1–43, 2018.

[17]

Alexander Luce, Ali Mahdavi, Florian Marquardt, and Heribert Wankerl. Tmm-fast, a transfer matrix computation package for multilayer thin-film optimization: tutorial. J. Opt. Soc. Am. A, 39(6):1007–1013, Jun 2022. URL: https://opg.optica.org/josaa/abstract.cfm?URI=josaa-39-6-1007, doi:10.1364/JOSAA.450928.

[18]

Charles R. Harris, K. Jarrod Millman, Stéfan J van der Walt, Ralf Gommers, Pauli Virtanen, David Cournapeau, Eric Wieser, Julian Taylor, Sebastian Berg, Nathaniel J. Smith, Robert Kern, Matti Picus, Stephan Hoyer, Marten H. van Kerkwijk, Matthew Brett, Allan Haldane, Jaime Fernández del Río, Mark Wiebe, Pearu Peterson, Pierre Gérard-Marchant, Kevin Sheppard, Tyler Reddy, Warren Weckesser, Hameer Abbasi, Christoph Gohlke, and Travis E. Oliphant. Array programming with NumPy. Nature, 585:357–362, 2020. doi:10.1038/s41586-020-2649-2.

[19]

Dougal Maclaurin, David Duvenaud, and Ryan P Adams. Autograd: effortless gradients in numpy. In ICML 2015 AutoML workshop, volume 238. CNRS, 2015.

[20]

DeepMind, Igor Babuschkin, Kate Baumli, Alison Bell, Surya Bhupatiraju, Jake Bruce, Peter Buchlovsky, David Budden, Trevor Cai, Aidan Clark, Ivo Danihelka, Antoine Dedieu, Claudio Fantacci, Jonathan Godwin, Chris Jones, Ross Hemsley, Tom Hennigan, Matteo Hessel, Shaobo Hou, Steven Kapturowski, Thomas Keck, Iurii Kemaev, Michael King, Markus Kunesch, Lena Martens, Hamza Merzic, Vladimir Mikulik, Tamara Norman, George Papamakarios, John Quan, Roman Ring, Francisco Ruiz, Alvaro Sanchez, Laurent Sartran, Rosalia Schneider, Eren Sezener, Stephen Spencer, Srivatsan Srinivasan, Miloš Stanojević, Wojciech Stokowiec, Luyu Wang, Guangyao Zhou, and Fabio Viola. The DeepMind JAX Ecosystem. 2020. URL: http://github.com/google-deepmind.

[21]

Dong C Liu and Jorge Nocedal. On the limited memory bfgs method for large scale optimization. Mathematical programming, 45(1):503–528, 1989.

[22]

Diederik P. Kingma and Jimmy Ba. Adam: a method for stochastic optimization. 2017. URL: https://arxiv.org/abs/1412.6980, arXiv:1412.6980.

[23]

Leandro Acquaroli. Lnacquaroli/thinfilmstools.jl: v0.9.0. April 2022. URL: https://doi.org/10.5281/zenodo.6479354, doi:10.5281/zenodo.6479354.

[24]

Mikhail N Polyanskiy. Refractiveindex. info database of optical constants. Scientific Data, 11(1):94, 2024.

[25]

Mark Kness. Colorpy-a python package for handling physical descriptions of color and light spectra. The source package can be found at https://github. com/markkness/ColorPy, 2008.