Activity Coefficients (thermo.activity)

This module contains a base class GibbsExcess for handling activity coefficient based models. The design is for a sub-class to provide the minimum possible number of derivatives of Gibbs energy, and for this base class to provide the rest of the methods. An ideal-liquid class with no excess Gibbs energy IdealSolution is also available.

For reporting bugs, adding feature requests, or submitting pull requests, please use the GitHub issue tracker.

Base Class

class thermo.activity.GibbsExcess[source]

Bases: object

Class for representing an activity coefficient model. While these are typically presented as tools to compute activity coefficients, in truth they are excess Gibbs energy models and activity coefficients are just one derived aspect of them.

This class does not implement any activity coefficient models itself; it must be subclassed by another model. All properties are derived with the CAS SymPy, not relying on any derivations previously published, and checked numerically for consistency.

Different subclasses have different parameter requirements for initialization; IdealSolution is available as a simplest model with activity coefficients of 1 to show what needs to be implemented in subclasses. It is also intended subclasses implement the method to_T_xs, which creates a new object at the specified temperature and composition but with the same parameters.

These objects are intended to lazy-calculate properties as much as possible, and for the temperature and composition of an object to be immutable.

Attributes
N
T
scalar
xs

Methods

CpE()

Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.

HE()

Calculate and return the excess entropy of a liquid phase using an activity coefficient model.

SE()

Calculates the excess entropy of a liquid phase using an activity coefficient model.

as_json()

Method to create a JSON-friendly representation of the Gibbs Excess model which can be stored, and reloaded later.

d2GE_dTdns()

Calculate and return the mole number derivative of the first temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

d2nGE_dTdns()

Calculate and return the partial mole number derivative of the first temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

d2nGE_dninjs()

Calculate and return the second partial mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

dGE_dns()

Calculate and return the mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

dHE_dT()

Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.

dHE_dns()

Calculate and return the mole number derivative of excess enthalpy of a liquid phase using an activity coefficient model.

dHE_dxs()

Calculate and return the mole fraction derivative of excess enthalpy of a liquid phase using an activity coefficient model.

dSE_dT()

Calculate and return the first temperature derivative of excess entropy of a liquid phase using an activity coefficient model.

dSE_dns()

Calculate and return the mole number derivative of excess entropy of a liquid phase using an activity coefficient model.

dSE_dxs()

Calculate and return the mole fraction derivative of excess entropy of a liquid phase using an activity coefficient model.

dgammas_dT()

Calculate and return the temperature derivatives of activity coefficients of a liquid phase using an activity coefficient model.

dgammas_dns()

Calculate and return the mole number derivative of activity coefficients of a liquid phase using an activity coefficient model.

dnGE_dns()

Calculate and return the partial mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

dnHE_dns()

Calculate and return the partial mole number derivative of excess enthalpy of a liquid phase using an activity coefficient model.

dnSE_dns()

Calculate and return the partial mole number derivative of excess entropy of a liquid phase using an activity coefficient model.

from_json(json_repr)

Method to create a Gibbs Excess model from a JSON-friendly serialization of another Gibbs Excess model.

gammas()

Calculate and return the activity coefficients of a liquid phase using an activity coefficient model.

gammas_infinite_dilution()

Calculate and return the infinite dilution activity coefficients of each component.

model_hash()

Basic method to calculate a hash of the non-state parts of the model This is useful for comparing to models to determine if they are the same, i.e. in a VLL flash it is important to know if both liquids have the same model.

state_hash()

Basic method to calculate a hash of the state of the model and its model parameters.

CpE()

Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.

hET=T2gET2\frac{\partial h^E}{\partial T} = -T \frac{\partial^2 g^E} {\partial T^2}
Returns
dHE_dTfloat

First temperature derivative of excess enthalpy of the liquid phase, [J/mol/K]

HE()[source]

Calculate and return the excess entropy of a liquid phase using an activity coefficient model.

hE=TgET+gEh^E = -T \frac{\partial g^E}{\partial T} + g^E
Returns
HEfloat

Excess enthalpy of the liquid phase, [J/mol]

N
SE()[source]

Calculates the excess entropy of a liquid phase using an activity coefficient model.

sE=hEgETs^E = \frac{h^E - g^E}{T}
Returns
SEfloat

Excess entropy of the liquid phase, [J/mol/K]

Notes

Note also the relationship of the expressions for partial excess entropy:

SiE=R(TlnγiT+lnγi)S_i^E = -R\left(T \frac{\partial \ln \gamma_i}{\partial T} + \ln \gamma_i\right)
T
__eq__(other)[source]

