Last active
December 15, 2020 23:32
-
-
Save skuschel/ffc7bcbfd095d3feda40d21951b02491 to your computer and use it in GitHub Desktop.
Download atomic form factors from henke and NIST directly within python
This file contains 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
import functools | |
import requests | |
from io import StringIO | |
from bs4 import BeautifulSoup | |
from urllib.parse import urljoin | |
# Henke | |
def atomicformfactor_henke(element): | |
element = element.lower() | |
return _download_henke(element) | |
@functools.cache | |
def _atomicformfactor_henke(element): | |
urltmplate = 'https://henke.lbl.gov/optical_constants/sf/{element}.nff' | |
url = urltmplate.format(element=element) | |
r = requests.get(url) | |
data = np.genfromtxt(StringIO(r.text))[1:] | |
f = data[:,1] + 1j*data[:,2] | |
eV = data[:,0] | |
return eV, f | |
# NIST | |
@functools.cache | |
def atomicformfactor_nist(Z): | |
#baseurl = 'https://physics.nist.gov/cgi-bin' | |
urltmplate = 'https://physics.nist.gov/cgi-bin/ffast/ffast.pl?gtype=4&Z={Z}' | |
url = urltmplate.format(Z=Z) | |
session = requests.Session() | |
r = session.get(url).content | |
# parse page | |
soup = BeautifulSoup(r) | |
tabledata = soup.select('body > pre')[0].text.splitlines()[3:] | |
tabledata = '\n'.join(tabledata) | |
data = np.genfromtxt(StringIO(tabledata)) | |
eV = data[:, 0] * 1e3 | |
f = data[:,1] + 1j*data[:,2] | |
return eV, f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment