Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6b995a8
Add DeltaLorentz model
henrikjacobsenfys May 13, 2026
09ec995
update to allow multiple A0 and A1
henrikjacobsenfys May 13, 2026
fb3341a
formatting
henrikjacobsenfys May 15, 2026
f3fb53d
Merge branch 'develop' into delta-lorentz
henrikjacobsenfys May 19, 2026
f127d44
update delta_lorentz model
henrikjacobsenfys May 20, 2026
81d38ca
remove unit property from model_base
henrikjacobsenfys May 20, 2026
dce5689
Make som progress on implementing Q in diffusion models
henrikjacobsenfys May 20, 2026
1eb7bbc
pixi run fix
henrikjacobsenfys May 20, 2026
49643a7
small docstring updates
henrikjacobsenfys May 20, 2026
0186e9e
Fix some tests
henrikjacobsenfys May 22, 2026
a94138b
all tests pass
henrikjacobsenfys May 22, 2026
d216909
Merge branch 'develop' into delta-lorentz
henrikjacobsenfys May 22, 2026
a5eb112
Add name and display name for components of diffusion models
henrikjacobsenfys May 23, 2026
b9eec8e
Update init, write some tests
henrikjacobsenfys May 26, 2026
f237d92
Fix minor bug
henrikjacobsenfys May 26, 2026
bd05e84
tests
henrikjacobsenfys May 26, 2026
ad6b5cf
More tests
henrikjacobsenfys May 26, 2026
8a58777
Minor fix
henrikjacobsenfys May 26, 2026
9c1e753
another minor fix
henrikjacobsenfys May 26, 2026
0f724ff
More tests
henrikjacobsenfys May 26, 2026
061fabe
update get_all_variables
henrikjacobsenfys May 27, 2026
c35370e
Update get_all_variables and pixi
henrikjacobsenfys May 27, 2026
636693c
A few tests and related fixes
henrikjacobsenfys May 27, 2026
f52856c
A few more tests
henrikjacobsenfys May 28, 2026
f820514
Finish delta_lorentz tests
henrikjacobsenfys May 28, 2026
b6287cb
PR comments
henrikjacobsenfys May 28, 2026
699c762
fix parameter bug
henrikjacobsenfys May 29, 2026
40cfb47
small bug fix
henrikjacobsenfys May 29, 2026
c1cc9dd
Fix bug with parameters in sample model
henrikjacobsenfys May 29, 2026
38ecbae
more tests
henrikjacobsenfys May 29, 2026
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
118 changes: 118 additions & 0 deletions docs/docs/tutorials/delta_lorentz.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"# Delta Lorentz\n",
"Model of Delta function and Lorentzian with intensities given by the Debye-Waller factor:\n",
"\n",
"$ I\n",
"= K \\exp \\left( \\frac{-\\langle u^2 \\rangle Q^2}{3} \\right)[A_0 \\delta(E) + A_1 L(E, \\Gamma)]\n",
"$,\n",
"\n",
"where $K$ is the scale factor, $\\langle u^2 \\rangle$ is the mean square displacement, $Q$ is\n",
"the scattering vector, $A_0$ and $A_1$ are the relative amplitudes of the delta function and\n",
"Lorentzian, respectively, with the constraint that $A_0+A_1=1$, and $L(E, \\Gamma)$ is the\n",
"Lorentzian function with width $\\Gamma$. $A_0$, $A_1$ and the width of the Lorentzian can be\n",
"the same at all $Q$ or be allowed to vary with $Q$.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from easydynamics.sample_model.diffusion_model.delta_lorentz import DeltaLorentz\n",
"\n",
"%matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6d6e1984",
"metadata": {},
"outputs": [],
"source": [
"Q = np.linspace(0.5, 2, 7)\n",
"energy = np.linspace(-2, 2, 501)\n",
"scale = 1.0\n",
"mean_u_squared = 0.5\n",
"A_0 = 0.2\n",
"lorentzian_width = 0.2\n",
"\n",
"diffusion_model = DeltaLorentz(\n",
" scale=scale,\n",
" mean_u_squared=mean_u_squared,\n",
" A_0=A_0,\n",
" lorentzian_width=lorentzian_width,\n",
" allow_Q_variation={'A_0': True, 'lorentzian_width': True},\n",
" Q=Q,\n",
" lorentzian_name='Lorentzian',\n",
" delta_name='Delta function',\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "389aa3cd",
"metadata": {},
"outputs": [],
"source": [
"component_collections = diffusion_model.get_component_collections()\n",
"cmap = plt.cm.jet\n",
"nQ = len(component_collections)\n",
"plt.figure()\n",
"for Q_index in range(len(component_collections)):\n",
" color = cmap(Q_index / (nQ - 1))\n",
" y = component_collections[Q_index].evaluate(energy)\n",
" plt.plot(energy, y, label=f'Q={Q[Q_index]} Å^-1', color=color)\n",
"\n",
"plt.legend()\n",
"plt.show()\n",
"plt.xlabel('Energy (meV)')\n",
"plt.ylabel('Intensity (arb. units)')\n",
"plt.title('Delta-Lorentz Model')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf360b45",
"metadata": {},
"outputs": [],
"source": [
"diffusion_model.get_all_variables()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.14.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
12 changes: 5 additions & 7 deletions docs/docs/tutorials/diffusion_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"metadata": {},
"source": [
"# Diffusion Model\n",
"We support several standard models of diffusion. Here we show an example of Browniand Translational Diffusion, where the scattering is a Lorentzian with width ($\\Gamma$) given by $\\Gamma = D Q^2$, where $D$ is the diffusion coefficient (in m$^2$/s) and $Q$ is the momentum transfer."
"We support several standard models of diffusion. Here we show an example of Brownian Translational Diffusion, where the scattering is a Lorentzian with width ($\\Gamma$) given by $\\Gamma = D Q^2$, where $D$ is the diffusion coefficient (in m$^2$/s) and $Q$ is the momentum transfer."
]
},
{
Expand Down Expand Up @@ -41,12 +41,10 @@
"diffusion_coefficient = 2.4e-9 # m^2/s\n",
"\n",
"diffusion_model = BrownianTranslationalDiffusion(\n",
" display_name='DiffusionModel',\n",
" scale=scale,\n",
" diffusion_coefficient=diffusion_coefficient,\n",
" display_name='DiffusionModel', scale=scale, diffusion_coefficient=diffusion_coefficient, Q=Q\n",
")\n",
"\n",
"component_collections = diffusion_model.create_component_collections(Q)\n",
"component_collections = diffusion_model.get_component_collections()\n",
"\n",
"\n",
"cmap = plt.cm.jet\n",
Expand Down Expand Up @@ -87,7 +85,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "easydynamics_newbase",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -101,7 +99,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.12"
"version": "3.14.4"
}
},
"nbformat": 4,
Expand Down
3 changes: 3 additions & 0 deletions docs/docs/tutorials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ tutorials.
balancing.
- [Diffusion model](diffusion_model.ipynb) – Learn how to create and use
a model of diffusion.
- [DeltaLorentz](delta_lorentz.ipynb) – Learn how to create and use a
model with a Delta function and a Lorentzian that have a shared
Debye-Waller-like Q-dependence.
- [Sample model](sample_model.ipynb) – Learn how to create a model of
the scattering from your sample including model components and
diffusion models.
Expand Down
12 changes: 11 additions & 1 deletion docs/docs/tutorials/tutorial0_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@
"id": "dc33728c",
"metadata": {},
"source": [
"To see the parameters we can use the `get_all_parameters()` method:"
"To see the parameters we can use the `get_all_parameters()` method. We can also see only the parameters that can be fitted:"
]
},
{
Expand All @@ -464,6 +464,16 @@
"source": [
"parameter_analysis.get_all_parameters()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "068f755c",
"metadata": {},
"outputs": [],
"source": [
"parameter_analysis.get_fittable_parameters()"
]
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/tutorials/tutorial0_more_advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"id": "4c8e97b7",
"metadata": {},
"source": [
"As before, we createa an `Experiment` to hold the data, and rebin it."
"As before, we create an `Experiment` to hold the data, and rebin it."
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/tutorials/tutorial1_brownian.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@
"metadata": {},
"outputs": [],
"source": [
"diffusion_model.get_all_parameters()"
"diffusion_model.get_global_variables()"
]
},
{
Expand All @@ -706,7 +706,7 @@
"metadata": {},
"outputs": [],
"source": [
"parameter_analysis.get_all_parameters()"
"parameter_analysis.get_all_variables()"
]
}
],
Expand Down
Loading
Loading