%matplotlib inline
from micromeritics import util
from micromeritics import isotherm_examples as ex
import matplotlib.pyplot as plt

carb = ex.carbon_black()   # example isotherm of Carbon Black with N2 at 77K
sial = ex.silica_alumina() # example isotherm of Silica Alumina with N2 at 77K
mcm = ex.mcm_41() # example isotherm of MCM 41 with N2 at 77K

fig = plt.figure(figsize=(12,5))
axes = fig.add_subplot(111)
plt.title('Isotherm Plot')
plt.ylabel("Quantity Adsorbed (cm^3/g STP)")
plt.xlabel("Relative Pressure")
plt.gca().set_xscale('linear')
plt.plot( carb.Prel, carb.Qads, 'ro', label='Carbon Black with N2 at 77K' )
plt.plot( sial.Prel, sial.Qads, 'bo-', label='Silica Alumina with N2 at 77K')
plt.plot( mcm.Prel, mcm.Qads, 'go-', label='MCM 41 with N2 at 77K')
legend = axes.legend(loc='upper left', shadow=True)
plt.show()

"""
Explanation: What is an Adsorption Isotherm?
In a typical isotherm analysis, a small sample of material, which one wants to determine the surface properties of, is placed in a test tube and put under vacuum.  A known species of gas such as Nitrogen is then incrementally dosed to the sample tube with each increment followed by a measurement of the equilibrated pressure $P$.  Much of the dosed analysis gas just fills the free space in the sample tube resulting in an increase in gas pressure, but some fraction of the dosed gas is adsorbed to the surface of the sample material, also finding its way into any pores on the surface of the sample.  Using the measurement of the pressures before and after the dose, and using knowledge of the exact amount of gas that was dosed, one may then infer the quantity of gas $Q_{ads}$ that is adsorbed onto the sample.   The series of controlled doses all happens at a nearly constant temperature (typically 77K for Nitrogen analysis), and the convention is to refer to the collected $P$ vs. $Q_{ads}$ data as an "Isotherm."  The above description is somewhat simplified, and the details of the experimental method, the apparatus, and the determination of the quantity adsorbed is explained in detail in many references such as [1].
The quantity of gas adsorbed onto the sample's surface can be expressed as the number of moles of gas $n$.  However the convention is to use the ideal gas law at standard temperature and pressure to represent this quantity as a volume of gas $V = nR T_{STD}/P_{STD}$.  Then dividing by the mass of the sample, the quantities adsorbed $Q_{ads}$ are typically reported in units of $\textrm{cm}^3 / \textrm{g STP}$.  This is the system of units employed here. When discussing particular models however, the number of moles $n$ or the number of molecules $N$ will be employed.
Another convention for isotherm data is to convert absolute pressures to relative pressures.  Specifically, for analysis gases which can condense to a liquid at the analysis temperature, it is the relative pressure which is typically reported rather than the absolute pressure.  The relative pressure is simply $P_{rel} = \frac{P_{abs}}{P_0}$ where $P_{abs}$ is the absolute pressure measured in millimeters Mercury (mmHg) or some other pressure unit and $P_0$ is the saturation pressure of the analysis gas which is also typically measured in the course of the experiment. The relative pressure is a dimensionless quantity.  Many gas adsorption calculations will us relative pressure units rather than the absolute pressure.
[1] Webb, Paul A., and Clyde Orr. Analytical methods in fine particle technology. Micromeritics Instrument Corp, 1997.
Isotherm adsorption data shown in a few representations
A few isotherms from reference data sets are shown below.  These example sets are available on github report-models-python in the 'micromeritics' python package.  Isotherm data may be obtained from other online resources as well.
First we show a few data sets using a linear scale with relative pressure as the dependent variable
End of explanation
"""


fig = plt.figure(figsize=(12,5))
axes = fig.add_subplot(111)
plt.title('Isotherm Plot')
plt.ylabel("Quantity Adsorbed (cm^3/g STP)")
plt.xlabel("Relative Pressure")

plt.gca().set_xscale('log')
plt.plot( carb.Prel, carb.Qads, 'ro', label='Carbon Black with N2 at 77K' )
plt.plot( sial.Prel, sial.Qads, 'bo-', label='Silica Alumina with N2 at 77K')
plt.plot( mcm.Prel, mcm.Qads, 'go-', label='MCM 41 with N2 at 77K')
legend = axes.legend(loc='upper left', shadow=True)
plt.show()

"""
Explanation: It is also useful to show the isotherm with the Pressure axis scaled as logarithmic.
End of explanation
"""


zsm = ex.zsm_5()   # example isotherm of ZSM-5 with Ar at 87K
fig = plt.figure(figsize=(12,5))
axes = fig.add_subplot(111)
plt.title('Isotherm Plot')
plt.ylabel("Quantity Adsorbed (cm^3/g STP)")
plt.xlabel("Absolute Pressure (mmHg)")
plt.gca().set_xscale('log')
plt.plot( zsm.Pabs, zsm.Qads, 'ro', label='ZSM-5 with Ar at 87K' )
legend = axes.legend(loc='upper left', shadow=True)
plt.show()

"""
Explanation: While it is more common to show isotherm data using relative pressure, it is also worth while to have the absolute pressures available.  Below is an example data set for ZSM-5 analyzed with argon gas at 87k shown with absolute pressure as the dependent variable.
End of explanation
"""


