Package Chem :: Package Pharm2D :: Module Generate
[hide private]
[frames] | no frames]

Source Code for Module Chem.Pharm2D.Generate

  1  # $Id: Generate.py 2 2006-05-06 22:54:39Z glandrum $ 
  2  # 
  3  # Copyright (C) 2002-2006 greg Landrum and Rational Discovery LLC 
  4  # 
  5  #   @@ All Rights Reserved  @@ 
  6  # 
  7  """ generation of 2D pharmacophores 
  8   
  9  **Notes** 
 10   
 11    - The terminology for this gets a bit rocky, so here's a glossary of what 
 12      terms used here mean: 
 13   
 14        1) *N-point pharmacophore* a combination of N features along with 
 15           distances betwen them. 
 16   
 17        2) *N-point proto-pharmacophore*: a combination of N feature 
 18           definitions without distances.  Each N-point 
 19           proto-pharmacophore defines a manifold of potential N-point 
 20           pharmacophores. 
 21   
 22        3) *N-point scaffold*: a collection of the distances defining 
 23           an N-point pharmacophore without feature identities. 
 24   
 25   
 26    See Docs/Chem/Pharm2D.triangles.jpg for an illustration of the way 
 27    pharmacophores are broken into triangles and labelled. 
 28   
 29    See Docs/Chem/Pharm2D.signatures.jpg for an illustration of bit 
 30    numbering 
 31   
 32  """ 
 33  from Chem.Pharm2D import Utils,Signature,SigFactory 
 34   
 35  _verbose = 0 
 36   
37 -def _ShortestPathsMatch(match,featureSet,sig,dMat):
38 """ Internal use only 39 40 """ 41 if _verbose: 42 print 'match:',match 43 nPts = len(match) 44 distsToCheck = Utils.nPointDistDict[nPts] 45 nDists = len(distsToCheck) 46 dist = [0]*nDists 47 #minD,maxD = sig.GetMinDist(),sig.GetMaxDist() 48 minD,maxD = sig.bins[0][0],sig.bins[-1][1] 49 50 for i in range(nDists): 51 pt0,pt1 = distsToCheck[i] 52 idx1,idx2 = match[pt0][0],match[pt1][0] 53 # FIX: treats all matches as single-atom 54 # FIX: is it ok that this is an int? 55 d = int(dMat[idx1,idx2]) 56 # do a quick distance filter 57 if d == 0 or d <= minD or d > maxD: 58 return 59 dist[i] = d 60 if _verbose: 61 print '\t',dist,sig.GetMinDist(),sig.GetMaxDist() 62 sig.SetBit(featureSet,dist,checkPatts=0)
63 64 65
66 -def Gen2DFingerprint(mol,sig,perms=None,dMat=None):
67 """ generates a 2D fingerprint for a molecule using the 68 parameters in _sig_ 69 70 **Arguments** 71 72 - mol: the molecule for which the signature should be generated 73 74 - sig: the signature object which will be filled. 75 76 - perms: (optional) a sequence of permutation indices limiting which 77 pharmacophore combinations are allowed 78 79 - dMat: (optional) the distance matrix to be used 80 81 **Notes** 82 83 - no preprocessing is carried out for _sig_. It *must* be pre-initialized. 84 Any bits which are already set will not be changed by this operation. 85 86 87 """ 88 if isinstance(sig,SigFactory.SigFactory): 89 sig = sig.GetSignature() 90 nPatts = sig.GetNumPatterns() 91 minCount = sig.GetMinCount() 92 maxCount = sig.GetMaxCount() 93 94 # generate the molecule's distance matrix, if required 95 if dMat is None: 96 import Chem 97 useBO = sig.GetIncludeBondOrder() 98 dMat = Chem.GetDistanceMatrix(mol,useBO) 99 100 # generate the permutations, if required 101 if perms is None: 102 perms = [] 103 for count in range(minCount,maxCount+1): 104 perms += Utils.GetIndexCombinations(nPatts,count) 105 106 # generate the matches: 107 pattMatches = [None]*nPatts 108 for i in range(nPatts): 109 patt = sig.GetPattern(i) 110 pattMatches[i] = mol.GetSubstructMatches(patt) 111 112 for perm in perms: 113 # the permutation is a combination of feature indices 114 # defining the feature set for a proto-pharmacophore 115 116 # Get a set of matches at each index of 117 # the proto-pharmacophore. 118 matchPerms = [pattMatches[x] for x in perm] 119 if _verbose: 120 print '\n->Perm: %s'%(str(perm)) 121 print ' matchPerms: %s'%(str(matchPerms)) 122 123 # Get all unique combinations of those possible matches: 124 matchesToMap = Utils.UniquifyCombinations(Utils.GetAllCombinations(matchPerms)) 125 126 for match in matchesToMap: 127 if sig.GetShortestPathsOnly(): 128 _ShortestPathsMatch(match,perm,sig,dMat) 129 130 return sig
131 if __name__ == '__main__': 132 import Chem
133 - def test1():
134 sig = Signature.Pharm2DSig() 135 sig.SetPatternsFromSmarts(['O','N']) 136 sig.SetBins([(1,2),(2,4),(4,6)]) 137 sig.SetMinCount(2) 138 sig.SetMaxCount(3) 139 sig.Init() 140 141 mol = Chem.MolFromSmiles('C1OCOCC1O') 142 Gen2DFingerprint(mol,sig) 143 144 print list(sig.GetOnBits()) 145 print sig._size
146
147 - def test2():
148 sig = Signature.Pharm2DSig() 149 sig.SetPatternsFromSmarts(['[OD1]','[OD2]','[CD3]',]) 150 sig.SetBins([(1,3),(3,8)]) 151 sig.SetMinCount(3) 152 sig.SetMaxCount(3) 153 sig.Init() 154 mol = Chem.MolFromSmiles('OCCC1COCCO1') 155 dMat= Chem.GetDistanceMatrix(mol) 156 157 #Signature._verbose = 1 158 Gen2DFingerprint(mol,sig) 159 160 #print sig._binCombos 161 print list(sig.GetOnBits()) 162 print sig._size
163 Signature._verbose=1 164 _verbose = 1 165 test1() 166