-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNISTISODB.py
70 lines (67 loc) · 3.7 KB
/
NISTISODB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python 2
import json
import requests
#Defines an isotherm object class
#NOTE: This class was rewritten in 2018 to be compatible with the 2017 isotherm standard (multicomponent-capable)
class NIST_ISODB_isotherm:
def __init__(self,filename):
host='adsorption.nist.gov'
URL = 'https://'+host+'/isodb/api/isotherm/'+filename
isotherm_JSON = json.loads(requests.get(URL).content)
#----------------------------------------------------------------
#Essential Check: Confirm that input isotherm is single component
n_adsorbates = len(isotherm_JSON["adsorbates"])
if n_adsorbates > 1:
raise Exception("ERROR: Filename "+filename+" has multiple adsorbates.\n Input isotherm must be single component.")
#----------------------------------------------------------------
self.filename = filename
self.pressureUnits = isotherm_JSON["pressureUnits"]
self.adsorptionUnits = isotherm_JSON["adsorptionUnits"]
self.p_label = "Pressure ("+self.pressureUnits+")"
self.ads_label = "Loading ("+self.adsorptionUnits+")"
self.p_list = [ point["pressure"] for point in isotherm_JSON["isotherm_data"] ]
# Uses the first entry (index 0) as the isotherm is single component, or would have failed earlier test
self.ads_list = [ point["species_data"][0]["adsorption"] for point in isotherm_JSON["isotherm_data"] ]
self.adsorbate = isotherm_JSON["adsorbates"][0]
self.adsorbent = isotherm_JSON["adsorbent"]
self.temperature = float(isotherm_JSON["temperature"])
def error_check_isotherms(isotherms):
#Basic System Checks:
print( 'ESSENTIAL SYSTEM CHECKS: ')
# Confirm that pressure units are consistent
pressure_units = [ isotherm.pressureUnits for isotherm in isotherms ]
if len(set(pressure_units)) > 1:
print('ERROR: Incompatible pressure units in isotherms')
for (i,isotherm) in enumerate(isotherms):
print( ' Isotherm '+str(i+1)+": "+isotherm.pressureUnits )
raise ValueError("Incompatible pressure units in isotherms")
else:
print('Pressure units are compatible: '+list(set(pressure_units))[0] )
# Confirm that adsorption units are consistent
adsorption_units = [ isotherm.adsorptionUnits for isotherm in isotherms ]
if len(set(adsorption_units)) > 1:
print('ERROR: Incompatible adsorption units in isotherms')
for (i,isotherm) in enumerate(isotherms):
print( ' Isotherm '+str(i+1)+": "+isotherm.adsorptionUnits )
raise ValueError("Incompatible adsorption units in isotherms")
else:
print('Adsorption units are compatible: '+list(set(adsorption_units))[0] )
# Confirm that the material is the same across the isotherms
material_hashes = [ isotherm.adsorbent["hashkey"] for isotherm in isotherms ]
material_names = [ isotherm.adsorbent["name"] for isotherm in isotherms ]
if len(set(material_hashes)) > 1:
print( 'WARNING: Different Materials Specified' )
for (i,isotherm) in enumerate(isotherms):
print( ' Isotherm '+str(i+1)+": "+isotherm.adsorbent["name"] )
else:
print( 'Same material is specified: '+list(set(material_names))[0] )
# Confirm that the temperature is consistent
temperatures = [ isotherm.temperature for isotherm in isotherms ]
if len(set(temperatures)) > 1:
print('ERROR: Different temperatures in isotherms')
for (i,isotherm) in enumerate(isotherms):
print( ' Isotherm '+str(i+1)+": "+isotherm.temperatures )
raise ValueError("Different temperatures in isotherms")
else:
print('Temperature is consistent: '+str(list(set(temperatures))[0]) )
return None