How I Recreated a Photonic-Crystal Light Trap in Python, and Tested Whether I Could Trust It
By Gagan Saisaket Saranam (Saket) | Focus: Semiconductors
Project Deliverables:
Video Walkthrough: https://youtu.be/8Gh9aO2BhWA?si=Lh4QUQurUu0r4Fms
Interactive Colab Notebook: https://colab.research.google.com/drive/1QxdJCW3WinFrMGMtv2xhYdlfMkVaNEsr?usp=sharing
TL;DR
I recreated a classic photonic-crystal simulation from MIT’s MPB software. It models a square grid of silicon-like rods that blocks a range of light frequencies, with one rod removed to trap light in a single spot. Using Python and MPB in Google Colab, I reproduced three results, all within 0.6% of the published values:
- the band gap (0.2809–0.4171)
- the frequency of the trapped light (0.3773)
- the share of its energy held near the defect (62.3%)
I then extended the simulation in three ways:
- tuning the trapped frequency by changing the middle rod
- testing whether my answer holds up at higher resolution and in larger grids
- converting the result into real dimensions for 1550 nm telecom light, which needs about 585 nm between rods
1. Why put light on chips?
A lot of what modern computers do is move data: between transistors, between chips, and between servers. Long-distance internet traffic already travels as light through optical fibre, because light carries way more data, with less loss than electrical wires. Silicon photonics tries to bring that advantage onto the chip itself, by building parts that guide, filter and generate light from the same silicon used for transistors.
To do that, we need ways to control light in spaces about as small as its own wavelength. Photonic crystals are one of those ways. A photonic crystal is a material with a repeating pattern, such as a grid of rods or holes, spaced so that it interacts strongly with light.
I chose this project to understand one of the basic building blocks by recreating it myself.
2. The idea in plain words
Imagine shining light into a grid of rods. Each rod reflects a small amount of light back, like an echo. Echoes from deeper rods travel further: in to the rod and back out again, so twice the spacing.
At most wavelengths, these echoes come back out of step and cancel each other, so the light passes through. But at certain wavelengths, the delay between echoes matches the wave exactly. Every echo returns in step, they add up into a strong reflection, and the light cannot get through.
In a 2D grid, light can arrive from any direction. If a range of frequencies is blocked in every direction at once, that range is called a photonic band gap. It is the light version of the electronic band gap in semiconductors, where electrons cannot have certain energies.
Now remove one rod from the middle of the grid. The pattern is broken at that spot, so one frequency inside the band gap is allowed to exist there. But the surrounding crystal still blocks that frequency, so the light has nowhere to go. It stays trapped, like light bouncing inside a small room whose walls are perfect mirrors. This trapped light is called a defect mode, and devices built on this idea are used as filters, sensors and tiny laser cavities.
3. What I recreated
I followed two sections of the MPB documentation, “Finding a Point-Defect State” and “Tuning the Point-Defect Mode”. Both are based on Chapter 5 of Photonic Crystals: Molding the Flow of Light (Joannopoulos, Johnson, Winn and Meade). MPB (MIT Photonic Bands) is open-source software that calculates which light frequencies a periodic structure allows.
I used the tutorial’s exact settings, so my results could be compared directly:
- a square grid of rods with a radius of 0.2 times the rod spacing
- rods with a dielectric constant (ε) of 12, close to silicon’s value at telecom wavelengths, standing in air
- TM light, meaning its electric field points along the rods
- a 5 × 5 block of rods with the centre rod removed, for the defect calculations
Frequencies are given as rod spacing ÷ wavelength. This means the result works at any size: you choose the spacing later for the light you want.
What this does not reproduce: this is a 2D simulation of an idealised structure, not a fabricated device. I ran everything in Google Colab using MPB’s Python interface, NumPy and Matplotlib.
4. Step 1: The perfect crystal
The first step was to calculate the band diagram of a perfect grid: which frequencies of light can travel through it, in every direction.
MPB repeats a single 1 × 1 tile (one rod) forever in every direction, then checks light travelling along the rows (Γ → X), turning towards the diagonal (X → M), and along the diagonal (M → Γ). I asked for the lowest 8 bands, at a resolution of 32 pixels per rod spacing.
Each line in the diagram is a kind of light wave that can travel through the crystal. The shaded strip has no lines in it for any direction, so that range of frequencies is blocked completely.
MPB found a 39% band gap between band 1 and band 2:
- 0.2809: the top of band 1, reached along the diagonal (M)
- 0.4171: the bottom of band 2, reached along the rows (X)
5. Step 2: Trapping light
Removing a rod sounds simple, but it raised a problem I hadn’t expected. MPB always repeats the tile forever, so if I removed the rod from my 1 × 1 tile, I would remove every rod and lose the crystal entirely.
The fix is a supercell: a bigger tile of 5 × 5 rods with only the centre rod removed. MPB repeats this tile too, but the missing rods end up 5 spacings apart, far enough that each one behaves almost as if it were alone.
There is a cost. A tile of 25 rods contains the original bands 25 times over, so I had to calculate 50 bands instead of 8 to reach the band gap. Exactly one of them landed inside it: band 25, at a frequency of 0.3773. That is the trapped light.
The heat-map shows the light concentrated where the rod is missing, with faint traces in the four nearest rods and almost nothing beyond. I measured how much of the light’s energy sits within one rod spacing of the defect: 62.3%.
6. How close did I get?
Every result matches to within 0.6%. But every one of my numbers is also slightly lower than the tutorial’s. Because the difference always goes in the same direction, it is not random noise. I discuss this further in Section 8.
7. Extension 1: Tuning the trap
Instead of removing the middle rod completely, I made it weaker or stronger by changing its ε from 1 (air, rod removed) to 12 (a normal rod). To speed this up, I told MPB to find only the single band closest to the middle of the gap, which is the trapped light.
As the rod gets stronger, the trapped frequency falls smoothly from 0.3773 to 0.2822. That means the trap can be set to hold any frequency in that range, which is how designers choose the colour of light a cavity holds. Near ε = 12, the curve flattens into the bottom edge of the band gap. At that point the rod is back to normal, the crystal is perfect again, and the trap no longer exists.
8. Extension 2: Can I trust it?
A simulation gives a number whether or not it is accurate, so I tested whether mine would change if I gave MPB more detail.
Resolution: going from 24 to 32 pixels changed the answer by under 0.01%, so it has settled (converged).
Grid size: a 3 × 3 grid was too small. The defects were close enough to affect each other, shifting the answer by almost 3%. From 5 × 5 to 7 × 7, it changed by only 0.3%.
My best estimate for the trapped frequency is 0.376–0.377, accurate to about 0.3%. Both tests pushed my answer further below the tutorial’s, so neither explains the offset from Section 6. I would like to ask an expert about it.
9. Extension 3: Real-world size
Because frequencies are given as spacing ÷ wavelength, I can choose a real size. To trap 1550 nm light, the wavelength used in fibre-optic communication, the rods need to be about 585 nm apart with a 117 nm radius. The crystal would then block wavelengths from about 1402 to 2082 nm, with 1550 nm comfortably inside the gap.
10. Limitations
- The rods are infinitely tall. Real chips use thin slabs, where some light leaks up and down.
- Rods vs holes. Freestanding rods this thin would be fragile. Real devices usually etch holes into a silicon sheet instead, which needs a different design.
- Perfect rods. The model assumes every rod is identical. Real fabrication errors would blur the band gap and weaken the trap.
- An unexplained offset. My results sit 0.1–0.6% below the tutorial’s, and I ruled out resolution and grid size as the cause.
11. What I learned
The idea sounded simple, but it took so much understanding to make it work. I found the supercell problem interesting to tackle.
Matching the tutorial felt sounded quite simple, but the small, consistent offset made me ask: “how would I know if my number’s right?” Running the resolution and grid-size tests taught me that a simulation result only means something alongside evidence of how stable it is.
Finally, I learned that photonic crystals use the same idea as the semiconductor band gaps: a repeating structure that forbids certain energies. Seeing the same physics show up in light and in electrons was the most satisfying part of the project.