Gibbs Models

Open In Colab

In some situation you may not require to instantiate all the models supported by ugropy, for that, you can search the model’s groups individually.

UNIFAC

The classic liquid-vapor UNIFAC model can be imported and used by doing:

[1]:
try:
  import google.colab
  IN_COLAB = True
except:
  IN_COLAB = False


if IN_COLAB:
  %pip install ugropy
[2]:
from ugropy import unifac

hexane = unifac.get_groups("n-hexane")

print(hexane.subgroups)
{'CH3': 2, 'CH2': 4}
[3]:
hexane.draw()
[3]:
../_images/tutorial_gibbs_models_3_0.svg

As you can see, the UNIFAC model can be used just like we did on the Groups class. The Groups class is only intended to be used when you want all the groups from all the models with a single call.

The signature of the UNIFAC model is:

Signature:
unifac.get_groups(
    identifier: Union[str, rdkit.Chem.rdchem.Mol],
    identifier_type: str = 'name',
    solver: ugropy.core.ilp_solvers.ilp_solver.ILPSolver = <class 'ugropy.core.ilp_solvers.default_solver.DefaultSolver'>,
    search_multiple_solutions: bool = False,
) -> Union[ugropy.core.frag_classes.gibbs_model.gibbs_result.GibbsFragmentationResult, List[ugropy.core.frag_classes.gibbs_model.gibbs_result.GibbsFragmentationResult]]
Docstring:
Get the groups of a molecule.

Parameters
----------
identifier : Union[str, Chem.rdchem.Mol]
    Identifier of the molecule. You can use either the name of the
    molecule, the SMILEs of the molecule or a rdkit Mol object.
identifier_type : str, optional
    Identifier type of the molecule. Use "name" if you are providing
    the molecules' name, "smiles" if you are providing the SMILES
    or "mol" if you are providing a rdkir mol object, by default "name"
solver : ILPSolver, optional
    ILP solver class, by default DefaultSolver
search_multiple_solutions : bool, optional
    Weather search for multiple solutions or not, by default False
    If False the return will be a FragmentationResult object, if True
    the return will be a list of FragmentationResult objects.

Returns
-------
Union[GibbsFragmentationResult, List[GibbsFragmentationResult]]
    Fragmentation result. If search_multiple_solutions is False the
    return will be a FragmentationResult object, if True the return
    will be a list of FragmentationResult objects.

As you can see, it has the same arguments as the Groups class. We can obtain multiple solution by:

[4]:
mol = unifac.get_groups("CCCC1=CC=C(CC(=O)OC)C=C1", "smiles", search_multiple_solutions=True)

mol
[4]:
[<ugropy.core.frag_classes.gibbs_model.gibbs_result.GibbsFragmentationResult at 0x7f48ebef1e50>,
 <ugropy.core.frag_classes.gibbs_model.gibbs_result.GibbsFragmentationResult at 0x7f48ebef1d10>]
[5]:
mol[0].subgroups
[5]:
{'CH3': 2, 'CH2': 1, 'ACH': 4, 'ACCH2': 2, 'COO': 1}
[6]:
mol[1].subgroups
[6]:
{'CH3': 2, 'CH2': 1, 'ACH': 4, 'AC': 1, 'ACCH2': 1, 'CH2COO': 1}
[7]:
mol[0].draw(width=800)
[7]:
../_images/tutorial_gibbs_models_9_0.svg
[8]:
mol[1].draw(width=800)
[8]:
../_images/tutorial_gibbs_models_10_0.svg

Finally GibbsModels can estimate the R and Q (volume and surface area) of a molecule, very useful for the UNIQUAC model.

[9]:
chex = unifac.get_groups("cyclohexane")

chex.r, chex.q
[9]:
(np.float64(4.0464), np.float64(3.24))
[10]:
chex.draw()
[10]:
../_images/tutorial_gibbs_models_13_0.svg

PSRK

The predictive Soave-Redlich-Kwong model can be imported and used by doing:

[11]:
from ugropy import psrk

toluene = psrk.get_groups("toluene")

toluene.subgroups
[11]:
{'ACH': 5, 'ACCH3': 1}

PSRK model works the same as the UNIFAC model.

[12]:
toluene.draw()
[12]:
../_images/tutorial_gibbs_models_17_0.svg
[13]:
toluene.r, toluene.q
[13]:
(np.float64(3.9227999999999996), np.float64(2.968))