From 0d95dc44de8b17395e50eee5f63c062a5c87ab1c Mon Sep 17 00:00:00 2001 From: maxdolan Date: Wed, 26 Jun 2024 16:57:00 +0100 Subject: [PATCH 1/5] added interactive features --- examples/ideal_gas_law/first_principles.ipynb | 78 ++++++++++++++++++- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/examples/ideal_gas_law/first_principles.ipynb b/examples/ideal_gas_law/first_principles.ipynb index 984c75b..23c4cfa 100644 --- a/examples/ideal_gas_law/first_principles.ipynb +++ b/examples/ideal_gas_law/first_principles.ipynb @@ -1,5 +1,15 @@ { "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -15,9 +25,39 @@ "where, $V$ is the volume of the system and $\\Lambda$ is the de Broglie thermal wavelength, \n", "\n", "$$\n", - "\\Lambda = \\bigg(\\frac{\\beta h^2}{2\\pi m}\\bigg)^{1/2}.\n", - "$$\n", + "\\Lambda = \\bigg(\\frac{\\beta h^2}{2\\pi m}\\bigg)^{1/2} = \\bigg(\\frac{h^2}{2 k_B T \\pi m}\\bigg)^{1/2}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The De Broglie wavelength for an electron can be calculated using electron mass:\n", + "\n", + "$$m_e = 9.11*10^{-31}$$ \n", + "\n", + "Write a function that calculates the De Broglie wavelength for an electron at room temp (293k)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "m_e = 9.11e-31\n", + "h = 6.626e-34\n", + "k_b = 1.38e-23\n", "\n", + "def db_wavelength(T)\n", + " return ◽◽◽" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "The most useful way to work with the partition function is in its logarithmic form, \n", "\n", "$$\n", @@ -49,12 +89,44 @@ "$$" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the cell below, write a function that calculates the pressure using the ideal gas law" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def ideal_pressure(◽◽◽,◽◽◽,◽◽◽)\n", + " return ◽◽◽" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "See how this changes for a range of temperatures" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "T = ◽◽◽\n", + "p = ideal_pressure(◽◽◽,◽◽◽,◽◽◽)\n", + "\n", + "plt.plot(T, p)\n", + "plt.xlabel('Temperature')\n", + "plt.ylabel('Ideal Pressure')\n", + "plt.show()" + ] } ], "metadata": { From 98bc324746a91e67a1fecd386e5f9e665f6f3d8b Mon Sep 17 00:00:00 2001 From: maxdolan Date: Wed, 26 Jun 2024 19:42:01 +0100 Subject: [PATCH 2/5] removed useless jit import messages --- pylj/forcefields.py | 1 - pylj/md.py | 1 - pylj/util.py | 1 - 3 files changed, 3 deletions(-) diff --git a/pylj/forcefields.py b/pylj/forcefields.py index bdb2e51..ddc59e2 100644 --- a/pylj/forcefields.py +++ b/pylj/forcefields.py @@ -1,5 +1,4 @@ import numpy as np -from numba import njit class lennard_jones(object): diff --git a/pylj/md.py b/pylj/md.py index 859ba3d..86e9268 100644 --- a/pylj/md.py +++ b/pylj/md.py @@ -1,7 +1,6 @@ import numpy as np from pylj import pairwise as heavy from pylj import forcefields as ff -from numba import njit def initialise( diff --git a/pylj/util.py b/pylj/util.py index 5888519..eda0122 100644 --- a/pylj/util.py +++ b/pylj/util.py @@ -2,7 +2,6 @@ import numpy as np import webbrowser from pylj import md, mc -from numba import njit class System: From e83bd8db4c41588bab670e0ee912b671167a7eb6 Mon Sep 17 00:00:00 2001 From: maxdolan Date: Thu, 27 Jun 2024 10:49:47 +0100 Subject: [PATCH 3/5] removing final numba tags --- pylj/pairwise.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pylj/pairwise.py b/pylj/pairwise.py index fd0e26a..72f2f60 100644 --- a/pylj/pairwise.py +++ b/pylj/pairwise.py @@ -1,6 +1,5 @@ from __future__ import division import numpy as np -from numba import njit, jit from pylj import pairwise as heavy #Jit tag here had to be removed @@ -56,7 +55,7 @@ def compute_force(particles, box_length, cut_off, constants, forcefield, mass): particles = update_accelerations(particles, forces, mass_kg, dx, dy, distances) return particles, distances, forces, energies -@njit +#Jit tag here had to be removed def separation(dx, dy): """Calculate the distance in 2D space. Parameters @@ -290,7 +289,7 @@ def heat_bath(particles, temperature_sample, bath_temp): return particles -@njit +#Jit tag here had to be removed def dist(xposition, yposition, box_length): """Returns the distance array for the set of particles. Parameters @@ -330,7 +329,7 @@ def dist(xposition, yposition, box_length): return drr, dxr, dyr -@njit +#Jit tag here had to be removed def pbc_correction(position, cell): """Correct for the periodic boundary condition. Parameters From 68a2ce292fd591007fb71d96e8125a045112afd1 Mon Sep 17 00:00:00 2001 From: Max Dolan <147044155+maximillian-dolan@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:50:48 +0100 Subject: [PATCH 4/5] removing numba from requirements.txt --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e8f5d5d..fe893d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,6 @@ jupyter cython numpy>=1.16 matplotlib -numba coverage coveralls ipympl From 3a26f69d800b8003718899ed76a8f36a8208e9d0 Mon Sep 17 00:00:00 2001 From: Max Dolan <147044155+maximillian-dolan@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:52:16 +0100 Subject: [PATCH 5/5] remove numba from setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 062f115..f8b4a8f 100644 --- a/setup.py +++ b/setup.py @@ -25,8 +25,8 @@ 'author_email': 'arm61@bath.ac.uk', 'packages': packages, 'include_package_data': True, - 'setup_requires': ['jupyter', 'numpy', 'matplotlib', 'cython', 'numba'], - 'install_requires': ['jupyter', 'numpy', 'matplotlib', 'cython', 'numba'], + 'setup_requires': ['jupyter', 'numpy', 'matplotlib', 'cython'], + 'install_requires': ['jupyter', 'numpy', 'matplotlib', 'cython'], 'version': VERSION, 'license': 'MIT', 'long_description': long_description,