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

Source Code for Module rdkit.Chem.AtomPairs.Sheridan

  1  # 
  2  #  Copyright (C) 2015 Greg Landrum 
  3  # 
  4  #   @@ All Rights Reserved @@ 
  5  #  This file is part of the RDKit. 
  6  #  The contents are covered by the terms of the BSD license 
  7  #  which is included in the file license.txt, found at the root 
  8  #  of the RDKit source tree. 
  9  # 
 10  """ Contains an implementation of Physicochemical property fingerprints, as 
 11  described in: 
 12  Kearsley, S. K. et al. 
 13  "Chemical Similarity Using Physiochemical Property Descriptors." 
 14  J. Chem.Inf. Model. 36, 118-127 (1996) 
 15  """ 
 16  from rdkit.DataStructs import IntSparseIntVect 
 17  from rdkit import Chem 
 18  from rdkit.Chem import rdMolDescriptors 
 19  from rdkit import DataStructs 
 20   
 21  from rdkit.Chem.rdMolDescriptors import GetAtomPairFingerprint,GetTopologicalTorsionFingerprint 
 22   
 23   
 24  numPathBits=rdMolDescriptors.AtomPairsParameters.numPathBits 
 25  _maxPathLen=(1<<numPathBits)-1 
 26  numFpBits=numPathBits+2*rdMolDescriptors.AtomPairsParameters.codeSize 
 27  fpLen=1<<numFpBits 
 28   
 29  import os.path,re 
 30  from rdkit import RDConfig 
31 -def _readPattyDefs(fname=os.path.join(RDConfig.RDDataDir,'SmartsLib','patty_rules.txt')):
32 with open(fname,'r') as inf: 33 lines = [x.strip().split('# ')[0].strip() for x in inf] 34 splitl = [re.split('[ ]*',x) for x in lines if x != ''] 35 matchers = [] 36 for tpl in splitl: 37 if len(tpl)>1: 38 mol = Chem.MolFromSmarts(tpl[0]) 39 if mol is None: 40 continue 41 nm = tpl[1] 42 matchers.append((mol,nm)) 43 return matchers
44 45 _pattyDefs=None
46 -def AssignPattyTypes(mol,defns=None):
47 """ 48 49 >>> from rdkit import Chem 50 >>> AssignPattyTypes(Chem.MolFromSmiles('OCC(=O)O')) 51 ['POL', 'HYD', 'OTH', 'ANI', 'ANI'] 52 53 """ 54 global _pattyDefs 55 if defns is None: 56 if _pattyDefs is None: 57 _pattyDefs = _readPattyDefs() 58 defns = _pattyDefs 59 res = ['']*mol.GetNumAtoms() 60 for matcher,nm in defns: 61 matches = mol.GetSubstructMatches(matcher,uniquify=False) 62 for match in matches: 63 res[match[0]] = nm 64 return res
65 66 typMap=dict(CAT=1,ANI=2,POL=3,DON=4,ACC=5,HYD=6,OTH=7)
67 -def GetBPFingerprint(mol,fpfn=GetAtomPairFingerprint):
68 """ 69 >>> from rdkit import Chem 70 >>> fp = GetBPFingerprint(Chem.MolFromSmiles('OCC(=O)O')) 71 >>> fp.GetTotalVal() 72 10 73 >>> nze=fp.GetNonzeroElements() 74 >>> sorted([(k,v) for k,v in nze.items()]) 75 [(32834, 1), (49219, 2), (98370, 2), (98401, 1), (114753, 2), (114786, 1), (114881, 1)] 76 77 """ 78 typs = [typMap[x] for x in AssignPattyTypes(mol)] 79 fp = fpfn(mol,atomInvariants=typs) 80 return fp
81
82 -def GetBTFingerprint(mol,fpfn=GetTopologicalTorsionFingerprint):
83 """ 84 >>> from rdkit import Chem 85 >>> mol = Chem.MolFromSmiles('OCC(N)O') 86 >>> AssignPattyTypes(mol) 87 ['POL', 'HYD', 'HYD', 'CAT', 'POL'] 88 >>> fp = GetBTFingerprint(mol) 89 >>> fp.GetTotalVal() 90 2 91 >>> nze=fp.GetNonzeroElements() 92 >>> sorted([(k,v) for k,v in nze.items()]) 93 [(538446850L, 1), (538446852L, 1)] 94 95 """ 96 return GetBPFingerprint(mol,fpfn=fpfn)
97 98 99 100 101 #------------------------------------ 102 # 103 # doctest boilerplate 104 #
105 -def _test():
106 import doctest,sys 107 return doctest.testmod(sys.modules["__main__"])
108 109 110 if __name__ == '__main__': 111 import sys 112 failed,tried = _test() 113 sys.exit(failed) 114