1
|
|
|
#! /usr/bin/env python |
2
|
|
|
# |
3
|
|
|
# Copyright (C) 2016 Rich Lewis <[email protected]> |
4
|
|
|
# License: 3-clause BSD |
5
|
|
|
|
6
|
1 |
|
""" |
7
|
|
|
# skchem.filters.stereo |
8
|
|
|
|
9
|
|
|
Stereo filters for scikit-chem. |
10
|
|
|
""" |
11
|
|
|
|
12
|
1 |
|
from rdkit.Chem.MolKey.InchiInfo import InchiInfo |
|
|
|
|
13
|
1 |
|
import pandas as pd |
|
|
|
|
14
|
|
|
|
15
|
1 |
|
from .base import Filter |
16
|
1 |
|
from ..utils import Suppressor |
17
|
|
|
|
18
|
|
|
|
19
|
1 |
|
class ChiralFilter(Filter): |
20
|
|
|
|
21
|
|
|
""" Filter chiral compounds. |
22
|
|
|
|
23
|
|
|
Examples: |
24
|
|
|
>>> import skchem |
25
|
|
|
>>> cf = skchem.filters.ChiralFilter() |
26
|
|
|
>>> ms = [ |
27
|
|
|
... skchem.Mol.from_smiles('F[C@@H](F)[C@H](F)F', name='achiral'), |
28
|
|
|
... skchem.Mol.from_smiles('F[C@@H](Br)[C@H](Br)F', name='chiral'), |
29
|
|
|
... skchem.Mol.from_smiles('F[C@H](Br)[C@H](Br)F', name='meso'), |
30
|
|
|
... skchem.Mol.from_smiles('FC(Br)C(Br)F', name='racemic') |
31
|
|
|
... ] |
32
|
|
|
>>> cf.transform(ms) |
33
|
|
|
achiral False |
34
|
|
|
chiral True |
35
|
|
|
meso False |
36
|
|
|
racemic False |
37
|
|
|
Name: is_chiral, dtype: bool |
38
|
|
|
|
39
|
|
|
""" |
40
|
1 |
|
def __init__(self, check_meso=True, n_jobs=1, verbose=True): |
41
|
|
|
|
42
|
|
|
""" Initialize a `ChiralFilter` object. |
43
|
|
|
|
44
|
|
|
Args: |
45
|
|
|
check_meso (bool): |
46
|
|
|
Whether to include a check for meso compounds. |
47
|
|
|
|
48
|
|
|
n_jobs (int): |
49
|
|
|
The number of procesess to run the filter in. |
50
|
|
|
|
51
|
|
|
verbose (bool): |
52
|
|
|
Whether to output a progress bar. |
53
|
|
|
""" |
54
|
|
|
|
55
|
1 |
|
self.check_meso = check_meso |
56
|
1 |
|
super(ChiralFilter, self).__init__(agg='any', n_jobs=n_jobs, |
57
|
|
|
verbose=verbose) |
58
|
|
|
|
59
|
1 |
|
@property |
60
|
|
|
def columns(self): |
61
|
1 |
|
return pd.Index(['is_chiral']) |
62
|
|
|
|
63
|
1 |
|
@staticmethod |
64
|
|
|
def is_meso(mol): |
65
|
|
|
""" Determines whether the molecule is meso. |
66
|
|
|
|
67
|
|
|
Meso compounds have chiral centres, but has a mirror plane allowing |
68
|
|
|
superposition. |
69
|
|
|
|
70
|
|
|
Examples: |
71
|
|
|
>>> import skchem |
72
|
|
|
|
73
|
|
|
>>> cf = skchem.filters.ChiralFilter() |
74
|
|
|
|
75
|
|
|
>>> meso = skchem.Mol.from_smiles('F[C@H](Br)[C@H](Br)F') |
76
|
|
|
|
77
|
|
|
>>> cf.is_meso(meso) |
78
|
|
|
True |
79
|
|
|
|
80
|
|
|
>>> non_meso = skchem.Mol.from_smiles('F[C@H](Br)[C@@H](Br)F') |
81
|
|
|
>>> cf.is_meso(non_meso) |
82
|
|
|
False |
83
|
|
|
""" |
84
|
1 |
|
with Suppressor(): |
85
|
1 |
|
info = InchiInfo(mol.to_inchi()) |
86
|
1 |
|
return info.get_sp3_stereo()['main']['non-isotopic'][2] |
87
|
|
|
|
88
|
1 |
|
def _transform_mol(self, mol): |
|
|
|
|
89
|
|
|
|
90
|
1 |
|
is_meso = self.is_meso(mol) if self.check_meso else False |
91
|
|
|
|
92
|
|
|
return any(atom.GetChiralTag() for atom in mol.atoms) and not is_meso |
93
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.