1
2
3
4
5
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
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
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
54
55 d = int(dMat[idx1,idx2])
56
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
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
95 if dMat is None:
96 import Chem
97 useBO = sig.GetIncludeBondOrder()
98 dMat = Chem.GetDistanceMatrix(mol,useBO)
99
100
101 if perms is None:
102 perms = []
103 for count in range(minCount,maxCount+1):
104 perms += Utils.GetIndexCombinations(nPatts,count)
105
106
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
114
115
116
117
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
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
146
163 Signature._verbose=1
164 _verbose = 1
165 test1()
166