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