Bjoern Olausson

anaout.py
Friday, 10 April 2009 00:10

  1. # -*- coding: utf-8 -*-
  2. #
  3. #--------------------------------------------------------------------------------
  4. #anaout.py v1.2, Copyright Bjoern Olausson
  5. #--------------------------------------------------------------------------------
  6. #This program is free software; you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation; either version 2 of the License, or
  9. #(at your option) any later version.
  10. #
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. #GNU General Public License for more details.
  15. #
  16. #To view the license visit
  17. #http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  18. #or write to
  19. #Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. #--------------------------------------------------------------------------------
  21. #--------------------------------------------------------------------------------
  22. #
  23. #This script is intended to pars CHARMM output files and plot energy, temperature, and
  24. #whatever information CHARMM writes down for DYNA.
  25. #
  26. #For example:
  27. #
  28. #DYNA DYN: Step Time TOTEner TOTKe ENERgy TEMPerature
  29. #DYNA PROP: GRMS HFCTote HFCKe EHFCor VIRKe
  30. #DYNA INTERN: BONDs ANGLes UREY-b DIHEdrals IMPRopers
  31. #DYNA CROSS: CMAPs
  32. #DYNA EXTERN: VDWaals ELEC HBONds ASP USER
  33. #DYNA IMAGES: IMNBvdw IMELec IMHBnd RXNField EXTElec
  34. #DYNA EWALD: EWKSum EWSElf EWEXcl EWQCor EWUTil
  35. #DYNA CONSTR: HARMonic CDIHedral CIC RESDistance NOE
  36. #DYNA MMFP: GEO MDIP SSBP SHEL DROFfa
  37. #DYNA PRESS: VIRE VIRI PRESSE PRESSI VOLUme
  38. #DYNA XTLE: XTLTe SURFtension XTLPe XTLtemp
  39. #---------- --------- --------- --------- --------- ---------
  40.  
  41. #DYNA> 0 50.00000-154327.02601 76739.59712-231066.62313 303.04814
  42. #DYNA PROP> 16.53147-154187.74874 77157.31193 139.27726 35759.35840
  43. #DYNA INTERN> 6875.17059 26031.47702 8099.17560 20014.17660 468.25788
  44. #DYNA CROSS> -671.51578
  45. #DYNA EXTERN> 5323.04913-211972.77063 0.00000 0.00000 0.00000
  46. #DYNA IMAGES> -1480.14932 -13098.37023 0.00000 0.00000 0.00000
  47. #DYNA EWALD> 4283.1528-1565911.3520 1490022.1635 0.0000 0.0000
  48. #DYNA CONSTR> 410.87665 0.00000 0.00000 0.00000 0.00000
  49. #DYNA MMFP> 540.03511 0.00000 0.00000 0.00000 0.00000
  50. #DYNA PRESS> -5704.1194 -18135.4529 364.4002 2127.5031 1073329.5749
  51. #DYNA XTLE> -14733.71807 -52.29616 -2039.36602 128.28182
  52. #---------- --------- --------- --------- --------- ---------
  53. import sys, os, shutil, string, glob, subprocess, itertools, pylab, scipy
  54.  
  55. from optparse import OptionParser, OptionGroup
  56. opa = OptionParser()
  57.  
  58. opa.add_option("-f", action="append", dest="chmout", metavar="FILE",
  59. help="CHARMM out file")
  60. opa.add_option("-o", action="store", dest="saveplot", metavar="FILE",
  61. help="Filename to which we save the plot (.png) and RAW data (.dat)")
  62.  
  63. opa.add_option("-s", action="store_true", dest="singleplot",
  64. help="Plot to single image")
  65.  
  66. group = OptionGroup(opa, "You can choose freely from the following Values which will occure on either X or Y Axis",
  67. " Step Time TOTEner TOTKe ENERgy TEMPerature GRMS HFCTote HFCKe EHFCor VIRKe BONDs ANGLes UREYb DIHEdrals IMPRopers CMAPs VDWaals ELEC HBONds ASP USER IMNBvdw IMELec IMHBnd RXNField EXTElec EWKSum EWSElf EWEXcl EWQCor EWUTil HARMonic CDIHedral CIC RESDistance NOE GEO MDIP SSBP SHEL DROFfa VIRE VIRI PRESSE PRESSI VOLUme XTLTe SURFtension XTLPe XTLtemp")
  68.  
  69. group.add_option("-x", action="append", dest="xax",
  70. help="Choose Value from above you want to appear on the X-axis.")
  71.  
  72. group.add_option("-y", action="append", dest="yax",
  73. help="Choose Value from above you want to appear on the Y-axis. If you want to plot multible Y values, you have to asign every Y value a X value and vice versa. For example: anaout.py -x Time -x Time -y PRESSE -y TEMPerature")
  74. opa.add_option_group(group)
  75.  
  76. # instruct optparse to parse the program's command line
  77. (options, args) = opa.parse_args()
  78.  
  79. # Checking for required otions
  80. if not options.chmout:
  81. parser.error("-f must be set")
  82.  
  83. #chmout = options.chmout.split(" ")
  84. chmout = options.chmout
  85. xax = options.xax
  86. yax = options.yax
  87. saveplot = options.saveplot
  88. singleplot = options.singleplot
  89.  
  90. #If "*" is found in a parameter, glob it.
  91. for element in chmout :
  92. if '*' in element :
  93. chmout.extend(glob.glob(element))
  94. chmout.remove(element)
  95. chmout.sort()
  96.  
  97. #Defining the lists
  98. Step = []; Time = []; TOTEner = []; TOTKe = []; ENERgy = []; TEMPerature = []
  99. GRMS = []; HFCTote = []; HFCKe = []; EHFCor = []; VIRKe = []
  100. BONDs = []; ANGLes = []; UREYb = []; DIHEdrals = []; IMPRopers = []
  101. CMAPs = []
  102. VDWaals = []; ELEC = []; HBONds = []; ASP = []; USER = []
  103. IMNBvdw = []; IMELec = []; IMHBnd = []; RXNField = []; EXTElec = []
  104. EWKSum = []; EWSElf = []; EWEXcl = []; EWQCor = []; EWUTil = []
  105. HARMonic = []; CDIHedral = []; CIC = []; RESDistance = []; NOE = []
  106. GEO = []; MDIP = []; SSBP = []; SHEL = []; DROFfa = []
  107. VIRE = []; VIRI = []; PRESSE = []; PRESSI = []; VOLUme = []
  108. XTLTe = []; SURFtension = []; XTLPe = []; XTLtemp = []
  109.  
  110. #DYNA DYN: Step Time TOTEner TOTKe ENERgy TEMPerature
  111. #DYNA> 0 50.00000-154327.02601 76739.59712-231066.62313 303.04814
  112. def Dyna(line) :
  113. if fnum > 0 :
  114. CurStep = int(line[5:14].strip())
  115. NewStep = CurStep + LastStep
  116. Step.append(str(NewStep))
  117. else :
  118. Step.append(line[5:14].strip())
  119.  
  120. Time.append(line[14:27].strip())
  121. TOTEner.append(line[27:40].strip())
  122. TOTKe.append(line[40:53].strip())
  123. ENERgy.append(line[53:66].strip())
  124. TEMPerature.append(line[66:79].strip())
  125.  
  126. #DYNA PROP: GRMS HFCTote HFCKe EHFCor VIRKe
  127. #DYNA PROP> 16.53147-154187.74874 77157.31193 139.27726 35759.35840
  128. def DynaProp(line) :
  129. GRMS.append(line[10:27].strip())
  130. HFCTote.append(line[27:40].strip())
  131. HFCKe.append(line[40:53].strip())
  132. EHFCor.append(line[53:66].strip())
  133. VIRKe.append(line[66:79].strip())
  134.  
  135. #DYNA INTERN: BONDs ANGLes UREY-b DIHEdrals IMPRopers
  136. #DYNA INTERN> 6875.17059 26031.47702 8099.17560 20014.17660 468.25788
  137. def DynaIntern(line) :
  138. BONDs.append(line[12:27].strip())
  139. ANGLes.append(line[27:40].strip())
  140. UREYb.append(line[40:53].strip())
  141. DIHEdrals.append(line[53:66].strip())
  142. IMPRopers.append(line[66:79].strip())
  143.  
  144. #DYNA CROSS: CMAPs
  145. #DYNA CROSS> -671.51578
  146. def DynaCross(line) :
  147. CMAPs.append(line[11:27].strip())
  148.  
  149. #DYNA EXTERN: VDWaals ELEC HBONds ASP USER
  150. #DYNA EXTERN> 5323.04913-211972.77063 0.00000 0.00000 0.00000
  151. def DynaExtern(line) :
  152. VDWaals.append(line[12:27].strip())
  153. ELEC.append(line[27:40].strip())
  154. HBONds.append(line[40:53].strip())
  155. ASP.append(line[53:66].strip())
  156. USER.append(line[66:79].strip())
  157.  
  158. #DYNA IMAGES: IMNBvdw IMELec IMHBnd RXNField EXTElec
  159. #DYNA IMAGES> -1480.14932 -13098.37023 0.00000 0.00000 0.00000
  160. def DynaImages(line) :
  161. IMNBvdw.append(line[12:27].strip())
  162. IMELec.append(line[27:40].strip())
  163. IMHBnd.append(line[40:53].strip())
  164. RXNField.append(line[53:66].strip())
  165. EXTElec.append(line[66:79].strip())
  166.  
  167. #DYNA EWALD: EWKSum EWSElf EWEXcl EWQCor EWUTil
  168. #DYNA EWALD> 4283.1528-1565911.3520 1490022.1635 0.0000 0.0000
  169. def DynaEwald(line) :
  170. EWKSum.append(line[11:27].strip())
  171. EWSElf.append(line[27:40].strip())
  172. EWEXcl.append(line[40:53].strip())
  173. EWQCor.append(line[53:66].strip())
  174. EWUTil.append(line[66:79].strip())
  175.  
  176. #DYNA CONSTR: HARMonic CDIHedral CIC RESDistance NOE
  177. #DYNA CONSTR> 410.87665 0.00000 0.00000 0.00000 0.00000
  178. def DynaConstr(line) :
  179. HARMonic.append(line[12:27].strip())
  180. CDIHedral.append(line[27:40].strip())
  181. CIC.append(line[40:53].strip())
  182. RESDistance.append(line[53:66].strip())
  183. NOE.append(line[66:79].strip())
  184.  
  185. #DYNA MMFP: GEO MDIP SSBP SHEL DROFfa
  186. #DYNA MMFP> 540.03511 0.00000 0.00000 0.00000 0.00000
  187. def DynaMmfp(line) :
  188. GEO.append(line[10:27].strip())
  189. MDIP.append(line[22:40].strip())
  190. SSBP.append(line[40:53].strip())
  191. SHEL.append(line[53:66].strip())
  192. DROFfa.append(line[66:79].strip())
  193.  
  194. #DYNA PRESS: VIRE VIRI PRESSE PRESSI VOLUme
  195. #DYNA PRESS> -5704.1194 -18135.4529 364.4002 2127.5031 1073329.5749
  196. def DynaPress(line) :
  197. VIRE.append(line[11:27].strip())
  198. VIRI.append(line[22:40].strip())
  199. PRESSE.append(line[40:53].strip())
  200. PRESSI.append(line[53:66].strip())
  201. VOLUme.append(line[66:79].strip())
  202.  
  203. #DYNA XTLE: XTLTe SURFtension XTLPe XTLtemp
  204. #DYNA XTLE> -14733.71807 -52.29616 -2039.36602 128.28182
  205. def DynaXtle(line) :
  206. XTLTe.append(line[22:40].strip())
  207. SURFtension.append(line[40:53].strip())
  208. XTLPe.append(line[53:66].strip())
  209. XTLtemp.append(line[66:79].strip())
  210.  
  211. LineFunc = {
  212. 'DYNA': Dyna,
  213. 'DYNA PROP': DynaProp,
  214. 'DYNA INTERN': DynaIntern,
  215. 'DYNA CROSS': DynaCross,
  216. 'DYNA EXTERN': DynaExtern,
  217. 'DYNA IMAGES': DynaImages,
  218. 'DYNA EWALD': DynaEwald,
  219. 'DYNA CONSTR': DynaConstr,
  220. 'DYNA MMFP': DynaMmfp,
  221. 'DYNA PRESS': DynaPress,
  222. 'DYNA XTLE': DynaXtle
  223. }
  224.  
  225. fnum = 0
  226. for outfile in chmout :
  227. for lines in open(outfile, "r") :
  228. LineStart = lines.split(">")
  229. if LineStart[0] in LineFunc :
  230. LineFunc[LineStart[0]](lines)
  231. # print "Step: ", Step
  232. LastStep = int(Step[-1])
  233. # print "LastStep: ", LastStep
  234. fnum = fnum + 1
  235.  
  236. #Convert Lists to scipy arrays
  237. Step = scipy.array(Step)
  238. Time = scipy.array(Time)
  239. TOTEner = scipy.array(TOTEner)
  240. TOTKe = scipy.array(TOTKe)
  241. ENERgy = scipy.array(ENERgy)
  242. TEMPerature = scipy.array(TEMPerature)
  243.  
  244. GRMS = scipy.array(GRMS)
  245. HFCTote = scipy.array(HFCTote)
  246. HFCKe = scipy.array(HFCKe)
  247. EHFCor = scipy.array(EHFCor)
  248. VIRKe = scipy.array(VIRKe)
  249.  
  250. BONDs = scipy.array(BONDs)
  251. ANGLes = scipy.array(ANGLes)
  252. UREYb = scipy.array(UREYb)
  253. DIHEdrals = scipy.array(DIHEdrals)
  254. IMPRopers = scipy.array(IMPRopers)
  255.  
  256. CMAPs = scipy.array(CMAPs)
  257.  
  258. VDWaals = scipy.array(VDWaals)
  259. ELEC = scipy.array(ELEC)
  260. HBONds = scipy.array(HBONds)
  261. ASP = scipy.array(ASP)
  262. USER = scipy.array(USER)
  263.  
  264. IMNBvdw = scipy.array(IMNBvdw)
  265. IMELec = scipy.array(IMELec)
  266. IMHBnd = scipy.array(IMHBnd)
  267. RXNField = scipy.array(RXNField)
  268. EXTElec = scipy.array(EXTElec)
  269.  
  270. EWKSum = scipy.array(EWKSum)
  271. EWSElf = scipy.array(EWSElf)
  272. EWEXcl = scipy.array(EWEXcl)
  273. EWQCor = scipy.array(EWQCor)
  274. EWUTil = scipy.array(EWUTil)
  275.  
  276. HARMonic = scipy.array(HARMonic)
  277. CDIHedral = scipy.array(CDIHedral)
  278. CIC = scipy.array(CIC)
  279. RESDistance = scipy.array(RESDistance)
  280. NOE = scipy.array(NOE)
  281.  
  282. GEO = scipy.array(GEO)
  283. MDIP = scipy.array(MDIP)
  284. SSBP = scipy.array(SSBP)
  285. SHEL = scipy.array(SHEL)
  286. DROFfa = scipy.array(DROFfa)
  287.  
  288. VIRE = scipy.array(VIRE)
  289. VIRI = scipy.array(VIRI)
  290. PRESSE = scipy.array(PRESSE)
  291. PRESSI = scipy.array(PRESSI)
  292. VOLUme = scipy.array(VOLUme)
  293.  
  294. XTLTe = scipy.array(XTLTe)
  295. SURFtension = scipy.array(SURFtension)
  296. XTLPe = scipy.array(XTLPe)
  297. XTLtemp = scipy.array(XTLtemp)
  298.  
  299. #COMBINED = scipy.array([[Step], [Time], [TOTEner], [TOTKe], [ENERgy], [TEMPerature], [GRMS], [HFCTote], [HFCKe], [EHFCor], [VIRKe], [BONDs], [ANGLes], [UREYb], [DIHEdrals], [IMPRopers], [CMAPs], [VDWaals], [ELEC], [HBONds], [ASP], [USER], [IMNBvdw], [IMELec], [IMHBnd], [RXNField], [EXTElec], [EWKSum], [EWSElf], [EWEXcl], [EWQCor], [EWUTil], [HARMonic], [CDIHedral], [CIC], [RESDistance], [NOE], [GEO], [MDIP], [SSBP], [SHEL], [DROFfa], [VIRE], [VIRI], [PRESSE], [PRESSI], [VOLUme]])
  300. PlotDict = {
  301. 'Step': Step,
  302. 'Time': Time,
  303. 'TOTEner': TOTEner,
  304. 'TOTKe': TOTKe,
  305. 'ENERgy': ENERgy,
  306. 'TEMPerature': TEMPerature,
  307. 'GRMS': GRMS,
  308. 'HFCTote': HFCTote,
  309. 'HFCKe': HFCKe,
  310. 'EHFCor': EHFCor,
  311. 'VIRKe': VIRKe,
  312. 'BONDs': BONDs,
  313. 'ANGLes': ANGLes,
  314. 'UREYb': UREYb,
  315. 'DIHEdrals': DIHEdrals ,
  316. 'CMAPs': CMAPs,
  317. 'IMPRopers': IMPRopers,
  318. 'ASP': ASP,
  319. 'USER': USER,
  320. 'IMNBvdw': IMNBvdw,
  321. 'IMELec': IMELec,
  322. 'IMHBnd': IMHBnd,
  323. 'RXNField': RXNField,
  324. 'EXTElec': EXTElec,
  325. 'EWKSum': EWKSum,
  326. 'EWSElf': EWSElf,
  327. 'EWEXcl': EWEXcl,
  328. 'EWQCor': EWQCor,
  329. 'EWUTil': EWUTil,
  330. 'HARMonic': HARMonic,
  331. 'CDIHedral': CDIHedral,
  332. 'CIC': CIC,
  333. 'RESDistance': RESDistance,
  334. 'NOE': NOE,
  335. 'GEO': GEO,
  336. 'MDIP': MDIP,
  337. 'SSBP': SSBP,
  338. 'SHEL': SHEL,
  339. 'DROFfa': DROFfa,
  340. 'VIRE': VIRE,
  341. 'VIRI': VIRI,
  342. 'PRESSE': PRESSE,
  343. 'PRESSI': PRESSI,
  344. 'VOLUme': VOLUme,
  345. 'XTLTe' : XTLTe,
  346. 'SURFtension' : SURFtension,
  347. 'XTLPe' : XTLPe,
  348. 'XTLtemp' : XTLtemp
  349. }
  350.  
  351. def SaveData(Xvalues,Yvalues, Xname, Yname, saveplot) :
  352. if saveplot :
  353. savedata = Xname+"-"+Yname+"_"+saveplot+".dat"
  354. fout = open(savedata, "w")
  355. for i,j in itertools.izip(Xvalues,Yvalues) :
  356. fout.writelines("%s %s
    "
    % (i,j))
  357. fout.close()
  358.  
  359. def SaveImage(Xname, Yname, saveplot) :
  360. if saveplot :
  361. saveimg = Xname+"-"+Yname+"_"+saveplot+".png"
  362. pylab.savefig(saveimg)
  363.  
  364. def DynaPltSingle(Xvalues,Yvalues,Xname,Yname) :
  365. #Do some nice plots later
  366. SaveData(Xvalues, Yvalues, Xname, Yname, saveplot)
  367. pylab.plot(Xvalues, Yvalues)
  368. Xlegend.append(Xname)
  369. Ylegend.append(Yname)
  370.  
  371. def DynaPltMulti(Xvalues,Yvalues,Xname,Yname, figure) :
  372. pylab.figure(figure)
  373. pylab.plot(Xvalues, Yvalues)
  374. pylab.xlabel(Xname)
  375. pylab.ylabel(Yname)
  376. SaveImage(Xname, Yname, saveplot)
  377. SaveData(Xvalues,Yvalues, Xname, Yname, saveplot)
  378.  
  379. fign = 0
  380. Xlegend = []
  381. Xlabel = []
  382. Ylegend = []
  383. Ylabel = []
  384. if singleplot :
  385. for xAxis,yAxis in itertools.izip(xax,yax) :
  386. DynaPltSingle(PlotDict[xAxis], PlotDict[yAxis], xAxis, yAxis)
  387. pylab.legend((Ylegend), shadow = True)
  388. pylab.ylabel(Ylegend)
  389. pylab.xlabel(Xlegend)
  390. SaveImage(xAxis, 'MULTI', saveplot)
  391. else :
  392. figure = 0
  393. for xAxis,yAxis in itertools.izip(xax,yax) :
  394. DynaPltMulti(PlotDict[xAxis], PlotDict[yAxis], xAxis, yAxis, figure)
  395. figure = figure + 1
  396.  
  397. pylab.show()

Attachments:
FileFile sizeLast Modified
Download this file (anaout.py)anaout.py13 Kb07/09/09 10:47
Last Updated ( Wednesday, 30 September 2009 09:56 )
 

Add comment


Security code
Refresh

Comments

Qt Ambassador

Qt Ambassador

www. is deprecated

Banner

Play OGG

Banner

Gixen

web2sms

Banner