|
Package rdkit ::
Package Chem
|
|
1
2
3
4
5
6
7
8
9 """ A module for molecules and stuff
10
11 see Chem/index.html in the doc tree for documentation
12
13 """
14 from rdkit import rdBase
15 from rdkit import RDConfig
16
17 from rdkit import DataStructs
18 from rdkit.Geometry import rdGeometry
19 import PeriodicTable as pyPeriodicTable
20 import rdchem
21 _HasSubstructMatchStr=rdchem._HasSubstructMatchStr
22 from rdchem import *
23 from rdmolfiles import *
24 from rdmolops import *
25
27 try:
28 from rdkit.Chem import CDXMLWriter
29 except:
30 CDXMLWriter = None
31 if CDXMLWriter is None:
32 return ''
33 try:
34 from cStringIO import StringIO
35 except:
36 from StringIO import StringIO
37 if not showAllAtoms and (which < 0 or not len(maps) or len(maps)<which+1):
38 return ''
39 io = StringIO()
40 matchBonds = []
41 matchAtoms = []
42 if not showAllAtoms:
43 mapL = maps[which]
44 for bondIdx in range(patt.GetNumBonds()):
45 bnd = patt.GetBondWithIdx(bondIdx)
46 begIdx = bnd.GetBeginAtomIdx()
47 endIdx = bnd.GetEndAtomIdx()
48 molBegIdx = mapL[begIdx]
49 molEndIdx = mapL[endIdx]
50 matchBonds.append(mol.GetBondBetweenAtoms(molBegIdx,molEndIdx).GetIdx())
51 else:
52 for mapL in maps:
53 for idx in mapL:
54 if idx not in matchAtoms: matchAtoms.append(idx)
55
56 CDXMLWriter.MolToCDXML(mol,io,highlightBonds=matchBonds,
57 highlightAtoms=matchAtoms)
58 cdxml = io.getvalue()
59 cdxml = cdxml.replace('><','>\n<')
60 return cdxml
61
63 try:
64 from rdkit.utils import chemdraw
65 except:
66 chemdraw = None
67 cdxml = GetSmartsMatchCDXML(mol,patt,maps,which=which,showAllAtoms=showAllAtoms)
68 if cdxml and chemdraw:
69 chemdraw.CDXDisplay(cdxml)
70 return cdxml
71
79
83
93
112
114 """
115 >>> mol = Chem.MolFromSmiles('[C@H](Cl)(F)Br')
116 >>> FindMolChiralCenters(mol)
117 [(0, 'R')]
118 >>> mol = Chem.MolFromSmiles('[C@@H](Cl)(F)Br')
119 >>> FindMolChiralCenters(mol)
120 [(0, 'S')]
121
122 >>> FindMolChiralCenters(Chem.MolFromSmiles('CCC'))
123 []
124
125 """
126 AssignAtomChiralCodes(mol)
127 centers = []
128 for atom in mol.GetAtoms():
129 if atom.HasProp('_CIPCode'):
130 centers.append((atom.GetIdx(),atom.GetProp('_CIPCode')))
131 return centers
132