Skip to content

Commit b127ea6

Browse files
Merge pull request #37 from ipqa-research/pubchempy_error
Pubchempy error
2 parents ecd38dc + b71d1c5 commit b127ea6

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
name: Tox
22

33
on:
4-
- push
5-
- pull_request
6-
- release
7-
- workflow_dispatch
4+
push:
5+
pull_request:
6+
release:
7+
workflow_dispatch:
8+
schedule:
9+
- cron: '0 12 * * *' # Every day at 09:00 ART (12:00 UTC)
810

911
jobs:
1012
test-linux:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ markers = [
3535

3636
[project]
3737
name = "ugropy"
38-
version = "3.1.5"
38+
version = "3.1.6"
3939
authors = [{name = "Brandolín, Salvador Eduardo", email = "[email protected]"}]
4040
license = {text = "The MIT License"}
4141
readme = "README.md"

ugropy/core/frag_classes/gibbs_model/gibbs_result.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class GibbsFragmentationResult(FragmentationResult):
2222
Dictionary of subgroups atoms indexes.
2323
subgroups_info : pd.DataFrame
2424
DataFrame with subgroups information.
25+
calculate_r_q : bool
26+
If True, calculate R and Q values for the molecule.
27+
calculate_num_dict : bool, optional
28+
If True, calculate the subgroup numbers dictionary. Default is True.
2529
2630
Attributes
2731
----------
@@ -37,6 +41,9 @@ class GibbsFragmentationResult(FragmentationResult):
3741
Gibss excess model R value estimation of the molecule.
3842
q : float
3943
Gibss excess model Q value estimation of the molecule.
44+
subgroups_num : dict
45+
Dictionary with the subgroup numbers and the number of times they
46+
appear in the molecule.
4047
"""
4148

4249
def __init__(
@@ -46,12 +53,14 @@ def __init__(
4653
subgroups_atoms_indexes: dict,
4754
subgroups_info: pd.DataFrame,
4855
calculate_r_q: bool,
56+
calculate_num_dict: bool = True,
4957
):
5058
super().__init__(molecule, subgroups, subgroups_atoms_indexes)
5159

5260
r = 0.0
5361
q = 0.0
5462

63+
# R and Q
5564
if self.subgroups != {}:
5665
if calculate_r_q:
5766
for group, n in self.subgroups.items():
@@ -66,3 +75,16 @@ def __init__(
6675
else:
6776
self.r = None
6877
self.q = None
78+
79+
# Subgroups numbers dictionary
80+
if self.subgroups != {}:
81+
if calculate_num_dict:
82+
self.subgroups_num = {}
83+
84+
for group, occ in self.subgroups.items():
85+
snum = int(subgroups_info.loc[group, "subgroup_number"])
86+
87+
self.subgroups_num[snum] = occ
88+
89+
else:
90+
self.subgroups_num = None

ugropy/core/get_rdkit_object.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,16 @@ def instantiate_mol_from_name(name: str) -> Chem.rdchem.Mol:
7474
"""
7575
try:
7676
pcp_object = pcp.get_compounds(name, "name")[0]
77-
smiles = pcp_object.canonical_smiles
78-
chem_object = Chem.MolFromSmiles(smiles)
77+
78+
if pcp_object.canonical_smiles:
79+
chem_object = Chem.MolFromSmiles(pcp_object.canonical_smiles)
80+
elif pcp_object.inchi:
81+
chem_object = Chem.MolFromInchi(pcp_object.inchi)
82+
else:
83+
raise IndexError(
84+
f"Could not find a SMILES or InChI for the molecule '{name}' "
85+
"on PubChem."
86+
)
7987
except IndexError:
8088
raise ValueError(
8189
f"Could not find a molecule with the name '{name}' on " "PubChem"

0 commit comments

Comments
 (0)