Package rdkit :: Package Chem :: Module Lipinski

[hide private]
[frames] | no frames]

# Source Code for Module rdkit.Chem.Lipinski

      1  # $Id$
      2  #
      3  # Copyright (C) 2001-2006 greg Landrum and Rational Discovery LLC
      4  #
      5  #   @@ All Rights Reserved @@
      6  #  This file is part of the RDKit.
      7  #  The contents are covered by the terms of the BSD license
      8  #  which is included in the file license.txt, found at the root
      9  #  of the RDKit source tree.
     10  #
     11  """ Calculation of Lipinski parameters for molecules
     12
     13  """
     14  #from Chem import rdchem
     15  from rdkit import Chem
     16  from rdkit.Chem import rdMolDescriptors
     17
     18  #-----------------------------------
     19  # on import build the SMARTS patterns so we only have to do it once
     20  #-----------------------------------
     21
     22  # The Daylight SMARTS expressions for
     23  # recognizing H-bond donors and acceptors in the Lipinski scheme.
     24  # HDonor     '[!#6;!H0;-0]'
     25  # HAcceptor  '[$([!#6;+0]);!$([F,Cl,Br,I]);
     26  #             !$([o,s,nX3]);!$([Nv5,Pv5,Sv4,Sv6])]'
     27  # Heteroatom '[B,N,O,P,S,F,Cl,Br,I]'
     28
     29
     30  # 2 definitions adapted from those in the Gobbi Paper
     31  #  NOTE: if you want traditional Lipinski numbers, you
     32  #  should use NOCounts (below) instead of HAcceptor
     33  #
     34  HDonorSmarts = Chem.MolFromSmarts('[$([N;!H0;v3]),$([N;!H0;+1;v4]),$([O,S;H1;+0]),$([n;H1;+0])]')
     35  # changes log for HAcceptorSmarts:
     36  #  v2, 1-Nov-2008, GL : fix amide-N exclusion; remove Fs from definition
     37  HAcceptorSmarts = Chem.MolFromSmarts('[$([O,S;H1;v2]-[!$(*=[O,N,P,S])]),\
     38  $([O,S;H0;v2]),$([O,S;-]),\
     39  $([N;v3;!$(N-*=!@[O,N,P,S])]),\
     40  $([nH0,o,s;+0])\
     41  ]')
     42  HeteroatomSmarts = Chem.MolFromSmarts('[!#6;!#1]')
     43  #  NOTE: the Rotatable bond smarts here doesn't treat deuteriums (which are left in the graph
     44  #  and therefore contribute to the degree of a carbon) the same as hydrogens (which are removed
     45  #  from the graph). So the bond in [2H]C([2H])([2H])C([2H])([2H])[2H] *is* considered
     46  #  rotatable.
     47  RotatableBondSmarts = Chem.MolFromSmarts('[!$(*#*)&!D1]-&!@[!$(*#*)&!D1]')
     48  NHOHSmarts = Chem.MolFromSmarts('[#8H1,#7H1,#7H2,#7H3]')
     49  NOCountSmarts = Chem.MolFromSmarts('[#7,#8]')
     50
     51  # this little trick saves duplicated code
     52 -def _NumMatches(mol,smarts):
     53    return len(mol.GetSubstructMatches(smarts,uniquify=1))
     54
     55  NumHDonors = lambda x:rdMolDescriptors.CalcNumHBD(x)
     56  NumHDonors.__doc__="Number of Hydrogen Bond Donors"
     57  NumHDonors.version="1.0.0"
     58  _HDonors = lambda x,y=HDonorSmarts:x.GetSubstructMatches(y,uniquify=1)
     59  NumHAcceptors = lambda x:rdMolDescriptors.CalcNumHBA(x)
     60  NumHAcceptors.__doc__="Number of Hydrogen Bond Acceptors"
     61  NumHAcceptors.version="2.0.0"
     62  _HAcceptors = lambda x,y=HAcceptorSmarts:x.GetSubstructMatches(y,uniquify=1)
     63  NumHeteroatoms = lambda x:rdMolDescriptors.CalcNumHeteroatoms(x)
     64  NumHeteroatoms.__doc__="Number of Heteroatoms"
     65  NumHeteroatoms.version="1.0.0"
     66  _Heteroatoms = lambda x,y=HeteroatomSmarts:x.GetSubstructMatches(y,uniquify=1)
     67  NumRotatableBonds = lambda x:rdMolDescriptors.CalcNumRotatableBonds(x)
     68  NumRotatableBonds.__doc__="Number of Rotatable Bonds"
     69  NumRotatableBonds.version="1.0.0"
     70  _RotatableBonds = lambda x,y=RotatableBondSmarts:x.GetSubstructMatches(y,uniquify=1)
     71  NOCount = lambda x:rdMolDescriptors.CalcNumLipinskiHBA(x)
     72  NOCount.__doc__="Number of Nitrogens and Oxygens"
     73  NOCount.version="1.0.0"
     74  NHOHCount = lambda x:rdMolDescriptors.CalcNumLipinskiHBD(x)
     75  NHOHCount.__doc__="Number of NHs or OHs"
     76  NHOHCount.version="2.0.0"
     77
     78  RingCount=lambda x:rdMolDescriptors.CalcNumRings(x)
     79  RingCount.version = "1.0.0"
     80
     81 -def HeavyAtomCount(mol):
     82    " Number of heavy atoms a molecule."
     83    return mol.GetNumHeavyAtoms()
     84  HeavyAtomCount.version = "1.0.1"
     85
     86
     87  _bulkConvert=("CalcFractionCSP3","CalcNumAromaticRings","CalcNumSaturatedRings","CalcNumAromaticHeterocycles",
     88                "CalcNumAromaticCarbocycles","CalcNumSaturatedHeterocycles","CalcNumSaturatedCarbocycles","CalcNumAliphaticRings",
     89                "CalcNumAliphaticHeterocycles","CalcNumAliphaticCarbocycles")
     90  for txt in _bulkConvert:
     91    _cfn = getattr(rdMolDescriptors,txt)
     92    _fn = lambda x,y=_cfn:y(x)
     93    try:
     94      _fn.version=getattr(rdMolDescriptors,"_"+txt+"_version")
     95    except AttributeError:
     96      pass
     97    _fn.__doc__=_cfn.__doc__
     98    nm = txt.replace("Calc","")
     99    locals()[nm]=_fn
    100