Return self==value.

__hash__()[source]

Method to calculate and return a hash representing the exact state of the object. This includes T, xs, the model class, and which values have already been calculated.

Returns
hashint

Hash of the object, [-]

__repr__()[source]

Method to create a string representation of the state of the model. Included is T, xs, and all constants necessary to create the model. This can be passed into exec to re-create the model. Note that parsing strings like this can be slow.

Returns
reprstr

String representation of the object, [-]

Examples

>>> IdealSolution(T=300.0, xs=[.1, .2, .3, .4])
IdealSolution(T=300.0, xs=[.1, .2, .3, .4])
as_json()[source]

Method to create a JSON-friendly representation of the Gibbs Excess model which can be stored, and reloaded later.

Returns
json_reprdict

JSON-friendly representation, [-]

Examples

>>> import json
>>> model = IdealSolution(T=300.0, xs=[.1, .2, .3, .4])
>>> json_view = model.as_json()
>>> json_str = json.dumps(json_view)
>>> assert type(json_str) is str
>>> model_copy = IdealSolution.from_json(json.loads(json_str))
>>> assert model_copy == model
d2GE_dTdns()[source]

Calculate and return the mole number derivative of the first temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

2GEniT\frac{\partial^2 G^E}{\partial n_i \partial T}
Returns
d2GE_dTdnslist[float]

First mole number derivative of the temperature derivative of excess Gibbs entropy of the liquid phase, [J/(mol^2*K)]

d2nGE_dTdns()[source]

Calculate and return the partial mole number derivative of the first temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

2nGEniT\frac{\partial^2 n G^E}{\partial n_i \partial T}
Returns
d2nGE_dTdnslist[float]

First partial mole number derivative of the temperature derivative of excess Gibbs entropy of the liquid phase, [J/(mol*K)]

d2nGE_dninjs()[source]

Calculate and return the second partial mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

2nGEnini\frac{\partial^2 n G^E}{\partial n_i \partial n_i}
Returns
d2nGE_dninjslist[list[float]]

Second partial mole number derivative of excess Gibbs energy of a liquid phase, [J/(mol^2)]

dGE_dns()[source]

Calculate and return the mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

GEni\frac{\partial G^E}{\partial n_i}
Returns
dGE_dnslist[float]

First mole number derivative of excess Gibbs entropy of the liquid phase, [J/(mol^2*K)]

dHE_dT()[source]

Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.

hET=T2gET2\frac{\partial h^E}{\partial T} = -T \frac{\partial^2 g^E} {\partial T^2}
Returns
dHE_dTfloat

First temperature derivative of excess enthalpy of the liquid phase, [J/mol/K]

dHE_dns()[source]

Calculate and return the mole number derivative of excess enthalpy of a liquid phase using an activity coefficient model.

hEni\frac{\partial h^E}{\partial n_i}
Returns
dHE_dnslist[float]

First mole number derivative of excess enthalpy of the liquid phase, [J/mol^2]

dHE_dxs()[source]

Calculate and return the mole fraction derivative of excess enthalpy of a liquid phase using an activity coefficient model.

hExi=T2gETxi+gExi\frac{\partial h^E}{\partial x_i} = -T \frac{\partial^2 g^E} {\partial T \partial x_i} + \frac{\partial g^E}{\partial x_i}
Returns
dHE_dxslist[float]

First mole fraction derivative of excess enthalpy of the liquid phase, [J/mol]

dSE_dT()[source]

Calculate and return the first temperature derivative of excess entropy of a liquid phase using an activity coefficient model.

sET=1T(gET+hET(G+H)T)\frac{\partial s^E}{\partial T} = \frac{1}{T} \left(\frac{-\partial g^E}{\partial T} + \frac{\partial h^E}{\partial T} - \frac{(G + H)}{T}\right)
Returns
dSE_dTfloat

First temperature derivative of excess entropy of the liquid phase, [J/mol/K]

dSE_dns()[source]

Calculate and return the mole number derivative of excess entropy of a liquid phase using an activity coefficient model.

SEni\frac{\partial S^E}{\partial n_i}
Returns
dSE_dnslist[float]

First mole number derivative of excess entropy of the liquid phase, [J/(mol^2*K)]

dSE_dxs()[source]

Calculate and return the mole fraction derivative of excess entropy of a liquid phase using an activity coefficient model.

SExi=1T(hExigExi)=2gExiT\frac{\partial S^E}{\partial x_i} = \frac{1}{T}\left( \frac{\partial h^E} {\partial x_i} - \frac{\partial g^E}{\partial x_i}\right) = -\frac{\partial^2 g^E}{\partial x_i \partial T}
Returns
dSE_dxslist[float]

