Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
128 changes: 128 additions & 0 deletions examples/diffusion_model.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "64deaa41",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"from easydynamics.sample_model import BrownianTranslationalDiffusion\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "784d9e82",
"metadata": {},
"outputs": [],
"source": [
"# Create Brownian Translational Diffusion model and plot the model for different Q values.\n",
"# Q is in Angstrom^-1 and energy in meV.\n",
"\n",
"Q=np.linspace(0.5,2,7)\n",
"# energy=np.linspace(-2, 2, 501)\n",
"energy=sc.linspace(start=-2,stop=2,num=501,unit=\"meV\",dim='energy')\n",
"scale=1.0\n",
"diffusion_coefficient = 2.4e-9 # m^2/s\n",
"diffusion_unit= \"m**2/s\"\n",
"\n",
"diffusion_model=BrownianTranslationalDiffusion(display_name=\"DiffusionModel\", scale=scale, diffusion_coefficient= diffusion_coefficient, diffusion_unit=diffusion_unit)\n",
"\n",
"component_collections=diffusion_model.create_component_collections(Q)\n",
"\n",
"\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('Brownian Translational Diffusion Model') "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dce619d8",
"metadata": {},
"outputs": [],
"source": [
"energy=np.linspace(-2, 2, 501)\n",
"energy=sc.linspace(start=-2,stop=2,num=501,unit=\"meV\",dim='energy')\n",
"energy"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "555cb19a",
"metadata": {},
"outputs": [],
"source": [
"component_collections[0].get_all_parameters()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7247d79d",
"metadata": {},
"outputs": [],
"source": [
"component_collections[0].get_all_parameters()[2].dependency_expression"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "04e99b93",
"metadata": {},
"outputs": [],
"source": [
"diffusion_model.diffusion_coefficient=5.0e-9"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "486cb003",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "easydynamics_newbase",
"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.12.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
4 changes: 4 additions & 0 deletions src/easydynamics/sample_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
Polynomial,
Voigt,
)
from .diffusion_model.brownian_translational_diffusion import (
BrownianTranslationalDiffusion,
)

__all__ = [
"ComponentCollection",
Expand All @@ -16,4 +19,5 @@
"DeltaFunction",
"DampedHarmonicOscillator",
"Polynomial",
"BrownianTranslationalDiffusion",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note, maybe you don't want everything exposed at the top-level?
More obscure/rare functionality makes sense to require a full path to import, just like how it makes sense to import your components from the components group:

from easydynamic.sample_model.components import Gaussian, Lorentzian

Rather than:

from easydynamics import Gaussian

Or whatever your modules are called. Just a note for consideration :)

]
7 changes: 7 additions & 0 deletions src/easydynamics/sample_model/diffusion_model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .brownian_translational_diffusion import BrownianTranslationalDiffusion
from .diffusion_model_base import DiffusionModelBase

__all__ = [
"DiffusionModelBase",
"BrownianTranslationalDiffusion",
]
Loading