Skip to content

Add sphere and isotropic rotational diffusion models - #280

Open
markbujehein wants to merge 22 commits into
easyscience:developfrom
markbujehein:rotational-diffusion-models
Open

markbujehein wants to merge 22 commits into
easyscience:developfrom
markbujehein:rotational-diffusion-models

Conversation

@markbujehein

@markbujehein markbujehein commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Adds two diffusion models, both build on DeltaLorentzianDiffusionModelBase from #279.

The models

  • DiffusionInSphere: a particle diffusing inside a sphere it cannot leave. [Volino and Dianoux]
  • IsotropicRotationalDiffusion: a scatterer at a fixed distance from a centre, such as a hydrogen atom in a freely tumbling molecule, moving over the surface of that sphere by rotational diffusion. [Sears]

Both give an elastic line plus a series of Lorentzians. In theory the series is infinite, so each model keeps a limited number of terms (based on how this is handled in other libraries)

  • The sphere model can use up to 98 terms, the same set as Mantid, and uses 10 by default.
  • The rotational model uses orders up to l_max: 6 by default (enough up to QR of about 4.3), and at most 20.

The defaults are kept low for speed. Every term adds two dependent Parameters per Q, and updating dependent Parameters slows down as their number grows, a known issue.
Users who need higher Q or a larger sphere can raise the number of terms (a warning tells them when that is needed).

Spherical Bessel functions

Both models need the Spherical Bessel Function of the First Kind:

  • Inside the dependency expressions that link the components to the model parameters. These cannot call SciPy, so spherical_bessel_expression writes each function out as an ordinary formula.
  • Everywhere else, through easydynamics.utils.spherical_bessel.spherical_jn. Numba is added as an optional dependency, which offers a speed-up in some cases. Without numba it uses scipy.special.spherical_jn and gives the same values.
  • Two different approaches are being tried out here, and I'm not entirely sure what makes the most sense.

The Spherical Bessel Function of the First Kind allow a bunch of rotational diffusion models to now be added.


Related:

markbujehein and others added 22 commits October 26, 2026 11:13
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clarify equations, parameters, and references across multiple classes.
- Introduced a new tutorial notebook for the equivalent sites on a circle model, detailing the mathematical framework and providing visualizations.
- Added a tutorial for the 3D Gaussian model, explaining diffusion in a harmonic potential and including relevant plots.
- Created a tutorial for jump sites with a log-normal distribution, extending the equivalent sites model to disordered environments with log-normal jump rates.
- Updated mkdocs.yml to include links to the new tutorials.
- Enhanced documentation in the equivalent sites circle model and jump sites log-normal distribution code to clarify model parameters and references.
Clarify diffusion model details more clearly and explicitly
Solves Ruff throwing 'useless-expression' during notebook-lint-check
Test that the circle, log-normal and 3D Gaussian models reject a non-float Q,
and test the delta_name and delta_display_name setters of the base class.
Rename the base-class test model from Toy to DummyDiffusionModel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
numba is an optional extra ('fast'), and a dev dependency so the fast
path is tested. The lock adds conda numba and llvmlite for the dev
environments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes failing patch coverage reported by Codecov
- Introduced the IsotropicRotationalDiffusion class for modeling isotropic rotational diffusion of scatterers.
- Updated the mkdocs.yml to include a tutorial for the new model.
- Modified the __init__.py files to import the new model and include it in the public API.
- Added unit and integration tests for the IsotropicRotationalDiffusion model, covering construction, parameter validation, physics calculations, and component behavior.
- Ensured that the model adheres to expected physical properties and provides accurate outputs for various input parameters.
@easyscience

easyscience Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Label error. Requires at least 1 of: [bot] release, [scope] bug, [scope] documentation, [scope] enhancement, [scope] maintenance, [scope] significant. Found:

@markbujehein
markbujehein marked this pull request as ready for review October 26, 2026 15:31
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.57128% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.40%. Comparing base (b1d6773) to head (f95da61).

Files with missing lines Patch % Lines
src/easydynamics/utils/spherical_bessel.py 86.20% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #280      +/-   ##
===========================================
+ Coverage    98.23%   98.40%   +0.17%     
===========================================
  Files           61       70       +9     
  Lines         6227     7160     +933     
  Branches      1039     1121      +82     
===========================================
+ Hits          6117     7046     +929     
- Misses          57       61       +4     
  Partials        53       53              
Flag Coverage Δ
unittests 98.40% <99.57%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/easydynamics/__init__.py 100.00% <100.00%> (ø)
src/easydynamics/sample_model/__init__.py 100.00% <100.00%> (ø)
...ydynamics/sample_model/diffusion_model/__init__.py 100.00% <100.00%> (ø)
...ion_model/delta_lorentzian_diffusion_model_base.py 100.00% <100.00%> (ø)
...ample_model/diffusion_model/diffusion_in_sphere.py 100.00% <100.00%> (ø)
...e_model/diffusion_model/equivalent_sites_circle.py 100.00% <100.00%> (ø)
.../sample_model/diffusion_model/gaussian_model_3d.py 100.00% <100.00%> (ø)
..._model/diffusion_model/hall_ross_jump_diffusion.py 100.00% <100.00%> (ø)
.../diffusion_model/isotropic_rotational_diffusion.py 100.00% <100.00%> (ø)
...fusion_model/jump_sites_log_normal_distribution.py 100.00% <100.00%> (ø)
... and 2 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant