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()
>>> file.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"))
read(self, file)[source]

Parse a NPZ file.

Parameters
filefile-like object or str

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

write(self, file)[source]

Write a NPZ file.

Parameters
filefile-like object or str

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

get_structure(self)[source]

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 in the content of this file

set_structure(self, array)[source]

Set the AtomArray or AtomArrayStack for the file.

Parameters
arrayAtomArray or AtomArrayStack

The array or stack to be saved into this file.

copy(self)

Create a deep copy of this object.

Returns
copy

A copy of this object.