Skip to content

Instantly share code, notes, and snippets.

@ajd98
Created May 29, 2015 19:32
Show Gist options
  • Save ajd98/abd7cadd8017557582da to your computer and use it in GitHub Desktop.
Save ajd98/abd7cadd8017557582da to your computer and use it in GitHub Desktop.
This script is used to generate a movie of the time evolution of an energy surface from a WESTPA simulation.
#!/bin/bash
# Written 29 May 2015 by Alex DeGrave <ajd98@pitt.edu>
# This script generates a movie of a free energy surface, evolving in time.
# The script uses a moving block of width $BLOCK_SIZE.
# A movie is output to evolution_plots/energy_surface_evolution.avi.
# Make sure the utility mencoder is installed.
############ USER VARIABLES ############
# Set location of westpa tools
WEST_ROOT=~/apps/westpa/
# Set location of west.h5
WESTH5=../west.h5
# Set iteration ranges.
MAX_ITER=1000
FIRST_ITER=1
BLOCK_SIZE=100
STEP_ITER=1
# Set axis labels
X_AXIS_LABEL="Dimension 0"
Y_AXIS_LABEL="Dimension 1"
# Set the bounds for the plot axes.
X_AXIS_LOWER_BOUND=0
X_AXIS_UPPER_BOUND=30
Y_AXIS_LOWER_BOUND=0
Y_AXIS_UPPER_BOUND=30
#######################################
echo \
"def add_movie_labels(hist,midpoints,binbounds):
import matplotlib.pyplot as plt
import h5py
iterations_reference_file = open('iters.out')
first_iter = int(iterations_reference_file.readline())
last_iter = int(iterations_reference_file.readline())
iterations_reference_file.close()
plt.xlabel('$X_AXIS_LABEL')
plt.ylabel('$Y_AXIS_LABEL')
plt.title('Iterations %d to %d'%(first_iter,last_iter))
ca = plt.gca()
ca.set_xlim([$X_AXIS_LOWER_BOUND,$X_AXIS_UPPER_BOUND])
ca.set_ylim([$Y_AXIS_LOWER_BOUND,$Y_AXIS_UPPER_BOUND])
return" > surface_plot_functions.py
mkdir evolution_plots
echo "Running w_pdist..."
$WEST_ROOT/bin/w_pdist -W $WESTH5 --first-iter $FIRST_ITER --last-iter $MAX_ITER -o pdist_for_surface_evolution.h5
FIRST_ITER=1
LAST_ITER=$[$FIRST_ITER+$BLOCK_SIZE]
echo "Generating plots..."
while [ $LAST_ITER -le $MAX_ITER ]
do echo "working on iteration $LAST_ITER"
printf -v FIRST_ITER_FORMAT "%05d" $FIRST_ITER
printf -v LAST_ITER_FORMAT "%05d" $LAST_ITER
echo $FIRST_ITER > iters.out
echo $LAST_ITER >> iters.out
$WEST_ROOT/bin/plothist average \
--first-iter $FIRST_ITER --last-iter $LAST_ITER \
--postprocess-function surface_plot_functions.add_movie_labels \
--range 0,20 \
-o evolution_plots/$(echo $FIRST_ITER_FORMAT)_to_$(echo $LAST_ITER_FORMAT).png \
pdist_for_surface_evolution.h5 0 1
FIRST_ITER=$[$FIRST_ITER+$STEP_ITER]
LAST_ITER=$[$LAST_ITER+$STEP_ITER]
done
cd evolution_plots
mencoder mf://*.png -mf w=800:h=600:fps=25:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o energy_surface_evolution.avi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment