Skip to content

Commit 07ae417

Browse files
committedMar 7, 2025
edit the lines.py script and some research examples
1 parent 9a090a9 commit 07ae417

File tree

3 files changed

+48
-21
lines changed

3 files changed

+48
-21
lines changed
 

‎python/lines.py

+38-8
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
# add the
1515
parser.add_argument("-h", "--help", action="help", default=ap.SUPPRESS, help="This help message.")
1616
parser.add_argument("-o", "--output", type=str, help="The output file to save the plot.")
17+
parser.add_argument("-a", "--animate", type=int, help="Animate the plot.")
1718

1819
# add the plotting arguments
1920
parser.add_argument("--colormap", type=str, default="tab10", help="The colormap to use for the plot.")
2021
parser.add_argument("--dpi", type=int, default=96, help="The DPI of the plot.")
2122
parser.add_argument("--figsize", type=int, nargs=2, default=[6, 8], help="The dimensions of the plot in inches.")
23+
parser.add_argument("--fps", type=int, default=30, help="Frames per second for the animation.")
2224
parser.add_argument("--legend", type=str, nargs="+", help="Add a legend to the plot.")
2325
parser.add_argument("--title", type=str, help="The title of the plot.")
2426
parser.add_argument("--xlabel", type=str, help="The an x-axis label.")
@@ -47,13 +49,15 @@
4749
data_errors, cols_errors = zip(*[load(file) for file in args.errors[1:]]) if args.errors else ((), ())
4850

4951
# get the line indices for the error bars
50-
lind_errors = (list(map(lambda x: int(x), args.errors [0].split(","))) if args.errors [0] != "all" else np.arange(sum([len(col) for col in cols_errors]))) if args.errors else []
51-
lind_offsets = (list(map(lambda x: int(x), args.offsets[0].split(","))) if args.offsets[0] != "all" else np.arange(len(args.offsets) - 1 )) if args.offsets else []
52-
lind_scales = (list(map(lambda x: int(x), args.scales [0].split(","))) if args.scales [0] != "all" else np.arange(len(args.scales ) - 1 )) if args.scales else []
52+
lind_errors = (list(map(lambda x: int(x), args.errors [0].split(","))) if args.errors [0] != "all" else range(sum([len(col) for col in cols_errors]))) if args.errors else []
53+
lind_offsets = (list(map(lambda x: int(x), args.offsets[0].split(","))) if args.offsets[0] != "all" else range(len(args.offsets) - 1 )) if args.offsets else []
54+
lind_scales = (list(map(lambda x: int(x), args.scales [0].split(","))) if args.scales [0] != "all" else range(len(args.scales ) - 1 )) if args.scales else []
5355

