Chemistry tools tutorials/scripts

Tutorials and scripts for several computational chemistry tools

KBS - Home
Chem. tools tutorials
File conversion

File Conversion

There are hundreds of chemical file formats… Here is a compilation of some Python scripts to convert between common file formats.


This contains functions to write atomic coordinates files. The functions are formatted as:

write_file(file_name, atoms, coordinates)

where file_name is the output file name, atoms is a list of elements and coordinates is a 2D list of atomic coordinates.

Example (writing a water molecule in pdb format):

filename = 'water.pdb'
atoms = ['O', 'H', 'H']
coordinates = [[0.0, 0.0, 0.0],
               [0.757, 0.586, 0.0],
               [-0.757, 0.586, 0.0]]

write_pdb(filename, atoms, coordinates)

xyz/cif conversion

This conversion is important for defining a unit cell for a given structure. The tricky part for this conversion is converting cartesian coordinates to fractional coordinates. This script currently only works for orthogonal cells, however using IPMOF library a P1 version can be generated easily.



This would prompt the user to enter cell dimensions and an output file name for the cif file.

Fill unit cell (P1 conversion)

This script allows converting a unit cell to P1 space group using OpenBabel. This means that the cell would be filled with all atoms by applying all the symmetry operations. This is necessary for some software such as lammps_interface which is used to assign force field parameters.


python non-P1.cif P1.cif


There are two scripts that allow conversion of tinker xyz file to regular xyz file. One ( is for converting a single file and the other ( is for converting a set of tinker xyz files in a directory and collect them into a single xyz trajectory file.


# Convert single file to xyz (output file name is prompted)
>>> python

# Convert multiple files to xyz trajectory
# Input file basename, number of frames and output file name are prompted
>>> python