1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 Get binding energy from fold_X
25 """
26
27 from Biskit import Executor, TemplateError
28 from Biskit import BiskitError
29
30 import Biskit.tools as T
31
32 import re, string, tempfile
33
34 import Biskit.molUtils as molUtils
35
36
38 pass
39
40
42 """
43 Run fold_X with given PDBModel
44 ==============================
45 Returns a dictionary with energy terms.
46
47 Example usage
48 -------------
49 >>> x = Fold_X( model, verbose=1 )
50 >>> result = x.run()
51
52 Energy terms (kcal/mol)
53 -----------------------
54 This is the order of the energy terms in the output file. There
55 are two additional values that are unlabeled in the output
56 (version 2.5.2). The first is the entropy cost of making a complex.
57 This is zero if not 'AnalyseComplex' is run. The final value are
58 the number of residues.
59
60 We'll try to keep the energy labels of Fold-X version 1 of possible.
61 ::
62 ene - total energy
63 bb_hb - Backbone Hbond
64 sc_hb - Sidechain Hbond
65 vw - Van der Waals
66 el - Electrostatics
67 sol_p - Solvation Polar
68 sol_h - Solvation Hydrophobic
69 vwcl - Van de Waals clashes
70 sc - entropy side chain
71 mc - entropy main chain
72 sloop - sloop_entropy
73 mloop - mloop_entropy
74 cis - cis_bond
75 tcl - torsional clash
76 bbcl - backbone clash
77 dip - helix dipole
78 wtbr - water bridge
79 disu - disulfide
80 el_kon - electrostatic kon
81 p_cov - partial covalent bonds
82 ( - complex entropy )
83 ( - number of residues )
84
85 Reference
86 ---------
87 U{http://foldx.embl.de} for more info
88
89 @note: September 11 - 2006:
90 Tested with Fold-X 2.5.2
91 """
92
94 """
95 @param model: reference PDBModel
96 @type model: PDBModel
97
98 @param kw: additional key=value parameters for Executor:
99 @type kw: key=value pairs
100 ::
101 debug - 0|1, keep all temporary files (default: 0)
102 verbose - 0|1, print progress messages to log (log != STDOUT)
103 node - str, host for calculation (None->local) NOT TESTED
104 (default: None)
105 nice - int, nice level (default: 0)
106 log - Biskit.LogFile, program log (None->STOUT) (default: None)
107 """
108 self.temp_pdb = tempfile.mktemp('_foldx_.pdb')
109 self.temp_command = tempfile.mktemp('_foldx_.command')
110 self.temp_option = tempfile.mktemp('_foldx_.option')
111 self.temp_result = tempfile.mktemp('_foldx_.result')
112 self.temp_runlog = tempfile.mktemp('_foldx_.log')
113 self.temp_errlog = tempfile.mktemp('_foldx_.err')
114
115 Executor.__init__( self, 'fold_X', args='-manual %s %s %s'\
116 %(self.temp_pdb, self.temp_option,
117 self.temp_command), **kw )
118
119 self.model = model.clone()
120
121
122 self.aminoAcidDict = molUtils.aaAtoms
123 for k in self.aminoAcidDict:
124 if 'HN' not in self.aminoAcidDict[ k ]:
125 self.aminoAcidDict[ k ] += ['HN']
126
127
129 """
130 Prepare model for fold_X and write to file::
131 - remove all hydrogens but H
132 - rename H to HN
133 - rename H1 to HN (remove H2 and H3)
134 - ( terminal oxygens should be OXT )
135 - sort atoms according to self.aminoAcidDict
136
137 @param model: reference PDBModel
138 @type model: PDBModel
139 @param f_pdb_out: remaned pdb file name
140 @type f_pdb_out: str
141
142 @raise Fold_XError: if preparation fail
143 """
144
145 def __cmpAtoms( a1, a2 ):
146 """
147 compare atoms.
148
149 @param a1: atom name
150 @type a1: str
151 @param a2: atom name
152 @type a2: str
153 """
154 res = a1['residue_name']
155 target = self.aminoAcidDict[ res ]
156 try:
157 return cmp(target.index( a1['name'] ),
158 target.index( a2['name'] ))
159 except ValueError, why:
160 s = "Unknown atom for %s %i: %s or %s" % \
161 (res, a1['residue_number'], a1['name'], a2['name'] )
162 raise Fold_XError( s )
163
164
165
166
167
168 heavy_mask = model.maskHeavy()
169
170
171
172
173
174
175
176
177
178 keep_mask = heavy_mask
179 model = model.compress( keep_mask )
180
181
182 model.renumberResidues()
183
184
185 model = model.sort( model.argsort( __cmpAtoms ) )
186
187 model.writePdb( f_pdb_out )
188
189
191 """
192 Write a Fold-X compatible pdb file to disc.
193
194 @note: Overrides Executor method.
195 """
196 self.__prepareModel( self.model, self.temp_pdb )
197
198 f_com = open( self.temp_command, 'w')
199 f_com.writelines(['<TITLE>FOLDX_commandfile;\n',
200 '<Stability>%s;\n'%self.temp_result])
201 f_com.close()
202
203 f_opt = open( self.temp_option, 'w')
204 f_opt.writelines(['<TITLE> FOLDX_optionfile;\n',
205 '<logfile_name> %s;'%self.temp_runlog,
206 '<errorfile_name> %s;'%self.temp_errlog])
207 f_opt.close()
208
209
230
231
233 """
234 Extract energies from output.
235
236 @return: dictionary with energy terms as keys
237 @rtype: dict
238 """
239 energy = {}
240
241
242 l= open(self.temp_result).readlines()
243
244 if len(l) == 0:
245 raise Fold_XError, 'ERROR: fold_X Segmentation fault'
246
247 if re.match('^%s'%self.temp_pdb, l[-1]):
248
249
250 E = string.split( l[-1])[1:]
251
252
253
254
255 keys = [ 'ene', 'bb_hb', 'sc_hb', 'vw',
256 'el', 'sol_p', 'sol_h', 'vwcl',
257 'sc', 'mc', 'sloop', 'mloop',
258 'cis', 'tcl', 'bbcl', 'dip',
259 'wtbr', 'disu', 'el_kon', 'p_cov' ]
260
261
262 for i in range( len( keys ) ):
263 energy[ keys[i] ] = float( E[i] )
264 else:
265 print 'No fold_X energy to extract'
266 energy = 0
267
268 return energy
269
270
272 """
273 @note: Overrides Executor method
274 """
275 return not self.error is None
276
277
284
285
286
287
288 import Biskit.test as BT
289
290 -class Test(BT.BiskitTest):
291 """Fold_X test"""
292
293 TAGS = [ BT.EXE ]
294
315
316
317 EXPECTED = {'el': -13.766400000000001, 'wtbr': -4.8059700000000003, 'ene': -18.475000000000001, 'mc': 160.28800000000001, 'sloop': 0.0, 'dip': 0.00177626, 'sol_p': 167.71100000000001, 'disu': 0.0, 'tcl': 0.72696700000000003, 'cis': 0.0, 'p_cov': 0.0, 'sol_h': -134.613, 'bb_hb': -87.362499999999997, 'sc_hb': -48.350000000000001, 'vw': -116.67100000000001, 'sc': 58.089300000000001, 'el_kon': 0.0, 'mloop': 0.0, 'vwcl': 0.27728599999999998, 'bbcl': 0.37019200000000002}
318
319
320
321 if __name__ == '__main__':
322
323 BT.localTest()
324