Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 34 additions & 26 deletions AGENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ C(T) = (V · 2π/ℏ) · g · W² · Σᵢⱼ pᵢ |⟨χᵢ|Q-Q₀|χⱼ⟩|²
Where:
- `V`: supercell volume (cm³)
- `g`: degeneracy factor (spin/orbital)
- `W`: electron-phonon coupling matrix element (eV)
- `W`: electron-phonon coupling matrix element (eV/(amu^0.5·Å))
- `pᵢ`: Boltzmann occupation of initial vibrational state `i`
- `χᵢ, χⱼ`: vibrational wavefunctions (eigenfunctions of 1D Schrödinger equation)
- `δ(εᵢ - εⱼ)`: energy-conserving delta function (Gaussian-broadened)
Expand Down Expand Up @@ -88,7 +88,7 @@ CarrierCapture.py/
│ └── cli/ # Command-line interface
│ ├── main.py # Click CLI entry point
│ └── commands/ # Subcommands (fit, solve, capture, scan, viz)
├── tests/ # 88 tests (pytest)
├── tests/ # 169 tests (pytest)
├── examples/
│ ├── notebooks/ # Jupyter tutorials
│ └── data/ # Example DFT data
Expand Down Expand Up @@ -142,8 +142,8 @@ Manages two-state capture calculation.
```python
pot_i: Potential # Initial state (excited)
pot_f: Potential # Final state (ground)
W: float # Electron-phonon coupling (eV)
g: int # Degeneracy factor
W: float # Electron-phonon coupling (eV/(amu^0.5·Å))
degeneracy: int # Degeneracy factor
overlap_matrix: ndarray # ⟨χᵢ|Q|χⱼ⟩
capture_coefficient: ndarray # C(T) in cm³/s
```
Expand All @@ -169,20 +169,21 @@ cc.capture_coefficient # Array of C(T) values

High-throughput parameter scanning.

**Key Functions**:
**Key Classes**:
```python
from carriercapture.analysis.parameter_scan import scan_parameters
from carriercapture.analysis.parameter_scan import ParameterScanner, ScanParameters

results = scan_parameters(
params = ScanParameters(
dQ_range=(0, 25, 25), # (min, max, n_points)
dE_range=(0, 2.5, 10),
hw_i=0.008,
hw_f=0.008,
W=0.068,
hbar_omega_i=0.008,
hbar_omega_f=0.008,
W=0.068, # eV/(amu^0.5·Å), required
volume=1e-21,
temperature=300.0,
n_jobs=-1 # Parallel execution
)
scanner = ParameterScanner(params)
results = scanner.run_harmonic_scan(n_jobs=-1) # Parallel execution

# Access results
results.capture_coefficients # 2D array [dQ, dE]
Expand Down Expand Up @@ -333,13 +334,16 @@ def solve(
**Structure**:
```
tests/
├── test_potential.py # Potential class tests
├── test_schrodinger.py # Solver validation (analytical solutions)
├── test_config_coord.py # Capture coefficient workflows
├── test_parameter_scan.py # High-throughput scanning
├── test_visualization.py # Plotting functions
├── test_io.py # File I/O
└── test_cli.py # Command-line interface
├── test_potential.py # Potential class tests
├── test_schrodinger.py # Solver validation (analytical solutions)
├── test_config_coord.py # Capture coefficient workflows
├── test_transfer_coord.py # Marcus theory (TransferCoordinate)
├── test_sommerfeld.py # Sommerfeld factor
├── test_parameter_scan.py # High-throughput scanning
├── test_advanced_fitting.py # Potential fitting methods
├── test_visualization.py # Plotting functions
├── test_interactive_dashboard.py# Dash dashboard
└── test_doped_integration.py # doped interface
```

**Run tests**:
Expand All @@ -351,7 +355,7 @@ pytest tests/ -x --pdb # Stop on first failure, debug
```

**Current Status** (2026-01-18):
- 88 tests passing
- 169 tests (doped-integration tests skip without the optional doped package)
- Core modules: >90% coverage
- Python 3.9-3.12 supported

