Differentiable biophysical modeling in JAX
Project description
๐งฌ Diff-Biophys: Differentiable Biophysics for the AI Era
Diff-Biophys is a high-performance Python library for differentiable biophysical modeling. Built on JAX, it re-implements core structural biology and spectroscopy observables (SAXS, NMR, CD) as hardware-accelerated, auto-differentiable kernels.
Documentation Website | Use Cases | Tutorials
๐ฏ Vision
To bridge the gap between static structural models and experimental solution-state data by providing a "differentiable bridge." This allows researchers to:
- Optimize protein structures directly against experimental spectra via gradient descent.
- Train machine learning models using physics-informed loss functions.
- Accelerate large-scale biophysical simulations on GPUs and TPUs.
๐ The Interdisciplinary Bridge
diff-biophys sits at the intersection of Machine Learning and Structural Biology. If you find the terminology confusing, please read our Concepts & Context Guide! It acts as a "Rosetta Stone" to explain:
- For ML Engineers: What SAXS and NMR are, and why traditional physics code can't be used in PyTorch/JAX loss functions.
- For Biologists: What automatic differentiation is, why JAX is used instead of traditional Monte Carlo/Simulated Annealing, and how it enables optimization on GPUs.
๐ Interactive Tutorials
Experience Diff-Biophys directly in your browser with our Colab tutorials:
| Tutorial | Audience | Description | Action |
|---|---|---|---|
| ๐ Hello, Gradient Descent! | Undergrad (any) | No biology needed. Learn what a gradient is, how gradient descent works, and how JAX computes gradients automatically โ then fit a real Karplus curve. | |
| ๐ฌ NMR Fundamentals | Undergrad (bio/chem) | Chemical shifts, the Karplus equation, RDCs, and the magic angle โ computed differentiably and connected back to protein backbone torsion angles. | |
| ๐ก CD Spectroscopy | Undergrad (bio/chem) | Build an ฮฑ-helix from scratch, simulate its CD spectrum via the DeVoe model, watch it change as the helix unwinds, and compute the gradient of [ฮธ]โโโ w.r.t. atomic positions. | |
| ๐งช Diff-Biophys Showcase | Graduate / researcher | A complete overview of the JAX-accelerated SAXS and NMR kernels. | |
| โ๏ธ Structure Refinement Lab | Graduate / researcher | Use gradient descent to optimize protein structures against experimental SAXS profiles. |
๐๏ธ Core Components
1. diff_biophys.geometry (Differentiable Structural Engine)
- NeRF (Natural Extension Reference Frame): Differentiable conversion from internal coordinates ($\phi, \psi, \omega$, bond lengths/angles) to Cartesian XYZ.
- Kabsch Alignment: Differentiable optimal superposition using SVD.
- Torsion Analysis: Vectorized calculation of all backbone and side-chain dihedrals.
- Macroscopic Properties: Differentiable Radius of Gyration ($R_g$) for driving compaction/expansion during structural optimization.
2. diff_biophys.saxs (Differentiable Scattering)
- Debye Formula: $O(N^2)$ inter-atomic interference summation.
- Hydration Shell Correction: Excluded-volume solvent subtraction (Fraser et al. 1978).
- Hardware Acceleration: GPU-optimized pairwise distance kernels via JAX
vmap. - Use Case: Fitting structure compactness and radius of gyration to solution-state X-ray scattering curves.
3. diff_biophys.nmr (Differentiable Spectroscopy)
- Residual Dipolar Couplings (RDCs): Differentiable Saupe tensor alignment and coupling calculation. Includes SVD-based tensor fitting.
- Chemical Shifts: Differentiable ring-current (Johnson-Bovey) shielding and softmax-weighted secondary structure Cฮฑ shift predictor.
- Karplus J-coupling: Parameterizable 3J coupling equation (Vuister & Bax 1993 defaults).
- Use Case: Refining side-chain packing and domain orientations against high-resolution NMR data.
4. diff_biophys.cd (Differentiable Dichroism)
- Matrix-Method Simulation: Differentiable simulation of peptide bond transition dipole coupling via DeVoe theory.
- Status: โ Implemented. Supports frequency-dependent coupled-oscillator response.
โก Technical Architecture
- Backend: JAX (XLA-compiled) โ supports CPU, GPU, and TPU.
- Parallelism: Native support for
vmap(vectorization across ensembles/trajectories) andpmap(multi-device execution). - Differentiability: Forward and reverse-mode autodiff through all kernels.
- Interoperability: JAX arrays are compatible with NumPy and can be exchanged with PyTorch via
dlpack(user-managed conversion).
๐งช Scientific Validation
DiffBiophys is validated against foundational biophysical principles and analytical solutions to ensure physical realism:
- SAXS Guinier Approximation: Recovers correct $R_g$ from low-q scattering slopes (
test_saxs_guinier.py). - SAXS Analytic Sphere: Reproduces the theoretical scattering profile of a uniform sphere (
test_science_saxs_sphere.py). - SAXS Kratky Topology: Correctly distinguishes between globular and unfolded topologies via Kratky plot signatures (
test_science_saxs_kratky.py). - SAXS $P(r)$ Distribution: Matches analytical pair-distance distribution for spheres (Guinier 1939) with $>0.98$ correlation (
test_science_saxs_pr.py). - NMR RDC Physics: Verified 1/rยณ distance scaling and $(3\cos^2\theta - 1)$ angular dependence, including zero coupling at the Magic Angle (
test_science_rdc_angular.py). - NMR Ring Currents: Reproduces shielding/deshielding cones of the Johnson-Bovey model (
test_science_ring_currents.py).
๐ Roadmap
Phase 1: Foundations (Alpha)
- Differentiable NeRF and Kabsch alignment.
- GPU-accelerated Debye formula for SAXS with hydration shell correction.
- Unit tests verifying parity with
synth-pdbNumPy implementations.
Phase 2: NMR & Spectroscopy (Beta)
- Differentiable RDC and Karplus kernels.
- Differentiable Johnson-Bovey ring current model.
- Integration with
synth-nmrparameter libraries (optional dependency).
Phase 3: Integration & Optimization (v1.0)
- Full CD matrix-method implementation (DeVoe theory).
- Example notebooks for structure refinement via gradient descent.
- Plugin for
torch-based AI models to use biophysical loss functions. - Full support for BinaryCIF streaming.
๐ Repository Structure
diff-biophys/
โโโ diff_biophys/ # Core package
โ โโโ geometry/ # NeRF, Kabsch, Torsions
โ โโโ saxs/ # Debye kernels, form factors
โ โโโ nmr/ # RDCs, Karplus, Ring Currents, Chemical Shifts
โ โโโ cd/ # CD simulation (DeVoe Matrix Method)
โ โโโ ensemble.py # Ensemble averaging API
โโโ tests/ # Parity, gradient, and scientific validation checks
โโโ examples/interactive_tutorials/ # Jupyter notebooks (Refinement Lab)
โโโ docs/ # API and Theory
โโโ pyproject.toml # Modern build config
โโโ README.md
๐ Installation
pip install diff-biophys
For GPU support (CUDA):
pip install "jax[cuda12]" diff-biophys
๐ค Contributing
Contributions are welcome from both ML and structural biology communities! Please open an issue or pull request on GitHub. Run pre-commit run --all-files before submitting.
๐ Related Projects
diff-biophys is the differentiable engine powering the higher-level tools in this ecosystem:
- synth-pdb โ Synthetic structure generation (uses NumPy implementations)
- synth-nmr โ NMR observables (optional dependency)
- synth-saxs โ SAXS profile simulator
- diff-fret โ Differentiable FRET (new)
- diff-hdx โ Differentiable HDX-MS (new)
- diff-epr โ Differentiable EPR/DEER (new)
- diff-ensemble โ IDP ensemble VAE (depends on diff-biophys)
- torsion-tuner โ GNN refinement (depends on diff-biophys)
- resonance-flow โ NMR-guided folding (depends on diff-biophys)
โ๏ธ License
MIT License โ see LICENSE for details.
๐ Citation
@software{diff_biophys,
author = {Elkins, George},
title = {diff-biophys: Differentiable biophysics kernels for JAX},
year = {2026},
url = {https://github.com/elkins-lab/diff-biophys},
version = {0.1.6}
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file diff_biophys-0.1.6.tar.gz.
File metadata
- Download URL: diff_biophys-0.1.6.tar.gz
- Upload date:
- Size: 65.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caed98cd88b47ac93b694f2a677db69d47fa95846bd8cb318214ece4b3a52a3d
|
|
| MD5 |
bfda56f8f6ae830147309f0b519bce6a
|
|
| BLAKE2b-256 |
5e73fa712a1fcbb8fa11e5d5acd01cdbad086824b6d125ce6cab9eef6703176c
|
File details
Details for the file diff_biophys-0.1.6-py3-none-any.whl.
File metadata
- Download URL: diff_biophys-0.1.6-py3-none-any.whl
- Upload date:
- Size: 24.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa5f5c9377d8fe4927b71c462f36cd6e56610ad0bfad906c87d83f43adf1cb13
|
|
| MD5 |
acb9e308d22aa349d1722c45480bb7d4
|
|
| BLAKE2b-256 |
523a74ddee58dadd4452273451d3b476d883a49f93de9ea64ac8868c56fba469
|