Image structure Image document-open


Reading structures from XYZ files.


structure.read_xyz(file=None, dir=None, read_mol=None, set_mol_name=None, read_model=None, set_model_num=None, verbosity=1)

Keyword arguments

file: The name of the XYZ file.

dir: The directory where the file is located.

read_mol: If set, only the given molecule(s) will be read. The molecules are numbered consecutively from 1. If unset, then all molecules will be loaded. By providing a list of numbers such as [1, 2], multiple molecules will be read.

set_mol_name: Set the names of the read molecules. If unset, then the molecules will be automatically labelled based on the file name or other information. This can either be a single name or a list of names.

read_model: If set, only the given model number(s) from the PDB file will be read. Otherwise all models will be read. This can be a single number or list of numbers.

set_model_num: Set the model numbers of the loaded molecules. If unset, then the PDB model numbers will be preserved if they exist. This can be a single number or list of numbers.

verbosity: The amount of information to print out. Set to zero to silence the user function, or one to see all messages.


The XYZ files with different models, which defined as an ensemble of the same molecule but with different atomic positions, can be read into relax. If there are several molecules in one xyz file, please separate them into different files and then load them individually. Loading different models and different molecules is controlled by specifying the molecule number read, setting the molecule names, specifying which model to read, and setting the model numbers.

The setting of molecule names is used to name the molecules within the XYZ (within one model). If not set, then the molecules will be named after the file name, with the molecule number appended if more than one exists.

Note that relax will complain if it cannot work out what to do.

Prompt examples

To load all structures from the XYZ file `' in the directory `~/xyz', including all models and all molecules, type one of:

relax> structure.read_xyz('', '~/xyz')

relax> structure.read_xyz(file='', dir='xyz')

To load the 10 th model from the file `' and naming it `CaM', use one of:

relax> structure.read_xyz('', read_model=10, set_mol_name='CaM')

relax> structure.read_xyz(file='', read_model=10, set_mol_name='CaM')

To load models 1 and 5 from the file `' as two different structures of the same model, type one of:

relax> structure.read_xyz('', read_model=[1, 5], set_model_num=[1, 1])

relax> structure.read_xyz('', set_mol_name=['CaM_1', 'CaM_2'], read_model=[1, 5], set_model_num=[1, 1])

To load the files `', `', `' and `' as models, type the following sequence of commands:

relax> structure.read_xyz('', set_mol_name='test_1', set_model_num=1)

relax> structure.read_xyz('', set_mol_name='test_2', set_model_num=2)

relax> structure.read_xyz('', set_mol_name='test_3', set_model_num=3)

relax> structure.read_xyz('', set_mol_name='test_4', set_model_num=4)

The relax user manual (PDF), created 2024-06-08.