The Chemics package is a collection of Python functions for performing calculations in the field of chemical engineering. Source code for the package is available on GitHub and contributions from the community are encouraged.
If you don’t have Python installed on your computer, the Anaconda or Miniconda distribution of Python is recommended for scientific computing. After setting up Python, the Chemics package can be downloaded and installed using the pip package manager.
The example below imports the Chemics package and uses the Gas class to calculate the density and viscosity of nitrogen gas at a temperature of 773 K and pressure of 101,325 Pa.
importchemicsascmgas=cm.Gas("N2",773)rho=gas.density()mu=gas.viscosity()print("Nitrogen gas properties at 773 K and 101,325 Pa")print(f"density {rho:.4f} kg/m³")print(f"viscosity {mu:.2f} μP")
This prints the following:
Nitrogen gas properties at 773 K and 101,325 Pa
density 0.4416 kg/m³
viscosity 363.82 μP
This example uses the ChemicalEquation class to get properties of the reactants and products from a given chemical equation.
importchemicsascmce=cm.ChemicalEquation('2 HCl + 2 Na -> 2 NaCl + H2')ce.is_balanced()# This returns True for balanced equationce.rct_properties# This returns a dataframe of the reactant properties# HCl Na# moles 2 2# species HCl Na# molwt 36.458 22.99# mass 72.916 45.98# molfrac 0.5 0.5# massfrac 0.613275 0.386725
See the Examples section for more ways to use Chemics.
The biocomp() function uses ultimate analysis data to estimate biomass composition in terms of cellulose, hemicellulose, lignins, and extractives. The example below uses the carbon yc and hydrogen yh mass fractions from ultimate analysis data to calculate the cellulose mass fraction on a dry ash-free basis.
Use the plot_biocomp() function to plot the biomass (triangle symbol) in relation to the reference mixtures (square symbols) as shown below.
# Carbon and hydrogen mass fractions from ultimate analysisyc=0.534yh=0.06# Calculate the biomass compositionbc=cm.biocomp(yc,yh)# Plot the biomass and reference mixturesfig,ax=plt.subplots(tight_layout=True)cm.plot_biocomp(ax,yc,yh,bc['y_rm1'],bc['y_rm2'],bc['y_rm3'])plt.show()
Notice that the C and H mass fractions may give negative biomass composition values when the default splitting parameters are used as shown below. This is also depicted by the biomass marker going outside the bounds (dashed triangle) of the reference mixtures.
The ChemicalEquation class provides product and reactant properties from an equation that represents a chemical reaction.
>>> eq=cm.ChemicalEquation('2 HCl + 2 Na -> 2 NaCl + H2')# Check if atomic elements of the reactants and products are balanced>>> eq.is_balanced()True# Total number of atomic elements for each product>>> eq.prod_elements{'Na': 2.0, 'Cl': 2.0, 'H': 2.0}# Total number of moles for the products>>> eq.prod_moles3.0# Total mass of the products>>> eq.prod_mass118.896# Total number of atomic elements for each reactant>>> eq.rct_elements{'H': 2.0, 'Cl': 2.0, 'Na': 2.0}# Total number of moles for the reactants>>> eq.rct_moles4.0# Total mass of the reactants>>> eq.rct_mass118.896...# Properties of the products>>> eq.prod_properties NaCl H2moles 2.0 1.0species NaCl H2molwt 58.44 2.016mass 116.88 2.016molfrac 0.666667 0.333333massfrac 0.983044 0.016956# Properties of the reactants>>> eq.rct_properties HCl Namoles 2.0 2.0species HCl Namolwt 36.458 22.99mass 72.916 45.98molfrac 0.5 0.5massfrac 0.613275 0.386725
Names can be assigned to chemical species using the names parameter.
Convert a list of mass fractions y to mole fractions where mw is the molecular weight in g/mol for each component. In this example, the components represent C, H, O, and N.
Use the reynolds() function to calculate the Reynolds number.
u=2.6# flow speed in m/sd=0.025# characteristic length or dimension in metersrho=910# density of the fluid or gas in kg/m³mu=0.38# dynamic viscosity of the fluid or gas in kg/(m⋅s)re=cm.reynolds(u,d,rho=rho,mu=mu)print(f'Reynolds number Re is {re:.2f}')
Reynolds number Re is 155.66
The kinematic viscosity can be used as an input parameter instead of the density and dynamic viscosity.
u=0.25# flow speed in m/sd=0.102# characteristic length or dimension in metersnu=1.4e-6# kinematic viscosity of the fluid or gas in m²/sre=cm.reynolds(u,d,nu=nu)print(f'Reynolds number Re is {re:.2f}')
Gas properties such as molecular weight, density, heat capacity, thermal conductivity, and viscosity can be calculated using the Gas class. The example given below calculates nitrogen gas properties at 773 K and 101,325 Pa which is the default pressure.
This example calculates the molecular weight and viscosity of a gas mixture using the GasMixture class. The gas mixture is initialized with a list of Gas objects and their associated mole fractions.
Use the Proximate class to express proximate analysis values as different bases. Bases are as-determined (ad), as-received (ar), dry (d), and dry ash-free (daf).
>>> prox=cm.Proximate([47.26,40.05,4.46,8.23],'ad')>>> print(prox) ad ar d dafFC 47.26 39.53 51.50 54.13VM 40.05 33.50 43.64 45.87ash 4.46 3.73 4.86 -moisture 8.23 23.24 - -total 100.00 100.00 100.00 100.00
>>> prox=cm.Proximate([39.53,33.50,3.73,23.24],'ar')>>> print(prox) ad ar d dafFC 47.26 39.53 51.50 54.13VM 40.05 33.50 43.64 45.87ash 4.46 3.73 4.86 -moisture 8.23 23.24 - -total 100.00 100.00 100.00 100.00
Use the Ultimate class to express ultimate analysis values as different bases. Bases are as-determined (ad), as-received (ar), dry (d), and dry ash-free (daf).
Functions are available to calculate the Biot and pyrolysis numbers PyI and PyII as shown below.
h=500# convective heat transfer coefficient in W/(m²⋅K)d=0.00001# biomass particle diameter in metersk=0.12# biomass thermal conductivity in W/(m⋅K)kr=1.4# reaction rate constant in 1/srho=540# biomass density in kg/m³cp=3092.8# biomass heat capacity in J/(kg⋅K)r=d/2biot=cm.biot(h,r,k)pyI=cm.pyrolysis_one(k,kr,rho,cp,r)pyII=cm.pyrolysis_two(h,kr,rho,cp,r)print(f'Biot number is {biot:.4f}')print(f'PyI number is {pyI:.2f}')print(f'PyII number is {pyII:.2f}')
Biot number is 0.0208
PyI number is 2052.90
PyII number is 42.77
The Biot and pyrolysis numbers can be used to create a regime map for a biomass particle as shown here.
h=500# convective heat transfer coefficient in W/(m²⋅K)d=0.00001# biomass particle diameter in metersk=0.12# biomass thermal conductivity in W/(m⋅K)kr=1.4# reaction rate constant in 1/srho=540# biomass density in kg/m³cp=3092.8# biomass heat capacity in J/(kg⋅K)r=d/2biot=cm.biot(h,r,k)pyI=cm.pyrolysis_one(k,kr,rho,cp,r)pyII=cm.pyrolysis_two(h,kr,rho,cp,r)ifbiot<1.0:py=pyIIelse:py=pyIfig,ax=plt.subplots(tight_layout=True)ax.plot(biot,py,'r^')ax.set_xlabel('Biot Number, Bi [-]')ax.set_ylabel('Pyrolysis Number, Py [-]')ax.text(0.2,0.91,'kinetics limited\nisothermal',ha='center',transform=ax.transAxes)ax.text(0.8,0.91,'kinetics limited\nnon-isothermal',ha='center',transform=ax.transAxes)ax.text(0.2,0.03,'convection limited',ha='center',transform=ax.transAxes)ax.text(0.8,0.03,'conduction limited',ha='center',transform=ax.transAxes)ax.axvline(1,c='k',ls='-.')ax.axvspan(10**-1,10**1,color='0.9')ax.axhline(1,c='k',ls='-.')ax.axhspan(10**-1,10**1,color='0.9')ax.grid(color='0.9')ax.set_frame_on(False)ax.set_xlim(10**-4,10**4)ax.set_ylim(10**-4,10**4)ax.set_xscale('log')ax.set_yscale('log')ax.tick_params(color='0.9')plt.minorticks_off()plt.show()
Dictionary containing atomic number, name, and atomic weight of elements in the
periodic table. Conventional atomic weight is used for atomic weight where
applicable. Values taken from IUPAC.
Biomass composition can be represented in terms of cellulose, hemicellulose, lignins, and extractives. If experimental data is not available, the components of biomass can be estimated from the ultimate analysis using a characterization method developed by Debiagi, Pecchi, Gentile, Frassoldati, Cuoci, Faravelli, and Ranzi.
Use the biocomp() function to calculate biomass composition. Use the plot_biocomp() function to create a Matplotlib figure of the biomass composition results.
Determine bimoass composition from ultimate analysis mass fractions of C,
H, and O. Composition returned as cellulose, hemicellulose, lignins, and
extractives based on method discussed in the Debiagi 2015 paper [1].
Parameters:
yc (float) – Mass fraction of carbon in biomass, dry ash free basis
yh (float) – Mass fraction of hydrogen in biomass, dry ash free basis
yo (float, optional) – Mass fraction of oxygen in biomass, if not given then value is
calculated as difference, dry ash free basis. Default is None.
yh2o (float, optional) – Mass fraction of water in biomass, as received basis. Default is 0.
yash (float, optional) – Mass fraction of ash in biomass, as received basis. Default is 0.
alpha (float, optional) – Splitting parameter as molar ratio of cellulose and hemicellulose
contained in reference mixture RM1. Default is 0.6.
beta (float, optional) – Splitting parameter as molar ratio of lignin LIG-O and lignin LIG-C
contained in reference mixture RM2. Default is 0.8.
gamma (float, optional) – Splitting parameter as molar ratio of lignin LIG-H and lignin LIG-C
contained in reference mixture RM3. Default is 0.8.
delta (float, optional) – Splitting parameter as molar ratio of lignins (LIG-H and LIG-C) and
extractive TGL to define reference mixture RM2. Default is 1.0.
epsilon (float, optional) – Splitting parameter as molar ratio of lignins (LIG-O and LIG-C) and
extractive TANN to define reference mixture RM3. Default is 1.0.
printcomp (bool, optional) – Print composition results if True. Default is False.
Returns:
comp (dict) – Dictionary representing reference mixtures and biomass compositions on
the basis of mole fractions (x) and mass fractions (y). The
dictionary contains the following items for the reference mixtures
where each item represents the C, H, O mass fraction.
y_rm1 reference mixture RM1
y_rm2 reference mixture RM2
y_rm3 reference mixture RM3
The dictionary also contains the following items for the biomass
composition where each item represents the CELL, HEMI, LIGC, LIGH,
LIGO, TANN, TGL mole or mass fraction.
x_daf mole fractions as dry ash-free basis
x_wet mole fractions as wet basis
y_daf mass fractions as dry ash-free basis
y_wet mass fractions as wet basis
y_wetash mass fractions as wet + ash basis
Raises:
ValueError – When sum of mass fractions is not equal to one.
Examples
Use the carbon and hydrogen mass fractions of the biomass to calculate the
biomass composition.
>>> yc=0.534>>> yh=0.06>>> bc=cm.biocomp(yc,yh)
The cellulose mass fraction on a dry ash-free basis.
>>> cell=bc['y_daf'][0]>>> cell0.293...
The hemicellulose mass fraction on a dry ash-free basis.
D.L. Pyle and C.A. Zaror. Heat Transfer and Kinetics in the Low
Temperature Pyrolysis of Solids. Chemical Engineering Science, vol. 39,
no. 1, pg. 147-158, 1984.
D.L. Pyle and C.A. Zaror. Heat Transfer and Kinetics in the Low
Temperature Pyrolysis of Solids. Chemical Engineering Science, vol. 39,
no. 1, pg. 147-158, 1984.
Calculate gas heat capacity as a function of temperature using Yaws’
coefficients [1]. The CAS (Chemical Abstracts Service) number may be
required for some species.
Calculate gas thermal conductivity as a function of temperature using
Yaws’ coefficients [2]. The CAS (Chemical Abstracts Service) number
may be required for some species.
Raises:
ValueError – If provided CAS number is not found.
ValueError – If multiple substances found for given formula.
ValueError – If gas chemical formula not found.
ValueError – If given temperataure is out of range for calculation.
Returns:
k (float) – Thermal conductivity of the gas in W/(m⋅K).
Calculate gas viscosity as a function of temperature using Ludwig’s
coefficients [3] or Yaws’ coefficients [4]. The CAS
(Chemical Abstracts Service) number may be required for some
species.
The Ludwig coefficients are used with the following correlation
\[\mu = A + B\,T + C\,T^2\]
The Yaws coefficients are used with the following correlation
\[\mu = A + B\,T + C\,T^2 + D\,T^3\]
Parameters:
method (str, optional) – Method for determining coefficients, choose yaws or ludwig.
Default method is yaws.
Raises:
ValueError – If provided CAS number is not found.
ValueError – If multiple substances found for given formula.
ValueError – If gas chemical formula not found.
ValueError – If given temperataure is out of range for calculation.
Calculate viscosity of the gas mixture using Graham’s method [1] or
the Herning and Zipperer method [2]. For the Graham method, Equation
1 from the Davidson report [3] is used
\[\mu_{mix} = \sum (x_i \cdot \mu_i)\]
where \(\mu_{mix}\) is viscosity of the gas mixture, \(x_i\)
is mole fraction [-] of each component, and \(\mu_i\) is gas
viscosity of each component. For the Herning and Zipperer method,
Equation 1 from the Davidson report is used
where \(\mu_{mix}\) is viscosity of the gas mixture, \(x_i\)
is mole fraction [-] of each component, \(\mu_i\) is gas
viscosity of each component, and \(MW_i\) is the molecular
weight [g/mol] of each gas component.
Parameters:
method (str) – Method for calculating the gas mixture viscosity, choose graham or
herning. Default value is graham.
Returns:
mu_mixture (float) – Viscosity of the gas mixture in units of microPoise (μP).
Liquid properties such as heat capacity can be calculated using the method available in the Liquid class. The method is based on a correlation and is named accordingly; for example, the cp_yaws() method uses Yaws’ coefficients to calculate the heat capacity for a range of temperatures.
Liquid heat capacity as a function of temperature using Yaws’ coefficients
[1]. The CAS(Chemical Abstracts Service) number may be required for some
species.
\[C_p = A + B\,T + C\,T^2 + D\,T^3 + E\,T^4\]
Parameters:
temp (float) – Temperature of the liquid in Kelvin
cas (str, optional) – CAS number of the liquid, required for some species
disp (bool) – Display information about the calculation such as the CAS number,
applicable temperature range in Kelvin, and values for regression
coefficients.
Raises:
ValueError – If provided CAS number is not found.
ValueError – If multiple substances found for given formula.
ValueError – If gas chemical formula not found.
ValueError – If given temperataure is out of range for calculation.
Returns:
cp (float) – Heat capacity of the liquid in J/(mol⋅K)
Functions to calculate molecular weight of an element, compound, or gas mixture.
Note that mole fractions must sum to one otherwise an error is raised.
Proximate analysis provides the percentage composition of a material in terms of fixed carbon (FC), volatile matter (VM), ash, and moisture. It can be represented on an as-determined (ad), as-received basis (ar), dry basis (d), and dry-ash free basis (daf).
Proximate analysis values expressed as different bases. Such bases are
as-determined (ad), as-received (ar), dry (d), and dry ash-free (daf).
Parameters:
vals (list) – Proximate analysis values given as weight percent (wt. %), μg/g
(trace elements), or Btu/lb (gross calorific value). Order of values
is [FC, VM, ash, moisture].
basis (str) – Basis of given proximate analysis values. Options are ‘ad’ for
as-determined basis or ‘ar’ for as-received basis.
ADL (float, optional) – Air-dry loss as weight percent. Default value is 16.36 weight percent.
ASTM D3180-15, Standard Practice for Calculating Coal and Coke Analyses
from As-Determined to Different Bases, ASTM International, West
Conshohocken, PA, 2015.
Ultimate analysis provides the percentage composition of a material in terms of carbon (C), hydrogen (H), oxygen (O), nitrogen (N), sulfur (S), ash, and moisture. It can be represented on an as-determined basis (ad), as-received basis (ar), dry basis (dry), and dry-ash free basis (daf).
Ultimate analysis values expressed as different bases. Such bases are
as-determined (ad), as-received (ar), dry (d), and dry ash-free (daf).
Parameters:
vals (list) – Ultimate analysis values given as weight percent (wt. %), μg/g
(trace elements), or Btu/lb (gross calorific value). Order of values
is [C, H, O, N, S, ash, moisture].
basis (str) – Basis of given ultimate analysis values. Options are ‘ad’ for
as-determined basis or ‘ar’ for as-received basis
ADL (float, optional) – Air-dry loss as weight percent
HO (bool, optional) – If True then the given H and O values include H and O from moisture.
If False then the given H and O values exclude H and O from the
moisture content.
ASTM D3180-15, Standard Practice for Calculating Coal and Coke Analyses
from As-Determined to Different Bases, ASTM International, West
Conshohocken, PA, 2015.
where \(c_{p,x}\) is heat capacity of wet wood [kJ/(kg K)],
\(c_{p0}\) is heat capacity of dry wood [kJ/(kg K)], \(c_{pw}\) is
heat capacity of water as 4.18 kJ/(kg K), \(x\) is moisture content [%],
and \(Ac\) is an adjustment factor that accounts for the additional
energy in the wood–water bond [1].
The \(c_{p0}\) term is determined from
\[c_{p0} = 0.1031 + 0.003867\,T\]
where \(T\) is temperature in Kelvin. The \(A_c\) term is calculated from
\[A_c = x (b_1 + b_2 T + b_3 x)\]
with \(b_1 = -0.06191\), \(b_2 = 2.36e\times10^{-4}\),
and \(b_3 = -1.33\times10^{-4}\).
Thermal conductivity of wood based on moisture content, volumetric
shrinkage, and basic specific gravity
\[k = G_x (B + C x) + A\]
where \(k\) is thermal conductivity [W/(mK)] of wood, \(G_x\) is
specific gravity [-] based on volume at moisture content \(x\) [%] and
\(A, B, C\) are constants.
The \(G_x\) term is determined from
\[G_x = \frac{G_b}{1 - S_x / 100}\]
where \(G_b\) is basic specific gravity [-] and \(S_x\) is
volumetric shrinkage [%] from green condition to moisture content \(x\).
The \(S_x\) term is calculated from
\[S_x = S_o \left(1 - \frac{x}{MC_{fs}} \right)\]
where \(S_o\) is volumetric shrinkage [%] from Table 4-3 [2] and \(MC_{fs}\)
is the fiber saturation point assumed to be 30% moisture content.