-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
47 lines (38 loc) · 1.09 KB
/
utils.py
File metadata and controls
47 lines (38 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
from rdkit.Chem import MolFromSmiles
from rdkit.Chem.rdchem import Mol
def is_mol(obj):
return isinstance(obj, Mol)
def to_mol(smi):
if isinstance(smi, Mol):
return smi
if isinstance(smi, str):
return MolFromSmiles(smi)
def catch_boost_argument_error(e) -> bool:
"""
This ugly code is to try and catch the Boost.Python.ArgumentError that rdkit throws when you pass an argument of
the wrong type into the function
Parameters
----------
e : an Exception
the Exception raised by the code
Returns
-------
bool
True if it is the Boost.Python.ArgumentError, False if it is not
"""
if str(e).startswith("Python argument types"):
return True
else:
return False
def to_list(obj):
if isinstance(obj, list):
return obj
elif isinstance(obj, np.ndarray):
return obj.tolist()
elif isinstance(obj, str):
return [obj]
elif not hasattr(obj, "__iter__"):
return [obj]
else:
return list(obj)