Expand Down Expand Up @@ -436,7 +440,7 @@ OCC_CUTOFF = 1e-5 # Max occupation for partition function convergence
hw = 0.008 eV # 8 meV phonon
dQ = 10.5 # amu^0.5·Å shift
dE = 0.5 eV # Energy difference
W = 0.068 eV # Electron-phonon coupling
W = 0.068 eV/(amu^0.5·Å) # Electron-phonon coupling
volume = 1e-21 cm³ # Supercell volume
temperature = 300 K # Room temperature
nev_initial = 180 # Initial state eigenvalues
Expand Down Expand Up @@ -508,12 +512,16 @@ E_n = ℏω * (n + 1/2)

**File**: `benchmarks/benchmark_sn_zn.py`

**Results** (vs CarrierCapture.jl):
- Initial eigenvalues: 0.005% difference ✓
- Final eigenvalues: 0.02% difference ✓
- Capture coefficient (300K): 1.5% difference ✓
**Results** (three-tier comparison vs CarrierCapture.jl):
- Tier 1: with Julia's grid/integration conventions emulated, eigenvalues and
C(300K) match the Julia reference to ~1e-12 (algorithmic equivalence) ✓
- Tier 2: native eigenvalues match analytic ℏω(n+½) to ≤1.5e-4 ✓
- Tier 3: native C(300K) differs from Julia by ~1.5%, entirely due to
CarrierCapture.jl's finite-difference spacing (ΔQ/N vs ΔQ/(N−1)) and
rectangle-rule overlaps; Python's native numerics are the more accurate ✓

**Conclusion**: Python matches Julia within ~1-2% (floating-point precision)
**Conclusion**: identical physics; the small native offset is a Julia grid
convention, not floating-point noise.

---

Expand Down Expand Up @@ -696,7 +704,7 @@ pot.eigenvectors # Array of χₙ(Q), shape: (nev, len(Q))
### Capture Calculation

```python
cc = ConfigCoordinate(pot_i, pot_f, W=0.068, g=1)
cc = ConfigCoordinate(pot_i, pot_f, W=0.068, degeneracy=1)
cc.calculate_overlap(Q0=5.0, sigma=0.025, cutoff=0.25)
cc.calculate_capture_coefficient(
volume=1e-21,
Expand Down
54 changes: 33 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CarrierCapture.py started life as an automated rewrite of [CarrierCapture.jl](ht

### 🔬 Scientific Validation
- Validated against CarrierCapture.jl
- Comprehensive test suite (88 tests)
- Comprehensive test suite (169 tests)
- Tutorial notebooks with real examples

---
Expand All @@ -65,14 +65,14 @@ pip install -e ".[dev]"

### Optional Dependencies
```bash
# Interactive dashboard
pip install carriercapture[viz]

# doped integration (for defect calculations)
pip install carriercapture[doped]

# All extras (recommended for development)
pip install -e ".[all]"
# Jupyter notebook support
pip install carriercapture[notebook]

# Development tools (tests, linting)
pip install -e ".[dev]"
```

---
Expand Down Expand Up @@ -118,7 +118,7 @@ carriercapture solve excited.json -n 180 -O excited_solved.json
carriercapture capture config.yaml -V 1e-21 --temp-range 100 500 50

# High-throughput parameter scan
carriercapture scan --dQ-min 0 --dQ-max 25 --dQ-points 25 \
carriercapture scan --dQ-min 0 --dQ-max 25 --dQ-points 25 -W 0.05 \
--dE-min 0 --dE-max 2.5 --dE-points 10 \
-j -1 -o scan_results.npz

Expand Down Expand Up @@ -159,7 +159,9 @@ pot_final.solve(nev=60)
### Tutorial Notebooks

- **[01_harmonic_sn_zn.ipynb](examples/notebooks/01_harmonic_sn_zn.ipynb)** - Basic workflow with harmonic oscillators
- **[02_anharmonic_dx_center.ipynb](examples/notebooks/02_anharmonic_dx_center.ipynb)** - Anharmonic potentials (DX center)
- **[03_parameter_scan.ipynb](examples/notebooks/03_parameter_scan.ipynb)** - High-throughput screening
- **[04_interactive_viz.ipynb](examples/notebooks/04_interactive_viz.ipynb)** - Interactive visualization

Full examples in [`examples/`](examples/) directory with detailed [README](examples/README.md).

Expand Down Expand Up @@ -195,7 +197,7 @@ $$C(T) = \frac{V \cdot 2\pi}{\hbar} \cdot g \cdot W^2 \cdot \sum_{i,j} p_i |\lan
Where:
- `V`: supercell volume
- `g`: degeneracy factor
- `W`: electron-phonon coupling matrix element
- `W`: electron-phonon coupling matrix element (eV/(amu^0.5·Å))
- `pᵢ`: thermal occupation of initial state `i`
- `χᵢ, χⱼ`: vibrational wavefunctions
- `δ`: energy-conserving delta function (Gaussian broadened)
Expand All @@ -222,9 +224,9 @@ pytest tests/ --cov=src/carriercapture --cov-report=html
```

