Skip to content
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

added interactive features to first_principles example notebook #67

Merged
merged 5 commits into from
Jun 27, 2024
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
78 changes: 75 additions & 3 deletions examples/ideal_gas_law/first_principles.ipynb
Original file line number Diff line number Diff line change
@@ -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": {},
Expand All @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
1 change: 0 additions & 1 deletion pylj/forcefields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
from numba import njit


class lennard_jones(object):
Expand Down
1 change: 0 additions & 1 deletion pylj/md.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
7 changes: 3 additions & 4 deletions pylj/pairwise.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pylj/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import numpy as np
import webbrowser
from pylj import md, mc
from numba import njit


class System:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ jupyter
cython
numpy>=1.16
matplotlib
numba
coverage
coveralls
ipympl
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
'author_email': '[email protected]',
'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,
Expand Down
Loading