XYZ Scripts
This page contains a collection of scripts for processing extended XYZ files containing atomic positions and other simulation data. XYZ files are used by a large variety of molecular dynamics simulation software, for example the libAtoms project. These scripts are designed to be used with the AtomEye atomistic configuration viewer, and all released under the GNU GPL.
xyz2ecfg
This awk script converts an extended XYZ file to a bunch of extended CFG files suitable for use with AtomEye. Usage is straightforward; if movie.xyz contains a series of extended XYZ frames concatentated together then the following commands will convert to CFG format and load the first frame in AtomEye.
/tmp:$ xyz2ecfg.awk movie.xyz Counting frames... Got 437 frames. Done 437 frames. /tmp:$ A movie000.cfg
Properties in the XYZ file are automatically converted to AtomEye auxiliary properties. If the XYZ file contains only a single configuration then there will be no numbers in the output file name.
Download: xyz2ecfg
xyz2clr
This awk script produces a series of AtomEye colour patch files from an XYZ file. This is useful with my cfg2movie script if you want fine control over the colour of each atom in an output movie. Edit the script to change which column is used to determine the colours, and the mapping of values of this column to RGB colours.
Usage is the same as xyz2ecfg. One .clr file is produced for each frame in the XYZ movie.
Download: xyz2clr
cfg2movie
This script takes a bunch of CFG files and an AtomEye view script and renders an MPEG movie. You need mencoder or ffmpeg installed to use it. To make the view script, open the first CFG file in AtomEye version 3 (which supports scripting) and arrange the viewport as you would like. Typing save view at the AtomEye command line will produce a file called view with all of AtomEye's internal parameters.
Then create a file with extra AtomEye commands that need to be executed to to make things work properly for the movie you're trying to make. For my fracture movies, this consists of shifting the crystal to the origin and changing the default Si-Si bond length:
$ cat extras shift_xtal 0 0 rcut_patch start Si Si rcut_patch_inc rcut_patch_inc rcut_patch finish
The usage of cfg2movie is then
cfg2movie <AtomEye view script> <Extra commands> <movie file> <cfg file>...
For example, to render the files movie000.cfg to movie436.cfg produced in the xyz2ecfg example above:
cfg2movie view extras movie.mp4 movie*.cfg
If .clr files corresponding to each CFG file exist, then they are treated as colour patch files to override the default atom colouring for each frame.
Edit the end of the script to change between mencoder (for AVI movies) and ffmpeg (for MP4), and to change the codec or bitrate. I've had good results with ffmpeg. This page has some useful tips on choosing these parameters.
See some of my simulation movies for an example of the movies that can be made in this way.
Download: cfg2movie
get_property
This script prints the columns of an extended XYZ file that correspond to a particular property. This is useful if you want to plot a graph. The usage is
get_property [-s] property_name < infile.xyz > outfile.xyz
If the -s option is present then the species names are printed at the beginning of each line, otherwise only the property values are printed.
Download: get_property
copy_property
This script makes a copy of an XYZ file, with an additional property added from another file. Usage is:
copy_property property_source.xyz input.xyz property_name
The output consists of all the properties in input.xyz plus property_name which is taken from property_source.xyz.
Download: copy_property
get_param
This script extracts per-frame parameters from the comment line on an extended XYZ movie. It's useful for plotting data, and can easily be combined with gnuplot. Usage is
get_param param1 [param2]... < movie.xyz
For example, to plot a graph of time vs. temperature from within gnuplot, you could do something like this:
gnuplot> plot '< get_param Time Temperature < movie.xyz' u 1:2 w l
Download: get_param
xyz2csv
This python script, which depends on my Atoms python library, converts an extended XYZ file to comma seperated value format, suitable for importing into commercial spreadsheet packages. Usage is
xyz2csv <xyz file> [<csv file>]
If the second argument is not given the the basename of the input file is used to name the output file (e.g. if the input is called file.xyz then the output will be to file.csv). Each property in the extended XYZ becomes a column in the CSV output, with the first line of the CSV file containing the column names.
Download: xyz2csv