**Test Statistics:**
- 88 tests passing (53 Phase 3 tests skipped)
- 169 tests (doped-integration tests skip without the optional doped package)
- Core modules: >90% coverage
- All tests pass on Python 3.11-3.12
- Supported Python versions: 3.9-3.12
- CI/CD with GitHub Actions

---
Expand Down Expand Up @@ -255,16 +257,26 @@ CarrierCapture.py has been validated against the original [CarrierCapture.jl](ht
- Phonon energy: ℏω = 8 meV
- Configuration coordinate shift: ΔQ = 10.5 amu^0.5·Å
- Energy offset: ΔE = 0.5 eV
- Electron-phonon coupling: W = 0.068 eV

**Results**:
| Observable | Python Value | Julia Value | Relative Diff | Status |
|------------|--------------|-------------|---------------|--------|
| Initial eigenvalues (E₀) | 0.504000 eV | 0.504001 eV | 0.005% | ✓ PASS |
| Final eigenvalues (E₀) | 0.004000 eV | 0.004001 eV | 0.02% | ✓ PASS |
| Capture coefficient (300K) | 1.339×10⁻¹⁰ cm³/s | 1.359×10⁻¹⁰ cm³/s | 1.5% | ✓ PASS |

**Conclusion**: Python implementation matches Julia results within ~1-2% across all observables. Small differences (~0.01-1.5%) are due to floating-point arithmetic differences between language implementations and are well within acceptable tolerances for physical calculations.
- Electron-phonon coupling: W = 0.068 eV/(amu^0.5·Å)

**Results** (three-tier comparison):

| Tier | Comparison | Max Relative Diff | Status |
|------|------------|-------------------|--------|
| 1 | Julia-convention emulation vs Julia reference (eigenvalues) | 3×10⁻¹² | ✓ PASS |
| 1 | Julia-convention emulation vs Julia reference (C at 300 K) | 5×10⁻¹² | ✓ PASS |
| 2 | Native eigenvalues vs analytic ℏω(n+½) | 1.5×10⁻⁴ | ✓ PASS |
| 3 | Native C(300 K) = 1.339×10⁻¹⁰ vs Julia 1.359×10⁻¹⁰ cm³/s | 1.5×10⁻² | ✓ (informational) |

**Conclusion**: When Python is run with CarrierCapture.jl's numerical
conventions, the two codes agree to near machine precision (Tier 1) — they
implement identical physics. The ~1.5% native difference (Tier 3) is entirely
due to two CarrierCapture.jl conventions: its finite-difference kinetic term
uses grid spacing ΔQ/N while its grid actually has spacing ΔQ/(N−1), and it
integrates overlaps with the rectangle rule. Python uses the true grid spacing
and the trapezoid rule, and its native eigenvalues are closer to the analytic
harmonic result (Tier 2). Both codes converge to the same answer with
increasing grid density.

### Running the Benchmark

Expand Down Expand Up @@ -340,7 +352,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
| Parameter Scanning | ✅ Complete |
| doped Integration | ✅ Complete |
| Documentation | ✅ Complete |
| Test Coverage | ✅ 88 tests |
| Test Coverage | ✅ 169 tests |
| PyPI Release | 🔄 Planned |

---
Expand Down
Loading
Loading