Exemple #1
0
def test_conversion_to_fraction(len_a, len_b, len_c, alpha, beta, gamma, x, y,
                                z):
    box = struc.vectors_from_unitcell(len_a, len_b, len_c, np.deg2rad(alpha),
                                      np.deg2rad(beta), np.deg2rad(gamma))
    coord = np.array([x, y, z])

    fractions = struc.coord_to_fraction(coord, box)
    if struc.is_orthogonal(box):
        assert fractions.tolist() == pytest.approx(coord / np.diagonal(box))
    new_coord = struc.fraction_to_coord(fractions, box)
    assert np.allclose(coord, new_coord)

    coords = np.stack([coord, coord])
    boxes = np.stack([box, box])
    fractions = struc.coord_to_fraction(coords, boxes)
    new_coords = struc.fraction_to_coord(fractions, boxes)
    assert np.allclose(coords, new_coords)
Exemple #2
0
# Depending on the source of the macromolecular structure, there might
# be an associated unit cell or simulation box.
# In this package such boxes are represented by *(3,3)*-shaped
# :class:`ndarray` objects, where each element in the array is one of
# the three vectors spanning the box or unit cell.
# Let's create an orthorhombic box from the vector lengths and the
# angles between the vectors.

import numpy as np
import biotite.structure as struc
# The function uses angles in radians
box = struc.vectors_from_unitcell(10, 20, 30, np.pi / 2, np.pi / 2, np.pi / 2)
print("Box:")
print(box)
print("Box volume:", struc.box_volume(box))
print("Is orthogonal?:", struc.is_orthogonal(box))
cell = struc.unitcell_from_vectors(box)
print("Cell:")
print(cell)

########################################################################
# An atom array can have an associated box, which is used in functions,
# that consider periodic boundary conditions.
# Atom array stacks require a *(m,3,3)*-shaped :class:`ndarray`,
# that contains the box vectors for each model.
# The box is accessed via the `box` attribute, which is ``None`` by
# default.
# When loaded from a structure file, the box described in the file is
# automatically used.

import biotite.database.rcsb as rcsb