Skip to content

Commit

Permalink
Final touches for version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SalvadorBrandolin committed Jan 9, 2025
1 parent 2390e42 commit 68710bf
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 165 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ OS.
You can try `ugropy` without installing it by clicking on the Colab badge.

# Models implemented

## Gibbs / EoS models
- Classic liquid-vapor UNIFAC
- Predictive Soave-Redlich-Kwong (PSRK)

## Property estimators
- Joback
- Abdulelah-Gani (beta)

# Writers
`ugropy` allows you to convert the obtained functional groups or estimated
Expand Down
162 changes: 49 additions & 113 deletions docs/source/tutorial/gibbs_models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,57 +103,43 @@
"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 UNIFAC model is:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;31mSignature:\u001b[0m\n",
"\u001b[0munifac\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_groups\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0midentifier\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrdkit\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mChem\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrdchem\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mMol\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0midentifier_type\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'name'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0msolver\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mugropy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0milp_solvers\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0milp_solver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mILPSolver\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m<\u001b[0m\u001b[0;32mclass\u001b[0m \u001b[0;34m'ugropy.core.ilp_solvers.default_solver.DefaultSolver'\u001b[0m\u001b[0;34m>\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0msearch_multiple_solutions\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbool\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mugropy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrag_classes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgibbs_model\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgibbs_result\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGibbsFragmentationResult\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mugropy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrag_classes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgibbs_model\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgibbs_result\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGibbsFragmentationResult\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m\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",
"\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",
"\u001b[0;31mFile:\u001b[0m ~/code/ugropy/ugropy/core/frag_classes/gibbs_model/gibbs_model.py\n",
"\u001b[0;31mType:\u001b[0m method"
]
}
],
"source": [
"?unifac.get_groups"
"The signature of the UNIFAC model is:\n",
"\n",
"\n",
"```\n",
"Signature:\n",
"unifac.get_groups(\n",
" identifier: Union[str, rdkit.Chem.rdchem.Mol],\n",
" identifier_type: str = 'name',\n",
" solver: ugropy.core.ilp_solvers.ilp_solver.ILPSolver = <class 'ugropy.core.ilp_solvers.default_solver.DefaultSolver'>,\n",
" search_multiple_solutions: bool = False,\n",
") -> Union[ugropy.core.frag_classes.gibbs_model.gibbs_result.GibbsFragmentationResult, List[ugropy.core.frag_classes.gibbs_model.gibbs_result.GibbsFragmentationResult]]\n",
"Docstring:\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",
"\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",
"```"
]
},
{
Expand All @@ -172,8 +158,8 @@
{
"data": {
"text/plain": [
"[<ugropy.core.frag_classes.gibbs_model.gibbs_result.GibbsFragmentationResult at 0x7fb7ed97a2f0>,\n",
" <ugropy.core.frag_classes.gibbs_model.gibbs_result.GibbsFragmentationResult at 0x7fb7ed979150>]"
"[<ugropy.core.frag_classes.gibbs_model.gibbs_result.GibbsFragmentationResult at 0x7fbd95affc40>,\n",
" <ugropy.core.frag_classes.gibbs_model.gibbs_result.GibbsFragmentationResult at 0x7fbd95aff040>]"
]
},
"execution_count": 5,
Expand Down Expand Up @@ -381,7 +367,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand All @@ -390,7 +376,7 @@
"(np.float64(4.0464), np.float64(3.24))"
]
},
"execution_count": 13,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -403,7 +389,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -436,7 +422,7 @@
"<IPython.core.display.SVG object>"
]
},
"execution_count": 14,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -456,7 +442,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -465,7 +451,7 @@
"{'ACH': 5, 'ACCH3': 1}"
]
},
"execution_count": 15,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -487,7 +473,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -524,7 +510,7 @@
"<IPython.core.display.SVG object>"
]
},
"execution_count": 16,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -535,7 +521,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand All @@ -544,64 +530,14 @@
"(np.float64(3.9227999999999996), np.float64(2.968))"
]
},
"execution_count": 17,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"toluene.r, toluene.q"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;31mSignature:\u001b[0m\n",
"\u001b[0mpsrk\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_groups\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0midentifier\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrdkit\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mChem\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrdchem\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mMol\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0midentifier_type\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'name'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0msolver\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mugropy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0milp_solvers\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0milp_solver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mILPSolver\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m<\u001b[0m\u001b[0;32mclass\u001b[0m \u001b[0;34m'ugropy.core.ilp_solvers.default_solver.DefaultSolver'\u001b[0m\u001b[0;34m>\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0msearch_multiple_solutions\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbool\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mugropy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrag_classes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgibbs_model\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgibbs_result\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGibbsFragmentationResult\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mugropy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrag_classes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgibbs_model\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgibbs_result\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGibbsFragmentationResult\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m\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",
"\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",
"\u001b[0;31mFile:\u001b[0m ~/code/ugropy/ugropy/core/frag_classes/gibbs_model/gibbs_model.py\n",
"\u001b[0;31mType:\u001b[0m method"
]
}
],
"source": [
"?psrk.get_groups"
]
}
],
"metadata": {
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion ugropy/core/get_rdkit_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
def instantiate_mol_object(
identifier: Union[str, Chem.rdchem.Mol], identifier_type: str = "name"
) -> Chem.rdchem.Mol:
"""Instantiate a RDKit Mol object from molecule's name or SMILES.
"""Instantiate a RDKit Mol object from molecule's name, SMILES or mol.
In case that the input its already a RDKit Mol object, the function will
return the input object.
Parameters
----------
Expand Down
11 changes: 6 additions & 5 deletions ugropy/core/ilp_solvers/default_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DefaultSolver(ILPSolver):
"""Default ILP solver for the set cover problem."""

def solve_one_problem(self, not_valid_solutions: List = []) -> List[int]:
"""Solve one problem with the Pulp library.
"""Solve one `Set Cover` problem with the Pulp library.
Parameters
----------
Expand Down Expand Up @@ -50,15 +50,15 @@ def solve_one_problem(self, not_valid_solutions: List = []) -> List[int]:

problem += pulp.lpSum(sum_list) == 1

# Constaints 2: if are not_valid_solutions, the newones cannot use less
# elements than the previous ones, otherwise the first one was not
# Constaints 2: if are not_valid_solutions, the new ones cannot use
# less elements than the previous ones, otherwise the first one was not
# optimal.
if not_valid_solutions:
opt = np.sum(np.array(not_valid_solutions[0], dtype=int))

problem += pulp.lpSum([x[i] for i in range(n_frag)]) == opt

# Constaints 3: already get solutions not allowed
# Constaints 3: already got solutions not allowed
for solution in not_valid_solutions:
problem += (
pulp.lpSum([x[i] * solution[i] for i in range(n_frag)])
Expand All @@ -83,6 +83,7 @@ def solve_one_problem(self, not_valid_solutions: List = []) -> List[int]:

return [pulp.value(x[i]) for i in range(n_frag)]
else:
# No feasible problem
return None

def solve(self) -> None:
Expand All @@ -96,4 +97,4 @@ def solve(self) -> None:
break
not_valid_solutions.append(solution)
else:
self.solve_one_problem()
_ = self.solve_one_problem()
Loading

0 comments on commit 68710bf

Please sign in to comment.