Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
138 changes: 138 additions & 0 deletions docs/docs/tutorials/delta_lorentz.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"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},\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()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "533dc719",
"metadata": {},
"outputs": [],
"source": [
"diffusion_model.get_free_parameters()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "742005ce",
"metadata": {},
"outputs": [],
"source": [
"component_collections[1].get_all_parameters()"
]
}
],
"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