1
2
3
4
5
6
7 import Geometry
8 import numpy
9 import Chem
10 from Chem import ChemicalFeatures
11
13 - def __init__(self, feats,initMats=True):
14 self._initializeFeats(feats)
15 nf = len(feats)
16 self._boundsMat = numpy.zeros((nf, nf), numpy.float)
17 self._boundsMat2D = numpy.zeros((nf, nf), numpy.int)
18 if initMats:
19 self._initializeMatrices()
20
31
33
34 nf = len(self._feats)
35 for i in range(1, nf):
36 loci = self._feats[i].GetPos()
37 for j in range(i):
38 locj = self._feats[j].GetPos()
39 dist = loci.Distance(locj)
40 self._boundsMat[i,j] = dist
41 self._boundsMat[j,i] = dist
42 for i in range(nf):
43 for j in range(i+1,nf):
44 self._boundsMat2D[i,j] = 1000
45
46
49
52
54 if (i > j):
55 j,i = i,j
56 return self._boundsMat[i, j]
57
59 if (j > i):
60 j,i = i,j
61 return self._boundsMat[i,j]
62
64 " raises ValueError on failure "
65 nf = len(self._feats)
66 if (i < 0) or (i >= nf):
67 raise ValueError, "Index out of bound"
68 if (j < 0) or (j >= nf):
69 raise ValueError, "Index out of bound"
70 return True
71
73 if (checkBounds): self._checkBounds(i,j)
74 if (i > j):
75 j,i = i,j
76 self._boundsMat[i,j] = val
77
79 if (checkBounds): self._checkBounds(i,j)
80 if (j > i):
81 j,i = i,j
82 self._boundsMat[i,j] = val
83
85 if (i > j):
86 j,i = i,j
87 return self._boundsMat2D[i, j]
88
90 if (j > i):
91 j,i = i,j
92 return self._boundsMat2D[i,j]
93
94
96 if (checkBounds): self._checkBounds(i,j)
97 if (i > j):
98 j,i = i,j
99 self._boundsMat2D[i,j] = val
100
102 if (checkBounds): self._checkBounds(i,j)
103 if (j > i):
104 j,i = i,j
105 self._boundsMat2D[i,j] = val
106
108 res = ' '*13
109 for i,iFeat in enumerate(self._feats):
110 res += '% 12s '%iFeat.GetFamily()
111 res += '\n'
112 for i,iFeat in enumerate(self._feats):
113 res += '% 12s '%iFeat.GetFamily()
114 for j,jFeat in enumerate(self._feats):
115 if j<i:
116 res += '% 12.3f '%self.getLowerBound(i,j)
117 elif j>i:
118 res += '% 12.3f '%self.getUpperBound(i,j)
119 else:
120 res += '% 12.3f '%0.0
121 res += '\n'
122 return res
123
125 """ this is a pharmacophore with explicit point locations and radii
126 """
127 - def __init__(self, feats=None,radii=None):
130
145
148
151
153 return self._feats[i]
154
156 return self._radii[i]
157
160
164
167
169 from Chem import ChemicalFeatures
170 logger = logging.logger()
171
172 import re
173 spaces = re.compile('[\ \t]+')
174
175 feats = []
176 rads = []
177 for lineNum,line in enumerate(lines):
178 txt = line.split('#')[0].strip()
179 if txt:
180 splitL = spaces.split(txt)
181 if len(splitL)<5:
182 logger.error('Input line %d only contains %d fields, 5 are required. Read failed.'%(lineNum,len(splitL)))
183 return
184 fName = splitL[0]
185 try:
186 xP = float(splitL[1])
187 yP = float(splitL[2])
188 zP = float(splitL[3])
189 rad = float(splitL[4])
190 except ValueError:
191 logger.error('Error parsing a number of line %d. Read failed.'%(lineNum))
192 return
193 feats.append(ChemicalFeatures.FreeChemicalFeature(fName,fName,Geometry.Point3D(xP,yP,zP)))
194 rads.append(rad)
195 self._initializeFeats(feats,rads)
196
198 res = ''
199 for feat,rad in zip(self._feats,self._radii):
200 res += '% 12s '%feat.GetFamily()
201 p = feat.GetPos()
202 res += ' % 8.4f % 8.4f % 8.4f '%(p.x,p.y,p.z)
203 res += '% 5.2f'%rad
204 res += '\n'
205 return res
206