@@ -283,11 +283,11 @@
Loading
283 283
284 284
    Attributes
285 285
    ----------
286 -
    current_smirks: list of tuples
286 +
    current_smirks : list of tuples
287 287
                    current SMIRKS patterns in the form (label, smirks)
288 -
    mols: list of chemper molecules
288 +
    mols : list of chemper molecules
289 289
          molecules being used to reduce the input SMIRKS
290 -
    cluster_dict: dictionary
290 +
    cluster_dict : dictionary
291 291
                  Dictionary specifying typing using current SMIRKS in the form:
292 292
                  {mol_idx:
293 293
                        { (tuple of atom indices): label } }

@@ -18,12 +18,13 @@
Loading
18 18
import os
19 19
from chemper.chemper_utils import get_data_path
20 20
from chemper.mol_toolkits.adapters import MolAdapter, BondAdapter, AtomAdapter
21 -
# define default_toolkit:
21 +
22 +
# identify which toolkits are available
23 +
HAS_OE = False
24 +
HAS_RDK = False
22 25
try:
23 -
    from openeye.oechem import OEChemIsLicensed
24 -
    if not OEChemIsLicensed():
25 -
        HAS_OE = False
26 -
    else:
26 +
    from openeye import oechem
27 +
    if oechem.OEChemIsLicensed():
27 28
        from chemper.mol_toolkits import cp_openeye
28 29
        HAS_OE = True
29 30
except ImportError:
@@ -36,105 +37,95 @@
Loading
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
@@ -202,32 +193,6 @@
Loading
202 193
203 194
    return path
204 195
205 -
206 -
# ================================================================
207 -
# get molecule from SMILES
208 -
# ================================================================
209 -
210 -
def mol_from_smiles(smiles, toolkit=None):
211 -
    """
212 -
213 -
    Parameters
214 -
    ----------
215 -
    smiles : str
216 -
             SMILES string
217 -
    toolkit : str or None
218 -
              'openeye' or 'rdkit'
219 -
              if None ChemPer will use whichever is available
220 -
221 -
    Returns
222 -
    -------
223 -
    mol : ChemPer Mol
224 -
    """
225 -
    toolkit = check_toolkit(toolkit)
226 -
    if toolkit.lower() == 'openeye':
227 -
        return cp_openeye.Mol.from_smiles(smiles)
228 -
229 -
    return cp_rdk.Mol.from_smiles(smiles)
230 -
231 196
# =======================================
232 197
# get molecules from files
233 198
# =======================================

@@ -81,8 +81,8 @@
Loading
81 81
    -------
82 82
    is_valid : boolean
83 83
    """
84 -
    from chemper.mol_toolkits.mol_toolkit import mol_from_smiles
85 -
    mol = mol_from_smiles('C')
84 +
    from chemper.mol_toolkits.mol_toolkit import Mol
85 +
    mol = Mol.from_smiles('C')
86 86
    try:
87 87
        mol.smirks_search(smirks)
88 88
        return True
Files Coverage
chemper 81.47%
Project Totals (12 files) 81.47%
592.2
TRAVIS_OS_NAME=osx
592.6
TRAVIS_PYTHON_VERSION=3.6
TRAVIS_OS_NAME=linux
1
coverage:
2
  ignore:
3
    - test/.*
4
    - compare/.*
5
    - test_helper.py
6
    - setup.py
7
  status:
8
    patch: false
9
    project:
10
      default:
11
        threshold: 80%
12
comment:
13
  layout: "header"
14
  require_changes: false
15
  branches: null
16
  behavior: default
17
  flags: null
18
  paths: null
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading