-
Notifications
You must be signed in to change notification settings - Fork 1
Diffusion model #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Diffusion model #64
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
774c0a8
Brownian diffusion with example and test
henrikjacobsenfys fab4aee
polishing
henrikjacobsenfys a118a31
Move tests to where they belong
henrikjacobsenfys c5fafaf
Updates based on PR comments
henrikjacobsenfys ff2ddca
Remove parameters as input
henrikjacobsenfys 5df823d
Updates based on PR comments
henrikjacobsenfys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
Rather than:
Or whatever your modules are called. Just a note for consideration :)