In [1]:
import pygaps
The backbone of the framework is the PointIsotherm class. This class stores the isotherm data alongside isotherm properties such as the material, adsorbate and temperature, as well as providing easy interaction with the framework calculations. There are several ways to create a PointIsotherm object:
See the isotherm creation part of the documentation for a more in-depth explanation. For the simplest method, the data can be passed in as arrays of pressure and loading. There are four other required parameters: the material name, the material batch or ID, the adsorbate used and the temperature (in K) at which the data was recorded.
In [2]:
isotherm = pygaps.PointIsotherm(
pressure=[0.1, 0.2, 0.3, 0.4, 0.5, 0.4, 0.35, 0.25, 0.15, 0.05],
loading=[0.1, 0.2, 0.3, 0.4, 0.5, 0.45, 0.4, 0.3, 0.15, 0.05],
material= 'Carbon X1',
adsorbate = 'N2',
temperature = 77,
)
isotherm.plot()
Unless specified, the loading is read in mmol/g and the pressure is read in bar, although these settings can be changed. Read more about it in the units section of the manual. The isotherm can also have other properties which are passed in at creation.
Alternatively, the data can be passed in the form of a pandas.DataFrame. This allows for other complementary data, such as isosteric enthalpy, XRD peak intensity, or other simultaneous measurements corresponding to each point to be saved.
The DataFrame should have at least two columns: the pressures
at which each point was recorded, and the loadings for each point.
The loading_key
and pressure_key
parameters specify which column in the DataFrame
contain the loading and pressure, respectively. The other_keys
parameter
should be a list of other columns to be saved.
In [3]:
import pandas
data = pandas.DataFrame({
'pressure': [0.1, 0.2, 0.3, 0.4, 0.5, 0.45, 0.35, 0.25, 0.15, 0.05],
'loading': [0.1, 0.2, 0.3, 0.4, 0.5, 0.5, 0.4, 0.3, 0.15, 0.05],
'isosteric_enthalpy (kJ/mol)': [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
})
isotherm = pygaps.PointIsotherm(
isotherm_data=data,
pressure_key='pressure',
loading_key='loading',
other_keys=['isosteric_enthalpy (kJ/mol)'],
material= 'Carbon X1',
adsorbate = 'N2',
temperature = 77,
pressure_unit='bar',
pressure_mode='absolute',
loading_unit='mmol',
loading_basis='molar',
adsorbent_unit='g',
adsorbent_basis='mass',
material_batch = 'Batch 1',
iso_type='characterisation'
)
isotherm.plot()
In [4]:
with open(r'data/carbon_x1_n2.json') as f:
isotherm = pygaps.isotherm_from_json(f.read())
To see a summary of the isotherm as well as a graph, use the included function:
In [5]:
isotherm.print_info()
Now that the PointIsotherm is created, we are ready to do some analysis.
The framework has several isotherm analysis tools which are commonly used to characterise porous materials such as:
All methods work directly with generated Isotherms. For example, to perform a tplot analysis and get the results in a dictionary use:
In [6]:
result_dict = pygaps.t_plot(isotherm)
import pprint
pprint.pprint(result_dict)
If in an interactive environment, such as iPython or Jupyter, it is useful to see the details of the calculation directly. To do this, increase the verbosity of the method and use matplotlib to display extra information, including graphs:
In [7]:
import matplotlib.pyplot as plt
result_dict = pygaps.area_BET(isotherm, verbose=True)
plt.show()
Depending on the method, different parameters can be passed to tweak the way the calculations are performed. For example, if a mesoporous size distribution is desired using the Dollimore-Heal method on the desorption branch of the isotherm, assuming the pores are cylindrical and that adsorbate thickness can be described by a Halsey-type thickness curve, the code will look like:
In [8]:
result_dict = pygaps.psd_mesoporous(
isotherm,
psd_model='DH',
branch='des',
pore_geometry='cylinder',
thickness_model='Halsey',
verbose=True,
)
plt.show()
The framework comes with functionality to fit point isotherm data with common isotherm models such as Henry, Langmuir, Temkin, Virial etc.
The modelling is done through the ModelIsotherm class. The class is similar to the PointIsotherm class, and shares the same ability to store parameters. However, instead of data, it stores model coefficients for the model it's describing.
To create a ModelIsotherm, the same parameters dictionary / pandas DataFrame procedure can be used. But, assuming we've already created a PointIsotherm object, we can use it to instantiate the ModelIsotherm instead. To do this we use the class method:
In [9]:
model_iso = pygaps.ModelIsotherm.from_pointisotherm(isotherm, model='BET', verbose=True)
A minimisation procedure will then attempt to fit the model's parameters to the isotherm points. If successful, the ModelIsotherm is returned.
In the user wants to screen several models at once, the class method can also be passed a parameter which allows the ModelIsotherm to select the best fitting model. Below, we will attempt to fit several simple available models, and the one with the best RMSE will be returned. Depending on the models requested, this method may take significant processing time.
In [10]:
model_iso = pygaps.ModelIsotherm.from_pointisotherm(isotherm, guess_model='all', verbose=True)
In [11]:
# Prints isotherm parameters and model info
model_iso.print_info()
We can calculate the loading at any pressure using the internal model by using the loading_at
function.
In [12]:
# Returns the loading at 1 bar calculated with the model
model_iso.loading_at(1.0)
Out[12]:
In [13]:
# Returns the loading in the range 0-1 bar calculated with the model
pressure = [0.1,0.5,1]
model_iso.loading_at(pressure)
Out[13]:
In [14]:
import matplotlib.pyplot as plt
pygaps.plot_iso([isotherm, model_iso], branch='ads')
plt.show()