Skip to content

Latest commit

 

History

120 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2D Electron Diffraction Simulation

A modular Python framework for simulating quantum wavepacket propagation and electron diffraction governed by the 2D Time-Dependent Schrödinger Equation (TDSE):

$$i\hbar \frac{\partial \psi(x, y, t)}{\partial t} = \left[ -\frac{\hbar^2}{2m} \left(\frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2}\right) + V(x, y) \right] \psi(x, y, t)$$

The solver uses the unconditionally stable implicit Crank-Nicolson method.


Features

  • 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.

Repository Structure

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)

Installation

Requires Python $\ge 3.10$. Install the package and dependencies locally:

# Clone the repository
git clone https://github.com/AgentFluxAI/Electron-diffraction.git
cd Electron-diffraction

# Install dependencies in editable mode
pip install -e ".[dev]"

Running Simulations

Main Experiments

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 high

Double Slit Diffraction Profile

2. 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 2d

Crystal Diffraction

3. Benchmarks

# Run free wavepacket dispersion benchmark
python -m experiments.run_free_packet

# Run memory and runtime scaling benchmarks
python -m experiments.profile_memory

Note: All generated figures and animations are saved to output/figures/ and output/animations/.

Numerical Prototypes

# 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_regression

Running Tests

Execute the automated test suite with pytest:

pytest -v tests/

About

Modular Python framework for 2D Time-Dependent Schrödinger Equation (TDSE) simulations and electron diffraction using Crank-Nicolson sparse solvers

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages