Skip to main content

Integrative Refinement Engine using differentiable forward models

Project description

⚙️ Diff-Integrator: The Integrative Refinement Engine

Tests Python 3.10+ License: MIT

Diff-Integrator is a JAX-accelerated optimization engine designed for integrative structural biology. It acts as the "orchestrator" that combines differentiable observables from diff-biophys into multi-objective loss functions.

By cleanly separating the optimization loop from the underlying biophysical kernels, diff-integrator enables robust, joint refinement of protein structures against diverse experimental data (e.g., SAXS, NMR Chemical Shifts, NMR RDCs) simultaneously.


🎯 Vision

The goal of diff-integrator is to provide a seamless optax-based refinement pipeline that handles:

  1. Multi-Objective Optimization: Easily weight and combine multiple experimental constraints via JointLoss.
  2. Abstract Parameterization: Optimize arbitrary parameter spaces—from Cartesian coordinates to internal backbone angles (phi/psi)—via user-defined kinematics_fn mappers.
  3. Dynamic Fitting: Analytically refit nuisance parameters (like Saupe alignment tensors or SAXS scaling factors) dynamically during gradient descent.

📚 Interactive Tutorials

Experience Diff-Integrator directly in your browser with our Colab tutorials:

Tutorial Audience Description Action
📉 Results Dashboard Graduate / researcher Visualizes the loss descent, Q-factors, chemical shift accuracy, NeRF drift, and structural changes across all three benchmarks. Open In Colab
🧪 Refinement Concepts Student / researcher Educational notebook explaining NMR observables, NeRF coordinate parameterization, RDC tensor degeneracy, and the fixed-tensor protocol. Open In Colab
⚠️ Method Limitations Reviewer / scientist Honest quantitative assessment of the current method's failure modes: NeRF geometric drift, RDC overfitting on PEG data, and degrees-of-freedom imbalance. Open In Colab

⚡ Core Components

IntegrativeRefiner

The core optimization engine. Built on optax (defaulting to the Adam optimizer), it manages the training loop, gradient calculation, and loss tracking.

  • Abstract Support: Accepts arbitrary parameter sets (init_params) and maps them to Cartesian space using an optional kinematics_fn.

JointLoss

A container for combining multiple LossTerm objects. It computes the total weighted loss by evaluating each term on the current parameters and generated coordinates.

LossTerm (Interface)

An abstract base class for defining differentiable constraints. All terms implement __call__(self, params, coords).

Included Observables

  • GeometryLoss: Implements basic structural priors, including harmonic restraints to a target Cartesian structure.
  • SAXSLoss: Dynamically scales and fits theoretical SAXS profiles against experimental data using Debye kernels.
  • RDCLoss: Analytically fits the Saupe tensor to current bond vectors at each step to compute Residual Dipolar Coupling (RDC) Mean Squared Errors or Q-factors.
  • CAShiftLoss: Wraps the ring-current and secondary structure shift predictor to compute $C_\alpha$ chemical shift RMSDs.

🚀 Usage Example

import jax.numpy as jnp
from diff_integrator.loss import JointLoss
from diff_integrator.optimizer import IntegrativeRefiner
from diff_integrator.terms.geometry import GeometryLoss
from diff_integrator.terms.nmr import RDCLoss

# 1. Define loss terms
target_coords = jnp.load("target.npy")
geom_term = GeometryLoss(target_coords, loss_type="rmsd")

rdc_term = RDCLoss(
    atom_pairs=bond_indices,
    exp_rdcs=experimental_rdc_values,
    d_max=21700.0,
    loss_type="q_factor"
)

# 2. Combine into a joint loss
joint_loss = JointLoss([
    (geom_term, 10.0),  # Weight = 10.0
    (rdc_term, 1.0)     # Weight = 1.0
])

# 3. Refine
refiner = IntegrativeRefiner(loss_fn=joint_loss)
final_coords, history = refiner.run(
    init_params=starting_coords,
    epochs=1000,
    learning_rate=0.01
)

🔬 Scientific Validation

diff-integrator is being validated against several experimental NMR datasets:

  • 2KZV (CvR118A): Joint refinement using $C_\alpha$ Chemical Shifts and dual-medium (PAG/PEG) RDCs, lowering the $C_\alpha$ RMSD and bringing RDC Q-factors near zero.
  • GmR58A & HR2876B: Successful gradient-based minimization of $C_\alpha$ shift RMSD using internal coordinates (dihedrals).

📂 Repository Structure

diff-integrator/
├── diff_integrator/       # Core package
│   ├── loss.py            # JointLoss and LossTerm interface
│   ├── optimizer.py       # IntegrativeRefiner engine
│   └── terms/             # Concrete loss implementations
│       ├── geometry.py    # Harmonic restraints, RMSD
│       ├── saxs.py        # Debye scattering loss
│       ├── nmr.py         # RDC and Q-factor loss
│       └── chemical_shifts.py # C-alpha shift loss
├── benchmarks/            # Real-world optimization tests
├── tests/                 # Unit tests (100% coverage)
├── docs/                  # MkDocs documentation
└── pyproject.toml         # Build configuration

🚀 Installation

Ensure you have JAX installed, then install diff-integrator locally:

pip install -e .

🤝 Contributing

Contributions are welcome! Please run the test suite and ensure mypy typing passes before submitting PRs:

pytest --cov=diff_integrator
mypy .

⚖️ License

MIT License — see LICENSE for details.

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_integrator-0.1.1.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

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

diff_integrator-0.1.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file diff_integrator-0.1.1.tar.gz.

File metadata

  • Download URL: diff_integrator-0.1.1.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for diff_integrator-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cd5c22e863e7906a08a14effc80550ef273683373869a7c1ebaec1076658ce39
MD5 a9233b3081466249c619cadd5e4de518
BLAKE2b-256 1ce20776f6b7271bcc2371691bc2f670b89b16ff7c3df324f5b1d2361b1bce92

See more details on using hashes here.

Provenance

The following attestation bundles were made for diff_integrator-0.1.1.tar.gz:

Publisher: publish.yml on elkins-lab/diff-integrator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file diff_integrator-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: diff_integrator-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for diff_integrator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2d818d4a1a75183565a66fa1d9a42a119c5a295c5b9e5ede5588515bbf64f6c
MD5 adee0b0255dd1bc5f1c8e989f6ab31f0
BLAKE2b-256 1976f0795ff48c502b01cdfd8d7cccd7d982c9fccea8a7fca46a4319ecf6172f

See more details on using hashes here.

Provenance

The following attestation bundles were made for diff_integrator-0.1.1-py3-none-any.whl:

Publisher: publish.yml on elkins-lab/diff-integrator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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