Package Chem :: Module Descriptors
[hide private]
[frames] | no frames]

Source Code for Module Chem.Descriptors

 1  # $Id: Descriptors.py 2 2006-05-06 22:54:39Z glandrum $ 
 2  # 
 3  # Copyright (C) 2001-2006 greg Landrum and Rational Discovery LLC 
 4  # 
 5  #   @@ All Rights Reserved  @@ 
 6  # 
 7  import Chem 
 8   
9 -def MolWt(mol,heavyAtomsOnly=0):
10 """ The average molecular weight of the molecule 11 12 >>> '%.2f'%MolWt(Chem.MolFromSmiles('CC')) 13 '30.07' 14 >>> '%.2f'%MolWt(Chem.MolFromSmiles('CC'),1) 15 '24.02' 16 >>> '%.2f'%MolWt(Chem.MolFromSmiles('[NH4+].[Cl-]')) 17 '53.49' 18 """ 19 hMass = Chem.GetPeriodicTable().GetAtomicWeight(1) 20 accum = 0.0 21 for atom in mol.GetAtoms(): 22 accum += atom.GetMass() 23 if not heavyAtomsOnly: 24 accum += atom.GetTotalNumHs()*hMass 25 return accum
26 MolWt.version="1.0.0" 27 28 HeavyAtomMolWt=lambda x:MolWt(x,1) 29 HeavyAtomMolWt.__doc__="""The average molecular weight of the molecule ignoring hydrogens 30 31 >>> '%.2f'%HeavyAtomMolWt(Chem.MolFromSmiles('CC')) 32 '24.02' 33 >>> '%.2f'%HeavyAtomMolWt(Chem.MolFromSmiles('[NH4+].[Cl-]')) 34 '49.46' 35 36 """ 37 HeavyAtomMolWt.version="1.0.0" 38
39 -def NumValenceElectrons(mol):
40 """ The number of valence electrons the molecule has 41 42 >>> NumValenceElectrons(Chem.MolFromSmiles('CC')) 43 14.0 44 >>> NumValenceElectrons(Chem.MolFromSmiles('C(=O)O')) 45 18.0 46 >>> NumValenceElectrons(Chem.MolFromSmiles('C(=O)[O-]')) 47 18.0 48 >>> NumValenceElectrons(Chem.MolFromSmiles('C(=O)')) 49 12.0 50 51 52 """ 53 tbl = Chem.GetPeriodicTable() 54 accum = 0.0 55 for atom in mol.GetAtoms(): 56 accum += tbl.GetNOuterElecs(atom.GetAtomicNum()) 57 accum -= atom.GetFormalCharge() 58 accum += atom.GetTotalNumHs() 59 60 return accum
61 NumValenceElectrons.version="1.0.0" 62 63 #------------------------------------ 64 # 65 # doctest boilerplate 66 #
67 -def _test():
68 import doctest,sys 69 return doctest.testmod(sys.modules["__main__"])
70 71 if __name__ == '__main__': 72 import sys 73 failed,tried = _test() 74 sys.exit(failed) 75