rdkit.Chem.Descriptors

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

# Source Code for Module rdkit.Chem.Descriptors

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