1
2
3
4
5
6
7
8
9
10
11 from rdkit import Chem
12 import collections
13
15 return (hasattr(collections,'Callable') and isinstance(thing,collections.Callable)) or \
16 hasattr(thing,'__call__')
17
18 _descList=[]
20 global _descList,descList
21 from rdkit.Chem import GraphDescriptors,MolSurf,Lipinski,Fragments,Crippen
22 from rdkit.Chem.EState import EState_VSA
23 mods = [GraphDescriptors,MolSurf,EState_VSA,Lipinski,Crippen,Fragments]
24
25 otherMods = [Chem]
26
27 for nm,thing in namespace.iteritems():
28 if nm[0]!='_' and _isCallable(thing):
29 _descList.append((nm,thing))
30
31 others = []
32 for mod in otherMods:
33 tmp = dir(mod)
34 for name in tmp:
35 if name[0] != '_':
36 thing = getattr(mod,name)
37 if _isCallable(thing):
38 others.append(name)
39
40 for mod in mods:
41 tmp = dir(mod)
42
43 for name in tmp:
44 if name[0] != '_' and name[-1] != '_' and name not in others:
45
46 if name[:2]=='py' and name[2:] in tmp:
47 continue
48 thing = getattr(mod,name)
49 if _isCallable(thing):
50 namespace[name]=thing
51 _descList.append((name,thing))
52 descList=_descList
53
54 from rdkit.Chem import rdMolDescriptors as _rdMolDescriptors
55 MolWt = lambda *x,**y:_rdMolDescriptors._CalcMolWt(*x,**y)
56 MolWt.version=_rdMolDescriptors._CalcMolWt_version
57 MolWt.__doc__="""The average molecular weight of the molecule ignoring hydrogens
58
59 >>> MolWt(Chem.MolFromSmiles('CC'))
60 30.07...
61 >>> MolWt(Chem.MolFromSmiles('[NH4+].[Cl-]'))
62 53.49...
63
64 """
65
66 HeavyAtomMolWt=lambda x:MolWt(x,True)
67 HeavyAtomMolWt.__doc__="""The average molecular weight of the molecule ignoring hydrogens
68
69 >>> HeavyAtomMolWt(Chem.MolFromSmiles('CC'))
70 24.02...
71 >>> HeavyAtomMolWt(Chem.MolFromSmiles('[NH4+].[Cl-]'))
72 49.46...
73
74 """
75 HeavyAtomMolWt.version="1.0.0"
76
78 """ The number of valence electrons the molecule has
79
80 >>> NumValenceElectrons(Chem.MolFromSmiles('CC'))
81 14.0
82 >>> NumValenceElectrons(Chem.MolFromSmiles('C(=O)O'))
83 18.0
84 >>> NumValenceElectrons(Chem.MolFromSmiles('C(=O)[O-]'))
85 18.0
86 >>> NumValenceElectrons(Chem.MolFromSmiles('C(=O)'))
87 12.0
88
89
90 """
91 tbl = Chem.GetPeriodicTable()
92 accum = 0.0
93 for atom in mol.GetAtoms():
94 accum += tbl.GetNOuterElecs(atom.GetAtomicNum())
95 accum -= atom.GetFormalCharge()
96 accum += atom.GetTotalNumHs()
97
98 return accum
99 NumValenceElectrons.version="1.0.0"
100
158 MolecularFormula=lambda x:_rdMolDescriptors.CalcMolFormula(x)
159 MolecularFormula.version=_rdMolDescriptors._CalcMolFormula_version
160
161 _setupDescriptors(locals())
162
163
164
165
166
167
168
170 import doctest,sys
171 return doctest.testmod(sys.modules["__main__"],optionflags=doctest.ELLIPSIS)
172
173 if __name__ == '__main__':
174 import sys
175 failed,tried = _test()
176 sys.exit(failed)
177