biotite.structure.io.npz.NpzFile

class biotite.structure.io.npz.NpzFile[source]

Bases: biotite.file.File

This class represents a NPZ file, the preferable format for Biotite internal structure storage.

Internally the this class writes/reads all attribute arrays of an AtomArray or AtomArrayStack using the NumPy save()/load() method. This format offers the fastest I/O operations and completely preserves the content all atom annotation arrays.

Examples

Load a \*.npz file, modify the structure and save the new structure into a new file:

>>> import os.path
>>> file = NpzFile.read(os.path.join(path_to_structures, "1l2y.npz"))
>>> array_stack = file.get_structure()
>>> array_stack_mod = rotate(array_stack, [1,2,3])
>>> file = NpzFile()
>>> file.set_structure(array_stack_mod)
>>> file.write(os.path.join(path_to_directory, "1l2y_mod.npz"))
copy()

Create a deep copy of this object.

Returns
copy

A copy of this object.

get_structure()

Get an AtomArray or AtomArrayStack from the file.

If this method returns an array or stack depends on which type of object was used when the file was written.

Returns
arrayAtomArray or AtomArrayStack

The array or stack contained in this file.

classmethod read(file)

Read a NPZ file.

Parameters
filefile-like object or str

The file to be read. Alternatively a file path can be supplied.

Returns
file_objectNPZFile

The parsed file.

set_structure(array)

Set the AtomArray or AtomArrayStack for the file.

Parameters
arrayAtomArray or AtomArrayStack

The array or stack to be saved into this file.

write(file)

Write a NPZ file.

Parameters
filefile-like object or str

The file to be read. Alternatively, a file path can be supplied.