36 |
37 |
|
except ImportError: |
37 |
38 |
|
HAS_RDK = False |
38 |
39 |
|
|
39 |
|
- |
if not HAS_OE and not HAS_RDK: |
40 |
|
- |
raise ImportWarning("No Cheminformatics toolkit was found."\ |
41 |
|
- |
" currently ChemPer supports OpenEye and RDKit") |
42 |
|
- |
|
43 |
|
- |
|
44 |
|
- |
def Mol(mol): |
45 |
|
- |
""" |
46 |
|
- |
|
47 |
|
- |
Parameters |
48 |
|
- |
---------- |
49 |
|
- |
mol : Mol |
50 |
|
- |
Molecule from any supported toolkit (ChemPer, OpenEye, RDKit) |
51 |
|
- |
|
52 |
|
- |
Returns |
53 |
|
- |
------- |
54 |
|
- |
mol : ChemPer Mol |
55 |
|
- |
|
56 |
|
- |
""" |
57 |
|
- |
# if it is already a chemper molecule return as is |
58 |
|
- |
if isinstance(mol, MolAdapter): |
59 |
|
- |
return mol |
60 |
|
- |
|
61 |
|
- |
# check if this is an Openeye molecule |
62 |
|
- |
if HAS_OE and isinstance(mol, oechem.OEMolBase): |
63 |
|
- |
return cp_openeye.Mol(mol) |
64 |
|
- |
|
65 |
|
- |
# check if it is an RDK molecule |
66 |
|
- |
if HAS_RDK and isinstance(mol, Chem.rdchem.Mol): |
67 |
|
- |
return cp_rdk.Mol(mol) |
68 |
|
- |
|
69 |
|
- |
err_msg = """ |
70 |
|
- |
Your molecule has the type %s. |
71 |
|
- |
Currently ChemPer only supports OpenEye and RDKit. |
72 |
|
- |
To add support to a new toolkit submit an issue on GitHub at |
73 |
|
- |
github.com/MobleyLab/chemper |
74 |
|
- |
""" |
75 |
|
- |
raise TypeError(err_msg % type(mol)) |
76 |
|
- |
|
77 |
|
- |
|
78 |
|
- |
def Atom(atom): |
79 |
|
- |
""" |
80 |
|
- |
|
81 |
|
- |
Parameters |
82 |
|
- |
---------- |
83 |
|
- |
atom : Atom |
84 |
|
- |
Atom from any supported toolkit (ChemPer, OpenEye, RDKit) |
85 |
40 |
|
|
86 |
|
- |
Returns |
87 |
|
- |
------- |
88 |
|
- |
atom : ChemPer Atom |
89 |
|
- |
|
90 |
|
- |
""" |
91 |
|
- |
if isinstance(atom, AtomAdapter): |
92 |
|
- |
return atom |
93 |
|
- |
|
94 |
|
- |
if HAS_OE and isinstance(atom, oechem.OEAtomBase): |
95 |
|
- |
return cp_openeye.Atom(atom) |
96 |
|
- |
|
97 |
|
- |
if HAS_RDK and isinstance(atom, Chem.rdchem.Atom): |
98 |
|
- |
return cp_rdk.Atom(atom) |
99 |
|
- |
|
100 |
|
- |
err_msg = """ |
101 |
|
- |
Your atom has the type %s. |
102 |
|
- |
Currently ChemPer only supports OpenEye and RDKit. |
103 |
|
- |
To add support to a new toolkit submit an issue on GitHub at |
104 |
|
- |
github.com/MobleyLab/chemper |
105 |
|
- |
""" |
106 |
|
- |
raise TypeError(err_msg % type(atom)) |
|
41 |
+ |
# ====================================================================== |
|
42 |
+ |
# Find super Mol/Atom/Bond classes |
|
43 |
+ |
# ====================================================================== |
107 |
44 |
|
|
|
45 |
+ |
if not HAS_OE and not HAS_RDK: |
|
46 |
+ |
raise ImportWarning("No Cheminformatics toolkit was found." \ |
|
47 |
+ |
" currently ChemPer supports OpenEye and RDKit") |
108 |
48 |
|
|
109 |
|
- |
def Bond(bond): |
110 |
|
- |
""" |
111 |
|
- |
|
112 |
|
- |
Parameters |
113 |
|
- |
---------- |
114 |
|
- |
bond : Bond |
115 |
|
- |
Bond from any supported toolkit (ChemPer, OpenEye, RDKit) |
116 |
|
- |
|
117 |
|
- |
Returns |
118 |
|
- |
------- |
119 |
|
- |
bond : ChemPer Bond |
120 |
|
- |
|
121 |
|
- |
""" |
122 |
|
- |
if isinstance(bond, BondAdapter): |
123 |
|
- |
return bond |
124 |
|
- |
|
125 |
|
- |
if HAS_OE and isinstance(bond, oechem.OEBondBase): |
126 |
|
- |
return cp_openeye.Bond(bond) |
127 |
|
- |
|
128 |
|
- |
if HAS_RDK and isinstance(bond, Chem.rdchem.Bond): |
129 |
|
- |
return cp_rdk.Bond(bond) |
130 |
49 |
|
|
131 |
|
- |
err_msg = """ |
132 |
|
- |
Your bond has the type %s. |
133 |
|
- |
Currently ChemPer only supports OpenEye and RDKit. |
134 |
|
- |
To add support to a new toolkit submit an issue on GitHub at |
135 |
|
- |
github.com/MobleyLab/chemper |
136 |
|
- |
""" |
137 |
|
- |
raise TypeError(err_msg % type(bond)) |
|
50 |
+ |
class Mol: |
|
51 |
+ |
def __init__(self, mol): |
|
52 |
+ |
# if it is already a chemper molecule return as is |
|
53 |
+ |
if isinstance(mol, MolAdapter): |
|
54 |
+ |
self.mol = mol.mol |
|
55 |
+ |
self.__class__ = mol.__class__ |
|
56 |
+ |
|
|
57 |
+ |
# check if this is an Openeye molecule |
|
58 |
+ |
elif HAS_OE and isinstance(mol, oechem.OEMolBase): |
|
59 |
+ |
self.__class__ = cp_openeye.Mol |
|
60 |
+ |
self.__class__.__init__(self,mol) |
|
61 |
+ |
|
|
62 |
+ |
# check if it is an RDK molecule |
|
63 |
+ |
elif HAS_RDK and isinstance(mol, Chem.rdchem.Mol): |
|
64 |
+ |
self.__class__ = cp_rdk.Mol |
|
65 |
+ |
self.__class__.__init__(self, mol) |
|
66 |
+ |
|
|
67 |
+ |
else: |
|
68 |
+ |
err_msg = """ |
|
69 |
+ |
Your molecule has the type %s. |
|
70 |
+ |
Currently ChemPer only supports OpenEye and RDKit. |
|
71 |
+ |
To add support to a new toolkit submit an issue on GitHub at |
|
72 |
+ |
github.com/MobleyLab/chemper |
|
73 |
+ |
""" |
|
74 |
+ |
raise TypeError(err_msg % type(mol)) |
|
75 |
+ |
|
|
76 |
+ |
@staticmethod |
|
77 |
+ |
def from_smiles(smiles): |
|
78 |
+ |
if HAS_OE: |
|
79 |
+ |
return cp_openeye.Mol.from_smiles(smiles) |
|
80 |
+ |
return cp_rdk.Mol.from_smiles(smiles) |
|
81 |
+ |
|
|
82 |
+ |
class Atom: |
|
83 |
+ |
def __init__(self, atom): |
|
84 |
+ |
|
|
85 |
+ |
if isinstance(atom, AtomAdapter): |
|
86 |
+ |
self.atom = atom.atom |
|
87 |
+ |
self.__class__ = atom.__class__ |
|
88 |
+ |
|
|
89 |
+ |
elif HAS_OE and isinstance(atom, oechem.OEAtomBase): |
|
90 |
+ |
self.__class__ = cp_openeye.Atom |
|
91 |
+ |
self.__class__.__init__(self, atom) |
|
92 |
+ |
|
|
93 |
+ |
elif HAS_RDK and isinstance(atom, Chem.rdchem.Atom): |
|
94 |
+ |
self.__class__ = cp_rdk.Atom |
|
95 |
+ |
self.__class__.__init__(self, atom) |
|
96 |
+ |
|
|
97 |
+ |
else: |
|
98 |
+ |
err_msg = """ |
|
99 |
+ |
Your atom has the type %s. |
|
100 |
+ |
Currently ChemPer only supports OpenEye and RDKit. |
|
101 |
+ |
To add support to a new toolkit submit an issue on GitHub at |
|
102 |
+ |
github.com/MobleyLab/chemper |
|
103 |
+ |
""" |
|
104 |
+ |
raise TypeError(err_msg % type(atom)) |
|
105 |
+ |
|
|
106 |
+ |
|
|
107 |
+ |
class Bond: |
|
108 |
+ |
def __init__(self, bond): |
|
109 |
+ |
if isinstance(bond, BondAdapter): |
|
110 |
+ |
self.bond = bond.bond |
|
111 |
+ |
self.__class__ = bond.__class__ |
|
112 |
+ |
|
|
113 |
+ |
elif HAS_OE and isinstance(bond, oechem.OEBondBase): |
|
114 |
+ |
self.__class__ = cp_openeye.Bond |
|
115 |
+ |
self.__class__.__init__(self,bond) |
|
116 |
+ |
|
|
117 |
+ |
elif HAS_RDK and isinstance(bond, Chem.rdchem.Bond): |
|
118 |
+ |
self.__class__ = cp_rdk.Bond |
|
119 |
+ |
self.__class__.__init__(self,bond) |
|
120 |
+ |
|
|
121 |
+ |
else: |
|
122 |
+ |
err_msg = """ |
|
123 |
+ |
Your bond has the type %s. |
|
124 |
+ |
Currently ChemPer only supports OpenEye and RDKit. |
|
125 |
+ |
To add support to a new toolkit submit an issue on GitHub at |
|
126 |
+ |
github.com/MobleyLab/chemper |
|
127 |
+ |
""" |
|
128 |
+ |
raise TypeError(err_msg % type(bond)) |
138 |
129 |
|
|
139 |
130 |
|
# ======================================= |
140 |
131 |
|
# check user specifications |