PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/utils/mktraj.py

https://gitlab.com/exaalt/parsplice
Python | 106 lines | 78 code | 13 blank | 15 comment | 17 complexity | cf7445ce487ea375905f5df479f8fbc2 MD5 | raw file
  1. import sys
  2. from math import *
  3. import string
  4. import glob
  5. import shutil
  6. import itertools as it
  7. import copy
  8. run=sys.argv[1]
  9. skipLoops=True
  10. if len(sys.argv)>2:
  11. skipLoops=bool(int(sys.argv[2]))
  12. else:
  13. skipLoops=False
  14. #print skipLoops, len(sys.argv), sys.argv[2], bool(sys.argv[2])
  15. inc=open('traj.out','r')
  16. i={}
  17. cl={}
  18. tl={}
  19. ntraj=1
  20. for l in inc.readlines():
  21. try:
  22. sl=string.split(l)
  23. c=int(sl[0])
  24. t=int(sl[1])
  25. itraj=int(sl[2])
  26. if itraj in cl:
  27. cl[itraj].append(c)
  28. tl[itraj].append(t)
  29. ntraj = max(ntraj,itraj+1)
  30. else:
  31. i[itraj] = 0
  32. cl[itraj] = [c]
  33. tl[itraj] = [t]
  34. except:
  35. pass
  36. #i=0
  37. # Loop through all trajectories:
  38. for itraj in range(ntraj):
  39. if not itraj in cl: continue
  40. if skipLoops:
  41. last={}
  42. for j in range(len(cl[itraj])):
  43. last[cl[itraj][j]]=j
  44. #indices = xrange(len(cl[itraj]) - 1, 0, -1)
  45. #gen = it.izip(indices, reversed(cl[itraj]))
  46. #cr=copy.copy(cl[itraj])
  47. #cr.reverse()
  48. j=0
  49. while j<len(cl[itraj]):
  50. c=cl[itraj][j]
  51. filei=glob.glob(run+"/"+"state-%i.out" % c)
  52. #print filei
  53. if len(filei)>0:
  54. if ntraj>1: fileo=run+"/"+"traj-%d-%09d.out" % (itraj,i[itraj])
  55. else: fileo=run+"/"+"traj-%09d.out" % (i[itraj])
  56. shutil.copyfile(filei[0],fileo)
  57. print filei,fileo
  58. i[itraj]+=1
  59. else:
  60. #print "Skipped ", c
  61. pass
  62. if not (c==0 or c==666):
  63. #print c
  64. jp=j
  65. j=last[c]
  66. #print "jumping from ",jp," to ",j
  67. """
  68. try:
  69. jp=j
  70. j=len(cr)-1-cr.index(c)
  71. print "jumping from ",jp," to ",j
  72. except:
  73. pass
  74. """
  75. j+=1
  76. else:
  77. for j in range(len(cl[itraj])):
  78. c=cl[itraj][j]
  79. t=tl[itraj][j]
  80. #print c
  81. filei=glob.glob(run+"/"+"state-%i.out" % c)
  82. #print filei
  83. if len(filei)>0:
  84. if ntraj>1: fileo=run+"/"+"traj-%d-%09d.out" % (itraj,i[itraj])
  85. else: fileo=run+"/"+"traj-%09d.out" % (i[itraj])
  86. shutil.copyfile(filei[0],fileo)
  87. print filei,fileo
  88. i[itraj]+=1
  89. else:
  90. #print "Skipped ", c
  91. pass