diff --git a/SpectroscoPy/atomic/nist/__init__.py b/SpectroscoPy/atomic/nist/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/SpectroscoPy/atomic/nist/nistIonizationQuery.py b/SpectroscoPy/atomic/nist/nistIonizationQuery.py new file mode 100644 index 0000000..8444973 --- /dev/null +++ b/SpectroscoPy/atomic/nist/nistIonizationQuery.py @@ -0,0 +1,324 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Fri Jul 14 15:18:45 2017 + +Queries NIST database on ionization energies. +Mainly used for generating Saha-Boltzmann plots. + +TODO: +- Add tests for nistIonEnergiesQuery() +- Move status of connection into a log file +-improve this query function by making it a class and allowing for the use + of methods to get different column values +- Use code for generalized query of all energies for all charge states + as this will be a useful speedup +- implement an object that can be returned from this query and methods + that take slices through the table + +@author: Pawel M. Kozlowski +""" + +# importing Python modules +import requests as req +import parse as parse +import re +import numpy as np +import astropy.units as u +import mendeleev as lev + + +def cleanhtml(raw_html): + """ + Cleaning HTML tags using regular expressions + """ + cleanr = re.compile('<.*?>') + cleantext = re.sub(cleanr, '', raw_html) + return cleantext + + +# URL to nist ionization energy database +nistIonizationURL1 = 'https://physics.nist.gov/PhysRefData/ASD/ionEnergy.html' +nistIonizationURL2 = 'https://physics.nist.gov/cgi-bin/ASD/ie.pl' + +# Checking website status +reqObj = req.post(nistIonizationURL1) +print("STATUS:") +print(reqObj.status_code) +if reqObj.status_code == req.codes.ok: + print("OK!") +else: + print("CONNECTION FAILED!") +reqObj.raise_for_status() + +# for testing purposes only +# print("HEADERS:") +# print(reqObj.headers['content-type']) +# print("ENCODING:") +# print(reqObj.encoding) +# print("TEXT:") +# print(reqObj.text) + +#%% NIST levels + + +def nistIonEnergiesQuery(element): + """ + Given an element, and a charge state this + script queries the NIST ionization energy level database and retrieves + the value of ionization energy and its uncertainty. The uncertainty + is given in units of the last decimal place of the value. + Elements (string) + chargeState [dimless integer] + Ionization energy [eV] + Uncertainty [eV] + """ + # checking inputs + if not isinstance(element, str): + raise ValueError("Element must be a string!") + elementCharge = element + # Starting requests session + with req.session() as s: + # values to be filled into website form + payload = {'spectra': elementCharge, # element and charge state + 'submit': 'Retrieve Data', + 'units': '1', # selects energy units eV + 'format': '1', # ASCII output + 'order': '0', # order by Z or sequence + 'at_num_out': 'on', # output atomic number + 'sp_name_out': 'on', # output spectrum name + 'ion_charge_out': 'on', # output ion charge + 'el_name_out': 'on', # output element name + 'seq_out': 'on', # output isoelectronic sequence + 'shells_out': 'on', # output ground-state electronic shells + 'conf_out': 'on', # outpuse ground-state configuration + 'level_out': 'on', # output ground-state level + 'ion_conf_out': 'on', # output ionization configuration + 'e_out': '0', # selects ionization energy not binding + 'unc_out': 'on', # output uncertainty + 'biblio': 'on' # output bibliographic references + } + # website's repsonse to query + response = s.post(nistIonizationURL2, data=payload) +# # for testing purposes only +# print("URL:") +# print(response.url) +# print("STATUS:") +# print(response.status_code) +# print("TEXT:") +# print(response.text) + + # Extract ionization energy value string from HTML/ASCII + # Getting entire ASCII table +# searchStringTable = "
{}"
+ searchStringTable = "{} (atomicNum - 1):
+ raise Exception("Charge state cannot be greater than element's "
+ "atomic number!")
+ # converting integer charge state to Roman numeral
+# chargeStateStr = intToRoman(chargeState)
+ # formatting input strings
+# elementCharge = element + ' ' + chargeStateStr
+ elementCharge = element
+ # Starting requests session
+ with req.session() as s:
+ # values to be filled into website form
+ payload = {'spectra': elementCharge, # element and charge state
+ 'submit': 'Retrieve Data',
+ 'units': '1', # selects energy units eV
+ 'format': '1', # ASCII output
+ 'order': '0', # order by Z or sequence
+ 'at_num_out': 'on', # output atomic number
+ 'sp_name_out': 'on', # output spectrum name
+ 'ion_charge_out': 'on', # output ion charge
+ 'el_name_out': 'on', # output element name
+ 'seq_out': 'on', # output isoelectronic sequence
+ 'shells_out': 'on', # output ground-state electronic shells
+ 'conf_out': 'on', # outpuse ground-state configuration
+ 'level_out': 'on', # output ground-state level
+ 'ion_conf_out': 'on', # output ionization configuration
+ 'e_out': '0', # selects ionization energy not binding
+ 'unc_out': 'on', # output uncertainty
+ 'biblio': 'on' # output bibliographic references
+ }
+ # website's repsonse to query
+ response = s.post(nistIonizationURL2, data=payload)
+# # for testing purposes only
+# print("URL:")
+# print(response.url)
+# print("STATUS:")
+# print(response.status_code)
+# print("TEXT:")
+# print(response.text)
+
+ # Extract ionization energy value string from HTML/ASCII
+ # Getting entire ASCII table
+# searchStringTable = "
{}"
+ searchStringTable = "{}= 1.13)
scipy (>= 0.19)
astropy (>= 2.0)
+mendeleev (>= 0.4.2)
+requests (>= 2.18.4)
+parse (>= 1.8.2)