Package rdkit :: Package Chem

[hide private]
[frames] | no frames]

# Source Code for Package rdkit.Chem

      1  ## Automatically adapted for numpy.oldnumeric Jun 27, 2008 by -c
      2
      3  # $Id$
      4  #
      5  #  Copyright (C) 2000-2008  greg Landrum and Rational Discovery LLC
      6  #
      7  #   @@ All Rights Reserved @@
      8  #  This file is part of the RDKit.
      9  #  The contents are covered by the terms of the BSD license
     10  #  which is included in the file license.txt, found at the root
     11  #  of the RDKit source tree.
     12  #
     13  """ A module for molecules and stuff
     14
     15   see Chem/index.html in the doc tree for documentation
     16
     17  """
     18  from rdkit import rdBase
     19  from rdkit import RDConfig
     20
     21  from rdkit import DataStructs
     22  from rdkit.Geometry import rdGeometry
     23  from rdkit.Chem import PeriodicTable as pyPeriodicTable
     24  from rdkit.Chem import rdchem
     25  _HasSubstructMatchStr=rdchem._HasSubstructMatchStr
     26  from rdkit.Chem.rdchem import *
     27  from rdkit.Chem.rdmolfiles import *
     28  from rdkit.Chem.rdmolops import *
     29  from rdkit.Chem.inchi import *
     30
     31 -def QuickSmartsMatch(smi,sma,unique=True,display=False):
     32    m = MolFromSmiles(smi)
     33    p = MolFromSmarts(sma)
     34    res = m.GetSubstructMatches(p,unique)
     35    if display:
     36      pass
     37    return res
     38
     39 -def CanonSmiles(smi,useChiral=1):
     40    m = MolFromSmiles(smi)
     41    return MolToSmiles(m,useChiral)
     42
     43 -def SupplierFromFilename(fileN,delim='',**kwargs):
     44    ext = fileN.split('.')[-1].lower()
     45    if ext=='sdf':
     46      suppl = SDMolSupplier(fileN,**kwargs)
     47    elif ext=='csv':
     48      if not delim:
     49        delim = ','
     50      suppl = SmilesMolSupplier(fileN,delimiter=delim,**kwargs)
     51    elif ext=='txt':
     52      if not delim:
     53        delim='\t'
     54      suppl = SmilesMolSupplier(fileN,delimiter=delim,**kwargs)
     55    elif ext=='tdt':
     56      suppl = TDTMolSupplier(fileN,delimiter=delim,**kwargs)
     57    else:
     58      raise ValueError("unrecognized extension: %s"%ext)
     59
     60    return suppl
     61
     62 -def FindMolChiralCenters(mol,force=True,includeUnassigned=False):
     63    """
     64      >>> from rdkit import Chem
     65      >>> mol = Chem.MolFromSmiles('[C@H](Cl)(F)Br')
     66      >>> FindMolChiralCenters(mol)
     67      [(0, 'R')]
     68      >>> mol = Chem.MolFromSmiles('[C@@H](Cl)(F)Br')
     69      >>> FindMolChiralCenters(mol)
     70      [(0, 'S')]
     71
     72      >>> FindMolChiralCenters(Chem.MolFromSmiles('CCC'))
     73      []
     74
     75      By default unassigned stereo centers are not reported:
     76      >>> mol = Chem.MolFromSmiles('C[C@H](F)C(F)(Cl)Br')
     77      >>> FindMolChiralCenters(mol,force=True)
     78      [(1, 'S')]
     79
     80      but this can be changed:
     81      >>> FindMolChiralCenters(mol,force=True,includeUnassigned=True)
     82      [(1, 'S'), (3, '?')]
     83
     84      The handling of unassigned stereocenters for dependent stereochemistry is not correct:
     85      >>> Chem.FindMolChiralCenters(Chem.MolFromSmiles('C1CC(C)C(C)C(C)C1'),includeUnassigned=True)
     86      [(2, '?'), (6, '?')]
     87      >>> Chem.FindMolChiralCenters(Chem.MolFromSmiles('C1C[C@H](C)C(C)[C@H](C)C1'),includeUnassigned=True)
     88      [(2, 'S'), (4, '?'), (6, 'R')]
     89
     90    """
     91    AssignStereochemistry(mol,force=force, flagPossibleStereoCenters=includeUnassigned)
     92    centers = []
     93    for atom in mol.GetAtoms():
     94      if atom.HasProp('_CIPCode'):
     95        centers.append((atom.GetIdx(),atom.GetProp('_CIPCode')))
     96      elif includeUnassigned and atom.HasProp('_ChiralityPossible'):
     97        centers.append((atom.GetIdx(),'?'))
     98    return centers
     99
    100  #------------------------------------
    101  #
    102  #  doctest boilerplate
    103  #
    104 -def _test():
    105    import doctest,sys
    106    return doctest.testmod(sys.modules["__main__"])
    107
    108
    109  if __name__ == '__main__':
    110    import sys
    111    failed,tried = _test()
    112    sys.exit(failed)
    113