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   
32 -def QuickSmartsMatch(smi, sma, unique=True, display=False):
33 m = MolFromSmiles(smi) 34 p = MolFromSmarts(sma) 35 res = m.GetSubstructMatches(p, unique) 36 if display: 37 pass 38 return res
39 40
41 -def CanonSmiles(smi, useChiral=1):
42 m = MolFromSmiles(smi) 43 return MolToSmiles(m, useChiral)
44 45
46 -def SupplierFromFilename(fileN, delim='', **kwargs):
47 ext = fileN.split('.')[-1].lower() 48 if ext == 'sdf': 49 suppl = SDMolSupplier(fileN, **kwargs) 50 elif ext == 'csv': 51 if not delim: 52 delim = ',' 53 suppl = SmilesMolSupplier(fileN, delimiter=delim, **kwargs) 54 elif ext == 'txt': 55 if not delim: 56 delim = '\t' 57 suppl = SmilesMolSupplier(fileN, delimiter=delim, **kwargs) 58 elif ext == 'tdt': 59 suppl = TDTMolSupplier(fileN, delimiter=delim, **kwargs) 60 else: 61 raise ValueError("unrecognized extension: %s" % ext) 62 63 return suppl
64 65
66 -def FindMolChiralCenters(mol, force=True, includeUnassigned=False):
67 """ 68 >>> from rdkit import Chem 69 >>> mol = Chem.MolFromSmiles('[C@H](Cl)(F)Br') 70 >>> FindMolChiralCenters(mol) 71 [(0, 'R')] 72 >>> mol = Chem.MolFromSmiles('[C@@H](Cl)(F)Br') 73 >>> FindMolChiralCenters(mol) 74 [(0, 'S')] 75 76 >>> FindMolChiralCenters(Chem.MolFromSmiles('CCC')) 77 [] 78 79 By default unassigned stereo centers are not reported: 80 >>> mol = Chem.MolFromSmiles('C[C@H](F)C(F)(Cl)Br') 81 >>> FindMolChiralCenters(mol,force=True) 82 [(1, 'S')] 83 84 but this can be changed: 85 >>> FindMolChiralCenters(mol,force=True,includeUnassigned=True) 86 [(1, 'S'), (3, '?')] 87 88 The handling of unassigned stereocenters for dependent stereochemistry is not correct: 89 >>> Chem.FindMolChiralCenters(Chem.MolFromSmiles('C1CC(C)C(C)C(C)C1'),includeUnassigned=True) 90 [(2, '?'), (6, '?')] 91 >>> Chem.FindMolChiralCenters(Chem.MolFromSmiles('C1C[C@H](C)C(C)[C@H](C)C1'),includeUnassigned=True) 92 [(2, 'S'), (4, '?'), (6, 'R')] 93 94 """ 95 AssignStereochemistry(mol, force=force, flagPossibleStereoCenters=includeUnassigned) 96 centers = [] 97 for atom in mol.GetAtoms(): 98 if atom.HasProp('_CIPCode'): 99 centers.append((atom.GetIdx(), atom.GetProp('_CIPCode'))) 100 elif includeUnassigned and atom.HasProp('_ChiralityPossible'): 101 centers.append((atom.GetIdx(), '?')) 102 return centers
103 104 105 #------------------------------------ 106 # 107 # doctest boilerplate 108 #
109 -def _test():
110 import doctest, sys 111 return doctest.testmod(sys.modules["__main__"])
112 113 114 if __name__ == '__main__': 115 import sys 116 failed, tried = _test() 117 sys.exit(failed) 118