1
2
3
4
5
6
7 """ Import all RDKit chemistry modules
8
9 """
10 import rdBase
11 import RDConfig
12 import Numeric
13 import DataStructs
14 from Geometry import rdGeometry
15 from Chem import *
16 from rdPartialCharges import *
17 from rdDepictor import *
18 from rdForceFieldHelpers import *
19 from Chem.ChemicalFeatures import *
20 from rdDistGeom import *
21 from rdMolAlign import *
22 from rdMolTransforms import *
23 from rdShapeHelpers import *
24 from rdChemReactions import *
25 import ForceField
26 Mol.Compute2DCoords = Compute2DCoords
27 Mol.ComputeGasteigerCharges = ComputeGasteigerCharges
28
29
46
51
71
85
87 """ Returns a generator for the virtual library defined by
88 a reaction and a sequence of sidechain sets
89
90 >>> import Chem
91 >>> from Chem import AllChem
92 >>> s1=[Chem.MolFromSmiles(x) for x in ('NC','NCC')]
93 >>> s2=[Chem.MolFromSmiles(x) for x in ('OC=O','OC(=O)C')]
94 >>> rxn = AllChem.ReactionFromSmarts('[O:2]=[C:1][OH].[N:3]>>[O:2]=[C:1][N:3]')
95 >>> r = AllChem.EnumerateLibraryFromReaction(rxn,[s2,s1])
96 >>> [Chem.MolToSmiles(x[0]) for x in list(r)]
97 ['CNC=O', 'CCNC=O', 'CNC(=O)C', 'CCNC(=O)C']
98
99 Note that this is all done in a lazy manner, so "infinitely" large libraries can
100 be done without worrying about running out of memory. Your patience will run out first:
101
102 Define a set of 10000 amines:
103 >>> amines = (Chem.MolFromSmiles('N'+'C'*x) for x in range(10000))
104
105 ... a set of 10000 acids
106 >>> acids = (Chem.MolFromSmiles('OC(=O)'+'C'*x) for x in range(10000))
107
108 ... now the virtual library (1e8 compounds in principle):
109 >>> r = AllChem.EnumerateLibraryFromReaction(rxn,[acids,amines])
110
111 ... look at the first 4 compounds:
112 >>> [Chem.MolToSmiles(r.next()[0]) for x in range(4)]
113 ['NC=O', 'CNC=O', 'CCNC=O', 'CCCNC=O']
114
115
116 """
117 if len(sidechainSets) != reaction.GetNumReactantTemplates():
118 raise ValueError,'%d sidechains provided, %d required'%(len(sidechainSets),reaction.getNumReactantTemplates())
119
120 def _combiEnumerator(items,depth=0):
121 for item in items[depth]:
122 if depth+1 < len(items):
123 v = _combiEnumerator(items,depth+1)
124 for entry in v:
125 l=[item]
126 l.extend(entry)
127 yield l
128 else:
129 yield [item]
130 for chains in _combiEnumerator(sidechainSets):
131 prodSets = reaction.RunReactants(chains)
132 for prods in prodSets:
133 yield prods
134
135
136
137
138
140 import doctest,sys
141 return doctest.testmod(sys.modules["__main__"])
142
143
144 if __name__ == '__main__':
145 import sys
146 failed,tried = _test()
147 sys.exit(failed)
148