Skip to main content

Differentiable biophysical modeling in JAX

Project description

๐Ÿงฌ Diff-Biophys: Differentiable Biophysics for the AI Era

Tests PyPI version Python 3.10+ License: MIT codecov JAX Ruff Checked with mypy OpenSSF Best Practices

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:

  1. Optimize protein structures directly against experimental spectra via gradient descent.
  2. Train machine learning models using physics-informed loss functions.
  3. 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. Open In Colab
๐Ÿ”ฌ 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. Open In Colab
๐Ÿ’ก 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. Open In Colab
๐Ÿงช Diff-Biophys Showcase Graduate / researcher A complete overview of the JAX-accelerated SAXS and NMR kernels. Open In Colab
โš—๏ธ Structure Refinement Lab Graduate / researcher Use gradient descent to optimize protein structures against experimental SAXS profiles. Open In Colab

๐Ÿ—๏ธ 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) and pmap (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-pdb NumPy implementations.

Phase 2: NMR & Spectroscopy (Beta)

  • Differentiable RDC and Karplus kernels.
  • Differentiable Johnson-Bovey ring current model.
  • Integration with synth-nmr parameter 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

diff_biophys-0.1.6.tar.gz (65.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diff_biophys-0.1.6-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

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

Hashes for diff_biophys-0.1.6.tar.gz
Algorithm Hash digest
SHA256 caed98cd88b47ac93b694f2a677db69d47fa95846bd8cb318214ece4b3a52a3d
MD5 bfda56f8f6ae830147309f0b519bce6a
BLAKE2b-256 5e73fa712a1fcbb8fa11e5d5acd01cdbad086824b6d125ce6cab9eef6703176c

See more details on using hashes here.

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

Hashes for diff_biophys-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 aa5f5c9377d8fe4927b71c462f36cd6e56610ad0bfad906c87d83f43adf1cb13
MD5 acb9e308d22aa349d1722c45480bb7d4
BLAKE2b-256 523a74ddee58dadd4452273451d3b476d883a49f93de9ea64ac8868c56fba469

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page