[1]:
try:
import google.colab
%pip install -q ugropy
except ImportError:
pass
Gibbs Models
In some situations, you may not need to instantiate all the models supported by ugropy. Instead, you can search for a specific model’s groups individually.
Warning
For the UNIFAC, PSRK, and Dortmund models, the aldehyde group name has been changed to HCO, in accordance with the following discussion:
https://github.com/ClapeyronThermo/Clapeyron.jl/issues/225
This is more consistent with the ether groups and formate group.
UNIFAC
The classic liquid-vapor UNIFAC model can be imported and used by doing:
[2]:
from ugropy import unifac
hexane = unifac.get_groups("n-hexane")
print(hexane.subgroups)
{'CH3': 2, 'CH2': 4}
[3]:
hexane.draw()
[3]:
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 get_groups method is:
unifac.get_groups(
identifier: Union[str, Chem.rdchem.Mol],
identifier_type: str = "name",
solver: ILPSolver = DefaultSolver,
search_multiple_solutions: bool = False,
search_nonoptimal: bool = False,
) -> Union[GibbsFragmentationResult, List[GibbsFragmentationResult]]:
"""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.
search_nonoptimal : bool, optional
If True, the solver will search for non-optimal solutions along
with the optimal ones. This is useful when the user wants to find
all possible combinations of fragments that cover the universe. By
default False. If `search_multiple_solutions` is False, this
parameter will be ignored.
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.
Let’s obtain multiple solution by doing:
[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 0x7f45985d6120>,
<ugropy.core.frag_classes.gibbs_model.gibbs_result.GibbsFragmentationResult at 0x7f4557f308c0>]
[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]:
[8]:
mol[1].draw(width=800)
[8]:
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]:
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]:
[13]:
toluene.r, toluene.q
[13]:
(np.float64(3.9227999999999996), np.float64(2.968))
Dortmund (modified UNIFAC)
The Dortmund model can be imported and used by doing:
[14]:
from ugropy import dortmund
cyclohexane = dortmund.get_groups("cyclohexane")
cyclohexane.subgroups
[14]:
{'CY-CH2': 6}
[15]:
cyclohexane.draw()
[15]:
Since the \(R\) and \(Q\) values of the Dortmund model are fitted along the interaction parameters and do not represent the volume and surface area of the molecule, the values are not calculated by ugropy to avoid confusion.
[16]:
print(cyclohexane.r, cyclohexane.q)
None None