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 Run ptraj entropy analysis on existing amber trajectory (.crd) and
26 topology (.parm7) file.
27 """
28
29 import os.path as osp
30 import re
31 import tempfile
32
33 import Biskit.tools as T
34
35 from Biskit.Errors import BiskitError
36 from Biskit.Executor import Executor
37
39 pass
40
42 """
43 Run ptraj entropy analysis on existing amber trajectory (.crd) and
44 topology (.parm7) file.
45 """
46
47
48 ptraj_script = """
49 trajin %(f_crd)s %(start)i %(stop)i %(step)i
50 matrix mwcovar name mwc
51 analyze matrix mwc vecs 0 thermo
52 """
53
54 - def __init__( self, f_parm, f_crd, f_template=None,
55 s=0, e=None, step=1, **kw ):
56 """
57 @param f_parm: path to amber topology file
58 @type f_parm: str
59 @param f_crd: path to amber trajectory file
60 @type f_crd: str
61 @param f_template: alternative ptraj input template (default: None)
62 @type f_template: str
63 @param s: start frame (default: 0, first)
64 @type s: int
65 @param e: end frame (default: None, last)
66 @type e: int
67 @param step: frame offset (default: 1, no offset )
68 @type step: int
69
70 @param kw: additional key=value parameters for Executor:
71 @type kw: key=value pairs
72 ::
73 debug - 0|1, keep all temporary files (default: 0)
74 verbose - 0|1, print progress messages to log (log != STDOUT)
75 node - str, host for calculation (None->local) NOT TESTED
76 (default: None)
77 nice - int, nice level (default: 0)
78 log - Biskit.LogFile, program log (None->STOUT) (default: None)
79 """
80 template = f_template or self.ptraj_script
81
82 Executor.__init__( self, 'ptraj', template=template, push_inp=0, **kw )
83
84 self.f_parm = T.absfile( f_parm )
85 self.f_crd = T.absfile( f_crd )
86
87 self.start = s
88 self.stop = e or 10000000
89 self.step = step
90
91
92 self.result = { 'T':None, 'mass':None, 'vibes':None,
93 'S_total':None, 'S_trans':None, 'S_rot':None,
94 'S_vibes':None,
95 'contributions':None, 'nframes':None,
96 'version':self.version(), 'node':self.node }
97
98
100 """
101 Version of class.
102
103 @return: version
104 @rtype: str
105 """
106 return 'AmberCrdEntropist $Revision: 2.5 $'
107
108
110 """
111 Build the command string.
112
113 @return: command
114 @rtype: str
115 """
116 return "%s %s %s" % (self.exe.bin, self.f_parm, self.f_in)
117
118
119
121 m = regex.search( str )
122 if m:
123 return round( float( m.groups()[0] ), 3 )
124 return None
125
126
128 """
129 Overrides Executor method
130 """
131 self.result = self.parsePtrajResult( self.f_out )
132
133
135 """
136 Detect whether external program failed, override!
137 """
138 if not osp.exists( self.f_out ):
139 return 1
140
141 return 0
142
143
145 """
146 Extract results from ptraj.
147
148 @param f_out: result of ptraj run
149 @type f_out: str
150
151 @return: extracted prtaj result
152 @rtype: dict
153
154 @raise EntropistError: if unexpected end of ptraj output file
155 """
156
157 re_thermo= re.compile('- Thermochemistry -')
158 re_T = re.compile('^\s*temperature\s*(\d+\.\d+)\s*kelvin')
159 re_mass = re.compile('^\s*molecular mass\D*(\d+\.\d+)\s*amu')
160 re_vibes = re.compile('^\s*Warning--\s*(\d+)\s*vibrations have low')
161 re_table = re.compile('^-{80}$')
162 re_value = re.compile('(-*\d+\.\d+)$')
163 re_nsets = re.compile('Successfully read in (\d+) sets')
164
165 r = self.result
166
167 try:
168 lines = open( f_out, 'r' ).readlines()
169 lines.reverse()
170 l = lines.pop()
171
172 while not re_thermo.search(l):
173 l = lines.pop()
174
175 while not re_table.search(l):
176 r['T'] = r['T'] or self.__tryMatch( re_T, l )
177 r['mass'] = r['mass'] or self.__tryMatch( re_mass, l )
178 r['vibes']= r['vibes'] or self.__tryMatch( re_vibes,l )
179 l = lines.pop()
180
181 l = lines.pop()
182 v = []
183 while l != '\n':
184 v += [ self.__tryMatch( re_value, l ) ]
185 l = lines.pop()
186
187 r['S_total'], r['S_trans'], r['S_rot'], r['S_vibes'] = tuple(v[:4])
188 r['contributions'] = v[4:]
189
190 while len( lines ) > 0:
191 r['nframes'] = r['nframes'] or self.__tryMatch( re_nsets, l )
192 l = lines.pop()
193
194 except IndexError:
195 raise EntropistError, 'unexpected end of ptraj output file.'
196
197 return r
198
199 if __name__ == '__main__':
200
201 print "Setting up"
202
203 f = T.testRoot() + '/Amber/AmberCrdEntropist/'
204
205 e = AmberCrdEntropist( f + 'lig_traj.parm',
206 f + 'lig_traj.crd', debug=0, verbose=1)
207
208 print "Running"
209
210 e.run()
211