Permalink
Browse files

Adding new density of states notebook example.

  • Loading branch information...
1 parent 0f16a10 commit b55bc76093e8653b536aa6c97f9505ecec393d7e @ellisonbg ellisonbg committed with ellisonbg Jun 6, 2011
Showing with 1 addition and 0 deletions.
  1. +1 −0 docs/examples/notebooks/dos.ipynb
@@ -0,0 +1 @@
+{"cells":[{"code":"%notebook save dos.ipynb","cell_type":"code","prompt_number":5},{"code":"from sympy import *\nimport numpy as np\nimport math","cell_type":"code","prompt_number":1},{"cell_type":"text","text":"<h2>Strutinsky Energy Averaging Method</h2>"},{"cell_type":"text","text":"Define a callable class for computing the smooth part of the density of states $\\tilde{g}_m(E)$ with curvature\ncorrection of order $2M$."},{"code":"class SmoothDOS(object):\n\n def __init__(self, energies):\n self.energies = energies\n\n def gaussian_smoothing_func(self, M, x):\n return (mpmath.laguerre(M,0.5,x**2)*exp(-x**2)/sqrt(pi)).evalf()\n\n def __call__(self, e, M=3, gamma=1.0):\n return sum(self.gaussian_smoothing_func(M, (e-ei)/gamma)/gamma for ei in self.energies)","cell_type":"code","prompt_number":67},{"code":"def avgf(M, x):\n return (mpmath.laguerre(M,0.5,x**2)*exp(-x**2)/sqrt(pi)).evalf()","cell_type":"code","prompt_number":14},{"code":"def smooth_dos(gamma, M, e, energies):\n return sum(avgf(M, (e-ei)/gamma)/gamma for ei in energies)","cell_type":"code","prompt_number":2},{"cell_type":"text","text":"<h2>1D Simple Harmonic Oscillator DOS</h2>"},{"code":"def sho_smooth_dos(e):\n \"\"\"Compute the exact smooth DOS.\"\"\"\n return 1","cell_type":"code","prompt_number":2},{"code":"def sho_spectrum(nmax):\n \"\"\"Compute the first nmax energies of the 1D SHO.\"\"\"\n return [n+0.5 for n in range(nmax)]","cell_type":"code","prompt_number":51},{"code":"sho_evalues = np.linspace(0.0,20,100)","cell_type":"code","prompt_number":63},{"code":"sho_dos = SmoothDOS(sho_spectrum(30))","cell_type":"code","prompt_number":68},{"code":"sho_exact_dos = [sho_smooth_dos(e) for e in evalues]","cell_type":"code","prompt_number":69},{"code":"sho_approx_dos = [sho_dos(e,M=3,gamma=10.0) for e in evalues]","cell_type":"code","prompt_number":72},{"code":"plot(evalues, sho_exact, label=\"exact\")\nplot(evalues, sho_approx, label=\"approx\")\ntitle(\"Smooth part of the DOS for the 1D SHO\")\nxlabel(\"Energy\"); ylabel(\"$g(E)$\")\nlegend(loc=4)","cell_type":"code","prompt_number":73},{"cell_type":"text","text":"Note how the exact smoothed DOS and the Strutinsky approximation agree once the energy is away from\n0. In general, these are edge effects and are also present at the right limit if you don't use enough energy\nlevels. Here we have used 30, so the right side doesn't show these artifacts."},{"cell_type":"text","text":"<h2>1D Particle in a BOX (PIAB) DOS</h2>"},{"code":"def piab_smooth_dos(e):\n \"\"\"Compute the exact smooth DOS.\"\"\"\n return 1.0/(2.0*math.sqrt(e*math.pi**2/2))","cell_type":"code","prompt_number":76},{"code":"def piab_spectrum(nmax):\n \"\"\"Compute the first nmax energies of the 1D PIAB.\"\"\"\n return [0.5*math.pi**2*(n+1)**2 for n in range(nmax)]","cell_type":"code","prompt_number":77},{"code":"piab_evalues = linspace(1.0,1000.0,100)","cell_type":"code","prompt_number":78},{"code":"piab_dos = SmoothDOS(piab_spectrum(20))","cell_type":"code","prompt_number":79},{"code":"piab_exact_dos = [piab_smooth_dos(e) for e in piab_evalues]","cell_type":"code","prompt_number":80},{"code":"piab_approx_dos = [piab_dos(e, M=4, gamma=150.0) for e in piab_evalues]","cell_type":"code","prompt_number":81},{"code":"plot(piab_evalues, piab_exact, label=\"exact\")\nplot(piab_evalues, piab_approx, label=\"approx\")\ntitle(\"Smooth part of the DOS for the 1D PIAB\")\nxlabel(\"Energy\"); ylabel(\"$g(E)$\")\nlegend(loc=1)","cell_type":"code","prompt_number":85},{"code":"","cell_type":"code","prompt_number":24}]}

0 comments on commit b55bc76

Please sign in to comment.