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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
from matplotlib import pyplot as pl
from matplotlib import animation
import sys
# read data
# time dependent data
frames=[]
# asymptotic data (located in the first block)
asym=[]
infile=open(sys.argv[1],'r')
row=[]
for line in infile:
# read first block
if len(asym)==0:
if line=='\n':
asym=row
row=[]
else:
dat=[]
for n in line.split():
dat.append(float(n))
row.append(dat)
# read other blocks
else:
if line=='\n':
frames.append(row)
row=[]
else:
dat=[]
for n in line.split():
dat.append(float(n))
row.append(dat)
infile.close()
# set up plot
fig = pl.figure()
#pl.subplot(211)
axr=fig.gca()
asym_rho, = axr.plot([],[],linewidth=3.5,color='#00FF00')
rho, = axr.plot([],[],color='red')
#pl.subplot(212)
#axJ=fig.gca()
#asym_J, = axJ.plot([],[],linewidth=3.5,color='#00FF00')
#J, = axJ.plot([],[],color='red')
# plot ranges
xmax=0
maxyr=0
maxyJ=0
for frame in frames:
for i in range(len(frame)):
if frame[i][1]>xmax:
xmax=frame[i][1]
if frame[i][2]>maxyr:
maxyr=frame[i][2]
if frame[i][3]>maxyJ:
maxyJ=frame[i][3]
for i in range(len(asym)):
if asym[i][0]>xmax:
xmax=asym[i][0]
if asym[i][1]>maxyr:
maxyr=asym[i][1]
if asym[i][2]>maxyJ:
maxyJ=asym[i][2]
xmin=0
minyr=0
minyJ=0
for frame in frames:
for i in range(len(frame)):
if frame[i][1]<xmin:
xmin=frame[i][1]
if frame[i][2]<minyr:
minyr=frame[i][2]
if frame[i][3]<minyJ:
minyJ=frame[i][3]
for i in range(len(asym)):
if asym[i][0]<xmin:
xmin=asym[i][0]
if asym[i][1]<minyr:
minyr=asym[i][1]
if asym[i][2]<minyJ:
minyJ=asym[i][2]
# plot asymptotes
asym_rho_datax=[]
asym_rho_datay=[]
for i in range(len(asym)):
asym_rho_datax.append(asym[i][0])
asym_rho_datay.append(asym[i][1])
asym_rho.set_data(asym_rho_datax,asym_rho_datay)
#asym_J_datax=[]
#asym_J_datay=[]
#for i in range(len(asym)):
# asym_J_datax.append(asym[i][0])
# asym_J_datay.append(asym[i][2])
#asym_J.set_data(asym_J_datax,asym_J_datay)
# animate
def init_plot():
axr.set_ylim(minyr,maxyr)
axr.set_xlim(xmin,xmax)
#axJ.set_ylim(minyJ,maxyJ)
#axJ.set_xlim(xmin,xmax)
axr.vlines(0,minyr,maxyr,linestyles="dotted")
#axJ.vlines(0,minyJ,maxyJ,linestyles="dotted")
def update(frame):
axr.set_title("t=% .3f fs" % (frame[0][0]))
xdata=[]
ydata=[]
for i in range(len(frame)):
xdata.append(frame[i][1])
ydata.append(frame[i][2])
rho.set_data(xdata,ydata)
#xdata=[]
#ydata=[]
#for i in range(len(frame)):
# xdata.append(frame[i][1])
# ydata.append(frame[i][3])
#J.set_data(xdata,ydata)
anim = animation.FuncAnimation(fig, update, frames=frames, blit=False, interval=100, repeat=True, init_func=init_plot)
#anim.save('schrodinger_barrier.mp4', fps=15, extra_args=['-vcodec', 'libx264'])
pl.show()
|