#!/bin/bash # Usage: ./graph_avg_bond_length_afo_x_displacement.sh # This program creates xmgrace-readable output from a LAMMPS dump file. # Independent variable: x displacement of each atom # Dependent variable: average bond length of that atom's bonds. script_dir=$( cd $(dirname $0) ; pwd -P |sed 's@^\(.*/scripts\).*@\1@') source $script_dir/func/dump_parsing.src # Test validity of input and output files, and create list of input files. dump_file=$1 xmgrace_file=$2 default_output_file=script_output.xm if [ -z $dump_file ]; then echo No input file specified. Exiting. exit 1 fi echo Using input file $dump_file. if [ -w $dump_file -a -r $dump_file ]; then echo $dump_file looks good. else echo Cannot access $dump_file. Exiting. exit 1 fi if [ -z $xmgrace_file ]; then xmgrace_file=${default_output_file} echo No output file specified. Using $xmgrace_file. fi if `! touch $xmgrace_file`; then echo Cannot access $xmgrace_file. Exiting. exit 2 fi echo Output to $xmgrace_file. > $xmgrace_file num_atoms=$(parse_num_atoms_from_dump $dump_file) #echo Found $num_atoms atoms. # Index entries by atom ID echo -n "Indexing values for atom 0/$num_atoms." for atom_id in $(seq 1 $num_atoms); do echo -ne "\rIndexing values for atom $atom_id/$num_atoms." Z[$atom_id]=$(parse_coord x $dump_file $atom_id) U[$atom_id]=$(parse_avg_bond_length $dump_file $atom_id) done echo -ne "\n" # Bubble sort by x value. -- Not finished and not necessary # size=$num_atoms # count=0 # until [[ $made_swap == "false" ]]; do # made_swap="false" # for index in $(seq 2 $size); do # diff1=$(sed -n 5p ${info_array[$((index-1))]}) # diff2=$(sed -n 5p ${info_array[$index]}) # if [[ $(echo "$diff1 > $diff2"|bc) == "1" ]]; then # temp_info=${info_array[$((index-1))]} # info_array[$((index-1))]=${info_array[$index]} # info_array[$index]=$temp_info # made_swap="true" # fi # done # # done # Write array to xmgrace-readable file. echo Writing $num_atoms entries to table. for index in $(seq 1 $num_atoms ); do echo ${Z[$index]} ${U[$index]} >> $xmgrace_file done echo Done. exit 0