54-
# add the scales and offsets to the data
55-
for i, (data_i, j) in enumerate(dcit(data, data_cols)): data_i[:, j + 1] *= float(args.scales [lind_scales .index(i) + 1]) if i in lind_scales else 1
56-
for i, (data_i, j) in enumerate(dcit(data, data_cols)): data_i[:, j + 1] += float(args.offsets[lind_offsets.index(i) + 1]) if i in lind_offsets else 0
56+
# add the scales and offsets to the initial lines in the data
57+
for (frame, step) in ((frame, args.animate if args.animate else 0) for frame in range((data[0].shape[1] - 1) // args.animate if args.animate else 1)):
58+
for i, (data_i, j) in enumerate(dcit(data, data_cols)): data_i[:, j + frame * step + 1] *= float(args.scales [lind_scales .index(i) + 1]) if i in lind_scales else 1
59+
for (frame, step) in ((frame, args.animate if args.animate else 0) for frame in range((data[0].shape[1] - 1) // args.animate if args.animate else 1)):
60+
for i, (data_i, j) in enumerate(dcit(data, data_cols)): data_i[:, j + frame * step + 1] += float(args.offsets[lind_offsets.index(i) + 1]) if i in lind_offsets else 0
5761

5862
# create the figure and the container for plots and error bars
5963
fig, ax = plt.subplots(dpi=args.dpi, figsize=(args.figsize[1], args.figsize[0])); plots, ebars = [], []
@@ -78,7 +82,11 @@
7882
ebars.append(ax.fill_between(data_errors_i[:, 0], bot, top, color=cmap[lind_errors[len(ebars)] % len(cmap)], alpha=0.2))
7983

8084
# set the default axis limits
81-
ax.set_xlim(min([data_i[:, 0].min() for data_i in data]), max([data_i[:, 0].max() for data_i in data]))
85+
ax.set_xlim(min([data_i[:, 0 ].min() for data_i in data]), max([data_i[:, 0 ].max() for data_i in data]))
86+
ax.set_ylim(min([data_i[:, 1:].min() for data_i in data]), max([data_i[:, 1:].max() for data_i in data]))
87+
88+
# enlarge the y limit by 5 percent
89+
ax.set_ylim(ax.get_ylim()[0] - 0.05 * np.diff(ax.get_ylim()), ax.get_ylim()[1] + 0.05 * np.diff(ax.get_ylim()))
8290

8391
# add the legend
8492
if args.legend: ax.legend(args.legend, frameon=False)
@@ -97,5 +105,27 @@
97105
# set the layout
98106
fig.tight_layout()
99107

108+
# update function
109+
def update(frame):
110+
111+
# loop over the data and its columns to plot
112+
for i, (data_i, j) in enumerate(dcit(data, data_cols)):
113+
114+
# update the data
115+
plots[i][0].set_ydata(data_i[:, j + frame * args.animate + 1])
116+
117+
# loop over the error bars and their columns
118+
for i, (data_errors_i, j) in enumerate(dcit(data_errors, cols_errors)):
119+
120+
# update the error bars
121+
top = plots[lind_errors[i]][0].get_ydata() + data_errors_i[:, j + 1]
122+
bot = plots[lind_errors[i]][0].get_ydata() - data_errors_i[:, j + 1]
123+
124+
# fill the area between the top and bottom line
125+
ebars[i].remove(); ebars[i] = ax.fill_between(data_errors_i[:, 0], bot, top, color=cmap[lind_errors[i] % len(cmap)], alpha=0.2)
126+
127+
# create the animation
128+
anm = anm.FuncAnimation(fig, update, frames=(data[0].shape[1] - 1) // args.animate, init_func=lambda: None, interval=1000 // args.fps) if args.animate else None
129+
100130
# save or show the plot
101-
plt.savefig(args.output) if args.output else plt.show()
131+
(anm.save(args.output, fps=args.fps) if args.animate else plt.savefig(args.output)) if args.output else plt.show()

‎research/analyze/ho_excited_states.sh

+4-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ $PLOT ACF_TRANSFORMED_2D.mat --xlabel "Time (a.u)" --ylabel "Autocorrelation Fun
99
$PLOT SPECTRUM_1D.mat --xlim 0 6 --xlabel "Energy (a.u)" --ylabel "Intensity" --output SPECTRUM_1D.png
1010
$PLOT SPECTRUM_2D.mat --xlim 0 8 --xlabel "Energy (a.u)" --ylabel "Intensity" --output SPECTRUM_2D.png
1111

12-
$PLOT SPECTRUM_TRANSFORMED_1D.mat --xlim 0 6 --xlabel "Energy (a.u)" --ylabel "Intensity" --output SPECTRUM_TRANSFORMED_1D.png
13-
$PLOT SPECTRUM_TRANSFORMED_2D.mat --xlim 0 8 --xlabel "Energy (a.u)" --ylabel "Intensity" --output SPECTRUM_TRANSFORMED_2D.png
12+
$PLOT SPECTRUM_TRANSFORMED_1D.mat --xlim 0 6 --xlabel "Energy (a.u)" --ylabel "Intensity" --output SPECTRUM_TRANSFORMED_1D.png
13+
$PLOT SPECTRUM_TRANSFORMED_2D.mat --xlim 0 8 --xlabel "Energy (a.u)" --ylabel "Intensity" --output SPECTRUM_TRANSFORMED_2D.png
1414

15-
# $PLOT WAVEFUNCTION_1D_REAL.mat:0,1 --animate 2 --ndim 1 --xlabel "Coordinate (a.u)" --ylabel "Value" --output WAVEFUNCTION_1D --gif
16-
# $PLOT WAVEFUNCTION_2D_REAL.mat:0,1 --animate 2 --ndim 2 --xlabel "Coordinate #1 (a.u)" --ylabel "Coordinate #2 (a.u)" --output WAVEFUNCTION_2D --gif
15+
$PLOT WAVEFUNCTION_1D_REAL.mat:0,1 --xlabel "Coordinate (a.u)" --ylabel "Value" --animate 2 --output WAVEFUNCTION_1D.gif
1716

18-
# $PLOT POTENTIAL_1D.mat WAVEFUNCTION_1D_IMAG_1.mat:1000,1001 WAVEFUNCTION_1D_IMAG_2.mat:1000,1001 WAVEFUNCTION_1D_IMAG_3.mat:1000,1001 WAVEFUNCTION_1D_IMAG_4.mat:1000,1001 WAVEFUNCTION_1D_IMAG_5.mat:1000,1001 WAVEFUNCTION_1D_IMAG_6.mat:1000,1001 WAVEFUNCTION_1D_IMAG_7.mat:1000,1001 WAVEFUNCTION_1D_IMAG_8.mat:1000,1001 WAVEFUNCTION_1D_IMAG_9.mat:1000,1001 --offset 0 0.5 0.5 1.5 1.5 2.5 2.5 3.5 3.5 4.5 4.5 5.5 5.5 6.5 6.5 7.5 7.5 8.5 8.5 --xlabel "Coordinate (a.u)" --ylabel "Energy (a.u)" --domain -5 5 --value 0 9 --scale 0.8 --output EIGENSTATES_1D --png
19-
20-
# $PLOT WAVEFUNCTION_2D_IMAG_1.mat:1000,1001 WAVEFUNCTION_2D_IMAG_2.mat:1000,1001 WAVEFUNCTION_2D_IMAG_3.mat:1000,1001 WAVEFUNCTION_2D_IMAG_4.mat:1000,1001 WAVEFUNCTION_2D_IMAG_5.mat:1000,1001 WAVEFUNCTION_2D_IMAG_6.mat:1000,1001 WAVEFUNCTION_2D_IMAG_7.mat:1000,1001 WAVEFUNCTION_2D_IMAG_8.mat:1000,1001 WAVEFUNCTION_2D_IMAG_9.mat:1000,1001 --ndim 2 --blank --output EIGENSTATES_2D --png
17+
lines.py POTENTIAL_1D.mat WAVEFUNCTION_1D_IMAG_1.mat:2000,2001 WAVEFUNCTION_1D_IMAG_2.mat:2000,2001 WAVEFUNCTION_1D_IMAG_3.mat:2000,2001 WAVEFUNCTION_1D_IMAG_4.mat:2000,2001 WAVEFUNCTION_1D_IMAG_5.mat:2000,2001 WAVEFUNCTION_1D_IMAG_6.mat:2000,2001 WAVEFUNCTION_1D_IMAG_7.mat:2000,2001 WAVEFUNCTION_1D_IMAG_8.mat:2000,2001 WAVEFUNCTION_1D_IMAG_9.mat:2000,2001 --xlabel "Coordinate (a.u)" --ylabel "Energy (a.u)" --xlim -5 5 --ylim 0 9 --offsets 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 0.5 0.5 1.5 1.5 2.5 2.5 3.5 3.5 4.5 4.5 5.5 5.5 6.5 6.5 7.5 7.5 8.5 8.5 --scales 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 -o EIGENSTATES_1D.png
2118

2219
montage ACF_1D.png SPECTRUM_1D.png -mode concatenate -tile x1 JOIN_ACF_SPECTRUM_1D.png
2320
montage ACF_2D.png SPECTRUM_2D.png -mode concatenate -tile x1 JOIN_ACF_SPECTRUM_2D.png
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22

3-
# $PLOT WAVEFUNCTION_DIABATIC_tully1D_1.mat:0,1,2,3~POTENTIAL_DIABATIC_tully1D_1.mat:0-0,1-0,2-3,3-3 --animate 4 --scale 0.01 --xlabel "Coordinate (a.u)" --ylabel "Value" --output WAVEFUNCTION_DIABATIC_tully1D_1 --gif
4-
# $PLOT WAVEFUNCTION_ADIABATIC_tully1D_1.mat:0,1,2,3~POTENTIAL_ADIABATIC_tully1D_1.mat:0-0,1-0,2-3,3-3 --animate 4 --scale 0.01 --xlabel "Coordinate (a.u)" --ylabel "Value" --output WAVEFUNCTION_ADIABATIC_tully1D_1 --gif
3+
$PLOT WAVEFUNCTION_DIABATIC_tully1D_1.mat:0,1,2,3 --offsets all -1 -1 1 1 --animate 4 --xlabel "Coordinate (a.u)" --ylabel "Value" --title "Diabatic" --output WAVEFUNCTION_DIABATIC_tully1D_1.gif
4+
$PLOT WAVEFUNCTION_ADIABATIC_tully1D_1.mat:0,1,2,3 --offsets all -1 -1 1 1 --animate 4 --xlabel "Coordinate (a.u)" --ylabel "Value" --title "Adiabatic" --output WAVEFUNCTION_ADIABATIC_tully1D_1.gif
55

6-
# $PLOT WAVEFUNCTION_DIABATIC_tripleState1D_3.mat:0,1,2,3,4,5~POTENTIAL_DIABATIC_tripleState1D_3.mat:0-0,1-0,2-4,3-4,4-8,5-8 --animate 6 --scale 0.01 --xlabel "Coordinate (a.u)" --ylabel "Value" --output WAVEFUNCTION_DIABATIC_tripleState1D_3 --gif
7-
# $PLOT WAVEFUNCTION_ADIABATIC_tripleState1D_3.mat:0,1,2,3,4,5~POTENTIAL_ADIABATIC_tripleState1D_3.mat:0-0,1-0,2-4,3-4,4-8,5-8 --animate 6 --scale 0.01 --xlabel "Coordinate (a.u)" --ylabel "Value" --output WAVEFUNCTION_ADIABATIC_tripleState1D_3 --gif
6+
$PLOT WAVEFUNCTION_DIABATIC_tripleState1D_3.mat:0,1,2,3,4,5 --offsets all -1 -1 0 0 1 1 --animate 6 --xlabel "Coordinate (a.u)" --ylabel "Value" --title "Diabatic" --output WAVEFUNCTION_DIABATIC_tripleState1D_3.gif
7+
$PLOT WAVEFUNCTION_ADIABATIC_tripleState1D_3.mat:0,1,2,3,4,5 --offsets all -1 -1 0 0 1 1 --animate 6 --xlabel "Coordinate (a.u)" --ylabel "Value" --title "Adiabatic" --output WAVEFUNCTION_ADIABATIC_tripleState1D_3.gif
88

99
$PLOT POPULATION_DIABATIC_tully1D_1.mat --xlabel "Time (a.u)" --ylabel "Population" --legend "S0" "S1" --output POPULATION_DIABATIC_tully1D_1.png
1010
$PLOT POPULATION_ADIABATIC_tully1D_1.mat --xlabel "Time (a.u)" --ylabel "Population" --legend "S0" "S1" --output POPULATION_ADIABATIC_tully1D_1.png
@@ -15,8 +15,8 @@ $PLOT POPULATION_ADIABATIC_tripleState1D_3.mat --xlabel "Time (a.u)" --ylabel "P
1515
montage POPULATION_DIABATIC_tully1D_1.png POPULATION_ADIABATIC_tully1D_1.png -mode concatenate -tile x1 POPULATION_tully1D_1.png
1616
montage POPULATION_DIABATIC_tripleState1D_3.png POPULATION_ADIABATIC_tripleState1D_3.png -mode concatenate -tile x1 POPULATION_tripleState1D_3.png
1717

18-
# ffmpeg -i WAVEFUNCTION_DIABATIC_tripleState1D_3.gif -i WAVEFUNCTION_ADIABATIC_tripleState1D_3.gif -filter_complex "palettegen" -loglevel error palette.png && ffmpeg -i WAVEFUNCTION_DIABATIC_tripleState1D_3.gif -i WAVEFUNCTION_ADIABATIC_tully1D_1.gif -i palette.png -filter_complex "[0:v][1:v]hstack[v]; [v][2:v]paletteuse" -loglevel error WAVEFUNCTION_tully1D_1.gif && rm palette.png
18+
ffmpeg -i WAVEFUNCTION_DIABATIC_tully1D_1.gif -i WAVEFUNCTION_ADIABATIC_tully1D_1.gif -filter_complex "palettegen" -loglevel error palette.png && ffmpeg -i WAVEFUNCTION_DIABATIC_tully1D_1.gif -i WAVEFUNCTION_ADIABATIC_tully1D_1.gif -i palette.png -filter_complex "[0:v][1:v]hstack[v]; [v][2:v]paletteuse" -loglevel error WAVEFUNCTION_tully1D_1.gif && rm palette.png
1919

20-
# ffmpeg -i WAVEFUNCTION_DIABATIC_tripleState1D_3.gif -i WAVEFUNCTION_ADIABATIC_tripleState1D_3.gif -filter_complex "palettegen" -loglevel error palette.png && ffmpeg -i WAVEFUNCTION_DIABATIC_tripleState1D_3.gif -i WAVEFUNCTION_ADIABATIC_tripleState1D_3.gif -i palette.png -filter_complex "[0:v][1:v]hstack[v]; [v][2:v]paletteuse" -loglevel error WAVEFUNCTION_tripleState1D_3.gif && rm palette.png
20+
ffmpeg -i WAVEFUNCTION_DIABATIC_tripleState1D_3.gif -i WAVEFUNCTION_ADIABATIC_tripleState1D_3.gif -filter_complex "palettegen" -loglevel error palette.png && ffmpeg -i WAVEFUNCTION_DIABATIC_tripleState1D_3.gif -i WAVEFUNCTION_ADIABATIC_tripleState1D_3.gif -i palette.png -filter_complex "[0:v][1:v]hstack[v]; [v][2:v]paletteuse" -loglevel error WAVEFUNCTION_tripleState1D_3.gif && rm palette.png
2121

2222
rm *DIABATIC*.gif *DIABATIC*.png

0 commit comments

Comments
 (0)