An interactive simulation of a quantum particle in an infinitely deep box, in 1D, 2D or 3D, drawn in an
A Python backend (Flask and NumPy) builds and checks the quantum state; the browser animates it.
pip install -r requirements.txt
python server.pyYour browser opens at http://127.0.0.1:8004. On Windows you can double-click launch.pyw instead
(no console window). The server quits by itself when you close the tab.
-
Sliders and number boxes for
$L_x$ ,$L_y$ ,$L_z$ (0 to 6 on the slider, up to 50 in the box) and$n_x$ ,$n_y$ ,$n_z$ (1 to 20 on the slider, up to 60 in the box). Everything updates as you drag. - State: eigenstate, superposition of two eigenstates, or Gaussian wave packet.
- View: drag to rotate, wheel to zoom, double-click to reset. The buttons Iso, x-y, x-z and y-z jump to standard viewpoints, and Auto-rotate spins the scene.
- Playback: pause, restart and speed.
A length of
| Lengths | Box |
|---|---|
|
|
1D, length 2 along |
|
|
2D rectangle |
|
|
2D rectangle in the |
|
|
3D cuboid |
| all three |
no box, so nothing is drawn |
The axes are always
-
1D: the box is a segment of one axis. The wave is drawn as a curve in the space around it:
$\mathrm{Re},\psi$ on one perpendicular axis and$\mathrm{Im},\psi$ on the other, so$\psi$ itself is a helix. A second view plots$|\psi|^2$ along one perpendicular axis. -
2D: the box is a rectangle in a coordinate plane and the remaining axis is the height of a surface:
$\mathrm{Re},\psi$ ,$\mathrm{Im},\psi$ or$|\psi|^2$ (orange positive, blue negative). -
3D: a cloud of points inside the wireframe box. Brightness follows
$|\psi|^2$ , or you can show the sign of$\mathrm{Re},\psi$ or$\mathrm{Im},\psi$ . The cut-off slider hides the faintest points.
Heights and brightness use one fixed scale for the whole animation (the largest value the state ever reaches) for 1D and 2D, so you can see a packet spread and fade. The 3D cloud is scaled to the peak of each frame, because a spread-out packet would otherwise vanish.
Three kinds of state are available:
-
Eigenstate: a stationary state. The density never changes but the phase of
$\psi$ rotates. -
Superposition: the eigenstates
$\mathbf{n}$ and$\mathbf{n}+\hat{x}_1$ added together (one level up along the first existing axis), so the density sloshes back and forth. - Gaussian wave packet: the closest thing to a "particle". It travels, bounces off the walls, spreads out, interferes with itself and eventually reforms.
Units are
The box is separable, so in
The wave packet is a Gaussian expanded in box eigenstates, which makes the wall reflections exact:
Because
Each second of animation corresponds to a chosen amount of physical time, so a full cycle of the motion takes about 6 seconds on screen. For a packet that cycle is one round trip across the longest side.
.
├── server.py # Flask app: validates input, serves the page, quits with the tab
├── box_physics.py # all the physics, pure NumPy
├── static/index.html # the page: sliders, 3D canvas renderer, animation
├── launch.pyw # double-click launcher (Windows)
├── requirements.txt # web app: flask, numpy
├── assets/screenshot.png
└── docs/
└── Particle in a box.pdf # every formula used in the program
The server sends the page the eigenfunction expansion of the state (quantum numbers, coefficients, energies).
The page then evaluates
All the mathematics used in the program (eigenstates, superposition, wave packet, the plotted quantities and the 3D projection) is collected in docs/Particle in a box.pdf.
MIT, see LICENSE.