First mole fraction derivative of excess entropy of the liquid phase, [J/(mol*K)]

dgammas_dT()[source]

Calculate and return the temperature derivatives of activity coefficients of a liquid phase using an activity coefficient model.

γiT=(2nGETniRTniGEniRT2)exp(niGEniRT)\frac{\partial \gamma_i}{\partial T} = \left(\frac{\frac{\partial^2 n G^E}{\partial T \partial n_i}}{RT} - \frac{{\frac{\partial n_i G^E}{\partial n_i }}}{RT^2}\right) \exp\left(\frac{\frac{\partial n_i G^E}{\partial n_i }}{RT}\right)
Returns
dgammas_dTlist[float]

Temperature derivatives of activity coefficients, [1/K]

dgammas_dns()[source]

Calculate and return the mole number derivative of activity coefficients of a liquid phase using an activity coefficient model.

γini=γi(2GExixjRT)\frac{\partial \gamma_i}{\partial n_i} = \gamma_i \left(\frac{\frac{\partial^2 G^E}{\partial x_i \partial x_j}}{RT}\right)
Returns
dgammas_dnslist[list[float]]

Mole number derivatives of activity coefficients, [1/mol]

dnGE_dns()[source]

Calculate and return the partial mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

nGEni\frac{\partial n G^E}{\partial n_i}
Returns
dnGE_dnslist[float]

First partial mole number derivative of excess Gibbs entropy of the liquid phase, [J/(mol)]

dnHE_dns()[source]

Calculate and return the partial mole number derivative of excess enthalpy of a liquid phase using an activity coefficient model.

nhEni\frac{\partial n h^E}{\partial n_i}
Returns
dnHE_dnslist[float]

First partial mole number derivative of excess enthalpy of the liquid phase, [J/mol]

dnSE_dns()[source]

Calculate and return the partial mole number derivative of excess entropy of a liquid phase using an activity coefficient model.

nSEni\frac{\partial n S^E}{\partial n_i}
Returns
dnSE_dnslist[float]

First partial mole number derivative of excess entropy of the liquid phase, [J/(mol*K)]

classmethod from_json(json_repr)[source]

Method to create a Gibbs Excess model from a JSON-friendly serialization of another Gibbs Excess model.

Parameters
json_reprdict

JSON-friendly representation, [-]

Returns
modelGibbsExcess

Newly created object from the json serialization, [-]

Notes

It is important that the input string be in the same format as that created by GibbsExcess.as_json.

Examples

>>> model = IdealSolution(T=300.0, xs=[.1, .2, .3, .4])
>>> json_view = model.as_json()
>>> new_model = IdealSolution.from_json(json_view)
>>> assert model == new_model
gammas()[source]

Calculate and return the activity coefficients of a liquid phase using an activity coefficient model.

γi=exp(niGEniRT)\gamma_i = \exp\left(\frac{\frac{\partial n_i G^E}{\partial n_i }}{RT}\right)
Returns
gammaslist[float]

Activity coefficients, [-]

gammas_infinite_dilution()[source]

Calculate and return the infinite dilution activity coefficients of each component.

Returns
gammas_infinitelist[float]

Infinite dilution activity coefficients, [-]

Notes

The algorithm is as follows. For each component, set its composition to zero. Normalize the remaining compositions to 1. Create a new object with that composition, and calculate the activity coefficient of the component whose concentration was set to zero.

model_hash()[source]

Basic method to calculate a hash of the non-state parts of the model This is useful for comparing to models to determine if they are the same, i.e. in a VLL flash it is important to know if both liquids have the same model.

Note that the hashes should only be compared on the same system running in the same process!

Returns
model_hashint

Hash of the object’s model parameters, [-]

scalar
state_hash()[source]

Basic method to calculate a hash of the state of the model and its model parameters.

Note that the hashes should only be compared on the same system running in the same process!

Returns
state_hashint

Hash of the object’s model parameters and state, [-]

xs

Ideal Liquid Class

class thermo.activity.IdealSolution(T=None, xs=None)[source]

Bases: thermo.activity.GibbsExcess

Class for representing an ideal liquid, with no excess gibbs energy and thus activity coefficients of 1.

Parameters
Tfloat

Temperature, [K]

xslist[float]

Mole fractions, [-]

Examples

