A modular Python framework for simulating quantum wavepacket propagation and electron diffraction governed by the 2D Time-Dependent Schrödinger Equation (TDSE):
The solver uses the unconditionally stable implicit Crank-Nicolson method.
-
Implicit 2D TDSE Solver: Unconditionally stable Crank-Nicolson sparse solver (
$A\psi^{n+1} = M\psi^n$ ) with pre-factorized LU acceleration. - Modular Potentials: Double-slit barriers, periodic atomic crystal lattices (e.g., graphene), and Complex Absorbing Potentials (CAP).
- Physical Analysis: Extraction of detector probability density profiles and prediction of crystal lattice parameters via Bragg/de Broglie diffraction relations.
- Pedagogical Numerical Prototypes: Standalone benchmark scripts for Monte Carlo integration, ODE convergence, 1D heat diffusion, and 2D sparse Poisson solvers.
- Physics-Informed Verification: Unit tests for norm conservation, potential geometry, and wavepacket dispersion.
Electron-diffraction/
├── src/electron_diffraction/ # Core reusable physics & numerical engine
│ ├── grid.py # 2D spatial & temporal grid discretization
│ ├── state.py # Normalized Gaussian wavepacket initialization
│ ├── potentials.py # Slit, crystal, and absorbing potential generators
│ ├── solver.py # Crank-Nicolson sparse matrix builder & LU solver
│ ├── observables.py # Probability norm, screen intensity & peak detection
│ └── visualization.py # Static figure generation & MP4 animation export
├── experiments/ # Executable simulation drivers
│ ├── run_free_packet.py # Free wavepacket dispersion benchmark
│ ├── run_double_slit.py # Double-slit diffraction simulation
│ ├── run_crystal.py # Crystal diffraction & lattice constant prediction
│ └── profile_memory.py # Sparse matrix memory and runtime profiling
├── prototypes/ # Standalone numerical physics test scripts
│ ├── monte_carlo_volume.py # Multi-D hypersphere Monte Carlo integration
│ ├── ode_pendulum_convergence.py # Non-linear damped pendulum ODE convergence
│ ├── pde_1d_heat_bvp.py # 1D Heat equation BVP with Robin boundary conditions
│ └── pde_2d_poisson_sparse.py # 2D Poisson sparse matrix linear solver
├── docs/ # In-depth physics, numerical, and validation notes
│ ├── physics_model.md
│ ├── numerical_method.md
│ └── validation_and_benchmarks.md
└── tests/ # Automated test suite (pytest)
Requires Python
# Clone the repository
git clone https://github.com/AgentFluxAI/Electron-diffraction.git
cd Electron-diffraction
# Install dependencies in editable mode
pip install -e ".[dev]"1. Double-Slit Diffraction
# Run double-slit diffraction simulation (Fresnel near-field or Fraunhofer far-field)
python -m experiments.run_double_slit --regime fresnel
python -m experiments.run_double_slit --regime fraunhofer --resolution high2. Crystal Lattice Diffraction
# Run crystal lattice diffraction (1D atomic chain or 2D Bravais TEM lattice)
python -m experiments.run_crystal --lattice 1d
python -m experiments.run_crystal --lattice 2d3. Benchmarks
# Run free wavepacket dispersion benchmark
python -m experiments.run_free_packet
# Run memory and runtime scaling benchmarks
python -m experiments.profile_memoryNote: All generated figures and animations are saved to
output/figures/andoutput/animations/.
# Monte Carlo hypersphere integration
python -m prototypes.monte_carlo_volume
# Damped pendulum temporal convergence
python -m prototypes.ode_pendulum_convergence
# 1D Heat BVP (Robin/Neumann boundary conditions)
python -m prototypes.pde_1d_heat_bvp
# 2D Poisson sparse solver
python -m prototypes.pde_2d_poisson_sparse
# Non-linear Gauss-Newton parameter regression
python -m prototypes.opt_newton_regressionExecute the automated test suite with pytest:
pytest -v tests/
