xyz files
This module contains functions for input/output operations (reading and writing) of .xyz files.
These files have a regular structure with the following format:
N_atoms (first frame)
Comment_line
Atom_1_chemical_symbol Atom_1_x_coordinate Atom_1_y_coordinate Atom_1_z_coordinate
Atom_2_chemical_symbol Atom_2_x_coordinate Atom_2_y_coordinate Atom_2_z_coordinate
...
N_atoms (second frame)
Comment_line
Atom_1_chemical_symbol Atom_1_x_coordinate Atom_1_y_coordinate Atom_1_z_coordinate
...
PySNOW expects your xyz files to be formatted in this way for I/O operations.
Functions
snow.io.xyz
read_xyz_movie(file_path, extra_cols_indexes=None)
Obtains the coordinates and elements for each frame of an xyz trajectory.
Data from extra columns can also be loaded with the extra_cols_indexes variable. Consider that the first four 'indexes' are element and three cartesian coordinates and are returned by deafult from the function. Example: if your .xyz file has per-atom information like " El pos1 pos2 pos3 force1 force2 force3 charge ", you can get the extra columns force1, force2, charge by passing extra_cols_indexes=[4, 5, 7]. At the moment only float values parsing is supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the xyz file with the structure |
required |
extra_frames_indexes
|
list[int]
|
index for the extra columns of per-atom data to be extracted from the .xyz file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple
|
|
|
el_list |
list[list]
|
list of lists of chemical elements of the atoms in the system |
coords_list |
list[ndarray]
|
list of arrays of coordinates fo atoms in the system |
extra_cols_list |
list[ndarray]
|
list of arrays of data extra from extra columns. Only returned if extra_cols_indexes is set. |
Source code in snow/io/xyz.py
read_xyz(file, extra_cols_indexes=None)
Read an xyz file that contains a single configuration.
wrapper of read_xyz_movie to read single-frame xyz files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
file from where to read |
required |
extra_frames_indexes
|
list[int]
|
index for the extra columns of per-atom data to be extracted from the .xyz file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple
|
|
|
elements |
list
|
list of lists of chemical elements of the atoms in the system |
cordinates |
ndarray
|
array of coordinates fo atoms in the system |
extra_cols |
ndarray
|
array of data extra from extra columns. Only returned if extra_cols_indexes is set. |
Source code in snow/io/xyz.py
write_xyz(filename, elements, coords, additional_data=None, box=None, mode='w')
Writes atomic data to an XYZ file in OVITO-compatible format.
The function is currently only accepting numbers as additional data. If needed, it can write the simulation box as well.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of the output .xyz file. |
required |
elements
|
ndarray
|
List of atomic symbols (e.g., ['Au', 'Au', ...]). |
required |
coords
|
ndarray)
|
Nx3 array of atomic coordinates. |
required |
additional_data
|
list or ndarray
|
Additional per-atom data, such as coordination numbers. |
None
|
box
|
ndarray
|
a simulation box to be written to file |
None
|
mode
|
str
|
mode for writing ('a'->append, 'w'->(over)write) |
'w'
|
Source code in snow/io/xyz.py
write_xyz_movie(filename, elements_list, coords_list, additional_data_list=None, box_list=None)
Writes an xyz movie by reiterating the usage of write_xyz function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of the output .xyz file. |
required |
elements
|
list[list[str]]
|
List of lists of atomic symbols (e.g., ['Au', 'Au', ...]). |
required |
coords
|
ndarray or list[ndarray]
|
list or array of arrays of atomic coordinates. |
required |
additional_data
|
list or np.ndarray of np.ndarrays
|
Additional per-atom data, such as coordination numbers. |
required |
box
|
ndarray
|
a simulation box to be written to file |
required |
Source code in snow/io/xyz.py
write_phantom_xyz(filename, coords, additional_data=None)
Writes 'phantom' atomic data to an XYZ file in OVITO-compatible format.
used to write xyz files with positions of adsorption sites as fictitious atoms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Name of the output .xyz file. |
required | |
elements
|
List of atomic symbols (e.g., ['Au', 'Au', ...]). |
required | |
coords
|
Nx3 array of atomic coordinates. |
required | |
additional_data
|
Additional per-atom data, such as coordination numbers. |
None
|
Source code in snow/io/xyz.py
write_xyz_movie_with_str(frame, filename, elements, coords, additional_data=None)
Writes atomic data to an XYZ file in OVITO-compatible format with additional_data of type string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
Frame number. |
required | |
filename
|
Name of the output .xyz file. |
required | |
elements
|
List of atomic symbols (e.g., ['Au', 'Au', ...]). |
required | |
coords
|
Nx3 array of atomic coordinates. |
required | |
additional_data
|
Additional per-atom data, such as coordination numbers, site types, etc. Can contain both numeric and string data. |
None
|