{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" import google.colab\n",
" %pip install -q ugropy\n",
"except ImportError:\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Gibbs Models\n",
"\n",
"[](https://colab.research.google.com/github/ipqa-research/ugropy/blob/main/docs/source/tutorial/gibbs_models.ipynb)\n",
"\n",
"In some situations, you may not need to instantiate all the models supported by\n",
"`ugropy`. Instead, you can search for a specific model's groups individually."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Warning"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For the UNIFAC, PSRK, and Dortmund models, the aldehyde group name has been\n",
"changed to `HCO`, in accordance with the following discussion:\n",
"\n",
"https://github.com/ClapeyronThermo/Clapeyron.jl/issues/225\n",
"\n",
"This is more consistent with the ether groups and formate group."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### UNIFAC\n",
"\n",
"The classic liquid-vapor [UNIFAC model](https://www.ddbst.com/published-parameters-unifac.html) can be imported and used by doing:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'CH3': 2, 'CH2': 4}\n"
]
}
],
"source": [
"from ugropy import unifac\n",
"\n",
"hexane = unifac.get_groups(\"n-hexane\")\n",
"\n",
"print(hexane.subgroups)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hexane.draw()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As you can see, the UNIFAC model can be used just like we did on the Groups \n",
"class. The Groups class is only intended to be used when you want all the \n",
"groups from all the models with a single call.\n",
"\n",
"The signature of the `get_groups` method is:\n",
"\n",
"\n",
"```Python\n",
"unifac.get_groups(\n",
" identifier: Union[str, Chem.rdchem.Mol],\n",
" identifier_type: str = \"name\",\n",
" solver: ILPSolver = DefaultSolver,\n",
" search_multiple_solutions: bool = False,\n",
" search_nonoptimal: bool = False,\n",
") -> Union[GibbsFragmentationResult, List[GibbsFragmentationResult]]:\n",
" \"\"\"Get the groups of a molecule.\n",
"\n",
" Parameters\n",
" ----------\n",
" identifier : Union[str, Chem.rdchem.Mol]\n",
" Identifier of the molecule. You can use either the name of the\n",
" molecule, the SMILEs of the molecule or a rdkit Mol object.\n",
" identifier_type : str, optional\n",
" Identifier type of the molecule. Use \"name\" if you are providing\n",
" the molecules' name, \"smiles\" if you are providing the SMILES\n",
" or \"mol\" if you are providing a rdkir mol object, by default \"name\"\n",
" solver : ILPSolver, optional\n",
" ILP solver class, by default DefaultSolver\n",
" search_multiple_solutions : bool, optional\n",
" Weather search for multiple solutions or not, by default False\n",
" If False the return will be a FragmentationResult object, if True\n",
" the return will be a list of FragmentationResult objects.\n",
" search_nonoptimal : bool, optional\n",
" If True, the solver will search for non-optimal solutions along\n",
" with the optimal ones. This is useful when the user wants to find\n",
" all possible combinations of fragments that cover the universe. By\n",
" default False. If `search_multiple_solutions` is False, this\n",
" parameter will be ignored.\n",
"\n",
" Returns\n",
" -------\n",
" Union[GibbsFragmentationResult, List[GibbsFragmentationResult]]\n",
" Fragmentation result. If search_multiple_solutions is False the\n",
" return will be a FragmentationResult object, if True the return\n",
" will be a list of FragmentationResult objects.\n",
" \"\"\"\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As you can see, it has the same arguments as the Groups class.\n",
"\n",
"Let's obtain multiple solution by doing:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[,\n",
" ]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mol = unifac.get_groups(\"CCCC1=CC=C(CC(=O)OC)C=C1\", \"smiles\", search_multiple_solutions=True)\n",
"\n",
"mol"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'CH3': 2, 'CH2': 1, 'ACH': 4, 'ACCH2': 2, 'COO': 1}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mol[0].subgroups"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'CH3': 2, 'CH2': 1, 'ACH': 4, 'AC': 1, 'ACCH2': 1, 'CH2COO': 1}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mol[1].subgroups"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mol[0].draw(width=800)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mol[1].draw(width=800)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally `GibbsModels` can estimate the $R$ and $Q$ (volume and surface area) of\n",
"a molecule, very useful for the UNIQUAC model."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(np.float64(4.0464), np.float64(3.24))"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chex = unifac.get_groups(\"cyclohexane\")\n",
"\n",
"chex.r, chex.q"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chex.draw()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### PSRK\n",
"\n",
"The [Predictive Soave-Redlich-Kwong model](https://www.ddbst.com/psrk.html) can be imported and used by doing:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'ACH': 5, 'ACCH3': 1}"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ugropy import psrk\n",
"\n",
"toluene = psrk.get_groups(\"toluene\")\n",
"\n",
"toluene.subgroups"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"PSRK model works the same as the UNIFAC model."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"toluene.draw()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(np.float64(3.9227999999999996), np.float64(2.968))"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"toluene.r, toluene.q"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Dortmund (modified UNIFAC)\n",
"\n",
"The [Dortmund model](https://www.ddbst.com/PublishedParametersUNIFACDO.html) can be imported and used by doing:"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'CY-CH2': 6}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ugropy import dortmund\n",
"\n",
"\n",
"cyclohexane = dortmund.get_groups(\"cyclohexane\")\n",
"\n",
"cyclohexane.subgroups"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cyclohexane.draw()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since the $R$ and $Q$ values of the Dortmund model are fitted along the \n",
"interaction parameters and do not represent the volume and surface area of the\n",
"molecule, the values are not calculated by `ugropy` to avoid confusion."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"None None\n"
]
}
],
"source": [
"print(cyclohexane.r, cyclohexane.q)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ugropy",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}