1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 """
27 Parse output file from hex docking run.
28 """
29
30 import re
31 import numpy.oldnumeric as Numeric
32 from Biskit.Dock import Complex, ComplexList
33
34 from Biskit import PCRModel
35 import Biskit.tools as t
36
38 """
39 Parse hex result file and extract Complex objects into a dictionary
40 indexed by the hex solution number.
41 The hex file is only closed when this object is discarded.
42 The HexParser is created with a dictionary containing PCRModel objects
43 for ligand and receptor indexed by hex model number.
44 """
45
46 - def __init__(self, hexFile, rec_dic, lig_dic, forceModel=None):
47 """
48 @param hexFile: name of hex output file
49 @type hexFile: string
50 @param rec_dic: map between model number and PCRModel
51 { 1 : model1, 2 : model2,..} types: { int : PCRModel}
52 @type rec_dic: {int:model}
53 @param lig_dic: same as rec_dic but for ligand PCRModels
54 @type lig_dic: {int:model}
55 @param forceModel: force parser to accept model numbers
56 @type forceModel: int, int
57 """
58 self.hex = open( hexFile )
59 self.rec_models = rec_dic
60 self.lig_models = lig_dic
61 self.forceModel = forceModel
62
63 self.ex_line = re.compile("^(\S+):\s*([-0-9\.\s]*)")
64
65 self.ex_matrix = re.compile("([-0-9]+\.[0-9]+e[-+0-9]+)")
66
67
69 self.hex.close()
70
71
73 """
74 Take list of lines, extract all Hex info about one complex
75 (Solution number, hex energy,..) also extract 16 numbers of
76 the transformation matrix and put them into 4 by 4 numeric
77 array.
78
79 @return: Complex created from the output from Hex
80 @rtype: Complex
81 """
82
83 lines = self._nextBlock()
84 if lines == None:
85
86 return None
87
88 if len(lines) < 13:
89 lines = self._nextBlock()
90
91
92 i = {}
93 matrix = None
94 for l in lines:
95 try:
96
97 m = self.ex_line.search( l )
98 if m != None:
99 m = m.groups()
100
101 if m[0] == 'Orientation':
102 i['hex_clst'] = int(m[1])
103 elif m[0] == 'Solution':
104 i['soln'] = int(m[1])
105 elif m[0] == 'ReceptorModel':
106 if self.forceModel:
107 i['model1'] = self.forceModel[0]
108 else:
109 i['model1'] = int(m[1])
110 elif m[0] == 'LigandModel':
111 if self.forceModel:
112 i['model2'] = self.forceModel[1]
113 else:
114 i['model2'] = int(m[1])
115 elif m[0] == 'Bumps':
116 if int(m[1]) != -1:
117 i['bumps'] = int(m[1])
118 elif m[0] == 'ReferenceRMS':
119 i['rms'] = float(m[1])
120 elif m[0] == 'Vshape':
121 if float(m[1]) != 0.0:
122 i['hex_Vshape'] = float(m[1])
123 elif m[0] == 'Vclash':
124 if float(m[1]) != 0.0:
125 i['hex_Vclash'] = float(m[1])
126 elif m[0] == 'Etotal':
127 i['hex_etotal'] = float(m[1])
128 elif m[0] == 'Eshape':
129 i['hex_eshape'] = float(m[1])
130 elif m[0] == 'LigandMatrix':
131
132 strings = self.ex_matrix.findall( l )
133
134 numbers = []
135 for each in strings:
136 numbers += [float(each)]
137
138 matrix = []
139 for j in range(0,4):
140 matrix.append( numbers[4*j:4*(j+1)] )
141
142 matrix = Numeric.array(matrix, Numeric.Float32)
143 except AttributeError:
144 print "HexParser.nextComplex(): ",t.lastError()
145
146
147 c = Complex( self.rec_models[ i['model1'] ],
148 self.lig_models[ i['model2'] ], matrix, i )
149 return c
150
151
153 """
154 return all lines describing next complex in the Hex output file.
155
156 @return: list of information strings
157 @rtype: [str]
158 """
159 line = self.hex.readline()
160 result = []
161 while line:
162 if line[:4] != "# --":
163
164 if self.ex_matrix.search(line) != None:
165 result[-1] = result[-1] + line
166 else:
167 result += [line]
168 else:
169 return result
170 line = self.hex.readline()
171
172
173 return None
174
175
177 """
178 Create one Complex Object for each paragraph in hex output file.
179
180 @return: ComplexList with all complexes from the Hex output
181 @rtype: ComplexList
182 """
183 complexes = ComplexList()
184 c = self.nextComplex()
185
186 while (c <> None):
187 complexes.append(c)
188 c = self.nextComplex( )
189
190 return complexes
191
192
193
194
195
196 import Biskit.test as BT
197
198 -class Test(BT.BiskitTest):
199 """Test case"""
200
202 """Dock.hexParser test"""
203
204 rec_dic = t.Load( t.testRoot() + "/dock/rec/1A2P_model.dic" )
205 lig_dic = t.Load( t.testRoot() + "/dock/lig/1A19_model.dic" )
206
207 self.h = HexParser( t.testRoot() + "/dock/hex/1A2P-1A19_hex.out",
208 rec_dic, lig_dic)
209
210 c_lst = self.h.parseHex()
211
212 if self.local:
213 print c_lst[1].info
214
215 globals().update( locals() )
216
217
218 self.assertEqual( c_lst[1].info.keys(),
219 ['soln', 'rms', 'hex_clst', 'hex_eshape',
220 'model2', 'model1', 'hex_etotal', 'date'] )
221
222 if __name__ == '__main__':
223
224 BT.localTest()
225