Supported File Formats

The AtomsReaders and AtomsWriters dictionaries are used by the Atoms constructor, Atoms.write(), the AtomsList constructor and AtomsList.write() to work out how to read or write a particular file type, based on the filename extension.

The quippy native formats are Extended XYZ and NetCDF.

quippy.AtomsReaders

Supported file formats for reading Atoms objects from files.

File extension Description
castep or castep_log CASTEP output file
cell CASTEP cell file
geom CASTEP geom file
md CASTEP MD file
nc NetCDF file
pos ASAP coordinate file
stdin Read from stdin in extended XYZ format
string Read from string in extended XYZ format
xyz Extended XYZ format
quippy.AtomsWriters

Supported file formats for writing Atoms objects to files.

File extension Description
cell CASTEP cell file
nc NetCDF file
pos ASAP coordinate file
pov POV-ray script
stdout Write to stdout in extended XYZ format
string Write to string in extended XYZ format
xyz Extended XYZ format

Adding a new file type

To add support for a new file format, implement routines which read from or write to files following the templates below.

def sample_reader(filename):
    # insert code to open `filename` for reading

    while True:
       # determine if more frame are available
       if more_frames:
          # read next frame from `filename` into new Atoms object
          at = Atoms()
          yield at
       else:
          break


class sample_writer(object):
    def __init__(self, filename):
       # insert code to open `filename` for writing
       pass

    def write(self, at):
       # insert code to write `at` to `filename`
       pass

    def close(self):
       # insert code to close `filename`
       pass

sample_reader() is a generator which yields a succession of Atoms objects, raising StopIteration when there are no more available - for a file format which only permits one configuration per file, a simplified implementation template would be:

def sample_reader(filename):
   # insert code to open `filename` for reading
   # insert code to read from `filename` into new Atoms object
   yield at

To register the new file format, you just need to set entries in AtomsReaders and AtomsWriters:

from quippy import AtomsReaders, AtomsWriters
AtomsReaders['new_format'] = sample_reader
AtomsWriters['new_format'] = sameple_writer

For the case of reading, there is a generator atoms_reader() which can be used to simplify the registration process:

@atoms_reader('new_format')
def sample_reader(filename):
   ...

See the code in quippy.xyz_netcdf and quippy.castep for full examples.

Table Of Contents

Previous topic

atomeye – Interface to AtomEye viewer

Next topic

Extended XYZ

This Page