>>> model = IdealSolution(T=300.0, xs=[.1, .2, .3, .4])
>>> model.GE()
0.0
>>> model.gammas()
[1.0, 1.0, 1.0, 1.0]
>>> model.dgammas_dT()
[0.0, 0.0, 0.0, 0.0]
Attributes
Tfloat

Temperature, [K]

xslist[float]

Mole fractions, [-]

Methods

GE()

Calculate and return the excess Gibbs energy of a liquid phase using an activity coefficient model.

d2GE_dT2()

Calculate and return the second temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

d2GE_dTdxs()

Calculate and return the temperature derivative of mole fraction derivatives of excess Gibbs energy of an ideal liquid.

d2GE_dxixjs()

Calculate and return the second mole fraction derivatives of excess Gibbs energy of an ideal liquid.

d3GE_dT3()

Calculate and return the third temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

d3GE_dxixjxks()

Calculate and return the third mole fraction derivatives of excess Gibbs energy of an ideal liquid.

dGE_dT()

Calculate and return the temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

dGE_dxs()

Calculate and return the mole fraction derivatives of excess Gibbs energy of an ideal liquid.

to_T_xs(T, xs)

Method to construct a new IdealSolution instance at temperature T, and mole fractions xs with the same parameters as the existing object.

GE()[source]

Calculate and return the excess Gibbs energy of a liquid phase using an activity coefficient model.

gE=0g^E = 0
Returns
GEfloat

Excess Gibbs energy of an ideal liquid, [J/mol]

d2GE_dT2()[source]

Calculate and return the second temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

2gET2=0\frac{\partial^2 g^E}{\partial T^2} = 0
Returns
d2GE_dT2float

Second temperature derivative of excess Gibbs energy of an ideal liquid, [J/(mol*K^2)]

d2GE_dTdxs()[source]

Calculate and return the temperature derivative of mole fraction derivatives of excess Gibbs energy of an ideal liquid.

2gExiT=0\frac{\partial^2 g^E}{\partial x_i \partial T} = 0
Returns
d2GE_dTdxslist[float]

Temperature derivative of mole fraction derivatives of excess Gibbs energy of an ideal liquid, [J/(mol*K)]

d2GE_dxixjs()[source]

Calculate and return the second mole fraction derivatives of excess Gibbs energy of an ideal liquid.

2gExixj=0\frac{\partial^2 g^E}{\partial x_i \partial x_j} = 0
Returns
d2GE_dxixjslist[list[float]]

Second mole fraction derivatives of excess Gibbs energy of an ideal liquid, [J/mol]

d3GE_dT3()[source]

Calculate and return the third temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

3gET3=0\frac{\partial^3 g^E}{\partial T^3} = 0
Returns
d3GE_dT3float

Third temperature derivative of excess Gibbs energy of an ideal liquid, [J/(mol*K^3)]

d3GE_dxixjxks()[source]

Calculate and return the third mole fraction derivatives of excess Gibbs energy of an ideal liquid.

3gExixjxk=0\frac{\partial^3 g^E}{\partial x_i \partial x_j \partial x_k} = 0
Returns
d3GE_dxixjxkslist[list[list[float]]]

Third mole fraction derivatives of excess Gibbs energy of an ideal liquid, [J/mol]

dGE_dT()[source]

Calculate and return the temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.

gET=0\frac{\partial g^E}{\partial T} = 0
Returns
dGE_dTfloat

First temperature derivative of excess Gibbs energy of an ideal liquid, [J/(mol*K)]

dGE_dxs()[source]

Calculate and return the mole fraction derivatives of excess Gibbs energy of an ideal liquid.

gExi=0\frac{\partial g^E}{\partial x_i} = 0
Returns
dGE_dxslist[float]

Mole fraction derivatives of excess Gibbs energy of an ideal liquid, [J/mol]

to_T_xs(T, xs)[source]

Method to construct a new IdealSolution instance at temperature T, and mole fractions xs with the same parameters as the existing object.

Parameters
Tfloat

Temperature, [K]

xslist[float]

Mole fractions of each component, [-]

Returns
objIdealSolution

New IdealSolution object at the specified conditions [-]

Examples

>>> p = IdealSolution(T=300.0, xs=[.1, .2, .3, .4])
>>> p.to_T_xs(T=500.0, xs=[.25, .25, .25, .25])
IdealSolution(T=500.0, xs=[0.25, 0.25, 0.25, 0.25])

Notes

References

1

Walas, Stanley M. Phase Equilibria in Chemical Engineering. Butterworth-Heinemann, 1985.

2

Gmehling, Jurgen. Chemical Thermodynamics: For Process Simulation. Weinheim, Germany: Wiley-VCH, 2012.