Пример #1
0
def test_array_conversion(path):
    npz_file = npz.NpzFile()
    npz_file.read(path)
    array1 = npz_file.get_structure()
    npz_file = npz.NpzFile()
    npz_file.set_structure(array1)
    array2 = npz_file.get_structure()
    assert array1 == array2
Пример #2
0
def input_atoms(request):
    ndim, as_coord = request.param

    file = npz.NpzFile()
    file.read(join(data_dir, "1l2y.npz"))
    atoms = file.get_structure()

    if ndim == 2:
        # Only one model
        atoms = atoms[0]
    elif ndim == 1:
        # Only one atom
        atoms = atoms[0, 0]

    if as_coord:
        return atoms.coord
    else:
        return atoms
Пример #3
0
def test_dihedral_backbone():
    file = npz.NpzFile()
    file.read(join(data_dir, "1l2y.npz"))
    # Test array
    array = file.get_structure()[0]
    phi, psi, omega = struc.dihedral_backbone(array, "A")
    assert omega.shape == (20, )
    # Remove nan values
    omega = np.abs(omega)[:-1]
    assert omega.tolist() == pytest.approx([np.pi] * len(omega), rel=0.05)
    # Test stack
    stack = file.get_structure()
    phi, psi, omega = struc.dihedral_backbone(stack, "A")
    assert omega.shape == (38, 20)
    # Remove nan values
    omega = np.abs(omega)[:, :-1]
    omega = np.average(omega, axis=0)
    assert omega.tolist() == pytest.approx([np.pi] * len(omega), rel=0.05)
Пример #4
0
def array():
    file = npz.NpzFile()
    file.read(join(data_dir, "1l2y.npz"))
    return file.get_structure()[0]
Пример #5
0
def test_rotate_centered():
    file = npz.NpzFile()
    file.read(join(data_dir, "1l2y.npz"))
    array = file.get_structure()[0]
    rotated = struc.rotate_centered(array, [2 * np.pi, 2 * np.pi, 2 * np.pi])
    assert np.sum(rotated.coord - array.coord) == pytest.approx(0, abs=1e-4)
Пример #6
0
#
# An alternative file format for storing and loading atom arrays and
# stacks even faster, is the *NPZ* format.
# The big disadvantage is that the format is *Biotite*-exclusive:
# No other software will be able to read these files.
# These are simple binary files, that are used to store *NumPy* arrays.
# In case of atom arrays and stacks, the annotation arrays and
# coordinates are written/read to/from *npz* files via the
# :class:`NpzFile` class.
# Since no expensive data conversion has to be performed,
# this format is the fastest way to save and load atom arrays and
# stacks.

import biotite.structure.io.npz as npz

file = npz.NpzFile()
file.set_structure(array)
reloaded_array = file.get_structure()

########################################################################
# .. currentmodule:: biotite.structure.io
#
# Since programmers are usually lazy and do not want to write more code
# than necessary, there are two convenient function for loading and
# saving atom arrays or stacks, unifying the forementioned file formats:
# :func:`load_structure()` takes a file path and outputs an array
# (or stack, if the file contains multiple models).
# Internally, this function uses the appropriate :class:`File` class,
# depending on the file format.
# The analogous :func:`save_structure()` function provides a shortcut
# for writing to structure files.